Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sainingo committed Nov 19, 2023
1 parent e680ab0 commit 611dab7
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
157 changes: 157 additions & 0 deletions app/otz/cohort-module.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
var db = require('../../etl-db');
var obs_service = require('../../service/openmrs-rest/obs.service');

export class CohortModuleService {
getCohortOtzModules = (cohortUuid) => {
return new Promise((resolve, reject) => {
let queryParts = {};
const sql = `SELECT
b.patient_id,
b.uuid,
MAX(b.mod1) AS mod1,
MAX(b.mod2) AS mod2,
MAX(b.mod3) AS mod3,
MAX(b.mod4) AS mod4,
MAX(b.mod5) AS mod5,
MAX(b.mod6) AS mod6,
MAX(b.mod7) AS mod7,
MAX(b.mod8) AS mod8
FROM
(SELECT
c.cohort_id,
c.name AS cohort_name,
cm.patient_id,
en.encounter_id,
en.encounter_datetime,
ob.value_coded,
ob.value_text,
ob.concept_id,
p.uuid,
CASE
WHEN
ob.concept_id = 11032
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11032
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod1',
CASE
WHEN
ob.concept_id = 11033
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11033
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod2',
CASE
WHEN
ob.concept_id = 11034
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11034
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod3',
CASE
WHEN
ob.concept_id = 11035
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11035
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod4',
CASE
WHEN
ob.concept_id = 9302
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 9302
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod5',
CASE
WHEN
ob.concept_id = 11037
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11037
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod6',
CASE
WHEN
ob.concept_id = 11038
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11038
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod7',
CASE
WHEN
ob.concept_id = 11039
AND ob.value_coded = 1065
THEN
TRUE
WHEN
ob.concept_id = 11039
AND ob.value_coded = 1066
THEN
FALSE
ELSE FALSE
END AS 'mod8'
FROM
amrs.cohort c
INNER JOIN amrs.cohort_member cm ON c.cohort_id = cm.cohort_id
INNER JOIN amrs.encounter en ON (en.patient_id = cm.patient_id
AND en.encounter_type = 284)
INNER JOIN amrs.obs ob ON ob.encounter_id = en.encounter_id
INNER JOIN amrs.person p ON p.person_id = cm.patient_id
WHERE
c.uuid = '${cohortUuid}'
AND en.voided = 0
AND ob.concept_id IN (11032 , 11033, 11034, 11035, 11036, 11037, 11038, 11039)) b
GROUP BY b.patient_id;`;

queryParts = {
sql: sql
};

return db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result);
});
});
};
}
26 changes: 26 additions & 0 deletions etl-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { getPatientCovidVaccinationStatus } from './service/covid-19/covid-19-va
import { Covid19MonthlyReport } from './service/covid-19/covid-19-monthly-report';
import { MlWeeklyPredictionsService } from './service/ml-weekly-predictions.service';
import { getPatientPredictedScore } from './service/predictions/ml-prediction-service';
import { CohortModuleService } from './app/otz/cohort-module.service';

module.exports = (function () {
var routes = [
Expand Down Expand Up @@ -6291,6 +6292,31 @@ module.exports = (function () {
notes: 'Returns the patients predictions data.',
tags: ['api']
}
},
{
method: 'GET',
path: '/etl/cohort-modules/{cohortUuid}',
config: {
auth: 'simple',
plugins: {},
handler: function (request, reply) {
const { cohortUuid } = request.params;
console.log('req', cohortUuid);
const cohortService = new CohortModuleService();
cohortService
.getCohortOtzModules(cohortUuid)
.then(function (cohortUsers) {
reply(cohortUsers);
})
.catch(function (error) {
reply(new Boom(500, 'Internal server error.', '', '', error));
});
},
description: 'Get cohort modules for otz cohort group',
notes:
'Api endpoint that returns cohort users based on the cohort uuid',
tags: ['api']
}
}
];

Expand Down
2 changes: 2 additions & 0 deletions programs/patient-program-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,8 @@
"uuid": "d3d5fd4a-508c-4610-97b7-5197a0bdb88d",
"name": "OTZ Visit ",
"groupVisit": true,
"allowedIf": "age >= 9 && age <= 19",
"message": "Patient has to be between the age of 9 and 19",
"encounterTypes": [
{
"uuid": "76680613-2974-4d89-9b85-6b0a4bf56267",
Expand Down

0 comments on commit 611dab7

Please sign in to comment.