From 5684581bcee9f3b3eb403b0c0fb2dfd9b173959f Mon Sep 17 00:00:00 2001 From: patryllus Date: Thu, 9 May 2024 18:53:24 +0300 Subject: [PATCH] Bug fixes for pop type: removed persons in prison not required, updated key pop to include all variables --- omod/src/main/resources/sql/DDL.sql | 1 - omod/src/main/resources/sql/DML.sql | 19 +++++++++++++---- omod/src/main/resources/sql/DataTools.sql | 1 - .../main/resources/sql/Scheduled_Updates.sql | 21 ++++++++++++++----- omod/src/main/resources/sql/dwapi/DDL.sql | 1 - omod/src/main/resources/sql/dwapi/DML.sql | 19 +++++++++++++---- 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/omod/src/main/resources/sql/DDL.sql b/omod/src/main/resources/sql/DDL.sql index 41c4c1d7..b5be2a8b 100644 --- a/omod/src/main/resources/sql/DDL.sql +++ b/omod/src/main/resources/sql/DDL.sql @@ -1286,7 +1286,6 @@ visit_date DATE, test_type INT(11) DEFAULT NULL, population_type VARCHAR(50), key_population_type VARCHAR(50), -people_in_prison VARCHAR(50), priority_population_type VARCHAR(50), ever_tested_for_hiv VARCHAR(10), months_since_last_test INT(11), diff --git a/omod/src/main/resources/sql/DML.sql b/omod/src/main/resources/sql/DML.sql index c6361d69..20e071ce 100644 --- a/omod/src/main/resources/sql/DML.sql +++ b/omod/src/main/resources/sql/DML.sql @@ -2555,7 +2555,6 @@ visit_date, test_type, population_type, key_population_type, -people_in_prison, priority_population_type, ever_tested_for_hiv, months_since_last_test, @@ -2608,8 +2607,20 @@ if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_l e.encounter_datetime as visit_date, max(if((o.concept_id=162084 and o.value_coded=162082 and f.uuid = "402dc5d7-46da-42d4-b2be-f43ea4ad87b0") or (f.uuid = "b08471f6-0892-4bf7-ab2b-bf79797b8ea4"), 2, 1)) as test_type , -- 2 for confirmation, 1 for initial max(if(o.concept_id=164930,(case o.value_coded when 164928 then "General Population" when 164929 then "Key Population" when 138643 then "Priority Population" else "" end),null)) as population_type, -max(if(o.concept_id=165241,(case o.value_coded when 163488 then "Community" when 1142 then "Staff" when 167691 then "Inmates" else "" end),null)) as people_in_prison, -max(if(o.concept_id=160581 and o.value_coded in(105,160578,160579,165100,162277,5622), (case o.value_coded when 105 then "People who inject drugs" when 160578 then "Men who have sex with men" when 160579 then "Female sex worker" when 165100 then "Transgender" when 162277 then "People in prison and other closed settings" when 5622 then "Other" else null end),null)) as key_population_type, +max(if((o.concept_id=160581 or o.concept_id=165241) and o.value_coded in (105,160666,160578,165084,160579,165100,162277,167691,1142,163488,159674,162198,6096,5622), (case o.value_coded when 105 then 'People who inject drugs' + when 160666 then 'People who use drugs' + when 160578 then 'Men who have sex with men' + when 165084 then 'Male Sex Worker' + when 160579 then 'Female sex worker' + when 165100 then 'Transgender' + when 162277 then 'People in prison and other closed settings' + when 167691 then 'Inmates' + when 1142 then 'Prison Staff' + when 163488 then 'Prison Community' + when 159674 then 'Fisher folk' + when 162198 then 'Truck driver' + when 6096 then 'Discordant' + when 5622 then 'Other' else null end),null)) as key_population_type, max(if(o.concept_id=160581 and o.value_coded in(159674,162198,160549,162277,1175,165192), (case o.value_coded when 159674 then "Fisher folk" when 162198 then "Truck driver" when 160549 then "Adolescent and young girls" when 162277 then "Prisoner" when 1175 then "Not applicable" when 165192 then "Military and other uniformed services" else null end),null)) as priority_population_type, max(if(o.concept_id=164401,(case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end),null)) as ever_tested_for_hiv, max(if(o.concept_id=159813,o.value_numeric,null)) as months_since_last_test, @@ -2668,7 +2679,7 @@ from encounter e inner join person p on p.person_id=e.patient_id and p.voided=0 inner join form f on f.form_id=e.form_id and f.uuid in ("402dc5d7-46da-42d4-b2be-f43ea4ad87b0","b08471f6-0892-4bf7-ab2b-bf79797b8ea4") inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (162084, 164930, 160581, 164401, 164951, 162558,160632, 1710, 164959, 164956,165241, - 160540,159427, 164848, 6096, 1659, 164952, 163042, 159813,165215,163556,161550,1887,1272,164359,160481,229,167163,167162,165093) + 160540,159427, 164848, 6096, 1659, 164952, 163042, 159813,165215,163556,161550,1887,1272,164359,160481,229,167163,167162,165093,165241) inner join ( select o.person_id, diff --git a/omod/src/main/resources/sql/DataTools.sql b/omod/src/main/resources/sql/DataTools.sql index 7a3f9cda..a9cf04c9 100644 --- a/omod/src/main/resources/sql/DataTools.sql +++ b/omod/src/main/resources/sql/DataTools.sql @@ -1337,7 +1337,6 @@ create table kenyaemr_datatools.hts_test t.test_type, t.population_type, t.key_population_type, - t.people_in_prison, t.priority_population_type, t.ever_tested_for_hiv, t.months_since_last_test, diff --git a/omod/src/main/resources/sql/Scheduled_Updates.sql b/omod/src/main/resources/sql/Scheduled_Updates.sql index 9db1a51a..ee45a6e7 100644 --- a/omod/src/main/resources/sql/Scheduled_Updates.sql +++ b/omod/src/main/resources/sql/Scheduled_Updates.sql @@ -2584,7 +2584,6 @@ CREATE PROCEDURE sp_update_hts_test(IN last_update_time DATETIME) test_type, population_type, key_population_type, - people_in_prison, priority_population_type, ever_tested_for_hiv, months_since_last_test, @@ -2637,9 +2636,22 @@ CREATE PROCEDURE sp_update_hts_test(IN last_update_time DATETIME) e.encounter_datetime as visit_date, max(if((o.concept_id=162084 and o.value_coded=162082 and f.uuid = "402dc5d7-46da-42d4-b2be-f43ea4ad87b0") or (f.uuid = "b08471f6-0892-4bf7-ab2b-bf79797b8ea4"), 2, 1)) as test_type , max(if(o.concept_id=164930,(case o.value_coded when 164928 then "General Population" when 164929 then "Key Population" when 138643 then "Priority Population" else null end),null)) as population_type, - max(if(o.concept_id=165241,(case o.value_coded when 163488 then "Community" when 1142 then "Staff" when 167691 then "Inmates" else "" end),null)) as people_in_prison, - max(if(o.concept_id=160581 and o.value_coded in(105,160578,160579,165100,162277,5622), (case o.value_coded when 105 then "People who inject drugs" when 160578 then "Men who have sex with men" when 160579 then "Female sex worker" when 165100 then "Transgender" when 162277 then "People in prison and other closed settings" when 5622 then "Other" else null end),null)) as key_population_type, - max(if(o.concept_id=160581 and o.value_coded in(159674,162198,160549,162277,1175,165192), (case o.value_coded when 159674 then "Fisher folk" when 162198 then "Truck driver" when 160549 then "Adolescent and young girls" when 162277 then "Prisoner" when 1175 then "Not applicable" when 165192 then "Military and other uniformed services" else null end),null)) as priority_population_type, + max(if((o.concept_id=160581 or o.concept_id=165241) and o.value_coded in (105,160666,160578,165084,160579,165100,162277,167691,1142,163488,159674,162198,6096,5622), (case o.value_coded when 105 then 'People who inject drugs' + when 160666 then 'People who use drugs' + when 160578 then 'Men who have sex with men' + when 165084 then 'Male Sex Worker' + when 160579 then 'Female sex worker' + when 165100 then 'Transgender' + when 162277 then 'People in prison and other closed settings' + when 167691 then 'Inmates' + when 1142 then 'Prison Staff' + when 163488 then 'Prison Community' + when 159674 then 'Fisher folk' + when 162198 then 'Truck driver' + when 6096 then 'Discordant' + when 5622 then 'Other' else null end),null)) as key_population_type, + + max(if(o.concept_id=160581 and o.value_coded in(159674,162198,160549,162277,1175,165192), (case o.value_coded when 159674 then "Fisher folk" when 162198 then "Truck driver" when 160549 then "Adolescent and young girls" when 162277 then "Prisoner" when 1175 then "Not applicable" when 165192 then "Military and other uniformed services" else null end),null)) as priority_population_type, max(if(o.concept_id=164401,(case o.value_coded when 1065 then "Yes" when 1066 then "No" else null end),null)) as ever_tested_for_hiv, max(if(o.concept_id=159813,o.value_numeric,null)) as months_since_last_test, max(if(o.concept_id=164951,(case o.value_coded when 1065 then "Yes" when 1066 then "No" else null end),null)) as patient_disabled, @@ -2733,7 +2745,6 @@ CREATE PROCEDURE sp_update_hts_test(IN last_update_time DATETIME) test_2_kit_lot_no=VALUES(test_2_kit_lot_no), test_2_kit_expiry=VALUES(test_2_kit_expiry), test_2_result=VALUES(test_2_result), test_3_kit_name=VALUES(test_3_kit_name), test_3_kit_lot_no=VALUES(test_3_kit_lot_no), test_3_kit_expiry=VALUES(test_3_kit_expiry), test_3_result=VALUES(test_3_result), - people_in_prison=VALUES(people_in_prison), final_test_result=VALUES(final_test_result), patient_given_result=VALUES(patient_given_result), couple_discordant=VALUES(couple_discordant),referred=VALUES(referred), tb_screening=VALUES(tb_screening), neg_referral_for=VALUES(neg_referral_for), patient_had_hiv_self_test=VALUES(patient_had_hiv_self_test), remarks=VALUES(remarks), voided=VALUES(voided) diff --git a/omod/src/main/resources/sql/dwapi/DDL.sql b/omod/src/main/resources/sql/dwapi/DDL.sql index a1f072c1..35451d86 100644 --- a/omod/src/main/resources/sql/dwapi/DDL.sql +++ b/omod/src/main/resources/sql/dwapi/DDL.sql @@ -1255,7 +1255,6 @@ visit_date DATE, test_type INT(11) DEFAULT NULL, population_type VARCHAR(50), key_population_type VARCHAR(50), -people_in_prison VARCHAR(50), priority_population_type VARCHAR(50), ever_tested_for_hiv VARCHAR(10), months_since_last_test INT(11), diff --git a/omod/src/main/resources/sql/dwapi/DML.sql b/omod/src/main/resources/sql/dwapi/DML.sql index a96e1f60..43b145cd 100644 --- a/omod/src/main/resources/sql/dwapi/DML.sql +++ b/omod/src/main/resources/sql/dwapi/DML.sql @@ -2545,7 +2545,6 @@ visit_date, test_type, population_type, key_population_type, -people_in_prison, priority_population_type, ever_tested_for_hiv, months_since_last_test, @@ -2599,8 +2598,20 @@ if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_l e.encounter_datetime as visit_date, max(if((o.concept_id=162084 and o.value_coded=162082 and f.uuid = "402dc5d7-46da-42d4-b2be-f43ea4ad87b0") or (f.uuid = "b08471f6-0892-4bf7-ab2b-bf79797b8ea4"), 2, 1)) as test_type , -- 2 for confirmation, 1 for initial max(if(o.concept_id=164930,(case o.value_coded when 164928 then "General Population" when 164929 then "Key Population" when 138643 then "Priority Population" else "" end),null)) as population_type, -max(if(o.concept_id=165241,(case o.value_coded when 163488 then "Community" when 1142 then "Staff" when 167691 then "Inmates" else "" end),null)) as people_in_prison, -max(if(o.concept_id=160581 and o.value_coded in(105,160578,160579,165100,162277,5622), (case o.value_coded when 105 then "People who inject drugs" when 160578 then "Men who have sex with men" when 160579 then "Female sex worker" when 165100 then "Transgender" when 162277 then "People in prison and other closed settings" when 5622 then "Other" else null end),null)) as key_population_type, +max(if((o.concept_id=160581 or o.concept_id=165241) and o.value_coded in (105,160666,160578,165084,160579,165100,162277,167691,1142,163488,159674,162198,6096,5622), (case o.value_coded when 105 then 'People who inject drugs' + when 160666 then 'People who use drugs' + when 160578 then 'Men who have sex with men' + when 165084 then 'Male Sex Worker' + when 160579 then 'Female sex worker' + when 165100 then 'Transgender' + when 162277 then 'People in prison and other closed settings' + when 167691 then 'Inmates' + when 1142 then 'Prison Staff' + when 163488 then 'Prison Community' + when 159674 then 'Fisher folk' + when 162198 then 'Truck driver' + when 6096 then 'Discordant' + when 5622 then 'Other' else null end),null)) as key_population_type, max(if(o.concept_id=160581 and o.value_coded in(159674,162198,160549,162277,1175,165192), (case o.value_coded when 159674 then "Fisher folk" when 162198 then "Truck driver" when 160549 then "Adolescent and young girls" when 162277 then "Prisoner" when 1175 then "Not applicable" when 165192 then "Military and other uniformed services" else null end),null)) as priority_population_type, max(if(o.concept_id=164401,(case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end),null)) as ever_tested_for_hiv, max(if(o.concept_id=159813,o.value_numeric,null)) as months_since_last_test, @@ -2658,7 +2669,7 @@ e.voided from encounter e inner join person p on p.person_id=e.patient_id and p.voided=0 inner join form f on f.form_id=e.form_id and f.uuid in ("402dc5d7-46da-42d4-b2be-f43ea4ad87b0","b08471f6-0892-4bf7-ab2b-bf79797b8ea4") -inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (162084, 164930, 160581, 164401, 164951, 162558,160632, 1710, 164959, 164956,160581, +inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (162084, 164930, 160581, 164401, 164951, 162558,160632, 1710, 164959, 164956,160581,165241, 160540,159427, 164848, 6096, 1659, 164952, 163042, 159813,165215,163556,161550,1887,1272,164359,160481,229,167163,167162,165093) inner join ( select