Skip to content

Commit

Permalink
Merge branch 'master' into POC-560
Browse files Browse the repository at this point in the history
  • Loading branch information
sainingo authored Aug 2, 2024
2 parents 6be8b9f + f0ca347 commit 7f48485
Show file tree
Hide file tree
Showing 83 changed files with 27,340 additions and 7,197 deletions.
13 changes: 13 additions & 0 deletions app/amrs-3.x/amrs_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const axios = require('axios');
try {
const formData = {
user: '1'
};
const formBody = querystring.stringify(formData);
request = await axios.post(
'https://ngx.ampath.or.ke/amrs-id-generator/generateidentifier',
formBody
);
} catch (error) {
reply.response('Internal Server Error').code(500);
}
34 changes: 21 additions & 13 deletions app/lab-integration/utils/lab-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class LabClient {
return this.postViralLoad(payload);
case 3:
return this.postCD4(payload);
case 5:
return this.postHPV(payload);
default:
break;
}
Expand All @@ -84,20 +86,26 @@ export class LabClient {
postCD4(payload) {
return this.getPostRequest(payload, `${this.config.serverUrl}/api/cd4`);
}

postHPV(payload) {
return this.getPostRequest(payload, `${this.config.serverUrl}/api/hpv`);
}
getPostRequest(payload, endpoint) {
const options = {
uri: endpoint,
headers: {
apikey: this.config.apiKey,
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'POST',
// json: true,
form: payload,
timeout: 40000
};
return rp(options);
try {
const options = {
uri: endpoint,
headers: {
apikey: this.config.apiKey,
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'POST',
// json: true,
form: payload,
timeout: 40000
};
return rp(options);
} catch (error) {
console.log('getPostRequestError', error.message);
}
}

getFetchRequest(filterOptions, offset) {
Expand Down
11 changes: 11 additions & 0 deletions app/lab-integration/utils/poc-eid-payload-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
amrs_location: getLocation(payload, 'mrsId')
};
break;
case 'HPV':
eidPayload = {
test: 5,
mflCode: getLocation(payload, 'mflCode'),
patient_identifier: payload.patientIdentifier,
dob: payload.birthDate,
order_no: payload.orderNumber,
datecollected: payload.dateDrawn,
sex: getGenderCode(payload.sex)
};
break;
case 'DNAPCR':
eidPayload = {
test: 1,
Expand Down
54 changes: 54 additions & 0 deletions app/otz/cohort-module.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var db = require('../../etl-db');

export class CohortModuleService {
getCohortSummary = (cohortUuids) => {
const uuids = cohortUuids
.split(',')
.map((s) => {
return `"${s}"`;
})
.join(',');
return new Promise((resolve, reject) => {
let queryParts = {};
const sql = `SELECT
c.uuid,
COUNT(DISTINCT cm.patient_id) AS total_patients,
IFNULL(SUM(CASE
WHEN fl.hiv_viral_load < 200 THEN 1
ELSE 0
END) / NULLIF(COUNT(DISTINCT cm.patient_id), 0) * 100,
0) AS suppression_rate_percentage
FROM
amrs.cohort c
LEFT JOIN
amrs.location l ON l.location_id = c.location_id
INNER JOIN
amrs.cohort_member cm ON c.cohort_id = cm.cohort_id
LEFT JOIN
(SELECT
person_id, MAX(test_datetime) AS latest_test_datetime
FROM
etl.flat_labs_and_imaging
WHERE
hiv_viral_load IS NOT NULL
GROUP BY person_id) AS latest_tests ON cm.patient_id = latest_tests.person_id
LEFT JOIN
etl.flat_labs_and_imaging fl ON latest_tests.person_id = fl.person_id
AND latest_tests.latest_test_datetime = fl.test_datetime
WHERE
l.uuid = '${cohortUuids}'
GROUP BY c.cohort_id;
`;

queryParts = {
sql: sql
};

return db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result);
});
});
};
}
194 changes: 193 additions & 1 deletion app/reporting-framework/base-mysql.report.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,63 @@ import * as txrtt_aggregate_report from './json-reports/tx-reports/tx-rtt/tx-rtt
import * as txrtt_base_report from './json-reports/tx-reports/tx-rtt/tx-rtt-report-base.json';
import * as txrtt_summary from './json-reports/txrtt-summary.json';

//plhiv-ncd report
import * as plhiv_ncd_v2_monthly_report from './json-reports/plhiv-ncd-v2-reports/plhiv-ncd-v2-report.json';

import * as htn_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/hypertensive/htn-base.json';
import * as htn_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/hypertensive/htn-aggregate.json';

import * as dm_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/diabetic/dm-base.json';
import * as dm_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/diabetic/dm-aggregate.json';

import * as mh_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/mh-base.json';
import * as mh_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/mh-aggregate.json';

import * as dep_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/depressive-base.json';
import * as dep_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/depressive-aggregate.json';

import * as anx_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/anxiety-base.json';
import * as anx_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/anxiety-aggregate.json';

import * as bip_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/bipolar-and-related-mh-base.json';
import * as bip_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/bipolar-and-related-mh-aggregate.json';

import * as per_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/personality-mh-base.json';
import * as per_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/personality-mh-aggregate.json';

import * as fed_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/feeding-and-eating-mh-base.json';
import * as fed_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/feeding-and-eating-mh-aggregate.json';

import * as ocd_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/ocd-base.json';
import * as ocd_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/ocd-aggregate.json';

import * as genMD_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/general-mental-disorder-base.json';
import * as genMD_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/general-mental-disorder-aggregate.json';

import * as stMD_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/status-sub-total-base.json';
import * as stMD_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/status-sub-total-aggregate.json';

import * as totMD_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/total-mh-base.json';
import * as totMD_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/mental-health-disorder/total-mh-aggregate.json';

import * as cvd_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/cardiovascular-disease/cvd-base.json';
import * as cvd_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/cardiovascular-disease/cvd-aggregate.json';

import * as neu_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/neurological-disease/neuro-base.json';
import * as neu_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/neurological-disease/neuro-aggregate.json';

import * as rhe_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/rheumatologic-disease/rheu-base.json';
import * as rhe_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/rheumatologic-disease/rheu-aggregate.json';

import * as kd_plhiv_base from './json-reports/plhiv-ncd-v2-reports/disaggregations/kidney-disease/kd-base.json';
import * as kd_plhiv_aggregate from './json-reports/plhiv-ncd-v2-reports/disaggregations/kidney-disease/kd-aggregate.json';
//ahd report
import * as ahd_monthly_summary from './json-reports/ahd_reports/ahd-monthly.json';
import * as ahd_monthly_aggregate from './json-reports/ahd_reports/ahd-monthly-aggregate.json';
import * as ahd_cohort_monthly_aggregate from './json-reports/ahd_reports/ahd-cohort-monthly-aggregate.json';
import * as ahd_monthly_dataset_base from './json-reports/ahd_reports/ahd-monthly-dataset-base.json';
import * as ahd_cohort_monthly_dataset_base from './json-reports/ahd_reports/ahd-cohort-monthly-dataset-base.json';
import * as ahd_monthly_patient_list_template from './json-reports/ahd_reports/ahd_monthly_patient_list_template_post.json';
export class BaseMysqlReport {
constructor(reportName, params) {
this.reportName = reportName;
Expand Down Expand Up @@ -977,6 +1034,40 @@ export class BaseMysqlReport {
prepDatasetReport: this.cloneJsonSchema(prep_dataset_report)
});
break;
case 'ahd-monthly-summary':
resolve({
main: this.cloneJsonSchema(ahd_monthly_summary)
});
break;
case 'ahdMonthlySummaryReport':
resolve({
main: this.cloneJsonSchema(ahd_monthly_summary),
ahdMonthlyDataSetBase: this.cloneJsonSchema(
ahd_monthly_dataset_base
)
});
break;
case 'ahd-monthly-report-patient-list-template':
resolve({
main: this.cloneJsonSchema(ahd_monthly_patient_list_template)
});
break;
case 'ahdMonthlyAggregate':
resolve({
main: this.cloneJsonSchema(ahd_monthly_aggregate),
ahdMonthlyDataSetBase: this.cloneJsonSchema(
ahd_monthly_dataset_base
)
});
break;
case 'ahdCohortMonthlyAggregate':
resolve({
main: this.cloneJsonSchema(ahd_cohort_monthly_aggregate),
ahdCohortMonthlyDataSetBase: this.cloneJsonSchema(
ahd_cohort_monthly_dataset_base
)
});
break;
case 'surgeBaselineReport':
resolve({
main: this.cloneJsonSchema(ltfu_surge_baseline_aggregate_report),
Expand Down Expand Up @@ -1795,6 +1886,107 @@ export class BaseMysqlReport {
main: this.cloneJsonSchema(txrtt_summary)
});
break;
case 'plhiv-ncd-v2-monthly-report':
resolve({
main: this.cloneJsonSchema(plhiv_ncd_v2_monthly_report)
});
break;
case 'htnPlhivAggregate':
resolve({
main: this.cloneJsonSchema(htn_plhiv_aggregate),
htnPlhivBase: this.cloneJsonSchema(htn_plhiv_base)
});
break;
case 'dmPlhivAggregate':
resolve({
main: this.cloneJsonSchema(dm_plhiv_aggregate),
dmPlhivBase: this.cloneJsonSchema(dm_plhiv_base)
});
break;

case 'depPlhivAggregate':
resolve({
main: this.cloneJsonSchema(dep_plhiv_aggregate),
depPlhivBase: this.cloneJsonSchema(dep_plhiv_base)
});
break;

case 'anxPlhivAggregate':
resolve({
main: this.cloneJsonSchema(anx_plhiv_aggregate),
anxPlhivBase: this.cloneJsonSchema(anx_plhiv_base)
});
break;

case 'bipPlhivAggregate':
resolve({
main: this.cloneJsonSchema(bip_plhiv_aggregate),
bipPlhivBase: this.cloneJsonSchema(bip_plhiv_base)
});
break;

case 'perPlhivAggregate':
resolve({
main: this.cloneJsonSchema(per_plhiv_aggregate),
perPlhivBase: this.cloneJsonSchema(per_plhiv_base)
});
break;
case 'fedPlhivAggregate':
resolve({
main: this.cloneJsonSchema(fed_plhiv_aggregate),
fedPlhivBase: this.cloneJsonSchema(fed_plhiv_base)
});
break;

case 'ocdPlhivAggregate':
resolve({
main: this.cloneJsonSchema(ocd_plhiv_aggregate),
ocdPlhivBase: this.cloneJsonSchema(ocd_plhiv_base)
});
break;

case 'genMDPlhivAggregate':
resolve({
main: this.cloneJsonSchema(genMD_plhiv_aggregate),
genMDPlhivBase: this.cloneJsonSchema(genMD_plhiv_base)
});
break;
case 'stMDPlhivAggregate':
resolve({
main: this.cloneJsonSchema(stMD_plhiv_aggregate),
stMDPlhivBase: this.cloneJsonSchema(stMD_plhiv_base)
});
break;
case 'totMDPlhivAggregate':
resolve({
main: this.cloneJsonSchema(totMD_plhiv_aggregate),
totMDPlhivBase: this.cloneJsonSchema(totMD_plhiv_base)
});
break;
case 'cvdPlhivAggregate':
resolve({
main: this.cloneJsonSchema(cvd_plhiv_aggregate),
cvdPlhivBase: this.cloneJsonSchema(cvd_plhiv_base)
});
break;
case 'neuPlhivAggregate':
resolve({
main: this.cloneJsonSchema(neu_plhiv_aggregate),
neuPlhivBase: this.cloneJsonSchema(neu_plhiv_base)
});
break;
case 'rhePlhivAggregate':
resolve({
main: this.cloneJsonSchema(rhe_plhiv_aggregate),
rhePlhivBase: this.cloneJsonSchema(rhe_plhiv_base)
});
break;
case 'kdPlhivAggregate':
resolve({
main: this.cloneJsonSchema(kd_plhiv_aggregate),
kdPlhivBase: this.cloneJsonSchema(kd_plhiv_base)
});
break;
default:
reject('Unknown report ', reportName);
break;
Expand Down Expand Up @@ -1829,7 +2021,7 @@ export class BaseMysqlReport {
});
})
.catch((error) => {
// console.error('Error Executing Mysql Query', error);
console.error('Error Executing Mysql Query', error);
reject(error);
});
});
Expand Down
2 changes: 2 additions & 0 deletions app/reporting-framework/hiv/moh-731.report.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class Moh731Report extends MultiDatasetPatientlistReport {
params.hivMonthlyDatasetSource = 'etl.hiv_monthly_report_dataset_frozen'; // defaults to frozen
params.hivVlDataSource =
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)';
params.hivSummaryDataSource =
'(SELECT fhsvb.person_id, fhsvb.weight, fhsvb.height, fhsvb.cur_who_stage as stage FROM etl.flat_hiv_summary_v15b fhsvb where fhsvb.is_clinical_encounter = 1 and fhsvb.next_clinical_datetime_hiv is null)';
console.log('creating new moh 731 report service');
super(reportName, params);
}
Expand Down
Loading

0 comments on commit 7f48485

Please sign in to comment.