diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/DRCFacilityBasedARTDeliveryReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/DRCFacilityBasedARTDeliveryReportManager.java index 8041f9a..8d5ecda 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/reports/DRCFacilityBasedARTDeliveryReportManager.java +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/DRCFacilityBasedARTDeliveryReportManager.java @@ -77,7 +77,8 @@ public String getDescription() { private Parameter getReportingDateParameter() { String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - return new Parameter("onOrBefore", MessageUtil.translate("commonreports.report.util.reportingEndDate"), Date.class, null, DateUtil.parseDate(today, "yyyy-MM-dd")); + return new Parameter("onOrBefore", MessageUtil.translate("commonreports.report.util.reportingEndDate"), Date.class, + null, DateUtil.parseDate(today, "yyyy-MM-dd")); } public static String col1 = ""; diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/DRCMissedAppointmentReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/DRCMissedAppointmentReportManager.java new file mode 100644 index 0000000..ad94d5b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/DRCMissedAppointmentReportManager.java @@ -0,0 +1,90 @@ +package org.openmrs.module.commonreports.reports; + +import static org.openmrs.module.commonreports.common.Helper.getStringFromResource; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Date; + +import org.openmrs.module.commonreports.ActivatedReportManager; +import org.openmrs.module.initializer.api.InitializerService; +import org.openmrs.module.reporting.common.MessageUtil; +import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.reporting.evaluation.parameter.Mapped; +import org.openmrs.module.reporting.report.ReportDesign; +import org.openmrs.module.reporting.report.definition.ReportDefinition; +import org.openmrs.module.reporting.report.manager.ReportManagerUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class DRCMissedAppointmentReportManager extends ActivatedReportManager { + + @Autowired + private InitializerService inizService; + + @Override + public boolean isActivated() { + return true; + } + + @Override + public String getVersion() { + return "1.0.0-SNAPSHOT"; + } + + @Override + public String getUuid() { + return "82a51c4b-acd3-4868-a0fb-74cf01c61479"; + } + + @Override + public String getName() { + return "Missed Appointments Report"; + } + + @Override + public String getDescription() { + return "Missed Appointments Report"; + } + + @Override + public List getParameters() { + return Arrays.asList( + new Parameter("startDate", MessageUtil.translate("commonreports.report.util.startDate"), Date.class), + new Parameter("endDate", MessageUtil.translate("commonreports.report.util.endDate"), Date.class)); + } + + @Override + public ReportDefinition constructReportDefinition() { + ReportDefinition rd = new ReportDefinition(); + rd.setName(getName()); + rd.setDescription(getDescription()); + rd.setParameters(getParameters()); + rd.setUuid(getUuid()); + + SqlDataSetDefinition sqlDsd = new SqlDataSetDefinition(); + sqlDsd.setName(MessageUtil.translate("commonreports.report.missedAppointments.datasetName")); + sqlDsd.setDescription(MessageUtil.translate("commonreports.report.missedAppointments.datasetDescription")); + String sql = getStringFromResource("org/openmrs/module/commonreports/sql/missedAppointments.sql"); + sqlDsd.setSqlQuery(sql); + sqlDsd.addParameters(getParameters()); + + Map parameterMappings = new HashMap(); + parameterMappings.put("startDate", "${startDate}"); + parameterMappings.put("endDate", "${endDate}"); + + rd.addDataSetDefinition(getName(), sqlDsd, parameterMappings); + return rd; + } + + @Override + public List constructReportDesigns(ReportDefinition reportDefinition) { + ReportDesign reportDesign = ReportManagerUtil.createCsvReportDesign("86cc3558-8181-4fc3-aac4-fdb738f7c888", + reportDefinition); + return Arrays.asList(reportDesign); + } +} diff --git a/api/src/main/resources/messages.properties b/api/src/main/resources/messages.properties index 151ba50..c5db2e3 100644 --- a/api/src/main/resources/messages.properties +++ b/api/src/main/resources/messages.properties @@ -292,4 +292,8 @@ ${project.parent.artifactId}.report.appointments.datasetDescription= commonreports.report.disbursement.reportName= Disbursement Report commonreports.report.disbursement.reportDescription= commonreports.report.disbursement.datasetName=Disbursement SQL Dataset -commonreports.report.disbursement.datasetDescription= \ No newline at end of file +commonreports.report.disbursement.datasetDescription= + +${project.parent.artifactId}.report.missedAppointments.reportDescription=Missed Appointments Report +${project.parent.artifactId}.report.missedAppointments.datasetName=Missed Appointments SQL Dataset +${project.parent.artifactId}.report.missedAppointments.datasetDescription=Missed Appointments SQL Dataset \ No newline at end of file diff --git a/api/src/main/resources/messages_fr.properties b/api/src/main/resources/messages_fr.properties index d436b59..834130f 100644 --- a/api/src/main/resources/messages_fr.properties +++ b/api/src/main/resources/messages_fr.properties @@ -283,3 +283,7 @@ ${project.parent.artifactId}.report.appointments.reportDescription=Appointments ${project.parent.artifactId}.report.appointments.datasetName=Appointments SQL Dataset ${project.parent.artifactId}.report.appointments.datasetDescription=Appointments SQL Dataset + +${project.parent.artifactId}.report.missedAppointments.reportDescription=Missed Appointments Report +${project.parent.artifactId}.report.missedAppointments.datasetName=Missed Appointments SQL Dataset +${project.parent.artifactId}.report.missedAppointments.datasetDescription=Missed Appointments SQL Dataset diff --git a/api/src/main/resources/org/openmrs/module/commonreports/sql/missedAppointments.sql b/api/src/main/resources/org/openmrs/module/commonreports/sql/missedAppointments.sql new file mode 100644 index 0000000..9358974 --- /dev/null +++ b/api/src/main/resources/org/openmrs/module/commonreports/sql/missedAppointments.sql @@ -0,0 +1,36 @@ +SELECT DISTINCT + p.patient_id, + pn.given_name, + pn.family_name, + per.gender, + per.birthdate, + o.value_datetime AS missed_date, + 'Return visit date' AS source +FROM patient p +JOIN obs o ON p.patient_id = o.person_id +JOIN person per ON p.patient_id = per.person_id +JOIN person_name pn ON per.person_id = pn.person_id +WHERE o.concept_id = 211 + AND o.voided = 0 + AND p.voided = 0 + AND o.value_datetime BETWEEN :startDate AND :endDate + AND pn.preferred = 1 + +UNION + +SELECT DISTINCT + pa.patient_id, + pn.given_name, + pn.family_name, + per.gender, + per.birthdate, + pa.start_date_time AS missed_date, + 'Appointment' AS source +FROM patient_appointment pa +JOIN patient p ON pa.patient_id = p.patient_id +JOIN person per ON p.patient_id = per.person_id +JOIN person_name pn ON per.person_id = pn.person_id +WHERE pa.start_date_time BETWEEN :startDate AND :endDate + AND pa.voided = 0 + AND p.voided = 0 + AND pn.preferred = 1; \ No newline at end of file