Skip to content

Commit

Permalink
Merge pull request #450 from njorocs/revised-tools-kvp
Browse files Browse the repository at this point in the history
Aligning clinical visit etl with additional revision to clinical visi…
  • Loading branch information
patryllus authored Jun 11, 2024
2 parents 3894c2f + aae2151 commit 8ea741b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 24 deletions.
10 changes: 9 additions & 1 deletion omod/src/main/resources/sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
33 changes: 27 additions & 6 deletions omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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());
Expand Down
12 changes: 10 additions & 2 deletions omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2275,7 +2278,7 @@ select
mental_health_referred,
mental_health_text,
mat_screened,
-- mat_results,
-- mat_results,
mat_treated,
mat_referred,
mat_text,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 8ea741b

Please sign in to comment.