Skip to content

Commit

Permalink
fix(patients): fix broken PatientService API
Browse files Browse the repository at this point in the history
This commit fixes the broken patient service API introduced in the last
PR. The PatientService behaves uniformly as all other services do, with
a `read(uuid)` method for reading one or more patients from the
database.
  • Loading branch information
Jonathan Niles committed May 4, 2016
1 parent 33e8148 commit e2deaa2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
84 changes: 42 additions & 42 deletions client/src/js/services/PatientService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ PatientService.$inject = [ '$http', 'util', 'SessionService' ];

/**
* Patient Service
*
* This service is reponsible for providing an interface between angular
* module controllers and the server /patients API.
*
* This service is reponsible for providing an interface between angular
* module controllers and the server /patients API.
*
* @example
* Controller.$inject = ['PatientService'];
*
*
* var Patients = PatientService;
*
*
* // returns patient details
* Patients.list(uuid)...
* Patients.read(uuid)...
*
* // creates a patient
* // creates a patient
* Patients.create(medicalDetails, financeDetails)...
*
* @module services/PatientService
Expand All @@ -26,46 +26,46 @@ function PatientService($http, util, Session) {
var service = this;
var baseUrl = '/patients/';

service.list = list;
service.read = read;
service.create = create;
service.update = update;
service.groups = groups;
service.updateGroups = updateGroups;
service.logVisit = logVisit;

service.billingServices = billingServices;
service.subsidies = subsidies;

/** uses the "search" endpoint to pass query strings to the database */
service.search = search;
/**
* This method returns information on a patient given the patients UUID. This
* route provides almost all of the patients attributes.

/**
* This method returns information on a patient given the patients UUID. This
* route provides almost all of the patients attributes.
*
* @param {String} uuid The patient's UUID
* @param {String|Null} uuid The patient's UUID (could be null)
* @return {Object} Promise object that will return patient details
*/
function list(uuid) {
function read(uuid) {
return $http.get(baseUrl.concat(uuid || ''))
.then(util.unwrapHttpResponse);
}

/**
* This method accepts infromation recorded by a controllers form, formats it
* for submission and forwards it to the server /patients/create API. It can
* This method accepts infromation recorded by a controllers form, formats it
* for submission and forwards it to the server /patients/create API. It can
* be used for creating new patient records in the database.
*
* @params {Object} medical A patients medical information.
* @params {Object} finance A patients financial information.
* @returns {Object} Promise object returning success/failure confirmation.
* @params {Object} finance A patients financial information.
* @returns {Object} Promise object returning success/failure confirmation.
*/
function create(medical, finance) {
var formatPatientRequest = {
var formatPatientRequest = {
medical : medical,
finance : finance
};

// Assign implicit information
formatPatientRequest.medical.project_id = Session.project.id;

Expand All @@ -77,13 +77,13 @@ function PatientService($http, util, Session) {
return $http.put(baseUrl.concat(uuid), definition)
.then(util.unwrapHttpResponse);
}

/**
* This method is responsible for fetching patient groups. If a patient UUID
* is provided the method will only get the groups for that patient. If no
* This method is responsible for fetching patient groups. If a patient UUID
* is provided the method will only get the groups for that patient. If no
* value is passed it will request all of the patient groups.
*
* @param {String} patientUuid The patient's UUID - used to subselect groups
* @param {String} patientUuid The patient's UUID - used to subselect groups
* @return {Object} Promise object that will return the groups requested
*/
function groups(patientUuid) {
Expand All @@ -101,16 +101,16 @@ function PatientService($http, util, Session) {
return $http.get(path)
.then(util.unwrapHttpResponse);
}

/**
* Responsible for assigning groups to a patient entity based on the groups
* provided. Note: This process will clear all previous groups and leave the
* patient subscribed to only the groups passed to this method.
* Responsible for assigning groups to a patient entity based on the groups
* provided. Note: This process will clear all previous groups and leave the
* patient subscribed to only the groups passed to this method.
*
* @params {String} uuid The target patient's UUID
* @params {String} uuid The target patient's UUID
* @params {Array} subsribedGroups An array of group UUIDs
* @return {Object} Promise object returning success/ failure
* confiramtion.
* @return {Object} Promise object returning success/ failure
* confiramtion.
*/
function updateGroups(uuid, subscribedGroups) {
var options = formatGroupOptions(subscribedGroups);
Expand All @@ -127,7 +127,7 @@ function PatientService($http, util, Session) {

/**
* Uses query strings to generically search for patients.
*
*
* @method search
*
* @param {object} options - a JSON of options to be parsed by Angular's
Expand All @@ -139,27 +139,27 @@ function PatientService($http, util, Session) {
return $http.get(target, { params : options })
.then(util.unwrapHttpResponse);
}

/**
* Fetches all billing services subslected by a patient entity
*
* @param {String} patientUuid UUID of patient to select billing services for
* @returnl {Object} Promise object returning an array of billing
* services
*/
function billingServices(patientUuid) {
function billingServices(patientUuid) {
var path = patientAttributePath('services', patientUuid);
return $http.get(path)
.then(util.unwrapHttpResponse);
}

/**
* Fetches all subsidies subslected by a patient entity
*
* @param {String} patientUuid UUID of patient to select subsidies for
* @returnl {Object} Promise object returning an array of subsidies
*/
function subsidies(patientUuid) {
function subsidies(patientUuid) {
var path = patientAttributePath('subsidies', patientUuid);
return $http.get(path)
.then(util.unwrapHttpResponse);
Expand All @@ -181,16 +181,16 @@ function PatientService($http, util, Session) {
assignments : formatted
};
}
/**
* Combine and return the patient entity with a service/attribute - returns a

/**
* Combine and return the patient entity with a service/attribute - returns a
* correctly formatted path.
*
* @param {String} path Entity path (e.g 'services')
* @param {String} uuid UUID of patient to format services request
* @return {String} Formatted URL for patient service
*/
function patientAttributePath(path, patientUuid) {
function patientAttributePath(path, patientUuid) {
var root = '/patients/';
return root.concat(patientUuid, '/', path);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/cash/modals/receipt.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function CashReceiptModalController(uuid, patientUuid, ModalInstance, Cash, Proj
Projects.read(receipt.project_id),

// load in the patient details
Patients.detail(patientUuid),
Patients.read(patientUuid),

// ensure the exchange rates are loaded
Exchange.read(),
Expand Down
14 changes: 7 additions & 7 deletions client/src/partials/patient_invoice/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function PatientInvoiceController($q, $location, Patients, PriceLists, PatientIn

// bind the enterprise to the enterprise currency
vm.enterprise = Session.enterprise;

var gridOptions = {
appScopeProvider : vm,
enableSorting : false,
Expand All @@ -50,7 +50,7 @@ function PatientInvoiceController($q, $location, Patients, PriceLists, PatientIn
function setPatient(patient) {
var uuid = patient.uuid;

Patients.detail(uuid)
Patients.read(uuid)
.then(configureInvoice);
}

Expand Down Expand Up @@ -91,15 +91,15 @@ function PatientInvoiceController($q, $location, Patients, PriceLists, PatientIn

function handleCompleteInvoice(invoice) {
vm.Invoice.items.removeCache();

Receipts.invoice(invoice.uuid)
.then(function (result) {
.then(function (result) {

// receipt closed fired
console.log('got closed');
})
.catch(function (error) {
.catch(function (error) {

// receipt closed rejected
});
}
Expand Down
18 changes: 9 additions & 9 deletions client/src/partials/patients/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ PatientRegistryController.$inject = [
'$translate', 'PatientService',
];

/**
* Patient Registry Controller
*
/**
* Patient Registry Controller
*
* This module is responsible for the management
* of Patient Registry.
*
*/
function PatientRegistryController($translate, Patients) {
var vm = this;
// options for the UI grid

/** TODO MANAGE COLUMN : LAST_TRANSACTION */
vm.uiGridOptions = {
appScopeProvider : vm, // ensure that the controller's `this` variable is bound to appScope
Expand All @@ -27,19 +27,19 @@ function PatientRegistryController($translate, Patients) {
{ field : 'sex', name : $translate.instant('TABLE.COLUMNS.GENDER') },
{ field : 'registration_date', cellFilter:'date', name : $translate.instant('TABLE.COLUMNS.DATE_REGISTERED') },
{ field : 'last_visit', cellFilter:'date', name : $translate.instant('TABLE.COLUMNS.LAST_VISIT') },
{ field : '', name : $translate.instant('TABLE.COLUMNS.LAST_TRANSACTION') }
{ field : '', name : $translate.instant('TABLE.COLUMNS.LAST_TRANSACTION') }
],
enableSorting : true
};

// load Patient Registry Grid
function loadGrid() {
Patients.list().then(function (patients) {
Patients.read().then(function (patients) {

patients.forEach(function (patient) {
var patientAge = moment(patient.dob).fromNow();
patient.patientAge = patientAge;
});
patient.patientAge = patientAge;
});
vm.uiGridOptions.data = patients;
});
}
Expand All @@ -51,4 +51,4 @@ function PatientRegistryController($translate, Patients) {

// fire up the module
startup();
}
}

0 comments on commit e2deaa2

Please sign in to comment.