Skip to content

Commit

Permalink
fix(patient): ensure patient card is rendered
Browse files Browse the repository at this point in the history
This commit fixes a bug that was not rendering the patient card.  The
card creation and handlebars code has been cleaned up a bit.  The
loading indicator on the patient registration form is fixed (broken form
reference). Finally, some missing translation keys are added to the i18n
files.
  • Loading branch information
Jonathan Niles committed Aug 25, 2016
1 parent 9ac3716 commit a259917
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 66 deletions.
4 changes: 3 additions & 1 deletion client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,9 @@
},
"PATIENT_REG": {
"PAGE_TITLE" : "Patient Registration",
"PATIENT_DETAILS" : "Patient Details"
"PATIENT_DETAILS" : "Patient Details",
"SUCCESS" : "Patient Registered Successfully",
"CARD" : "Patient Card"
},
"PATIENT_REGISTRY" : {
"DAY" : "day",
Expand Down
4 changes: 2 additions & 2 deletions client/src/partials/patients/registration/registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
ng-class="{'has-error' : DetailForm.firstName.$invalid && PatientRegistrationForm.$submitted}">
<label class="col-md-3 control-label">{{ "FORM.LABELS.FIRST_NAME" | translate }}</label>
<div class="col-md-9">
<input class="form-control" name="firstName" ng-model="PatientRegCtrl.medical.first_name">
<input class="form-control" name="firstName" ng-model="PatientRegCtrl.medical.first_name" required>
<div class="help-block" ng-messages="DetailForm.firstName.$error" ng-show="PatientRegistrationForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
Expand Down Expand Up @@ -225,7 +225,7 @@ <h4>{{ "FORM.LABELS.CURRENT_LOCATION" | translate }}</h4>
</div>

<div class="panel-footer text-right">
<bh-loading-button loading-state="DetailForm.$loading">
<bh-loading-button loading-state="PatientRegistrationForm.$loading">
{{ "FORM.BUTTONS.REGISTER_PATIENT" | translate }}
</bh-loading-button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/patients/registry/registry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('bhima.controllers')
.controller('PatientRegistryController', PatientRegistryController);
.controller('PatientRegistryController', PatientRegistryController);

PatientRegistryController.$inject = [
'PatientService', 'NotifyService', 'moment', 'AppCache', 'util'
Expand Down
3 changes: 0 additions & 3 deletions server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ exports.reference = reference;
/** Expose lookup invoice for other controllers to use internally */
exports.lookupInvoice = lookupInvoice;

/** Undo the financial effects of a invoice generating an equal and opposite credit note. */
// exports.reverse = reverse;

/**
* list
*
Expand Down
39 changes: 8 additions & 31 deletions server/controllers/medical/reports/patient.receipt.handlebars
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
<head>
<title>{{patient.first_name}} {{patient.middle_name}} {{patient.last_name}}</title>
<link href="{{absolutePath}}/vendor/components-font-awesome/css/font-awesome.css" rel="stylesheet"/>
<link href="{{absolutePath}}/css/style.min.css" rel="stylesheet"/>
<link href="{{absolutePath}}/css/bhima-bootstrap.css" rel="stylesheet"/>
</head>
{{> head title="PATIENT_REG.CARD" }}

<div class="container">
<body class="container">
<div class="row">
<div class="col-xs-8">
<h2>
<strong> {{patient.first_name}} {{patient.middle_name}} {{patient.last_name}} </strong>
<strong>{{patient.first_name}} {{patient.middle_name}} {{patient.last_name}}</strong>
</h2>
</div>
<div class="col-xs-4" style="text-align:right;">
<h2>
<strong> {{patient.reference}} </strong>
<strong>{{patient.reference}}</strong>
</h2>
</div>
</div>

<div class="row">
<div class="col-xs-12">
<h4> <strong> {{patient.enterprise_name}} </strong> </h4>
</div>
</div>

<div class="row">
<div class="col-xs-12">
<h4> <strong> {{translate "TABLE.COLUMNS.REGISTERED_ON"}} {{date patient.registration_date }} </strong> </h4>
</div>
</div>

<div class="row">
<div class="col-xs-7">
<h4> <strong> <i class="fa fa-{{patient.symbol}}"></i> {{date patient.dob }} </strong> </h4>
</div>
<div class="col-xs-5">

</div>
</div>

</div>
<h4>{{patient.enterprise_name}}</h4>
<h4>{{translate "TABLE.COLUMNS.REGISTERED_ON"}} {{date patient.registration_date }}</h4>
<h4><i class="fa fa-{{patient.symbol}}"></i> {{date patient.dob }}</h4>
</body>
74 changes: 46 additions & 28 deletions server/controllers/medical/reports/patient.receipt.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,65 @@
var Patients = require ('../patients');
var path = require('path');
var _ = require('lodash');
/**
* @module reports/patient.receipt
*
* @description
* This module provides rendering for the patient receipt: a patient card.
* A new patient card is automatically generated when the patient is registered
* at the Patient Registration module. Additionally, copies can be printed from
* the Patient Record page.
*
* @requires Patients
* @requires path
* @requires lodash
* @requires lib/errors/BadRequest
*/

var BadRequest = require('../../../lib/errors/BadRequest');
const Patients = require ('../patients');
const path = require('path');
const _ = require('lodash');

var supportedRender = {};
supportedRender.json = require('../../../lib/renderers/json');
supportedRender.html = require('../../../lib/renderers/html');
supportedRender.pdf = require('../../../lib/renderers/pdf');
const BadRequest = require('../../../lib/errors/BadRequest');

var defaultRender = 'json';

var template = path.normalize('./server/controllers/medical/reports/patient.receipt.handlebars');
// group supported renderers
const renderers = {
'json': require('../../../lib/renderers/json'),
'html': require('../../../lib/renderers/html'),
'pdf': require('../../../lib/renderers/pdf'),
};

/* @todo these can be overridden given the clients request if required */
var receiptOptions = {
pageSize : 'A6',
orientation : 'landscape'
// default rendering parameters
const defaults = {
pageSize: 'A6',
renderer: 'pdf',
orientation: 'landscape',
lang: 'en'
};

const template = path.normalize('./server/controllers/medical/reports/patient.receipt.handlebars');

exports.build = build;

function build(req, res, next) {
const qs = req.query;


var queryString = req.query;
var patientID = req.params.uuid;

var renderTarget = queryString.renderer || defaultRender;
var renderer = supportedRender[renderTarget];

// choose the renderer
const renderer = renderers[qs.renderer || defaults.renderer];
if (_.isUndefined(renderer)) {
throw new BadRequest('Render target provided is invalid or not supported by this report '.concat(renderTarget));
return next(new BadRequest(`The application does not support rendering ${qs.renderer}.`));
}

Patients.lookupPatient(patientID)
// delete from the query string
delete qs.renderer;

const context = { lang : qs.lang };
_.defaults(context, defaults);

Patients.lookupPatient(req.params.uuid)
.then(function (patient) {
patient.enterprise_name = req.session.enterprise.name;
patient.symbol = patient.sex === 'M' ? 'mars' : 'venus';

return renderer.render({ patient }, template, receiptOptions);
patient.symbol = (patient.sex === 'M') ? 'mars' : 'venus';
return renderer.render({ patient }, template, context);
})
.then(function (result) {
.then(function (result) {
res.set(renderer.headers).send(result);
})
.catch(next)
Expand Down

0 comments on commit a259917

Please sign in to comment.