From 0abdd3537987a8f7289dddb77f0bc71c6117ed3e Mon Sep 17 00:00:00 2001 From: shilpa-iplit Date: Fri, 12 Jul 2019 19:47:33 +0530 Subject: [PATCH 1/2] reports additional tabs for customize reports --- openmrs/apps/reports/facilityReports.json | 9 +++++++++ openmrs/apps/reports/sql/missedAppointments.sql | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 openmrs/apps/reports/facilityReports.json create mode 100644 openmrs/apps/reports/sql/missedAppointments.sql diff --git a/openmrs/apps/reports/facilityReports.json b/openmrs/apps/reports/facilityReports.json new file mode 100644 index 000000000..398126ff4 --- /dev/null +++ b/openmrs/apps/reports/facilityReports.json @@ -0,0 +1,9 @@ +{ + "appointmentReport": { + "name": "Missed Appointment Report", + "type": "MRSGeneric", + "config": { + "sqlPath": "/var/www/bahmni_config/openmrs/apps/reports/sql/missedAppointments.sql" + } + } +} diff --git a/openmrs/apps/reports/sql/missedAppointments.sql b/openmrs/apps/reports/sql/missedAppointments.sql new file mode 100644 index 000000000..e4618502d --- /dev/null +++ b/openmrs/apps/reports/sql/missedAppointments.sql @@ -0,0 +1,14 @@ +SELECT + pai.identifier AS 'patient ID', + pn.given_name AS 'First Name', + ifnull(pn.family_name,'') AS 'Last Name', + paMobile.value AS 'Telephone No.', + p.gender AS 'Gender', + DATE_FORMAT(start_date_time, "%d/%m/%Y") AS 'Appointment Date' +FROM patient_appointment pa + LEFT JOIN person p ON p.person_id = pa.patient_id AND pa.voided IS FALSE + LEFT JOIN person_name pn ON p.person_id = pn.person_id AND pn.voided IS FALSE + LEFT JOIN patient_identifier pai on (pai.patient_id = pa.patient_id and pai.preferred = 1) + LEFT JOIN person_attribute_type patMobile on patMobile.name = "MobileNumber" and patMobile.retired IS FALSE + LEFT JOIN person_attribute paMobile on (pa.patient_id = paMobile.person_id and paMobile.voided is false and patMobile.person_attribute_type_id = paMobile.person_attribute_type_id) +WHERE pa.status = 'Missed' OR start_date_time < CURDATE() ORDER BY start_date_time DESC; From ea2c043c7097d1ab4c2361a81a1b0170c3b5b967 Mon Sep 17 00:00:00 2001 From: shilpa-iplit Date: Mon, 15 Jul 2019 17:00:37 +0530 Subject: [PATCH 2/2] Missed appointment report sql --- openmrs/apps/reports/sql/missedAppointments.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openmrs/apps/reports/sql/missedAppointments.sql b/openmrs/apps/reports/sql/missedAppointments.sql index e4618502d..47f96dfc1 100644 --- a/openmrs/apps/reports/sql/missedAppointments.sql +++ b/openmrs/apps/reports/sql/missedAppointments.sql @@ -4,6 +4,7 @@ SELECT ifnull(pn.family_name,'') AS 'Last Name', paMobile.value AS 'Telephone No.', p.gender AS 'Gender', + DATE_FORMAT(obsConcept.artStartDate, "%d/%m/%Y") AS 'ART Start Date', DATE_FORMAT(start_date_time, "%d/%m/%Y") AS 'Appointment Date' FROM patient_appointment pa LEFT JOIN person p ON p.person_id = pa.patient_id AND pa.voided IS FALSE @@ -11,4 +12,9 @@ FROM patient_appointment pa LEFT JOIN patient_identifier pai on (pai.patient_id = pa.patient_id and pai.preferred = 1) LEFT JOIN person_attribute_type patMobile on patMobile.name = "MobileNumber" and patMobile.retired IS FALSE LEFT JOIN person_attribute paMobile on (pa.patient_id = paMobile.person_id and paMobile.voided is false and patMobile.person_attribute_type_id = paMobile.person_attribute_type_id) -WHERE pa.status = 'Missed' OR start_date_time < CURDATE() ORDER BY start_date_time DESC; + JOIN (SELECT o.value_datetime AS 'artStartDate', v.patient_id AS 'visitPatientId' FROM visit v + LEFT JOIN encounter enc ON enc.visit_id = v.visit_id + LEFT JOIN obs o ON o.encounter_id = enc.encounter_id + JOIN concept_name cn on (o.concept_id = cn.concept_id and cn.concept_name_type = "FULLY_SPECIFIED" and cn.voided=0 and cn.name="ANC, ART Start Date") + order by v.date_started desc limit 1) AS obsConcept ON obsConcept.visitPatientId = pa.patient_id +WHERE start_date_time BETWEEN '#startDate#' AND '#endDate#' ORDER BY start_date_time DESC;