diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/ActivePatientSnapshotReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/ActivePatientSnapshotReportBuilder.java index 11f70bf3d4..6cc704a6e8 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/ActivePatientSnapshotReportBuilder.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/ActivePatientSnapshotReportBuilder.java @@ -30,43 +30,10 @@ import org.openmrs.module.kenyaemr.reporting.cohort.definition.ActivePatientsSnapshotCohortDefinition; import org.openmrs.module.kenyaemr.reporting.data.converter.ActiveInProgramConverter; import org.openmrs.module.kenyaemr.reporting.data.converter.BooleanResultsConverter; +import org.openmrs.module.kenyaemr.reporting.data.converter.CalculationResultConverter; import org.openmrs.module.kenyaemr.reporting.data.converter.definition.ActivePatientsPopulationTypeDataDefinition; import org.openmrs.module.kenyaemr.reporting.data.converter.definition.MFLCodeDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ActiveInMchDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ActiveInOtzDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ActiveInOvcDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ActiveInTbDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.AgeAtReportingDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.BaselineCD4CountDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.BaselineCD4DateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.BloodPressureDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLArtStartDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLCaseManagerDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLCurrentRegLineDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLCurrentRegimenDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLDifferentiatedCareModelDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLFirstRegimenDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLHivSelfVisitDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastCD4DateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastCD4ResultDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVLDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVLJustificationDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVLResultDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVLResultValidityDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastVisitDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLLastWHOStageDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLMonthsOfPrescriptionDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLNextAppointmentDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLRefillDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.ETLStabilityDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.HeightAtArtDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.MedicalCoverDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.MedicalCoverStatusDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.NCDDateDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.NCDStatusDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.NCDsDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.WHOStageArtDataDefinition; -import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.WeightAtArtDataDefinition; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.*; import org.openmrs.module.metadatadeploy.MetadataUtils; import org.openmrs.module.reporting.cohort.definition.CohortDefinition; import org.openmrs.module.reporting.data.DataDefinition; @@ -201,6 +168,15 @@ protected PatientDataSetDefinition activePatientsDataSetDefinition(String datase lastCD4ResultDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); ETLLastCD4DateDataDefinition etlLastCD4DateDataDefinition = new ETLLastCD4DateDataDefinition(); etlLastCD4DateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + LastRiskScoreDataDefinition lastRiskScoreDataDefinition = new LastRiskScoreDataDefinition(); + lastRiskScoreDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + lastRiskScoreDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + LastRiskCategorizationDataDefinition lastRiskCategorizationDataDefinition = new LastRiskCategorizationDataDefinition(); + lastRiskCategorizationDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + lastRiskCategorizationDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + LastRiskEvaluationDateDataDefinition lastRiskEvaluationDateDataDefinition = new LastRiskEvaluationDateDataDefinition(); + lastRiskEvaluationDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + lastRiskEvaluationDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); DataConverter formatter = new ObjectFormatter("{familyName}, {givenName}"); @@ -256,6 +232,10 @@ protected PatientDataSetDefinition activePatientsDataSetDefinition(String datase dsd.addColumn("AHD Client", new CalculationDataDefinition("AHD Client", new PatientsWithAdvancedHivDiseaseCalculation()), "", new BooleanResultsConverter()); dsd.addColumn("Medical cover", medicalCoverDataDefinition, "endDate=${endDate}"); dsd.addColumn("Medical cover status", medicalCoverStatusDataDefinition, "endDate=${endDate}"); + dsd.addColumn("Last risk score", lastRiskScoreDataDefinition, "endDate=${endDate}"); + dsd.addColumn("Risk categorization", lastRiskCategorizationDataDefinition, "endDate=${endDate}"); + dsd.addColumn("Evaluation date", lastRiskEvaluationDateDataDefinition, "endDate=${endDate}"); + return dsd; diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskCategorizationDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskCategorizationDataDefinition.java new file mode 100644 index 0000000000..0713baae9d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskCategorizationDataDefinition.java @@ -0,0 +1,47 @@ +/** + * 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.data.converter.definition.art; + +import org.openmrs.module.reporting.data.BaseDataDefinition; +import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition; +import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy; +import org.openmrs.module.reporting.evaluation.caching.Caching; + +/** + * Most current risk categorization + */ +@Caching(strategy=ConfigurationPropertyCachingStrategy.class) +public class LastRiskCategorizationDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public LastRiskCategorizationDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public LastRiskCategorizationDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Double.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskEvaluationDateDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskEvaluationDateDataDefinition.java new file mode 100644 index 0000000000..ca79ae2963 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskEvaluationDateDataDefinition.java @@ -0,0 +1,47 @@ +/** + * 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.data.converter.definition.art; + +import org.openmrs.module.reporting.data.BaseDataDefinition; +import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition; +import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy; +import org.openmrs.module.reporting.evaluation.caching.Caching; + +/** + * Most current risk evaluation date + */ +@Caching(strategy=ConfigurationPropertyCachingStrategy.class) +public class LastRiskEvaluationDateDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public LastRiskEvaluationDateDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public LastRiskEvaluationDateDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Double.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskScoreDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskScoreDataDefinition.java new file mode 100644 index 0000000000..219c7538e0 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/art/LastRiskScoreDataDefinition.java @@ -0,0 +1,47 @@ +/** + * 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.data.converter.definition.art; + +import org.openmrs.module.reporting.data.BaseDataDefinition; +import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition; +import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy; +import org.openmrs.module.reporting.evaluation.caching.Caching; + +/** + * Most current risk score + */ +@Caching(strategy=ConfigurationPropertyCachingStrategy.class) +public class LastRiskScoreDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public LastRiskScoreDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public LastRiskScoreDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Double.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskCategorizationDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskCategorizationDataEvaluator.java new file mode 100644 index 0000000000..e829981ae3 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskCategorizationDataEvaluator.java @@ -0,0 +1,53 @@ +/** + * 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.data.converter.definition.evaluator.art; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.LastRiskCategorizationDataDefinition; +import org.openmrs.module.reporting.data.person.EvaluatedPersonData; +import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition; +import org.openmrs.module.reporting.data.person.evaluator.PersonDataEvaluator; +import org.openmrs.module.reporting.evaluation.EvaluationContext; +import org.openmrs.module.reporting.evaluation.EvaluationException; +import org.openmrs.module.reporting.evaluation.querybuilder.SqlQueryBuilder; +import org.openmrs.module.reporting.evaluation.service.EvaluationService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.Map; + +/** + * Evaluates LastRiskCategorizationDataDefinition + */ +@Handler(supports= LastRiskCategorizationDataDefinition.class, order=50) +public class LastRiskCategorizationDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select ml.patient_id,\n" + + " mid(max(concat(ml.date_created ,concat(ml.description ))),20) as risk_score\n" + + "from kenyaemr_ml_patient_risk_score ml where ml.date_created <= date(:endDate)\n" + + "GROUP BY ml.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + queryBuilder.append(qry); + Date startDate = (Date)context.getParameterValue("startDate"); + Date endDate = (Date)context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + Map data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context); + c.setData(data); + return c; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskEvaluationDateDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskEvaluationDateDataEvaluator.java new file mode 100644 index 0000000000..04d031f5c5 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskEvaluationDateDataEvaluator.java @@ -0,0 +1,54 @@ +/** + * 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.data.converter.definition.evaluator.art; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.LastRiskCategorizationDataDefinition; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.LastRiskEvaluationDateDataDefinition; +import org.openmrs.module.reporting.data.person.EvaluatedPersonData; +import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition; +import org.openmrs.module.reporting.data.person.evaluator.PersonDataEvaluator; +import org.openmrs.module.reporting.evaluation.EvaluationContext; +import org.openmrs.module.reporting.evaluation.EvaluationException; +import org.openmrs.module.reporting.evaluation.querybuilder.SqlQueryBuilder; +import org.openmrs.module.reporting.evaluation.service.EvaluationService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.Map; + +/** + * Evaluates LastRiskCategorizationDataDefinition + */ +@Handler(supports= LastRiskEvaluationDateDataDefinition.class, order=50) +public class LastRiskEvaluationDateDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select ml.patient_id,\n" + + " mid(max(concat(ml.date_created ,NULLIF(concat(date(ml.evaluation_date)),'0000-00-00'))),20) as evaluation_date\n" + + "from kenyaemr_ml_patient_risk_score ml where ml.date_created <= date(:endDate)\n" + + "GROUP BY ml.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + queryBuilder.append(qry); + Date startDate = (Date)context.getParameterValue("startDate"); + Date endDate = (Date)context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + Map data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context); + c.setData(data); + return c; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskScoreDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskScoreDataEvaluator.java new file mode 100644 index 0000000000..eaa2b32afc --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/art/LastRiskScoreDataEvaluator.java @@ -0,0 +1,53 @@ +/** + * 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.data.converter.definition.evaluator.art; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.LastRiskScoreDataDefinition; +import org.openmrs.module.reporting.data.person.EvaluatedPersonData; +import org.openmrs.module.reporting.data.person.definition.PersonDataDefinition; +import org.openmrs.module.reporting.data.person.evaluator.PersonDataEvaluator; +import org.openmrs.module.reporting.evaluation.EvaluationContext; +import org.openmrs.module.reporting.evaluation.EvaluationException; +import org.openmrs.module.reporting.evaluation.querybuilder.SqlQueryBuilder; +import org.openmrs.module.reporting.evaluation.service.EvaluationService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.Map; + +/** + * Evaluates LastRiskScoreDataDefinition + */ +@Handler(supports= LastRiskScoreDataDefinition.class, order=50) +public class LastRiskScoreDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select ml.patient_id,\n" + + " mid(max(concat(ml.date_created ,concat(ml.risk_score ))),20) as risk_score\n" + + " from kenyaemr_ml_patient_risk_score ml where ml.date_created <= date(:endDate)\n" + + " GROUP BY ml.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + queryBuilder.append(qry); + Date startDate = (Date)context.getParameterValue("startDate"); + Date endDate = (Date)context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + Map data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context); + c.setData(data); + return c; + } +} diff --git a/omod/src/main/webapp/resources/reports/active_on_art_linelist.xls b/omod/src/main/webapp/resources/reports/active_on_art_linelist.xls index 1d5daed76e..28c810c212 100644 Binary files a/omod/src/main/webapp/resources/reports/active_on_art_linelist.xls and b/omod/src/main/webapp/resources/reports/active_on_art_linelist.xls differ