Skip to content

Commit

Permalink
HIV-851: Clinic Flow Provider Statistics to Generate Patient List (AM…
Browse files Browse the repository at this point in the history
  • Loading branch information
maikofelix47 authored Nov 2, 2021
1 parent 3faacda commit d442bd5
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/reporting-framework/base-mysql.report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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": "<<base_column>> = <<template_column>>",
"baseColumn": "person_id",
"templateColumn": "person_id"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
38 changes: 38 additions & 0 deletions etl-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion report-post-processors/patient-flow-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions reports/patient-flow-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
"type": "single",
"sql": "t7.person_id"
},
{
"label": "provider_uuid",
"type": "single",
"sql": "t7.uuid"
},
{
"label": "visit_person_id",
"type": "single",
Expand Down Expand Up @@ -280,6 +285,11 @@
"label": "location_id",
"type": "single",
"sql": "t12.location_id"
},
{
"label": "location_uuid",
"type": "single",
"sql": "t12.uuid"
}
],
"indicatorHandlers": [
Expand Down
42 changes: 42 additions & 0 deletions service/clinic-flow-service.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
}

0 comments on commit d442bd5

Please sign in to comment.