-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vouchers): implement manual Prise En Charge form
This commit implements a manual Prise En Charge form on the Complex Voucher page. The manual form does not rely on hardware compatibilities of a barcode scanner. The user must specify an account and a patient, the form will load all the patient's bills, and then correctly assign the patient to the voucher.
- Loading branch information
Showing
13 changed files
with
338 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
angular.module('bhima.controllers') | ||
.controller('SupportPatientKitController', SupportPatientKitController); | ||
|
||
// DI definition | ||
SupportPatientKitController.$inject = [ | ||
'$uibModalInstance', 'NotifyService', 'SessionService', 'data', 'bhConstants', | ||
'DebtorService', 'PatientInvoiceService' | ||
]; | ||
|
||
// Import transaction rows for a Support Patient | ||
function SupportPatientKitController(Instance, Notify, Session, Data, bhConstants, Debtors, Invoices) { | ||
var vm = this; | ||
|
||
// global variables | ||
vm.enterprise = Session.enterprise; | ||
vm.gridOptions = {}; | ||
vm.tool = Data; | ||
vm.patientInvoice = false; | ||
|
||
var MAX_DECIMAL_PRECISION = bhConstants.precision.MAX_DECIMAL_PRECISION; | ||
|
||
// expose to the view | ||
vm.selectPatientInvoices = selectPatientInvoices; | ||
vm.close = Instance.close; | ||
vm.import = submit; | ||
vm.loadInvoice = loadInvoice; | ||
vm.onSelectAccount = onSelectAccount; | ||
|
||
// debtors from store | ||
Debtors.store() | ||
.then(function (data) { | ||
vm.patients = data; | ||
}) | ||
.catch(Notify.handleError); | ||
|
||
// get debtor group invoices | ||
function selectPatientInvoices(debtorId) { | ||
// load patient invoices | ||
vm.debtorUuid = debtorId; | ||
|
||
Debtors.invoices(debtorId, { balanced : 0 }) | ||
.then(function (invoices) { | ||
|
||
vm.gridOptions.data = invoices || []; | ||
|
||
// total amount | ||
vm.totalInvoices = vm.gridOptions.data.reduce(function (current, previous) { | ||
return current + previous.balance; | ||
}, 0); | ||
|
||
// make sure we are always within precision | ||
vm.totalInvoices = Number.parseFloat(vm.totalInvoices.toFixed(MAX_DECIMAL_PRECISION)); | ||
|
||
return Invoices.search({debtor_uuid : debtorId}); | ||
}) | ||
.then(function (data) { | ||
vm.invoices = data; | ||
}) | ||
.catch(Notify.handleError); | ||
} | ||
|
||
function loadInvoice(patient){ | ||
vm.patient = patient; | ||
selectPatientInvoices(patient.debtor_uuid); | ||
} | ||
|
||
function onSelectAccount(account) { | ||
vm.account_id = account.id; | ||
} | ||
|
||
// generate transaction rows | ||
function generateTransactionRows(result) { | ||
var rows = []; | ||
var supportAccountId = result.account_id; | ||
var supportedAccountId = result.patient.account_id; | ||
var invoices = result.invoices; | ||
rows.typeId = bhConstants.transactionType.SUPPORT_INCOME; | ||
|
||
// first, generate a support row | ||
var supportRow = generateRow(); | ||
supportRow.account_id = supportAccountId; | ||
supportRow.debit = vm.totalSelected; | ||
supportRow.credit = 0; | ||
rows.push(supportRow); | ||
|
||
// then loop through each selected item and credit it with the Supported account | ||
invoices.forEach(function (invoice) { | ||
var row = generateRow(); | ||
|
||
row.account_id = supportedAccountId; | ||
row.reference_uuid = invoice.uuid; | ||
row.entity_uuid = invoice.entity_uuid; | ||
row.credit = invoice.balance; | ||
|
||
// this is needed for a nice display in the grid | ||
row.entity = formatEntity(invoice.entity_uuid); | ||
|
||
// this is need to display references in the grid nicely | ||
row.document = getInvoiceReference(invoice.uuid); | ||
|
||
// add the row in to the | ||
rows.push(row); | ||
}); | ||
|
||
return rows; | ||
} | ||
|
||
// format entityco | ||
function formatEntity(uuid) { | ||
var entity = vm.patients.get(uuid); | ||
return { | ||
label: entity.text, | ||
type: 'D', | ||
uuid: entity.uuid | ||
}; | ||
} | ||
|
||
// get invoice reference | ||
function getInvoiceReference(uuid) { | ||
var invoice = vm.invoices.filter(function (item) { | ||
return item.uuid === uuid; | ||
})[0]; | ||
|
||
if (invoice) { | ||
invoice.document_type = 'VOUCHERS.COMPLEX.PATIENT_INVOICE'; | ||
} | ||
|
||
return invoice; | ||
} | ||
|
||
// generate row element | ||
function generateRow() { | ||
return { | ||
account_id : undefined, | ||
debit : 0, | ||
credit : 0, | ||
reference_uuid : undefined, | ||
entity_uuid : undefined | ||
}; | ||
} | ||
|
||
/* ================ Invoice grid parameters ===================== */ | ||
vm.gridOptions.appScopeProvider = vm; | ||
vm.gridOptions.enableFiltering = true; | ||
vm.gridOptions.onRegisterApi = onRegisterApi; | ||
vm.gridOptions.fastWatch = true; | ||
vm.gridOptions.flatEntityAccess = true; | ||
|
||
vm.gridOptions.columnDefs = [ | ||
{ field : 'reference', displayName : 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate' }, | ||
{ field : 'date', cellFilter:'date', displayName : 'TABLE.COLUMNS.BILLING_DATE', headerCellFilter : 'translate', enableFiltering: false }, | ||
{ field : 'balance', displayName : 'TABLE.COLUMNS.BALANCE', | ||
headerCellFilter : 'translate', enableFiltering: false, | ||
cellTemplate: '/modules/templates/grid/balance.cell.html' | ||
} | ||
]; | ||
|
||
function onRegisterApi(gridApi) { | ||
vm.gridApi = gridApi; | ||
vm.gridApi.selection.on.rowSelectionChanged(null, rowSelectionCallback); | ||
vm.gridApi.selection.on.rowSelectionChangedBatch(null, rowSelectionCallback); | ||
} | ||
|
||
function rowSelectionCallback(row) { | ||
vm.selectedRows = vm.gridApi.selection.getSelectedRows(); | ||
vm.totalSelected = vm.selectedRows.reduce(function (current, previous) { | ||
return current + previous.balance; | ||
}, 0); | ||
|
||
vm.totalSelected = Number.parseFloat(vm.totalSelected.toFixed(MAX_DECIMAL_PRECISION)); | ||
} | ||
|
||
/* ================ End Invoice grid parameters ===================== */ | ||
|
||
// submission | ||
function submit(form) { | ||
if (form.$invalid) { return; } | ||
|
||
var bundle = generateTransactionRows({ | ||
account_id: vm.account_id, | ||
patient: vm.patient, | ||
invoices: vm.selectedRows | ||
}); | ||
|
||
Instance.close({ rows: bundle, patient: vm.patient }); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
client/src/modules/vouchers/toolkit/support_patient.modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<div class="modal-header"> | ||
<ol class="headercrumb"> | ||
<li class="static" translate>{{ ToolCtrl.tool.label }}</li> | ||
</ol> | ||
</div> | ||
|
||
<form name="ToolForm" bh-submit="ToolCtrl.import(ToolForm)" novalidate> | ||
<div class="modal-body"> | ||
<bh-account-select | ||
name="account_id" | ||
account-id="ToolCtrl.account_id" | ||
on-select-callback="ToolCtrl.onSelectAccount(account)"> | ||
</bh-account-select> | ||
|
||
<bh-find-patient | ||
suppress-reset="false" | ||
on-search-complete="ToolCtrl.loadInvoice(patient)" | ||
on-register-api="ToolCtrl.onRegisterApiCallback(api)" | ||
validation-trigger="ToolForm.$submitted" | ||
required="true"> | ||
</bh-find-patient> | ||
|
||
<!-- select invoices --> | ||
<div ng-show="ToolCtrl.debtorUuid"> | ||
<div | ||
id="invoiceGrid" | ||
style="height: 40vh; margin-bottom: 20px;" | ||
ui-grid="ToolCtrl.gridOptions" | ||
ui-grid-filtering | ||
ui-grid-auto-resize | ||
ui-grid-selection> | ||
</div> | ||
</div> | ||
|
||
<p ng-show="!ToolCtrl.debtorUuid" class="text-info"> | ||
<i class="fa fa-info-circle"></i> <span translate> VOUCHERS.GLOBAL.SUPPORT_TEXT </span> | ||
</p> | ||
|
||
<div ng-show="ToolCtrl.debtorUuid" class="text-right"> | ||
<span translate>FORM.LABELS.TOTAL_BILLED</span>: <strong class="text-danger">{{ ToolCtrl.totalInvoices || 0 | currency: ToolCtrl.enterprise.currency_id }}</strong><br> | ||
<span translate>FORM.LABELS.TOTAL_SELECTED_INVOICES</span>: <strong class="text-success">{{ ToolCtrl.totalSelected || 0 | currency: ToolCtrl.enterprise.currency_id }}</strong> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button | ||
type="button" | ||
class="btn btn-default" | ||
ng-click="ToolCtrl.close()" | ||
data-method="close" | ||
translate> | ||
FORM.BUTTONS.CANCEL | ||
</button> | ||
|
||
<bh-loading-button loading-state="ToolForm.$loading" disabled="ToolCtrl.$invalid || !ToolCtrl.selectedRows.length"> | ||
<span translate>FORM.BUTTONS.SUBMIT</span> | ||
</bh-loading-button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.