Skip to content

Commit

Permalink
Merge pull request #11 from Alfred-Mutai/POC-745
Browse files Browse the repository at this point in the history
Poc 745
  • Loading branch information
hiqedme authored Jul 1, 2024
2 parents 8ed6457 + 43cea83 commit 3a8e362
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
20 changes: 20 additions & 0 deletions app/facility-mappings/registers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var db = require('../../etl-db');

var defs = {
getPrEPRegisterData: (params) => {
return new Promise((resolve, reject) => {
let queryParts = {};
let sql =
'SELECT l.name as location_name, fps.encounter_id, pi.identifier AS PrEP_Number, pi2.identifier AS National_ID, pi3.identifier AS NUPI, fps.encounter_datetime AS Date_Of_Visit, EXTRACT(YEAR FROM fps.encounter_datetime) - EXTRACT(YEAR FROM fps.birthdate) - CASE WHEN (EXTRACT(MONTH FROM fps.encounter_datetime) < EXTRACT(MONTH FROM fps.birthdate)) OR (EXTRACT(MONTH FROM fps.encounter_datetime) = EXTRACT(MONTH FROM fps.birthdate) AND EXTRACT(DAY FROM fps.encounter_datetime) < EXTRACT(DAY FROM fps.birthdate)) THEN 1 ELSE 0 END Age, fps.gender AS Sex, fps.population_type, NULL AS client_prep_status, NULL AS prep_method, CASE WHEN COALESCE(fps.hiv_rapid_test_result) = 664 THEN "N" WHEN COALESCE(fps.hiv_rapid_test_result) = 703 THEN "P" END AS HIV_result, NULL AS with_STI, COALESCE(fps.initiation_reason, fps.discontinued_reason) AS remarks FROM etl.flat_prep_summary_v1_1 fps LEFT JOIN amrs.location l ON l.location_id = fps.location_id LEFT JOIN amrs.patient_identifier pi ON fps.person_id = pi.patient_id AND pi.identifier_type = 44 LEFT JOIN amrs.patient_identifier pi2 ON fps.person_id = pi2.patient_id AND pi2.identifier_type = 5 LEFT JOIN amrs.patient_identifier pi3 ON fps.person_id = pi3.patient_id AND pi3.identifier_type = 45 WHERE DATE(fps.encounter_datetime)= "2024-01-02" AND fps.location_id in (1,13,14)';
queryParts = {
sql: sql
};
return db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result.result);
});
});
}
};

module.exports = defs;
34 changes: 34 additions & 0 deletions app/routes/registers.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var authorizer = require('../../authorization/etl-authorizer');
var privileges = authorizer.getAllPrivileges();
var facilitymappings = require('../facility-mappings/registers');

const routes = [
{
method: 'GET',
path: '/etl/prepregisterdata',
config: {
plugins: {},
handler: function (request, reply) {
facilitymappings
.getPrEPRegisterData(request.query)
.then((result) => {
reply(result);
})
.catch((error) => {
reply(error);
});
},
description: 'List of facilities with MFL code',
notes: 'Returns facilities list',
tags: ['api'],
validate: {
options: {
allowUnknown: true
},
params: {}
}
}
}
];

exports.routes = (server) => server.route(routes);
4 changes: 3 additions & 1 deletion programs/patient-program-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"0904172d-0b6a-40df-b8a2-b3653d16dc45",
"a8e7c30d-6d2f-401c-bb52-d4433689a36b",
"f7793d42-11ac-4cfd-9b35-e0a21a7a7c31",
"c4246ff0-b081-460c-bcc5-b0678012659e"
"c4246ff0-b081-460c-bcc5-b0678012659e",
"52aeb285-fb18-455b-893e-3e53ccc77ceb",
"d2552058-d7bd-47c6-aed1-480a4308027a"
],
"visitTypes": [
{
Expand Down
40 changes: 38 additions & 2 deletions programs/scope-builder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,25 @@ function buildScope(dataDictionary) {
'0900831e-1352-11df-a1f1-0026b9348838',
'8f5694dc-cba7-47b5-a97c-677cfb9a8d7c',
'0900b74e-1352-11df-a1f1-0026b9348838',
'cb4a90fd-28b8-4c01-b15c-242ff5e5e731'
'cb4a90fd-28b8-4c01-b15c-242ff5e5e731',
'49fa8ba9-06f4-4072-afe7-fd3e51ed4482',
'8c7ec4f7-270c-45e9-a4f9-8589242d50d5',
'96d2964e-8cec-4eca-ad05-a9c1fb29a045',
'2b1d2083-b4df-4e5c-96fe-af88122ef75b',
'0db6a78c-6b64-420c-bc30-ac403417c237',
'2c89c870-560d-4521-90f9-b62f56939595',
'ce8089a9-d105-4d79-8a0a-d4a389d691b4',
'3db5339b-491c-4e80-8c55-7ef21d7141e6',
'a580930d-9a57-48ec-aa3e-c170802f45b0',
'6b9bebc0-bea7-4c90-8dc8-4c14f33c96de',
'090089ea-1352-11df-a1f1-0026b9348838',
'e93d79ea-13c8-4f0c-a757-0858a7f387eb',
'19874e26-f614-47bb-99c7-a3756bfe3c64',
'b8135ddf-e02c-4098-b4ce-17880a9ddb0f',
'09004e76-1352-11df-a1f1-0026b9348838',
'e907044b-4170-49e1-98e8-93258596bb23',
'0900b000-1352-11df-a1f1-0026b9348838',
'b4f7483a-00b8-4ff4-be70-dfefc85c60fa'
].includes(dataDictionary.intendedVisitLocationUuid);
if (dataDictionary.patient) {
buildPatientScopeMembers(scope, dataDictionary.patient);
Expand Down Expand Up @@ -157,7 +175,25 @@ function buildScope(dataDictionary) {
'0900831e-1352-11df-a1f1-0026b9348838',
'8f5694dc-cba7-47b5-a97c-677cfb9a8d7c',
'0900b74e-1352-11df-a1f1-0026b9348838',
'cb4a90fd-28b8-4c01-b15c-242ff5e5e731'
'cb4a90fd-28b8-4c01-b15c-242ff5e5e731',
'49fa8ba9-06f4-4072-afe7-fd3e51ed4482',
'8c7ec4f7-270c-45e9-a4f9-8589242d50d5',
'96d2964e-8cec-4eca-ad05-a9c1fb29a045',
'2b1d2083-b4df-4e5c-96fe-af88122ef75b',
'0db6a78c-6b64-420c-bc30-ac403417c237',
'2c89c870-560d-4521-90f9-b62f56939595',
'ce8089a9-d105-4d79-8a0a-d4a389d691b4',
'3db5339b-491c-4e80-8c55-7ef21d7141e6',
'a580930d-9a57-48ec-aa3e-c170802f45b0',
'6b9bebc0-bea7-4c90-8dc8-4c14f33c96de',
'090089ea-1352-11df-a1f1-0026b9348838',
'e93d79ea-13c8-4f0c-a757-0858a7f387eb',
'19874e26-f614-47bb-99c7-a3756bfe3c64',
'b8135ddf-e02c-4098-b4ce-17880a9ddb0f',
'09004e76-1352-11df-a1f1-0026b9348838',
'e907044b-4170-49e1-98e8-93258596bb23',
'0900b000-1352-11df-a1f1-0026b9348838',
'b4f7483a-00b8-4ff4-be70-dfefc85c60fa'
].includes(dataDictionary.intendedVisitLocationUuid);
}

Expand Down

0 comments on commit 3a8e362

Please sign in to comment.