Skip to content

Commit

Permalink
Merge pull request #436 from patryllus/revised-tools-pnc
Browse files Browse the repository at this point in the history
Added test 3 rd tier testing for etl_hts_test and etl_mch_post_natal, referral_reasons form etl_post_natal
  • Loading branch information
njorocs authored May 9, 2024
2 parents 4ad8fa9 + af9e018 commit d257425
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 15 deletions.
12 changes: 11 additions & 1 deletion omod/src/main/resources/sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,10 @@ SELECT "Successfully created etl_patient_program_discontinuation table";
test_2_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_2_kit_expiry DATE DEFAULT NULL,
test_2_result VARCHAR(50) DEFAULT NULL,
test_3_kit_name VARCHAR(50),
test_3_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_3_kit_expiry DATE DEFAULT NULL,
test_3_result VARCHAR(50) DEFAULT NULL,
final_test_result VARCHAR(50) DEFAULT NULL,
syphilis_results INT(11) DEFAULT NULL,
patient_given_result VARCHAR(50) DEFAULT NULL,
Expand All @@ -862,6 +866,7 @@ SELECT "Successfully created etl_patient_program_discontinuation table";
family_planning_method INT(11),
referred_from INT(11),
referred_to INT(11),
referral_reason VARCHAR(255) DEFAULT NULL,
clinical_notes VARCHAR(200) DEFAULT NULL,
appointment_date DATE DEFAULT NULL,
date_created DATETIME NOT NULL,
Expand Down Expand Up @@ -1294,6 +1299,10 @@ test_2_kit_name VARCHAR(50),
test_2_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_2_kit_expiry DATE DEFAULT NULL,
test_2_result VARCHAR(50) DEFAULT NULL,
test_3_kit_name VARCHAR(50),
test_3_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_3_kit_expiry DATE DEFAULT NULL,
test_3_result VARCHAR(50) DEFAULT NULL,
final_test_result VARCHAR(50) DEFAULT NULL,
syphillis_test_result VARCHAR(50) DEFAULT NULL,
patient_given_result VARCHAR(50) DEFAULT NULL,
Expand All @@ -1319,7 +1328,8 @@ index(test_type),
index(final_test_result),
index(couple_discordant),
index(test_1_kit_name),
index(test_2_kit_name)
index(test_2_kit_name),
index(test_3_kit_name)
);

-- ------------- CREATE HTS LINKAGE AND REFERRALS ------------------------
Expand Down
30 changes: 25 additions & 5 deletions omod/src/main/resources/sql/DML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,10 @@ CREATE PROCEDURE sp_populate_etl_mch_postnatal_visit()
test_2_kit_lot_no,
test_2_kit_expiry,
test_2_result,
test_3_kit_name,
test_3_kit_lot_no,
test_3_kit_expiry,
test_3_result,
final_test_result,
syphilis_results,
patient_given_result,
Expand All @@ -1534,6 +1538,7 @@ CREATE PROCEDURE sp_populate_etl_mch_postnatal_visit()
family_planning_method,
referred_from,
referred_to,
referral_reason,
clinical_notes,
date_created,
date_last_modified
Expand Down Expand Up @@ -1597,6 +1602,10 @@ CREATE PROCEDURE sp_populate_etl_mch_postnatal_visit()
max(if(t.test_2_result is not null, t.lot_no, null)) as test_2_kit_lot_no,
max(if(t.test_2_result is not null, t.expiry_date, null)) as test_2_kit_expiry,
max(if(t.test_2_result is not null, t.test_2_result, null)) as test_2_result,
max(if(t.test_3_result is not null, t.kit_name, null)) as test_3_kit_name,
max(if(t.test_3_result is not null, t.lot_no, null)) as test_3_kit_lot_no,
max(if(t.test_3_result is not null, t.expiry_date, null)) as test_3_kit_expiry,
max(if(t.test_3_result is not null, t.test_3_result, null)) as test_3_result,
max(if(o.concept_id=159427,(case o.value_coded when 703 then "Positive" when 664 then "Negative" when 1138 then "Inconclusive" else "" end),null)) as final_test_result,
max(if(o.concept_id=299,o.value_coded,null)) as syphilis_results,
max(if(o.concept_id=164848,(case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end),null)) as patient_given_result,
Expand All @@ -1619,6 +1628,7 @@ CREATE PROCEDURE sp_populate_etl_mch_postnatal_visit()
max(if(o.concept_id=374,o.value_coded,null)) as family_planning_method,
max(if(o.concept_id=160481,o.value_coded,null)) as referred_from,
max(if(o.concept_id=163145,o.value_coded,null)) as referred_to,
max(if(o.concept_id=164359,o.value_text,null)) as referral_reason,
max(if(o.concept_id=159395,o.value_text,null)) as clinical_notes,
e.date_created as date_created,
if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_last_modified
Expand All @@ -1627,7 +1637,7 @@ CREATE PROCEDURE sp_populate_etl_mch_postnatal_visit()
inner join person p on p.person_id=e.patient_id and p.voided=0
inner join obs o on e.encounter_id = o.encounter_id and o.voided =0
and o.concept_id in(1646,159893,5599,5630,1572,5088,5087,5085,5086,5242,5092,5089,5090,1343,21,1147,1856,159780,162128,162110,159840,159844,5245,230,1396,162134,1151,162121,162127,1382,163742,160968,160969,160970,160971,160975,160972,159427,164848,161557,1436,1109,5576,159595,163784,1282,161074,160085,161004,159921,164934,163589,160653,374,160481,163145,159395,159949,5096,161651,165070,
1724,167017,163783,162642,166665,165218,160632,299)
1724,167017,163783,162642,166665,165218,160632,299,164359)
inner join
(
select form_id, uuid,name from form where
Expand All @@ -1640,14 +1650,15 @@ CREATE PROCEDURE sp_populate_etl_mch_postnatal_visit()
o.obs_group_id,
max(if(o.concept_id=1040, (case o.value_coded when 703 then "Positive" when 664 then "Negative" when 163611 then "Invalid" else "" end),null)) as test_1_result ,
max(if(o.concept_id=1326, (case o.value_coded when 703 then "Positive" when 664 then "Negative" when 1175 then "N/A" else "" end),null)) as test_2_result ,
max(if(o.concept_id=164962, (case o.value_coded when 164960 then "Determine" when 164961 then "First Response" when 165351 then "Dual Kit" else "" end),null)) as kit_name ,
max(if(o.concept_id=1000630, (case o.value_coded when 703 then "Positive" when 664 then "Negative" when 1175 then "N/A" else "" end),null)) as test_3_result ,
max(if(o.concept_id=164962, (case o.value_coded when 164960 then "Determine" when 164961 then "First Response" when 165351 then "Dual Kit" when 1000629 then "One step" else "" end),null)) as kit_name ,
max(if(o.concept_id=164964,trim(o.value_text),null)) as lot_no,
max(if(o.concept_id=162502,date(o.value_datetime),null)) as expiry_date
from obs o
inner join encounter e on e.encounter_id = o.encounter_id
inner join person p on p.person_id = o.person_id and p.voided=0
inner join form f on f.form_id=e.form_id and f.uuid in ('72aa78e0-ee4b-47c3-9073-26f3b9ecc4a7')
where o.concept_id in (1040, 1326, 164962, 164964, 162502) and o.voided=0
where o.concept_id in (1040, 1326, 1000630, 164962, 164964, 162502) and o.voided=0
group by e.encounter_id, o.obs_group_id
) t on e.encounter_id = t.encounter_id
where e.voided=0
Expand Down Expand Up @@ -2547,6 +2558,10 @@ test_2_kit_name,
test_2_kit_lot_no,
test_2_kit_expiry,
test_2_result,
test_3_kit_name,
test_3_kit_lot_no,
test_3_kit_expiry,
test_3_result,
final_test_result,
syphillis_test_result,
patient_given_result,
Expand Down Expand Up @@ -2601,6 +2616,10 @@ max(if(t.test_2_result is not null, t.kit_name, null)) as test_2_kit_name,
max(if(t.test_2_result is not null, t.lot_no, null)) as test_2_kit_lot_no,
max(if(t.test_2_result is not null, t.expiry_date, null)) as test_2_kit_expiry,
max(if(t.test_2_result is not null, t.test_2_result, null)) as test_2_result,
max(if(t.test_3_result is not null, t.kit_name, null)) as test_3_kit_name,
max(if(t.test_3_result is not null, t.lot_no, null)) as test_3_kit_lot_no,
max(if(t.test_3_result is not null, t.expiry_date, null)) as test_3_kit_expiry,
max(if(t.test_3_result is not null, t.test_3_result, null)) as test_3_result,
max(if(o.concept_id=159427,(case o.value_coded when 703 then "Positive" when 664 then "Negative" when 1138 then "Inconclusive" when 163611 then "Invalid" else "" end),null)) as final_test_result,
max(if(o.concept_id=299,(case o.value_coded when 1229 then "Positive" when 1228 then "Negative" else "" end),null)) as syphillis_test_result,
max(if(o.concept_id=164848,(case o.value_coded when 1065 then "Yes" when 1066 then "No" else "" end),null)) as patient_given_result,
Expand Down Expand Up @@ -2637,13 +2656,14 @@ inner join (
o.obs_group_id,
max(if(o.concept_id=1040, (case o.value_coded when 703 then "Positive" when 664 then "Negative" when 163611 then "Invalid" else "" end),null)) as test_1_result ,
max(if(o.concept_id=1326, (case o.value_coded when 703 then "Positive" when 664 then "Negative" when 1175 then "N/A" else "" end),null)) as test_2_result ,
max(if(o.concept_id=164962, (case o.value_coded when 164960 then "Determine" when 164961 then "First Response" when 165351 then "Dual Kit" else "" end),null)) as kit_name ,
max(if(o.concept_id=1000630, (case o.value_coded when 703 then "Positive" when 664 then "Negative" when 1175 then "N/A" else "" end),null)) as test_3_result ,
max(if(o.concept_id=164962, (case o.value_coded when 164960 then "Determine" when 164961 then "First Response" when 165351 then "Dual Kit" when 1000629 then "One step" else "" end),null)) as kit_name ,
max(if(o.concept_id=164964,trim(o.value_text),null)) as lot_no,
max(if(o.concept_id=162502,date(o.value_datetime),null)) as expiry_date
from obs o
inner join encounter e on e.encounter_id = o.encounter_id
inner join form f on f.form_id=e.form_id and f.uuid in ("402dc5d7-46da-42d4-b2be-f43ea4ad87b0","b08471f6-0892-4bf7-ab2b-bf79797b8ea4")
where o.concept_id in (1040, 1326, 164962, 164964, 162502) and o.voided=0
where o.concept_id in (1040, 1326, 1000630, 164962, 164964, 162502) and o.voided=0
group by e.encounter_id, o.obs_group_id
) t on e.encounter_id = t.encounter_id
where e.voided=0
Expand Down
2 changes: 1 addition & 1 deletion omod/src/main/resources/sql/DataTools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ SELECT "Successfully created pharmacy extract table";
when 1472 then "Tubal Ligation" when 190 then "Condoms" when 1489 then "Vasectomy" when 162332 then "Undecided" else "" end) as family_planning_method,
(case referred_from when 1537 then "Another Health Facility" when 163488 then "Community Unit" when 1175 then "N/A" else "" end) as referred_from,
(case referred_to when 1537 then "Another Health Facility" when 163488 then "Community Unit" when 165093 then "HIV Preventive services" when 1175 then "N/A" else "" end) as referred_to,
referral_reason,
clinical_notes,
appointment_date

from kenyaemr_etl.etl_mch_postnatal_visit;

ALTER TABLE kenyaemr_datatools.mch_postnatal_visit ADD FOREIGN KEY (patient_id) REFERENCES kenyaemr_datatools.patient_demographics(patient_id);
Expand Down
6 changes: 4 additions & 2 deletions omod/src/main/resources/sql/Scheduled_Updates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ CREATE PROCEDURE sp_update_etl_mch_postnatal_visit(IN last_update_time DATETIME)
family_planning_method,
referred_from,
referred_to,
referral_reason,
clinical_notes,
date_created,
date_last_modified
Expand Down Expand Up @@ -1486,14 +1487,15 @@ CREATE PROCEDURE sp_update_etl_mch_postnatal_visit(IN last_update_time DATETIME)
max(if(o.concept_id=374,o.value_coded,null)) as family_planning_method,
max(if(o.concept_id=160481,o.value_coded,null)) as referred_from,
max(if(o.concept_id=163145,o.value_coded,null)) as referred_to,
max(if(o.concept_id=164359,o.value_text,null)) as referral_reason,
max(if(o.concept_id=159395,o.value_text,null)) as clinical_notes,
e.date_created as date_created,
if(max(o.date_created) > min(e.date_created),max(o.date_created),NULL) as date_last_modified
from encounter e
inner join person p on p.person_id=e.patient_id and p.voided=0
inner join obs o on e.encounter_id = o.encounter_id and o.voided =0
and o.concept_id in(1646,159893,5599,5630,1572,5088,5087,5085,5086,5242,5092,5089,5090,1343,21,1147,1856,159780,162128,162110,159840,159844,5245,230,1396,162134,1151,162121,162127,1382,163742,160968,160969,160970,160971,160975,160972,159427,164848,161557,1436,1109,5576,159595,163784,1282,161074,160085,161004,159921,164934,163589,160653,374,160481,163145,159395,159949,5096,161651,165070,
1724,167017,163783,162642,166665,165218,160632,299)
1724,167017,163783,162642,166665,165218,160632,299,159395)
inner join
(
select form_id, uuid,name from form where
Expand All @@ -1514,7 +1516,7 @@ CREATE PROCEDURE sp_update_etl_mch_postnatal_visit(IN last_update_time DATETIME)
final_test_result=VALUES(final_test_result),
patient_given_result=VALUES(patient_given_result),couple_counselled=VALUES(couple_counselled),partner_hiv_tested=VALUES(partner_hiv_tested),partner_hiv_status=VALUES(partner_hiv_status),mother_haart_given=VALUES(mother_haart_given),prophylaxis_given=VALUES(prophylaxis_given),infant_prophylaxis_timing=VALUES(infant_prophylaxis_timing),baby_azt_dispensed=VALUES(baby_azt_dispensed),baby_nvp_dispensed=VALUES(baby_nvp_dispensed)
,maternal_condition=VALUES(maternal_condition),iron_supplementation=VALUES(iron_supplementation),fistula_screening=VALUES(fistula_screening),cacx_screening=VALUES(cacx_screening),cacx_screening_method=VALUES(cacx_screening_method),family_planning_status=VALUES(family_planning_status),family_planning_method=VALUES(family_planning_method)
,referred_from=VALUES(referred_from),referred_to=VALUES(referred_to), clinical_notes=VALUES(clinical_notes),appointment_date=VALUES(appointment_date),counselled_on_infant_feeding=VALUES(counselled_on_infant_feeding),pnc_hiv_test_timing_mother=VALUES(pnc_hiv_test_timing_mother),other_maternal_complications=VALUES(other_maternal_complications),syphilis_results=VALUES(syphilis_results)
,referred_from=VALUES(referred_from),referred_to=VALUES(referred_to),referral_reason=VALUES(referral_reason), clinical_notes=VALUES(clinical_notes),appointment_date=VALUES(appointment_date),counselled_on_infant_feeding=VALUES(counselled_on_infant_feeding),pnc_hiv_test_timing_mother=VALUES(pnc_hiv_test_timing_mother),other_maternal_complications=VALUES(other_maternal_complications),syphilis_results=VALUES(syphilis_results)
;

END $$
Expand Down
12 changes: 11 additions & 1 deletion omod/src/main/resources/sql/dwapi/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,10 @@ SELECT "Successfully created etl_patient_program_discontinuation table";
test_2_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_2_kit_expiry DATE DEFAULT NULL,
test_2_result VARCHAR(50) DEFAULT NULL,
test_3_kit_name VARCHAR(50),
test_3_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_3_kit_expiry DATE DEFAULT NULL,
test_3_result VARCHAR(50) DEFAULT NULL,
final_test_result VARCHAR(50) DEFAULT NULL,
syphilis_results INT(11) DEFAULT NULL,
patient_given_result VARCHAR(50) DEFAULT NULL,
Expand All @@ -850,6 +854,7 @@ SELECT "Successfully created etl_patient_program_discontinuation table";
family_planning_method INT(11),
referred_from INT(11),
referred_to INT(11),
referral_reason VARCHAR(255) DEFAULT NULL,
clinical_notes VARCHAR(200) DEFAULT NULL,
appointment_date DATE DEFAULT NULL,
date_created DATETIME NOT NULL,
Expand Down Expand Up @@ -1263,6 +1268,10 @@ test_2_kit_name VARCHAR(50),
test_2_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_2_kit_expiry DATE DEFAULT NULL,
test_2_result VARCHAR(50) DEFAULT NULL,
test_3_kit_name VARCHAR(50),
test_3_kit_lot_no VARCHAR(50) DEFAULT NULL,
test_3_kit_expiry DATE DEFAULT NULL,
test_3_result VARCHAR(50) DEFAULT NULL,
final_test_result VARCHAR(50) DEFAULT NULL,
syphillis_test_result VARCHAR(50) DEFAULT NULL,
patient_given_result VARCHAR(50) DEFAULT NULL,
Expand All @@ -1288,7 +1297,8 @@ index(test_type),
index(final_test_result),
index(couple_discordant),
index(test_1_kit_name),
index(test_2_kit_name)
index(test_2_kit_name),
index(test_3_kit_name)
);

-- ------------- CREATE HTS LINKAGE AND REFERRALS ------------------------
Expand Down
Loading

0 comments on commit d257425

Please sign in to comment.