From aae21515a9948c97a156386e005f40cb1900aa72 Mon Sep 17 00:00:00 2001 From: njorocs Date: Fri, 7 Jun 2024 00:47:29 +0300 Subject: [PATCH] Aligning clinical visit etl with additional revision to clinical visit form variables --- omod/src/main/resources/sql/DDL.sql | 10 ++++- omod/src/main/resources/sql/DML.sql | 33 +++++++++++--- omod/src/main/resources/sql/DataTools.sql | 12 +++++- .../main/resources/sql/Scheduled_Updates.sql | 43 ++++++++++++++++--- omod/src/main/resources/sql/dwapi/DDL.sql | 12 +++++- omod/src/main/resources/sql/dwapi/DML.sql | 33 +++++++++++--- 6 files changed, 119 insertions(+), 24 deletions(-) diff --git a/omod/src/main/resources/sql/DDL.sql b/omod/src/main/resources/sql/DDL.sql index e8d3836c..eb18ed3a 100644 --- a/omod/src/main/resources/sql/DDL.sql +++ b/omod/src/main/resources/sql/DDL.sql @@ -2459,11 +2459,14 @@ CREATE TABLE kenyaemr_etl.etl_patient_program ( tb_referred_text VARCHAR(255), hepatitisB_screened VARCHAR(10), hepatitisB_results VARCHAR(255), + hepatitisB_confirmatory_results VARCHAR(50), + hepatitisB_vaccinated VARCHAR(50), hepatitisB_treated VARCHAR(10), hepatitisB_referred VARCHAR(10), hepatitisB_text VARCHAR(255), hepatitisC_screened VARCHAR(10), hepatitisC_results VARCHAR(255), + hepatitisC_confirmatory_results VARCHAR(255), hepatitisC_treated VARCHAR(10), hepatitisC_referred VARCHAR(10), hepatitisC_text VARCHAR(255), @@ -2534,7 +2537,7 @@ CREATE TABLE kenyaemr_etl.etl_patient_program ( self_use_kits VARCHAR (10), distribution_kits VARCHAR (10), self_tested VARCHAR(10), - self_test_date DATE, + hiv_test_date DATE, self_test_frequency VARCHAR(100), self_test_results VARCHAR(100), test_confirmatory_results VARCHAR(100), @@ -2545,10 +2548,15 @@ CREATE TABLE kenyaemr_etl.etl_patient_program ( hiv_care_facility VARCHAR(255), other_hiv_care_facility VARCHAR(255), initiated_art_this_month VARCHAR(10), + started_on_art VARCHAR(10), + date_started_art DATE, active_art VARCHAR(10), + primary_care_facility_name VARCHAR(250), + ccc_number VARCHAR(50), eligible_vl VARCHAR(50), vl_test_done VARCHAR(100), vl_results VARCHAR(100), + vl_results_date DATE, received_vl_results VARCHAR(100), condom_use_education VARCHAR(10), post_abortal_care VARCHAR(10), diff --git a/omod/src/main/resources/sql/DML.sql b/omod/src/main/resources/sql/DML.sql index 0b207eac..99fe4911 100644 --- a/omod/src/main/resources/sql/DML.sql +++ b/omod/src/main/resources/sql/DML.sql @@ -5272,11 +5272,14 @@ CREATE PROCEDURE sp_populate_etl_client_trace() tb_referred_text, hepatitisB_screened, hepatitisB_results, + hepatitisB_confirmatory_results, + hepatitisB_vaccinated, hepatitisB_treated, hepatitisB_referred, hepatitisB_text, hepatitisC_screened, hepatitisC_results, + hepatitisC_confirmatory_results, hepatitisC_treated, hepatitisC_referred, hepatitisC_text, @@ -5347,7 +5350,7 @@ CREATE PROCEDURE sp_populate_etl_client_trace() self_use_kits, distribution_kits, self_tested, - self_test_date, + hiv_test_date, self_test_frequency, self_test_results, test_confirmatory_results, @@ -5358,10 +5361,15 @@ CREATE PROCEDURE sp_populate_etl_client_trace() hiv_care_facility, other_hiv_care_facility, initiated_art_this_month, + started_on_art, + date_started_art, active_art, + primary_care_facility_name, + ccc_number, eligible_vl, vl_test_done, vl_results, + vl_results_date, received_vl_results, condom_use_education, post_abortal_care, @@ -5403,11 +5411,14 @@ CREATE PROCEDURE sp_populate_etl_client_trace() max(if(o.concept_id=163323,o.value_text,null)) as tb_referred_text, max(if(o.concept_id=165040,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "" end),null)) as hepatitisB_screened, max(if(o.concept_id=1322,(case o.value_coded when 664 then "N" when 703 THEN "P" else "" end),null)) as hepatitisB_results, - max(if(o.concept_id=165251,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" when 782 then "Vaccinated" else "NA" end),null)) as hepatitisB_treated, + max(if(o.concept_id=159430,(case o.value_coded when 664 then "Negative" when 703 THEN "Positive" when 1118 then "Not done" end),null)) as hepatitisB_confirmatory_results, + max(if(o.concept_id=165251,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" when 1175 then "NA" end),null)) as hepatitisB_vaccinated, + max(if(o.concept_id=166665,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" end),null)) as hepatitisB_treated, max(if(o.concept_id=165252,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as hepatitisB_referred, max(if(o.concept_id=165253,o.value_text,null)) as hepatitisB_text, max(if(o.concept_id=165041,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "" end),null)) as hepatitisC_screened, max(if(o.concept_id=161471,(case o.value_coded when 664 then "N" when 703 THEN "P" else "" end),null)) as hepatitisC_results, + max(if(o.concept_id=167786,(case o.value_coded when 664 then "Negative" when 703 THEN "Positive" end),null)) as hepatitisC_confirmatory_results, max(if(o.concept_id=165254,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "NA" end),null)) as hepatitisC_treated, max(if(o.concept_id=165255,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as hepatitisC_referred, max(if(o.concept_id=165256,o.value_text,null)) as hepatitisC_text, @@ -5440,7 +5451,12 @@ CREATE PROCEDURE sp_populate_etl_client_trace() max(if(o.concept_id=165270,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as prep_referred, max(if(o.concept_id=165271,o.value_text,null)) as prep_text, max(if(o.concept_id=165204,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as violence_screened, - max(if(o.concept_id=165205,(case o.value_coded when 165206 then "Emotional & Psychological" when 121387 then "Physical" when 165207 THEN "Emotional & Psychological" when 123007 THEN "Emotional & Psychological" when 127910 THEN "Rape/Sexual assault" when 126312 THEN "Emotional & Psychological" when 141537 then "Economical" when 5622 then "Others" end),null)) as violence_results, + concat_ws(',', max(if(o.concept_id = 165205 and o.value_coded in (165206, 165207, 123007, 126312), + "Emotional & Psychological", null)), + max(if(o.concept_id = 165205 and o.value_coded = 121387, "Physical", null)), + max(if(o.concept_id = 165205 and o.value_coded = 127910, "Rape/Sexual assault", null)), + max(if(o.concept_id = 165205 and o.value_coded = 141537, "Economical", null)), + max(if(o.concept_id = 165205 and o.value_coded = 5622, "Other", null))) as violence_results, max(if(o.concept_id=165208,(case o.value_coded when 1065 then "Supported" when 1066 THEN "Not supported" else "" end),null)) as violence_treated, max(if(o.concept_id=165273,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as violence_referred, max(if(o.concept_id=165274,o.value_text,null)) as violence_text, @@ -5478,7 +5494,7 @@ CREATE PROCEDURE sp_populate_etl_client_trace() max(if(o.concept_id=165222,o.value_numeric,null)) as self_use_kits, max(if(o.concept_id=165223,o.value_numeric,null)) as distribution_kits, max(if(o.concept_id=164952,(case o.value_coded when 1065 THEN "Y" when 1066 then "N" else "" end),null)) as self_tested, - max(if(o.concept_id=164400,o.value_datetime,null)) as self_test_date, + max(if(o.concept_id=164400,o.value_datetime,null)) as hiv_test_date, max(if(o.concept_id=165231,(case o.value_coded when 162080 THEN "Initial" when 162081 then "Repeat" else "" end),null)) as self_test_frequency, max(if(o.concept_id=165233,(case o.value_coded when 664 THEN "Negative" when 703 then "Positive" when 165232 then "Inconclusive" else "" end),null)) as self_test_results, max(if(o.concept_id=165234,(case o.value_coded when 664 THEN "Negative" when 703 then "Positive" when 1118 then "Not done" else "" end),null)) as test_confirmatory_results, @@ -5489,10 +5505,15 @@ CREATE PROCEDURE sp_populate_etl_client_trace() max(if(o.concept_id=165239,(case o.value_coded when 163266 THEN "Provided here" when 162723 then "Provided elsewhere" when 160563 then "Referred" else "" end),null)) as hiv_care_facility, max(if(o.concept_id=163042,o.value_text,null)) as other_hiv_care_facility, max(if(o.concept_id=165240,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as initiated_art_this_month, + max(if(o.concept_id=167790,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" end),null)) as started_on_art, + max(if(o.concept_id=159599,o.value_datetime,null)) as date_started_art, max(if(o.concept_id=160119,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as active_art, + max(if(o.concept_id=162724,o.value_text,null)) as primary_care_facility_name, + max(if(o.concept_id=162053,o.value_numeric,null)) as ccc_number, max(if(o.concept_id=165242,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as eligible_vl, max(if(o.concept_id=165243,(case o.value_coded when 1065 THEN "Y" when 1066 then "N" when 1175 then "Not Applicable" else "" end),null)) as vl_test_done, - COALESCE(max(if(o.concept_id=165246,(case o.value_coded when 167484 THEN "LDL" END), NULL)), max(if(o.concept_id=856,o.value_numeric,null))) as vl_results, + COALESCE(max(if(o.concept_id=165246,(case o.value_coded when 167484 THEN "LDL" when 1107 then "None" END), NULL)), max(if(o.concept_id=856,o.value_numeric,null))) as vl_results, + max(if(o.concept_id = 163281, o.value_datetime, null)) as vl_results_date, max(if(o.concept_id=165246,(case o.value_coded when 164369 then "N" else "Y" end),null)) as received_vl_results, max(if(o.concept_id=165247,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" else "" end),null)) as condom_use_education, max(if(o.concept_id=164820,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" else "" end),null)) as post_abortal_care, @@ -5519,7 +5540,7 @@ CREATE PROCEDURE sp_populate_etl_client_trace() 164934,165196,165266,165267,165268,116030,165076,165202,165203,165270,165271,165204,165205,165208,165273,165274,165045,165050,165053,161595,165277,1382, 165209,160653,165279,165280,165210,165211,165213,165281,165282,166663,166664,165052,166637,165093,165214,165215,159382,164401,165218,164848,159427,1648,163042,165220,165221,165222,165223, 164952,164400,165231,165233,165234,165237,162724,165238,161562,165239,163042,165240,160119,165242,165243,165246,165247,164820,165302,163766,165055,165056, - 165057,165058,164845,165248,5096,164142,856) + 165057,165058,164845,165248,5096,164142,856,159599,167790,162724,162053,163281,159430,165251,167786) where e.voided=0 group by e.patient_id, e.encounter_id, visit_date; SELECT "Completed processing Clinical visit data ", CONCAT("Time: ", NOW()); diff --git a/omod/src/main/resources/sql/DataTools.sql b/omod/src/main/resources/sql/DataTools.sql index f378766e..ac024488 100644 --- a/omod/src/main/resources/sql/DataTools.sql +++ b/omod/src/main/resources/sql/DataTools.sql @@ -2218,11 +2218,14 @@ select tb_referred_text, hepatitisB_screened, hepatitisB_results, + hepatitisB_confirmatory_results, + hepatitisB_vaccinated, hepatitisB_treated, hepatitisB_referred, hepatitisB_text, hepatitisC_screened, hepatitisC_results, + hepatitisC_confirmatory_results, hepatitisC_treated, hepatitisC_referred, hepatitisC_text, @@ -2275,7 +2278,7 @@ select mental_health_referred, mental_health_text, mat_screened, --- mat_results, +-- mat_results, mat_treated, mat_referred, mat_text, @@ -2293,7 +2296,7 @@ select self_use_kits, distribution_kits, self_tested, - self_test_date, + hiv_test_date, self_test_frequency, self_test_results, test_confirmatory_results, @@ -2304,10 +2307,15 @@ select hiv_care_facility, other_hiv_care_facility, initiated_art_this_month, + started_on_art, + date_started_art, active_art, + primary_care_facility_name, + ccc_number, eligible_vl, vl_test_done, vl_results, + vl_results_date, received_vl_results, condom_use_education, post_abortal_care, diff --git a/omod/src/main/resources/sql/Scheduled_Updates.sql b/omod/src/main/resources/sql/Scheduled_Updates.sql index b411370d..71633e3b 100644 --- a/omod/src/main/resources/sql/Scheduled_Updates.sql +++ b/omod/src/main/resources/sql/Scheduled_Updates.sql @@ -5396,11 +5396,14 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) tb_referred_text, hepatitisB_screened, hepatitisB_results, + hepatitisB_confirmatory_results, + hepatitisB_vaccinated, hepatitisB_treated, hepatitisB_referred, hepatitisB_text, hepatitisC_screened, hepatitisC_results, + hepatitisC_confirmatory_results, hepatitisC_treated, hepatitisC_referred, hepatitisC_text, @@ -5471,7 +5474,7 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) self_use_kits, distribution_kits, self_tested, - self_test_date, + hiv_test_date, self_test_frequency, self_test_results, test_confirmatory_results, @@ -5482,10 +5485,15 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) hiv_care_facility, other_hiv_care_facility, initiated_art_this_month, + started_on_art, + date_started_art, active_art, + primary_care_facility_name, + ccc_number, eligible_vl, vl_test_done, vl_results, + vl_results_date, received_vl_results, condom_use_education, post_abortal_care, @@ -5527,11 +5535,14 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) max(if(o.concept_id=163323,o.value_text,null)) as tb_referred_text, max(if(o.concept_id=165040,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "" end),null)) as hepatitisB_screened, max(if(o.concept_id=1322,(case o.value_coded when 664 then "N" when 703 THEN "P" else "" end),null)) as hepatitisB_results, - max(if(o.concept_id=165251,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" when 782 then "Vaccinated" else "NA" end),null)) as hepatitisB_treated, + max(if(o.concept_id=159430,(case o.value_coded when 664 then "Negative" when 703 THEN "Positive" when 1118 then "Not done" end),null)) as hepatitisB_confirmatory_results, + max(if(o.concept_id=165251,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" when 1175 then "NA" end),null)) as hepatitisB_vaccinated, + max(if(o.concept_id=166665,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" end),null)) as hepatitisB_treated, max(if(o.concept_id=165252,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as hepatitisB_referred, max(if(o.concept_id=165253,o.value_text,null)) as hepatitisB_text, max(if(o.concept_id=165041,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "" end),null)) as hepatitisC_screened, max(if(o.concept_id=161471,(case o.value_coded when 664 then "N" when 703 THEN "P" else "" end),null)) as hepatitisC_results, + max(if(o.concept_id=167786,(case o.value_coded when 664 then "Negative" when 703 THEN "Positive" end),null)) as hepatitisC_confirmatory_results, max(if(o.concept_id=165254,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "NA" end),null)) as hepatitisC_treated, max(if(o.concept_id=165255,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as hepatitisC_referred, max(if(o.concept_id=165256,o.value_text,null)) as hepatitisC_text, @@ -5564,7 +5575,12 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) max(if(o.concept_id=165270,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as prep_referred, max(if(o.concept_id=165271,o.value_text,null)) as prep_text, max(if(o.concept_id=165204,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as violence_screened, - max(if(o.concept_id=165205,(case o.value_coded when 165206 then "Emotional & Psychological" when 121387 then "Physical" when 165207 THEN "Emotional & Psychological" when 123007 THEN "Emotional & Psychological" when 127910 THEN "Rape/Sexual assault" when 126312 THEN "Emotional & Psychological" when 141537 then "Economical" when 5622 then "Others" end),null)) as violence_results, + concat_ws(',', max(if(o.concept_id = 165205 and o.value_coded in (165206, 165207, 123007, 126312), + "Emotional & Psychological", null)), + max(if(o.concept_id = 165205 and o.value_coded = 121387, "Physical", null)), + max(if(o.concept_id = 165205 and o.value_coded = 127910, "Rape/Sexual assault", null)), + max(if(o.concept_id = 165205 and o.value_coded = 141537, "Economical", null)), + max(if(o.concept_id = 165205 and o.value_coded = 5622, "Other", null))) as violence_results, max(if(o.concept_id=165208,(case o.value_coded when 1065 then "Supported" when 1066 THEN "Not supported" else "" end),null)) as violence_treated, max(if(o.concept_id=165273,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as violence_referred, max(if(o.concept_id=165274,o.value_text,null)) as violence_text, @@ -5602,7 +5618,7 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) max(if(o.concept_id=165222,o.value_numeric,null)) as self_use_kits, max(if(o.concept_id=165223,o.value_numeric,null)) as distribution_kits, max(if(o.concept_id=164952,(case o.value_coded when 1065 THEN "Y" when 1066 then "N" else "" end),null)) as self_tested, - max(if(o.concept_id=164400,o.value_datetime,null)) as self_test_date, + max(if(o.concept_id=164400,o.value_datetime,null)) as hiv_test_date, max(if(o.concept_id=165231,(case o.value_coded when 162080 THEN "Initial" when 162081 then "Repeat" else "" end),null)) as self_test_frequency, max(if(o.concept_id=165233,(case o.value_coded when 664 THEN "Negative" when 703 then "Positive" when 165232 then "Inconclusive" else "" end),null)) as self_test_results, max(if(o.concept_id=165234,(case o.value_coded when 664 THEN "Negative" when 703 then "Positive" when 1118 then "Not done" else "" end),null)) as test_confirmatory_results, @@ -5613,10 +5629,15 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) max(if(o.concept_id=165239,(case o.value_coded when 163266 THEN "Provided here" when 162723 then "Provided elsewhere" when 160563 then "Referred" else "" end),null)) as hiv_care_facility, max(if(o.concept_id=163042,o.value_text,null)) as other_hiv_care_facility, max(if(o.concept_id=165240,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as initiated_art_this_month, + max(if(o.concept_id=167790,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" end),null)) as started_on_art, + max(if(o.concept_id=159599,o.value_datetime,null)) as date_started_art, max(if(o.concept_id=160119,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as active_art, + max(if(o.concept_id=162724,o.value_text,null)) as primary_care_facility_name, + max(if(o.concept_id=162053,o.value_numeric,null)) as ccc_number, max(if(o.concept_id=165242,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as eligible_vl, max(if(o.concept_id=165243,(case o.value_coded when 1065 THEN "Y" when 1066 then "N" when 1175 then "Not Applicable" else "" end),null)) as vl_test_done, - COALESCE(max(if(o.concept_id=165246,(case o.value_coded when 167484 THEN "LDL" END), NULL)), max(if(o.concept_id=856,o.value_numeric,null))) as vl_results, + COALESCE(max(if(o.concept_id=165246,(case o.value_coded when 167484 THEN "LDL" when 1107 then "None" END), NULL)), max(if(o.concept_id=856,o.value_numeric,null))) as vl_results, + max(if(o.concept_id = 163281, o.value_datetime, null)) as vl_results_date, max(if(o.concept_id=165246,(case o.value_coded when 164369 then "N" else "Y" end),null)) as received_vl_results, max(if(o.concept_id=165247,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" else "" end),null)) as condom_use_education, max(if(o.concept_id=164820,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" else "" end),null)) as post_abortal_care, @@ -5643,7 +5664,7 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) 164934,165196,165266,165267,165268,116030,165076,165202,165203,165270,165271,165204,165205,165208,165273,165274,165045,165050,165053,161595,165277,1382, 165209,160653,165279,165280,165210,165211,165213,165281,165282,166663,166664,165052,166637,165093,165214,165215,159382,164401,165218,164848,159427,1648,163042,165220,165221,165222,165223, 164952,164400,165231,165233,165234,165237,162724,165238,161562,165239,163042,165240,160119,165242,165243,165246,165247,164820,165302,163766,165055,165056, - 165057,165058,164845,165248,5096,164142,856) + 165057,165058,164845,165248,5096,164142,856,159599,167790,162724,162053,163281,159430,165251,167786) where e.voided=0 and e.date_created >= last_update_time or e.date_changed >= last_update_time or e.date_voided >= last_update_time @@ -5669,11 +5690,14 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) tb_referred_text=VALUES(tb_referred_text), hepatitisB_screened=VALUES(hepatitisB_screened), hepatitisB_results=VALUES(hepatitisB_results), + hepatitisB_confirmatory_results=VALUES(hepatitisB_confirmatory_results), + hepatitisB_vaccinated=VALUES(hepatitisB_vaccinated), hepatitisB_treated=VALUES(hepatitisB_treated), hepatitisB_referred=VALUES(hepatitisB_referred), hepatitisB_text=VALUES(hepatitisB_text), hepatitisC_screened=VALUES(hepatitisC_screened), hepatitisC_results=VALUES(hepatitisC_results), + hepatitisC_confirmatory_results=VALUES(hepatitisC_confirmatory_results), hepatitisC_treated=VALUES(hepatitisC_treated), hepatitisC_referred=VALUES(hepatitisC_referred), hepatitisC_text=VALUES(hepatitisC_text), @@ -5744,7 +5768,7 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) self_use_kits=VALUES(self_use_kits), distribution_kits=VALUES(distribution_kits), self_tested=VALUES(self_tested), - self_test_date=VALUES(self_test_date), + hiv_test_date=VALUES(hiv_test_date), self_test_frequency=VALUES(self_test_frequency), self_test_results=VALUES(self_test_results), test_confirmatory_results=VALUES(test_confirmatory_results), @@ -5755,10 +5779,15 @@ CREATE PROCEDURE sp_update_etl_kp_clinical_visit(IN last_update_time DATETIME) hiv_care_facility=VALUES(hiv_care_facility), other_hiv_care_facility=VALUES(other_hiv_care_facility), initiated_art_this_month=VALUES(initiated_art_this_month), + started_on_art=VALUES(started_on_art), + date_started_art=VALUES(date_started_art), active_art=VALUES(active_art), + primary_care_facility_name=VALUES(primary_care_facility_name), + ccc_number=VALUES(ccc_number), eligible_vl=VALUES(eligible_vl), vl_test_done=VALUES(vl_test_done), vl_results=VALUES(vl_results), + vl_results_date=VALUES(vl_results_date), received_vl_results=VALUES(received_vl_results), condom_use_education=VALUES(condom_use_education), post_abortal_care=VALUES(post_abortal_care), diff --git a/omod/src/main/resources/sql/dwapi/DDL.sql b/omod/src/main/resources/sql/dwapi/DDL.sql index 935c5add..b3f62493 100644 --- a/omod/src/main/resources/sql/dwapi/DDL.sql +++ b/omod/src/main/resources/sql/dwapi/DDL.sql @@ -2427,11 +2427,14 @@ CREATE TABLE dwapi_etl.etl_patient_program ( tb_referred_text VARCHAR(255), hepatitisB_screened VARCHAR(10), hepatitisB_results VARCHAR(255), + hepatitisB_confirmatory_results VARCHAR(50), + hepatitisB_vaccinated VARCHAR(50), hepatitisB_treated VARCHAR(10), hepatitisB_referred VARCHAR(10), hepatitisB_text VARCHAR(255), hepatitisC_screened VARCHAR(10), hepatitisC_results VARCHAR(255), + hepatitisC_confirmatory_results VARCHAR(255), hepatitisC_treated VARCHAR(10), hepatitisC_referred VARCHAR(10), hepatitisC_text VARCHAR(255), @@ -2502,7 +2505,7 @@ CREATE TABLE dwapi_etl.etl_patient_program ( self_use_kits VARCHAR (10), distribution_kits VARCHAR (10), self_tested VARCHAR(10), - self_test_date DATE, + hiv_test_date DATE, self_test_frequency VARCHAR(100), self_test_results VARCHAR(100), test_confirmatory_results VARCHAR(100), @@ -2513,10 +2516,15 @@ CREATE TABLE dwapi_etl.etl_patient_program ( hiv_care_facility VARCHAR(255), other_hiv_care_facility VARCHAR(255), initiated_art_this_month VARCHAR(10), + started_on_art VARCHAR(10), + date_started_art DATE, active_art VARCHAR(10), + primary_care_facility_name VARCHAR(250), + ccc_number VARCHAR(50), eligible_vl VARCHAR(50), vl_test_done VARCHAR(100), vl_results VARCHAR(100), + vl_results_date DATE, received_vl_results VARCHAR(100), condom_use_education VARCHAR(10), post_abortal_care VARCHAR(10), @@ -2882,7 +2890,7 @@ CREATE TABLE dwapi_etl.etl_PrEP_verification ( date_created DATETIME NOT NULL, date_last_modified DATETIME, voided INT(11), - CONSTRAINT FOREIGN KEY (patient_id) REFERENCES kenyaemr_etl.etl_patient_demographics(patient_id), + CONSTRAINT FOREIGN KEY (patient_id) REFERENCES dwapi_etl.etl_patient_demographics(patient_id), CONSTRAINT unique_uuid UNIQUE(uuid), INDEX(visit_date), INDEX(encounter_id), diff --git a/omod/src/main/resources/sql/dwapi/DML.sql b/omod/src/main/resources/sql/dwapi/DML.sql index d4562a70..ddf2f53c 100644 --- a/omod/src/main/resources/sql/dwapi/DML.sql +++ b/omod/src/main/resources/sql/dwapi/DML.sql @@ -5032,11 +5032,14 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() tb_referred_text, hepatitisB_screened, hepatitisB_results, + hepatitisB_confirmatory_results, + hepatitisB_vaccinated, hepatitisB_treated, hepatitisB_referred, hepatitisB_text, hepatitisC_screened, hepatitisC_results, + hepatitisC_confirmatory_results, hepatitisC_treated, hepatitisC_referred, hepatitisC_text, @@ -5107,7 +5110,7 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() self_use_kits, distribution_kits, self_tested, - self_test_date, + hiv_test_date, self_test_frequency, self_test_results, test_confirmatory_results, @@ -5118,10 +5121,15 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() hiv_care_facility, other_hiv_care_facility, initiated_art_this_month, + started_on_art, + date_started_art, active_art, + primary_care_facility_name, + ccc_number, eligible_vl, vl_test_done, vl_results, + vl_results_date, received_vl_results, condom_use_education, post_abortal_care, @@ -5164,11 +5172,14 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() max(if(o.concept_id=163323,o.value_text,null)) as tb_referred_text, max(if(o.concept_id=165040,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "" end),null)) as hepatitisB_screened, max(if(o.concept_id=1322,(case o.value_coded when 664 then "N" when 703 THEN "P" else "" end),null)) as hepatitisB_results, - max(if(o.concept_id=165251,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" when 782 then "Vaccinated" else "NA" end),null)) as hepatitisB_treated, + max(if(o.concept_id=159430,(case o.value_coded when 664 then "Negative" when 703 THEN "Positive" when 1118 then "Not done" end),null)) as hepatitisB_confirmatory_results, + max(if(o.concept_id=165251,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" when 1175 then "NA" end),null)) as hepatitisB_vaccinated, + max(if(o.concept_id=166665,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" end),null)) as hepatitisB_treated, max(if(o.concept_id=165252,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as hepatitisB_referred, max(if(o.concept_id=165253,o.value_text,null)) as hepatitisB_text, max(if(o.concept_id=165041,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "" end),null)) as hepatitisC_screened, max(if(o.concept_id=161471,(case o.value_coded when 664 then "N" when 703 THEN "P" else "" end),null)) as hepatitisC_results, + max(if(o.concept_id=167786,(case o.value_coded when 664 then "Negative" when 703 THEN "Positive" end),null)) as hepatitisC_confirmatory_results, max(if(o.concept_id=165254,(case o.value_coded when 1065 then "Y" when 1066 THEN "N" else "NA" end),null)) as hepatitisC_treated, max(if(o.concept_id=165255,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as hepatitisC_referred, max(if(o.concept_id=165256,o.value_text,null)) as hepatitisC_text, @@ -5201,7 +5212,12 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() max(if(o.concept_id=165270,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as prep_referred, max(if(o.concept_id=165271,o.value_text,null)) as prep_text, max(if(o.concept_id=165204,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as violence_screened, - max(if(o.concept_id=165205,(case o.value_coded when 165206 then "Emotional & Psychological" when 121387 then "Physical" when 165207 THEN "Emotional & Psychological" when 123007 THEN "Emotional & Psychological" when 127910 THEN "Rape/Sexual assault" when 126312 THEN "Emotional & Psychological" when 141537 then "Economical" when 5622 then "Others" end),null)) as violence_results, + concat_ws(',', max(if(o.concept_id = 165205 and o.value_coded in (165206, 165207, 123007, 126312), + "Emotional & Psychological", null)), + max(if(o.concept_id = 165205 and o.value_coded = 121387, "Physical", null)), + max(if(o.concept_id = 165205 and o.value_coded = 127910, "Rape/Sexual assault", null)), + max(if(o.concept_id = 165205 and o.value_coded = 141537, "Economical", null)), + max(if(o.concept_id = 165205 and o.value_coded = 5622, "Other", null))) as violence_results, max(if(o.concept_id=165208,(case o.value_coded when 1065 then "Supported" when 1066 THEN "Not supported" else "" end),null)) as violence_treated, max(if(o.concept_id=165273,(case o.value_coded when 1065 then "Yes" when 1066 THEN "No" else "" end),null)) as violence_referred, max(if(o.concept_id=165274,o.value_text,null)) as violence_text, @@ -5239,7 +5255,7 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() max(if(o.concept_id=165222,o.value_numeric,null)) as self_use_kits, max(if(o.concept_id=165223,o.value_numeric,null)) as distribution_kits, max(if(o.concept_id=164952,(case o.value_coded when 1065 THEN "Y" when 1066 then "N" else "" end),null)) as self_tested, - max(if(o.concept_id=164400,o.value_datetime,null)) as self_test_date, + max(if(o.concept_id=164400,o.value_datetime,null)) as hiv_test_date, max(if(o.concept_id=165231,(case o.value_coded when 162080 THEN "Initial" when 162081 then "Repeat" else "" end),null)) as self_test_frequency, max(if(o.concept_id=165233,(case o.value_coded when 664 THEN "Negative" when 703 then "Positive" when 165232 then "Inconclusive" else "" end),null)) as self_test_results, max(if(o.concept_id=165234,(case o.value_coded when 664 THEN "Negative" when 703 then "Positive" when 1118 then "Not done" else "" end),null)) as test_confirmatory_results, @@ -5250,10 +5266,15 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() max(if(o.concept_id=165239,(case o.value_coded when 163266 THEN "Provided here" when 162723 then "Provided elsewhere" when 160563 then "Referred" else "" end),null)) as hiv_care_facility, max(if(o.concept_id=163042,o.value_text,null)) as other_hiv_care_facility, max(if(o.concept_id=165240,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as initiated_art_this_month, + max(if(o.concept_id=167790,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" end),null)) as started_on_art, + max(if(o.concept_id=159599,o.value_datetime,null)) as date_started_art, max(if(o.concept_id=160119,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as active_art, + max(if(o.concept_id=162724,o.value_text,null)) as primary_care_facility_name, + max(if(o.concept_id=162053,o.value_numeric,null)) as ccc_number, max(if(o.concept_id=165242,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" when 1175 then "Not Applicable" else "" end),null)) as eligible_vl, max(if(o.concept_id=165243,(case o.value_coded when 1065 THEN "Y" when 1066 then "N" when 1175 then "Not Applicable" else "" end),null)) as vl_test_done, - COALESCE(max(if(o.concept_id=165246,(case o.value_coded when 167484 THEN "LDL" END), NULL)), max(if(o.concept_id=856,o.value_numeric,null))) as vl_results, + COALESCE(max(if(o.concept_id=165246,(case o.value_coded when 167484 THEN "LDL" when 1107 then "None" END), NULL)), max(if(o.concept_id=856,o.value_numeric,null))) as vl_results, + max(if(o.concept_id = 163281, o.value_datetime, null)) as vl_results_date, max(if(o.concept_id=165246,(case o.value_coded when 164369 then "N" else "Y" end),null)) as received_vl_results, max(if(o.concept_id=165247,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" else "" end),null)) as condom_use_education, max(if(o.concept_id=164820,(case o.value_coded when 1065 THEN "Yes" when 1066 then "No" else "" end),null)) as post_abortal_care, @@ -5281,7 +5302,7 @@ CREATE PROCEDURE sp_populate_dwapi_client_trace() 164934,165196,165266,165267,165268,116030,165076,165202,165203,165270,165271,165204,165205,165208,165273,165274,165045,165050,165053,161595,165277,1382, 165209,160653,165279,165280,165210,165211,165213,165281,165282,166663,166664,165052,166637,165093,165214,165215,159382,164401,165218,164848,159427,1648,163042,165220,165221,165222,165223, 164952,164400,165231,165233,165234,165237,162724,165238,161562,165239,163042,165240,160119,165242,165243,165246,165247,164820,165302,163766,165055,165056, - 165057,165058,164845,165248,5096,164142,856) + 165057,165058,164845,165248,5096,164142,856,159599,167790,162724,162053,163281,159430,165251,167786) group by e.patient_id, e.encounter_id, visit_date; SELECT "Completed processing Clinical visit data ", CONCAT("Time: ", NOW()); END $$