diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/HIVARTReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/HIVARTReportBuilder.java new file mode 100755 index 00000000..361650c8 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/HIVARTReportBuilder.java @@ -0,0 +1,182 @@ +/** + * 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.kenyaemrextras.reporting; + +import org.openmrs.PatientIdentifierType; +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.hiv.art.DateOfEnrollmentArtCalculation; +import org.openmrs.module.kenyaemr.metadata.HivMetadata; +import org.openmrs.module.kenyaemr.reporting.calculation.converter.DateArtStartDateConverter; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.*; +import org.openmrs.module.kenyaemrextras.reporting.cohort.definition.ARTPedsQualityOfCareCohortDefinition; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.*; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.sims.SimsCTXDispensedDataDefinition; +import org.openmrs.module.metadatadeploy.MetadataUtils; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +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.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.extras.report.HIVARTReport" }) +public class HIVARTReportBuilder extends AbstractHybridReportBuilder { + + public static final String DATE_FORMAT = "dd/MM/yyyy"; + + /** + * @see org.openmrs.module.kenyacore.report.builder.AbstractCohortReportBuilder#addColumns(org.openmrs.module.kenyacore.report.CohortReportDescriptor, + * PatientDataSetDefinition) + */ + @Override + protected void addColumns(HybridReportDescriptor report, PatientDataSetDefinition dsd) { + + } + + @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 Mapped buildCohort(HybridReportDescriptor descriptor, PatientDataSetDefinition dsd) { + return null; + } + + protected Mapped activePedsCohort() { + CohortDefinition cd = new ARTPedsQualityOfCareCohortDefinition(); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.setName("Active Peds"); + return ReportUtils.map(cd, "startDate=${startDate},endDate=${endDate}"); + } + + String paramMapping = "startDate=${startDate},endDate=${endDate}"; + + @Override + protected List> buildDataSets(ReportDescriptor descriptor, ReportDefinition report) { + + PatientDataSetDefinition activePedsDataSetDefinition = activePedsDataSetDefinition("activePeds"); + activePedsDataSetDefinition.addRowFilter(activePedsCohort()); + DataSetDefinition activePedsDSD = activePedsDataSetDefinition; + + return Arrays.asList(ReportUtils.map(activePedsDSD, "startDate=${startDate},endDate=${endDate}")); + + } + + protected PatientDataSetDefinition activePedsDataSetDefinition(String datasetName) { + + PatientDataSetDefinition dsd = new PatientDataSetDefinition(datasetName); + String indParams = "startDate=${startDate},endDate=${endDate}"; + + dsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + + PatientIdentifierType upn = MetadataUtils.existing(PatientIdentifierType.class, + HivMetadata._PatientIdentifierType.UNIQUE_PATIENT_NUMBER); + DataConverter identifierFormatter = new ObjectFormatter("{identifier}"); + DataDefinition identifierDef = new ConvertedPatientDataDefinition("identifier", new PatientIdentifierDataDefinition( + upn.getName(), upn), identifierFormatter); + + DataConverter nameFormatter = new ObjectFormatter("{familyName}, {givenName}"); + DataDefinition nameDef = new ConvertedPersonDataDefinition("name", new PreferredNameDataDefinition(), nameFormatter); + dsd.addColumn("id", new PersonIdDataDefinition(), ""); + + dsd.addColumn("CCC No", identifierDef, ""); + dsd.addColumn("Date of Birth", new BirthdateDataDefinition(), "", new BirthdateConverter(DATE_FORMAT)); + dsd.addColumn("Age", new AgeDataDefinition(), ""); + + dsd.addColumn("Sex", new GenderDataDefinition(), "", null); + DQAWeightDataDefinition weightDataDefinition = new DQAWeightDataDefinition(); + weightDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + weightDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Weight", weightDataDefinition, indParams, null); + + DQAHeightDataDefinition heightDataDefinition = new DQAHeightDataDefinition(); + heightDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + heightDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Height", heightDataDefinition, indParams, null); + + dsd.addColumn("Date Enrolled in HIV Care", new CalculationDataDefinition("Enrollment Date", + new DateOfEnrollmentArtCalculation()), "", new DateArtStartDateConverter()); + + ETLArtStartDateDataDefinition artInitiationDataDefinition = new ETLArtStartDateDataDefinition(); + artInitiationDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + artInitiationDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Date Started ART", artInitiationDataDefinition, indParams, new DateConverter(DATE_FORMAT)); + + dsd.addColumn("Start Regimen", new ETLFirstRegimenDataDefinition(), ""); + + DQACurrentRegimenDataDefinition currentRegimenDataDefinition = new DQACurrentRegimenDataDefinition(); + currentRegimenDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + currentRegimenDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Current Regimen", currentRegimenDataDefinition, indParams, null); + dsd.addColumn("Baseline CD4 Date", new BaselineCD4DateDataDefinition(), "", null); + dsd.addColumn("Baseline CD4", new DQABaselineCD4DataDefinition(), "", null); + + ETLLastVLDateDataDefinition lastVLDateDataDefinition = new ETLLastVLDateDataDefinition(); + lastVLDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + lastVLDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addColumn("Last VL date", lastVLDateDataDefinition, paramMapping, null); + + ETLLastVLResultDataDefinition lastVLResultDataDefinition = new ETLLastVLResultDataDefinition(); + lastVLResultDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + lastVLResultDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addColumn("Last VL result", lastVLResultDataDefinition, paramMapping, null); + + dsd.addColumn("CTX dispensed", new SimsCTXDispensedDataDefinition(), ""); + + DQATBScreeningLastVisitOutcomeDataDefinition tbScreeningOutcomeDataDefinition = new DQATBScreeningLastVisitOutcomeDataDefinition(); + tbScreeningOutcomeDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + tbScreeningOutcomeDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("TB Screening Outcome", tbScreeningOutcomeDataDefinition, indParams, null); + + ETLLastVisitDateDataDefinition lastVisitDateDataDefinition = new ETLLastVisitDateDataDefinition(); + lastVisitDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + lastVisitDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Last Visit Date", lastVisitDateDataDefinition, "endDate=${endDate}", new DateConverter(DATE_FORMAT)); + + ETLNextAppointmentDateDataDefinition nextAppointmentDateDataDefinition = new ETLNextAppointmentDateDataDefinition(); + nextAppointmentDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + nextAppointmentDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Next Appointment Date", nextAppointmentDateDataDefinition, "endDate=${endDate}", new DateConverter( + DATE_FORMAT)); + + return dsd; + } + +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/HIVHTSReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/HIVHTSReportBuilder.java new file mode 100755 index 00000000..ed19287a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/HIVHTSReportBuilder.java @@ -0,0 +1,138 @@ +/** + * 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.kenyaemrextras.reporting; + +import org.openmrs.PatientIdentifierType; +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.kenyaemr.metadata.HivMetadata; +import org.openmrs.module.kenyaemr.reporting.data.converter.HTSEntryPointConverter; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.art.*; +import org.openmrs.module.kenyaemrextras.reporting.cohort.definition.HTSAdolescentsQualityOfCareCohortDefinition; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.*; +import org.openmrs.module.metadatadeploy.MetadataUtils; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.data.converter.BirthdateConverter; +import org.openmrs.module.reporting.data.converter.DateConverter; +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.extras.report.HIVHTSReport" }) +public class HIVHTSReportBuilder extends AbstractHybridReportBuilder { + + public static final String DATE_FORMAT = "dd/MM/yyyy"; + + /** + * @see org.openmrs.module.kenyacore.report.builder.AbstractCohortReportBuilder#addColumns(org.openmrs.module.kenyacore.report.CohortReportDescriptor, + * PatientDataSetDefinition) + */ + @Override + protected void addColumns(HybridReportDescriptor report, PatientDataSetDefinition dsd) { + + } + + @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 Mapped buildCohort(HybridReportDescriptor descriptor, PatientDataSetDefinition dsd) { + return null; + } + + protected Mapped htsAdolescentsCohort() { + CohortDefinition cd = new HTSAdolescentsQualityOfCareCohortDefinition(); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.setName("HTS Adolescents"); + return ReportUtils.map(cd, "startDate=${startDate},endDate=${endDate}"); + } + + String paramMapping = "startDate=${startDate},endDate=${endDate}"; + + @Override + protected List> buildDataSets(ReportDescriptor descriptor, ReportDefinition report) { + + PatientDataSetDefinition htsAdolescentsDataSetDefinition = htsAdolescentsDefinition("htsAdolescents"); + htsAdolescentsDataSetDefinition.addRowFilter(htsAdolescentsCohort()); + DataSetDefinition htsPedsDSD = htsAdolescentsDataSetDefinition; + + return Arrays.asList(ReportUtils.map(htsPedsDSD, "startDate=${startDate},endDate=${endDate}")); + + } + + protected PatientDataSetDefinition htsAdolescentsDefinition(String datasetName) { + + PatientDataSetDefinition dsd = new PatientDataSetDefinition(datasetName); + String indParams = "startDate=${startDate},endDate=${endDate}"; + + dsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + + PatientIdentifierType upn = MetadataUtils.existing(PatientIdentifierType.class, + HivMetadata._PatientIdentifierType.UNIQUE_PATIENT_NUMBER); + + dsd.addColumn("id", new PersonIdDataDefinition(), ""); + + dsd.addColumn("Date of Birth", new BirthdateDataDefinition(), "", new BirthdateConverter(DATE_FORMAT)); + dsd.addColumn("Age", new AgeDataDefinition(), ""); + dsd.addColumn("Sex", new GenderDataDefinition(), "", null); + + HTSEntryPointDataDefinition entryPointDataDefinition = new HTSEntryPointDataDefinition(); + entryPointDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + entryPointDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addColumn("Entry Point", entryPointDataDefinition, indParams, new HTSEntryPointConverter()); + + HTSDateDataDefinition htsDateDataDefinition = new HTSDateDataDefinition(); + htsDateDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + htsDateDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addColumn("Date tested", htsDateDataDefinition, indParams, new DateConverter(DATE_FORMAT)); + + FinalHTSResultDataDefinition finalHTSResultDataDefinition = new FinalHTSResultDataDefinition(); + finalHTSResultDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + finalHTSResultDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addColumn("Final result", finalHTSResultDataDefinition, indParams, null); + + FinalHTSResultGivenDataDefinition finalHTSResultGivenDataDefinition = new FinalHTSResultGivenDataDefinition(); + finalHTSResultGivenDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + finalHTSResultGivenDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + dsd.addColumn("Results Received", finalHTSResultGivenDataDefinition, indParams, null); + + RetestedBeforeARTInititionDataDefinition confirmatoryTestBeforeEnrollmentDataDefinition = new RetestedBeforeARTInititionDataDefinition(); + confirmatoryTestBeforeEnrollmentDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + confirmatoryTestBeforeEnrollmentDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Confirmatory Tests Done Before Enrollment", confirmatoryTestBeforeEnrollmentDataDefinition, + indParams, null); + + ReferredForServicesDataDefinition referredForServicesDataDefinition = new ReferredForServicesDataDefinition(); + referredForServicesDataDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + referredForServicesDataDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addColumn("Referred for Services", referredForServicesDataDefinition, indParams, null); + + return dsd; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/ARTPedsQualityOfCareCohortDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/ARTPedsQualityOfCareCohortDefinition.java new file mode 100644 index 00000000..771f2937 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/ARTPedsQualityOfCareCohortDefinition.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.cohort.definition; + +import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition; +import org.openmrs.module.reporting.common.Localized; +import org.openmrs.module.reporting.definition.configuration.ConfigurationProperty; +import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy; +import org.openmrs.module.reporting.evaluation.caching.Caching; + +import java.util.Date; + +/** + * Active on ART Peds definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +@Localized("reporting.ARTPedsQualityOfCareCohortDefinition") +public class ARTPedsQualityOfCareCohortDefinition extends BaseCohortDefinition { + + @ConfigurationProperty + private Date startDate; + + @ConfigurationProperty + private Date endDate; + + public ARTPedsQualityOfCareCohortDefinition() { + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/HTSAdolescentsQualityOfCareCohortDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/HTSAdolescentsQualityOfCareCohortDefinition.java new file mode 100644 index 00000000..4521d604 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/HTSAdolescentsQualityOfCareCohortDefinition.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.cohort.definition; + +import org.openmrs.module.reporting.cohort.definition.BaseCohortDefinition; +import org.openmrs.module.reporting.common.Localized; +import org.openmrs.module.reporting.definition.configuration.ConfigurationProperty; +import org.openmrs.module.reporting.definition.configuration.ConfigurationPropertyCachingStrategy; +import org.openmrs.module.reporting.evaluation.caching.Caching; + +import java.util.Date; + +/** + * HTS adolescents definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +@Localized("reporting.HTSAdolescentsQualityOfCareCohortDefinition") +public class HTSAdolescentsQualityOfCareCohortDefinition extends BaseCohortDefinition { + + @ConfigurationProperty + private Date startDate; + + @ConfigurationProperty + private Date endDate; + + public HTSAdolescentsQualityOfCareCohortDefinition() { + } + + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/evaluator/ARTPedsQualityOfServiceCohortDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/evaluator/ARTPedsQualityOfServiceCohortDefinitionEvaluator.java new file mode 100644 index 00000000..8571eb9b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/evaluator/ARTPedsQualityOfServiceCohortDefinitionEvaluator.java @@ -0,0 +1,92 @@ +/** + * 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.kenyaemrextras.reporting.cohort.definition.evaluator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.Cohort; +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.cohort.definition.ARTPedsQualityOfCareCohortDefinition; +import org.openmrs.module.reporting.cohort.EvaluatedCohort; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.cohort.definition.evaluator.CohortDefinitionEvaluator; +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.HashSet; +import java.util.List; + +/** + * Evaluator for Active on ART Peds + */ +@Handler(supports = { ARTPedsQualityOfCareCohortDefinition.class }) +public class ARTPedsQualityOfServiceCohortDefinitionEvaluator implements CohortDefinitionEvaluator { + + private final Log log = LogFactory.getLog(this.getClass()); + + @Autowired + EvaluationService evaluationService; + + @Override + public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException { + + ARTPedsQualityOfCareCohortDefinition definition = (ARTPedsQualityOfCareCohortDefinition) cohortDefinition; + + if (definition == null) + return null; + + Cohort newCohort = new Cohort(); + + String qry = " select t.patient_id\n" + + " from (\n" + + " select fup.visit_date,fup.patient_id, max(e.visit_date) as enroll_date,\n" + + " mid(max(concat(e.visit_date, e.patient_type)), 11) as patient_type,\n" + + " greatest(max(fup.visit_date), ifnull(max(d.visit_date),'0000-00-00')) as latest_vis_date,\n" + + " greatest(mid(max(concat(fup.visit_date,fup.next_appointment_date)),11), ifnull(max(d.visit_date),'0000-00-00')) as latest_tca,\n" + + " p.dob as dob,\n" + + " d.patient_id as disc_patient,\n" + + " d.effective_disc_date as effective_disc_date,\n" + + " max(d.visit_date) as date_discontinued,\n" + + " de.patient_id as started_on_drugs,\n" + + " mid(max(concat(date (de.date_started), ifnull(de.discontinued, 0))), 11) as on_drugs\n" + + " from kenyaemr_etl.etl_patient_hiv_followup fup\n" + + " join kenyaemr_etl.etl_patient_demographics p on p.patient_id=fup.patient_id\n" + + " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id=e.patient_id\n" + + " inner join kenyaemr_etl.etl_drug_event de on e.patient_id = de.patient_id and de.program='HIV' and date (date_started) <= date (:endDate)\n" + + " left outer JOIN\n" + + " (select patient_id, coalesce (date (effective_discontinuation_date),visit_date) visit_date,max(date (effective_discontinuation_date)) as effective_disc_date from kenyaemr_etl.etl_patient_program_discontinuation\n" + + " where date (visit_date) <= date (:endDate) and program_name='HIV'\n" + + " group by patient_id\n" + + " ) d on d.patient_id = fup.patient_id\n" + + " where fup.visit_date <= date (:endDate)\n" + + " group by patient_id\n" + + " having timestampdiff(YEAR ,dob, date (:endDate)) < 15 and\n" + + " timestampdiff(MONTH, date (latest_vis_date), date (:endDate)) <= 6 and (\n" + + " (\n" + + " ((timestampdiff(DAY, date (latest_tca), date (:endDate)) <= 30 and ((date (d.effective_disc_date) > date (:endDate) or date (enroll_date) > date (d.effective_disc_date)) or d.effective_disc_date is null))\n" + + " and (date (latest_vis_date) >= date (date_discontinued) or date (latest_tca) >= date (date_discontinued) or disc_patient is null)\n" + + " ))) order by latest_vis_date desc limit 10) t;"; + + SqlQueryBuilder builder = new SqlQueryBuilder(); + builder.append(qry); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + builder.addParameter("startDate", startDate); + builder.addParameter("endDate", endDate); + + List ptIds = evaluationService.evaluateToList(builder, Integer.class, context); + newCohort.setMemberIds(new HashSet(ptIds)); + return new EvaluatedCohort(newCohort, definition, context); + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/evaluator/HTSAdolescentsQualityOfServiceCohortDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/evaluator/HTSAdolescentsQualityOfServiceCohortDefinitionEvaluator.java new file mode 100644 index 00000000..e8c9139b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/cohort/definition/evaluator/HTSAdolescentsQualityOfServiceCohortDefinitionEvaluator.java @@ -0,0 +1,65 @@ +/** + * 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.kenyaemrextras.reporting.cohort.definition.evaluator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.Cohort; +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.cohort.definition.HTSAdolescentsQualityOfCareCohortDefinition; +import org.openmrs.module.reporting.cohort.EvaluatedCohort; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.cohort.definition.evaluator.CohortDefinitionEvaluator; +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.HashSet; +import java.util.List; + +/** + * Evaluator for HTS adolescents + */ +@Handler(supports = { HTSAdolescentsQualityOfCareCohortDefinition.class }) +public class HTSAdolescentsQualityOfServiceCohortDefinitionEvaluator implements CohortDefinitionEvaluator { + + private final Log log = LogFactory.getLog(this.getClass()); + + @Autowired + EvaluationService evaluationService; + + @Override + public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException { + + HTSAdolescentsQualityOfCareCohortDefinition definition = (HTSAdolescentsQualityOfCareCohortDefinition) cohortDefinition; + + if (definition == null) + return null; + + Cohort newCohort = new Cohort(); + + String qry = "SELECT t.patient_id from kenyaemr_etl.etl_hts_test t inner join kenyaemr_etl.etl_patient_demographics p on p.patient_id=t.patient_id and p.voided = 0 where t.voided = 0 and date(t.visit_date) BETWEEN date(:startDate) AND date(:endDate)\n" + + "and timestampdiff(YEAR ,p.dob, date (:endDate)) < 15 between 10 and 19 order by t.visit_date desc limit 10;"; + + SqlQueryBuilder builder = new SqlQueryBuilder(); + builder.append(qry); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + builder.addParameter("startDate", startDate); + builder.addParameter("endDate", endDate); + + List ptIds = evaluationService.evaluateToList(builder, Integer.class, context); + newCohort.setMemberIds(new HashSet(ptIds)); + return new EvaluatedCohort(newCohort, definition, context); + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/FinalHTSResultDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/FinalHTSResultDataDefinition.java new file mode 100644 index 00000000..4437d538 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/FinalHTSResultDataDefinition.java @@ -0,0 +1,49 @@ +/** + * 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.kenyaemrextras.reporting.data.definition; + +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; + +import java.util.Date; + +/** + * HTS clients referred for services Data Definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +public class FinalHTSResultDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public FinalHTSResultDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public FinalHTSResultDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/FinalHTSResultGivenDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/FinalHTSResultGivenDataDefinition.java new file mode 100644 index 00000000..be6db8ab --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/FinalHTSResultGivenDataDefinition.java @@ -0,0 +1,49 @@ +/** + * 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.kenyaemrextras.reporting.data.definition; + +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; + +import java.util.Date; + +/** + * HTS clients referred for services Data Definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +public class FinalHTSResultGivenDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public FinalHTSResultGivenDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public FinalHTSResultGivenDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/HTSDateDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/HTSDateDataDefinition.java new file mode 100644 index 00000000..626b7d4c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/HTSDateDataDefinition.java @@ -0,0 +1,49 @@ +/** + * 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.kenyaemrextras.reporting.data.definition; + +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; + +import java.util.Date; + +/** + * HIV TEST DATE Data Definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +public class HTSDateDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public HTSDateDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public HTSDateDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/HTSEntryPointDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/HTSEntryPointDataDefinition.java new file mode 100644 index 00000000..6e2cc9d1 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/HTSEntryPointDataDefinition.java @@ -0,0 +1,49 @@ +/** + * 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.kenyaemrextras.reporting.data.definition; + +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; + +import java.util.Date; + +/** + * HTS entry point Data Definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +public class HTSEntryPointDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public HTSEntryPointDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public HTSEntryPointDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/ReferredForServicesDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/ReferredForServicesDataDefinition.java new file mode 100644 index 00000000..3366789d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/ReferredForServicesDataDefinition.java @@ -0,0 +1,49 @@ +/** + * 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.kenyaemrextras.reporting.data.definition; + +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; + +import java.util.Date; + +/** + * HTS clients referred for services Data Definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +public class ReferredForServicesDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public ReferredForServicesDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public ReferredForServicesDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/RetestedBeforeARTInititionDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/RetestedBeforeARTInititionDataDefinition.java new file mode 100644 index 00000000..85ca9e51 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/RetestedBeforeARTInititionDataDefinition.java @@ -0,0 +1,49 @@ +/** + * 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.kenyaemrextras.reporting.data.definition; + +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; + +import java.util.Date; + +/** + * HTS clients who turn HIV positive retest confirmation Data Definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +public class RetestedBeforeARTInititionDataDefinition extends BaseDataDefinition implements PersonDataDefinition { + + public static final long serialVersionUID = 1L; + + /** + * Default Constructor + */ + public RetestedBeforeARTInititionDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public RetestedBeforeARTInititionDataDefinition(String name) { + super(name); + } + + //***** INSTANCE METHODS ***** + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/FinalHTSResultDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/FinalHTSResultDataEvaluator.java new file mode 100644 index 00000000..95d5a8dc --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/FinalHTSResultDataEvaluator.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.data.definition.evaluator; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.FinalHTSResultDataDefinition; +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 Final result Data Definition + */ +@Handler(supports = FinalHTSResultDataDefinition.class, order = 50) +public class FinalHTSResultDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) + throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select t.patient_id, mid(max(concat(t.visit_date,t.final_test_result)),11) as final_test_result from kenyaemr_etl.etl_hts_test t where date(t.visit_date) between\n" + + "date(:startDate) and date(:endDate) group by t.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + queryBuilder.append(qry); + 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/kenyaemrextras/reporting/data/definition/evaluator/FinalHTSResultGivenDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/FinalHTSResultGivenDataEvaluator.java new file mode 100644 index 00000000..0e7dd2a3 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/FinalHTSResultGivenDataEvaluator.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.data.definition.evaluator; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.FinalHTSResultGivenDataDefinition; +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 final results given Data Definition + */ +@Handler(supports = FinalHTSResultGivenDataDefinition.class, order = 50) +public class FinalHTSResultGivenDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) + throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select t.patient_id, mid(max(concat(t.visit_date,t.patient_given_result)),11) as final_test_result_given from kenyaemr_etl.etl_hts_test t where date(t.visit_date) between\n" + + "date(:startDate) and date(:endDate) group by t.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + queryBuilder.append(qry); + 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/kenyaemrextras/reporting/data/definition/evaluator/HTSDateDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/HTSDateDataEvaluator.java new file mode 100644 index 00000000..bae84a59 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/HTSDateDataEvaluator.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.data.definition.evaluator; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.HTSDateDataDefinition; +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 HIV test date Data Definition + */ +@Handler(supports = HTSDateDataDefinition.class, order = 50) +public class HTSDateDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) + throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select t.patient_id, max(t.visit_date) as test_date from kenyaemr_etl.etl_hts_test t where date(t.visit_date) between\n" + + "date(:startDate) and date(:endDate) group by t.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + queryBuilder.append(qry); + 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/kenyaemrextras/reporting/data/definition/evaluator/HTSEntryPointDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/HTSEntryPointDataEvaluator.java new file mode 100644 index 00000000..c47afd17 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/HTSEntryPointDataEvaluator.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.data.definition.evaluator; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.HTSEntryPointDataDefinition; +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 HTS entry point Data Definition + */ +@Handler(supports = HTSEntryPointDataDefinition.class, order = 50) +public class HTSEntryPointDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) + throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select t.patient_id, mid(max(concat(t.visit_date,t.hts_entry_point)),11) as hts_entry_point from kenyaemr_etl.etl_hts_test t where date(t.visit_date) between\n" + + "date(:startDate) and date(:endDate) group by t.patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + queryBuilder.append(qry); + 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/kenyaemrextras/reporting/data/definition/evaluator/ReferredForServicesDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/ReferredForServicesDataEvaluator.java new file mode 100644 index 00000000..04e5132c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/ReferredForServicesDataEvaluator.java @@ -0,0 +1,52 @@ +/** + * 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.kenyaemrextras.reporting.data.definition.evaluator; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.ReferredForServicesDataDefinition; +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 Referred For Services Data Definition + */ +@Handler(supports = ReferredForServicesDataDefinition.class, order = 50) +public class ReferredForServicesDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) + throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select t.patient_id, concat_ws('\\n\\r',t.referral_for, t.neg_referral_for, t.neg_referral_specify) as referred\n" + + " from kenyaemr_etl.etl_hts_test t where t.visit_date between date (:startDate) and date (:endDate);"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + queryBuilder.append(qry); + 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/kenyaemrextras/reporting/data/definition/evaluator/RetestedBeforeARTInititionDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/RetestedBeforeARTInititionDataEvaluator.java new file mode 100644 index 00000000..bd4cdab9 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemrextras/reporting/data/definition/evaluator/RetestedBeforeARTInititionDataEvaluator.java @@ -0,0 +1,61 @@ +/** + * 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.kenyaemrextras.reporting.data.definition.evaluator; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.DQATBScreeningLastVisitOutcomeDataDefinition; +import org.openmrs.module.kenyaemrextras.reporting.data.definition.RetestedBeforeARTInititionDataDefinition; +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 Retested Before ART Initition Data Definition + */ +@Handler(supports = RetestedBeforeARTInititionDataDefinition.class, order = 50) +public class RetestedBeforeARTInititionDataEvaluator implements PersonDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedPersonData evaluate(PersonDataDefinition definition, EvaluationContext context) + throws EvaluationException { + EvaluatedPersonData c = new EvaluatedPersonData(definition, context); + + String qry = "select a.patient_id, if (retestDate is null or hts_test_result = 'Negative','NA', if (hts_test_result = 'Positive' and retestDate <= enr_date ,'Y','N' )) as retested_before_enrollment from (\n" + + " select a.patient_id, x.enr_date,h.retestDate,h.hts_test_result from kenyaemr_etl.etl_patient_demographics a\n" + + " left outer join (\n" + + " select t.patient_id, max(t.visit_date) as retestDate, mid(max(concat(date (t.visit_date),t.final_test_result)),11) as hts_test_result,\n" + + " mid(max(concat(date (t.visit_date),t.test_type)),11) as test_type from kenyaemr_etl.etl_hts_test t\n" + + " GROUP BY t.patient_id\n" + + " ) h on a.patient_id = h.patient_id left outer join (\n" + + " select d.patient_id, min(d.visit_date) as enr_date from kenyaemr_etl.etl_hiv_enrollment d\n" + + " GROUP BY d.patient_id ) x on a.patient_id = x.patient_id GROUP BY a.patient_id) a\n" + + " group by patient_id;"; + + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + Date startDate = (Date) context.getParameterValue("startDate"); + Date endDate = (Date) context.getParameterValue("endDate"); + queryBuilder.addParameter("endDate", endDate); + queryBuilder.addParameter("startDate", startDate); + queryBuilder.append(qry); + Map data = evaluationService.evaluateToMap(queryBuilder, Integer.class, Object.class, context); + c.setData(data); + return c; + } +} diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 93bb1a40..c80874af 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -76,6 +76,8 @@ + + @@ -116,6 +118,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/omod/src/main/webapp/resources/reports/.~lock.sims.xls# b/omod/src/main/webapp/resources/reports/.~lock.sims.xls# deleted file mode 100644 index 10b80136..00000000 --- a/omod/src/main/webapp/resources/reports/.~lock.sims.xls# +++ /dev/null @@ -1 +0,0 @@ -,sc,sc-Latitude-7410,06.09.2023 08:39,file:///home/sc/.config/libreoffice/4; \ No newline at end of file diff --git a/omod/src/main/webapp/resources/reports/hiv_art.xls b/omod/src/main/webapp/resources/reports/hiv_art.xls new file mode 100644 index 00000000..0a6d068d Binary files /dev/null and b/omod/src/main/webapp/resources/reports/hiv_art.xls differ diff --git a/omod/src/main/webapp/resources/reports/hiv_hts.xls b/omod/src/main/webapp/resources/reports/hiv_hts.xls new file mode 100644 index 00000000..3cecf868 Binary files /dev/null and b/omod/src/main/webapp/resources/reports/hiv_hts.xls differ