Skip to content

Commit

Permalink
POC-737: Added pnc and maternity endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Mutai committed Oct 31, 2024
1 parent d1d3419 commit 1ebc183
Show file tree
Hide file tree
Showing 3 changed files with 8,437 additions and 12,904 deletions.
203 changes: 203 additions & 0 deletions app/moh-registers/registers-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,209 @@ var defs = {
resolve(result.result);
});
});
},
getPNCRegisterData: (params) => {
return new Promise((resolve, reject) => {
let queryParts = {};
const sql = `
select
a.encounter_datetime as date_of_visit,
b.identifier as pnc_number,
c.identifier as NUPI,
c.identifier as pncNumber_or_NUPI,
concat(d.given_name, ' ', d.middle_name, ' ', d.family_name) as full_names,
e.birthdate as date_of_birth,
timestampdiff(year,
e.birthdate,
a.encounter_datetime) as age,
f.county_district as county_subcounty,
f.city_village as village_estate_landmark,
g.value as telephone_number,
a.day_of_delivery as date_of_delivery,
a.place_of_delivery as place_of_delivery,
a.mode_of_delivery as mode_of_delivery,
null as timing_mother,
null as timing_baby,
a.temperature as temp,
a.pulse as pulse,
a.blood_pressure as blood_pressure,
a.pallor as pallor,
null as pallor_type,
a.breast as breast,
a.uterus as uterus,
a.pph as PPH,
a.c_section_site as c_section_site,
a.lochia as lochia,
a.episiotomy as episiotomy,
a.fistula as fistula,
a.tb_screening as tb_screening,
a.tested_pnc as tested_pnc,
a.hiv_test_1_kit_name as hiv_test_1_kit_name,
a.hiv_test_1_lot_no as hiv_test_1_lot_no,
a.hiv_test_1_expiry_date as hiv_test_1_expiry_no,
a.hiv_test_2_kit_name as hiv_test_2_kit_name,
a.hiv_test_2_lot_no as hiv_test_2_lot_no,
a.hiv_test_2_expiry_date as hiv_test_2_expiry_no,
a.hiv_test_3_kit_name as hiv_test_3_kit_name,
a.hiv_test_3_lot_no as hiv_test_3_lot_no,
a.hiv_test_3_expiry_date as hiv_test_3_expiry_no,
a.pnc_at_6_weeks_or_less as pnc_results_6_weeks_or_less,
a.pnc_at_more_than_6_weeks as pnc_results_more_than_6_weeks,
a.infant_prophylaxis_at_6_weeks_or_less as infant_prophylaxis_less_6_weeks,
a.infant_prophylaxis_at_more_than_6_weeks as infant_prophylaxis_greater_6_weeks,
a.maternal_haart_at_6_weeks_or_less as maternal_haart_less_6_weeks,
a.maternal_haart_at_more_than_6_weeks as maternal_haart_greater_6_weeks,
a.cervical_cancer_method as cacx_method,
a.cervical_cancer_result as cacx_results,
a.ppfp_done as PPFP,
a.ppfp_method as PPFP_couselled_method_received,
a.other_complications as other_maternal_complications,
a.haematinics as haematinics,
a.referrals_from as referrals_from,
a.referrals_to as referrals_to,
a.reason_for_referral as reason_for_referral,
a.remarks as remarks
from
etl.flat_mnch_summary a
left JOIN
amrs.patient_identifier b on
a.person_id = b.patient_id
AND b.identifier_type = 48
INNER JOIN
amrs.patient_identifier c ON
a.person_id = c.patient_id
AND c.identifier_type = 45
left join amrs.person_name d on
d.person_id = a.person_id
left join amrs.person e on
e.person_id = a.person_id
left join amrs.location f on
f.location_id = a.location_id
left join amrs.person_attribute g on
g.person_id = a.person_id
AND g.person_attribute_type_id = 10
where
DATE(a.encounter_datetime)= '${params.endDate}'
AND f.uuid in (${params.locationUuids});
`;
queryParts = {
sql: sql
};
return db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result.result);
});
});
},
getMatRegisterData: (params) => {
return new Promise((resolve, reject) => {
let queryParts = {};
const sql = `
select
a.encounter_datetime as admission_date,
null as admission_number,
b.identifier as NUPI,
concat(c.given_name, ' ', c.middle_name, ' ', c.family_name) as full_names,
h.birthdate as date_of_birth,
timestampdiff(year,
h.birthdate,
a.encounter_datetime) as age,
d.county_district as county_subcounty,
d.city_village as village_estate_landmark,
f.value as phone_number,
case
when g.value = 555 THEN 'MARRIED'
when g.value = 1059 THEN 'WIDOWED'
when g.value = 1057 THEN 'NEVER MARRIED'
when g.value = 1175 THEN 'NOT APPLICABLE'
when g.value = 1056 THEN 'SEPARATED'
end as marital_status,
a.parity as parity,
a.gravidae as gravidae,
a.anc_visit_no as no_of_anc_visits,
a.last_lmp_date as lmp,
a.edd as edd,
a.diagnosis as diagnosis,
a.duration_of_delivery as duration_of_labour,
a.day_of_delivery as date_of_delivery,
a.time_of_delivery as time_of_delivery,
a.gestation_at_birth as gestation_at_birth,
a.mode_of_delivery as mode_of_delivery,
a.no_of_babies as no_of_babies_delivered,
a.placenta_complete as placenta_complete,
a.uterotonic_given as uterotonic_given,
a.vaginal_examination as vaginal_examination,
a.blood_loss as blood_loss,
a.mothers_status_after_delivery as mothers_status_after_delivery,
null as maternal_deaths_notified,
a.maternal_death_notified as date_death_notified,
a.delivery_complications as delivery_complications,
a.apgar_score as apgaar_score,
a.birth_outcome as birth_outcome,
a.birth_weight as birth_weight,
a.baby_sex as sex,
a.BF_in_one_hour as initiated_on_BF_less_1hr,
a.kangaroo_mother_care as kangaroo_mother_care,
a.teo_at_birth as teo_given_at_birth,
a.chlorhexidine_for_cord as chlorhexidine_applied_at_cord_stamp,
a.birth_with_deformity as birth_with_deformity,
a.type_of_deformity as type_of_deformity,
a.vitamin_k as given_vitamin_K,
a.rpr_test_result as vdrl_rpr,
a.vdrl_test_result as vdrl_rpr_results,
a.hiv_test_1_kit_name as hiv_test_1_kit_name,
a.hiv_test_1_lot_no as hiv_test_1_lot_no,
a.hiv_test_1_expiry_date as h1v_test_1_expiry,
a.hiv_test_2_kit_name as hiv_test_2_kit_name,
a.hiv_test_2_lot_no as hiv_test_2_lot_no,
a.hiv_test_2_expiry_date as hiv_test_2_expiry,
a.hiv_test_3_kit_name as hiv_test_3_kit_name,
a.hiv_test_3_lot_no as hiv_test_3_lot_no,
a.hiv_test_3_expiry_date as hiv_test_3_expiry,
a.hiv_test_3_test_result as hiv_result_maternity,
a.hiv_test_type as hiv_test_type,
a.maternal_haart as maternal_haart,
a.infant_prophylaxis as infant_prophylaxis,
null as partner_tested_for_hiv,
a.infant_feeding_counselling as couselled_on_infant_feeding,
a.delivery_conducted_by as delivery_conducted_by,
a.birth_notification_number as birth_notification_number,
a.discharge_date as discharge_date,
a.baby_status_on_discharge as discharge_status_of_baby,
a.referrals_from as referrals_from,
a.referrals_to as referrals_to,
a.reason_for_referral as reason_for_referral,
a.remarks as comments
from
etl.flat_mnch_summary a
INNER JOIN
amrs.patient_identifier b ON
a.person_id = b.patient_id
AND b.identifier_type = 45
left join amrs.person_name c on
c.person_id = a.person_id
left join amrs.location d on
d.location_id = a.location_id
left join amrs.person_attribute f on
f.person_id = a.person_id
AND f.person_attribute_type_id = 10
left join amrs.person_attribute g on
g.person_id = a.person_id
AND g.person_attribute_type_id = 5
left join amrs.person h on
h.person_id = a.person_id
where
DATE(a.encounter_datetime)= '${params.endDate}'
AND d.uuid in (${params.locationUuids});
`;
queryParts = {
sql: sql
};
return db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result.result);
});
});
}
};

Expand Down
52 changes: 52 additions & 0 deletions app/routes/registers-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,58 @@ const routes = [
params: {}
}
}
},
{
method: 'GET',
path: '/etl/registers/pncregister',
config: {
plugins: {},
handler: function (request, reply) {
registersmappings
.getPNCRegisterData(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: {}
}
}
},
{
method: 'GET',
path: '/etl/registers/maternityregister',
config: {
plugins: {},
handler: function (request, reply) {
registersmappings
.getMatRegisterData(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: {}
}
}
}
];

Expand Down
Loading

0 comments on commit 1ebc183

Please sign in to comment.