forked from AMPATH/etl-rest-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIV-855: Defaulter Module Not Generating the Correct Report
- Loading branch information
1 parent
4922e61
commit faa00ec
Showing
5 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/reporting-framework/json-reports/defaulter-list-aggregate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "defaulterListAggregate", | ||
"version": "1.0", | ||
"tag": "", | ||
"description": "", | ||
"uses": [ | ||
{ | ||
"name": "defaulterListBase", | ||
"version": "1.0", | ||
"type": "dataset_def" | ||
} | ||
], | ||
"sources": [ | ||
{ | ||
"dataSet": "defaulterListBase", | ||
"alias": "t2" | ||
} | ||
], | ||
"columns": [ | ||
{ | ||
"type": "simple_column", | ||
"alias": "person_id", | ||
"column": "t2.person_id" | ||
}, | ||
{ | ||
"type": "simple_column", | ||
"alias": "total_defaulted", | ||
"column": "count(distinct t2.person_id)" | ||
} | ||
], | ||
"groupBy": { | ||
"groupParam": "groupByParam", | ||
"columns": ["person_id"], | ||
"excludeParam": "excludeParam" | ||
}, | ||
"dynamicJsonQueryGenerationDirectives": { | ||
"patientListGenerator": { | ||
"useTemplate": "patient-list-template", | ||
"useTemplateVersion": "1.0", | ||
"generatingDirectives": { | ||
"joinDirectives": { | ||
"joinType": "INNER", | ||
"joinCondition": "<<base_column>> = <<template_column>>", | ||
"baseColumn": "person_id", | ||
"templateColumn": "person_id" | ||
} | ||
} | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/reporting-framework/json-reports/defaulter-list-base.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"name": "defaulterListBase", | ||
"version": "1.0", | ||
"tag": "", | ||
"description": "", | ||
"uses": [], | ||
"sources": [ | ||
{ | ||
"table": "etl.flat_defaulters", | ||
"alias": "fd" | ||
}, | ||
{ | ||
"table": "etl.flat_hiv_summary_v15b", | ||
"alias": "de", | ||
"join": { | ||
"type": "LEFT", | ||
"joinCondition": "de.encounter_id = fd.encounter_id" | ||
} | ||
}, | ||
{ | ||
"table": "etl.program_visit_map", | ||
"alias": "pm", | ||
"join": { | ||
"type": "LEFT", | ||
"joinCondition": "de.visit_type = pm.visit_type_id" | ||
} | ||
}, | ||
{ | ||
"table": "amrs.program", | ||
"alias": "p", | ||
"join": { | ||
"type": "LEFT", | ||
"joinCondition": "p.program_id = pm.program_type_id" | ||
} | ||
} | ||
], | ||
"columns": [ | ||
{ | ||
"type": "simple_column", | ||
"alias": "person_id", | ||
"column": "fd.person_id" | ||
}, | ||
{ | ||
"type": "simple_column", | ||
"alias": "filed_id", | ||
"column": "fd.filed_id" | ||
}, | ||
{ | ||
"type": "simple_column", | ||
"alias": "days_since_rtc", | ||
"column": "fd.days_since_rtc" | ||
}, | ||
{ | ||
"type": "simple_column", | ||
"alias": "program", | ||
"column": "p.name" | ||
}, | ||
{ | ||
"type": "simple_column", | ||
"alias": "rtc_date", | ||
"column": "DATE_FORMAT(fd.rtc_date,'%Y-%m-%d')" | ||
} | ||
], | ||
"filters": { | ||
"conditionJoinOperator": "and", | ||
"conditions": [ | ||
{ | ||
"filterType": "tableColumns", | ||
"conditionExpression": "fd.days_since_rtc >= ?", | ||
"parameterName": "defaulterPeriod" | ||
}, | ||
{ | ||
"filterType": "tableColumns", | ||
"conditionExpression": "fd.days_since_rtc <= ?", | ||
"parameterName": "maxDefaultPeriod" | ||
}, | ||
{ | ||
"filterType": "tableColumns", | ||
"conditionExpression": "fd.location_id in (?)", | ||
"parameterName": "locations" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const dao = require('../etl-dao'); | ||
const Promise = require('bluebird'); | ||
const _ = require('lodash'); | ||
import { BaseMysqlReport } from '../app/reporting-framework/base-mysql.report'; | ||
import { PatientlistMysqlReport } from '../app/reporting-framework/patientlist-mysql.report'; | ||
|
||
export class DefaulterListService { | ||
getAggregateReport(reportParams) { | ||
return new Promise(function (resolve, reject) { | ||
let report; | ||
|
||
report = new BaseMysqlReport( | ||
'defaulterListAggregate', | ||
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); | ||
// TODO Do some post processing | ||
}).catch((errors) => { | ||
reject(errors); | ||
}); | ||
}); | ||
} | ||
|
||
getPatientListReport(reportParams) { | ||
let indicators = reportParams.indicators | ||
? reportParams.indicators.split(',') | ||
: []; | ||
delete reportParams['gender']; | ||
|
||
let report = new PatientlistMysqlReport( | ||
'defaulterListAggregate', | ||
reportParams | ||
); | ||
|
||
return new Promise(function (resolve, reject) { | ||
Promise.join(report.generatePatientListReport(indicators), (results) => { | ||
results['result'] = results.results.results; | ||
delete results['results']; | ||
resolve(results); | ||
}).catch((errors) => { | ||
console.log('Error', errors); | ||
reject(errors); | ||
}); | ||
}); | ||
} | ||
} |