Skip to content

Commit

Permalink
feat(patient registrations): implement pdf report
Browse files Browse the repository at this point in the history
This commit refactors the server side to complete the PDF report
implementation.  Some notable improvements:
 1. Automatically template in the filters. This should be improved with
 varied colorschemes (IMA colors, for example).
 2. Adds `timestamp` helper to handlebars for more detailed time
 templates.
 3. Adds initial bare-bones clients structure for PDF printing modal.
  • Loading branch information
jniles committed Jun 13, 2016
1 parent 992f832 commit cc595a4
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 93 deletions.
2 changes: 1 addition & 1 deletion client/src/js/components/bhFiltersApplied.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ angular.module('bhima.components')
bindings: {
filters: '='
}
});
});
6 changes: 3 additions & 3 deletions client/src/js/services/receipts/ReceiptModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function ReceiptModal(Modal, Receipts) {
// expose available receipts
service.invoice = invoice;
service.patient = patient;

/**
* Invokes a patient invoice receipt
*
*
* @param {String} uuid Target invoice UUID
* @param {Boolean} notifyCreated Defines if a success message should be shown for entity creation
*/
Expand All @@ -56,7 +56,7 @@ function ReceiptModal(Modal, Receipts) {
var instance = Modal.open(configuration);
return instance.result;
}

function patient(uuid, notifyCreated) {

var options = {
Expand Down
14 changes: 7 additions & 7 deletions client/src/js/services/receipts/ReceiptService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ function ReceiptService($http, util) {
HTML : 'html',
JSON : 'json'
};

service.invoice = invoice;
service.patient = patient;
service.renderers = renderers;

/**
* Fetch invoice report data from /reports/invoices/:uuid
*
Expand All @@ -41,16 +41,16 @@ function ReceiptService($http, util) {
return $http.get(route, {params: options, responseType: responseType})
.then(util.unwrapHttpResponse);
}

function patient(uuid, options) {
var route ='/reports/patient/'.concat(uuid);
var responseType = null;
if (options.render === renderers.PDF) {

if (options.render === renderers.PDF) {
responseType = 'arraybuffer';
}

return $http.get(route, {params : options, responseType : responseType})
.then(util.unwrapHttpResponse);
.then(util.unwrapHttpResponse);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
angular.module('bhima.controllers')
.controller('ReceiptModalController', ReceiptModalController);

ReceiptModalController.$inject = ['$uibModalInstance', '$window', '$sce', 'ReceiptService', 'NotifyService', 'receipt', 'options'];
ReceiptModalController.$inject = [
'$uibModalInstance', '$window', '$sce', 'ReceiptService', 'NotifyService', 'receipt', 'options'
];

/**
* Receipt Modal Controller
Expand Down
43 changes: 19 additions & 24 deletions client/src/partials/patients/registry/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>

<div class="modal-body" style="overflow: auto; max-height: 300px;">
<legend>{{ "FORM.LABELS.DATE_REGISTRATION" | translate }}</legend>
<legend>{{ "FORM.LABELS.DATE_REGISTRATION" | translate }}</legend>
<fieldset>
<div class="row text-center">
<div class="btn-group">
Expand All @@ -27,10 +27,10 @@
</div>
</div>
<hr>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.dateFrom.$invalid }">
<div class="col-md-9">
<div class="input-group">
<div class="input-group">
<bh-date-editor
id = "date-registration-from"
date-value="ModalCtrl.patient.dateRegistrationFrom"
Expand All @@ -41,8 +41,8 @@
</div>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.dateTo.$invalid }">

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.dateTo.$invalid }">
<div class="col-md-9">
<div class="input-group">
<bh-date-editor
Expand All @@ -53,9 +53,9 @@
>
</bh-date-editor>
</div>
</div>
</div>
<br>
</div>
</div>
<br>
</fieldset>

<legend>{{ "FORM.LABELS.PATIENT_DETAILS" | translate }}</legend>
Expand All @@ -65,34 +65,29 @@
<input type="text" class="form-control" name="name" id="name" ng-model="ModalCtrl.patient.name">
<div class="help-block" ng-messages="ModalForm.name.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.reference.$invalid }">
<label class="control-label" for="reference">{{ 'FORM.LABELS.REFERENCE' | translate }}</label>
<input type="text" class="form-control" name="reference" id="reference" ng-model="ModalCtrl.patient.reference">
<div class="help-block" ng-messages="ModalForm.reference.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.hospital_no.$invalid }">
<label class="control-label" for="reference">{{ 'FORM.LABELS.HOSPITAL_FILE_NR' | translate }}</label>
<input type="text" class="form-control" name="hospital_no" id="hospital_no" ng-model="ModalCtrl.patient.fields.hospital_no">
<div class="help-block" ng-messages="ModalForm.reference.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

<div id="gender" class="form-group has-feedback"
ng-class="{'has-error' : ModalForm.genderOptions.$invalid && ModalForm.$submitted}">
<label for="male" class="col-md-3 control-label"> {{ "FORM.LABELS.GENDER" | translate }} </label>
<div class="col-md-9">
<label class="radio-inline">
<input type="radio" name="genderOptions" id="all" value="all" ng-model="ModalCtrl.patient.sex">
{{ "FORM.LABELS.ALL_GENDER" | translate }}
</label>

<label class="radio-inline">
<input type="radio" name="genderOptions" id="male" value="M" ng-model="ModalCtrl.patient.sex">
{{ "FORM.LABELS.MALE" | translate }}
Expand All @@ -107,10 +102,10 @@
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
</div>
</div>
</fieldset>

<legend>{{ "FORM.LABELS.DOB" | translate }}</legend>
<legend>{{ "FORM.LABELS.DOB" | translate }}</legend>
<fieldset>

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.dateFrom.$invalid }">
Expand All @@ -126,8 +121,8 @@
</div>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.dateTo.$invalid }">

<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.dateTo.$invalid }">
<div class="col-md-9">
<div class="input-group">
<bh-date-editor
Expand All @@ -138,12 +133,12 @@
>
</bh-date-editor>
</div>
</div>
</div>
<br>
</div>
</div>
<br>
</fieldset>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="ModalCtrl.cancel()">{{ "FORM.BUTTONS.CLOSE" | translate }}</button>
<button class="btn btn-default" id="patient_search" type="submit" data-method="submit">
Expand Down
12 changes: 10 additions & 2 deletions client/src/partials/patients/registry/registry.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
<button
ng-click="PatientRegistryCtrl.search()"
data-method="search"
class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-search"></span> {{ "FORM.BUTTONS.SEARCH" | translate }}
class="btn btn-default">
<span class="fa fa-search"></span> {{ "FORM.BUTTONS.SEARCH" | translate }}
</button>
</div>
<div class="toolbar-item">
<button
ng-click="PatientRegistryCtrl.print()"
data-method="print"
class="btn btn-default">
<span class="fa fa-print"></span> {{ "FORM.BUTTONS.PRINT" | translate }}
</button>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions client/src/partials/patients/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ PatientRegistryController.$inject = [
*
* This module is responsible for the management of Patient Registry.
*/
function PatientRegistryController(Patients, Notify, moment) {
function PatientRegistryController(Patients, Notify, moment, Modals) {
var vm = this;

var patientActionsTemplate =
'<div style="padding : 5px"><a ui-sref="patientRecord.details({patientID : row.entity.uuid})"><span class="glyphicon glyphicon-list-alt"></span> {{ "PATIENT_REGISTRY.RECORD" | translate }}</a> <a ui-sref="patientEdit({uuid : row.entity.uuid})"><span class="glyphicon glyphicon-edit"></span> {{ "TABLE.COLUMNS.EDIT" | translate }}</a></div>';

vm.search = search;
vm.momentAge = momentAge;
vm.print = print;

// track if module is making a HTTP request for patients
vm.loading = false;

/** TODO manage column : last_transaction */
// the column attribute `displayName` must be used in favour of `name` in order to allow `headerCellFilter` to function
vm.uiGridOptions = {
appScopeProvider : vm,
enableColumnMenus : false,
Expand Down Expand Up @@ -84,6 +84,10 @@ function PatientRegistryController(Patients, Notify, moment) {
});
}

function print() {
//Modals.
}

// moment() provides the current date, similar to the new Date() API. This requests the difference between two dates
function momentAge(dateOfBirth){
return moment().diff(dateOfBirth, 'years');
Expand Down
18 changes: 9 additions & 9 deletions client/src/partials/templates/bhFiltersApplied.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div ng-if="!$ctrl.filters">
<span style="color: rgb(150, 150, 150);" class="glyphicon glyphicon-filter"></span> {{ "FORM.INFOS.NO_FILTERS_APPLIED" | translate }}
<div ng-hide="$ctrl.filters">
<span class="text-muted fa fa-filter"></span> {{ "FORM.INFOS.NO_FILTERS_APPLIED" | translate }}
</div>

<div ng-if="$ctrl.filters">
<span style="color: rgb(7, 150, 35);" class="glyphicon glyphicon-filter"></span>
<span class="text-primary fa fa-filter"></span>
<span ng-repeat="f in $ctrl.filters">
<span class="label label-primary">
({{ f.title | translate }})
<strong ng-if="!f.reference2"> {{ f.reference1 }} </strong>
<strong ng-if="f.reference2"> {{ f.reference1 | date }} - {{ f.reference2 | date }} </strong>
</span>&nbsp;
<span class="label label-primary">
({{ f.title | translate }})
<strong ng-hide="f.reference2"> {{ f.reference1 }} </strong>
<strong ng-show="f.reference2"> {{ f.reference1 | date }} - {{ f.reference2 | date }} </strong>
</span>
&nbsp;
</span>
</div>

11 changes: 6 additions & 5 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const users = require('../controllers/admin/users');
var locations = require('../controllers/locations');
var tree = require('../controllers/tree');
var patients = require('../controllers/medical/patients');
var patientReceipt = require('../controllers/medical/reports/patient.receipt');
var patientGroups = require('../controllers/medical/patientGroups');
var snis = require('../controllers/medical/snis');
var projects = require('../controllers/admin/projects');
Expand Down Expand Up @@ -68,6 +67,7 @@ var sectionBilans = require('../controllers/finance/sectionBilan');
var creditors = require('../controllers/finance/creditors.js');
const system = require('../controllers/system');
const languages = require('../controllers/admin/languages');
const medicalReports = require('../controllers/medical/reports');

const upload = require('../lib/uploader');

Expand Down Expand Up @@ -134,7 +134,7 @@ exports.configure = function configure(app) {
app.put('/accounts/:id', accounts.update);


// API for cost_center routes crud
// API for cost_center routes CRUD
app.get('/cost_centers', costCenter.list);
app.get('/cost_centers/:id', costCenter.detail);
app.get('/cost_centers/:id/cost', costCenter.getCostValue);
Expand Down Expand Up @@ -258,7 +258,7 @@ exports.configure = function configure(app) {

app.post('/posting_donation/', donations.post);

/* Inventory and Stock Managment */
/* Inventory and Stock Management */
app.post('/inventory/metadata', inventory.createInventoryItems);
app.get('/inventory/metadata', inventory.getInventoryItems);
app.get('/inventory/:uuid/metadata', inventory.getInventoryItemsById);
Expand Down Expand Up @@ -356,9 +356,10 @@ exports.configure = function configure(app) {
app.get('/invoices/:uuid', patientInvoice.details);
app.get('/invoices/references/:reference', patientInvoice.reference);

// Reports API: Invoices (receipts)
// reports API: Invoices (receipts)
app.get('/reports/invoices/:uuid', invoiceReceipt.build);
app.get('/reports/patient/:uuid', patientReceipt.build);
app.get('/reports/patient/registrations', medicalReports.patientRegistrations);
app.get('/reports/patient/:uuid', medicalReports.patientReceipt);

// patient group routes
app.get('/patients/groups', patientGroups.list);
Expand Down
9 changes: 8 additions & 1 deletion server/controllers/medical/patients/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function find(options) {
// if the find should included detailed results
if (options.detailed) {
detailedColumns = `
, q.abbr, q.father_name, q.mother_name, q.profession, q.employer,
, q.abbr, q.father_name, q.mother_name, q.profession, q.employer, q.hospital_no,
q.spouse, q.spouse_profession, q.spouse_employer, q.religion, q.marital_status,
q.phone, q.email, q.address_1, q.address_2, q.renewal, BUID(q.origin_location_id) as origin_location_id,
BUID(q.current_location_id) as current_location_id, q.registration_date, q.title, q.notes, q.hospital_no,
Expand Down Expand Up @@ -442,6 +442,13 @@ function find(options) {
parameters.push(limit);
}

// if nothing was submitted to the search, get all records
if (!parameters.length) {

// this writes in WHERE 1; to the SQL query
sql += ' 1;';
}

return db.exec(sql, parameters);
}

Expand Down
14 changes: 14 additions & 0 deletions server/controllers/medical/reports/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @overview medical/reports
*
* @description
* This module simply exposes the build() methods of the receipts and reports
* in the medical module.
*/


// expose to the express router
module.exports = {
patientReceipt: require('./patient.receipt').build,
patientRegistrations : require('./registrations')
};
Loading

0 comments on commit cc595a4

Please sign in to comment.