Skip to content

Commit

Permalink
Merge pull request #1869 from patryllus/moh240_706
Browse files Browse the repository at this point in the history
Initial stubs for MOH 240 and MOH 706 pulling from kenyaemr_etl reporting tables
  • Loading branch information
patryllus committed Apr 19, 2024
2 parents 5ef2cb9 + 9d86908 commit 9a6193f
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public static List<ColumnParameters> 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 https://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at https://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<CohortDefinition> buildCohort(HybridReportDescriptor hybridReportDescriptor,
PatientDataSetDefinition patientDataSetDefinition) {
return null;
}

@Override
protected List<Mapped<DataSetDefinition>> 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<Parameter> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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 https://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at https://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<Parameter> 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<Mapped<DataSetDefinition>> 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;
}

}

Original file line number Diff line number Diff line change
@@ -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 https://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at https://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}"));
}
}
Original file line number Diff line number Diff line change
@@ -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 https://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at https://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;
}
}
24 changes: 24 additions & 0 deletions api/src/main/resources/content/kenyaemr.common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
<ref bean="kenyaemr.ehrReports.report.moh204A" />
<ref bean="kenyaemr.ehrReports.report.moh204B" />
<ref bean="kenyaemr.ehrReports.report.facility.monthly.collection" />
<ref bean="kenyaemr.ehrReports.706.report" />
<ref bean="kenyaemr.ehrReports.report.240" />
</set>
</property>
</bean>
Expand Down Expand Up @@ -981,5 +983,27 @@
</set></property>
<property name="template" value="kenyaemr:MOH_717.xls" />
</bean>
<bean id="kenyaemr.ehrReports.706.report" class="org.openmrs.module.kenyacore.report.IndicatorReportDescriptor">
<property name="targetUuid" value="cf9f6e96-bfd4-41c0-8dfe-9807707bbf9d" />
<property name="name" value="MOH 706" />
<property name="description" value="MOH 706 Report" />
<property name="apps">
<set>
<ref bean="kenyaemr.app.reports" />
</set></property>
<property name="template" value="kenyaemr:MOH706.xls" />
</bean>
<bean id="kenyaemr.ehrReports.report.240" class="org.openmrs.module.kenyacore.report.HybridReportDescriptor">
<property name="targetUuid" value="30ca99ad-97a8-47f8-92fd-da2997a64bfb" />
<property name="name" value="Laboratory Register - MOH 240" />
<property name="description" value="Laboratory Register - MOH 240 Report" />
<property name="apps">
<set>
<ref bean="kenyaemr.app.reports" />
</set>
</property>
<property name="template" value="kenyaemr:MOH240.xls" />
<property name="repeatingSection" value="sheet:3,row:3,dataset:lrr" />
</bean>

</beans>
Binary file added omod/src/main/webapp/resources/reports/MOH240.xls
Binary file not shown.
Binary file added omod/src/main/webapp/resources/reports/MOH706.xls
Binary file not shown.

0 comments on commit 9a6193f

Please sign in to comment.