Skip to content

Commit

Permalink
Merge pull request #449 from jembi/dev
Browse files Browse the repository at this point in the history
Release 19 March 2021
  • Loading branch information
tmvumbi2 authored Mar 19, 2021
2 parents e425a4c + 9ceba2e commit 1bb24f9
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 53 deletions.
3 changes: 2 additions & 1 deletion metadata/configuration/concepts/1280_TB_form.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ a196e44f-7911-4942-b586-b59cf79c202f,,,Site extrapulmonaire,Extrapulmonary site,
41bde817-b2e0-4f58-88be-f875e7b31eed,,,Confirmé bactériologiquement,Bacteriologically Confirmed,Confirmé bactériologiquement,Bacteriologically Confirmed,Misc,N/A,,
c1e4f600-2cdd-4ce0-a687-af76e9e20721,,,"Non confirmé, diag cliniquement","Non-confirmed, clinically diag","Non confirmé, diag cliniquement","Non-confirmed, clinically diag",Misc,N/A,,
c4bbc310-2e01-4c6d-be90-decc1b91a800,,"Bacteriologically Confirmed;Non-confirmed, clinically diag",Confirmation MTB,MTB confirmation,Confirmation MTB,MTB confirmation,Misc,Coded,,
6ab25a03-6ac3-45f1-aa04-af54186411e0,,Positive;Negative,Résultat Diagnostic TB,TB Diagnostic Result,Résultat Diagnostic TB,TB Diagnostic Result,Misc,Coded,,
91884f8a-36fe-4974-85bc-6b8b5c1c9da1,,,Prélèvement,Smear,Prélèvement,Smear,Misc,N/A,,
3f80913f-0d3e-43be-b033-324e8e351dc7,,,Xpert MTB/RIF,Xpert MTB/RIF,Xpert MTB/RIF,Xpert MTB/RIF,Misc,N/A,,
6ad904f9-8bb2-4dfa-b3a2-579e7e798f6b,,,Test de Hain,Hain test,Test de Hain,Hain test,Misc,N/A,,
Expand All @@ -45,5 +46,5 @@ ae1baeb2-4e9b-4500-bdc8-39cd40f91715,,,Évaluation de 2 semaines,2 week assessme
7a4d5ae7-8d76-435d-84f1-ff4248304927,,,Évaluation mensuelle planifiée,Planned monthly assessment,Évaluation mensuelle planifiée,Planned monthly assessment,Misc,N/A,,
29c66c54-716b-4df1-adb0-db74c0c42c22,,,Autre évaluation,Other assessment,Autre évaluation,Other assessment,Misc,N/A,,
ec81acc9-b48c-4497-9916-fe5d2bdf9193,,2 week assessment;Planned monthly assessment;Other assessment,Raison de la prochaine visite,Reason for next visit,Raison de la prochaine visite,Reason for next visit,Misc,Coded,,
9f22febc-7826-4550-9174-3e31ae95cc2c,WHO registration group;Previously treated group;Disease site;Extrapulmonary site;MTB confirmation;Method of confirmation;Other method of confirmation;Drug resistance profile;Sub-class of drug resistance profile;MDR-TB diagnosis date;Reason for next visit,,Définition du Cas,Case Definition,Définition du Cas,Case Definition,Misc,N/A,,
9f22febc-7826-4550-9174-3e31ae95cc2c,WHO registration group;Previously treated group;Disease site;Extrapulmonary site;MTB confirmation;TB Diagnostic Result;Method of confirmation;Other method of confirmation;Drug resistance profile;Sub-class of drug resistance profile;MDR-TB diagnosis date;Reason for next visit,,Définition du Cas,Case Definition,Définition du Cas,Case Definition,Misc,N/A,,
3804e2cc-dd14-4879-88d2-94391853f7fb,Date baseline assessment;Screened;Cough > 2 weeks;Fever > 2 weeks;Weight Loss;Night Sweats;TB Contact;Malnutrition;TB Status;3dce13a8-c7e5-45ec-a6f0-8050fd4a2ca2;Case Definition,,Formulaire TB,TB Form,Formulaire TB,TB Form,Misc,N/A,,
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ BEGIN
"VISIT_TYPE_OPD",
"Special OPD"
)
ORDER BY v.date_started DESC
LIMIT 1;

RETURN (result);
Expand Down
6 changes: 4 additions & 2 deletions metadata/reportssql/drug_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ BEGIN
WHERE o.voided = 0
AND o.person_id = p_patientId
AND o.order_id = p_orderId
AND c.uuid = uuidDispensedConcept;
AND c.uuid = uuidDispensedConcept
LIMIT 1;

SELECT TRUE INTO retrospectiveDrugEntry
FROM orders o
Expand All @@ -105,7 +106,8 @@ BEGIN
AND o.date_created > calculateTreatmentEndDate(
o.scheduled_date,
do.duration,
c.uuid);
c.uuid)
LIMIT 1;

RETURN (drugDispensed OR retrospectiveDrugEntry);
END$$
Expand Down
13 changes: 6 additions & 7 deletions metadata/reportssql/index_program_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ CREATE FUNCTION getFirstIndexID(
p_contactPatientId INT(11)) RETURNS INT(11)
DETERMINISTIC
BEGIN
DECLARE result TEXT DEFAULT 0;
DECLARE result INT(11);

SELECT p.patient_id INTO result
FROM patient p
WHERE patientsAreRelated(p_contactPatientId, p.patient_id) AND
patientIsIndex(p.patient_id)
ORDER BY p.date_created ASC
LIMIT 1;
ORDER BY p.date_created ASC
LIMIT 1;

RETURN (result);
END$$
Expand Down Expand Up @@ -191,10 +191,9 @@ BEGIN

SELECT TRUE INTO result
FROM relationship r
JOIN person pIndex ON (r.person_a = p_contactId AND r.person_b = pIndex.person_id) OR
(r.person_a = pIndex.person_id AND r.person_b = p_contactId)
WHERE
patientIsIndex(pIndex.person_id)
JOIN person pIndex ON (r.person_a = p_contactId AND r.person_b = pIndex.person_id AND patientIsIndex(r.person_b)) OR
(r.person_a = pIndex.person_id AND r.person_b = p_contactId AND patientIsIndex(r.person_a))
WHERE r.voided = 0
LIMIT 1;

RETURN (result);
Expand Down
5 changes: 1 addition & 4 deletions metadata/reportssql/testing_report_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1806,9 +1806,7 @@ DROP FUNCTION IF EXISTS getTestingEntryPointWithinRepPeriod;

DELIMITER $$
CREATE FUNCTION getTestingEntryPointWithinRepPeriod(
p_patientId INT(11),
p_startDate DATE,
p_endDate DATE) RETURNS VARCHAR(50)
p_patientId INT(11)) RETURNS VARCHAR(50)
DETERMINISTIC
BEGIN
DECLARE result VARCHAR(50);
Expand All @@ -1822,7 +1820,6 @@ BEGIN
WHERE o.voided = 0
AND o.person_id = p_patientId
AND c.uuid = uuidTestingEntryPoint
AND o.date_created BETWEEN p_startDate AND p_endDate
ORDER BY o.date_created DESC
LIMIT 1;

Expand Down
41 changes: 37 additions & 4 deletions metadata/reportssql/treatment_report_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ WHERE
patientHasStartedARVTreatmentDuringOrBeforeReportingPeriod(pat.patient_id, p_endDate) AND
IF (
isOldPatient(pat.patient_id, p_startDate),
(patientOnARTDuringPartOfReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, p_minDuration, p_maxDuration) OR
(patientOnARTDuringPartOfReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, p_endDate, p_minDuration, p_maxDuration) OR
patientPickedARVDrugDuringReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, p_endDate, p_minDuration, p_maxDuration)),
patientPickedARVDrugDuringReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, p_endDate, p_minDuration, p_maxDuration)
) AND
patientIsNotDead(pat.patient_id) AND
patientIsNotLostToFollowUp(pat.patient_id) AND
(
patientIsNotTransferredOut(pat.patient_id) OR
patientOnARTDuringPartOfReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, 0, 2000)
patientOnARTDuringPartOfReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, p_endDate, 0, 2000)
);

RETURN (result);
Expand Down Expand Up @@ -139,7 +139,7 @@ WHERE
patientIsNotLostToFollowUp(pat.patient_id) AND
(
patientIsNotTransferredOut(pat.patient_id) OR
patientOnARTDuringPartOfReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, 0, 2000)
patientOnARTDuringPartOfReportingPeriodAndDurationBetween(pat.patient_id, p_startDate, p_endDate, 0, 2000)
);

RETURN (result);
Expand Down Expand Up @@ -610,12 +610,27 @@ DELIMITER $$
CREATE FUNCTION patientOnARTDuringPartOfReportingPeriodAndDurationBetween(
p_patientId INT(11),
p_startDate DATE,
p_endDate DATE,
p_minDuration INT(11),
p_maxDuration INT(11)) RETURNS TINYINT(1)
DETERMINISTIC
BEGIN

DECLARE result TINYINT(1) DEFAULT 0;
DECLARE orderIdMostRecentDispense INT(11);

SELECT o.order_id INTO orderIdMostRecentDispense
FROM orders o
JOIN drug_order do ON do.order_id = o.order_id
JOIN concept c ON do.duration_units = c.concept_id AND c.retired = 0
JOIN drug d ON d.drug_id = do.drug_inventory_id AND d.retired = 0
WHERE o.patient_id = p_patientId AND o.voided = 0
AND drugIsARV(d.concept_id)
AND drugOrderIsDispensed(o.patient_id, o.order_id)
AND o.scheduled_date IS NOT NULL
AND o.scheduled_date <= p_endDate
ORDER BY o.scheduled_date
LIMIT 1;

SELECT TRUE INTO result
FROM orders o
Expand All @@ -633,7 +648,9 @@ BEGIN
) >= p_startDate
AND o.scheduled_date IS NOT NULL
AND calculateDurationInMonths(o.scheduled_date, do.duration,c.uuid) >= p_minDuration
AND calculateDurationInMonths(o.scheduled_date, do.duration,c.uuid) < p_maxDuration
AND calculateDurationInMonths(o.scheduled_date, do.duration,c.uuid) < p_maxDuration
AND orderIdMostRecentDispense IS NOT NULL
AND o.order_id = orderIdMostRecentDispense
GROUP BY o.patient_id;

RETURN (result );
Expand Down Expand Up @@ -687,6 +704,20 @@ CREATE FUNCTION patientPickedARVDrugDuringReportingPeriodAndDurationBetween(
BEGIN

DECLARE result TINYINT(1) DEFAULT 0;
DECLARE orderIdMostRecentDispense INT(11);

SELECT o.order_id INTO orderIdMostRecentDispense
FROM orders o
JOIN drug_order do ON do.order_id = o.order_id
JOIN concept c ON do.duration_units = c.concept_id AND c.retired = 0
JOIN drug d ON d.drug_id = do.drug_inventory_id AND d.retired = 0
WHERE o.patient_id = p_patientId AND o.voided = 0
AND drugIsARV(d.concept_id)
AND drugOrderIsDispensed(o.patient_id, o.order_id)
AND o.scheduled_date IS NOT NULL
AND o.scheduled_date <= p_endDate
ORDER BY o.scheduled_date
LIMIT 1;

SELECT TRUE INTO result
FROM orders o
Expand All @@ -700,6 +731,8 @@ BEGIN
AND o.scheduled_date BETWEEN p_startDate AND p_endDate
AND calculateDurationInMonths(o.scheduled_date, do.duration,c.uuid) >= p_minDuration
AND calculateDurationInMonths(o.scheduled_date, do.duration,c.uuid) < p_maxDuration
AND orderIdMostRecentDispense IS NOT NULL
AND o.order_id = orderIdMostRecentDispense
GROUP BY o.patient_id;

RETURN (result );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ SELECT DISTINCT
DATE(getProgramAttributeValueWithinReportingPeriod(p.patient_id, "2000-01-01","2100-01-01", "2dc1aafd-a708-11e6-91e9-0800270d80ce")) as "Date of Initiation",
getPatientARTNumber(getFirstIndexID(p.patient_id)) as "Index Related ART Code",
getPatientIdentifier(getFirstIndexID(p.patient_id)) as "Index Related Unique ID"
FROM patient p, patient_program_attribute_history ppah, patient_program pp, program_attribute_type pat
FROM patient p
LEFT JOIN patient_program pp ON pp.patient_id = p.patient_id
LEFT JOIN patient_program_attribute_history ppah ON ppah.patient_program_id = pp.patient_program_id
LEFT JOIN program_attribute_type pat ON pat.program_attribute_type_id = ppah.attribute_type_id
AND pat.name IN ("PROGRAM_MANAGEMENT_2_NOTIFICATION_DATE", "PROGRAM_MANAGEMENT_3_NOTIFICATION_OUTCOME")
WHERE
ppah.patient_program_id = pp.patient_program_id AND
pp.patient_id = p.patient_id AND
pat.program_attribute_type_id = ppah.attribute_type_id AND
pat.name IN ("PROGRAM_MANAGEMENT_2_NOTIFICATION_DATE", "PROGRAM_MANAGEMENT_3_NOTIFICATION_OUTCOME") AND
patientIsContact(p.patient_id)
ORDER BY ppah.date_created DESC;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SELECT
IF(patientIsEligibleForVL(p.patient_id), "Yes", "No") as "eligibilityForVl",
getDateLatestARVRelatedVisit(p.patient_id) as "dateOfLastVisit",
getDateMostRecentARVAppointment(p.patient_id) as "lastAppointmentDate",
getPatientMostRecentProgramOutcome(p.patient_id, "en", "HIV_PROGRAM_KEY") as "hivOutcome",
getPatientMostRecentProgramAttributeCodedValue(p.patient_id, "39202f47-a709-11e6-91e9-0800270d80ce", "en") as "transferredIn",
IF(getPatientMostRecentProgramOutcome(p.patient_id, "en", "HIV_PROGRAM_KEY")="Transferred Out", "Yes", "No") as "transfertOut",
IF(getObsCodedValue(p.patient_id, "211f0857-61a3-4049-9777-374c4a592453") IS NOT NULL, "True", "False") as "kp",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
SELECT
CAST(@a:=@a+1 AS CHAR) as "serialNumber",
getPatientIdentifier(r.person_b) as "uniquePatientId",
getPatientBirthdate(r.person_b) as "dateOfBirth",
getPatientAgeInMonthsAtDate(r.person_b, NOW()) as "ageInMonths",
getPatientIdentifier(r.person_a) as "motherId",
CONCAT(getPatientPreciseLocation(r.person_a),", ",getPatientVillage(r.person_a)) as "mothersAddress",
getPatientPhoneNumber(r.person_a) as "mothersContact",
getMostRecentTestResultDate(r.person_b,"a5239a85-6f75-4882-9b9b-60168e54b7da","9bb7b360-3790-4e1a-8aca-0d1341663040") as "resultDatePcr",
getTestResultWithinReportingPeriod(r.person_b,"2000-01-01","2100-01-01","a5239a85-6f75-4882-9b9b-60168e54b7da","9bb7b360-3790-4e1a-8aca-0d1341663040") as "pcrResult",
getProgramAttributeDateValueFromAttributeAndProgramName(r.person_b, "PROGRAM_MANAGEMENT_2_PATIENT_TREATMENT_DATE", "HIV_PROGRAM_KEY") as "artInitiationDate",
getObsCodedValue(r.person_b, "3447254f-501f-4b07-815c-cd0f6da98158") as "reasonOfNonInitiation"
getPatientIdentifier(r.person_a) as "uniquePatientId",
getPatientBirthdate(r.person_a) as "dateOfBirth",
getPatientAgeInMonthsAtDate(r.person_a, NOW()) as "ageInMonths",
getPatientIdentifier(r.person_b) as "motherId",
CONCAT(getPatientPreciseLocation(r.person_b),", ",getPatientVillage(r.person_b)) as "mothersAddress",
getPatientPhoneNumber(r.person_b) as "mothersContact",
getMostRecentTestResultDate(r.person_a,"a5239a85-6f75-4882-9b9b-60168e54b7da","9bb7b360-3790-4e1a-8aca-0d1341663040") as "resultDatePcr",
getTestResultWithinReportingPeriod(r.person_a,"2000-01-01","2100-01-01","a5239a85-6f75-4882-9b9b-60168e54b7da","9bb7b360-3790-4e1a-8aca-0d1341663040") as "pcrResult",
getProgramAttributeDateValueFromAttributeAndProgramName(r.person_a, "PROGRAM_MANAGEMENT_2_PATIENT_TREATMENT_DATE", "HIV_PROGRAM_KEY") as "artInitiationDate",
getObsCodedValue(r.person_a, "3447254f-501f-4b07-815c-cd0f6da98158") as "reasonOfNonInitiation"
FROM (SELECT @a:= 0) AS a, relationship r
JOIN relationship_type rt ON rt.relationship_type_id = r.relationship AND rt.a_is_to_b = "RELATIONSHIP_BIO_MOTHER"
JOIN patient_identifier pi ON pi.patient_id = r.person_a AND pi.preferred = 1;
JOIN patient_identifier pi ON pi.patient_id = r.person_a AND pi.preferred = 1
WHERE
getPatientAgeInMonthsAtDate(r.person_a, NOW()) <= 24 AND
patientHasEnrolledIntoHivProgram(r.person_b) = "Yes";
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ SELECT
getPatientPhoneNumber(p.patient_id) as "telephone",
getMostRecentCodedObservation(p.patient_id,"Method of confirmation","en") as "Type of Exam",
getDateTBPosDiagnose(p.patient_id) as "dateTBPosDiag",
getMostRecentCodedObservation(p.patient_id,"TB Diagnostic Result","en") as "tbDiagnosticResult",
getMostRecentDateObservation(p.patient_id,"MDR-TB diagnosis date") as "tbDiagnosticDate",
getProgramAttributeDateValueFromAttributeAndProgramName(p.patient_id, "PROGRAM_MANAGEMENT_2_PATIENT_TREATMENT_DATE", "TB_PROGRAM_KEY") as "dateOfTxTbStart",
getHIVTestDate(p.patient_id,"2000-01-01","2100-01-01") as "dateOfHivTesting",
getHIVResult(p.patient_id,"2000-01-01","2100-01-01") as "hivTestingResult",
getProgramAttributeDateValueFromAttributeAndProgramName(p.patient_id, "PROGRAM_MANAGEMENT_2_PATIENT_TREATMENT_DATE", "HIV_PROGRAM_KEY") as "dateOfInitiation"
FROM patient p, (SELECT @a:= 0) AS a
WHERE
getDateTBPosDiagnose(p.patient_id) IS NOT NULL AND
getObsCodedValue(p.patient_id, "f0447183-d13f-463d-ad0f-1f45b99d97cc") LIKE "Yes%";
getObsCodedValue(p.patient_id, "61931c8b-0637-40f9-97dc-07796431dd3b") = "Suspected / Probable";
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SELECT
getHIVResult(p.patient_id,"#startDate#", "#endDate#") as "result",
DATE(getProgramAttributeValueWithinReportingPeriod(p.patient_id, "2000-01-01", "2100-12-31", "2dc1aafd-a708-11e6-91e9-0800270d80ce")) as "dateOfArtInitiation",
getObsCodedValue(p.patient_id, "3447254f-501f-4b07-815c-cd0f6da98158") as "reasonOfNonInitiation",
IF(wasHIVTestDoneInANCVisitWithinRepPeriod(p.patient_id, "#startDate#", "#endDate#"),"PMTCT [ANC1-only]",getTestingEntryPointWithinRepPeriod(p.patient_id, "#startDate#", "#endDate#")) as "facilityEntryPoint",
IF(wasHIVTestDoneInANCVisitWithinRepPeriod(p.patient_id, "#startDate#", "#endDate#"),"PMTCT [ANC1-only]",getTestingEntryPointWithinRepPeriod(p.patient_id)) as "facilityEntryPoint",
getHIVTestDate(p.patient_id,"#startDate#", "#endDate#") as "dateFinalResultProvidedToPatient"
FROM patient p, (SELECT @a:= 0) AS a
WHERE getHIVTestDate(p.patient_id, "#startDate#", "#endDate#") IS NOT NULL;
24 changes: 20 additions & 4 deletions report-testing-framework/data/backup-openmrs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,25 @@ LOCK TABLES `concept_name_tag` WRITE;
/*!40000 ALTER TABLE `concept_name_tag` ENABLE KEYS */;
UNLOCK TABLES;

DROP TABLE IF EXISTS `patient_program_attribute_history`;
CREATE TABLE `patient_program_attribute_history` (
`patient_program_attribute_history_id` int(11) NOT NULL AUTO_INCREMENT,
`patient_program_id` int(11) NOT NULL,
`attribute_type_id` int(11) NOT NULL,
`value_reference` text NOT NULL,
`uuid` char(38) NOT NULL,
`creator` int(11) NOT NULL,
`date_created` datetime NOT NULL,
PRIMARY KEY (`patient_program_attribute_history_id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `patient_program_attribute_history_programid_fk` (`patient_program_id`),
KEY `patient_program_attribute_history_attributetype_fk` (`attribute_type_id`),
KEY `patient_program_attribute_history_creator_fk` (`creator`),
CONSTRAINT `patient_program_attribute_history_attributetype_fk` FOREIGN KEY (`attribute_type_id`) REFERENCES `program_attribute_type` (`program_attribute_type_id`),
CONSTRAINT `patient_program_attribute_history_creator_fk` FOREIGN KEY (`creator`) REFERENCES `users` (`user_id`),
CONSTRAINT `patient_program_attribute_history_programid_fk` FOREIGN KEY (`patient_program_id`) REFERENCES `patient_program` (`patient_program_id`)
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8;

--
-- Table structure for table `concept_name_tag_map`
--
Expand Down Expand Up @@ -13247,9 +13266,7 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `getTestingEntryPointWithinRepPeriod`(
p_patientId INT(11),
p_startDate DATE,
p_endDate DATE) RETURNS varchar(50) CHARSET utf8
p_patientId INT(11)) RETURNS varchar(50) CHARSET utf8
DETERMINISTIC
BEGIN
DECLARE result VARCHAR(50);
Expand All @@ -13263,7 +13280,6 @@ BEGIN
WHERE o.voided = 0
AND o.person_id = p_patientId
AND c.uuid = uuidTestingEntryPoint
AND o.date_created BETWEEN p_startDate AND p_endDate
ORDER BY o.date_created DESC
LIMIT 1;

Expand Down
Loading

0 comments on commit 1bb24f9

Please sign in to comment.