diff --git a/.gitignore b/.gitignore index 21bb07652..b8e2e24cc 100755 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ etl-daemon.js coverage conf/config-bk.json .DS_Store +conf/config-live.json diff --git a/app/reporting-framework/base-mysql.report.js b/app/reporting-framework/base-mysql.report.js index a8b254b3b..759635f91 100755 --- a/app/reporting-framework/base-mysql.report.js +++ b/app/reporting-framework/base-mysql.report.js @@ -552,6 +552,13 @@ import * as tb_screen__less_15_base from './json-reports/moh-731-report/aggregat import * as nutrition_mam_aggregate from './json-reports/moh-731-report/aggregations/nutrition-mam-aggregate.json'; import * as nutrition_mam_base from './json-reports/moh-731-report/aggregations/nutrition-mam-base.json'; import * as patient_list_template_731 from './json-reports/731-patient-list-template.json'; + +//service queue report + +import * as service_queue_daily_aggregate from './json-reports/service-queue-daily-aggregate.json'; +import * as service_queue_daily_base from './json-reports/service-queue-daily-base.json'; +import * as service_queue_patient_list_template from './json-reports/service-queue-patient-list-template.json'; + export class BaseMysqlReport { constructor(reportName, params) { this.reportName = reportName; @@ -2460,6 +2467,19 @@ export class BaseMysqlReport { nutritionMamBase: this.cloneJsonSchema(nutrition_mam_base) }); break; + case 'serviceQueueDailyAggregate': + resolve({ + main: this.cloneJsonSchema(service_queue_daily_aggregate), + serviceQueueDailyBase: this.cloneJsonSchema( + service_queue_daily_base + ) + }); + break; + case 'service-queue-patient-list-template': + resolve({ + main: this.cloneJsonSchema(service_queue_patient_list_template) + }); + break; default: reject('Unknown report ', reportName); break; diff --git a/app/reporting-framework/json-reports/service-queue-daily-aggregate.json b/app/reporting-framework/json-reports/service-queue-daily-aggregate.json new file mode 100644 index 000000000..343116477 --- /dev/null +++ b/app/reporting-framework/json-reports/service-queue-daily-aggregate.json @@ -0,0 +1,53 @@ +{ + "name": "serviceQueueDailyAggregate", + "version": "1.0", + "tag": "service_queue_daily_aggregate", + "description": "", + "uses": [ + { + "name": "serviceQueueDailyBase", + "version": "1.0", + "type": "dataset_def" + } + ], + "sources": [ + { + "dataSet": "serviceQueueDailyBase", + "alias": "b" + } + ], + "columns": [ + { + "type": "simple_column", + "alias": "queue_room_name", + "column": "b.queue_room_name" + }, + { + "type": "derived_column", + "alias": "patients", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "COUNT(b.patient_id)" + } + } + ], + "groupBy": { + "groupParam": "groupByParam", + "columns": ["queue_room_id"], + "excludeParam": "excludeParam" + }, + "dynamicJsonQueryGenerationDirectives": { + "patientListGenerator": { + "useTemplate": "service-queue-patient-list-template", + "useTemplateVersion": "1.0", + "generatingDirectives": { + "joinDirectives": { + "joinType": "INNER", + "joinCondition": "<> = <>", + "baseColumn": "patient_id", + "templateColumn": "person_id" + } + } + } + } +} diff --git a/app/reporting-framework/json-reports/service-queue-daily-base.json b/app/reporting-framework/json-reports/service-queue-daily-base.json new file mode 100644 index 000000000..329850813 --- /dev/null +++ b/app/reporting-framework/json-reports/service-queue-daily-base.json @@ -0,0 +1,145 @@ +{ + "name": "serviceQueueDailyBase", + "version": "1.0", + "tag": "service_queue_base", + "description": "", + "uses": [], + "sources": [ + { + "table": "amrs.queue_entry", + "alias": "qe" + }, + { + "table": "amrs.queue_entry", + "alias": "served_qe", + "join": { + "type": "LEFT", + "joinCondition": "served_qe.patient_id = qe.patient_id AND DATE(qe.started_at) = DATE(served_qe.started_at) AND served_qe.queue_id = qe.queue_id AND served_qe.voided = 0 AND served_qe.status = 12363" + } + }, + { + "table": "amrs.queue_room", + "alias": "qr", + "join": { + "type": "INNER", + "joinCondition": "qe.queue_id = qr.queue_id" + } + }, + { + "table": "amrs.queue", + "alias": "q", + "join": { + "type": "INNER", + "joinCondition": "qe.queue_id = q.queue_id" + } + }, + { + "table": "amrs.concept", + "alias": "c", + "join": { + "type": "INNER", + "joinCondition": "c.concept_id = q.service" + } + }, + { + "table": "amrs.concept_name", + "alias": "cn", + "join": { + "type": "INNER", + "joinCondition": "cn.concept_id = c.concept_id" + } + }, + { + "table": "amrs.location", + "alias": "l", + "join": { + "type": "INNER", + "joinCondition": "q.location_id = l.location_id" + } + } + ], + "columns": [ + { + "type": "simple_column", + "alias": "queue_entry_id", + "column": " qe.queue_entry_id" + }, + { + "type": "simple_column", + "alias": "patient_id", + "column": "qe.patient_id" + }, + { + "type": "simple_column", + "alias": "queue_id", + "column": "qe.queue_id" + }, + { + "type": "simple_column", + "alias": "queue_room_name", + "column": "qr.name" + }, + { + "type": "derived_column", + "alias": "served_status", + "expressionType": "case_statement", + "expressionOptions": { + "caseOptions": [ + { + "condition": "served_qe.status is not null", + "value": "SERVED" + }, + { + "condition": "else", + "value": "NOT SERVED" + } + ] + } + }, + { + "type": "simple_column", + "alias": "queue_room_id", + "column": "qr.queue_room_id" + }, + { + "type": "simple_column", + "alias": "service_name", + "column": "cn.name" + } + ], + "filters": { + "conditionJoinOperator": "and", + "conditions": [ + { + "filterType": "tableColumns", + "conditionExpression": "DATE(qe.started_at) = DATE(NOW())" + }, + { + "filterType": "tableColumns", + "conditionExpression": "qe.voided = 0" + }, + { + "filterType": "tableColumns", + "conditionExpression": "qr.retired = 0" + }, + { + "filterType": "tableColumns", + "conditionExpression": "cn.voided = 0" + }, + { + "filterType": "tableColumns", + "conditionExpression": "c.uuid = ? ", + "parameterName": "serviceUuid" + }, + { + "filterType": "tableColumns", + "conditionExpression": "l.uuid = ? ", + "parameterName": "locationUuid" + } + ] + }, + "groupBy": { + "groupParam": "groupByParam", + "columns": ["qe.patient_id", "qr.queue_room_id"] + } +} diff --git a/app/reporting-framework/json-reports/service-queue-patient-list-template.json b/app/reporting-framework/json-reports/service-queue-patient-list-template.json new file mode 100644 index 000000000..ef2411869 --- /dev/null +++ b/app/reporting-framework/json-reports/service-queue-patient-list-template.json @@ -0,0 +1,109 @@ +{ + "name": "service_queue_patient_list_template", + "version": "1.0", + "tag": "service_queue_patient_list_template", + "description": "Service Queue Patient list template", + "sources": [ + { + "table": "amrs.person", + "alias": "t1" + }, + { + "table": "amrs.person_name", + "alias": "person_name", + "join": { + "type": "LEFT", + "joinCondition": "t1.person_id = person_name.person_id AND (person_name.voided IS NULL || person_name.voided = 0) AND person_name.preferred = 1" + } + }, + { + "table": "amrs.patient_identifier", + "alias": "id", + "join": { + "type": "LEFT", + "joinCondition": "t1.person_id = id.patient_id AND (id.voided IS NULL || id.voided = 0)" + } + }, + { + "table": "amrs.person_attribute", + "alias": "contacts", + "join": { + "type": "LEFT", + "joinCondition": "t1.person_id = contacts.person_id AND (contacts.voided IS NULL || contacts.voided = 0) AND contacts.person_attribute_type_id in (10, 48)" + } + }, + { + "table": "amrs.person_address", + "alias": "pa", + "join": { + "type": "LEFT", + "joinCondition": "t1.person_id = pa.person_id" + } + } + ], + "columns": [ + { + "type": "simple_column", + "alias": "patient_uuid", + "column": "t1.uuid" + }, + { + "type": "derived_column", + "alias": "uuid", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "t1.uuid" + } + }, + { + "type": "simple_column", + "alias": "person_id", + "column": "t1.person_id" + }, + { + "type": "simple_column", + "alias": "gender", + "column": "t1.gender" + }, + { + "type": "simple_column", + "alias": "birthdate", + "column": "t1.birthdate" + }, + { + "type": "derived_column", + "alias": "age", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "extract(year from (from_days(datediff(now(),t1.birthdate))))" + } + }, + { + "type": "derived_column", + "alias": "person_name", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": " CONCAT(COALESCE(person_name.given_name, ''), ' ', COALESCE(person_name.middle_name, ''), ' ', COALESCE(person_name.family_name, ''))" + } + }, + { + "type": "derived_column", + "alias": "identifiers", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": " GROUP_CONCAT(DISTINCT id.identifier SEPARATOR ', ')" + } + }, + { + "type": "derived_column", + "alias": "phone_number", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": " GROUP_CONCAT(DISTINCT contacts.value SEPARATOR ', ')" + } + } + ], + "groupBy": { + "columns": ["t1.person_id"] + } +} diff --git a/app/reporting-framework/json-reports/service-queue/service-queue-report.json b/app/reporting-framework/json-reports/service-queue/service-queue-report.json new file mode 100644 index 000000000..b5b3478fa --- /dev/null +++ b/app/reporting-framework/json-reports/service-queue/service-queue-report.json @@ -0,0 +1,3 @@ +{ + "reports": ["serviceQueueDailyAggregate"] +} diff --git a/authorization/etl-authorizer.js b/authorization/etl-authorizer.js index c7b82ba1e..a996e82cc 100755 --- a/authorization/etl-authorizer.js +++ b/authorization/etl-authorizer.js @@ -7,7 +7,7 @@ var currentUserRoles = []; var analytics = require('../dao/analytics/etl-analytics-dao'); var _ = require('underscore'); -var PRIVILEGES = { +const PRIVILEGES = { canViewPatient: 'View Patients', canViewDataAnalytics: 'View Data Analytics', canViewDataEntryStats: 'View POC Data entry statitsisc', @@ -61,7 +61,7 @@ var reportPrivileges = { 'patient-referral-report': [PRIVILEGES.canViewDataAnalytics] }; -var SUPERUSER_ROLES = ['System Developer']; +const SUPERUSER_ROLES = ['System Developer']; authorizer.setUser = function (openmrsUser) { currentUser = openmrsUser; @@ -89,12 +89,12 @@ authorizer.getAllPrivileges = function () { }; authorizer.getAllPrivilegesArray = function () { - var allPrivileges = []; + const allPrivileges = []; - for (var prop in PRIVILEGES) { + for (let prop in PRIVILEGES) { allPrivileges.push(PRIVILEGES[prop]); } - //console.log('All privileges', allPrivileges); + return allPrivileges; }; @@ -118,7 +118,7 @@ authorizer.hasPrivileges = function (arrayOfPrivileges) { return true; } - var hasPrivilege = true; + let hasPrivilege = true; for (var i = 0; i < arrayOfPrivileges.length; i++) { if (!authorizer.hasPrivilege(arrayOfPrivileges[i])) { @@ -153,22 +153,42 @@ authorizer.isSuperUser = function () { }; authorizer.getUserAuthorizedLocations = function (userProperties, callback) { - var authorized = []; - resolveLocationName(userProperties, 'aggregate', function (r) { - authorized.push.apply(authorized, r); - resolveLocationName(userProperties, 'operational', function (s) { - authorized.push.apply(authorized, s); - callback(authorized); + const authorized = []; + try { + resolveLocationName(userProperties, 'aggregate', (aggregateResults) => { + try { + authorized.push.apply(authorized, aggregateResults); + resolveLocationName( + userProperties, + 'operational', + (operationalResults) => { + try { + authorized.push.apply(authorized, operationalResults); + callback(authorized); + } catch (err) { + console.error('Error processing operational results:', err); + callback(authorized); + } + } + ); + } catch (err) { + console.error('Error processing aggregate results:', err); + callback(authorized); + } }); - }); + } catch (err) { + console.error('Error in getUserAuthorizedLocations:', err); + callback([]); + } }; function resolveLocationName(userProperties, type, callback) { - var authorized = []; + const authorized = []; for (var key in userProperties) { if (type === 'operational') { if (/^grantAccessToLocationOperationalData/.test(key)) { if (userProperties[key] === '*') { + // If 'All' access, return immediately with only the "All" object return callback([ { uuid: userProperties[key], @@ -183,6 +203,7 @@ function resolveLocationName(userProperties, type, callback) { } else if (type === 'aggregate') { if (/^grantAccessToLocationAggregateData/.test(key)) { if (userProperties[key] === '*') { + // If 'All' access, return immediately with only the "All" object return callback([ { uuid: userProperties[key], @@ -198,37 +219,50 @@ function resolveLocationName(userProperties, type, callback) { } if (authorized.length > 0) { - analytics.resolveLocationUuidsToName(authorized, function (results) { - var i = []; - _.each(results, function (result) { - if (type === 'operational') { - i.push({ - uuid: result.uuid, - name: result.name, - type: 'operational' - }); - } else if (type === 'aggregate') { - i.push({ - uuid: result.uuid, - name: result.name, - type: 'aggregate' + // Extract UUIDs for lookup + const uuids = authorized.map((item) => + typeof item === 'object' ? item.uuid : item + ); + + try { + analytics.resolveLocationUuidsToName(uuids, (results) => { + try { + const resolveLocationUuids = []; + _.each(results, (result) => { + if (type === 'operational') { + resolveLocationUuids.push({ + uuid: result.uuid, + name: result.name, + type: 'operational' + }); + } else if (type === 'aggregate') { + resolveLocationUuids.push({ + uuid: result.uuid, + name: result.name, + type: 'aggregate' + }); + } }); + callback(resolveLocationUuids); + } catch (err) { + console.error('Error processing location resolution results:', err); + callback([]); } }); - callback(i); - }); + } catch (err) { + console.error('Error calling resolveLocationUuidsToName:', err); + callback([]); + } } else { //for users whose privileges are not set callback(authorized); } } -module.exports = authorizer; - function _setCurrentUserPrivileges() { currentUserPrivileges = []; for (var i = 0; i < currentUser.privileges.length; i++) { - //console.log('Adding privilege: ', currentUser.privileges[i].display); + // console.log('Adding privilege: ', currentUser.privileges[i].display); currentUserPrivileges.push(currentUser.privileges[i].display); } } @@ -239,3 +273,5 @@ function _setCurrentUserRoles() { currentUserRoles.push(currentUser.roles[i].display); } } + +module.exports = authorizer; diff --git a/etl-routes.js b/etl-routes.js index ed1243979..cbdeb04c8 100755 --- a/etl-routes.js +++ b/etl-routes.js @@ -90,6 +90,7 @@ import { ServiceEntry } from './service/queues/queue-entry/queue-entry.service.j import EmailService from './service/login-otp/email.service.js'; import OtpService from './service/otp/otp.service.js'; import OtpStore from './service/otp-store/otp-store.service.js'; +import { LogoService } from './service/logo/logo-service.js'; import SupersetService from './service/superset/superset.service.js'; import { loadAndMaplocationUuidToId, @@ -97,6 +98,7 @@ import { } from './location/location.service.js'; import SmsService from './service/login-otp/sms.service.js'; import { DashboardSummaryService } from './service/dashboard-summary/dashboard-summary.service.js'; +import { ServiceQueueDailyReportService } from './service/queues/queue-entry/service-queue-report.service.js'; module.exports = (function () { var routes = [ @@ -108,7 +110,7 @@ module.exports = (function () { hapiAuthorization: false }, handler: function (request, reply) { - console.log('default rote', request.path); + console.log('default route', request.path); reply('Welcome to Ampath ETL service.'); //return reply(Boom.forbidden('Not this end point bruh')); @@ -120,7 +122,7 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/user-feedback', + path: '/user-feedback', config: { plugins: { hapiAuthorization: false @@ -146,7 +148,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinic-lab-orders', + path: '/clinic-lab-orders', config: { plugins: { hapiAuthorization: { @@ -202,7 +204,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/poc-user-feedback/{count*2}', + path: '/poc-user-feedback/{count*2}', config: { auth: false, handler: function (request, reply) { @@ -228,7 +230,7 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/posttochannel', + path: '/posttochannel', config: { plugins: { hapiAuthorization: false @@ -255,7 +257,7 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/posttogroup', + path: '/posttogroup', config: { plugins: { hapiAuthorization: false @@ -283,8 +285,8 @@ module.exports = (function () { { method: 'GET', - path: '/etl/channel-user-feedback/{count*2}', - /* /etl/channel-user-feedback/10/1504081732.000145 */ + path: '/channel-user-feedback/{count*2}', + /* /channel-user-feedback/10/1504081732.000145 */ config: { auth: false, handler: function (request, reply) { @@ -310,8 +312,8 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/channel-user-feedback/{count*3}', - /* /etl/channel-user-feedback/poc-user-feedback/10/1504081732.000145 */ + path: '/channel-user-feedback/{count*3}', + /* /channel-user-feedback/poc-user-feedback/10/1504081732.000145 */ config: { auth: false, handler: function (request, reply) { @@ -338,8 +340,8 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/group-user-feedback/{count*3}', - /* /etl/channel-user-feedback/poc-user-feedback/10/1504081732.000145 */ + path: '/group-user-feedback/{count*3}', + /* /channel-user-feedback/poc-user-feedback/10/1504081732.000145 */ config: { auth: false, handler: function (request, reply) { @@ -366,7 +368,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/get-monthly-schedule', + path: '/get-monthly-schedule', config: { plugins: { hapiAuthorization: { @@ -433,7 +435,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/daily-appointments/{startDate}', + path: '/daily-appointments/{startDate}', config: { plugins: { hapiAuthorization: { @@ -512,7 +514,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/daily-visits/{startDate}', + path: '/daily-visits/{startDate}', config: { plugins: { hapiAuthorization: { @@ -587,7 +589,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/daily-has-not-returned/{startDate}', + path: '/daily-has-not-returned/{startDate}', config: { plugins: { hapiAuthorization: { @@ -668,7 +670,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinic-lab-orders/{dateActivated}', + path: '/clinic-lab-orders/{dateActivated}', config: { plugins: { hapiAuthorization: { @@ -728,9 +730,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/defaulter-list', + path: '/defaulter-list', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (request.query.locationUuids) { request.query.reportName = 'defaulter-list'; @@ -789,9 +791,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{patientUuids}/cdm-summary', + path: '/patient/{patientUuids}/cdm-summary', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -829,9 +831,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{patientUuids}/medication-change', + path: '/patient/{patientUuids}/medication-change', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -869,9 +871,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{patientUuid}/hiv-clinical-reminder/{referenceDate}', + path: '/patient/{patientUuid}/hiv-clinical-reminder/{referenceDate}', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1002,9 +1004,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/forms/error', + path: '/forms/error', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { dao.logError(request, reply); } @@ -1042,9 +1044,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}', + path: '/patient/{uuid}', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1057,9 +1059,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/program-visit-configs', + path: '/program-visit-configs', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { // var requestParams = Object.assign({}, request.query, request.params); @@ -1083,9 +1085,9 @@ module.exports = (function () { { method: 'GET', path: - '/etl/patient/{patientUuid}/program/{programUuid}/enrollment/{enrollmentUuid}', + '/patient/{patientUuid}/program/{programUuid}/enrollment/{enrollmentUuid}', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1148,9 +1150,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/clinical-notes', + path: '/patient/{uuid}/clinical-notes', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1178,9 +1180,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/hiv-patient-clinical-summary', + path: '/patient/{uuid}/hiv-patient-clinical-summary', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewPatient, privileges.canViewDataAnalytics] @@ -1193,9 +1195,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{id}/hiv-patient-clinical-summary', + path: '/location/{id}/hiv-patient-clinical-summary', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewPatient, privileges.canViewDataAnalytics] @@ -1208,9 +1210,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/vitals', + path: '/patient/{uuid}/vitals', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1237,9 +1239,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/data', + path: '/patient/{uuid}/data', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1266,9 +1268,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/hiv-summary', + path: '/patient/{uuid}/hiv-summary', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1305,9 +1307,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/oncology/summary', + path: '/patient/{uuid}/oncology/summary', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1336,9 +1338,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{uuid}/patient-summary', + path: '/patient/{uuid}/patient-summary', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1369,9 +1371,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/clinic-encounter-data', + path: '/location/{uuid}/clinic-encounter-data', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -1392,9 +1394,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-program-config', + path: '/patient-program-config', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { var requestParams = Object.assign({}, request.query); @@ -1429,9 +1431,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/monthly-appointment-visits', + path: '/location/{uuid}/monthly-appointment-visits', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -1468,9 +1470,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/hiv-summary-indicators', + path: '/location/{uuid}/hiv-summary-indicators', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -1506,9 +1508,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinical-hiv-comparative-overview', + path: '/clinical-hiv-comparative-overview', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -1567,9 +1569,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinical-hiv-comparative-overview/patient-list', + path: '/clinical-hiv-comparative-overview/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1640,9 +1642,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-referrals', + path: '/patient-referrals', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -1713,9 +1715,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/referral-patient-list', + path: '/referral-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -1782,9 +1784,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-referral-details/{locationUuid}/{enrollmentUuid}', + path: '/patient-referral-details/{locationUuid}/{enrollmentUuid}', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientReferralDao @@ -1807,9 +1809,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/patient-referral', + path: '/patient-referral', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientReferralDao @@ -1835,9 +1837,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/patient-referral/{patientReferralId}', + path: '/patient-referral/{patientReferralId}', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { // console.log('xxxxxxxxxxxx', request) @@ -1867,9 +1869,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinical-patient-care-status-overview', + path: '/clinical-patient-care-status-overview', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -1923,9 +1925,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinical-patient-care-status-overview/patient-list', + path: '/clinical-patient-care-status-overview/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -1985,9 +1987,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinical-art-overview', + path: '/clinical-art-overview', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -2040,9 +2042,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinical-art-overview/patient-list', + path: '/clinical-art-overview/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -2101,9 +2103,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/appointment-schedule', + path: '/location/{uuid}/appointment-schedule', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2140,9 +2142,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-flow-data', + path: '/patient-flow-data', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2175,9 +2177,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinic-flow-provider-statistics/patient-list', + path: '/clinic-flow-provider-statistics/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2212,9 +2214,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/clinic-lab-orders-data', + path: '/clinic-lab-orders-data', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2247,9 +2249,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{patient_uuid}/monthly-care-status', + path: '/patient/{patient_uuid}/monthly-care-status', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -2281,9 +2283,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{patient_uuid}/daily-care-status', + path: '/patient/{patient_uuid}/daily-care-status', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -2323,9 +2325,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/daily-visits', + path: '/location/{uuid}/daily-visits', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2362,9 +2364,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/has-not-returned', + path: '/location/{uuid}/has-not-returned', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2401,9 +2403,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/monthly-appointment-schedule', + path: '/location/{uuid}/monthly-appointment-schedule', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2439,9 +2441,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/monthly-visits', + path: '/location/{uuid}/monthly-visits', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -2478,9 +2480,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{uuid}/defaulter-list', + path: '/location/{uuid}/defaulter-list', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { dao.getClinicDefaulterList(request, reply); }, @@ -2537,9 +2539,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/custom_data/{userParams*3}', + path: '/custom_data/{userParams*3}', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { dao.getCustomData(request, reply); } @@ -2553,9 +2555,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/creation/statistics', + path: '/patient/creation/statistics', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewDataEntryStats, privileges.canViewPatient] @@ -2593,9 +2595,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{location}/patient/creation/statistics', + path: '/location/{location}/patient/creation/statistics', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewDataEntryStats, privileges.canViewPatient] @@ -2629,9 +2631,9 @@ module.exports = (function () { **/ method: 'GET', - path: '/etl/get-report-by-report-name', + path: '/get-report-by-report-name', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -2763,9 +2765,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/MOH-731-report', + path: '/MOH-731-report', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -2875,9 +2877,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/MOH-731-report/patient-list', + path: '/MOH-731-report/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -2978,9 +2980,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-status-change-tracking', + path: '/patient-status-change-tracking', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -3059,9 +3061,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-status-change-tracking/patient-list', + path: '/patient-status-change-tracking/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -3123,9 +3125,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/user-cohorts', + path: '/user-cohorts', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { request.query.reportName = 'cohort-report'; @@ -3158,9 +3160,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/cohort-user/{cohortUserId}', + path: '/cohort-user/{cohortUserId}', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientList @@ -3184,9 +3186,9 @@ module.exports = (function () { }, { method: 'DELETE', - path: '/etl/cohort-user/{cohortUserId}', + path: '/cohort-user/{cohortUserId}', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientList @@ -3206,9 +3208,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/cohort-user/{cohortUserId}', + path: '/cohort-user/{cohortUserId}', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientList @@ -3234,9 +3236,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/cohort-user', + path: '/cohort-user', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientList @@ -3263,9 +3265,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/cohort/{cohortUuid}/cohort-users', + path: '/cohort/{cohortUuid}/cohort-users', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { patientList @@ -3285,7 +3287,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-register-report', + path: '/patient-register-report', config: { plugins: { hapiAuthorization: { @@ -3345,9 +3347,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hiv-summary-indicators', + path: '/hiv-summary-indicators', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -3438,9 +3440,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hiv-summary-indicators/patient-list', + path: '/hiv-summary-indicators/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -3523,9 +3525,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hiv-summary-monthly-indicators', + path: '/hiv-summary-monthly-indicators', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -3615,9 +3617,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hiv-summary-monthly-indicators/patient-list', + path: '/hiv-summary-monthly-indicators/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -3686,9 +3688,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/location/{locationUuids}/patient-by-indicator', + path: '/location/{locationUuids}/patient-by-indicator', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewPatient, privileges.canViewDataAnalytics] @@ -3733,9 +3735,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-by-indicator', + path: '/patient-by-indicator', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewPatient, privileges.canViewDataAnalytics] @@ -3776,9 +3778,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/data-entry-statistics/{sub}', + path: '/data-entry-statistics/{sub}', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataEntryStats @@ -3879,9 +3881,9 @@ module.exports = (function () { **/ method: 'GET', - path: '/etl/indicators-schema', + path: '/indicators-schema', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -3912,9 +3914,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/indicators-schema-with-sections', + path: '/indicators-schema-with-sections', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -3927,9 +3929,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hiv-summary-data', + path: '/hiv-summary-data', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewPatient, privileges.canViewDataAnalytics] @@ -3942,9 +3944,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/compare-patient-lists', + path: '/compare-patient-lists', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { var r = request; var handler; @@ -3988,9 +3990,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-list-by-indicator', + path: '/patient-list-by-indicator', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [privileges.canViewPatient, privileges.canViewDataAnalytics] @@ -4040,9 +4042,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-lab-orders', + path: '/patient-lab-orders', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (config.eidSyncOn === true) { const labSyncService = new LabSyncService(); @@ -4062,9 +4064,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/sync-patient-labs', + path: '/sync-patient-labs', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (config.eidSyncOn === true) { const labSyncService = new LabSyncService(); @@ -4083,9 +4085,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/eid/order/{lab}', + path: '/eid/order/{lab}', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -4127,9 +4129,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/session/invalidate', + path: '/session/invalidate', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { dao.invalidateUserSession(request, reply); } @@ -4137,7 +4139,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lab-cohorts', + path: '/lab-cohorts', config: { auth: false, plugins: { @@ -4175,7 +4177,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lab-cohorts-sync', + path: '/lab-cohorts-sync', config: { auth: false, plugins: { @@ -4200,9 +4202,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/eid/load-order-justifications', + path: '/eid/load-order-justifications', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { dao.loadOrderJustifications(request, reply); }, @@ -4213,9 +4215,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/fileupload', + path: '/fileupload', config: { - auth: 'simple', + auth: 'default', payload: { maxBytes: 5000000 }, @@ -4269,9 +4271,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/files/{param*}', + path: '/files/{param*}', config: { - auth: 'simple', + auth: 'default', handler: { directory: { path: config.etl.uploadsDirectory, @@ -4283,9 +4285,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/eid/patients-with-results', + path: '/eid/patients-with-results', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: false }, @@ -4310,9 +4312,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/motdNotifications', + path: '/motdNotifications', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: false }, @@ -4336,9 +4338,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patients-requiring-viral-load-order', + path: '/patients-requiring-viral-load-order', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -4402,9 +4404,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-care-cascade-analysis', + path: '/patient-care-cascade-analysis', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewDataAnalytics @@ -4463,9 +4465,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-care-cascade-analysis/patient-list', + path: '/patient-care-cascade-analysis/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -4528,9 +4530,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/indicator-disaggregation-filter-options', + path: '/indicator-disaggregation-filter-options', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { reply( require('./service/indicator-processor/indicator-filter-options.json') @@ -4546,9 +4548,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient/{patientUuid}/medical-history-report', + path: '/patient/{patientUuid}/medical-history-report', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewPatient @@ -4592,9 +4594,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/departments-programs-config', + path: '/departments-programs-config', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { reply(departmentProgramsService.getAllDepartmentsConfig()); @@ -4612,9 +4614,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/department-programs', + path: '/department-programs', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { let department = request.query.department; @@ -4641,7 +4643,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-program-enrollments', + path: '/patient-program-enrollments', config: { plugins: { hapiAuthorization: { @@ -4693,9 +4695,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lab-orders-by-patient', + path: '/lab-orders-by-patient', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { roles: [ @@ -4749,7 +4751,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/program-enrollment/patient-list', + path: '/program-enrollment/patient-list', config: { plugins: { hapiAuthorization: { @@ -4804,9 +4806,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/radiology-diagnostic-report', + path: '/radiology-diagnostic-report', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { var requestParams = request.query; @@ -4833,9 +4835,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/radiology-images', + path: '/radiology-images', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { var requestParams = request.query; @@ -4860,9 +4862,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/radiology-all-patient-images', + path: '/radiology-all-patient-images', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { var requestParams = request.query; @@ -4883,9 +4885,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/radiology-comments', + path: '/radiology-comments', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { var payload = request.payload; @@ -4905,9 +4907,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/oncology-reports', + path: '/oncology-reports', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { oncologyReportsService @@ -4932,9 +4934,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/oncology-report', + path: '/oncology-report', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.reportUuid) { @@ -4965,9 +4967,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/breast-cancer-screening-numbers', + path: '/breast-cancer-screening-numbers', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5023,9 +5025,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/breast-cancer-screening-numbers-patient-list', + path: '/breast-cancer-screening-numbers-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -5064,9 +5066,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/combined-breast-cervical-cancer-screening-numbers', + path: '/combined-breast-cervical-cancer-screening-numbers', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5124,10 +5126,9 @@ module.exports = (function () { }, { method: 'GET', - path: - '/etl/combined-breast-cervical-cancer-screening-numbers-patient-list', + path: '/combined-breast-cervical-cancer-screening-numbers-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -5167,9 +5168,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/cervical-cancer-screening-numbers', + path: '/cervical-cancer-screening-numbers', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5226,9 +5227,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/cervical-cancer-screening-numbers-patient-list', + path: '/cervical-cancer-screening-numbers-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -5268,9 +5269,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lung-cancer-screening-numbers', + path: '/lung-cancer-screening-numbers', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5326,9 +5327,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lung-cancer-screening-numbers-patient-list', + path: '/lung-cancer-screening-numbers-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -5367,9 +5368,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lung-cancer-treatment-numbers', + path: '/lung-cancer-treatment-numbers', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5426,9 +5427,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/lung-cancer-treatment-numbers-patient-list', + path: '/lung-cancer-treatment-numbers-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -5467,9 +5468,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/kibana-dashboards', + path: '/kibana-dashboards', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5493,7 +5494,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/differentiated-care-program/patient-list', + path: '/differentiated-care-program/patient-list', config: { plugins: { hapiAuthorization: { @@ -5560,9 +5561,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-referrals-peer-navigator', + path: '/patient-referrals-peer-navigator', config: { - auth: 'simple', + auth: 'default', plugins: { openmrsLocationAuthorizer: { locationParameter: [ @@ -5630,7 +5631,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/surge-report', + path: '/surge-report', config: { plugins: { hapiAuthorization: {} @@ -5675,7 +5676,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/surge-report-patient-list', + path: '/surge-report-patient-list', config: { plugins: { hapiAuthorization: {} @@ -5714,9 +5715,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/retention-summary-report', + path: '/retention-summary-report', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5768,9 +5769,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/retention-summary-report/patient-list', + path: '/retention-summary-report/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { request.query.reportName = 'retention-summary-report'; @@ -5812,9 +5813,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/retention-summary-report/indicator-definitions', + path: '/retention-summary-report/indicator-definitions', config: { - auth: 'simple', + auth: 'default', plugins: { hapiAuthorization: { role: privileges.canViewClinicDashBoard @@ -5838,7 +5839,7 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hei-monthly-summary', + path: '/hei-monthly-summary', config: { plugins: { hapiAuthorization: {} @@ -5884,9 +5885,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hei-monthly-summary/patient-list', + path: '/hei-monthly-summary/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { request.query.reportName = 'hei-summary-patient-list'; @@ -5922,9 +5923,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-gain-loses-numbers', + path: '/patient-gain-loses-numbers', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.locationUuid) { @@ -5963,9 +5964,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-gain-loses-patient-list', + path: '/patient-gain-loses-patient-list', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.locationUuid) { @@ -6009,9 +6010,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/patient-cervical-cancer-screening-summary', + path: '/patient-cervical-cancer-screening-summary', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { const patientUuid = request.query.uuid; @@ -6028,9 +6029,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/moh-412-report', + path: '/moh-412-report', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.locationUuids) { @@ -6075,9 +6076,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/moh-412-report/patient-list', + path: '/moh-412-report/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.locationUuids) { @@ -6125,9 +6126,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/covid-vaccination-status', + path: '/covid-vaccination-status', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.patientUuid) { @@ -6150,9 +6151,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/covid-19-monthly-vaccination-report', + path: '/covid-19-monthly-vaccination-report', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.locationUuids) { @@ -6190,9 +6191,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/covid-19-monthly-vaccination-report/patient-list', + path: '/covid-19-monthly-vaccination-report/patient-list', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.locationUuids) { @@ -6231,9 +6232,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/ml-weekly-predictions', + path: '/ml-weekly-predictions', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (request.query.locationUuids) { request.query.reportName = 'defaulter-list'; @@ -6285,9 +6286,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/predicted-score', + path: '/predicted-score', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { if (request.query.patientUuid) { @@ -6310,9 +6311,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/hiv-latest-summaries', + path: '/hiv-latest-summaries', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { dao.getPatientsLatestHivSummmary(request).then((summary) => { @@ -6326,9 +6327,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/viral-load-suppression-rate', + path: '/viral-load-suppression-rate', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: function (request, reply) { const { uuid } = request.query; @@ -6349,9 +6350,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/amrs_id', + path: '/amrs_id', config: { - auth: 'simple', + auth: 'default', plugins: {}, handler: async function (request, reply) { const axios = require('axios'); @@ -6378,9 +6379,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/ml-summary', + path: '/ml-summary', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (request.query.locationUuids) { preRequest.resolveLocationIdsToLocationUuids(request, function () { @@ -6431,9 +6432,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/ml-summary-patient-list', + path: '/ml-summary-patient-list', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (request.query.locationUuids) { preRequest.resolveLocationIdsToLocationUuids(request, function () { @@ -6484,9 +6485,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/moh-731', + path: '/moh-731', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (request.query.locationUuids) { preRequest.resolveLocationIdsToLocationUuids(request, function () { @@ -6537,9 +6538,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/moh-731-patient-list', + path: '/moh-731-patient-list', config: { - auth: 'simple', + auth: 'default', handler: function (request, reply) { if (request.query.locationUuids) { preRequest.resolveLocationIdsToLocationUuids(request, function () { @@ -6602,21 +6603,26 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/queue-entry', + path: '/queue-entry', config: { - auth: 'simple', + auth: 'default', handler: async function (request, reply) { const queueService = new ServiceEntry(); if (request.query.locationUuid && request.query.serviceUuid) { const locationUuid = request.query.locationUuid; const serviceUuid = request.query.serviceUuid; - const res = await queueService.getQueueEntriesByLocationAndService( - locationUuid, - serviceUuid - ); - reply({ - data: res - }); + try { + const res = await queueService.getQueueEntriesByLocationAndService( + locationUuid, + serviceUuid + ); + reply({ + data: res + }); + } catch (error) { + console.error({ error }); + reply(Boom.badData()); + } } else { reply(Boom.badData()); } @@ -6629,10 +6635,10 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/otp', + path: '/otp', config: { - auth: 'simple', - handler: async (request, reply) => { + auth: 'default', + handler: async function (request, reply) { const otpService = new OtpService(); const smsService = new SmsService(); const emailService = new EmailService(); @@ -6718,9 +6724,9 @@ module.exports = (function () { }, { method: 'POST', - path: '/etl/verify-otp', + path: '/verify-otp', config: { - auth: 'simple', + auth: 'default', handler: async function (request, reply) { const otpStore = new OtpStore(); const { username, otp } = request.payload || {}; @@ -6746,9 +6752,39 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/superset-token', + path: '/county-logo', + config: { + auth: 'default', + handler: async function (request, h) { + let logo = null; + let defaultSessionLocationUuid = + '18c343eb-b353-462a-9139-b16606e6b6c2'; // location test + let sessionLocationUuid = null; + const sessionLocation = + request.auth.credentials.sessionLocation || null; + if (sessionLocation) { + if (sessionLocation.uuid) { + sessionLocationUuid = sessionLocation.uuid; + } + } + const logoService = new LogoService(); + logo = await logoService.getLocationLogo( + sessionLocationUuid + ? sessionLocationUuid + : defaultSessionLocationUuid + ); + return h.redirect(logo); + }, + plugins: {}, + description: 'Get a users location logo', + notes: 'Returns the current users location logo' + } + }, + { + method: 'GET', + path: '/superset-token', config: { - auth: 'simple', + auth: 'default', handler: async function (request, reply) { const locationUuid = request.query.locationUuid; const supersetService = new SupersetService(); @@ -6776,9 +6812,9 @@ module.exports = (function () { }, { method: 'GET', - path: '/etl/dashboard-summary', + path: '/dashboard-summary', config: { - auth: 'simple', + auth: 'default', handler: async function (request, reply) { const locationUuid = request.query.locationUuid; const dashboardSummaryService = new DashboardSummaryService(); @@ -6809,6 +6845,90 @@ module.exports = (function () { description: 'Get Dashboard summary for a location', notes: 'Returns a dashboard summary for a location' } + }, + { + method: 'GET', + path: '/service-queue-daily-report', + config: { + auth: 'default', + plugins: {}, + handler: function (request, reply) { + if (request.query['locationUuid'] && request.query['serviceUuid']) { + let requestParams = Object.assign( + {}, + request.query, + request.params + ); + let reportParams = etlHelpers.getReportParams( + 'service-queue-daily-report', + [], + requestParams + ); + let serviceQueueDailyService = new ServiceQueueDailyReportService( + 'service-queue-daily-report', + reportParams.requestParams + ); + serviceQueueDailyService + .getAggregateReport(reportParams) + .then((result) => { + reply(result); + }) + .catch((error) => { + console.error('Error: ', error); + reply(error); + }); + } else { + reply(Boom.badData('Misssing location or service params')); + } + }, + description: 'Service Queue Daily report', + notes: 'Service Queue Daily report', + tags: ['api'] + } + }, + { + method: 'GET', + path: '/service-queue-daily-report/patient-list', + config: { + auth: 'default', + plugins: {}, + handler: function (request, reply) { + if (request.query['locationUuid'] && request.query['serviceUuid']) { + let requestParams = Object.assign( + {}, + request.query, + request.params + ); + let reportParams = etlHelpers.getReportParams( + 'service-queue-daily-report', + [], + requestParams + ); + + let serviceQueueDailyService = new ServiceQueueDailyReportService( + 'service-queue-daily-report', + reportParams.requestParams + ); + + delete reportParams.requestParams['gender']; + delete reportParams.requestParams['genders']; + serviceQueueDailyService + .getPatientListReport(reportParams.requestParams) + .then((result) => { + reply(result); + }) + .catch((error) => { + console.error('Error: ', error); + reply(error); + }); + } else { + reply(Boom.badData('Misssing location or service params')); + } + }, + description: 'Service Queue Daily report Patient List', + notes: 'Service Queue Daily report Patient List', + tags: ['api'] + } } ]; diff --git a/etl-server.js b/etl-server.js index ed18e8c9b..a7b493426 100755 --- a/etl-server.js +++ b/etl-server.js @@ -1,10 +1,10 @@ +const { Promise } = require('bluebird'); +const Boom = require('boom'); + try { var Hapi = require('hapi'); - var mysql = require('mysql'); var Good = require('good'); var requestConfig = require('./request-config'); - var Basic = require('hapi-auth-basic'); - // var etlBroadcast =require('./etl-broadcast'); var https = require('http'); var config = require('./conf/config'); var requestConfig = require('./request-config'); @@ -25,9 +25,7 @@ try { var os = require('os'); var locationAuthorizer = require('./authorization/location-authorizer.plugin'); var cache = require('./session-cache'); - var request = require('request'); var numCPUs = os.cpus().length; - var authencticated = false; var server = new Hapi.Server({ connections: { //routes: {cors:{origin:["https://amrs.ampath.or.ke:8443"]}} @@ -57,91 +55,145 @@ try { tls: tls_config, routes: { log: true } }); - var pool = mysql.createPool(config.mysql); - var validate = function (username, password, callback) { - try { - //Openmrs context - var openmrsAppName = config.openmrs.applicationName || 'amrs'; - var authBuffer = new Buffer(username + ':' + password).toString('base64'); - var options = { - hostname: config.openmrs.host, - port: config.openmrs.port, - path: '/' + openmrsAppName + '/ws/rest/v1/session', - headers: { - Authorization: 'Basic ' + authBuffer - } - }; - var key = username; - if (config.openmrs.https) { - https = require('https'); - } - var session = cache.getFromToCache(key); - if (session !== null) { - options.headers['Cookie'] = session.session; - delete options.headers.Authorization; + const authenticateWithCookie = (cookie) => { + const contextPath = config.openmrs.applicationName || 'amrs'; + const options = { + hostname: config.openmrs.host, + port: config.openmrs.port, + path: '/' + contextPath + '/ws/rest/v1/session', + headers: { + Cookie: cookie } + }; + + if (config.openmrs.https) { + https = require('https'); + } + + return new Promise((resolve, reject) => { https - .get(options, function (res) { - var body = ''; - res.on('data', function (chunk) { + .get(options, (res) => { + let body = ''; + //A chunk of data has been received. + res.on('data', (chunk) => { body += chunk; }); - res.on('end', function () { - var result; - try { - result = JSON.parse(body); - } catch (err) { - if (session !== null) { - cache.removeFromCache(key); - return validate(username, password, callback); - } else { - return callback(null, false); - } + + // The whole response has been received. + res.on('end', () => { + // Handle non-200 status codes + if (res.statusCode === 403 || res.statusCode === 401) { + console.log( + `Authentication failed with status ${res.statusCode}` + ); + return resolve(null); } - if (result.authenticated === true) { - authorizer.setUser(result.user); - authorizer.getUserAuthorizedLocations( - result.user.userProperties, - function (authorizedLocations) { - var currentUser = { - username: username, - role: authorizer.isSuperUser() - ? authorizer.getAllPrivilegesArray() - : authorizer.getCurrentUserPreviliges(), - authorizedLocations: authorizedLocations - }; - var sessionCookie = - res.headers['set-cookie'] && - res.headers['set-cookie'].length > 0 - ? res.headers['set-cookie'][0] - : session.session; - cache.saveToCache(key, { - result: result, - currentUser: currentUser, - session: sessionCookie - }); - currentUser.session = sessionCookie; - requestConfig.setAuthorization(sessionCookie); - callback(null, result.authenticated, currentUser); - } + + if (res.statusCode !== 200) { + console.error(`Unexpected status code: ${res.statusCode}`); + return reject( + new Error(`OpenMRS returned status ${res.statusCode}`) ); - } else { - console.log( - 'An error occurred while trying to validate; user is not authenticated' + } + + // Check if response is JSON + const contentType = res.headers['content-type'] || ''; + if (!contentType.includes('application/json')) { + console.error('Non-JSON response received:', contentType); + console.error('Response body:', body.substring(0, 200)); + return reject( + new Error( + 'Invalid response format from OpenMRS (expected JSON)' + ) ); - callback(null, false); + } + + try { + const result = JSON.parse(body); + // Validate user object exists + if (!result.user) { + return reject( + new Error('User object missing from authentication response') + ); + } + + // Extract sessionId from cookie if not in response + let sessionId = result.sessionId; + if (!sessionId) { + // Extract JSESSIONID from the cookie parameter (format: "JSESSIONID=xxxxx") + const cookieMatch = cookie.match(/JSESSIONID=([^;]+)/); + if (cookieMatch && cookieMatch[1]) { + sessionId = cookieMatch[1]; + } else { + return reject( + new Error( + 'Session ID missing from authentication response and cookie' + ) + ); + } + } + + //Set current user + authorizer.setUser(result.user); + console.log('Set user, getting authorized locations...'); + + // Wrap the callback in try-catch to handle errors + try { + authorizer.getUserAuthorizedLocations( + result.user.userProperties, + (authorizedLocations) => { + console.log( + 'Authorized locations retrieved:', + authorizedLocations + ); + try { + const currentUser = { + username: result.user.username, + role: authorizer.isSuperUser() + ? authorizer.getAllPrivilegesArray() + : authorizer.getCurrentUserPreviliges(), + authorizedLocations: authorizedLocations, + sessionLocation: result.sessionLocation || null + }; + + const validSessionCookie = 'JSESSIONID=' + sessionId; + const sessionCookie = + res.headers['set-cookie'] && + res.headers['set-cookie'].length > 0 + ? res.headers['set-cookie'][0] + : validSessionCookie; + cache.saveToCache(result.user.username, { + result: result, + currentUser: currentUser, + session: sessionCookie + }); + currentUser.session = sessionCookie; + requestConfig.setAuthorization(sessionCookie); + resolve({ + authenticated: result.authenticated, + currentUser: currentUser + }); + } catch (innerError) { + console.error('Error building current user:', innerError); + reject(innerError); + } + } + ); + } catch (authError) { + console.error('Error getting authorized locations:', authError); + reject(authError); + } + } catch (error) { + console.error('Error parsing authentication response:', error); + reject(error); } }); }) - .on('error', function (error) { - //console.log(error); - callback(null, false); + .on('error', (error) => { + reject(error); }); - } catch (ex) { - console.log('An error occurred while trying to validate', ex); - callback(null, false); - } + }); }; var HapiSwaggerOptions = { @@ -174,10 +226,6 @@ try { dir: `${__dirname}/app/routes` } }, - { - register: Basic, - options: {} - }, { register: hapiAuthorization, options: { @@ -194,10 +242,6 @@ try { register: locationAuthorizer, options: {} } - // { - // 'register': Nes, - // 'options': etlBroadcast.getOptions(server) - // } ], function (err) { @@ -205,9 +249,78 @@ try { console.error(err); throw err; // something bad happened loading the plugin } - server.auth.strategy('simple', 'basic', 'required', { - validateFunc: validate - }); + + const getCookieValue = (name) => + name.match(/(^|;)\s*JSESSIONID\s*=\s*([^;]+)/)?.pop() || ''; + + const scheme = function (server, options) { + return { + authenticate: function (request, reply) { + const req = request.raw.req; + const cookieHeader = req.headers.cookie; + // Extract JSessionID from the cookie + if (!cookieHeader) { + return reply(Boom.unauthorized('No cookie header', null)); + } + const cookie = getCookieValue(cookieHeader); + if (!cookie) { + return reply( + Boom.unauthorized(null, 'Invalid cookie/No cookie set!') + ); + } + //Construct valid cookie + const validCookie = 'JSESSIONID=' + cookie; + + authenticateWithCookie(validCookie) + .then((data) => { + if (!data) { + return reply( + Boom.unauthorized('User not authenticated!'), + null, + {} + ); + } + + try { + const result = data; + console.log('Current user: ', result.currentUser); + if (result.authenticated === true) { + //Authentication successful + return reply.continue({ + isAuthenticated: true, + credentials: result.currentUser + }); + } else { + //Authentication unsuccessful - reject the request + return reply( + Boom.unauthorized('User not authenticated!'), + null, + {} + ); + } + } catch (error) { + console.log('Oop error!', error); + return reply( + Boom.unauthorized('User not authenticated!'), + null, + {} + ); + } + }) + .catch((error) => { + console.error('Authentication error:', error); + return reply( + Boom.unauthorized('Authentication failed!'), + null, + {} + ); + }); + } + }; + }; + + server.auth.scheme('custom', scheme); + server.auth.strategy('default', 'custom', 'required'); //Adding routes for (var route in routes) { diff --git a/service/logo/logo-service.js b/service/logo/logo-service.js new file mode 100644 index 000000000..10d5e3554 --- /dev/null +++ b/service/logo/logo-service.js @@ -0,0 +1,45 @@ +const db = require('../../etl-db'); +export class LogoService { + constructor() {} + async getLocationLogo(locationUuid) { + if (!locationUuid) { + return '/logo/ampath-logo-white.png'; + } + const resp = await this.getCountyLogoByLocationUuid(locationUuid); + if (!resp || resp.length === 0) { + return '/logo/ampath-logo-white.png'; + } + const data = resp[0]; + const { logo } = data; + return logo; + } + async getCountyLogoByLocationUuid(locationUuid) { + if (!locationUuid) { + throw new Error('Missing Location params'); + } + return new Promise((resolve, reject) => { + const sql = `SELECT + l.name AS location, + lat.name AS attribute_type_name, + la.value_reference AS logo +FROM + amrs.location l + JOIN + amrs.location_attribute la ON (l.location_id = la.location_id + AND la.voided = 0) + JOIN + amrs.location_attribute_type lat ON (la.attribute_type_id = lat.location_attribute_type_id + AND lat.uuid = 'cef1526a-1855-47a3-8c3a-0f32b2d84707') +WHERE + l.uuid = '${locationUuid}' + AND lat.retired = 0;`; + const queryParts = { + sql: sql + }; + db.queryServer(queryParts, function (result) { + result.sql = sql; + resolve(result.result); + }); + }); + } +} diff --git a/service/queues/queue-entry/service-queue-report.service.js b/service/queues/queue-entry/service-queue-report.service.js new file mode 100644 index 000000000..966e0ef91 --- /dev/null +++ b/service/queues/queue-entry/service-queue-report.service.js @@ -0,0 +1,46 @@ +import { BaseMysqlReport } from '../../../app/reporting-framework/base-mysql.report'; +import { PatientlistMysqlReport } from '../../../app/reporting-framework/patientlist-mysql.report'; + +const _ = require('lodash'); +const Promise = require('bluebird'); + +export class ServiceQueueDailyReportService { + getAggregateReport(reportParams) { + return new Promise((resolve, reject) => { + let report = new BaseMysqlReport( + 'serviceQueueDailyAggregate', + reportParams.requestParams + ); + + Promise.join(report.generateReport(), (results) => { + let result = results.results.results; + results.size = result ? result.length : 0; + results.result = result; + delete results['results']; + resolve(results); + }).catch((errors) => { + reject(errors); + }); + }); + } + + getPatientListReport(reportParams) { + let indicators = reportParams.indicators + ? reportParams.indicators.split(',') + : []; + + let report = new PatientlistMysqlReport( + 'serviceQueueDailyAggregate', + reportParams + ); + + return new Promise(function (resolve, reject) { + Promise.join(report.generatePatientListReport(indicators), (results) => { + resolve(results); + }).catch((errors) => { + console.error('Error', errors); + reject(errors); + }); + }); + } +}