Skip to content

Commit

Permalink
fix(checkins): fix patient checkin report
Browse files Browse the repository at this point in the history
This commit updates the patient checkin report to the latest report
standard.  It adds integration tests for the patient checkin report
route.

Closes #770.
  • Loading branch information
Jonathan Niles committed Oct 11, 2016
1 parent cf3c414 commit cfda425
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 46 deletions.
2 changes: 1 addition & 1 deletion client/src/partials/patients/record/units/checkin.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<span class="pull-right">
<bh-pdf-link
pdf-url="reports/patients/{{ CheckInCtrl.id }}/checkins"
pdf-url="reports/medical/patients/{{ CheckInCtrl.id }}/checkins"
disable-cache="true"
>
</bh-pdf-link>
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/medical/patients/checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function create(req, res, next) {
INSERT INTO patient_visit
(uuid, patient_uuid, start_date, user_id)
VALUES
(?, ?, CURRENT_TIMESTAMP, ?)
(?, ?, CURRENT_TIMESTAMP, ?);
`;

db.exec(checkinQuery, [db.bid(uuid.v4()), db.bid(patientUuid), req.session.user.id])
Expand Down
61 changes: 17 additions & 44 deletions server/controllers/medical/reports/checkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,24 @@
* This file contains code to create a PDF report of all patient checkins,
* matching query conditions passed from the patient registry UI grid.
*
* @requires path
* @requires lodash
* @requires BadRequest
* @requires db
* @requires renderers/json
* @requires renderers/html
* @requires renderers/pdf
* @requires lib/db
* @requires lib/ReportManager
* @requires Patients
* @requires Locations
*/
'use strict';

const path = require('path');
const _ = require('lodash');

const BadRequest = require('../../../lib/errors/BadRequest');
const db = require('../../../lib/db');
const ReportManager = require('../../../lib/ReportManager');

const Patients = require('../patients');
const Locations = require('../../admin/locations');

// group supported renderers
const renderers = {
'json': require('../../../lib/renderers/json'),
'html': require('../../../lib/renderers/html'),
'pdf': require('../../../lib/renderers/pdf'),
};

// default rendering parameters
const defaults = {
pageSize: 'A4',
renderer: 'pdf'
};
const Patients = require('../patients');

// path to the template to render
const template = path.normalize('./server/controllers/medical/reports/checkins.handlebars');
const TEMPLATE = './server/controllers/medical/reports/checkins.handlebars';

/**
* @function getReportData
Expand Down Expand Up @@ -104,32 +88,21 @@ function getReportData(uuid) {
* GET /reports/patients/:uuid/checkins
*/
function build(req, res, next) {
const qs = req.query;

// choose the renderer
const renderer = renderers[qs.renderer || defaults.renderer];
if (_.isUndefined(renderer)) {
return next(new BadRequest(`The application does not support rendering ${qs.renderer}.`));
}
const options = req.query;

// delete from the query string
delete qs.renderer;
let report;

// create the correct context by setting the language and inheriting defaults
const context = { lang : qs.lang };
_.defaults(context, defaults);
try {
report = new ReportManager(TEMPLATE, req.session, options);
} catch (e) {
return next(e);
}

// gather data and template into report
getReportData(req.params.uuid)
.then(data => {

// attach session information as metadata
data.metadata.user = req.session.user;
data.metadata.enterprise = req.session.enterprise;
return data;
})
.then(data => renderer.render(data, template, context))
.then(data => report.render(data))
.then(result => {
res.set(renderer.headers).send(result);
res.set(result.headers).send(result.report);
})
.catch(next)
.done();
Expand Down
5 changes: 5 additions & 0 deletions test/integration/reports/medical/checkins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const RenderingTests = require('../rendering');
const patientUuid = '274c51ae-efcc-4238-98c6-f402bfb39866';
const target = `/reports/medical/patients/${patientUuid}/checkins`;

describe(`(${target}) Patient Checkin Report`, RenderingTests(target));

0 comments on commit cfda425

Please sign in to comment.