Skip to content

Commit

Permalink
feat: implement searching on debtor groups for each registry (#1740)
Browse files Browse the repository at this point in the history
* test(Complete insuffisance test E2E)

- Complete test E2E for the research with the inventorie group uuid
in Cash registry, Patient Registry and Invoice Registry
- Update some function the test E2E
- Update API for cash and patient invoice

* perf(Test e2e and best practice)

- Use ui-select instead select
- Use componant bhClear and fix issue 1702
- Update test E2E

closes #1702
  • Loading branch information
lomamech authored and jniles committed Jun 2, 2017
1 parent 76c0f0b commit d2ac8ae
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 86 deletions.
1 change: 1 addition & 0 deletions client/src/modules/cash/cash.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function CashService(Modal, Api, Exchange, Session, moment, $translate, Filters,
{ key : 'defaultPeriod', label : 'TABLE.COLUMNS.PERIOD', valueFilter : 'translate' },
{ key : 'invoiceReference', label : 'FORM.LABELS.INVOICE' },
{ key : 'patientReference', label : 'FORM.LABELS.REFERENCE_PATIENT' },
{ key : 'debtor_group_uuid', label : 'FORM.LABELS.DEBTOR_GROUP' },
{ key : 'invoice_uuid', label : 'FORM.LABELS.INVOICE' }]);

if (filterCache.filters) {
Expand Down
16 changes: 16 additions & 0 deletions client/src/modules/cash/payments/templates/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@
<bh-clear on-clear="$ctrl.clear('user_id')"></bh-clear>
</bh-user-select>

<div class="form-group">
<label class="control-label" translate>
FORM.LABELS.DEBTOR_GROUP
</label>
<bh-clear on-clear="$ctrl.clear('debtor_group_uuid')"></bh-clear>
<!-- @todo make data driven selects components to handle loading and error states -->
<ui-select
name="debtor_group_uuid"
ng-model="$ctrl.searchQueries.debtor_group_uuid">
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.DEBTOR_GROUP' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="group.uuid as group in ($ctrl.debtorGroups | filter:$select.search | orderBy:'name') track by group.uuid">
<span ng-bind-html="group.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<div class="form-group">
<label class="control-label" translate>
FORM.LABELS.REFERENCE_PATIENT
Expand Down
9 changes: 7 additions & 2 deletions client/src/modules/cash/payments/templates/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ angular.module('bhima.controllers')

// dependencies injections
SearchCashPaymentModalController.$inject = [
'CashboxService', 'NotifyService', '$uibModalInstance', 'filters', 'Store', 'PeriodService', 'util',
'CashboxService', 'NotifyService', '$uibModalInstance', 'filters', 'Store', 'PeriodService', 'util', 'DebtorGroupService',
];

/**
* Search Cash Payment controller
*/
function SearchCashPaymentModalController(Cashboxes, Notify, Instance, filters, Store, Periods, util) {
function SearchCashPaymentModalController(Cashboxes, Notify, Instance, filters, Store, Periods, util, DebtorGroups) {
var vm = this;
var changes = new Store({ identifier : 'key' });
vm.filters = filters;
Expand Down Expand Up @@ -40,6 +40,11 @@ function SearchCashPaymentModalController(Cashboxes, Notify, Instance, filters,
})
.catch(Notify.handleError);

DebtorGroups.read()
.then(function (result) {
vm.debtorGroups = result;
});

// custom filter user_id - assign the value to the searchQueries object
vm.onSelectUser = function onSelectUser(user) {
vm.searchQueries.user_id = user.id;
Expand Down
32 changes: 11 additions & 21 deletions client/src/modules/inventory/list/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,26 @@
<label class="control-label" translate>
FORM.LABELS.GROUP
</label>

<!-- @todo make this a component - it is used everywhere. Calls back method
`clear` and resets the id passed to the component -->
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('group_uuid')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('group_uuid')"></bh-clear>

<!-- @todo make data driven selects components to handle loading and error states -->
<select
class="form-control"
name="debtorGroup"
ng-options="group.uuid as group.name for group in ModalCtrl.inventoryGroups"
<ui-select
name="group_uuid"
ng-model="ModalCtrl.params.group_uuid">
<option disabled value="" translate>
FORM.SELECT.INVENTORY_GROUP
</option>
</select>
<ui-select-match placeholder="{{ 'FORM.SELECT.INVENTORY_GROUP' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="group.uuid as group in (ModalCtrl.inventoryGroups | filter:$select.search | orderBy:'name') track by group.uuid">
<span ng-bind-html="group.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>

</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.text.$invalid }">
<label class="control-label" translate>
FORM.LABELS.LABEL
</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('text')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('text')"></bh-clear>

<input type="text" class="form-control" name="text" ng-model="ModalCtrl.params.text">
<div class="help-block" ng-messages="ModalForm.text.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
Expand Down
5 changes: 3 additions & 2 deletions client/src/modules/invoices/patientInvoice.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ function PatientInvoiceService(Modal, util, Session, Api, Filters) {
{ field: 'reversed', displayName : 'FORM.INFO.CREDIT_NOTE' },
{ field: 'defaultPeriod', displayName : 'TABLE.COLUMNS.PERIOD', ngFilter : 'translate' },
{ field: 'cash_uuid', displayName : 'FORM.INFO.PAYMENT' },
{ field: 'defaultPeriod', displayName : 'TABLE.COLUMNS.PERIOD', ngFilter : 'translate' }
{ field: 'defaultPeriod', displayName : 'TABLE.COLUMNS.PERIOD', ngFilter : 'translate' },
{ field: 'debtor_group_uuid', displayName: 'FORM.LABELS.DEBTOR_GROUP' }
];

// returns columns from filters
Expand All @@ -143,7 +144,7 @@ function PatientInvoiceService(Modal, util, Session, Api, Filters) {
if (angular.isDefined(value)) {
column.value = value;

if (column.field === 'cash_uuid') {
if (column.field === 'cash_uuid' || column.field === 'debtor_group_uuid') {
column.value = column.value.slice(0, LIMIT_UUID_LENGTH).concat('...');
}

Expand Down
30 changes: 24 additions & 6 deletions client/src/modules/invoices/registry/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,34 @@
</div>
</div>

<div class="form-group">
<label class="control-label" translate>
FORM.LABELS.DEBTOR_GROUP
</label>
<bh-clear on-clear="ModalCtrl.clear('debtor_group_uuid')"></bh-clear>

<!-- @todo make data driven selects components to handle loading and error states -->
<ui-select
name="debtor_group_uuid"
ng-model="ModalCtrl.params.debtor_group_uuid">
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.DEBTOR_GROUP' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="group.uuid as group in (ModalCtrl.debtorGroups | filter:$select.search | orderBy:'name') track by group.uuid">
<span ng-bind-html="group.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.service.$invalid }">
<label class="control-label" translate>FORM.LABELS.SERVICE</label>
<bh-clear on-clear="ModalCtrl.clear('service_id')"></bh-clear>
<select
class="form-control"
<ui-select
name="service"
ng-model="ModalCtrl.params.service_id"
ng-options="s.id as s.name for s in ModalCtrl.services | orderBy:'name'">
<option value="" disabled translate>FORM.SELECT.SERVICE</option>
</select>
ng-model="ModalCtrl.params.service_id">
<ui-select-match placeholder="{{ 'FORM.SELECT.SERVICE' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="s.id as s in (ModalCtrl.services | filter:$select.search | orderBy:'name') track by s.id">
<span ng-bind-html="s.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<bh-user-select
Expand Down
9 changes: 7 additions & 2 deletions client/src/modules/invoices/registry/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('bhima.controllers')

InvoiceRegistrySearchModalController.$inject = [
'$uibModalInstance', 'ServiceService', 'filters',
'NotifyService', 'moment', 'bhConstants'
'NotifyService', 'moment', 'bhConstants', 'DebtorGroupService'
];

/**
Expand All @@ -14,7 +14,7 @@ InvoiceRegistrySearchModalController.$inject = [
* returning it as a JSON object to the parent controller. The data can be
* preset by passing in a filters object using filtersProvider().
*/
function InvoiceRegistrySearchModalController(ModalInstance, Services, filters, Notify, moment, bhConstants) {
function InvoiceRegistrySearchModalController(ModalInstance, Services, filters, Notify, moment, bhConstants, DebtorGroups) {
var vm = this;

// set controller data
Expand All @@ -41,6 +41,11 @@ function InvoiceRegistrySearchModalController(ModalInstance, Services, filters,

}

DebtorGroups.read()
.then(function (result) {
vm.debtorGroups = result;
});

// custom filter user_id - assign the value to the params object
vm.onSelectUser = function onSelectUser(user) {
vm.params.user_id = user.id;
Expand Down
70 changes: 21 additions & 49 deletions client/src/modules/patients/registry/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@
<label class="control-label">
{{ 'FORM.LABELS.NAME' | translate }}
</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('display_name')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('display_name')"></bh-clear>

<input type="text" class="form-control" name="display_name" ng-model="ModalCtrl.params.display_name">
<div class="help-block" ng-messages="ModalForm.display_name.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
Expand All @@ -50,11 +47,8 @@
<label class="control-label">
{{ 'FORM.LABELS.REFERENCE' | translate }}
</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('reference')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('reference')"></bh-clear>

<input type="text" class="form-control" name="reference" ng-model="ModalCtrl.params.reference">
<div class="help-block" ng-messages="ModalForm.reference.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
Expand All @@ -65,11 +59,8 @@
<label class="control-label" translate>
FORM.LABELS.HOSPITAL_FILE_NR
</label>
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('hospital_no')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('hospital_no')"></bh-clear>

<input type="text" class="form-control" name="hospital_no" ng-model="ModalCtrl.params.hospital_no">
<div class="help-block" ng-messages="ModalForm.reference.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
Expand All @@ -79,12 +70,7 @@
<div class="radio">
<p class="control-label">
<strong translate>FORM.LABELS.GENDER</strong>

<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('sex')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('sex')"></bh-clear>
</p>

<label>
Expand All @@ -105,49 +91,35 @@
FORM.LABELS.DEBTOR_GROUP
</label>

<!-- @todo make this a component - it is used everywhere. Calls back method
`clear` and resets the id passed to the component -->
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('debtor_group_uuid')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('debtor_group_uuid')"></bh-clear>

<!-- @todo make data driven selects components to handle loading and error states -->
<select
class="form-control"
<ui-select
name="debtorGroup"
ng-options="group.uuid as group.name for group in ModalCtrl.debtorGroups"
ng-model="ModalCtrl.params.debtor_group_uuid">
<option disabled value="" translate>
FORM.PLACEHOLDERS.DEBTOR_GROUP
</option>
</select>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.DEBTOR_GROUP' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="group.uuid as group in (ModalCtrl.debtorGroups | filter:$select.search | orderBy:'name') track by group.uuid">
<span ng-bind-html="group.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<div class="form-group">
<label class="control-label" translate>
PATIENT_GROUP.PATIENT_GROUP
</label>

<!-- @todo make this a component - it is used everywhere. Calls back method
`clear` and resets the id passed to the component -->
<span style="display:inline-block;" class="pull-right">
<a href ng-click="ModalCtrl.clear('patient_group_uuid')" tabindex="-1">
<i class="fa fa-eraser"></i> <span translate>FORM.BUTTONS.CLEAR</span>
</a>
</span>
<bh-clear on-clear="ModalCtrl.clear('patient_group_uuid')"></bh-clear>

<!-- @todo make data driven selects components to handle loading and error states -->
<select
class="form-control"
<ui-select
name="patientGroup"
ng-options="group.uuid as group.name for group in ModalCtrl.patientGroups"
ng-model="ModalCtrl.params.patient_group_uuid">
<option disabled value="" translate>
FORM.PLACEHOLDERS.PATIENT_GROUP
</option>
</select>
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.PATIENT_GROUP' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="group.uuid as group in (ModalCtrl.patientGroups | filter:$select.search | orderBy:'name') track by group.uuid">
<span ng-bind-html="group.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>
</div>

<bh-user-select
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/finance/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function read(req, res, next) {
*/
function listPayment(options) {
// ensure epected options are parsed appropriately as binary
db.convert(options, ['debtor_uuid']);
db.convert(options, ['debtor_uuid', 'debtor_group_uuid']);
const filters = new FilterParser(options, { tableAlias : 'cash', autoParseStatements : false });

const sql = `
Expand Down Expand Up @@ -165,6 +165,7 @@ function listPayment(options) {
filters.equals('debtor_uuid');
filters.equals('currency_id');
filters.equals('reversed');
filters.equals('debtor_group_uuid', 'group_uuid', 'd');

const referenceStatement = `CONCAT_WS('.', '${identifiers.CASH_PAYMENT.key}', project.abbr, cash.reference) = ?`;
filters.custom('reference', referenceStatement);
Expand Down
4 changes: 3 additions & 1 deletion server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function create(req, res, next) {

function find(options) {
// ensure expected options are parsed as binary
db.convert(options, ['patientUuid']);
db.convert(options, ['patientUuid', 'debtor_group_uuid']);

const filters = new FilterParser(options, { tableAlias : 'invoice' });

Expand All @@ -209,6 +209,7 @@ function find(options) {
service.name as serviceName, user.display_name, invoice.user_id, invoice.reversed
FROM invoice
LEFT JOIN patient ON invoice.debtor_uuid = patient.debtor_uuid
JOIN debtor AS d ON invoice.debtor_uuid = d.uuid
JOIN service ON service.id = invoice.service_id
JOIN user ON user.id = invoice.user_id
JOIN project ON project.id = invoice.project_id
Expand All @@ -217,6 +218,7 @@ function find(options) {
filters.equals('patientUuid', 'uuid', 'patient');
filters.dateFrom('billingDateFrom', 'date');
filters.dateTo('billingDateTo', 'date');
filters.equals('debtor_group_uuid', 'group_uuid', 'd');

filters.custom(
'cash_uuid',
Expand Down
7 changes: 7 additions & 0 deletions test/end-to-end/cash/registry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function CashPaymentsRegistryTests() {
modal.submit();
GU.expectRowCount('payment-registry', 0);
});

it('finds two payments in the primary cashbox', () => {
modal.setPaymentReference('Test Primary Cashbox A');
modal.submit();
Expand All @@ -70,6 +71,12 @@ function CashPaymentsRegistryTests() {
GU.expectRowCount('payment-registry', PAYMENT_INSIDE_REGISTRY);
});

it('finds all payments for creditor group Second Test Debtor Group', () => {
modal.setDebtorGroup('Second Test Debtor Group');
modal.submit();
GU.expectRowCount('payment-registry', PAYMENT_INSIDE_REGISTRY);
});

it('finds no payments for the disallowed user', () => {
modal.setUser('Regular User');
modal.submit();
Expand Down
4 changes: 4 additions & 0 deletions test/end-to-end/cash/search.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class SearchModal {
bhPeriodSelect.select(period);
}

setDebtorGroup(debtorGroup) {
FU.uiSelect('$ctrl.searchQueries.debtor_group_uuid', debtorGroup, this.element);
}

setCustomPeriod(start, end) {
bhPeriodSelect.custom(start, end);
}
Expand Down
Loading

0 comments on commit d2ac8ae

Please sign in to comment.