Skip to content

Commit

Permalink
Merge pull request #377 from njorocs/KHP3-3931
Browse files Browse the repository at this point in the history
Adding kenyaemr_datatools.art_fast_track
  • Loading branch information
patryllus authored Oct 5, 2023
2 parents 08ea965 + 2698386 commit ad2487c
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 2 deletions.
44 changes: 44 additions & 0 deletions omod/src/main/resources/sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 $$
95 changes: 95 additions & 0 deletions omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 $$
Expand Down Expand Up @@ -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;

Expand Down
57 changes: 55 additions & 2 deletions omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 $$
Expand Down
Loading

0 comments on commit ad2487c

Please sign in to comment.