Skip to content

Commit

Permalink
Merge pull request #390 from njorocs/KHP3-3324-Rebase
Browse files Browse the repository at this point in the history
Added defaulter tracing in datatools. Added reason_not_contacted colu…
  • Loading branch information
makombe authored Oct 12, 2023
2 parents 1261eba + 1d51c8b commit e1ba267
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 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 @@ -1440,6 +1440,7 @@ missed_appointment_date DATE,
reason_for_missed_appointment INT(11),
non_coded_missed_appointment_reason VARCHAR(100),
tracing_outcome INT(11),
reason_not_contacted INT(11),
attempt_number INT(11),
is_final_trace INT(11),
true_status INT(11),
Expand Down
4 changes: 3 additions & 1 deletion omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,7 @@ missed_appointment_date,
reason_for_missed_appointment,
non_coded_missed_appointment_reason,
tracing_outcome,
reason_not_contacted,
attempt_number,
is_final_trace,
true_status,
Expand All @@ -3100,6 +3101,7 @@ max(if(o.concept_id=164093,date(o.value_datetime),null)) as missed_appointment_d
max(if(o.concept_id = 1801, o.value_coded, null )) as reason_for_missed_appointment,
max(if(o.concept_id = 163513, o.value_text, "" )) as non_coded_missed_appointment_reason,
max(if(o.concept_id = 160721, o.value_coded, null )) as tracing_outcome,
max(if(o.concept_id = 166541, o.value_coded, null )) as reason_not_contacted,
max(if(o.concept_id = 1639, value_numeric, "" )) as attempt_number,
max(if(o.concept_id = 163725, o.value_coded, "" )) as is_final_trace,
max(if(o.concept_id = 160433, o.value_coded, "" )) as true_status,
Expand All @@ -3111,7 +3113,7 @@ if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_l
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 ("a1a62d1e-2def-11e9-b210-d663bd873d93")
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966,164093,1801, 163513, 160721, 1639, 163725, 160433, 1599, 160716,163526) and o.voided=0
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966,164093,1801, 163513, 160721, 1639, 163725, 160433, 1599, 160716,163526,166541) and o.voided=0
where e.voided=0
group by e.encounter_id;
SELECT "Completed processing CCC defaulter tracing forms", CONCAT("Time: ", NOW());
Expand Down
71 changes: 71 additions & 0 deletions omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,77 @@ ALTER TABLE kenyaemr_datatools.overdose_reporting ADD INDEX(naloxone_provided);
ALTER TABLE kenyaemr_datatools.overdose_reporting ADD INDEX(outcome);
SELECT "Successfully created overdose_reporting table";

-- Create table ccc_defaulter_tracing
create table kenyaemr_datatools.ccc_defaulter_tracing as
select uuid,
provider,
patient_id,
visit_id,
visit_date,
location_id,
encounter_id,
(case f.tracing_type
when 1650 then 'Client Called'
when 164965 then 'Physical Tracing'
when 161642 then 'Treatment supporter' end) as tracing_type,
case f.tracing_outcome when 1267 then 'Contact' when 1118 then 'No Contact' end as tracing_outcome,
missed_appointment_date,
(case f.reason_for_missed_appointment
when 165609 then 'Client has covid-19 infection'
when 165610 then 'COVID-19 restrictions'
when 164407 then 'Client refilled drugs from another facility'
when 159367 then 'Client has enough drugs'
when 162619 then 'Client travelled'
when 126240 then 'Client could not get an off from work/school'
when 160583 then 'Client is sharing drugs with partner'
when 162192 then 'Client forgot clinic dates'
when 164349 then 'Client stopped medications'
when 1654 then 'Client sick at home/admitted'
when 5622
then 'Other' end) as reason_for_missed_appointment,
non_coded_missed_appointment_reason,
(case f.reason_not_contacted
when 166538 then 'No locator information'
when 165075 then 'Inaccurate locator information'
when 160034 then 'Died'
when 1302 then 'Calls not going through'
when 1567 then 'Not picking calls'
when 160415 then 'Migrated from reported location'
when 1706 then 'Not found at home'
when 5622 then 'Other' end) as reason_not_contacted,
attempt_number,
(case f.is_final_trace when 1267 then 'Yes' when 163339 then 'No' end) as is_final_trace,
(case f.true_status
when 160432 then 'Dead'
when 1693 then 'Receiving ART from another clinic/Transferred'
when 160037 then 'Still in care at CCC'
when 5240 then 'Lost to follow up'
when 164435 then 'Stopped treatment'
when 142917 then 'Other' end) as true_status,
(case f.cause_of_death
when 165609 then 'Infection due to COVID-19'
when 162574 then 'Death related to HIV infection'
when 116030 then 'Cancer'
when 164500 then 'TB'
when 151522 then 'Other infectious and parasitic diseases'
when 133481 then 'Natural cause'
when 1603 then 'Unnatural Cause'
when 5622 then 'Unknown cause' end) as cause_of_death,
comments,
booking_date,
date_created,
date_last_modified
from kenyaemr_etl.etl_ccc_defaulter_tracing f;
Alter table kenyaemr_datatools.ccc_defaulter_tracing
ADD FOREIGN KEY (patient_id) REFERENCES kenyaemr_datatools.patient_demographics (patient_id);
ALTER TABLE kenyaemr_datatools.ccc_defaulter_tracing ADD INDEX (visit_date);
ALTER TABLE kenyaemr_datatools.ccc_defaulter_tracing ADD INDEX (patient_id);
ALTER TABLE kenyaemr_datatools.ccc_defaulter_tracing ADD INDEX (missed_appointment_date);
ALTER TABLE kenyaemr_datatools.ccc_defaulter_tracing ADD INDEX (true_status);
ALTER TABLE kenyaemr_datatools.ccc_defaulter_tracing ADD INDEX (cause_of_death);
ALTER TABLE kenyaemr_datatools.ccc_defaulter_tracing ADD INDEX (tracing_type);
SELECT "Successfully created ccc_defaulter_tracing table";

-- Create table ART fast track
create table kenyaemr_datatools.art_fast_track as
select patient_id,
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 @@ -3010,6 +3010,7 @@ CREATE PROCEDURE sp_update_etl_ccc_defaulter_tracing(IN last_update_time DATETIM
reason_for_missed_appointment,
non_coded_missed_appointment_reason,
tracing_outcome,
reason_not_contacted,
attempt_number,
is_final_trace,
true_status,
Expand All @@ -3026,6 +3027,7 @@ CREATE PROCEDURE sp_update_etl_ccc_defaulter_tracing(IN last_update_time DATETIM
max(if(o.concept_id = 1801, o.value_coded, null )) as reason_for_missed_appointment,
max(if(o.concept_id = 163513, o.value_text, "" )) as non_coded_missed_appointment_reason,
max(if(o.concept_id = 160721, o.value_coded, null )) as tracing_outcome,
max(if(o.concept_id = 166541, o.value_coded, null )) as reason_not_contacted,
max(if(o.concept_id = 1639, value_numeric, "" )) as attempt_number,
max(if(o.concept_id = 163725, o.value_coded, "" )) as is_final_trace,
max(if(o.concept_id = 160433, o.value_coded, "" )) as true_status,
Expand All @@ -3037,7 +3039,7 @@ CREATE PROCEDURE sp_update_etl_ccc_defaulter_tracing(IN last_update_time DATETIM
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 ("a1a62d1e-2def-11e9-b210-d663bd873d93")
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966,164093, 1801, 163513, 160721, 1639, 163725, 160433, 1599, 160716,163526) and o.voided=0
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966,164093, 1801, 163513, 160721, 1639, 163725, 160433, 1599, 160716,163526,166541) and o.voided=0
where e.date_created >= last_update_time
or e.date_changed >= last_update_time
or e.date_voided >= last_update_time
Expand All @@ -3048,6 +3050,7 @@ CREATE PROCEDURE sp_update_etl_ccc_defaulter_tracing(IN last_update_time DATETIM
missed_appointment_date=VALUES(missed_appointment_date),
reason_for_missed_appointment=VALUES(reason_for_missed_appointment),
tracing_outcome=VALUES(tracing_outcome),
reason_not_contacted=VALUES(reason_not_contacted),
attempt_number=VALUES(attempt_number),
is_final_trace=VALUES(is_final_trace),
true_status=VALUES(true_status),
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 @@ -1415,6 +1415,7 @@ missed_appointment_date DATE,
reason_for_missed_appointment INT(11),
non_coded_missed_appointment_reason VARCHAR(100),
tracing_outcome INT(11),
reason_not_contacted INT(11),
attempt_number INT(11),
is_final_trace INT(11),
true_status INT(11),
Expand Down
4 changes: 3 additions & 1 deletion omod/src/main/resources/sql/dwapi/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,7 @@ missed_appointment_date,
reason_for_missed_appointment,
non_coded_missed_appointment_reason,
tracing_outcome,
reason_not_contacted,
attempt_number,
is_final_trace,
true_status,
Expand All @@ -2951,6 +2952,7 @@ max(if(o.concept_id=164093,date(o.value_datetime),null)) as missed_appointment_d
max(if(o.concept_id = 1801, o.value_coded, null )) as reason_for_missed_appointment,
max(if(o.concept_id = 163513, o.value_text, "" )) as non_coded_missed_appointment_reason,
max(if(o.concept_id = 160721, o.value_coded, null )) as tracing_outcome,
max(if(o.concept_id = 166541, o.value_coded, null )) as reason_not_contacted,
max(if(o.concept_id = 1639, value_numeric, "" )) as attempt_number,
max(if(o.concept_id = 163725, o.value_coded, "" )) as is_final_trace,
max(if(o.concept_id = 160433, o.value_coded, "" )) as true_status,
Expand All @@ -2963,7 +2965,7 @@ e.voided as voided
from encounter e
inner join person p on p.person_id=e.patient_id
inner join form f on f.form_id=e.form_id and f.uuid in ("a1a62d1e-2def-11e9-b210-d663bd873d93")
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966,164093,1801, 163513, 160721, 1639, 163725, 160433, 1599, 160716,163526)
inner join obs o on o.encounter_id = e.encounter_id and o.concept_id in (164966,164093,1801, 163513, 160721, 1639, 163725, 160433, 1599, 160716,163526,166541)
group by e.encounter_id;
SELECT "Completed processing CCC defaulter tracing forms", CONCAT("Time: ", NOW());
END $$
Expand Down

0 comments on commit e1ba267

Please sign in to comment.