Skip to content

Commit

Permalink
Merge pull request #424 from makombe/new-updates
Browse files Browse the repository at this point in the history
New updates
  • Loading branch information
makombe authored Feb 29, 2024
2 parents 2dcdd8e + f690311 commit 463fa36
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions omod/src/main/resources/sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,7 @@ CREATE TABLE kenyaemr_etl.etl_clinical_encounter (
other_counselling_ordered VARCHAR(100),
procedures_prescribed INT(11),
procedures_ordered VARCHAR(100),
patient_outcome INT(11),
admission_needed INT(11),
date_of_patient_admission DATE,
admission_reason VARCHAR(100),
Expand Down
10 changes: 5 additions & 5 deletions omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2892,27 +2892,25 @@ CREATE TABLE kenyaemr_etl.etl_viral_load_tracker (

insert into kenyaemr_etl.etl_viral_load_tracker
select t.patient_id,vl.vl_date,vl.vl_result,vl.urgency from (select fup.visit_date,fup.patient_id, max(e.visit_date) as enroll_date,
mid(max(concat(e.visit_date, e.patient_type)), 11) as patient_type,
greatest(max(fup.visit_date), ifnull(max(d.visit_date),'0000-00-00')) as latest_vis_date,
greatest(mid(max(concat(fup.visit_date,fup.next_appointment_date)),11), ifnull(max(d.visit_date),'0000-00-00')) as latest_tca,
d.patient_id as disc_patient,
d.effective_disc_date as effective_disc_date,
max(d.visit_date) as date_discontinued,
de.patient_id as started_on_drugs,
mid(max(concat(date(de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs,
de.date_started
from kenyaemr_etl.etl_patient_hiv_followup fup
join kenyaemr_etl.etl_patient_demographics p on p.patient_id=fup.patient_id
join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id=e.patient_id
inner join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(curdate())
left join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date(date_started) <= date(curdate())
left outer JOIN
(select patient_id, coalesce(date(effective_discontinuation_date),visit_date) visit_date,max(date(effective_discontinuation_date)) as effective_disc_date from kenyaemr_etl.etl_patient_program_discontinuation
where date(visit_date) <= date(curdate()) and program_name='HIV'
group by patient_id
) d on d.patient_id = fup.patient_id
where fup.visit_date <= date(curdate())
group by patient_id
having (patient_type != 164931 and on_drugs != 1) and (
having (started_on_drugs is not null and started_on_drugs <> '') and (
(
((timestampdiff(DAY,date(latest_tca),date(curdate())) <= 30 or timestampdiff(DAY,date(latest_tca),date(curdate())) <= 30) and ((date(d.effective_disc_date) > date(curdate()) or date(enroll_date) > date(d.effective_disc_date)) or d.effective_disc_date is null))
and (date(latest_vis_date) >= date(date_discontinued) or date(latest_tca) >= date(date_discontinued) or disc_patient is null)
Expand Down Expand Up @@ -7469,6 +7467,7 @@ BEGIN
other_counselling_ordered,
procedures_prescribed,
procedures_ordered,
patient_outcome,
admission_needed,
date_of_patient_admission,
admission_reason,
Expand Down Expand Up @@ -7544,6 +7543,7 @@ BEGIN
nullif(max(if(o.concept_id=164174 and o.value_coded = 127896,'Lumbar Puncture','')),''),
nullif(max(if(o.concept_id=164174,o.value_text,'')),'')) as procedures_ordered,
max(if(o.concept_id=1651,(case o.value_coded when 1065 then 'Yes' when 1066 THEN 'No' else '' end),null)) as admission_needed,
max(if(o.concept_id=160433,o.value_coded,null)) as patient_outcome,
max(if(o.concept_id = 1640,o.value_datetime,null)) as date_of_patient_admission,
max(if(o.concept_id=164174,o.value_text,null)) as admission_reason,
max(if(o.concept_id=162477,(case o.value_coded when 164180 then 'New' when 159833 THEN 'Readmission' else '' end),null)) as admission_type,
Expand Down Expand Up @@ -7578,7 +7578,7 @@ BEGIN
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 = 'e958f902-64df-4819-afd4-7fb061f59308'
left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in
(164174,160632,165104,1651,1640,162477,1655,1000075,1896,1272,162724)
(164174,160632,165104,1651,1640,162477,1655,1000075,1896,1272,162724,160433)
and o.voided=0
where e.voided=0
group by e.patient_id,date(e.encounter_datetime);
Expand Down
1 change: 1 addition & 0 deletions omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,7 @@ select patient_id,
other_counselling_ordered,
procedures_prescribed,
procedures_ordered,
case patient_outcome when 160429 then 'Released Home' when 1654 then 'Admit' when 1693 then 'Referral' when 159 then 'Deceased' end as patient_outcome,
admission_needed,
date_of_patient_admission,
admission_reason,
Expand Down
5 changes: 4 additions & 1 deletion omod/src/main/resources/sql/Scheduled_Updates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8332,6 +8332,7 @@ INSERT INTO kenyaemr_etl.etl_clinical_encounter (
other_counselling_ordered,
procedures_prescribed,
procedures_ordered,
patient_outcome,
admission_needed,
date_of_patient_admission,
admission_reason,
Expand Down Expand Up @@ -8406,6 +8407,7 @@ select
nullif(max(if(o.concept_id=164174 and o.value_coded = 1000222,'Enema Administration','')),''),
nullif(max(if(o.concept_id=164174 and o.value_coded = 127896,'Lumbar Puncture','')),''),
nullif(max(if(o.concept_id=164174,o.value_text,'')),'')) as procedures_ordered,
max(if(o.concept_id=160433,o.value_coded,null)) as patient_outcome,
max(if(o.concept_id=1651,(case o.value_coded when 1065 then 'Yes' when 1066 THEN 'No' else '' end),null)) as admission_needed,
max(if(o.concept_id = 1640,o.value_datetime,null)) as date_of_patient_admission,
max(if(o.concept_id=164174,o.value_text,null)) as admission_reason,
Expand Down Expand Up @@ -8441,7 +8443,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 = 'e958f902-64df-4819-afd4-7fb061f59308'
left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in
(164174,160632,165104,1651,1640,162477,1655,1000075,1896,1272,162724)
(164174,160632,165104,1651,1640,162477,1655,1000075,1896,1272,162724,160433)
and o.voided=0
where e.voided=0
and e.date_created >= last_update_time
Expand All @@ -8459,6 +8461,7 @@ ON DUPLICATE KEY UPDATE visit_date=VALUES(visit_date),
other_counselling_ordered=VALUES(other_counselling_ordered),
procedures_prescribed=VALUES(procedures_prescribed),
procedures_ordered=VALUES(procedures_ordered),
patient_outcome=VALUES(patient_outcome),
admission_needed=VALUES(admission_needed),
date_of_patient_admission=VALUES(date_of_patient_admission),
admission_reason=VALUES(admission_reason),
Expand Down
1 change: 1 addition & 0 deletions omod/src/main/resources/sql/dwapi/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,7 @@ CREATE TABLE dwapi_etl.etl_clinical_encounter (
other_counselling_ordered VARCHAR(100),
procedures_prescribed INT(11),
procedures_ordered VARCHAR(100),
patient_outcome INT(11),
admission_needed INT(11),
date_of_patient_admission DATE,
admission_reason VARCHAR(100),
Expand Down
38 changes: 20 additions & 18 deletions omod/src/main/resources/sql/dwapi/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ inner join form f on f.form_id = e.form_id and f.uuid in ('22c68f86-bbf0-49ba-b2
left outer join obs o on o.encounter_id=e.encounter_id and o.voided=0
and o.concept_id in (1282,1246,161643,5089,5085,5086,5090,5088,5087,5242,5092,1343,162584,163515,5356,167394,5272,5632, 161033,163530,5596,1427,5624,1053,160653,374,160575,1659,161654,161652,162229,162230,1658,160582,160632,159423,5616,161557,159777,112603,161558,160581,5096,163300, 164930, 160581, 1154, 160430,162877, 164948, 164949, 164950, 1271, 307, 12, 162202, 1272, 163752, 163414, 162275, 160557, 162747,
121764, 164933, 160080, 1823, 164940, 164934, 164935, 159615, 160288, 1855, 164947,162549,162877,160596,1109,1113,162309,1729,162737,159615,1120,163309,164936,1123,1124,1125,164937,1126,166607,159356,161011,165911)
group by e.patient_id,visit_date;
group by e.patient_id, encounter_id;
SELECT "Completed processing HIV Followup data ", CONCAT("Time: ", NOW());
END $$

Expand Down Expand Up @@ -1172,7 +1172,7 @@ CREATE PROCEDURE sp_populate_dwapi_mch_antenatal_visit()
where o.concept_id in (1040, 1326, 164962, 164964, 162502) and o.voided=0
group by e.encounter_id, o.obs_group_id
) t on e.encounter_id = t.encounter_id
group by e.patient_id,visit_date;
group by e.patient_id,e.encounter_id;
SELECT "Completed processing MCH antenatal visits ", CONCAT("Time: ", NOW());
END $$

Expand Down Expand Up @@ -1748,7 +1748,7 @@ CREATE PROCEDURE sp_populate_dwapi_hei_enrolment()
select encounter_type_id, uuid, name from encounter_type where
uuid in('415f5136-ca4a-49a8-8db3-f994187c3af6','01894f88-dc73-42d4-97a3-0929118403fb')
) et on et.encounter_type_id=e.encounter_type
group by e.patient_id,visit_date ;
group by e.patient_id,e.encounter_id ;
SELECT "Completed processing HEI Enrollments", CONCAT("Time: ", NOW());
END $$

Expand Down Expand Up @@ -1903,7 +1903,7 @@ CREATE PROCEDURE sp_populate_dwapi_hei_follow_up()
select encounter_type_id, uuid, name from encounter_type where
uuid in('bcc6da85-72f2-4291-b206-789b8186a021','c6d09e05-1f25-4164-8860-9f32c5a02df0')
) et on et.encounter_type_id=e.encounter_type
group by e.patient_id,visit_date;
group by e.patient_id,e.encounter_id;

SELECT "Completed processing HEI Followup visits", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -2050,7 +2050,7 @@ CREATE PROCEDURE sp_populate_dwapi_hei_immunization()
)
) y
left join obs o on y.encounter_id = o.encounter_id and o.voided=0
group by patient_id;
group by patient_id,encounter_id;

SELECT "Completed processing hei_immunization data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -2304,7 +2304,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 ("22c68f86-bbf0-49ba-b2d1-23fa7ccf0259", "59ed8e62-7f1f-40ae-a2e3-eabe350277ce","23b4ebbd-29ad-455e-be0e-04aa6bc30798","72aa78e0-ee4b-47c3-9073-26f3b9ecc4a7")
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (1659, 1113, 160632,161643,1729,1271,307,12,162202,1272,163752,163414,162275,162309,1109) and o.voided=0
group by e.patient_id,visit_date;
group by e.patient_id,e.encounter_id;

SELECT "Completed processing TB Screening data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -2698,7 +2698,7 @@ INSERT INTO dwapi_etl.etl_hts_referral_and_linkage (
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 ("050a7f12-5c52-4cad-8834-863695af335d","15ed03d2-c972-11e9-a32f-2a2ae2dbcce4")
left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966, 159811, 162724, 160555, 159599, 162053, 1473,162577,160481) and o.voided=0
group by e.patient_id,e.visit_id;
group by e.patient_id,e.encounter_id;
SELECT "Completed processing hts linkages";

END $$
Expand Down Expand Up @@ -3236,7 +3236,7 @@ CREATE PROCEDURE sp_populate_dwapi_patient_triage()
) et on et.encounter_type_id=e.encounter_type
left outer join obs o on o.encounter_id=e.encounter_id and o.voided=0
and o.concept_id in (160430,1154,159368,5089,5090,5085,5086,5088,5087,5242,5092,1343,163515,163300,1427,160325,162584)
group by e.patient_id, visit_date
group by e.patient_id, e.encounter_id
;
SELECT "Completed processing Patient Triage data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -3750,7 +3750,7 @@ CREATE PROCEDURE sp_populate_dwapi_prep_followup()
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (161558,165098,165200,165308,165099,1272,1472,5272,5596,1426,164933,5632,160653,374,
165103,161033,1596,164122,162747,1284,159948,1282,1443,1444,160855,159368,1732,121764,1193,159935,162760,1255,160557,160643,159935,162760,160753,165101,165104,165106,
165109,167788,165144,166866,159777,165055,165309,5096,165310,163042,134346,164075,160582,160632,1417,164515,164433,165353,165354) and o.voided=0
group by e.patient_id,visit_date;
group by e.patient_id,e.encounter_id;
SELECT "Completed processing PrEP follow-up form", CONCAT("Time: ", NOW());
END $$

Expand Down Expand Up @@ -6257,7 +6257,7 @@ BEGIN
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 ('a74e3e4a-9e2a-41fb-8e64-4ba8a71ff984')
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (160482,165143,167094,160632,167131) and o.voided=0
group by e.patient_id,date(e.encounter_datetime);
group by e.patient_id,e.encounter_id;

SELECT "Completed processing vmmc enrolment data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -6336,7 +6336,7 @@ BEGIN
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 ('5ee93f48-960b-11ec-b909-0242ac120002')
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (167118,167119,163042,167120,163042,163049,164964,164254,160047,166650,160715,163138,167132,162871,162875,162760,162749,1473,163556,164141,166014,167133) and o.voided=0
group by e.patient_id,date(e.encounter_datetime);
group by e.patient_id,e.encounter_id;

SELECT "Completed processing vmmc circumcision procedure data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -6399,7 +6399,7 @@ CREATE PROCEDURE sp_populate_dwapi_vmmc_client_followup()
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 ('08873f91-7161-4f90-931d-65b131f2b12b')
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164181,162871,162875,162760,162749,159369,161011,1473,1542,160632) and o.voided=0
group by e.patient_id,date(e.encounter_datetime);
group by e.patient_id,e.encounter_id;

SELECT "Completed processing vmmc client followup data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -6524,7 +6524,7 @@ CREATE PROCEDURE sp_populate_dwapi_vmmc_client_followup()
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (167093,1710,159427,160554,164855,159599,162053,5096,165239,161550,856,
5497,1628,1728,163047,1794,163104,21,887,160557,164896,163393,54,161536,
1410,5085,5086,5242,5088,1855,165070,162169,167118,167119,167120,163049,163042,1272) and o.voided=0
group by e.patient_id,date(e.encounter_datetime);
group by e.patient_id,e.encounter_id;

SELECT "Completed processing vmmc medical examination form data ", CONCAT("Time: ", NOW());
END $$
Expand Down Expand Up @@ -6593,7 +6593,7 @@ CREATE PROCEDURE sp_populate_dwapi_vmmc_client_followup()
(5085, 5086, 5087, 5088, 162871,
160632, 159369, 161011, 160753, 5096,
1473, 1542) and o.voided=0
group by e.patient_id, date(e.encounter_datetime);
group by e.patient_id, e.encounter_id;

END $$

Expand Down Expand Up @@ -6790,7 +6790,7 @@ CREATE PROCEDURE sp_populate_dwapi_hts_eligibility_screening()
166559,159218,163568,167161,1396,167145,160658,165205,164845,165269,112141,
165203,1691,165200,165197,1729,1659,165090,165060,166365,165908,165098,
5272,5632,162699,1788,159803,160632,164126,159803,164082,160416,164951,162558,167229,160540,167163,167162,1396,5569,164956) and o.voided=0
group by e.patient_id,date(e.encounter_datetime);
group by e.patient_id,e.encounter_id;
SELECT "Completed processing hts eligibility screening";
END $$

Expand Down Expand Up @@ -7066,7 +7066,7 @@ BEGIN
inner join form f on f.form_id = e.form_id and f.uuid in ('92fd9c5a-c84a-483b-8d78-d4d7a600db30','d753bab3-0bbb-43f5-9796-5e95a5d641f3')
left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in
(162725,165146,165133,165006,165005,165136,165140,1193,163101,165141,160632,1473,165144,165143,160753) and o.voided=0
group by e.patient_id,e.encounter_type;
group by e.patient_id,e.encounter_type,e.encounter_id;
SELECT "Completed processing overdose reporting";
END $$

Expand Down Expand Up @@ -7182,6 +7182,7 @@ INSERT INTO dwapi_etl.etl_clinical_encounter (
other_counselling_ordered,
procedures_prescribed,
procedures_ordered,
patient_outcome,
admission_needed,
date_of_patient_admission,
admission_reason,
Expand Down Expand Up @@ -7258,6 +7259,7 @@ select
nullif(max(if(o.concept_id=164174 and o.value_coded = 1000222,'Enema Administration','')),''),
nullif(max(if(o.concept_id=164174 and o.value_coded = 127896,'Lumbar Puncture','')),''),
nullif(max(if(o.concept_id=164174,o.value_text,'')),'')) as procedures_ordered,
max(if(o.concept_id=160433,o.value_coded,null)) as patient_outcome,
max(if(o.concept_id=1651,(case o.value_coded when 1065 then 'Yes' when 1066 THEN 'No' else '' end),null)) as admission_needed,
max(if(o.concept_id = 1640,o.value_datetime,null)) as date_of_patient_admission,
max(if(o.concept_id=164174,o.value_text,null)) as admission_reason,
Expand Down Expand Up @@ -7296,10 +7298,10 @@ 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 = 'e958f902-64df-4819-afd4-7fb061f59308'
left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in
(164174,160632,165104,1651,1640,162477,1655,1000075,1896,1272,162724)
(164174,160632,165104,1651,1640,162477,1655,1000075,1896,1272,162724,160433)
and o.voided=0
where e.voided=0
group by e.patient_id,date(e.encounter_datetime);
group by e.patient_id,e.encounter_id;
SELECT "Completed processing Clinical Encounter";
END $$

Expand Down

0 comments on commit 463fa36

Please sign in to comment.