diff --git a/omod/src/main/resources/sql/DDL.sql b/omod/src/main/resources/sql/DDL.sql index d747b1c7..88498f83 100644 --- a/omod/src/main/resources/sql/DDL.sql +++ b/omod/src/main/resources/sql/DDL.sql @@ -97,6 +97,7 @@ DROP TABLE IF EXISTS kenyaemr_etl.etl_hts_eligibility_screening; DROP TABLE IF EXISTS kenyaemr_etl.etl_drug_order; DROP TABLE IF EXISTS kenyaemr_etl.etl_preventive_services; DROP TABLE IF EXISTS kenyaemr_etl.etl_overdose_reporting; +DROP TABLE IF EXISTS kenyaemr_etl.etl_art_fast_track; -- create table etl_patient_demographics create table kenyaemr_etl.etl_patient_demographics ( @@ -3265,6 +3266,49 @@ create table kenyaemr_etl.etl_overdose_reporting ( ); SELECT "Successfully created etl_overdose_reporting table"; +-- Create etl_overdose_reporting table"; +CREATE TABLE kenyaemr_etl.etl_art_fast_track +( + uuid char(38), + provider INT(11), + patient_id INT(11) NOT NULL, + visit_id INT(11), + visit_date DATE, + location_id INT(11) DEFAULT NULL, + encounter_id INT(11) NOT NULL, + art_refill_model INT(11), + ctx_dispensed INT(11), + dapsone_dispensed INT(11), + oral_contraceptives_dispensed INT(11), + condoms_distributed INT(11), + missed_arv_doses_since_last_visit INT(11), + doses_missed INT(11), + fatigue INT(11), + cough INT(11), + fever INT(11), + rash INT(11), + nausea_vomiting INT(11), + genital_sore_discharge INT(11), + diarrhea INT(11), + other_symptoms INT(11), + other_specific_symptoms INT(11), + pregnant INT(11), + family_planning_status INT(11), + family_planning_method varchar(250), + reason_not_on_family_planning varchar(250), + referred_to_clinic INT(11), + return_visit_date DATE, + 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 unique_uuid UNIQUE (uuid), + INDEX (visit_date), + INDEX (patient_id), + INDEX (encounter_id) +); +SELECT "Successfully created etl_art_fast_track table"; + UPDATE kenyaemr_etl.etl_script_status SET stop_time=NOW() where id= script_id; END $$ diff --git a/omod/src/main/resources/sql/DML.sql b/omod/src/main/resources/sql/DML.sql index 0e2e3e65..d1b14ccc 100644 --- a/omod/src/main/resources/sql/DML.sql +++ b/omod/src/main/resources/sql/DML.sql @@ -6941,6 +6941,100 @@ BEGIN group by e.patient_id,e.encounter_type; SELECT "Completed processing overdose reporting"; END $$ + +-- Procedure sp_populate_etl_art_fast_track -- +DROP PROCEDURE IF EXISTS sp_populate_etl_art_fast_track $$ +CREATE PROCEDURE sp_populate_etl_art_fast_track() +BEGIN + SELECT "Processing ART fast track"; + INSERT INTO kenyaemr_etl.etl_art_fast_track (uuid, + provider, + patient_id, + visit_id, + visit_date, + location_id, + encounter_id, + art_refill_model, + ctx_dispensed, + dapsone_dispensed, + oral_contraceptives_dispensed, + condoms_distributed, + doses_missed, + fatigue, + cough, + fever, + rash, + nausea_vomiting, + genital_sore_discharge, + diarrhea, + other_symptoms, + other_specific_symptoms, + pregnant, + family_planning_status, + family_planning_method, + reason_not_on_family_planning, + referred_to_clinic, + return_visit_date, + date_created, + date_last_modified, + voided) + select e.uuid, + e.creator as provider, + e.patient_id, + e.visit_id, + date(e.encounter_datetime) as visit_date, + e.location_id, + e.encounter_id, + max(if(o.concept_id = 1758, o.value_coded, null)) as art_refill_model, + max(if(o.concept_id = 1282 and o.value_coded = 162229, o.value_coded, + null)) as ctx_dispensed, + max(if(o.concept_id = 1282 and o.value_coded = 74250, o.value_coded, null)) as dapsone_dispensed, + max(if(o.concept_id = 1282 and o.value_coded = 780, o.value_coded, null)) as oral_contraceptives_dispensed, + max(if(o.concept_id = 159777, o.value_coded, null)) as condoms_distributed, + max(if(o.concept_id = 162878, o.value_numeric, null)) as doses_missed, + max(if(o.concept_id = 1284 and o.value_coded = 162626, o.value_coded, null)) as fatigue, + max(if(o.concept_id = 1284 and o.value_coded = 143264, o.value_coded, null)) as cough, + max(if(o.concept_id = 1284 and o.value_coded = 140238, o.value_coded, null)) as fever, + max(if(o.concept_id = 1284 and o.value_coded = 512, o.value_coded, null)) as rash, + max(if(o.concept_id = 1284 and o.value_coded = 5978, o.value_coded, null)) as nausea_vomiting, + max(if(o.concept_id = 1284 and o.value_coded = 135462, o.value_coded, null)) as genital_sore_discharge, + max(if(o.concept_id = 1284 and o.value_coded = 142412, o.value_coded, null)) as diarrhea, + max(if(o.concept_id = 1284 and o.value_coded = 5622, o.value_coded, null)) as other_symptoms, + max(if(o.concept_id = 160632, o.value_text, null)) as other_specific_symptoms, + max(if(o.concept_id = 5272, o.value_coded, null)) as pregnant, + max(if(o.concept_id = 160653, o.value_coded, null)) as family_planning_status, + concat_ws(',', max(if(o.concept_id = 374 and o.value_coded = 160570, 'Emergency contraceptive pills', null)), + max(if(o.concept_id = 374 and o.value_coded = 780, 'Oral Contraceptives Pills', null)), + max(if(o.concept_id = 374 and o.value_coded = 5279, 'Injectible', null)), + max(if(o.concept_id = 374 and o.value_coded = 1359, 'Implant', null)), + max(if(o.concept_id = 374 and o.value_coded = 5275, 'Intrauterine Device', null)), + max(if(o.concept_id = 374 and o.value_coded = 136163, 'Lactational Amenorhea Method', null)), + max(if(o.concept_id = 374 and o.value_coded = 5278, 'Diaphram/Cervical Cap', null)), + max(if(o.concept_id = 374 and o.value_coded = 159524, 'Fertility Awareness', null)), + max(if(o.concept_id = 374 and o.value_coded = 1472, 'Tubal Ligation', null)), + max(if(o.concept_id = 374 and o.value_coded = 190, 'Condoms', null)), + max(if(o.concept_id = 374 and o.value_coded = 1489, 'Vasectomy(Partner)', null)), + max(if(o.concept_id = 374 and o.value_coded = 1175, 'Undecided', null))) as family_planning_method, + concat_ws(',', max(if(o.concept_id = 160575 and o.value_coded = 160572, 'Thinks cannot get pregnant', null)), + max(if(o.concept_id = 160575 and o.value_coded = 160573, 'Not sexually active now', + null))) as reason_not_on_family_planning, + max(if(o.concept_id = 512, o.value_coded, null)) as referred_to_clinic, + max(if(o.concept_id = 2096, o.value_datetime, null)) as return_visit_date, + e.date_created, + if(max(o.date_created) > min(e.date_created), max(o.date_created), + NULL) as date_last_modified, + e.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 = '83fb6ab2-faec-4d87-a714-93e77a28a201' + left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in + (1758, 1282, 159777, 162878, 1284, 5272, + 160653, 374, 160575, 512, 2096) + and o.voided = 0 + where e.voided = 0 + group by e.patient_id; + SELECT "Completed processing ART fast track"; +END $$ -- end of dml procedures SET sql_mode=@OLD_SQL_MODE $$ @@ -7027,6 +7121,7 @@ CALL sp_populate_etl_hts_eligibility_screening(); CALL sp_populate_etl_drug_order(); CALL sp_populate_etl_preventive_services(); CALL sp_populate_etl_overdose_reporting(); +CALL sp_populate_etl_art_fast_track(); UPDATE kenyaemr_etl.etl_script_status SET stop_time=NOW() where id= populate_script_id; diff --git a/omod/src/main/resources/sql/DataTools.sql b/omod/src/main/resources/sql/DataTools.sql index 888fd6a3..4f01eb6d 100644 --- a/omod/src/main/resources/sql/DataTools.sql +++ b/omod/src/main/resources/sql/DataTools.sql @@ -2626,7 +2626,7 @@ ALTER TABLE kenyaemr_datatools.preventive_services ADD INDEX(patient_id); ALTER TABLE kenyaemr_datatools.preventive_services ADD INDEX(visit_date); SELECT "Successfully created preventive_services table"; --- create table preventive_services +-- create table overdose_reporting create table kenyaemr_datatools.overdose_reporting as select client_id, @@ -2672,13 +2672,66 @@ select date_last_modified, voided from kenyaemr_etl.etl_overdose_reporting; - ALTER TABLE kenyaemr_datatools.overdose_reporting ADD FOREIGN KEY (client_id) REFERENCES kenyaemr_datatools.patient_demographics(patient_id); ALTER TABLE kenyaemr_datatools.overdose_reporting ADD INDEX(client_id); ALTER TABLE kenyaemr_datatools.overdose_reporting ADD INDEX(visit_date); 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 ART fast track +create table kenyaemr_datatools.art_fast_track as +select patient_id, + visit_date, + provider, + location_id, + encounter_id, + case art_refill_model + when 1744 then 'Fast Track' + when 1555 then 'Community ART Distribution - HCW Led' + when 5618 then 'Community ART Distribution - Peer Led' + when 1537 then 'Facility ART Distribution Group' + else null end as art_refill_model, + case ctx_dispensed when 162229 then 'Yes' else null end as ctx_dispensed, + case dapsone_dispensed when 74250 then 'Yes' else null end as dapsone_dispensed, + case oral_contraceptives_dispensed when 780 then 'Yes' else null end as oral_contraceptives_dispensed, + case condoms_distributed + when 1065 then 'Yes' + when 1066 then 'No' + else null end as condoms_distributed, + doses_missed, + case fatigue when 162626 then 'Yes' when 1066 then 'No' else null end as fatigue, + case cough when 143264 then 'Yes' when 1066 then 'No' else null end as cough, + case fever when 140238 then 'Yes' when 1066 then 'No' else null end as fever, + case rash when 512 then 'Yes' when 1066 then 'No' else null end as rash, + case nausea_vomiting when 5978 then 'Yes' when 1066 then 'No' else null end as nausea_vomiting, + case genital_sore_discharge + when 135462 then 'Yes' + when 1066 then 'No' + else null end as genital_sore_discharge, + case diarrhea when 142412 then 'Yes' when 1066 then 'No' else null end as diarrhea, + case other_symptoms when 5622 then 'Yes' else null end as other_symptoms, + other_specific_symptoms, + case pregnant when 1065 then 'Yes' when 1066 then 'No' when 1067 then 'Not sure' else null end as pregnant, + case family_planning_status + when 965 then 'On Family Planning' + when 160652 then 'Not using Family Planning' + when 1360 then 'Wants Family Planning' + else null end as family_planning_status, + family_planning_method, + reason_not_on_family_planning, + date_created, + date_last_modified, + voided +from kenyaemr_etl.etl_art_fast_track; +ALTER TABLE kenyaemr_datatools.art_fast_track + ADD FOREIGN KEY (patient_id) REFERENCES kenyaemr_datatools.patient_demographics (patient_id); +ALTER TABLE kenyaemr_datatools.art_fast_track + ADD INDEX (patient_id); +ALTER TABLE kenyaemr_datatools.art_fast_track + ADD INDEX (visit_date); +SELECT "Successfully created art_fast_track table"; + UPDATE kenyaemr_etl.etl_script_status SET stop_time=NOW() where id= script_id; END $$ diff --git a/omod/src/main/resources/sql/Scheduled_Updates.sql b/omod/src/main/resources/sql/Scheduled_Updates.sql index 2204d22b..f2b912f7 100644 --- a/omod/src/main/resources/sql/Scheduled_Updates.sql +++ b/omod/src/main/resources/sql/Scheduled_Updates.sql @@ -7698,6 +7698,130 @@ BEGIN voided=VALUES(voided); SELECT "Completed processing overdose reporting"; END $$ + +DROP PROCEDURE IF EXISTS sp_update_etl_art_fast_track $$ +CREATE PROCEDURE sp_update_etl_art_fast_track(IN last_update_time DATETIME) +BEGIN + SELECT "Processing ART fast track"; + INSERT INTO kenyaemr_etl.etl_art_fast_track (uuid, + provider, + patient_id, + visit_id, + visit_date, + location_id, + encounter_id, + art_refill_model, + ctx_dispensed, + dapsone_dispensed, + oral_contraceptives_dispensed, + condoms_distributed, + doses_missed, + fatigue, + cough, + fever, + rash, + nausea_vomiting, + genital_sore_discharge, + diarrhea, + other_symptoms, + other_specific_symptoms, + pregnant, + family_planning_status, + family_planning_method, + reason_not_on_family_planning, + referred_to_clinic, + return_visit_date, + date_created, + date_last_modified, + voided) + select e.uuid, + e.creator as provider, + e.patient_id, + e.visit_id, + date(e.encounter_datetime) as visit_date, + e.location_id, + e.encounter_id, + max(if(o.concept_id = 1758, o.value_coded, null)) as art_refill_model, + max(if(o.concept_id = 1282 and o.value_coded = 162229, o.value_coded, + null)) as ctx_dispensed, + max(if(o.concept_id = 1282 and o.value_coded = 74250, o.value_coded, null)) as dapsone_dispensed, + max(if(o.concept_id = 1282 and o.value_coded = 780, o.value_coded, null)) as oral_contraceptives_dispensed, + max(if(o.concept_id = 159777, o.value_coded, null)) as condoms_distributed, + max(if(o.concept_id = 162878, o.value_numeric, null)) as doses_missed, + max(if(o.concept_id = 1284 and o.value_coded = 162626, o.value_coded, null)) as fatigue, + max(if(o.concept_id = 1284 and o.value_coded = 143264, o.value_coded, null)) as cough, + max(if(o.concept_id = 1284 and o.value_coded = 140238, o.value_coded, null)) as fever, + max(if(o.concept_id = 1284 and o.value_coded = 512, o.value_coded, null)) as rash, + max(if(o.concept_id = 1284 and o.value_coded = 5978, o.value_coded, null)) as nausea_vomiting, + max(if(o.concept_id = 1284 and o.value_coded = 135462, o.value_coded, null)) as genital_sore_discharge, + max(if(o.concept_id = 1284 and o.value_coded = 142412, o.value_coded, null)) as diarrhea, + max(if(o.concept_id = 1284 and o.value_coded = 5622, o.value_coded, null)) as other_symptoms, + max(if(o.concept_id = 160632, o.value_text, null)) as other_specific_symptoms, + max(if(o.concept_id = 5272, o.value_coded, null)) as pregnant, + max(if(o.concept_id = 160653, o.value_coded, null)) as family_planning_status, + concat_ws(',', max(if(o.concept_id = 374 and o.value_coded = 160570, 'Emergency contraceptive pills', null)), + max(if(o.concept_id = 374 and o.value_coded = 780, 'Oral Contraceptives Pills', null)), + max(if(o.concept_id = 374 and o.value_coded = 5279, 'Injectible', null)), + max(if(o.concept_id = 374 and o.value_coded = 1359, 'Implant', null)), + max(if(o.concept_id = 374 and o.value_coded = 5275, 'Intrauterine Device', null)), + max(if(o.concept_id = 374 and o.value_coded = 136163, 'Lactational Amenorhea Method', null)), + max(if(o.concept_id = 374 and o.value_coded = 5278, 'Diaphram/Cervical Cap', null)), + max(if(o.concept_id = 374 and o.value_coded = 159524, 'Fertility Awareness', null)), + max(if(o.concept_id = 374 and o.value_coded = 1472, 'Tubal Ligation', null)), + max(if(o.concept_id = 374 and o.value_coded = 190, 'Condoms', null)), + max(if(o.concept_id = 374 and o.value_coded = 1489, 'Vasectomy(Partner)', null)), + max(if(o.concept_id = 374 and o.value_coded = 1175, 'Undecided', null))) as family_planning_method, + concat_ws(',', max(if(o.concept_id = 160575 and o.value_coded = 160572, 'Thinks cannot get pregnant', null)), + max(if(o.concept_id = 160575 and o.value_coded = 160573, 'Not sexually active now', + null))) as reason_not_on_family_planning, + max(if(o.concept_id = 512, o.value_coded, null)) as referred_to_clinic, + max(if(o.concept_id = 2096, o.value_datetime, null)) as return_visit_date, + e.date_created, + if(max(o.date_created) > min(e.date_created), max(o.date_created), + NULL) as date_last_modified, + e.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 = '83fb6ab2-faec-4d87-a714-93e77a28a201' + left outer join obs o on o.encounter_id = e.encounter_id and o.concept_id in + (1758, 1282, 159777, 162878, 1284, 5272, + 160653, 374, 160575, 512, 2096) + and o.voided = 0 + 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 + or o.date_created >= last_update_time + or o.date_voided >= last_update_time + group by e.patient_id + ON DUPLICATE KEY UPDATE visit_date=VALUES(visit_date), + provider=VALUES(provider), + art_refill_model=VALUES(art_refill_model), + ctx_dispensed=VALUES(ctx_dispensed), + dapsone_dispensed=VALUES(dapsone_dispensed), + oral_contraceptives_dispensed=VALUES(oral_contraceptives_dispensed), + condoms_distributed=VALUES(condoms_distributed), + doses_missed=VALUES(doses_missed), + fatigue=VALUES(fatigue), + cough=VALUES(cough), + fever=VALUES(fever), + rash=VALUES(rash), + nausea_vomiting=VALUES(nausea_vomiting), + genital_sore_discharge=VALUES(genital_sore_discharge), + diarrhea=VALUES(diarrhea), + other_symptoms=VALUES(other_symptoms), + other_specific_symptoms=VALUES(other_specific_symptoms), + pregnant=VALUES(pregnant), + family_planning_status=VALUES(family_planning_status), + family_planning_method=VALUES(family_planning_method), + reason_not_on_family_planning=VALUES(reason_not_on_family_planning), + referred_to_clinic=VALUES(referred_to_clinic), + return_visit_date=VALUES(return_visit_date), + date_created=VALUES(date_created), + date_last_modified=VALUES(date_last_modified), + voided=VALUES(voided); + SELECT "Completed processing ART fast track"; +END $$ -- end of scheduled updates procedures SET sql_mode=@OLD_SQL_MODE $$ @@ -7779,6 +7903,7 @@ CREATE PROCEDURE sp_scheduled_updates() CALL sp_update_etl_drug_order(last_update_time); CALL sp_update_etl_preventive_services(last_update_time); CALL sp_update_etl_overdose_reporting(last_update_time); + CALL sp_update_etl_art_fast_track(last_update_time); CALL sp_update_dashboard_table();