diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/MohReportUtils/ReportAddonUtils.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/MohReportUtils/ReportAddonUtils.java index c24a20df2b..6afd0dd239 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/MohReportUtils/ReportAddonUtils.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/MohReportUtils/ReportAddonUtils.java @@ -63,16 +63,16 @@ public static List getGeneralOutPatientFilters() { "state=NEW|age=<5|gender=F", "03"); ColumnParameters under5FemaleRevisit = new ColumnParameters("over5FemaleRevisit", "below 5 and revisit", "state=RVT|age=<5|gender=F", "04"); - ColumnParameters over5MaleNew = new ColumnParameters("over5MaleNew", "above 5 and new", "state=NEW|age=>5|gender=M", + ColumnParameters over5MaleNew = new ColumnParameters("over5MaleNew", "above 5 and new", "state=NEW|age=5+|gender=M", "05"); ColumnParameters over5MaleRevisit = new ColumnParameters("over5MaleRevisit", "above 5 and revisit", - "state=RVT|age=>5|gender=M", "06"); + "state=RVT|age=5+|gender=M", "06"); ColumnParameters over5FemaleNew = new ColumnParameters("over5MaleNew", "above 5 and new", - "state=NEW|age=>5|gender=F", "07"); + "state=NEW|age=5+|gender=F", "07"); ColumnParameters over5FemaleRevisit = new ColumnParameters("over5MaleRevisit", "above 5 and revisit", - "state=RVT|age=>5|gender=F", "08"); - ColumnParameters over60New = new ColumnParameters("over60New", "above 60 and new", "state=NEW|age=>60", "09"); - ColumnParameters over60Revisit = new ColumnParameters("over60Revisit", "above 60 and revisit", "state=RVT|age=>60", + "state=RVT|age=5+|gender=F", "08"); + ColumnParameters over60New = new ColumnParameters("over60New", "above 60 and new", "state=NEW|age=60+", "09"); + ColumnParameters over60Revisit = new ColumnParameters("over60Revisit", "above 60 and revisit", "state=RVT|age=60+", "10"); return Arrays.asList(under5MaleNew, under5MaleRevisit, under5FemaleNew, under5FemaleRevisit, over5MaleNew, diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/SetupMOH240LabReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/SetupMOH240LabReportBuilder.java new file mode 100644 index 0000000000..8cd8227038 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/SetupMOH240LabReportBuilder.java @@ -0,0 +1,117 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.kenyaemr.reporting.builder.common; + +import org.openmrs.PatientIdentifierType; +import org.openmrs.PersonAttributeType; +import org.openmrs.api.context.Context; +import org.openmrs.module.kenyacore.report.HybridReportDescriptor; +import org.openmrs.module.kenyacore.report.ReportDescriptor; +import org.openmrs.module.kenyacore.report.ReportUtils; +import org.openmrs.module.kenyacore.report.builder.AbstractHybridReportBuilder; +import org.openmrs.module.kenyacore.report.builder.Builds; +import org.openmrs.module.kenyacore.report.data.patient.definition.CalculationDataDefinition; +import org.openmrs.module.kenyaemr.calculation.library.mchcs.PersonAddressCalculation; +import org.openmrs.module.kenyaemr.metadata.CommonMetadata; +import org.openmrs.module.kenyaemr.reporting.calculation.converter.RDQACalculationResultConverter; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition; +import org.openmrs.module.reporting.data.DataDefinition; +import org.openmrs.module.reporting.data.converter.BirthdateConverter; +import org.openmrs.module.reporting.data.converter.DataConverter; +import org.openmrs.module.reporting.data.converter.DateConverter; +import org.openmrs.module.reporting.data.converter.ObjectFormatter; +import org.openmrs.module.reporting.data.encounter.definition.EncounterDatetimeDataDefinition; +import org.openmrs.module.reporting.data.patient.definition.ConvertedPatientDataDefinition; +import org.openmrs.module.reporting.data.patient.definition.PatientIdentifierDataDefinition; +import org.openmrs.module.reporting.data.person.definition.*; +import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; +import org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Mapped; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.reporting.report.definition.ReportDefinition; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +@Component +@Builds({ "kenyaemr.ehrReports.report.240" }) +public class SetupMOH240LabReportBuilder extends AbstractHybridReportBuilder { + + public static final String ENC_DATE_FORMAT = "yyyy/MM/dd"; + + @Override + protected Mapped buildCohort(HybridReportDescriptor hybridReportDescriptor, + PatientDataSetDefinition patientDataSetDefinition) { + return null; + } + + @Override + protected List> buildDataSets(ReportDescriptor descriptor, ReportDefinition report) { + PatientDataSetDefinition dsd = LabRegister(); + dsd.setName("lrr"); + dsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + report.setBaseCohortDefinition(ReportUtils.map(getLabOrderEncounter(), "startDate=${startDate},endDate=${endDate}")); + + return Arrays.asList(ReportUtils.map((DataSetDefinition) dsd, "startDate=${startDate},endDate=${endDate}")); + } + + @Override + protected List getParameters(ReportDescriptor reportDescriptor) { + return Arrays.asList(new Parameter("startDate", "Start Date", Date.class), new Parameter("endDate", "End Date", + Date.class), new Parameter("dateBasedReporting", "", String.class)); + } + + private PatientDataSetDefinition LabRegister() { + PatientDataSetDefinition dsd = new PatientDataSetDefinition(); + dsd.setName("lrr"); + dsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addRowFilter(getLabOrderEncounter(), "startDate=${startDate},endDate=${endDate+23h}"); + DataConverter nameFormatter = new ObjectFormatter("{familyName}, {givenName}, {middleName}"); + DataDefinition nameDef = new ConvertedPersonDataDefinition("name", new PreferredNameDataDefinition(), nameFormatter); + + PersonAttributeType personAttributeType = Context.getPersonService().getPersonAttributeTypeByUuid(CommonMetadata._PersonAttributeType.TELEPHONE_CONTACT); + + PatientIdentifierType openmrsID = Context.getPatientService().getPatientIdentifierTypeByUuid("dfacd928-0370-4315-99d7-6ec1c9f7ae76"); + DataConverter identifierFormatter = new ObjectFormatter("{identifier}"); + DataDefinition identifierDef = new ConvertedPatientDataDefinition("identifier", new PatientIdentifierDataDefinition( + openmrsID.getName(), openmrsID), identifierFormatter); + + dsd.addColumn("id", new PersonIdDataDefinition(), ""); + dsd.addColumn("identifier", identifierDef, ""); + //dsd.addColumn("Date", new EncounterDatetimeDataDefinition(),"", new DateConverter(ENC_DATE_FORMAT)); + dsd.addColumn("Name", nameDef, ""); + dsd.addColumn("Sex", new GenderDataDefinition(), "", null); + dsd.addColumn("DOB", new BirthdateDataDefinition(), "", new BirthdateConverter("yyyy-MM-dd")); + dsd.addColumn("age", new AgeDataDefinition(), ""); + dsd.addColumn("village", new CalculationDataDefinition("Village/Estate/Landmark", new PersonAddressCalculation()), "",new RDQACalculationResultConverter()); + dsd.addColumn("telephone", new PersonAttributeDataDefinition(personAttributeType), "", + null); + return dsd; + + } + + private CohortDefinition getLabOrderEncounter() { + SqlCohortDefinition sqlEncounterQuery = new SqlCohortDefinition(); + sqlEncounterQuery.setName("Get unique lab encounter types"); + sqlEncounterQuery.addParameter(new Parameter("startDate", "Start Date", Date.class)); + sqlEncounterQuery.addParameter(new Parameter("endDate", "End Date", Date.class)); + sqlEncounterQuery + .setQuery("SELECT d.patient_id FROM kenyaemr_etl.etl_patient_demographics d\n" + + " INNER JOIN kenyaemr_etl.etl_laboratory_extract x ON x.patient_id = d.patient_id\n" + + " AND date(x.visit_date) BETWEEN :startDate AND :endDate;"); + return sqlEncounterQuery; + } + +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/SetupMOH706LabReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/SetupMOH706LabReportBuilder.java new file mode 100644 index 0000000000..0741be2b87 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/SetupMOH706LabReportBuilder.java @@ -0,0 +1,72 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.kenyaemr.reporting.builder.common; + +import org.openmrs.module.kenyacore.report.ReportDescriptor; +import org.openmrs.module.kenyacore.report.ReportUtils; +import org.openmrs.module.kenyacore.report.builder.AbstractReportBuilder; +import org.openmrs.module.kenyacore.report.builder.Builds; +import org.openmrs.module.kenyaemr.reporting.library.MOH706.Moh706LabCohortLibrary; +import org.openmrs.module.kenyaemr.reporting.library.MOH706.Moh706IndicatorLibrary; +import org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition; +import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Mapped; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.reporting.report.definition.ReportDefinition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import static org.openmrs.module.kenyacore.report.ReportUtils.map; + +@Component +@Builds({ "kenyaemr.ehrReports.706.report" }) +public class SetupMOH706LabReportBuilder extends AbstractReportBuilder { + + + private final Moh706IndicatorLibrary moh706IndicatorLibrary; + + @Autowired + public SetupMOH706LabReportBuilder(Moh706LabCohortLibrary moh706CohortLibrary, Moh706IndicatorLibrary moh706IndicatorLibrary) { + this.moh706IndicatorLibrary = moh706IndicatorLibrary; + } + + @Override + protected List getParameters(ReportDescriptor reportDescriptor) { + return Arrays.asList(new Parameter("startDate", "Start Date", Date.class), new Parameter("endDate", "End Date", + Date.class), new Parameter("dateBasedReporting", "", String.class)); + } + + @Override + protected List> buildDataSets(ReportDescriptor reportDescriptor, + ReportDefinition reportDefinition) { + return Arrays.asList(map(getMoh706LabDatasetDefinition(), + "startDate=${startDate},endDate=${endDate+23h}")); + } + + private DataSetDefinition getMoh706LabDatasetDefinition() { + CohortIndicatorDataSetDefinition cohortDsd = new CohortIndicatorDataSetDefinition(); + cohortDsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cohortDsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cohortDsd.setName("MOH706"); + cohortDsd.setDescription("MOH 706 for the lab"); + + //URINE ANALYSIS + cohortDsd.addColumn("UAGL", "1.2 Glucose", + ReportUtils.map(moh706IndicatorLibrary.getAllUrineAnalysisGlucoseTestsPositives(), "startDate=${startDate},endDate=${endDate}"), ""); + + return cohortDsd; + } + +} + diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/MOH706/Moh706IndicatorLibrary.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/MOH706/Moh706IndicatorLibrary.java new file mode 100644 index 0000000000..60fa731136 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/MOH706/Moh706IndicatorLibrary.java @@ -0,0 +1,32 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.kenyaemr.reporting.library.MOH706; + +import org.openmrs.module.reporting.indicator.CohortIndicator; +import org.springframework.stereotype.Component; + +import static org.openmrs.module.kenyacore.report.ReportUtils.map; +import static org.openmrs.module.kenyaemr.reporting.MohReportUtils.ReportingUtils.cohortIndicator; + +@Component +public class Moh706IndicatorLibrary { + private final Moh706LabCohortLibrary moh706LabCohortLibrary; + + public Moh706IndicatorLibrary(Moh706LabCohortLibrary moh706LabCohortLibrary) { + this.moh706LabCohortLibrary = moh706LabCohortLibrary; + } + + public CohortIndicator getAllUrineAnalysisGlucoseTestsPositives() { + return cohortIndicator( + "All patients who have urinalysis glucose", + map(moh706LabCohortLibrary.getAllUrineAnalysisGlucoseTestsPositives(), + "startDate=${startDate},endDate=${endDate}")); + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/MOH706/Moh706LabCohortLibrary.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/MOH706/Moh706LabCohortLibrary.java new file mode 100644 index 0000000000..cc66a4b09d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/MOH706/Moh706LabCohortLibrary.java @@ -0,0 +1,38 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.kenyaemr.reporting.library.MOH706; + +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@Component +public class Moh706LabCohortLibrary { + + public CohortDefinition getAllUrineAnalysisGlucoseTestsPositives() { + SqlCohortDefinition sql = new SqlCohortDefinition(); + sql.setName("Get urine analysis patients - glucose"); + sql.addParameter(new Parameter("startDate", "Start Date", Date.class)); + sql.addParameter(new Parameter("endDate", "End Date", Date.class)); + sql.setQuery("SELECT d.patient_id FROM kenyaemr_etl.etl_patient_demographics d\n" + + " INNER JOIN kenyaemr_etl.etl_laboratory_extract x ON x.patient_id = d.patient_id\n" + + " WHERE x.lab_test = 1305 AND x.test_result = 1302 AND date(x.visit_date) BETWEEN :startDate AND :endDate\n" + + " UNION\n" + + " SELECT d.patient_id FROM kenyaemr_etl.etl_patient_demographics d\n" + + " INNER JOIN kenyaemr_etl.etl_laboratory_extract x ON x.patient_id = d.patient_id\n" + + " WHERE x.lab_test = 856 AND x.test_result IS NOT NULL AND date(x.visit_date) BETWEEN :startDate AND :endDate;" + + ); + return sql; + } +} diff --git a/api/src/main/resources/content/kenyaemr.common.xml b/api/src/main/resources/content/kenyaemr.common.xml index 93cdbf3cd5..8d7fa48762 100644 --- a/api/src/main/resources/content/kenyaemr.common.xml +++ b/api/src/main/resources/content/kenyaemr.common.xml @@ -98,6 +98,8 @@ + + @@ -981,5 +983,27 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/omod/src/main/webapp/resources/reports/MOH240.xls b/omod/src/main/webapp/resources/reports/MOH240.xls new file mode 100644 index 0000000000..4f45cb3180 Binary files /dev/null and b/omod/src/main/webapp/resources/reports/MOH240.xls differ diff --git a/omod/src/main/webapp/resources/reports/MOH706.xls b/omod/src/main/webapp/resources/reports/MOH706.xls new file mode 100644 index 0000000000..6901b12084 Binary files /dev/null and b/omod/src/main/webapp/resources/reports/MOH706.xls differ