diff --git a/app/reporting-framework/base-mysql.report.js b/app/reporting-framework/base-mysql.report.js index b61654633..793535c95 100755 --- a/app/reporting-framework/base-mysql.report.js +++ b/app/reporting-framework/base-mysql.report.js @@ -225,6 +225,9 @@ import * as hiv_cervical_cancer_monthly_summary_lesions_pcf_aggregate from './js import * as defaulter_list_aggregate from './json-reports/defaulter-list-aggregate.json'; import * as defaulter_list_base from './json-reports/defaulter-list-base.json'; +//clinic clow report +import * as clinic_flow_provider_statistics_aggregate from './json-reports/clinic-flow-provider-statistics-aggregate.json'; +import * as clinic_flow_provider_statistics_base from './json-reports/clinic-flow-provider-statistics-base.json'; export class BaseMysqlReport { constructor(reportName, params) { this.reportName = reportName; @@ -1192,6 +1195,15 @@ export class BaseMysqlReport { main: this.cloneJsonSchema(defaulter_list_aggregate), defaulterListBase: this.cloneJsonSchema(defaulter_list_base) }); + case 'clinicFlowProviderStatisticsAggregate': + resolve({ + main: this.cloneJsonSchema( + clinic_flow_provider_statistics_aggregate + ), + clinicFlowProviderStatisticsBase: this.cloneJsonSchema( + clinic_flow_provider_statistics_base + ) + }); default: reject('Unknown report ', reportName); break; diff --git a/app/reporting-framework/json-reports/clinic-flow-provider-statistics-aggregate.json b/app/reporting-framework/json-reports/clinic-flow-provider-statistics-aggregate.json new file mode 100644 index 000000000..d56a12538 --- /dev/null +++ b/app/reporting-framework/json-reports/clinic-flow-provider-statistics-aggregate.json @@ -0,0 +1,60 @@ +{ + "name": "clinicFlowProviderStatisticsAggregate", + "version": "1.0", + "tag": "", + "description": "", + "uses": [ + { + "name": "clinicFlowProviderStatisticsBase", + "version": "1.0", + "type": "dataset_def" + } + ], + "sources": [ + { + "dataSet": "clinicFlowProviderStatisticsBase", + "alias": "b" + } + ], + "columns": [ + { + "type": "simple_column", + "alias": "location_id", + "column": "b.location_id" + }, + { + "type": "simple_column", + "alias": "person_id", + "column": "b.person_id" + }, + { + "type": "simple_column", + "alias": "seen", + "column": "COUNT(b.seen)" + }, + { + "type": "simple_column", + "alias": "visit_started", + "column": "COUNT(b.visit_started)" + } + ], + "groupBy": { + "groupParam": "groupByParam", + "columns": ["location_id"], + "excludeParam": "excludeParam" + }, + "dynamicJsonQueryGenerationDirectives": { + "patientListGenerator": { + "useTemplate": "patient-list-schedules-template", + "useTemplateVersion": "1.0", + "generatingDirectives": { + "joinDirectives": { + "joinType": "INNER", + "joinCondition": "<> = <>", + "baseColumn": "person_id", + "templateColumn": "person_id" + } + } + } + } +} diff --git a/app/reporting-framework/json-reports/clinic-flow-provider-statistics-base.json b/app/reporting-framework/json-reports/clinic-flow-provider-statistics-base.json new file mode 100644 index 000000000..143c602c3 --- /dev/null +++ b/app/reporting-framework/json-reports/clinic-flow-provider-statistics-base.json @@ -0,0 +1,174 @@ +{ + "name": "clinicFlowProviderStatisticsBase", + "version": "1.0", + "tag": "", + "description": "", + "uses": [], + "sources": [ + { + "table": "etl.flat_appointment", + "alias": "t2" + }, + { + "table": "amrs.encounter", + "alias": "ae", + "join": { + "type": "LEFT", + "joinCondition": "ae.encounter_id = t2.encounter_id" + } + }, + { + "table": "amrs.visit", + "alias": "v", + "join": { + "type": "LEFT", + "joinCondition": "ae.visit_id = v.visit_id" + } + }, + { + "table": "amrs.users", + "alias": "t10", + "join": { + "type": "LEFT", + "joinCondition": "v.creator = t10.user_id" + } + }, + { + "table": "amrs.person", + "alias": "t11", + "join": { + "type": "LEFT", + "joinCondition": "t10.person_id = t11.person_id" + } + }, + { + "table": "amrs.encounter_provider", + "alias": "t6", + "join": { + "type": "INNER", + "joinCondition": "t2.encounter_id = t6.encounter_id" + } + }, + { + "table": "amrs.provider", + "alias": "t7", + "join": { + "type": "INNER", + "joinCondition": "t7.provider_id = t6.provider_id" + } + }, + { + "table": "amrs.person", + "alias": "pp", + "join": { + "type": "INNER", + "joinCondition": "t7.person_id = pp.person_id AND pp.voided = 0" + } + }, + { + "table": "amrs.person_name", + "alias": "provider_name", + "join": { + "type": "INNER", + "joinCondition": "provider_name.person_id = pp.person_id AND provider_name.voided = 0" + } + }, + { + "table": "amrs.encounter_type", + "alias": "t9", + "join": { + "type": "INNER", + "joinCondition": "t9.encounter_type_id = t2.encounter_type" + } + }, + { + "table": "amrs.location", + "alias": "l", + "join": { + "type": "INNER", + "joinCondition": "t2.location_id = l.location_id" + } + } + ], + "columns": [ + { + "type": "simple_column", + "alias": "visit_start", + "column": "v.date_started" + }, + { + "type": "simple_column", + "alias": "person_id", + "column": "t2.person_id" + }, + { + "type": "simple_column", + "alias": "visit_person_id", + "column": "t10.person_id" + }, + { + "type": "simple_column", + "alias": "Encounter Type", + "column": "t9.name" + }, + { + "type": "simple_column", + "alias": "location", + "column": "l.name" + }, + { + "type": "derived_column", + "alias": "provider", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": " CONCAT(COALESCE(provider_name.given_name, ''), ' ', COALESCE(provider_name.middle_name, ''), ' ', COALESCE(provider_name.family_name, ''))" + } + }, + { + "type": "derived_column", + "alias": "seen", + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "IF(t2.encounter_id IS NOT NULL,1,NULL)" + } + }, + { + "type": "derived_column", + "alias": "visit_started", + "expressionType": "case_statement", + "expressionOptions": { + "caseOptions": [ + { + "condition": "t7.person_id = t11.person_id", + "value": 1 + } + ] + } + } + ], + "filters": { + "conditionJoinOperator": "and", + "conditions": [ + { + "filterType": "tableColumns", + "conditionExpression": "t7.uuid = ?", + "parameterName": "providerUuid" + }, + { + "filterType": "tableColumns", + "conditionExpression": "DATE(t2.encounter_datetime) = ?", + "parameterName": "encounterDate" + }, + { + "filterType": "tableColumns", + "conditionExpression": "t2.encounter_type in (?)", + "parameterName": "encounterTypeId" + }, + { + "filterType": "tableColumns", + "conditionExpression": "l.uuid in (?)", + "parameterName": "locationUuid" + } + ] + } +} diff --git a/etl-routes.js b/etl-routes.js index bc73f1593..54e6ee606 100755 --- a/etl-routes.js +++ b/etl-routes.js @@ -75,6 +75,7 @@ import { HIVGainsAndLossesService } from './service/gains-and-losses/hiv-gains-l const cervicalCancerScreeningService = require('./service/cervical-cancer-screening-service'); import { MOH412Service } from './service/moh-412/moh-412'; import { DefaulterListService } from './service/defaulter-list-service'; +import { ClinicFlowService } from './service/clinic-flow-service'; module.exports = (function () { var routes = [ @@ -2143,6 +2144,43 @@ module.exports = (function () { } } }, + { + method: 'GET', + path: '/etl/clinic-flow-provider-statistics/patient-list', + config: { + auth: 'simple', + plugins: { + hapiAuthorization: { + role: privileges.canViewClinicDashBoard + } + }, + handler: function (request, reply) { + let requestParams = Object.assign({}, request.query, request.params); + requestParams.reportName = 'clinic-flow-provider-statistics-report'; + const clinicFlowService = new ClinicFlowService(); + clinicFlowService + .getPatientListReport(requestParams) + .then((results) => { + reply(results); + }) + .catch((error) => { + console.error(error); + reply(error); + }); + }, + description: + 'Get patient list for the provider statistics in clinic flow', + notes: + 'Returns a patient list for the provider statistics in clinic flow.', + tags: ['api'], + validate: { + options: { + allowUnknown: true + }, + params: {} + } + } + }, { method: 'GET', path: '/etl/clinic-lab-orders-data', diff --git a/report-post-processors/patient-flow-processor.js b/report-post-processors/patient-flow-processor.js index 60901b46f..9ebe72af0 100755 --- a/report-post-processors/patient-flow-processor.js +++ b/report-post-processors/patient-flow-processor.js @@ -122,6 +122,7 @@ function _handleEncouters(result, visit) { encounter_end: result.encounter_end, encounter_type_name: result.encounter_type_name, location: result.location, + encounter_location: result.location_uuid, person_name: (result.provider_given_name && result.provider_given_name != null @@ -133,7 +134,8 @@ function _handleEncouters(result, visit) { (result.provider_family_name && result.provider_family_name != null ? ' ' + result.provider_family_name : ''), - person_id: result.person_id + person_id: result.person_id, + provider_uuid: result.provider_uuid }; visit.encounters.push(encounter); diff --git a/reports/patient-flow-report.json b/reports/patient-flow-report.json index 7bdf5c15b..73c46864a 100755 --- a/reports/patient-flow-report.json +++ b/reports/patient-flow-report.json @@ -231,6 +231,11 @@ "type": "single", "sql": "t7.person_id" }, + { + "label": "provider_uuid", + "type": "single", + "sql": "t7.uuid" + }, { "label": "visit_person_id", "type": "single", @@ -280,6 +285,11 @@ "label": "location_id", "type": "single", "sql": "t12.location_id" + }, + { + "label": "location_uuid", + "type": "single", + "sql": "t12.uuid" } ], "indicatorHandlers": [ diff --git a/service/clinic-flow-service.js b/service/clinic-flow-service.js new file mode 100644 index 000000000..a5deffaea --- /dev/null +++ b/service/clinic-flow-service.js @@ -0,0 +1,42 @@ +import { PatientlistMysqlReport } from '../app/reporting-framework/patientlist-mysql.report'; +const helpers = require('../etl-helpers'); + +export class ClinicFlowService { + getAggregateReport(reportParams) {} + + getPatientListReport(reportParams) { + let indicators = reportParams.indicators + ? reportParams.indicators.split(',') + : []; + + let report = new PatientlistMysqlReport( + 'clinicFlowProviderStatisticsAggregate', + reportParams + ); + + return new Promise(function (resolve, reject) { + report + .generatePatientListReport(indicators) + .then((results) => { + results.results.results.forEach((element) => { + if (element.cur_meds) { + element.cur_meds = helpers.getARVNames(element.cur_meds); + } + if (element.arv_first_regimen) { + element.arv_first_regimen = helpers.getARVNames( + element.arv_first_regimen + ); + } + }); + + results['results'] = results.results.results; + delete [results.results]; + resolve(results); + }) + .catch((errors) => { + console.error('Error', errors); + reject(errors); + }); + }); + } +}