diff --git a/client/src/partials/patients/record/units/checkin.html b/client/src/partials/patients/record/units/checkin.html index 0f7d208510..c75678bbb7 100644 --- a/client/src/partials/patients/record/units/checkin.html +++ b/client/src/partials/patients/record/units/checkin.html @@ -5,7 +5,7 @@ diff --git a/server/controllers/medical/patients/checkin.js b/server/controllers/medical/patients/checkin.js index 943f808374..5840223dfc 100644 --- a/server/controllers/medical/patients/checkin.js +++ b/server/controllers/medical/patients/checkin.js @@ -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]) diff --git a/server/controllers/medical/reports/checkins.js b/server/controllers/medical/reports/checkins.js index 349c185fa9..368a1dcff4 100644 --- a/server/controllers/medical/reports/checkins.js +++ b/server/controllers/medical/reports/checkins.js @@ -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 @@ -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(); diff --git a/test/integration/reports/medical/checkins.js b/test/integration/reports/medical/checkins.js new file mode 100644 index 0000000000..b57fcb0f57 --- /dev/null +++ b/test/integration/reports/medical/checkins.js @@ -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));