diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/ParentCalculation.java b/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/ParentCalculation.java index 3bd21f059a..7d7c3bbae2 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/ParentCalculation.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/ParentCalculation.java @@ -13,6 +13,8 @@ import org.openmrs.Patient; import org.openmrs.Person; import org.openmrs.Relationship; +import org.openmrs.RelationshipType; +import org.openmrs.api.PersonService; import org.openmrs.api.context.Context; import org.openmrs.calculation.patient.PatientCalculationContext; import org.openmrs.calculation.result.CalculationResultMap; @@ -20,6 +22,7 @@ import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation; import java.util.Collection; +import java.util.List; import java.util.Map; public class ParentCalculation extends AbstractPatientCalculation { @@ -36,40 +39,46 @@ public CalculationResultMap evaluate(Collection cohort, Map parentChildRel = personService.getRelationships(null, patient, parentChildType); + + // check if it is mothers + Person parent = null; + // a_is_to_b = 'Parent' and b_is_to_a = 'Child' + for (Relationship relationship : parentChildRel) { + + if (patient.equals(relationship.getPersonB())) { + if (relationship.getPersonA().getGender().equals(parentGender)) { + parent = relationship.getPersonA(); + break; } - - } else if (this.parentToSearch.equals("Mother")) { - - if (relationship.getPersonB().getGender().equals("F")) { - parentObj = relationship.getPersonB(); - break parentSearch; + } else if (patient.equals(relationship.getPersonA())) { + if (relationship.getPersonB().getGender().equals(parentGender)) { + parent = relationship.getPersonB(); + break; } - } - } - - } - - if (parentObj == null) { - ret.put(ptId, new SimpleResult(parentObj, this, context)); - }else{ - ret.put(ptId, new SimpleResult(parentObj.getPersonName().toString(), this, context)); + + + if (parent == null) { + ret.put(ptId, new SimpleResult(parent, this, context)); + } else { + ret.put(ptId, new SimpleResult(parent.getPersonName().toString(), this, context)); + } } } diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/PersonAddressCalculation.java b/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/PersonAddressCalculation.java index fa892a9755..b8ea76d865 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/PersonAddressCalculation.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/calculation/library/mchcs/PersonAddressCalculation.java @@ -9,6 +9,7 @@ */ package org.openmrs.module.kenyaemr.calculation.library.mchcs; +import org.apache.commons.lang.StringUtils; import org.openmrs.Patient; import org.openmrs.PersonAddress; import org.openmrs.api.context.Context; @@ -17,13 +18,15 @@ import org.openmrs.calculation.result.SimpleResult; import org.openmrs.module.kenyacore.calculation.AbstractPatientCalculation; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Map; public class PersonAddressCalculation extends AbstractPatientCalculation { private String address; - + public PersonAddressCalculation(String address) { this.address = address.toLowerCase(); @@ -42,57 +45,22 @@ public CalculationResultMap evaluate(Collection cohort, Map addresses = new ArrayList(); + + // get village + if (personAddress.getCityVillage() != null) { + addresses.add(patient.getPersonAddress().getCityVillage()); + } + + // get landmark + if (personAddress.getAddress2() != null) { + addresses.add(patient.getPersonAddress().getAddress2()); } - else { - - if (this.address.equals("province")) { - personAddressString = patient.getPersonAddress().getStateProvince(); - } - - if (this.address.equals("district")) { - personAddressString = patient.getPersonAddress().getCountyDistrict(); - } - - if (this.address.equals("division")) { - personAddressString = patient.getPersonAddress().getAddress4(); - } - - if (this.address.equals("location")) { - personAddressString = patient.getPersonAddress().getAddress6(); - } - - if (this.address.equals("sublocation")) { - personAddressString = patient.getPersonAddress().getAddress5(); - } - - if (this.address.equals("landmark")) { - personAddressString = patient.getPersonAddress().getAddress2(); - } - - if (this.address.equals("village")) { - personAddressString = patient.getPersonAddress().getCityVillage(); - } - + + if (addresses.size() > 0) { + personAddressString = StringUtils.join(addresses, "|"); + } ret.put(ptId, new SimpleResult(personAddressString, this, context)); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/chore/MigrateRegimenChangeHistory.java b/api/src/main/java/org/openmrs/module/kenyaemr/chore/MigrateRegimenChangeHistory.java index a08250debd..7fc5bb31a4 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/chore/MigrateRegimenChangeHistory.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/chore/MigrateRegimenChangeHistory.java @@ -20,6 +20,7 @@ import org.openmrs.Patient; import org.openmrs.Person; import org.openmrs.User; +import org.openmrs.api.AdministrationService; import org.openmrs.api.ConceptService; import org.openmrs.api.EncounterService; import org.openmrs.api.FormService; @@ -115,6 +116,9 @@ public void perform(PrintWriter out) { } out.println("Completed migration for drug regimen history"); + out.println("Voiding encounters with null regimen...."); + voidAllEncountersWithNullRegimen(); + out.println("Successfully completed all drug regimen migration operations"); } @@ -352,4 +356,23 @@ protected Set getPatientsWithOrders() { Cohort patientsHavingDrugOrder = Context.getPatientSetService().getPatientsHavingDrugOrder(null, null, null, null, null, null, null, null); return patientsHavingDrugOrder.getMemberIds(); } + + protected void voidAllEncountersWithNullRegimen(){ + + String encountersWithNullRegimenQry = "update encounter e inner join \n" + + "(\n" + + "select \n" + + "e.encounter_id,\n" + + "max(if(o.concept_id=1193,o.value_coded,null)) as regimen \n" + + "from encounter e \n" + + "inner join obs o on e.encounter_id = o.encounter_id and o.voided=0 and o.concept_id in(1193,1252,5622,1191,1255,1268) \n" + + "inner join ( select encounter_type, uuid,name from form where uuid in('da687480-e197-11e8-9f32-f2801f1b9fd1') ) f on f.encounter_type=e.encounter_type \n" + + "group by e.encounter_id having regimen is null\n" + + ") t on e.encounter_id=t.encounter_id\n" + + "set e.voided=1;"; + + AdministrationService as = Context.getAdministrationService(); + List> rowsAffected = as.executeSQL(encountersWithNullRegimenQry, false); + System.out.println("Rows affected: " + rowsAffected.size()); + } } diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/cwc/Moh510ReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/cwc/Moh510ReportBuilder.java index 3343e50cf2..e10376f63f 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/cwc/Moh510ReportBuilder.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/cwc/Moh510ReportBuilder.java @@ -18,6 +18,7 @@ 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.AbstractReportBuilder; import org.openmrs.module.kenyacore.report.builder.Builds; import org.openmrs.module.kenyacore.report.data.patient.definition.CalculationDataDefinition; import org.openmrs.module.kenyaemr.Dictionary; @@ -32,6 +33,9 @@ import org.openmrs.module.kenyaemr.reporting.calculation.converter.ObsDatetimeConverter; import org.openmrs.module.kenyaemr.reporting.calculation.converter.ObsValueDatetimeConverter; import org.openmrs.module.kenyaemr.reporting.calculation.converter.RDQACalculationResultConverter; +import org.openmrs.module.kenyaemr.reporting.cohort.definition.HTSRegisterCohortDefinition; +import org.openmrs.module.kenyaemr.reporting.cohort.definition.Moh510CohortDefinition; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.cwc.DateOfVaccineDataDefinition; import org.openmrs.module.kenyaemr.reporting.library.moh510.Moh510CohortLibrary; import org.openmrs.module.metadatadeploy.MetadataUtils; import org.openmrs.module.reporting.cohort.definition.CohortDefinition; @@ -39,8 +43,12 @@ 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.encounter.definition.EncounterIdDataDefinition; import org.openmrs.module.reporting.data.patient.definition.ConvertedPatientDataDefinition; +import org.openmrs.module.reporting.data.patient.definition.PatientIdDataDefinition; import org.openmrs.module.reporting.data.patient.definition.PatientIdentifierDataDefinition; import org.openmrs.module.reporting.data.person.definition.BirthdateDataDefinition; import org.openmrs.module.reporting.data.person.definition.ConvertedPersonDataDefinition; @@ -49,6 +57,7 @@ import org.openmrs.module.reporting.data.person.definition.PersonIdDataDefinition; import org.openmrs.module.reporting.data.person.definition.PreferredNameDataDefinition; import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; +import org.openmrs.module.reporting.dataset.definition.EncounterDataSetDefinition; import org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition; import org.openmrs.module.reporting.evaluation.parameter.Mapped; import org.openmrs.module.reporting.evaluation.parameter.Parameter; @@ -57,34 +66,23 @@ @Component @Builds({"kenyaemr.mchcs.report.moh510"}) -public class Moh510ReportBuilder extends AbstractHybridReportBuilder{ +public class Moh510ReportBuilder extends AbstractReportBuilder { public static final String DATE_FORMAT = "dd/MM/yyyy"; public Moh510ReportBuilder() { // TODO Auto-generated constructor stub } - - protected Mapped childrenEnrolledInCWCCohort() { - CohortDefinition cd = new Moh510CohortLibrary().enrolledInCWC(); - cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); - cd.addParameter(new Parameter("endDate", "End Date", Date.class)); - return ReportUtils.map(cd, "onOrAfter=${startDate},onOrBefore=${endDate}"); - } @SuppressWarnings("unchecked") @Override protected List> buildDataSets(ReportDescriptor descriptor, ReportDefinition report) { - PatientDataSetDefinition moh510PDSD = moh510DataSetDefinition("immunizationRegister"); - moh510PDSD.addRowFilter(childrenEnrolledInCWCCohort()); - DataSetDefinition moh510DSD = moh510PDSD; - return Arrays.asList( - ReportUtils.map(moh510DSD, "startDate=${startDate},endDate=${endDate}") + ReportUtils.map(moh510DataSetDefinition("immunizationRegister"), "startDate=${startDate},endDate=${endDate}") ); } - @Override + @Override protected List getParameters(ReportDescriptor descriptor) { return Arrays.asList( new Parameter("startDate", "Start Date", Date.class), @@ -93,9 +91,11 @@ protected List getParameters(ReportDescriptor descriptor) { ); } - protected PatientDataSetDefinition moh510DataSetDefinition(String datasetName) { + protected DataSetDefinition moh510DataSetDefinition(String datasetName) { + + String paramMapping = "startDate=${startDate},endDate=${endDate}"; - PatientDataSetDefinition dsd = new PatientDataSetDefinition(datasetName); + EncounterDataSetDefinition dsd = new EncounterDataSetDefinition(datasetName); dsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); dsd.addParameter(new Parameter("endDate", "End Date", Date.class)); @@ -105,43 +105,44 @@ protected PatientDataSetDefinition moh510DataSetDefinition(String datasetName) { DataConverter nameFormatter = new ObjectFormatter("{familyName}, {givenName}"); DataDefinition nameDef = new ConvertedPersonDataDefinition("name", new PreferredNameDataDefinition(), nameFormatter); + dsd.addColumn("id", new PersonIdDataDefinition(), ""); + dsd.addColumn("Visit Date", new EncounterDatetimeDataDefinition(), "", new DateConverter(DATE_FORMAT)); dsd.addColumn("Serial Number", new PersonIdDataDefinition(), ""); dsd.addColumn("CWC Number", identifierDef, ""); - dsd.addColumn("Childs Name", nameDef, ""); - dsd.addColumn("Sex", new GenderDataDefinition(), "", new GenderConverter()); + dsd.addColumn("Name", nameDef, ""); + dsd.addColumn("Sex", new GenderDataDefinition(), ""); dsd.addColumn("Date of Birth", new BirthdateDataDefinition(), "", new BirthdateConverter(DATE_FORMAT)); dsd.addColumn("Date first seen", new ObsForPersonDataDefinition("Date first seen", TimeQualifier.FIRST, Dictionary.getConcept(Dictionary.DATE_FIRST_SEEN), null, null), "", new ObsValueDatetimeConverter()); dsd.addColumn("Fathers full name", new CalculationDataDefinition("Father's full name", new ParentCalculation("Father")), "", new RDQACalculationResultConverter()); dsd.addColumn("Mothers full name", new CalculationDataDefinition("Mother's full name", new ParentCalculation("Mother")), "", new RDQACalculationResultConverter()); - dsd.addColumn("Village_Estate_Landmark", new CalculationDataDefinition("Village/Estate/Landmark", new PersonAddressCalculation()), "", new RDQACalculationResultConverter()); + dsd.addColumn("Village_Estate_Landmark", new CalculationDataDefinition("Village/Estate/Landmark", new PersonAddressCalculation()), "", new RDQACalculationResultConverter()); dsd.addColumn("Telephone Number", new CalculationDataDefinition("Telephone Number", new PersonAttributeCalculation("Telephone contact")), "", new RDQACalculationResultConverter()); - dsd.addColumn("BCG", new ObsForPersonDataDefinition("BCG", TimeQualifier.FIRST, Dictionary.getConcept(Dictionary.BACILLE_CAMILE_GUERIN_VACCINATION), null, null), "", new ObsDatetimeConverter()); - dsd.addColumn("Polio birth Dose", new CalculationDataDefinition("Polio birth Dose", new VaccinationDateCalculation(Dictionary.POLIO_VACCINATION_ORAL, 0)), "", new ObsDatetimeConverter()); - dsd.addColumn("OPV 1", new CalculationDataDefinition("OPV 1", new VaccinationDateCalculation(Dictionary.POLIO_VACCINATION_ORAL, 1)), "", new CustomDateConverter()); - dsd.addColumn("OPV 2", new CalculationDataDefinition("OPV 2", new VaccinationDateCalculation(Dictionary.POLIO_VACCINATION_ORAL, 2)), "", new CustomDateConverter()); - dsd.addColumn("OPV 3", new CalculationDataDefinition("OPV 3", new VaccinationDateCalculation(Dictionary.POLIO_VACCINATION_ORAL, 3)), "", new CustomDateConverter()); - dsd.addColumn("IPV", new ObsForPersonDataDefinition("IPV", TimeQualifier.FIRST, Dictionary.getConcept(Dictionary.POLIO_VACCINATION_INACTIVATED), null, null), "", new ObsDatetimeConverter()); - dsd.addColumn("DPT_HepB_Hib 1", new CalculationDataDefinition("DPT/Hep.B/Hib 1", new VaccinationDateCalculation(Dictionary.DIPHTHERIA_TETANUS_AND_PERTUSSIS_VACCINATION, 1)), "", new CustomDateConverter()); - dsd.addColumn("DPT_HepB_Hib 2", new CalculationDataDefinition("DPT/Hep.B/Hib 2", new VaccinationDateCalculation(Dictionary.DIPHTHERIA_TETANUS_AND_PERTUSSIS_VACCINATION, 2)), "", new CustomDateConverter()); - dsd.addColumn("DPT_HepB_Hib 3", new CalculationDataDefinition("DPT/Hep.B/Hib 3", new VaccinationDateCalculation(Dictionary.DIPHTHERIA_TETANUS_AND_PERTUSSIS_VACCINATION, 3)), "", new CustomDateConverter()); - dsd.addColumn("PCV 10(Pneumococcal) 1", new CalculationDataDefinition("PCV 10(Pneumococcal) 1", new VaccinationDateCalculation(Dictionary.PNEUMOCOCCAL_CONJUGATE_VACCINE, 1)), "", new CustomDateConverter()); - dsd.addColumn("PCV 10(Pneumococcal) 2", new CalculationDataDefinition("PCV 10(Pneumococcal) 2", new VaccinationDateCalculation(Dictionary.PNEUMOCOCCAL_CONJUGATE_VACCINE, 2)), "", new CustomDateConverter()); - dsd.addColumn("PCV 10(Pneumococcal) 3", new CalculationDataDefinition("PCV 10(Pneumococcal) 3", new VaccinationDateCalculation(Dictionary.PNEUMOCOCCAL_CONJUGATE_VACCINE, 3)), "", new CustomDateConverter()); - dsd.addColumn("ROTA 1", new CalculationDataDefinition("ROTA 1", new VaccinationDateCalculation(Dictionary.ROTA_VIRUS_VACCINE, 1)), "", new CustomDateConverter()); - dsd.addColumn("ROTA 2", new CalculationDataDefinition("ROTA 2", new VaccinationDateCalculation(Dictionary.ROTA_VIRUS_VACCINE, 2)), "", new CustomDateConverter()); + dsd.addColumn("BCG", new DateOfVaccineDataDefinition("BCG", "BCG"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("Polio birth Dose", new DateOfVaccineDataDefinition("Polio birth Dose", "OPV_birth"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("OPV 1", new DateOfVaccineDataDefinition("OPV 1", "OPV_1"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("OPV 2", new DateOfVaccineDataDefinition("OPV 2", "OPV_2"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("OPV 3", new DateOfVaccineDataDefinition("OPV 3", "OPV_3"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("IPV", new DateOfVaccineDataDefinition("IPV", "IPV"), "",new DateConverter(DATE_FORMAT)); + dsd.addColumn("DPT_HepB_Hib 1", new DateOfVaccineDataDefinition("DPT/Hep.B/Hib 1", "DPT_Hep_B_Hib_1"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("DPT_HepB_Hib 2", new DateOfVaccineDataDefinition("DPT/Hep.B/Hib 2", "DPT_Hep_B_Hib_2"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("DPT_HepB_Hib 3", new DateOfVaccineDataDefinition("DPT/Hep.B/Hib 3", "DPT_Hep_B_Hib_3"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("PCV 10(Pneumococcal) 1", new DateOfVaccineDataDefinition("PCV 10(Pneumococcal) 1", "PCV_10_1"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("PCV 10(Pneumococcal) 2", new DateOfVaccineDataDefinition("PCV 10(Pneumococcal) 2", "PCV_10_2"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("PCV 10(Pneumococcal) 3", new DateOfVaccineDataDefinition("PCV 10(Pneumococcal) 3", "PCV_10_3"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("ROTA 1", new DateOfVaccineDataDefinition("ROTA 1", "ROTA_1"), "", new DateConverter(DATE_FORMAT)); + dsd.addColumn("ROTA 2", new DateOfVaccineDataDefinition("ROTA 2", "ROTA_2"), "", new DateConverter(DATE_FORMAT)); dsd.addColumn("Vitamin A", new ObsForPersonDataDefinition("Vitamin A", TimeQualifier.LAST, Dictionary.getConcept(Dictionary.ADMINISTRATION_OF_VITAMIN_A), null, null), "", new ObsDatetimeConverter()); - dsd.addColumn("Measles 1", new CalculationDataDefinition("Measles 1", new VaccinationDateCalculation(Dictionary.MEASLES_RUBELLA_VACCINE, 1)), "", new CustomDateConverter()); + dsd.addColumn("Measles 1", new DateOfVaccineDataDefinition("Measles 1", "Measles_rubella_1"), "", new DateConverter(DATE_FORMAT)); dsd.addColumn("Yellow Fever", new ObsForPersonDataDefinition("Yellow Fever", TimeQualifier.FIRST, Dictionary.getConcept(Dictionary.YELLOW_FEVER_VACCINE), null, null), "", new ObsDatetimeConverter()); dsd.addColumn("Fully Immunized Child", new ObsForPersonDataDefinition("Fully Immunized Child", TimeQualifier.FIRST, Dictionary.getConcept(Dictionary.FULLY_IMMUNIZED_CHILD), null, null), "", new ConceptNamesDataConverter()); - dsd.addColumn("Measles 2", new CalculationDataDefinition("Measles 2", new VaccinationDateCalculation(Dictionary.MEASLES_RUBELLA_VACCINE, 2)), "", new CustomDateConverter()); - + dsd.addColumn("Measles 2", new DateOfVaccineDataDefinition("Measles 2", "Measles_rubella_2"), "", new DateConverter(DATE_FORMAT)); + Moh510CohortDefinition cd = new Moh510CohortDefinition(); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + + dsd.addRowFilter(cd, paramMapping); return dsd; } - @Override - protected Mapped buildCohort(HybridReportDescriptor descriptor, PatientDataSetDefinition dsd) { - - return childrenEnrolledInCWCCohort(); - } } diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/Moh510CohortDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/Moh510CohortDefinition.java new file mode 100644 index 0000000000..91261e463b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/Moh510CohortDefinition.java @@ -0,0 +1,42 @@ +/** + * 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.cohort.definition; + +import org.openmrs.Encounter; +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 org.openmrs.module.reporting.query.BaseQuery; +import org.openmrs.module.reporting.query.encounter.definition.EncounterQuery; + +import java.util.Date; + +/** + * MOH 510 cohort definition + */ +@Caching(strategy = ConfigurationPropertyCachingStrategy.class) +@Localized("reporting.moh510Cohort") +public class Moh510CohortDefinition extends BaseQuery implements EncounterQuery { + + @ConfigurationProperty + private Date asOfDate; + + public Moh510CohortDefinition() { + } + + public Date getAsOfDate() { + return asOfDate; + } + + public void setAsOfDate(Date asOfDate) { + this.asOfDate = asOfDate; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/Moh510CohortDefinitionEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/Moh510CohortDefinitionEvaluator.java new file mode 100644 index 0000000000..eba571f0a5 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/cohort/definition/evaluator/Moh510CohortDefinitionEvaluator.java @@ -0,0 +1,76 @@ +/** + * 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.cohort.definition.evaluator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemr.reporting.cohort.definition.HTSRegisterCohortDefinition; +import org.openmrs.module.kenyaemr.reporting.cohort.definition.Moh510CohortDefinition; +import org.openmrs.module.reporting.common.ObjectUtil; +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.openmrs.module.reporting.query.encounter.EncounterQueryResult; +import org.openmrs.module.reporting.query.encounter.definition.EncounterQuery; +import org.openmrs.module.reporting.query.encounter.evaluator.EncounterQueryEvaluator; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.List; + +/** + * Evaluator for patients for HTS Register + */ +@Handler(supports = {Moh510CohortDefinition.class}) +public class Moh510CohortDefinitionEvaluator implements EncounterQueryEvaluator { + + private final Log log = LogFactory.getLog(this.getClass()); + @Autowired + EvaluationService evaluationService; + + public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContext context) throws EvaluationException { + context = ObjectUtil.nvl(context, new EvaluationContext()); + EncounterQueryResult queryResult = new EncounterQueryResult(definition, context); + + String qry = "select encounter_id from kenyaemr_etl.etl_hei_immunization \n" + + "where \n" + + "\tvisit_date between :startDate and :endDate OR \n" + + "\tBCG between :startDate and :endDate OR \n" + + "\tOPV_birth between :startDate and :endDate OR \n" + + "\tOPV_1 between :startDate and :endDate OR \n" + + "\tOPV_2 between :startDate and :endDate OR \n" + + "\tOPV_3 between :startDate and :endDate OR \n" + + "\tIPV between :startDate and :endDate OR \n" + + "\tDPT_Hep_B_Hib_1 between :startDate and :endDate OR \n" + + "\tDPT_Hep_B_Hib_2 between :startDate and :endDate OR \n" + + "\tDPT_Hep_B_Hib_3 between :startDate and :endDate OR \n" + + "\tPCV_10_1 between :startDate and :endDate OR \n" + + "\tPCV_10_2 between :startDate and :endDate OR \n" + + "\tPCV_10_3 between :startDate and :endDate OR \n" + + "\tROTA_1 between :startDate and :endDate OR \n" + + "\tROTA_2 between :startDate and :endDate OR \n" + + "\tMeasles_rubella_1 between :startDate and :endDate OR \n" + + "\tMeasles_rubella_2 between :startDate and :endDate ; "; + + SqlQueryBuilder builder = new SqlQueryBuilder(); + builder.append(qry); + Date startDate = (Date)context.getParameterValue("startDate"); + Date endDate = (Date)context.getParameterValue("endDate"); + builder.addParameter("endDate", endDate); + builder.addParameter("startDate", startDate); + + List results = evaluationService.evaluateToList(builder, Integer.class, context); + queryResult.getMemberIds().addAll(results); + return queryResult; + } + +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/cwc/DateOfVaccineDataDefinition.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/cwc/DateOfVaccineDataDefinition.java new file mode 100644 index 0000000000..fb81b152a3 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/cwc/DateOfVaccineDataDefinition.java @@ -0,0 +1,68 @@ +/** + * 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.cwc; + +import org.openmrs.module.reporting.data.BaseDataDefinition; +import org.openmrs.module.reporting.data.encounter.definition.EncounterDataDefinition; +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; + +/** + * Visit ID Column + */ +@Caching(strategy=ConfigurationPropertyCachingStrategy.class) +public class DateOfVaccineDataDefinition extends BaseDataDefinition implements EncounterDataDefinition { + + public static final long serialVersionUID = 1L; + + @ConfigurationProperty + private String vaccineTableColumn; + + /** + * Default Constructor + */ + public DateOfVaccineDataDefinition() { + super(); + } + + /** + * Constructor to populate name only + */ + public DateOfVaccineDataDefinition(String name) { + + super(name); + } + + //***** INSTANCE METHODS ***** + + + public String getVaccineTableColumn() { + return vaccineTableColumn; + } + + public void setVaccineTableColumn(String vaccineTableColumn) { + this.vaccineTableColumn = vaccineTableColumn; + } + + public DateOfVaccineDataDefinition(String name, String vaccineTableColumn) { + super(name); + this.vaccineTableColumn = vaccineTableColumn; + } + + /** + * @see org.openmrs.module.reporting.data.DataDefinition#getDataType() + */ + public Class getDataType() { + return Date.class; + } +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/cwc/DateOfVaccineDataEvaluator.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/cwc/DateOfVaccineDataEvaluator.java new file mode 100644 index 0000000000..403196f665 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/data/converter/definition/evaluator/cwc/DateOfVaccineDataEvaluator.java @@ -0,0 +1,51 @@ +/** + * 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.cwc; + +import org.openmrs.annotation.Handler; +import org.openmrs.module.kenyaemr.reporting.data.converter.definition.cwc.DateOfVaccineDataDefinition; +import org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData; +import org.openmrs.module.reporting.data.encounter.definition.EncounterDataDefinition; +import org.openmrs.module.reporting.data.encounter.evaluator.EncounterDataEvaluator; +import org.openmrs.module.reporting.evaluation.EvaluationContext; +import org.openmrs.module.reporting.evaluation.EvaluationException; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +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 a VisitIdDataDefinition to produce a VisitData + */ +@Handler(supports=DateOfVaccineDataDefinition.class, order=50) +public class DateOfVaccineDataEvaluator implements EncounterDataEvaluator { + + @Autowired + private EvaluationService evaluationService; + + public EvaluatedEncounterData evaluate(EncounterDataDefinition definition, EvaluationContext context) throws EvaluationException { + EvaluatedEncounterData c = new EvaluatedEncounterData(definition, context); + DateOfVaccineDataDefinition def = (DateOfVaccineDataDefinition) definition; + + String tableColumn = def.getVaccineTableColumn(); + + String qry = "select encounter_id, (CASE WHEN :vaccineColumn != '' THEN STR_TO_DATE(:vaccineColumn, '%Y-%m-%d') ELSE NULL END) from kenyaemr_etl.etl_hei_immunization "; + + qry = qry.replaceAll(":vaccineColumn", tableColumn); + SqlQueryBuilder queryBuilder = new SqlQueryBuilder(); + 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/content/kenyaemr.mchcs.xml b/api/src/main/resources/content/kenyaemr.mchcs.xml index 7c85e61a37..abb1c78886 100755 --- a/api/src/main/resources/content/kenyaemr.mchcs.xml +++ b/api/src/main/resources/content/kenyaemr.mchcs.xml @@ -43,6 +43,7 @@ +