Skip to content

Commit

Permalink
POC-745:
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Mutai committed Jun 6, 2024
1 parent db9b16f commit 43cea83
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 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);

0 comments on commit 43cea83

Please sign in to comment.