Skip to content

Commit

Permalink
feat(patients): separate search() and find()
Browse files Browse the repository at this point in the history
This commit refactors the patients search functionality in the following
ways:
 1. Expose a programmatic API via `find()` to the query engine.
 2. Make `patients/search/?` use `find()` internally.
 3. Rename `detail` to `detailed`.
 4. Remove `fields` support.  Now any query parameter will be used to
 filter the columns from the database.

This provides a much richer API for searching for patients on both the
client and the server.
  • Loading branch information
jniles committed Jun 13, 2016
1 parent 5ce0586 commit 992f832
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 270 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@
"PATIENT_REG": {
"FIND_PATIENT" : "Find a Patient",
"PAGE_TITLE" : "Patient Registration",
"PATIENT_REGISTRATIONS" : "Patient Registrations",
"PATIENT_DETAILS" : "Patient Details",
"REGISTER_PATIENT" : "Register Patient",
"TITLE" : "Title",
Expand Down
21 changes: 11 additions & 10 deletions client/src/partials/patients/registry/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ PatientRegistryModalController.$inject = [
'$uibModalInstance', 'InventoryService', 'PatientService', 'util', 'DateService'
];

function PatientRegistryModalController( $uibModalInstance, Inventory, patients, util, dateService) {
function PatientRegistryModalController(ModalInstance, Inventory, Patients, util, Dates) {
var vm = this;

vm.period = dateService.period();
vm.period = Dates.period();

// bind methods
vm.submit = submit;
vm.cancel = cancel;
Expand All @@ -23,10 +24,10 @@ function PatientRegistryModalController( $uibModalInstance, Inventory, patients,
vm.patient = util.clean(vm.patient);

var patient = angular.copy(vm.patient);
patient.detail = 1;
patient.detailed = 1;

var promise = patients.search(patient);
var patientFilters = patients.patientFilters(patient);
var promise = Patients.search(patient);
var patientFilters = Patients.patientFilters(patient);

promise
.then(function (response) {
Expand All @@ -35,7 +36,7 @@ function PatientRegistryModalController( $uibModalInstance, Inventory, patients,
filters : patientFilters
};

return $uibModalInstance.close(data);
return ModalInstance.close(data);

});
}
Expand All @@ -49,18 +50,18 @@ function PatientRegistryModalController( $uibModalInstance, Inventory, patients,
vm.patient.dateRegistrationFrom = new Date();
break;
case 'week' :
vm.patient.dateRegistrationFrom = dateService.previous.week();
vm.patient.dateRegistrationFrom = Dates.previous.week();
break;
case 'month' :
vm.patient.dateRegistrationFrom = dateService.previous.month();
vm.patient.dateRegistrationFrom = Dates.previous.month();
break;
default:
vm.patient.dateRegistrationFrom = dateService.previous.year();
vm.patient.dateRegistrationFrom = Dates.previous.year();
}
}

function cancel() {
$uibModalInstance.dismiss();
ModalInstance.dismiss();
}

}
24 changes: 14 additions & 10 deletions client/src/partials/patients/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ angular.module('bhima.controllers')
.controller('PatientRegistryController', PatientRegistryController);

PatientRegistryController.$inject = [
'PatientService', '$uibModal', 'NotifyService', 'moment'
'PatientService', 'NotifyService', 'moment'
];

/**
* Patient Registry Controller
*
* This module is responsible for the management
* of Patient Registry.
*
* This module is responsible for the management of Patient Registry.
*/
function PatientRegistryController(Patients, $uibModal, Notify, moment) {
function PatientRegistryController(Patients, Notify, moment) {
var vm = this;

var patientActionsTemplate =
Expand Down Expand Up @@ -50,8 +48,8 @@ function PatientRegistryController(Patients, $uibModal, Notify, moment) {

// load Patient Registry Grid
function loadGrid() {
vm.loading = true;
vm.hasError = false;
toggleLoadingIndicator();

Patients.read()
.then(function (patients) {
Expand All @@ -62,14 +60,15 @@ function PatientRegistryController(Patients, $uibModal, Notify, moment) {
})
.catch(handler)
.finally(function () {
vm.loading = false;
toggleLoadingIndicator();
});
}

// Search and filter data in Patiens Registry
// search and filter data in Patient Registry
function search() {
vm.loading = true;
vm.hasError = false;
toggleLoadingIndicator();

Patients.openSearchModal()
.then(function (data) {
var response = data.response;
Expand All @@ -81,7 +80,7 @@ function PatientRegistryController(Patients, $uibModal, Notify, moment) {
})
.catch(handler)
.finally(function () {
vm.loading = false;
toggleLoadingIndicator();
});
}

Expand All @@ -90,6 +89,11 @@ function PatientRegistryController(Patients, $uibModal, Notify, moment) {
return moment().diff(dateOfBirth, 'years');
}

// toggles the loading indicator on or off
function toggleLoadingIndicator() {
vm.loading = !vm.loading;
}

// fire up the module
loadGrid();
}
7 changes: 0 additions & 7 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ exports.configure = function configure(app) {
app.get('/patients/:uuid/services', patients.billingServices);
app.get('/patients/:uuid/subsidies', patients.subsidies);

// app.get('/patients/search', patient.search);
app.get('/patients/search/name/:value', patients.searchFuzzy);
app.get('/patients/search/reference/:value', patients.searchReference);

app.get('/patients/:uuid/documents', patients.documents.list);
app.post('/patients/:uuid/documents', upload.middleware('docs', 'documents'), patients.documents.create);
Expand All @@ -411,10 +408,6 @@ exports.configure = function configure(app) {
app.post('/debtor_groups', debtorGroups.create);
app.put('/debtor_groups/:uuid', debtorGroups.update);

// search stuff
// TODO merge with patients API
app.get('/patient/search/fuzzy/:match', patients.searchFuzzy);
app.get('/patient/search/reference/:reference', patients.searchReference);

// analytics for financial dashboard
// cash flow analytics
Expand Down
Loading

0 comments on commit 992f832

Please sign in to comment.