Skip to content

Commit

Permalink
Merge branch 'dev' into COM-675
Browse files Browse the repository at this point in the history
# Conflicts:
#	metadata/reportssql/treatment_report_functions.sql
  • Loading branch information
tmvumbi2 committed Mar 25, 2020
2 parents 2647a04 + 1245714 commit 601c58c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
11 changes: 10 additions & 1 deletion metadata/reportssql/testing_report_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,15 @@ BEGIN
DECLARE result TINYINT(1) DEFAULT 0;
DECLARE uuidHIVTestFinalResult VARCHAR(38) DEFAULT "41e48d08-2235-47d5-af12-87a009057603";

DECLARE uuidHIVTestDate VARCHAR(38) DEFAULT "c6c08cdc-18dc-4f42-809c-959621bc9a6c";
DECLARE uuidHIVTestSection VARCHAR(38) DEFAULT "b70dfca0-db21-4533-8c08-4626ff0de265";
DECLARE withinReportingPeriod TINYINT(1) DEFAULT 0;

SET withinReportingPeriod = getObsDatetimeValueInSection(p_patientId, uuidHIVTestDate, uuidHIVTestSection) BETWEEN p_startDate AND p_endDate;
IF withinReportingPeriod IS NULL THEN
RETURN 0;
END IF;

SELECT
cn.name = p_result INTO result
FROM obs o
Expand All @@ -1281,7 +1290,7 @@ BEGIN
ORDER BY o.date_created DESC
LIMIT 1;

RETURN (result);
RETURN (result AND withinReportingPeriod);
END$$
DELIMITER ;

Expand Down
29 changes: 29 additions & 0 deletions metadata/reportssql/treatment_report_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,35 @@ WHERE
END$$
DELIMITER ;

DROP FUNCTION IF EXISTS TREATMENT_Indicator7a;

DELIMITER $$
CREATE FUNCTION TREATMENT_Indicator7a(
p_startDate DATE,
p_endDate DATE,
p_startAge INT(11),
p_endAge INT (11),
p_includeEndAge TINYINT(1),
p_gender VARCHAR(1)) RETURNS INT(11)
DETERMINISTIC
BEGIN
DECLARE result INT(11) DEFAULT 0;

SELECT
COUNT(DISTINCT pat.patient_id) INTO result
FROM
patient pat
WHERE
patientGenderIs(pat.patient_id, p_gender) AND
getPatientDateOfEnrollementInProgram(pat.patient_id, "TB_PROGRAM_KEY") BETWEEN p_startDate AND p_endDate AND
patientHasEnrolledIntoHivProgram(pat.patient_id) = "Yes" AND
patientHasStartedARVTreatmentDuringReportingPeriod(pat.patient_id, p_startDate, p_endDate) AND
patientAgeWhenRegisteredForHivProgramIsBetween(pat.patient_id, p_startAge, p_endAge, p_includeEndAge);

RETURN (result);
END$$
DELIMITER ;

DROP FUNCTION IF EXISTS TREATMENT_Indicator7c;

DELIMITER $$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT 'Not available' AS 'Not available',
0 AS '<15 M',
0 AS '<15 F',
0 AS '>= 15 M',
0 AS '>= 15 F',
SELECT 'Patients starting TB treatment who newly started ART ' AS 'Title',
TREATMENT_Indicator7a('#startDate#','#endDate#', 0, 15, 0, 'M') AS '<15 M',
TREATMENT_Indicator7a('#startDate#','#endDate#', 0, 15, 0, 'F') AS '<15 F',
TREATMENT_Indicator7a('#startDate#','#endDate#', 15, 200, 1, 'M') AS '>=15 M',
TREATMENT_Indicator7a('#startDate#','#endDate#', 15, 200, 1, 'F') AS '>=15 F',
0 AS 'Unknown M',
0 AS 'Unknown F';

0 comments on commit 601c58c

Please sign in to comment.