Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETL for Nutrition report register for 407A and 407B #486

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions omod/src/main/resources/sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ DROP TABLE IF EXISTS kenyaemr_etl.etl_enhanced_adherence;
DROP TABLE IF EXISTS kenyaemr_etl.etl_patient_triage;
DROP TABLE IF EXISTS kenyaemr_etl.etl_hts_linkage_tracing;
DROP TABLE IF EXISTS kenyaemr_etl.etl_generalized_anxiety_disorder;
DROP TABLE IF EXISTS kenyaemr_etl.etl_nutrition;
DROP TABLE IF EXISTS kenyaemr_etl.etl_ipt_initiation;
DROP TABLE IF EXISTS kenyaemr_etl.etl_ipt_follow_up;
DROP TABLE IF EXISTS kenyaemr_etl.etl_ipt_outcome;
Expand Down Expand Up @@ -1667,6 +1668,56 @@ SELECT "Successfully created etl_ART_preparation table";
SELECT "Successfully created etl_generalized_anxiety_disorder table";


--------------- Create table etl_nutrition ---------------------
CREATE TABLE kenyaemr_etl.etl_nutrition (
uuid CHAR(38),
encounter_id INT(11) NOT NULL PRIMARY KEY,
patient_id INT(11) NOT NULL ,
location_id INT(11) DEFAULT NULL,
visit_date DATE,
visit_id INT(11),
encounter_provider INT(11),
date_created DATETIME NOT NULL,
date_last_modified DATETIME,
visit_type INT(11),
facility_name VARCHAR(255),
patient_pregnant INT(11),
sero_status INT(11),
patient_on_arv INT(11),
medication_condition INT(11),
medication_condition_other VARCHAR(255),
patient_has_edema INT(11),
anaemia_level INT(11),
metabolic_disorders VARCHAR(255),
patient_sam_mam INT(11),
nutritional_intervention INT(11),
first_0_6_months INT(11),
first_6_12_months INT(11),
postnatal INT(11),
maternal_nutrition INT(11),
critical_nutrition_practices VARCHAR(255),
therapeutic_food VARCHAR(255),
therapeutic_food_other VARCHAR(255),
supplemental_food VARCHAR(255),
supplemental_food_other VARCHAR(255),
micronutrients VARCHAR(255),
micronutrients_other VARCHAR(255),
status_continuing_sam_mam_patient INT(11),
referral_status INT(11),
criteria_for_admission INT(11),
type_of_admission INT(11),
next_appointment_date DATE,
cadre INT(11),
cadre_other VARCHAR(255),
provider_name VARCHAR(255),
voided INT(11),
CONSTRAINT FOREIGN KEY (patient_id) REFERENCES kenyaemr_etl.etl_patient_demographics(patient_id),
CONSTRAINT unique_uuid UNIQUE(uuid),
INDEX(visit_date),
INDEX(encounter_id),
INDEX(patient_id),
INDEX(patient_id, visit_date)
);


-- ------------ create table etl_prep_behaviour_risk_assessment-----------------------
Expand Down
134 changes: 134 additions & 0 deletions omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3601,6 +3601,139 @@ CREATE PROCEDURE sp_populate_etl_generalized_anxiety_disorder()
group by e.encounter_id;
SELECT "Completed processing Processing Generalized Anxiety Disorder forms", CONCAT("Time: ", NOW());
END $$

-- ------------- populate etl_nutrition-------------------------

DROP PROCEDURE IF EXISTS sp_populate_etl_nutrition $$
CREATE PROCEDURE sp_populate_etl_nutrition()
BEGIN
SELECT "Processing Nutrition form", CONCAT("Time: ", NOW());
insert into kenyaemr_etl.etl_nutrition(
uuid,
patient_id,
visit_id,
visit_date,
location_id,
encounter_id,
encounter_provider,
date_created,
visit_type,
facility_name,
patient_pregnant,
sero_status,
patient_on_arv,
medication_condition,
medication_condition_other,
patient_has_edema,
anaemia_level,
metabolic_disorders,
patient_sam_mam,
nutritional_intervention,
first_0_6_months,
first_6_12_months,
postnatal,
maternal_nutrition,
critical_nutrition_practices,
therapeutic_food,
therapeutic_food_other,
supplemental_food,
supplemental_food_other,
micronutrients,
micronutrients_other,
status_continuing_sam_mam_patient,
referral_status,
criteria_for_admission,
type_of_admission,
next_appointment_date,
cadre,
cadre_other,
provider_name,
date_last_modified,
voided
)
select
e.uuid,
e.patient_id,
e.visit_id,
date(e.encounter_datetime) as visit_date,
e.location_id,
e.encounter_id as encounter_id,
e.creator,
e.date_created as date_created,
max(if(o.concept_id=164181,o.value_coded,null)) as visit_type,
max(if(o.concept_id=160632,o.value_text,null)) as facility_name,
max(if(o.concept_id=5272,o.value_coded,null)) as patient_pregnant,
max(if(o.concept_id=1169,o.value_coded,null)) as sero_status,
max(if(o.concept_id=1149,o.value_coded,null)) as patient_on_arv,
max(if(o.concept_id=162747,o.value_coded,null)) as medication_condition,
max(if(o.concept_id=160632,o.value_text,null)) as medication_condition_other,
max(if(o.concept_id=163894,o.value_coded,null)) as patient_has_edema,
max(if(o.concept_id=156625,o.value_coded,null)) as anaemia_level,
CONCAT_WS(',',max(if(o.concept_id = 163304 and o.value_coded = 1107, 'None',NULL)),
max(if(o.concept_id = 163304 and o.value_coded = 135761, 'Lypodystrophy',NULL)),
max(if(o.concept_id = 163304 and o.value_coded = 141623, 'Dyslipidemia',NULL)),
max(if(o.concept_id = 163304 and o.value_coded = 142473, 'Type II Diabetes',NULL))) as metabolic_disorders,
max(if(o.concept_id=160205,o.value_coded,null)) as patient_sam_mam,
max(if(o.concept_id=162696,o.value_coded,null)) as nutritional_intervention,
max(if(o.concept_id=985,o.value_coded,null)) as first_0_6_months,
max(if(o.concept_id=1151,o.value_coded,null)) as first_6_12_months,
max(if(o.concept_id=168734,o.value_coded,null)) as postnatal,
max(if(o.concept_id=163300,o.value_coded,null)) as maternal_nutrition,
CONCAT_WS(',',max(if(o.concept_id = 161005 and o.value_coded = 1107, 'None',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 163300, 'Nutrition status assessment',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 161648, 'Dietary/Energy needs',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 1906, 'Sanitation',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 135797, 'Positive living behaviour',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 159364, 'Exercise',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 154358, 'Safe drinking water',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 1611, 'Prompt treatment for Opportunistic Infections',NULL)),
max(if(o.concept_id = 161005 and o.value_coded = 164377, 'Drug food interactions side effects',NULL))) as critical_nutrition_practices,
CONCAT_WS(',',max(if(o.concept_id = 161648 and o.value_coded = 1107, 'None',NULL)),
max(if(o.concept_id = 161648 and o.value_coded = 163394, 'RUTF',NULL)),
max(if(o.concept_id = 161648 and o.value_coded = 163404, 'F-75',NULL)),
max(if(o.concept_id = 161648 and o.value_coded = 167247, 'F-100',NULL)),
max(if(o.concept_id = 161648 and o.value_coded = 159854, 'Fiesmol',NULL)),
max(if(o.concept_id = 161648 and o.value_coded = 159364, 'Exercise',NULL)),
max(if(o.concept_id = 161648 and o.value_coded = 5622, 'Others',NULL))) as therapeutic_food,
max(if(o.concept_id=160632,o.value_text,null)) as therapeutic_food_other,
CONCAT_WS(',',max(if(o.concept_id = 159854 and o.value_coded = 1107, 'None',NULL)),
max(if(o.concept_id = 159854 and o.value_coded = 159597, 'FBF',NULL)),
max(if(o.concept_id = 159854 and o.value_coded = 162758, 'CSB',NULL)),
max(if(o.concept_id = 159854 and o.value_coded = 166382, 'RUSF',NULL)),
max(if(o.concept_id = 159854 and o.value_coded = 165577, 'Liquid nutrition supplements',NULL)),
max(if(o.concept_id = 159854 and o.value_coded = 5622, 'Others',NULL))) as supplemental_food,
max(if(o.concept_id=160632,o.value_text,null)) as supplemental_food_other,
CONCAT_WS(',',max(if(o.concept_id = 5484 and o.value_coded = 1107, 'None',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 86339, 'Vitamin A',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 86343, 'B6',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 461, 'Multi-vitamins',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 104677, 'Iron-folate',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 86672, 'Zinc',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 161649, 'Multiple Micronutrients',NULL)),
max(if(o.concept_id = 5484 and o.value_coded = 5622, 'Others',NULL))) as micronutrients,
max(if(o.concept_id=160632,o.value_text,null)) as micronutrients_other,
max(if(o.concept_id=159402,o.value_coded,null)) as status_continuing_sam_mam_patient,
max(if(o.concept_id=1788,o.value_coded,null)) as referral_status,
max(if(o.concept_id=167381,o.value_coded,null)) as criteria_for_admission,
max(if(o.concept_id=162477,o.value_coded,null)) as type_of_admission,
max(if(o.concept_id=5096,o.value_datetime,null)) as next_appointment_date,
max(if(o.concept_id=5619,o.value_coded,null)) as cadre,
max(if(o.concept_id=160632,o.value_text,null)) as cadre_other,
max(if(o.concept_id=1473,o.value_text,null)) as provider_name,
if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_last_modified,
e.voided as 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 ("b8357314-0f6a-4fc9-a5b7-339f47095d62")
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (
164181,160632,5272,1169,1149,162747,160632,163894,156625,163304,160205,
162696,985,1151,168734,163300,161005,161648,160632,
159854,160632,159854,160632,5484,160632,159402,1788,167381,162477,5096,5619,160632,1473) and o.voided=0
where e.voided=0
group by e.encounter_id;
SELECT "Completed processing Nutrition forms", CONCAT("Time: ", NOW());
END $$

-- ------------- populate etl_prep_behaviour_risk_assessment-------------------------

DROP PROCEDURE IF EXISTS sp_populate_etl_prep_behaviour_risk_assessment $$
Expand Down Expand Up @@ -8320,6 +8453,7 @@ CALL sp_populate_etl_mch_discharge();
CALL sp_drug_event();
CALL sp_populate_hts_test();
CALL sp_populate_etl_generalized_anxiety_disorder();
CALL sp_populate_etl_nutrition();
CALL sp_populate_hts_linkage_and_referral();
CALL sp_populate_hts_referral();
CALL sp_populate_etl_ccc_defaulter_tracing();
Expand Down
48 changes: 47 additions & 1 deletion omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,53 @@ SELECT "Successfully created enhanced adherence table";
ALTER TABLE kenyaemr_datatools.generalized_anxiety_disorder ADD INDEX(visit_date);
SELECT "Successfully created generalized anxiety disorder table";


-- Create table nutrition
create table kenyaemr_datatools.nutrition as
select
uuid,
patient_id,
visit_id,
visit_date,
location_id,
encounter_id,
encounter_provider,
date_created,
(case visit_type when 164180 then 'New visit' when 160530 then 'Return Visit' when 160563 then 'Referred from other facilites' else '' end) as visit_type,
facility_name,
(case patient_pregnant when 1065 then 'Yes' when 1066 then 'No' when 1175 then 'N/A' else '' end) as patient_pregnant,
(case sero_status when 703 then 'Positive' when 664 then 'Negative' when 1067 then 'Unknown' else '' end) as sero_status,
(case patient_on_arv when 1065 then 'Yes' when 1066 then 'No' else '' end) as patient_on_arv,
(case medication_condition when 112141 then 'TB' when 119481 then 'Diabetes' when 117399 then 'Hypertension' when 5622 then 'Other' else '' end) as medication_condition,
medication_condition_other,
(case patient_has_edema when 1065 then 'Yes' when 1066 then 'No' else '' end) as patient_has_edema,
(case anaemia_level when 1118 then 'Not Done' when 1115 then 'Normal' when 1498 then 'Mild' when 1499 then 'Moderate' when 1500 then 'Severe' else '' end) as anaemia_level,
metabolic_disorders,
(case patient_sam_mam when 1687 then '1st Time Diagnosis' when 160033 then 'Relapse' when 1655 then 'Re-admission' else '' end) as patient_sam_mam,
(case nutritional_intervention when 1065 then 'Yes' when 1066 then 'No' else '' end) as nutritional_intervention,
(case first_0_6_months when 5526 then 'Exclusive breastfeeding' when 164477 then 'Exclusive replacement feeding' when 6046 then 'Mixed feeding' else '' end) as first_0_6_months,
(case first_6_12_months when 5632 then 'Breastfeeding' when 140719 then 'Not Breastfeeding' when 1067 then 'Not known' when 159854 then 'Began complimentary feeding' else '' end) as first_6_12_months,
(case postnatal when 5632 then 'Breastfeeding' when 164477 then 'Replacement feeding' when 159854 then 'Complimentary feeding' else '' end) as postnatal,
(case maternal_nutrition when 129202 then 'Pre-natal' when 164171 then 'Post Natal' else '' end) as maternal_nutrition,
critical_nutrition_practices,
therapeutic_food,
therapeutic_food_other,
supplemental_food,
supplemental_food_other,
micronutrients,
micronutrients_other,
(case status_continuing_sam_mam_patient when 5544 then 'Gaining Weight' when 832 then 'Losing Weight' when 128378 then 'Static Weight' when 159791 then 'Cured' when 1692 then 'Discharged' when 163484 then 'Refused Nutrition Support' else '' end) as status_continuing_sam_mam_patient,
(case referral_status when 5485 then 'Refer for admission' when 164407 then 'Referral for other clinics' when 163316 then 'Referral for livelihood support' when 159492 then 'Transferred Out' else '' end) as referral_status,
(case criteria_for_admission when 1362 then 'Edema +' when 1363 then 'Edema ++' when 1364 then 'Edema +++' when 1343 then 'MUAC' when 162584 then 'WHZ' when 1342 then 'BMI for Age' else '' end) as criteria_for_admission,
(case type_of_admission when 164144 then 'New' when 1000049 then 'Re-Admission' when 160033 then 'Relapse' when 160031 then 'Returned Defaulter' else '' end) as type_of_admission,
next_appointment_date,
(case cadre when 900009 then 'Nutritionist' when 1577 then 'Nurse' when 162591 then 'Doctor' when 1574 then 'Clinical Officer' when 5622 then 'Others' else '' end) as cadre,
cadre_other,
provider_name,
voided
from kenyaemr_etl.etl_nutrition;
ALTER TABLE kenyaemr_datatools.nutrition ADD FOREIGN KEY (patient_id) REFERENCES kenyaemr_datatools.patient_demographics(patient_id);
ALTER TABLE kenyaemr_datatools.nutrition ADD INDEX(visit_date);
SELECT "Successfully created nutrition table";
-- create table datatools_patient_contact
create table kenyaemr_datatools.patient_contact as
select
Expand Down
Loading