From b087c998c34667ed2d7813f022dab676cdbe9459 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Mon, 22 Dec 2025 19:09:55 +0530 Subject: [PATCH 01/15] C2C-434: Show list of patients in MSPP Family planning report --- .../commonreports/CommonReportsConstants.java | 2 + .../MSPPFamilyPlanningReportManager.java | 279 ++++++++++++------ 2 files changed, 198 insertions(+), 83 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java b/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java index f8d6331a..c3c7cc54 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java +++ b/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java @@ -37,6 +37,8 @@ public class CommonReportsConstants { public static final String COMPONENT_REPORTMANAGER_VACCINATION = MODULE_ARTIFACT_ID + ".vaccination"; + public static final String COMPONENT_REPORTMANAGER_FAMILYPLANNING = MODULE_ARTIFACT_ID + ".familyPlanning"; + /* * URIs URLs */ diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java index 7065a839..b25fdba6 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java @@ -1,29 +1,29 @@ package org.openmrs.module.commonreports.reports; -import static org.openmrs.module.commonreports.common.Helper.getStringFromResource; - -import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.apache.commons.io.IOUtils; + import org.openmrs.module.commonreports.ActivatedReportManager; +import org.openmrs.module.commonreports.CommonReportsConstants; import org.openmrs.module.initializer.api.InitializerService; import org.openmrs.module.reporting.common.MessageUtil; -import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition; +import org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition; +import org.openmrs.module.reporting.cohort.definition.GenderCohortDefinition; +import org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition; +import org.openmrs.module.reporting.dataset.definition.CohortCrossTabDataSetDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Mapped; import org.openmrs.module.reporting.evaluation.parameter.Parameter; import org.openmrs.module.reporting.report.ReportDesign; import org.openmrs.module.reporting.report.definition.ReportDefinition; import org.openmrs.module.reporting.report.manager.ReportManagerUtil; -import org.openmrs.util.OpenmrsClassLoader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -@Component +@Component(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILYPLANNING) public class MSPPFamilyPlanningReportManager extends ActivatedReportManager { @Autowired @@ -74,95 +74,208 @@ public List getParameters() { public ReportDefinition constructReportDefinition() { ReportDefinition rd = new ReportDefinition(); - + rd.setUuid(getUuid()); rd.setName(getName()); rd.setDescription(getDescription()); rd.setParameters(getParameters()); - rd.setUuid(getUuid()); - SqlDataSetDefinition sqlDsd = new SqlDataSetDefinition(); - sqlDsd.setName(MessageUtil.translate("commonreports.report.MSPP.familyPlanning.datasetName")); - sqlDsd.setDescription(MessageUtil.translate("commonreports.report.MSPP.familyPlanning.datasetDescription")); + CohortCrossTabDataSetDefinition familyPlanning = new CohortCrossTabDataSetDefinition(); + familyPlanning.addParameters(getParameters()); + rd.addDataSetDefinition(getName(), Mapped.mapStraightThrough(familyPlanning)); + + Map parameterMappings = new HashMap(); + parameterMappings.put("onOrAfter", "${startDate}"); + parameterMappings.put("onOrBefore", "${endDate}"); - String rawSql = getStringFromResource("org/openmrs/module/commonreports/sql/MSPPfamilyPlanning.sql"); - String sql = applyMetadataReplacements(rawSql); + // Define concept IDs + int fpAdministredConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.FPAdministred") + .getConceptId(); + int familyPlanningConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.familyPlanning") + .getConceptId(); + int typeOfUserConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.typeOfUser").getConceptId(); + int newConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.new").getConceptId(); + int existentConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.existent").getConceptId(); + int microgynonConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.microgynon").getConceptId(); + int microlutConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.microlut").getConceptId(); + int depoProveraInjectionConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.depoProveraInjection") + .getConceptId(); + int jadelConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.jadel").getConceptId(); + int condomConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.condom").getConceptId(); - sqlDsd.setSqlQuery(sql); - sqlDsd.addParameters(getParameters()); + // Add rows for each method and user type combination + // Microgynon - New Users + familyPlanning.addRow("Microgynon - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 1), + parameterMappings); + familyPlanning.addRow("Microgynon - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 1), + parameterMappings); + familyPlanning.addRow("Microgynon - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 1), + parameterMappings); + familyPlanning.addRow("Microgynon - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 1), + parameterMappings); - Map parameterMappings = new HashMap(); - parameterMappings.put("startDate", "${startDate}"); - parameterMappings.put("endDate", "${endDate}"); + // Microlut - New Users + familyPlanning.addRow("Microlut - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 1), + parameterMappings); + familyPlanning.addRow("Microlut - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 1), + parameterMappings); + familyPlanning + .addRow( + "Microlut - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, microlutConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 1), + parameterMappings); + familyPlanning.addRow("Microlut - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 1), + parameterMappings); + + // Depo Provera - New Users (3 months interval) + familyPlanning.addRow("Depo Provera - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 3), + parameterMappings); + familyPlanning.addRow( + "Depo Provera - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 3), + parameterMappings); + familyPlanning + .addRow("Depo Provera - Existent - Female <25", + createFamilyPlanningCohort(fpAdministredConceptId, depoProveraInjectionConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 3), + parameterMappings); + familyPlanning + .addRow("Depo Provera - Existent - Female >=25", + createFamilyPlanningCohort(fpAdministredConceptId, depoProveraInjectionConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 3), + parameterMappings); + + // Jadel - New Users (5 years interval) + familyPlanning.addRow("Jadel - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 60), parameterMappings); + familyPlanning.addRow("Jadel - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 60), parameterMappings); + familyPlanning + .addRow( + "Jadel - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 60), + parameterMappings); + familyPlanning + .addRow( + "Jadel - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 60), + parameterMappings); + + // Condom - New Users (no interval) + familyPlanning.addRow("Condom - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + condomConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 0), + parameterMappings); + familyPlanning.addRow("Condom - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + condomConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 0), + parameterMappings); + familyPlanning + .addRow( + "Condom - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 0), + parameterMappings); + familyPlanning + .addRow( + "Condom - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 0), + parameterMappings); + + // Condom - Males + familyPlanning.addRow("Condom - New - Male <25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "M", 25, false, 0), parameterMappings); + familyPlanning.addRow("Condom - New - Male >=25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "M", 25, true, 0), parameterMappings); + familyPlanning + .addRow( + "Condom - Existent - Male <25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "M", 25, false, 0), + parameterMappings); + familyPlanning + .addRow( + "Condom - Existent - Male >=25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "M", 25, true, 0), + parameterMappings); - rd.addDataSetDefinition(getName(), sqlDsd, parameterMappings); + // Add a single column for "Total" (all patients) + GenderCohortDefinition allGender = new GenderCohortDefinition(); + allGender.setMaleIncluded(true); + allGender.setFemaleIncluded(true); + familyPlanning.addColumn("Total", createCohortComposition(allGender), null); return rd; } - @Override - public List constructReportDesigns(ReportDefinition reportDefinition) { - ReportDesign reportDesign = ReportManagerUtil.createExcelTemplateDesign("c51fc24f-50ba-48f8-9678-90462f7cff80", - reportDefinition, "org/openmrs/module/commonreports/reportTemplates/familyPlanningReportTemplate.xls"); - - Properties designProperties = new Properties(); - - designProperties.put("newUser.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.newUser.label")); - designProperties.put("existentUser.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.existentUser.label")); - designProperties.put("LT25years.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.LT25years.label")); - designProperties.put("GT25years.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.GT25years.label")); - designProperties.put("method.label", MessageUtil.translate("commonreports.report.MSPP.familyPlanning.method.label")); - designProperties.put("females.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.females.label")); - designProperties.put("males.label", MessageUtil.translate("commonreports.report.MSPP.familyPlanning.males.label")); - designProperties.put("PC.label", MessageUtil.translate("commonreports.report.MSPP.familyPlanning.PC.label")); - designProperties.put("PP.label", MessageUtil.translate("commonreports.report.MSPP.familyPlanning.PP.label")); - designProperties.put("depo.label", MessageUtil.translate("commonreports.report.MSPP.familyPlanning.depo.label")); - designProperties.put("implant.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.implant.label")); - designProperties.put("condoms.label", - MessageUtil.translate("commonreports.report.MSPP.familyPlanning.condoms.label")); - designProperties.put("total.label", MessageUtil.translate("commonreports.report.MSPP.familyPlanning.total.label")); - - reportDesign.setProperties(designProperties); - return Arrays.asList(reportDesign); + /** + * Creates a SqlCohortDefinition for family planning based on the provided parameters + * + * @param fpAdministredConceptId The concept ID for FP Administered + * @param methodConceptId The concept ID for the method (microgynon, microlut, etc.) + * @param familyPlanningConceptId The concept ID for family planning + * @param typeOfUserConceptId The concept ID for type of user + * @param userTypeConceptId The concept ID for new or existent user + * @param gender Gender filter: "F" for female, "M" for male + * @param ageThreshold Age threshold (e.g., 25) + * @param ageGreaterOrEqual true for >= ageThreshold, false for < ageThreshold + * @param intervalMonths Number of months to subtract from startDate (0 for no interval, 1 for 1 + * month, 3 for 3 months, 60 for 5 years) + * @return SqlCohortDefinition + */ + private SqlCohortDefinition createFamilyPlanningCohort(int fpAdministredConceptId, int methodConceptId, + int familyPlanningConceptId, int typeOfUserConceptId, int userTypeConceptId, String gender, int ageThreshold, + boolean ageGreaterOrEqual, int intervalMonths) { + + String intervalClause = ""; + if (intervalMonths > 0) { + if (intervalMonths == 60) { + intervalClause = "DATE_SUB(:onOrAfter, INTERVAL 5 YEAR)"; + } else { + intervalClause = "DATE_SUB(:onOrAfter, INTERVAL " + intervalMonths + " MONTH)"; + } + } else { + intervalClause = ":onOrAfter"; + } + + String ageCondition; + if (ageGreaterOrEqual) { + ageCondition = "round(DATEDIFF(obs.obs_datetime, p.birthdate)/365.25, 1) >= " + ageThreshold; + } else { + ageCondition = "round(DATEDIFF(obs.obs_datetime, p.birthdate)/365.25, 1) < " + ageThreshold; + } + + String sql = "SELECT DISTINCT obs.person_id " + "FROM obs " + + "INNER JOIN person ON obs.person_id = person.person_id " + "WHERE obs.voided = 0 " + + "AND obs.concept_id = " + fpAdministredConceptId + " " + "AND obs.value_coded = " + methodConceptId + " " + + "AND obs.obs_group_id IN (" + " SELECT obs_group_id FROM obs " + + " INNER JOIN person p ON obs.person_id = p.person_id " + " WHERE obs.voided = 0 " + + " AND obs.obs_group_id IN (" + " SELECT obs_id FROM obs " + " WHERE obs_datetime >= " + + intervalClause + " " + " AND obs_datetime <= :onOrBefore " + " AND concept_id = " + + familyPlanningConceptId + " ) " + " AND p.gender = '" + gender + "' " + " AND " + ageCondition + " " + + " AND obs.concept_id = " + typeOfUserConceptId + " " + " AND obs.value_coded = " + userTypeConceptId + + ")"; + + SqlCohortDefinition cohort = new SqlCohortDefinition(sql); + cohort.addParameter(new Parameter("onOrAfter", "On Or After", Date.class)); + cohort.addParameter(new Parameter("onOrBefore", "On Or Before", Date.class)); + + return cohort; + } + + private CompositionCohortDefinition createCohortComposition(Object... elements) { + CompositionCohortDefinition compCD = new CompositionCohortDefinition(); + compCD.initializeFromElements(elements); + return compCD; } - private String applyMetadataReplacements(String rawSql) { - String s = rawSql - .replace(":FPAdministred", - inizService.getConceptFromKey("report.MSPP.familyPlanning.FPAdministred").getConceptId() + "") - .replace(":familyPlanning", - inizService.getConceptFromKey("report.MSPP.familyPlanning.familyPlanning").getConceptId() + "") - .replace(":femaleLT25", - "person.gender = 'F' AND round(DATEDIFF(obs.obs_datetime, person.birthdate)/365.25, 1) < 25") - .replace(":femaleGT25", - "person.gender = 'F' AND round(DATEDIFF(obs.obs_datetime, person.birthdate)/365.25, 1) >= 25") - .replace(":maleLT25", - "person.gender = 'M' AND round(DATEDIFF(obs.obs_datetime, person.birthdate)/365.25, 1) < 25") - .replace(":maleGT25", - "person.gender = 'M' AND round(DATEDIFF(obs.obs_datetime, person.birthdate)/365.25, 1) >= 25") - - .replace(":typeOfUser", - inizService.getConceptFromKey("report.MSPP.familyPlanning.typeOfUser").getConceptId() + "") - .replace(":new", inizService.getConceptFromKey("report.MSPP.familyPlanning.new").getConceptId() + "") - .replace(":existent", - inizService.getConceptFromKey("report.MSPP.familyPlanning.existent").getConceptId() + "") - - .replace(":microgynon", - inizService.getConceptFromKey("report.MSPP.familyPlanning.microgynon").getConceptId() + "") - - .replace(":microlut", - inizService.getConceptFromKey("report.MSPP.familyPlanning.microlut").getConceptId() + "") - - .replace(":depoProveraInjection", - inizService.getConceptFromKey("report.MSPP.familyPlanning.depoProveraInjection").getConceptId() + "") - .replace(":jadel", inizService.getConceptFromKey("report.MSPP.familyPlanning.jadel").getConceptId() + "") - .replace(":condom", inizService.getConceptFromKey("report.MSPP.familyPlanning.condom").getConceptId() + ""); - return s; + @Override + public List constructReportDesigns(ReportDefinition reportDefinition) { + return Arrays + .asList(ReportManagerUtil.createCsvReportDesign("a0ebe3c1-d6a3-4761-bff0-6a03626d2c75", reportDefinition)); } } From b421f05b7363e1667fd59211bf70fcd2cd8f45b6 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Tue, 23 Dec 2025 16:08:29 +0530 Subject: [PATCH 02/15] Fix query and labels --- .../MSPPFamilyPlanningReportManager.java | 134 ++++++++---------- 1 file changed, 57 insertions(+), 77 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java index b25fdba6..02c1973a 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java @@ -86,8 +86,7 @@ public ReportDefinition constructReportDefinition() { Map parameterMappings = new HashMap(); parameterMappings.put("onOrAfter", "${startDate}"); parameterMappings.put("onOrBefore", "${endDate}"); - - // Define concept IDs + int fpAdministredConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.FPAdministred") .getConceptId(); int familyPlanningConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.familyPlanning") @@ -104,103 +103,86 @@ public ReportDefinition constructReportDefinition() { // Add rows for each method and user type combination // Microgynon - New Users - familyPlanning.addRow("Microgynon - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + familyPlanning.addRow("newMycogynonFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 1), parameterMappings); - familyPlanning.addRow("Microgynon - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, + familyPlanning.addRow("newMycogynonFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 1), parameterMappings); - familyPlanning.addRow("Microgynon - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, - microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 1), - parameterMappings); - familyPlanning.addRow("Microgynon - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, - microgynonConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 1), - parameterMappings); + familyPlanning + .addRow( + "existentMycogynonFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, microgynonConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 1), + parameterMappings); + familyPlanning + .addRow( + "existentMycogynonFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, microgynonConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 1), + parameterMappings); // Microlut - New Users - familyPlanning.addRow("Microlut - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, - microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 1), - parameterMappings); - familyPlanning.addRow("Microlut - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, - microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 1), - parameterMappings); + familyPlanning.addRow("newMicrolutFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, microlutConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 1), parameterMappings); + familyPlanning.addRow("newMicrolutFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, microlutConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 1), parameterMappings); familyPlanning .addRow( - "Microlut - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, microlutConceptId, + "existentMicrolutFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 1), parameterMappings); - familyPlanning.addRow("Microlut - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, - microlutConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 1), - parameterMappings); + familyPlanning + .addRow( + "existentMicrolutFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, microlutConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 1), + parameterMappings); // Depo Provera - New Users (3 months interval) - familyPlanning.addRow("Depo Provera - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, + familyPlanning.addRow("newDepoFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 3), parameterMappings); - familyPlanning.addRow( - "Depo Provera - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, - depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 3), + familyPlanning.addRow("newDepoFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, + depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 3), parameterMappings); familyPlanning - .addRow("Depo Provera - Existent - Female <25", + .addRow("existentDepoFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 3), parameterMappings); familyPlanning - .addRow("Depo Provera - Existent - Female >=25", + .addRow("existentDepoFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, depoProveraInjectionConceptId, familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 3), parameterMappings); // Jadel - New Users (5 years interval) - familyPlanning.addRow("Jadel - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanning.addRow("newJadelFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 60), parameterMappings); - familyPlanning.addRow("Jadel - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanning.addRow("newJadelFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 60), parameterMappings); - familyPlanning - .addRow( - "Jadel - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, - familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 60), - parameterMappings); - familyPlanning - .addRow( - "Jadel - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, - familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 60), - parameterMappings); + familyPlanning.addRow("existentJadelFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 60), parameterMappings); + familyPlanning.addRow("existentJadelFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, jadelConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 60), parameterMappings); // Condom - New Users (no interval) - familyPlanning.addRow("Condom - New - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, - condomConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 0), - parameterMappings); - familyPlanning.addRow("Condom - New - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, - condomConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 0), - parameterMappings); - familyPlanning - .addRow( - "Condom - Existent - Female <25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, - familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 0), - parameterMappings); - familyPlanning - .addRow( - "Condom - Existent - Female >=25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, - familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 0), - parameterMappings); + familyPlanning.addRow("newCondomFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, false, 0), parameterMappings); + familyPlanning.addRow("newCondomFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, newConceptId, "F", 25, true, 0), parameterMappings); + familyPlanning.addRow("existentCondomFemaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, false, 0), parameterMappings); + familyPlanning.addRow("existentCondomFemaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "F", 25, true, 0), parameterMappings); // Condom - Males - familyPlanning.addRow("Condom - New - Male <25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanning.addRow("newCondomMaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "M", 25, false, 0), parameterMappings); - familyPlanning.addRow("Condom - New - Male >=25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanning.addRow("newCondomMaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, familyPlanningConceptId, typeOfUserConceptId, newConceptId, "M", 25, true, 0), parameterMappings); - familyPlanning - .addRow( - "Condom - Existent - Male <25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, - familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "M", 25, false, 0), - parameterMappings); - familyPlanning - .addRow( - "Condom - Existent - Male >=25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, - familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "M", 25, true, 0), - parameterMappings); + familyPlanning.addRow("existentCondomMaleLT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "M", 25, false, 0), parameterMappings); + familyPlanning.addRow("existentCondomMaleGT25", createFamilyPlanningCohort(fpAdministredConceptId, condomConceptId, + familyPlanningConceptId, typeOfUserConceptId, existentConceptId, "M", 25, true, 0), parameterMappings); // Add a single column for "Total" (all patients) GenderCohortDefinition allGender = new GenderCohortDefinition(); @@ -243,21 +225,19 @@ private SqlCohortDefinition createFamilyPlanningCohort(int fpAdministredConceptI String ageCondition; if (ageGreaterOrEqual) { - ageCondition = "round(DATEDIFF(obs.obs_datetime, p.birthdate)/365.25, 1) >= " + ageThreshold; + ageCondition = "round(DATEDIFF(obs.obs_datetime, person.birthdate)/365.25, 1) >= " + ageThreshold; } else { - ageCondition = "round(DATEDIFF(obs.obs_datetime, p.birthdate)/365.25, 1) < " + ageThreshold; + ageCondition = "round(DATEDIFF(obs.obs_datetime, person.birthdate)/365.25, 1) < " + ageThreshold; } String sql = "SELECT DISTINCT obs.person_id " + "FROM obs " + "INNER JOIN person ON obs.person_id = person.person_id " + "WHERE obs.voided = 0 " - + "AND obs.concept_id = " + fpAdministredConceptId + " " + "AND obs.value_coded = " + methodConceptId + " " - + "AND obs.obs_group_id IN (" + " SELECT obs_group_id FROM obs " - + " INNER JOIN person p ON obs.person_id = p.person_id " + " WHERE obs.voided = 0 " - + " AND obs.obs_group_id IN (" + " SELECT obs_id FROM obs " + " WHERE obs_datetime >= " - + intervalClause + " " + " AND obs_datetime <= :onOrBefore " + " AND concept_id = " - + familyPlanningConceptId + " ) " + " AND p.gender = '" + gender + "' " + " AND " + ageCondition + " " - + " AND obs.concept_id = " + typeOfUserConceptId + " " + " AND obs.value_coded = " + userTypeConceptId - + ")"; + + "AND obs.concept_id = " + fpAdministredConceptId + " AND obs.value_coded = " + methodConceptId + " " + + "AND obs.obs_group_id IN (" + " SELECT obs_group_id FROM obs WHERE " + "obs.obs_group_id IN (" + + " SELECT obs_id FROM obs " + "WHERE obs_datetime >= " + intervalClause + + " AND obs_datetime <= :onOrBefore " + "AND concept_id = " + familyPlanningConceptId + + " ) AND person.gender = '" + gender + "' " + "AND " + ageCondition + " AND obs.concept_id = " + + typeOfUserConceptId + " AND obs.value_coded = " + userTypeConceptId + ")"; SqlCohortDefinition cohort = new SqlCohortDefinition(sql); cohort.addParameter(new Parameter("onOrAfter", "On Or After", Date.class)); @@ -275,7 +255,7 @@ private CompositionCohortDefinition createCohortComposition(Object... elements) @Override public List constructReportDesigns(ReportDefinition reportDefinition) { return Arrays - .asList(ReportManagerUtil.createCsvReportDesign("a0ebe3c1-d6a3-4761-bff0-6a03626d2c75", reportDefinition)); + .asList(ReportManagerUtil.createCsvReportDesign("8e300676-75d7-48f8-82eb-4fe9971459fe", reportDefinition)); } } From 1e26c73ae6f499279cafc2d7bfafa540f5ca15a4 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Tue, 23 Dec 2025 18:33:39 +0530 Subject: [PATCH 03/15] Add unit tests --- .../commonreports/sql/MSPPfamilyPlanning.sql | 34 ------ .../MSPPFamilyPlanningReportManagerTest.java | 102 +++++++++++++++--- 2 files changed, 90 insertions(+), 46 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/module/commonreports/sql/MSPPfamilyPlanning.sql diff --git a/api/src/main/resources/org/openmrs/module/commonreports/sql/MSPPfamilyPlanning.sql b/api/src/main/resources/org/openmrs/module/commonreports/sql/MSPPfamilyPlanning.sql deleted file mode 100644 index e08205b5..00000000 --- a/api/src/main/resources/org/openmrs/module/commonreports/sql/MSPPfamilyPlanning.sql +++ /dev/null @@ -1,34 +0,0 @@ -SELECT -count(if( concept_id=:FPAdministred && value_coded=:microgynon && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newMycogynonFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:microgynon && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newMycogynonFemaleGT25, -count(if( concept_id=:FPAdministred && value_coded=:microgynon && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentMycogynonFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:microgynon && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentMycogynonFemaleGT25, - -count(if( concept_id=:FPAdministred && value_coded=:microlut && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newMicrolutFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:microlut && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newMicrolutFemaleGT25, -count(if( concept_id=:FPAdministred && value_coded=:microlut && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentMicrolutFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:microlut && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 1 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentMicrolutFemaleGT25, - -count(if( concept_id=:FPAdministred && value_coded=:depoProveraInjection && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 3 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newDepoFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:depoProveraInjection && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 3 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newDepoFemaleGT25, -count(if( concept_id=:FPAdministred && value_coded=:depoProveraInjection && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 3 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentDepoFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:depoProveraInjection && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 3 MONTH) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentDepoFemaleGT25, - -count(if( concept_id=:FPAdministred && value_coded=:jadel && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 5 YEAR) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newJadelFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:jadel && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 5 YEAR) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newJadelFemaleGT25, -count(if( concept_id=:FPAdministred && value_coded=:jadel && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 5 YEAR) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentJadelFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:jadel && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= DATE_SUB(:startDate, INTERVAL 5 YEAR) AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentJadelFemaleGT25, - -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newCondomFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newCondomFemaleGT25, -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleLT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentCondomFemaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :femaleGT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentCondomFemaleGT25, - -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :maleLT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newCondomMaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :maleGT25 AND concept_id=:typeOfUser AND value_coded=:new) ,1,null)) as newCondomMaleGT25, -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :maleLT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentCondomMaleLT25, -count(if( concept_id=:FPAdministred && value_coded=:condom && obs_group_id IN (select obs_group_id from obs where obs_group_id IN (SELECT obs_id FROM obs where obs_datetime >= :startDate AND obs_datetime <= :endDate AND concept_id=:familyPlanning) AND :maleGT25 AND concept_id=:typeOfUser AND value_coded=:existent) ,1,null)) as existentCondomMaleGT25 -from obs inner join person ON obs.person_id=person.person_id where obs.voided = 0 ; - - - diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index c77fe9f3..d079a83c 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -3,7 +3,9 @@ import java.io.File; import java.sql.Connection; import java.sql.SQLException; +import java.util.Date; import java.util.Iterator; +import java.util.List; import org.dbunit.DatabaseUnitException; import org.dbunit.DatabaseUnitRuntimeException; import org.dbunit.database.DatabaseConfig; @@ -12,18 +14,17 @@ import org.dbunit.dataset.IDataSet; import org.dbunit.ext.mysql.MySqlDataTypeFactory; import org.dbunit.operation.DatabaseOperation; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openmrs.api.ConceptService; -import org.openmrs.module.commonreports.reports.BaseModuleContextSensitiveMysqlBackedTest; -import org.openmrs.module.commonreports.reports.MSPPFamilyPlanningReportManager; import org.openmrs.module.initializer.Domain; import org.openmrs.module.initializer.api.InitializerService; import org.openmrs.module.initializer.api.loaders.Loader; import org.openmrs.module.reporting.common.DateUtil; import org.openmrs.module.reporting.dataset.DataSetRow; +import org.openmrs.module.reporting.dataset.definition.CohortCrossTabDataSetDefinition; import org.openmrs.module.reporting.evaluation.EvaluationContext; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; import org.openmrs.module.reporting.report.ReportData; import org.openmrs.module.reporting.report.ReportDesign; import org.openmrs.module.reporting.report.definition.ReportDefinition; @@ -39,6 +40,8 @@ import liquibase.resource.ClassLoaderResourceAccessor; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveMysqlBackedTest { @@ -100,23 +103,35 @@ public void setUp() throws Exception { } @Test - public void setupReport_shouldCreateExcelTemplateDesign() throws Exception { - // setup + public void constructReportDesigns_shouldCreateCsvReportDesign() { + // replay + ReportDefinition rd = manager.constructReportDefinition(); + List designs = manager.constructReportDesigns(rd); + + // verify + assertNotNull("Report designs should not be null", designs); + assertEquals("Should have 1 report design", 1, designs.size()); + ReportDesign design = designs.get(0); + assertEquals("8e300676-75d7-48f8-82eb-4fe9971459fe", design.getUuid()); + assertEquals(rd, design.getReportDefinition()); + } + + @Test + public void setupReport_shouldCreateCsvReportDesign() throws Exception { // replay ReportManagerUtil.setupReport(manager); - // verif - ReportDesign design = rs.getReportDesignByUuid("c51fc24f-50ba-48f8-9678-90462f7cff80"); - - Assert.assertEquals(1, design.getResources().size()); + // verify + ReportDesign design = rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe"); + assertNotNull("Report design should exist", design); ReportDefinition def = design.getReportDefinition(); - Assert.assertEquals("efd7ba26-7888-45a8-9184-423833ab79d3", def.getUuid()); + assertEquals("efd7ba26-7888-45a8-9184-423833ab79d3", def.getUuid()); } @Test - public void testReport() throws Exception { + public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { // setup EvaluationContext context = new EvaluationContext(); context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); @@ -127,28 +142,91 @@ public void testReport() throws Exception { ReportData data = rds.evaluate(rd, context); // verify + assertNotNull("Report data should not be null", data); + assertTrue("Should have data sets", data.getDataSets().size() > 0); + for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { DataSetRow row = itr.next(); + + // Verify Microlut data assertEquals(new Long(1), row.getColumnValue("existentMicrolutFemaleLT25")); assertEquals(new Long(0), row.getColumnValue("existentMicrolutFemaleGT25")); - assertEquals(new Long(1), row.getColumnValue("newMicrolutFemaleLT25")); assertEquals(new Long(0), row.getColumnValue("newMicrolutFemaleGT25")); + // Verify Jadel data assertEquals(new Long(1), row.getColumnValue("newJadelFemaleLT25")); assertEquals(new Long(0), row.getColumnValue("newJadelFemaleGT25")); + // Verify Depo Provera data assertEquals(new Long(1), row.getColumnValue("existentDepoFemaleGT25")); assertEquals(new Long(0), row.getColumnValue("existentDepoFemaleLT25")); + // Verify Condom Female data assertEquals(new Long(1), row.getColumnValue("newCondomFemaleGT25")); assertEquals(new Long(0), row.getColumnValue("newCondomFemaleLT25")); + // Verify Condom Male data assertEquals(new Long(1), row.getColumnValue("newCondomMaleGT25")); assertEquals(new Long(0), row.getColumnValue("newCondomMaleLT25")); + // Verify Total column exists + assertNotNull("Total column should exist", row.getColumnValue("Total")); } + } + + + @Test + public void testReport_shouldIncludeAllMethodRows() throws Exception { + // setup + EvaluationContext context = new EvaluationContext(); + context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); + context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); + // replay + ReportDefinition rd = manager.constructReportDefinition(); + ReportData data = rds.evaluate(rd, context); + + // verify - check that all method rows are present in the results + for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { + DataSetRow row = itr.next(); + + // Verify Microgynon rows exist + assertNotNull("newMycogynonFemaleLT25 should exist", row.getColumnValue("newMycogynonFemaleLT25")); + assertNotNull("newMycogynonFemaleGT25 should exist", row.getColumnValue("newMycogynonFemaleGT25")); + assertNotNull("existentMycogynonFemaleLT25 should exist", row.getColumnValue("existentMycogynonFemaleLT25")); + assertNotNull("existentMycogynonFemaleGT25 should exist", row.getColumnValue("existentMycogynonFemaleGT25")); + + // Verify Microlut rows exist + assertNotNull("newMicrolutFemaleLT25 should exist", row.getColumnValue("newMicrolutFemaleLT25")); + assertNotNull("newMicrolutFemaleGT25 should exist", row.getColumnValue("newMicrolutFemaleGT25")); + assertNotNull("existentMicrolutFemaleLT25 should exist", row.getColumnValue("existentMicrolutFemaleLT25")); + assertNotNull("existentMicrolutFemaleGT25 should exist", row.getColumnValue("existentMicrolutFemaleGT25")); + + // Verify Depo Provera rows exist + assertNotNull("newDepoFemaleLT25 should exist", row.getColumnValue("newDepoFemaleLT25")); + assertNotNull("newDepoFemaleGT25 should exist", row.getColumnValue("newDepoFemaleGT25")); + assertNotNull("existentDepoFemaleLT25 should exist", row.getColumnValue("existentDepoFemaleLT25")); + assertNotNull("existentDepoFemaleGT25 should exist", row.getColumnValue("existentDepoFemaleGT25")); + + // Verify Jadel rows exist + assertNotNull("newJadelFemaleLT25 should exist", row.getColumnValue("newJadelFemaleLT25")); + assertNotNull("newJadelFemaleGT25 should exist", row.getColumnValue("newJadelFemaleGT25")); + assertNotNull("existentJadelFemaleLT25 should exist", row.getColumnValue("existentJadelFemaleLT25")); + assertNotNull("existentJadelFemaleGT25 should exist", row.getColumnValue("existentJadelFemaleGT25")); + + // Verify Condom Female rows exist + assertNotNull("newCondomFemaleLT25 should exist", row.getColumnValue("newCondomFemaleLT25")); + assertNotNull("newCondomFemaleGT25 should exist", row.getColumnValue("newCondomFemaleGT25")); + assertNotNull("existentCondomFemaleLT25 should exist", row.getColumnValue("existentCondomFemaleLT25")); + assertNotNull("existentCondomFemaleGT25 should exist", row.getColumnValue("existentCondomFemaleGT25")); + + // Verify Condom Male rows exist + assertNotNull("newCondomMaleLT25 should exist", row.getColumnValue("newCondomMaleLT25")); + assertNotNull("newCondomMaleGT25 should exist", row.getColumnValue("newCondomMaleGT25")); + assertNotNull("existentCondomMaleLT25 should exist", row.getColumnValue("existentCondomMaleLT25")); + assertNotNull("existentCondomMaleGT25 should exist", row.getColumnValue("existentCondomMaleGT25")); + } } private void updateDatabase(String filename) throws Exception { From 15b77ef87d0028738d8fb679313fb84d4092afcf Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Tue, 23 Dec 2025 19:15:18 +0530 Subject: [PATCH 04/15] [WIP] Fix unit tests --- .../MSPPFamilyPlanningReportManagerTest.java | 103 +++++------------- 1 file changed, 26 insertions(+), 77 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index d079a83c..5dce85c3 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -16,6 +16,7 @@ import org.dbunit.operation.DatabaseOperation; import org.junit.Before; import org.junit.Test; +import org.openmrs.Cohort; import org.openmrs.api.ConceptService; import org.openmrs.module.initializer.Domain; import org.openmrs.module.initializer.api.InitializerService; @@ -149,83 +150,31 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { DataSetRow row = itr.next(); // Verify Microlut data - assertEquals(new Long(1), row.getColumnValue("existentMicrolutFemaleLT25")); - assertEquals(new Long(0), row.getColumnValue("existentMicrolutFemaleGT25")); - assertEquals(new Long(1), row.getColumnValue("newMicrolutFemaleLT25")); - assertEquals(new Long(0), row.getColumnValue("newMicrolutFemaleGT25")); - - // Verify Jadel data - assertEquals(new Long(1), row.getColumnValue("newJadelFemaleLT25")); - assertEquals(new Long(0), row.getColumnValue("newJadelFemaleGT25")); - - // Verify Depo Provera data - assertEquals(new Long(1), row.getColumnValue("existentDepoFemaleGT25")); - assertEquals(new Long(0), row.getColumnValue("existentDepoFemaleLT25")); - - // Verify Condom Female data - assertEquals(new Long(1), row.getColumnValue("newCondomFemaleGT25")); - assertEquals(new Long(0), row.getColumnValue("newCondomFemaleLT25")); - - // Verify Condom Male data - assertEquals(new Long(1), row.getColumnValue("newCondomMaleGT25")); - assertEquals(new Long(0), row.getColumnValue("newCondomMaleLT25")); - - // Verify Total column exists - assertNotNull("Total column should exist", row.getColumnValue("Total")); - } - } - - - @Test - public void testReport_shouldIncludeAllMethodRows() throws Exception { - // setup - EvaluationContext context = new EvaluationContext(); - context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); - context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); - - // replay - ReportDefinition rd = manager.constructReportDefinition(); - ReportData data = rds.evaluate(rd, context); - - // verify - check that all method rows are present in the results - for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { - DataSetRow row = itr.next(); - - // Verify Microgynon rows exist - assertNotNull("newMycogynonFemaleLT25 should exist", row.getColumnValue("newMycogynonFemaleLT25")); - assertNotNull("newMycogynonFemaleGT25 should exist", row.getColumnValue("newMycogynonFemaleGT25")); - assertNotNull("existentMycogynonFemaleLT25 should exist", row.getColumnValue("existentMycogynonFemaleLT25")); - assertNotNull("existentMycogynonFemaleGT25 should exist", row.getColumnValue("existentMycogynonFemaleGT25")); - - // Verify Microlut rows exist - assertNotNull("newMicrolutFemaleLT25 should exist", row.getColumnValue("newMicrolutFemaleLT25")); - assertNotNull("newMicrolutFemaleGT25 should exist", row.getColumnValue("newMicrolutFemaleGT25")); - assertNotNull("existentMicrolutFemaleLT25 should exist", row.getColumnValue("existentMicrolutFemaleLT25")); - assertNotNull("existentMicrolutFemaleGT25 should exist", row.getColumnValue("existentMicrolutFemaleGT25")); - - // Verify Depo Provera rows exist - assertNotNull("newDepoFemaleLT25 should exist", row.getColumnValue("newDepoFemaleLT25")); - assertNotNull("newDepoFemaleGT25 should exist", row.getColumnValue("newDepoFemaleGT25")); - assertNotNull("existentDepoFemaleLT25 should exist", row.getColumnValue("existentDepoFemaleLT25")); - assertNotNull("existentDepoFemaleGT25 should exist", row.getColumnValue("existentDepoFemaleGT25")); - - // Verify Jadel rows exist - assertNotNull("newJadelFemaleLT25 should exist", row.getColumnValue("newJadelFemaleLT25")); - assertNotNull("newJadelFemaleGT25 should exist", row.getColumnValue("newJadelFemaleGT25")); - assertNotNull("existentJadelFemaleLT25 should exist", row.getColumnValue("existentJadelFemaleLT25")); - assertNotNull("existentJadelFemaleGT25 should exist", row.getColumnValue("existentJadelFemaleGT25")); - - // Verify Condom Female rows exist - assertNotNull("newCondomFemaleLT25 should exist", row.getColumnValue("newCondomFemaleLT25")); - assertNotNull("newCondomFemaleGT25 should exist", row.getColumnValue("newCondomFemaleGT25")); - assertNotNull("existentCondomFemaleLT25 should exist", row.getColumnValue("existentCondomFemaleLT25")); - assertNotNull("existentCondomFemaleGT25 should exist", row.getColumnValue("existentCondomFemaleGT25")); - - // Verify Condom Male rows exist - assertNotNull("newCondomMaleLT25 should exist", row.getColumnValue("newCondomMaleLT25")); - assertNotNull("newCondomMaleGT25 should exist", row.getColumnValue("newCondomMaleGT25")); - assertNotNull("existentCondomMaleLT25 should exist", row.getColumnValue("existentCondomMaleLT25")); - assertNotNull("existentCondomMaleGT25 should exist", row.getColumnValue("existentCondomMaleGT25")); + Cohort existentMicrolutFemaleLT25= (Cohort) row.getColumnValue("existentMicrolutFemaleLT25"); + assertNotNull(existentMicrolutFemaleLT25); + assertEquals(1, existentMicrolutFemaleLT25.getSize()); +// assertEquals(new Long(0), row.getColumnValue("existentMicrolutFemaleGT25")); +// assertEquals(new Long(1), row.getColumnValue("newMicrolutFemaleLT25")); +// assertEquals(new Long(0), row.getColumnValue("newMicrolutFemaleGT25")); +// +// // Verify Jadel data +// assertEquals(new Long(1), row.getColumnValue("newJadelFemaleLT25")); +// assertEquals(new Long(0), row.getColumnValue("newJadelFemaleGT25")); +// +// // Verify Depo Provera data +// assertEquals(new Long(1), row.getColumnValue("existentDepoFemaleGT25")); +// assertEquals(new Long(0), row.getColumnValue("existentDepoFemaleLT25")); +// +// // Verify Condom Female data +// assertEquals(new Long(1), row.getColumnValue("newCondomFemaleGT25")); +// assertEquals(new Long(0), row.getColumnValue("newCondomFemaleLT25")); +// +// // Verify Condom Male data +// assertEquals(new Long(1), row.getColumnValue("newCondomMaleGT25")); +// assertEquals(new Long(0), row.getColumnValue("newCondomMaleLT25")); +// +// // Verify Total column exists +// assertNotNull("Total column should exist", row.getColumnValue("Total")); } } From 6d0ba158a9e7d0b4c6a70376c76c180e741a6c69 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Tue, 23 Dec 2025 20:06:44 +0530 Subject: [PATCH 05/15] [WIP] Fix unit tests+ --- .../MSPPFamilyPlanningReportManagerTest.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 5dce85c3..13519755 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -4,8 +4,10 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.dbunit.DatabaseUnitException; import org.dbunit.DatabaseUnitRuntimeException; import org.dbunit.database.DatabaseConfig; @@ -14,6 +16,8 @@ import org.dbunit.dataset.IDataSet; import org.dbunit.ext.mysql.MySqlDataTypeFactory; import org.dbunit.operation.DatabaseOperation; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import org.junit.Before; import org.junit.Test; import org.openmrs.Cohort; @@ -145,38 +149,33 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { // verify assertNotNull("Report data should not be null", data); assertTrue("Should have data sets", data.getDataSets().size() > 0); - + for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { DataSetRow row = itr.next(); - - // Verify Microlut data - Cohort existentMicrolutFemaleLT25= (Cohort) row.getColumnValue("existentMicrolutFemaleLT25"); - assertNotNull(existentMicrolutFemaleLT25); - assertEquals(1, existentMicrolutFemaleLT25.getSize()); -// assertEquals(new Long(0), row.getColumnValue("existentMicrolutFemaleGT25")); -// assertEquals(new Long(1), row.getColumnValue("newMicrolutFemaleLT25")); -// assertEquals(new Long(0), row.getColumnValue("newMicrolutFemaleGT25")); -// -// // Verify Jadel data -// assertEquals(new Long(1), row.getColumnValue("newJadelFemaleLT25")); -// assertEquals(new Long(0), row.getColumnValue("newJadelFemaleGT25")); -// -// // Verify Depo Provera data -// assertEquals(new Long(1), row.getColumnValue("existentDepoFemaleGT25")); -// assertEquals(new Long(0), row.getColumnValue("existentDepoFemaleLT25")); -// -// // Verify Condom Female data -// assertEquals(new Long(1), row.getColumnValue("newCondomFemaleGT25")); -// assertEquals(new Long(0), row.getColumnValue("newCondomFemaleLT25")); -// -// // Verify Condom Male data -// assertEquals(new Long(1), row.getColumnValue("newCondomMaleGT25")); -// assertEquals(new Long(0), row.getColumnValue("newCondomMaleLT25")); -// -// // Verify Total column exists -// assertNotNull("Total column should exist", row.getColumnValue("Total")); + Map columnValuePairs = getColumnValues(); + for (String column : columnValuePairs.keySet()) { + assertThat(column, ((Cohort) row.getColumnValue(column)).getSize(), is(columnValuePairs.get(column))); + } } } + + private Map getColumnValues() { + Map map = new HashMap(); + map.put("existentMicrolutFemaleLT25", 1); + map.put("existentMicrolutFemaleGT25", 0); + map.put("newMicrolutFemaleLT25", 1); + map.put("newMicrolutFemaleGT25", 0); + map.put("newJadelFemaleLT25", 1); + map.put("newJadelFemaleGT25", 0); + map.put("existentDepoFemaleGT25", 1); + map.put("existentDepoFemaleLT25", 0); + map.put("newCondomFemaleGT25", 1); + map.put("newCondomFemaleLT25", 0); + map.put("newCondomMaleGT25", 1); + map.put("newCondomMaleLT25", 0); + return map; + + } private void updateDatabase(String filename) throws Exception { Liquibase liquibase = getLiquibase(filename); From cbdeab471274c79996c72690339aa15b04f7548a Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 00:04:32 +0530 Subject: [PATCH 06/15] [WIP] Fix unit tests++ --- .../commonreports/CommonReportsConstants.java | 4 +- .../MSPPFamilyPlanningReportManager.java | 2 +- .../MSPPFamilyPlanningReportManagerTest.java | 117 +++--------------- 3 files changed, 22 insertions(+), 101 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java b/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java index c3c7cc54..2d3dad8d 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java +++ b/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java @@ -36,9 +36,7 @@ public class CommonReportsConstants { public static final String COMPONENT_REPORTMANAGER_LAB = MODULE_ARTIFACT_ID + ".lab"; public static final String COMPONENT_REPORTMANAGER_VACCINATION = MODULE_ARTIFACT_ID + ".vaccination"; - - public static final String COMPONENT_REPORTMANAGER_FAMILYPLANNING = MODULE_ARTIFACT_ID + ".familyPlanning"; - + /* * URIs URLs */ diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java index 02c1973a..ab837e33 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java @@ -23,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -@Component(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILYPLANNING) +@Component public class MSPPFamilyPlanningReportManager extends ActivatedReportManager { @Autowired diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 13519755..b6e78ff7 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -1,22 +1,11 @@ package org.openmrs.module.commonreports.reports; import java.io.File; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; -import org.dbunit.DatabaseUnitException; -import org.dbunit.DatabaseUnitRuntimeException; -import org.dbunit.database.DatabaseConfig; -import org.dbunit.database.DatabaseConnection; -import org.dbunit.database.IDatabaseConnection; -import org.dbunit.dataset.IDataSet; -import org.dbunit.ext.mysql.MySqlDataTypeFactory; -import org.dbunit.operation.DatabaseOperation; import static org.hamcrest.CoreMatchers.is; +import org.junit.Assert; import static org.junit.Assert.assertThat; import org.junit.Before; import org.junit.Test; @@ -27,112 +16,62 @@ import org.openmrs.module.initializer.api.loaders.Loader; import org.openmrs.module.reporting.common.DateUtil; import org.openmrs.module.reporting.dataset.DataSetRow; -import org.openmrs.module.reporting.dataset.definition.CohortCrossTabDataSetDefinition; import org.openmrs.module.reporting.evaluation.EvaluationContext; -import org.openmrs.module.reporting.evaluation.parameter.Parameter; import org.openmrs.module.reporting.report.ReportData; -import org.openmrs.module.reporting.report.ReportDesign; import org.openmrs.module.reporting.report.definition.ReportDefinition; import org.openmrs.module.reporting.report.definition.service.ReportDefinitionService; import org.openmrs.module.reporting.report.manager.ReportManagerUtil; import org.openmrs.module.reporting.report.service.ReportService; +import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import liquibase.Liquibase; -import liquibase.database.Database; -import liquibase.database.DatabaseFactory; -import liquibase.database.jvm.JdbcConnection; -import liquibase.resource.ClassLoaderResourceAccessor; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveMysqlBackedTest { - - public MSPPFamilyPlanningReportManagerTest() throws SQLException { - super(); - } - +public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveTest { + @Autowired private InitializerService iniz; - + @Autowired private ReportService rs; - + @Autowired private ReportDefinitionService rds; - + @Autowired @Qualifier("conceptService") private ConceptService cs; - + @Autowired private MSPPFamilyPlanningReportManager manager; - - @Override - public void executeDataSet(IDataSet dataset) { - try { - Connection connection = getConnection(); - IDatabaseConnection dbUnitConn = setupDatabaseConnection(connection); - DatabaseOperation.REFRESH.execute(dbUnitConn, dataset); - } - catch (Exception e) { - throw new DatabaseUnitRuntimeException(e); - } - } - - private IDatabaseConnection setupDatabaseConnection(Connection connection) throws DatabaseUnitException { - IDatabaseConnection dbUnitConn = new DatabaseConnection(connection); - - DatabaseConfig config = dbUnitConn.getConfig(); - config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory()); - - return dbUnitConn; - } - + + @Before - public void setUp() throws Exception { - updateDatabase("org/openmrs/module/commonreports/liquibase/test-liquibase.xml"); + public void setup() throws Exception { executeDataSet("org/openmrs/module/reporting/include/ReportTestDataset-openmrs-2.0.xml"); executeDataSet("org/openmrs/module/commonreports/include/MSPPfamilyPlanningTestDataset.xml"); - + String path = getClass().getClassLoader().getResource("testAppDataDir").getPath() + File.separator; System.setProperty("OPENMRS_APPLICATION_DATA_DIRECTORY", path); - + for (Loader loader : iniz.getLoaders()) { if (loader.getDomainName().equals(Domain.JSON_KEY_VALUES.getName())) { loader.load(); } } } - - @Test - public void constructReportDesigns_shouldCreateCsvReportDesign() { - // replay - ReportDefinition rd = manager.constructReportDefinition(); - List designs = manager.constructReportDesigns(rd); - - // verify - assertNotNull("Report designs should not be null", designs); - assertEquals("Should have 1 report design", 1, designs.size()); - - ReportDesign design = designs.get(0); - assertEquals("8e300676-75d7-48f8-82eb-4fe9971459fe", design.getUuid()); - assertEquals(rd, design.getReportDefinition()); - } - + @Test - public void setupReport_shouldCreateCsvReportDesign() throws Exception { + public void setupReport_shouldSetupFamilyPlanningReport() { + // replay ReportManagerUtil.setupReport(manager); - + // verify - ReportDesign design = rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe"); - assertNotNull("Report design should exist", design); - - ReportDefinition def = design.getReportDefinition(); - assertEquals("efd7ba26-7888-45a8-9184-423833ab79d3", def.getUuid()); + Assert.assertNotNull(rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe")); + } @Test @@ -173,23 +112,7 @@ private Map getColumnValues() { map.put("newCondomFemaleLT25", 0); map.put("newCondomMaleGT25", 1); map.put("newCondomMaleLT25", 0); - return map; - } - - private void updateDatabase(String filename) throws Exception { - Liquibase liquibase = getLiquibase(filename); - liquibase.update("Modify column datatype to longblob on reporting_report_design_resource table"); - liquibase.getDatabase().getConnection().commit(); - } - - private Liquibase getLiquibase(String filename) throws Exception { - Database liquibaseConnection = DatabaseFactory.getInstance() - .findCorrectDatabaseImplementation(new JdbcConnection(getConnection())); - - liquibaseConnection.setDatabaseChangeLogTableName("LIQUIBASECHANGELOG"); - liquibaseConnection.setDatabaseChangeLogLockTableName("LIQUIBASECHANGELOGLOCK"); - - return new Liquibase(filename, new ClassLoaderResourceAccessor(getClass().getClassLoader()), liquibaseConnection); + return map; } } From b8d92961a17cbffb7ef2fdb180726b8217080e46 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 13:42:06 +0530 Subject: [PATCH 07/15] [WIP] Fix unit tests+++ --- .../commonreports/CommonReportsConstants.java | 2 ++ .../MSPPFamilyPlanningReportManager.java | 2 +- api/src/main/resources/messages.properties | 2 -- .../MSPPFamilyPlanningReportManagerTest.java | 21 +++++++++++-------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java b/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java index 2d3dad8d..97b46289 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java +++ b/api/src/main/java/org/openmrs/module/commonreports/CommonReportsConstants.java @@ -37,6 +37,8 @@ public class CommonReportsConstants { public static final String COMPONENT_REPORTMANAGER_VACCINATION = MODULE_ARTIFACT_ID + ".vaccination"; + public static final String COMPONENT_REPORTMANAGER_FAMILY_PLANNING = MODULE_ARTIFACT_ID + ".familyPlanning"; + /* * URIs URLs */ diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java index ab837e33..224f3628 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java @@ -23,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -@Component +@Component(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILY_PLANNING) public class MSPPFamilyPlanningReportManager extends ActivatedReportManager { @Autowired diff --git a/api/src/main/resources/messages.properties b/api/src/main/resources/messages.properties index bd777430..ed37e0cd 100644 --- a/api/src/main/resources/messages.properties +++ b/api/src/main/resources/messages.properties @@ -122,8 +122,6 @@ ${project.parent.artifactId}.report.MSPP.emergency.0_14years=(0-14 years) ${project.parent.artifactId}.report.MSPP.emergency.above14years=(15 years and above) ${project.parent.artifactId}.report.MSPP.emergency.medicalAndSurgicalEmergency=Medical and surgical emergency -${project.parent.artifactId}.report.MSPP.familyPlanning.reportName=MSPP Family Planning -${project.parent.artifactId}.report.MSPP.familyPlanning.reportDescription=Family Planning report required by the Haitian MSPP ${project.parent.artifactId}.report.MSPP.familyPlanning.reportName=MSPP Family Planning ${project.parent.artifactId}.report.MSPP.familyPlanning.reportDescription=Family Planning report required by Haitian MSPP ${project.parent.artifactId}.report.MSPP.familyPlanning.datasetName=Family Planning SQL Dataset diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index b6e78ff7..99855fa3 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -1,6 +1,7 @@ package org.openmrs.module.commonreports.reports; import java.io.File; +import java.sql.SQLException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -10,7 +11,8 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Cohort; -import org.openmrs.api.ConceptService; +import org.openmrs.module.commonreports.ActivatedReportManager; +import org.openmrs.module.commonreports.CommonReportsConstants; import org.openmrs.module.initializer.Domain; import org.openmrs.module.initializer.api.InitializerService; import org.openmrs.module.initializer.api.loaders.Loader; @@ -22,14 +24,18 @@ import org.openmrs.module.reporting.report.definition.service.ReportDefinitionService; import org.openmrs.module.reporting.report.manager.ReportManagerUtil; import org.openmrs.module.reporting.report.service.ReportService; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveTest { +public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveMysqlBackedTest { + + public MSPPFamilyPlanningReportManagerTest() throws SQLException { + super(); + // TODO Auto-generated constructor stub + } @Autowired private InitializerService iniz; @@ -41,11 +47,8 @@ public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensit private ReportDefinitionService rds; @Autowired - @Qualifier("conceptService") - private ConceptService cs; - - @Autowired - private MSPPFamilyPlanningReportManager manager; + @Qualifier(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILY_PLANNING) + private ActivatedReportManager manager; @Before @@ -89,7 +92,7 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { assertNotNull("Report data should not be null", data); assertTrue("Should have data sets", data.getDataSets().size() > 0); - for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { + for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext();) { DataSetRow row = itr.next(); Map columnValuePairs = getColumnValues(); for (String column : columnValuePairs.keySet()) { From 7e66e0649098ff44f7ad5d14106034742128738a Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 14:03:14 +0530 Subject: [PATCH 08/15] [WIP] Fix unit tests++++ --- .../MSPPFamilyPlanningReportManagerTest.java | 211 +++++++++++------- 1 file changed, 125 insertions(+), 86 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 99855fa3..e05a1404 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -7,6 +7,7 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.is; import org.junit.Assert; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import org.junit.Before; import org.junit.Test; @@ -32,90 +33,128 @@ public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveMysqlBackedTest { - public MSPPFamilyPlanningReportManagerTest() throws SQLException { - super(); - // TODO Auto-generated constructor stub - } - - @Autowired - private InitializerService iniz; - - @Autowired - private ReportService rs; - - @Autowired - private ReportDefinitionService rds; - - @Autowired - @Qualifier(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILY_PLANNING) - private ActivatedReportManager manager; - - - @Before - public void setup() throws Exception { - executeDataSet("org/openmrs/module/reporting/include/ReportTestDataset-openmrs-2.0.xml"); - executeDataSet("org/openmrs/module/commonreports/include/MSPPfamilyPlanningTestDataset.xml"); - - String path = getClass().getClassLoader().getResource("testAppDataDir").getPath() + File.separator; - System.setProperty("OPENMRS_APPLICATION_DATA_DIRECTORY", path); - - for (Loader loader : iniz.getLoaders()) { - if (loader.getDomainName().equals(Domain.JSON_KEY_VALUES.getName())) { - loader.load(); - } - } - } - - @Test - public void setupReport_shouldSetupFamilyPlanningReport() { - - // replay - ReportManagerUtil.setupReport(manager); - - // verify - Assert.assertNotNull(rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe")); - - } - - @Test - public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { - // setup - EvaluationContext context = new EvaluationContext(); - context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); - context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); - - // replay - ReportDefinition rd = manager.constructReportDefinition(); - ReportData data = rds.evaluate(rd, context); - - // verify - assertNotNull("Report data should not be null", data); - assertTrue("Should have data sets", data.getDataSets().size() > 0); - - for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext();) { - DataSetRow row = itr.next(); - Map columnValuePairs = getColumnValues(); - for (String column : columnValuePairs.keySet()) { - assertThat(column, ((Cohort) row.getColumnValue(column)).getSize(), is(columnValuePairs.get(column))); - } - } - } - - private Map getColumnValues() { - Map map = new HashMap(); - map.put("existentMicrolutFemaleLT25", 1); - map.put("existentMicrolutFemaleGT25", 0); - map.put("newMicrolutFemaleLT25", 1); - map.put("newMicrolutFemaleGT25", 0); - map.put("newJadelFemaleLT25", 1); - map.put("newJadelFemaleGT25", 0); - map.put("existentDepoFemaleGT25", 1); - map.put("existentDepoFemaleLT25", 0); - map.put("newCondomFemaleGT25", 1); - map.put("newCondomFemaleLT25", 0); - map.put("newCondomMaleGT25", 1); - map.put("newCondomMaleLT25", 0); - - return map; - } + public MSPPFamilyPlanningReportManagerTest() throws SQLException { + super(); + // TODO Auto-generated constructor stub + } + + @Autowired + private InitializerService iniz; + + @Autowired + private ReportService rs; + + @Autowired + private ReportDefinitionService rds; + + @Autowired + @Qualifier(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILY_PLANNING) + private ActivatedReportManager manager; + + + @Before + public void setup() throws Exception { + executeDataSet("org/openmrs/module/reporting/include/ReportTestDataset-openmrs-2.0.xml"); + executeDataSet("org/openmrs/module/commonreports/include/MSPPfamilyPlanningTestDataset.xml"); + + String path = getClass().getClassLoader().getResource("testAppDataDir").getPath() + File.separator; + System.setProperty("OPENMRS_APPLICATION_DATA_DIRECTORY", path); + + for (Loader loader : iniz.getLoaders()) { + if (loader.getDomainName().equals(Domain.JSON_KEY_VALUES.getName())) { + loader.load(); + } + } + } + + @Test + public void setupReport_shouldSetupFamilyPlanningReport() { + + // replay + ReportManagerUtil.setupReport(manager); + + // verify + Assert.assertNotNull(rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe")); + + } + + @Test + public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { + // setup + EvaluationContext context = new EvaluationContext(); + context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); + context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); + + // replay + ReportDefinition rd = manager.constructReportDefinition(); + ReportData data = rds.evaluate(rd, context); + + // verify + assertNotNull("Report data should not be null", data); + assertTrue("Should have data sets", data.getDataSets().size() > 0); + + for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext(); ) { + DataSetRow row = itr.next(); + + // In CrossTabDataSet reports all rows and columns are in fact just columns of + // one row + System.out.println("Printing row values" + row.getColumnValues().toString()); + Cohort riskyPregnancy = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25"); + assertNotNull(riskyPregnancy); + assertEquals(1, riskyPregnancy.getSize()); + +// Cohort prenatalIronDef = (Cohort) row +// .getColumnValue("Iron Def and ANC Visit." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(prenatalIronDef); +// assertEquals(1, prenatalIronDef.getSize()); +// +// Cohort prenatalIronFolate = (Cohort) row +// .getColumnValue("Prenatal visit + Fer Folate Co." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(prenatalIronFolate); +// assertEquals(1, prenatalIronFolate.getSize()); +// +// Cohort prenatalIronTreatment = (Cohort) row +// .getColumnValue("Prenatal visit + treated for Fe def." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(prenatalIronTreatment); +// assertEquals(1, prenatalIronTreatment.getSize()); +// +// Cohort motherWithBirthPlan = (Cohort) row +// .getColumnValue("Mothers with birth plan." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(motherWithBirthPlan); +// assertEquals(1, motherWithBirthPlan.getSize()); +// +// Cohort prenatalMalariaChloroquine = (Cohort) row.getColumnValue( +// "Prenatal visit + malaria test positive + Chloroqine co." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(prenatalMalariaChloroquine); +// assertEquals(1, prenatalMalariaChloroquine.getSize()); +// +// Cohort prenatalMUAC = (Cohort) row +// .getColumnValue("Prenatal + MUAC =<21cm." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(prenatalMUAC); +// assertEquals(1, prenatalMUAC.getSize()); +// +// Cohort otherWomenIronFolate = (Cohort) row +// .getColumnValue("Women + fer folate co prescribed." + MSPPAntenatalReportManager.risksCol1); +// assertNotNull(otherWomenIronFolate); +// assertEquals(1, otherWomenIronFolate.getSize()); + } + } + + private Map getColumnValues() { + Map map = new HashMap(); + map.put("existentMicrolutFemaleLT25", 1); + map.put("existentMicrolutFemaleGT25", 0); + map.put("newMicrolutFemaleLT25", 1); + map.put("newMicrolutFemaleGT25", 0); + map.put("newJadelFemaleLT25", 1); + map.put("newJadelFemaleGT25", 0); + map.put("existentDepoFemaleGT25", 1); + map.put("existentDepoFemaleLT25", 0); + map.put("newCondomFemaleGT25", 1); + map.put("newCondomFemaleLT25", 0); + map.put("newCondomMaleGT25", 1); + map.put("newCondomMaleLT25", 0); + + return map; + } } From 2acb90e71890f1b78e9cb1603d89cc48a7ae73b3 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 14:24:08 +0530 Subject: [PATCH 09/15] [WIP] Fix unit tests+++++ --- .../MSPPFamilyPlanningReportManager.java | 2 +- .../MSPPFamilyPlanningReportManagerTest.java | 212 +++++++----------- 2 files changed, 83 insertions(+), 131 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java index 224f3628..78f25f28 100644 --- a/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java +++ b/api/src/main/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManager.java @@ -86,7 +86,7 @@ public ReportDefinition constructReportDefinition() { Map parameterMappings = new HashMap(); parameterMappings.put("onOrAfter", "${startDate}"); parameterMappings.put("onOrBefore", "${endDate}"); - + int fpAdministredConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.FPAdministred") .getConceptId(); int familyPlanningConceptId = inizService.getConceptFromKey("report.MSPP.familyPlanning.familyPlanning") diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index e05a1404..3fd6c1bc 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -2,16 +2,11 @@ import java.io.File; import java.sql.SQLException; -import java.util.HashMap; import java.util.Iterator; -import java.util.Map; -import static org.hamcrest.CoreMatchers.is; import org.junit.Assert; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import org.junit.Before; import org.junit.Test; -import org.openmrs.Cohort; import org.openmrs.module.commonreports.ActivatedReportManager; import org.openmrs.module.commonreports.CommonReportsConstants; import org.openmrs.module.initializer.Domain; @@ -32,129 +27,86 @@ import static org.junit.Assert.assertTrue; public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensitiveMysqlBackedTest { - - public MSPPFamilyPlanningReportManagerTest() throws SQLException { - super(); - // TODO Auto-generated constructor stub - } - - @Autowired - private InitializerService iniz; - - @Autowired - private ReportService rs; - - @Autowired - private ReportDefinitionService rds; - - @Autowired - @Qualifier(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILY_PLANNING) - private ActivatedReportManager manager; - - - @Before - public void setup() throws Exception { - executeDataSet("org/openmrs/module/reporting/include/ReportTestDataset-openmrs-2.0.xml"); - executeDataSet("org/openmrs/module/commonreports/include/MSPPfamilyPlanningTestDataset.xml"); - - String path = getClass().getClassLoader().getResource("testAppDataDir").getPath() + File.separator; - System.setProperty("OPENMRS_APPLICATION_DATA_DIRECTORY", path); - - for (Loader loader : iniz.getLoaders()) { - if (loader.getDomainName().equals(Domain.JSON_KEY_VALUES.getName())) { - loader.load(); - } - } - } - - @Test - public void setupReport_shouldSetupFamilyPlanningReport() { - - // replay - ReportManagerUtil.setupReport(manager); - - // verify - Assert.assertNotNull(rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe")); - - } - - @Test - public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { - // setup - EvaluationContext context = new EvaluationContext(); - context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); - context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); - - // replay - ReportDefinition rd = manager.constructReportDefinition(); - ReportData data = rds.evaluate(rd, context); - - // verify - assertNotNull("Report data should not be null", data); - assertTrue("Should have data sets", data.getDataSets().size() > 0); - - for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext(); ) { - DataSetRow row = itr.next(); - - // In CrossTabDataSet reports all rows and columns are in fact just columns of - // one row - System.out.println("Printing row values" + row.getColumnValues().toString()); - Cohort riskyPregnancy = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25"); - assertNotNull(riskyPregnancy); - assertEquals(1, riskyPregnancy.getSize()); - -// Cohort prenatalIronDef = (Cohort) row -// .getColumnValue("Iron Def and ANC Visit." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(prenatalIronDef); -// assertEquals(1, prenatalIronDef.getSize()); -// -// Cohort prenatalIronFolate = (Cohort) row -// .getColumnValue("Prenatal visit + Fer Folate Co." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(prenatalIronFolate); -// assertEquals(1, prenatalIronFolate.getSize()); -// -// Cohort prenatalIronTreatment = (Cohort) row -// .getColumnValue("Prenatal visit + treated for Fe def." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(prenatalIronTreatment); -// assertEquals(1, prenatalIronTreatment.getSize()); -// -// Cohort motherWithBirthPlan = (Cohort) row -// .getColumnValue("Mothers with birth plan." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(motherWithBirthPlan); -// assertEquals(1, motherWithBirthPlan.getSize()); -// -// Cohort prenatalMalariaChloroquine = (Cohort) row.getColumnValue( -// "Prenatal visit + malaria test positive + Chloroqine co." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(prenatalMalariaChloroquine); -// assertEquals(1, prenatalMalariaChloroquine.getSize()); -// -// Cohort prenatalMUAC = (Cohort) row -// .getColumnValue("Prenatal + MUAC =<21cm." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(prenatalMUAC); -// assertEquals(1, prenatalMUAC.getSize()); -// -// Cohort otherWomenIronFolate = (Cohort) row -// .getColumnValue("Women + fer folate co prescribed." + MSPPAntenatalReportManager.risksCol1); -// assertNotNull(otherWomenIronFolate); -// assertEquals(1, otherWomenIronFolate.getSize()); - } - } - - private Map getColumnValues() { - Map map = new HashMap(); - map.put("existentMicrolutFemaleLT25", 1); - map.put("existentMicrolutFemaleGT25", 0); - map.put("newMicrolutFemaleLT25", 1); - map.put("newMicrolutFemaleGT25", 0); - map.put("newJadelFemaleLT25", 1); - map.put("newJadelFemaleGT25", 0); - map.put("existentDepoFemaleGT25", 1); - map.put("existentDepoFemaleLT25", 0); - map.put("newCondomFemaleGT25", 1); - map.put("newCondomFemaleLT25", 0); - map.put("newCondomMaleGT25", 1); - map.put("newCondomMaleLT25", 0); - - return map; - } + + public MSPPFamilyPlanningReportManagerTest() throws SQLException { + super(); + // TODO Auto-generated constructor stub + } + + @Autowired + private InitializerService iniz; + + @Autowired + private ReportService rs; + + @Autowired + private ReportDefinitionService rds; + + @Autowired + @Qualifier(CommonReportsConstants.COMPONENT_REPORTMANAGER_FAMILY_PLANNING) + private ActivatedReportManager manager; + + @Before + public void setup() throws Exception { + executeDataSet("org/openmrs/module/reporting/include/ReportTestDataset-openmrs-2.0.xml"); + executeDataSet("org/openmrs/module/commonreports/include/MSPPfamilyPlanningTestDataset.xml"); + + String path = getClass().getClassLoader().getResource("testAppDataDir").getPath() + File.separator; + System.setProperty("OPENMRS_APPLICATION_DATA_DIRECTORY", path); + + for (Loader loader : iniz.getLoaders()) { + if (loader.getDomainName().equals(Domain.JSON_KEY_VALUES.getName())) { + loader.load(); + } + } + } + + @Test + public void setupReport_shouldSetupFamilyPlanningReport() { + + // replay + ReportManagerUtil.setupReport(manager); + + // verify + Assert.assertNotNull(rs.getReportDesignByUuid("8e300676-75d7-48f8-82eb-4fe9971459fe")); + + } + + @Test + public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { + // setup + EvaluationContext context = new EvaluationContext(); + context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); + context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); + + // replay + ReportDefinition rd = manager.constructReportDefinition(); + ReportData data = rds.evaluate(rd, context); + + // verify + assertNotNull("Report data should not be null", data); + assertTrue("Should have data sets", data.getDataSets().size() > 0); + + for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { + DataSetRow row = itr.next(); + assertEquals(new Long(1), row.getColumnValue("existentMicrolutFemaleLT25 - Total")); + assertEquals(new Long(0), row.getColumnValue("existentMicrolutFemaleGT25 - Total")); + + assertEquals(new Long(1), row.getColumnValue("newMicrolutFemaleLT25 - Total")); + assertEquals(new Long(0), row.getColumnValue("newMicrolutFemaleGT25 - Total")); + + assertEquals(new Long(1), row.getColumnValue("newJadelFemaleLT25 - Total")); + assertEquals(new Long(0), row.getColumnValue("newJadelFemaleGT25 - Total")); + + assertEquals(new Long(1), row.getColumnValue("existentDepoFemaleGT25 - Total")); + assertEquals(new Long(0), row.getColumnValue("existentDepoFemaleLT25 - Total")); + + assertEquals(new Long(1), row.getColumnValue("newCondomFemaleGT25 - Total")); + assertEquals(new Long(0), row.getColumnValue("newCondomFemaleLT25 - Total")); + + assertEquals(new Long(1), row.getColumnValue("newCondomMaleGT25 - Total")); + assertEquals(new Long(0), row.getColumnValue("newCondomMaleLT25 - Total")); + + } + } } From 1dbd538628cfe647f810a6ef17a125b63994a4ca Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 15:08:20 +0530 Subject: [PATCH 10/15] [WIP] Fix unit tests+++++_ --- .../MSPPFamilyPlanningReportManagerTest.java | 74 +++++++++++++------ 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 3fd6c1bc..d1042b99 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; +import org.openmrs.Cohort; import org.openmrs.module.commonreports.ActivatedReportManager; import org.openmrs.module.commonreports.CommonReportsConstants; import org.openmrs.module.initializer.Domain; @@ -78,35 +79,64 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { EvaluationContext context = new EvaluationContext(); context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); - + // replay ReportDefinition rd = manager.constructReportDefinition(); ReportData data = rds.evaluate(rd, context); - + // verify assertNotNull("Report data should not be null", data); assertTrue("Should have data sets", data.getDataSets().size() > 0); - - for (Iterator itr = data.getDataSets().get(rd.getName()).iterator(); itr.hasNext();) { + + for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext(); ) { DataSetRow row = itr.next(); - assertEquals(new Long(1), row.getColumnValue("existentMicrolutFemaleLT25 - Total")); - assertEquals(new Long(0), row.getColumnValue("existentMicrolutFemaleGT25 - Total")); - - assertEquals(new Long(1), row.getColumnValue("newMicrolutFemaleLT25 - Total")); - assertEquals(new Long(0), row.getColumnValue("newMicrolutFemaleGT25 - Total")); - - assertEquals(new Long(1), row.getColumnValue("newJadelFemaleLT25 - Total")); - assertEquals(new Long(0), row.getColumnValue("newJadelFemaleGT25 - Total")); - - assertEquals(new Long(1), row.getColumnValue("existentDepoFemaleGT25 - Total")); - assertEquals(new Long(0), row.getColumnValue("existentDepoFemaleLT25 - Total")); - - assertEquals(new Long(1), row.getColumnValue("newCondomFemaleGT25 - Total")); - assertEquals(new Long(0), row.getColumnValue("newCondomFemaleLT25 - Total")); - - assertEquals(new Long(1), row.getColumnValue("newCondomMaleGT25 - Total")); - assertEquals(new Long(0), row.getColumnValue("newCondomMaleLT25 - Total")); - + Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25 - Total"); + assertNotNull(existentMicrolutFemaleLT25); + assertEquals(1, existentMicrolutFemaleLT25.getSize()); + + Cohort existentMicrolutFemaleGT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleGT25 - Total"); + assertNotNull(existentMicrolutFemaleGT25); + assertEquals(0, existentMicrolutFemaleGT25.getSize()); + + Cohort newMicrolutFemaleLT25 = (Cohort) row.getColumnValue("newMicrolutFemaleLT25 - Total"); + assertNotNull(newMicrolutFemaleLT25); + assertEquals(1, newMicrolutFemaleLT25.getSize()); + + Cohort newMicrolutFemaleGT25 = (Cohort) row.getColumnValue("newMicrolutFemaleGT25 - Total"); + assertNotNull(newMicrolutFemaleGT25); + assertEquals(0, newMicrolutFemaleGT25.getSize()); + + Cohort newJadelFemaleLT25 = (Cohort) row.getColumnValue("newJadelFemaleLT25 - Total"); + assertNotNull(newJadelFemaleLT25); + assertEquals(1, newJadelFemaleLT25.getSize()); + + Cohort newJadelFemaleGT25 = (Cohort) row.getColumnValue("newJadelFemaleGT25 - Total"); + assertNotNull(newJadelFemaleGT25); + assertEquals(0, newJadelFemaleGT25.getSize()); + + Cohort existentDepoFemaleGT25 = (Cohort) row.getColumnValue("existentDepoFemaleGT25 - Total"); + assertNotNull(existentDepoFemaleGT25); + assertEquals(1, existentDepoFemaleGT25.getSize()); + + Cohort existentDepoFemaleLT25 = (Cohort) row.getColumnValue("existentDepoFemaleLT25 - Total"); + assertNotNull(existentDepoFemaleLT25); + assertEquals(0, existentDepoFemaleLT25.getSize()); + + Cohort newCondomFemaleGT25 = (Cohort) row.getColumnValue("newCondomFemaleGT25 - Total"); + assertNotNull(newCondomFemaleGT25); + assertEquals(1, newCondomFemaleGT25.getSize()); + + Cohort newCondomFemaleLT25 = (Cohort) row.getColumnValue("newCondomFemaleLT25 - Total"); + assertNotNull(newCondomFemaleLT25); + assertEquals(0, newCondomFemaleLT25.getSize()); + + Cohort newCondomMaleGT25 = (Cohort) row.getColumnValue("newCondomMaleGT25 - Total"); + assertNotNull(newCondomMaleGT25); + assertEquals(1, newCondomMaleGT25.getSize()); + + Cohort newCondomMaleLT25 = (Cohort) row.getColumnValue("newCondomMaleLT25 - Total"); + assertNotNull(newCondomMaleLT25); + assertEquals(0, newCondomMaleLT25.getSize()); } } } From c794caa8cbd745f19373207b1d737ec03c5fc98d Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 15:48:37 +0530 Subject: [PATCH 11/15] [WIP] Fix unit tests+++++ print --- .../commonreports/reports/MSPPAntenatalReportManagerTest.java | 2 ++ .../reports/MSPPFamilyPlanningReportManagerTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java index a0f81158..3d8570de 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java @@ -114,6 +114,8 @@ public void testReport() throws Exception { for (Iterator itr = data.getDataSets().get("MSPP Antenatal Risks").iterator(); itr.hasNext();) { DataSetRow row = itr.next(); + + System.out.println("Printing MSPPAntenatalReportManagerTest " + row.getColumnValues().toString()); // In CrossTabDataSet reports all rows and columns are in fact just columns of // one row diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index d1042b99..90b6cac0 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -90,6 +90,8 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext(); ) { DataSetRow row = itr.next(); + System.out.println("Printing MSPPFamilyPlanningReportManagerTest " + row.getColumnValues().toString()); + Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25 - Total"); assertNotNull(existentMicrolutFemaleLT25); assertEquals(1, existentMicrolutFemaleLT25.getSize()); From d438f3f99a5661022c4f3002527e7bce3c5ecea5 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 16:12:55 +0530 Subject: [PATCH 12/15] [WIP] Fix unit tests++++++ --- .../MSPPFamilyPlanningReportManagerTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 90b6cac0..60ef6377 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -92,51 +92,51 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { DataSetRow row = itr.next(); System.out.println("Printing MSPPFamilyPlanningReportManagerTest " + row.getColumnValues().toString()); - Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25 - Total"); + Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25."); assertNotNull(existentMicrolutFemaleLT25); assertEquals(1, existentMicrolutFemaleLT25.getSize()); - Cohort existentMicrolutFemaleGT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleGT25 - Total"); + Cohort existentMicrolutFemaleGT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleGT25."); assertNotNull(existentMicrolutFemaleGT25); assertEquals(0, existentMicrolutFemaleGT25.getSize()); - Cohort newMicrolutFemaleLT25 = (Cohort) row.getColumnValue("newMicrolutFemaleLT25 - Total"); + Cohort newMicrolutFemaleLT25 = (Cohort) row.getColumnValue("newMicrolutFemaleLT25."); assertNotNull(newMicrolutFemaleLT25); assertEquals(1, newMicrolutFemaleLT25.getSize()); - Cohort newMicrolutFemaleGT25 = (Cohort) row.getColumnValue("newMicrolutFemaleGT25 - Total"); + Cohort newMicrolutFemaleGT25 = (Cohort) row.getColumnValue("newMicrolutFemaleGT25."); assertNotNull(newMicrolutFemaleGT25); assertEquals(0, newMicrolutFemaleGT25.getSize()); - Cohort newJadelFemaleLT25 = (Cohort) row.getColumnValue("newJadelFemaleLT25 - Total"); + Cohort newJadelFemaleLT25 = (Cohort) row.getColumnValue("newJadelFemaleLT25."); assertNotNull(newJadelFemaleLT25); assertEquals(1, newJadelFemaleLT25.getSize()); - Cohort newJadelFemaleGT25 = (Cohort) row.getColumnValue("newJadelFemaleGT25 - Total"); + Cohort newJadelFemaleGT25 = (Cohort) row.getColumnValue("newJadelFemaleGT25."); assertNotNull(newJadelFemaleGT25); assertEquals(0, newJadelFemaleGT25.getSize()); - Cohort existentDepoFemaleGT25 = (Cohort) row.getColumnValue("existentDepoFemaleGT25 - Total"); + Cohort existentDepoFemaleGT25 = (Cohort) row.getColumnValue("existentDepoFemaleGT25."); assertNotNull(existentDepoFemaleGT25); assertEquals(1, existentDepoFemaleGT25.getSize()); - Cohort existentDepoFemaleLT25 = (Cohort) row.getColumnValue("existentDepoFemaleLT25 - Total"); + Cohort existentDepoFemaleLT25 = (Cohort) row.getColumnValue("existentDepoFemaleLT25."); assertNotNull(existentDepoFemaleLT25); assertEquals(0, existentDepoFemaleLT25.getSize()); - Cohort newCondomFemaleGT25 = (Cohort) row.getColumnValue("newCondomFemaleGT25 - Total"); + Cohort newCondomFemaleGT25 = (Cohort) row.getColumnValue("newCondomFemaleGT25."); assertNotNull(newCondomFemaleGT25); assertEquals(1, newCondomFemaleGT25.getSize()); - Cohort newCondomFemaleLT25 = (Cohort) row.getColumnValue("newCondomFemaleLT25 - Total"); + Cohort newCondomFemaleLT25 = (Cohort) row.getColumnValue("newCondomFemaleLT25."); assertNotNull(newCondomFemaleLT25); assertEquals(0, newCondomFemaleLT25.getSize()); - Cohort newCondomMaleGT25 = (Cohort) row.getColumnValue("newCondomMaleGT25 - Total"); + Cohort newCondomMaleGT25 = (Cohort) row.getColumnValue("newCondomMaleGT25."); assertNotNull(newCondomMaleGT25); assertEquals(1, newCondomMaleGT25.getSize()); - Cohort newCondomMaleLT25 = (Cohort) row.getColumnValue("newCondomMaleLT25 - Total"); + Cohort newCondomMaleLT25 = (Cohort) row.getColumnValue("newCondomMaleLT25."); assertNotNull(newCondomMaleLT25); assertEquals(0, newCondomMaleLT25.getSize()); } From 78d5cf70a04d91be5fb0e0f7681196efe65d1907 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 18:17:55 +0530 Subject: [PATCH 13/15] [WIP] Fix unit tests+++++++ --- .../MSPPFamilyPlanningReportManagerTest.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 60ef6377..c0872812 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -79,64 +79,64 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { EvaluationContext context = new EvaluationContext(); context.addParameterValue("startDate", DateUtil.parseDate("2021-07-01", "yyyy-MM-dd")); context.addParameterValue("endDate", DateUtil.parseDate("2021-07-30", "yyyy-MM-dd")); - + // replay ReportDefinition rd = manager.constructReportDefinition(); ReportData data = rds.evaluate(rd, context); - + // verify assertNotNull("Report data should not be null", data); assertTrue("Should have data sets", data.getDataSets().size() > 0); - - for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext(); ) { + + for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext();) { DataSetRow row = itr.next(); System.out.println("Printing MSPPFamilyPlanningReportManagerTest " + row.getColumnValues().toString()); - - Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25."); + + Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25.Total"); assertNotNull(existentMicrolutFemaleLT25); assertEquals(1, existentMicrolutFemaleLT25.getSize()); - - Cohort existentMicrolutFemaleGT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleGT25."); + + Cohort existentMicrolutFemaleGT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleGT25.Total"); assertNotNull(existentMicrolutFemaleGT25); assertEquals(0, existentMicrolutFemaleGT25.getSize()); - - Cohort newMicrolutFemaleLT25 = (Cohort) row.getColumnValue("newMicrolutFemaleLT25."); + + Cohort newMicrolutFemaleLT25 = (Cohort) row.getColumnValue("newMicrolutFemaleLT25.Total"); assertNotNull(newMicrolutFemaleLT25); assertEquals(1, newMicrolutFemaleLT25.getSize()); - - Cohort newMicrolutFemaleGT25 = (Cohort) row.getColumnValue("newMicrolutFemaleGT25."); + + Cohort newMicrolutFemaleGT25 = (Cohort) row.getColumnValue("newMicrolutFemaleGT25.Total"); assertNotNull(newMicrolutFemaleGT25); assertEquals(0, newMicrolutFemaleGT25.getSize()); - - Cohort newJadelFemaleLT25 = (Cohort) row.getColumnValue("newJadelFemaleLT25."); + + Cohort newJadelFemaleLT25 = (Cohort) row.getColumnValue("newJadelFemaleLT25.Total"); assertNotNull(newJadelFemaleLT25); assertEquals(1, newJadelFemaleLT25.getSize()); - - Cohort newJadelFemaleGT25 = (Cohort) row.getColumnValue("newJadelFemaleGT25."); + + Cohort newJadelFemaleGT25 = (Cohort) row.getColumnValue("newJadelFemaleGT25.Total"); assertNotNull(newJadelFemaleGT25); assertEquals(0, newJadelFemaleGT25.getSize()); - - Cohort existentDepoFemaleGT25 = (Cohort) row.getColumnValue("existentDepoFemaleGT25."); + + Cohort existentDepoFemaleGT25 = (Cohort) row.getColumnValue("existentDepoFemaleGT25.Total"); assertNotNull(existentDepoFemaleGT25); assertEquals(1, existentDepoFemaleGT25.getSize()); - - Cohort existentDepoFemaleLT25 = (Cohort) row.getColumnValue("existentDepoFemaleLT25."); + + Cohort existentDepoFemaleLT25 = (Cohort) row.getColumnValue("existentDepoFemaleLT25.Total"); assertNotNull(existentDepoFemaleLT25); assertEquals(0, existentDepoFemaleLT25.getSize()); - - Cohort newCondomFemaleGT25 = (Cohort) row.getColumnValue("newCondomFemaleGT25."); + + Cohort newCondomFemaleGT25 = (Cohort) row.getColumnValue("newCondomFemaleGT25.Total"); assertNotNull(newCondomFemaleGT25); assertEquals(1, newCondomFemaleGT25.getSize()); - - Cohort newCondomFemaleLT25 = (Cohort) row.getColumnValue("newCondomFemaleLT25."); + + Cohort newCondomFemaleLT25 = (Cohort) row.getColumnValue("newCondomFemaleLT25.Total"); assertNotNull(newCondomFemaleLT25); assertEquals(0, newCondomFemaleLT25.getSize()); - - Cohort newCondomMaleGT25 = (Cohort) row.getColumnValue("newCondomMaleGT25."); + + Cohort newCondomMaleGT25 = (Cohort) row.getColumnValue("newCondomMaleGT25.Total"); assertNotNull(newCondomMaleGT25); assertEquals(1, newCondomMaleGT25.getSize()); - - Cohort newCondomMaleLT25 = (Cohort) row.getColumnValue("newCondomMaleLT25."); + + Cohort newCondomMaleLT25 = (Cohort) row.getColumnValue("newCondomMaleLT25.Total"); assertNotNull(newCondomMaleLT25); assertEquals(0, newCondomMaleLT25.getSize()); } From befabbf8ce5ee1122b1b8358557f00d365321c86 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Wed, 24 Dec 2025 19:52:06 +0530 Subject: [PATCH 14/15] Remove print statments --- .../commonreports/reports/MSPPAntenatalReportManagerTest.java | 1 - .../reports/MSPPFamilyPlanningReportManagerTest.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java index 3d8570de..e8c8f403 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPAntenatalReportManagerTest.java @@ -115,7 +115,6 @@ public void testReport() throws Exception { for (Iterator itr = data.getDataSets().get("MSPP Antenatal Risks").iterator(); itr.hasNext();) { DataSetRow row = itr.next(); - System.out.println("Printing MSPPAntenatalReportManagerTest " + row.getColumnValues().toString()); // In CrossTabDataSet reports all rows and columns are in fact just columns of // one row diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index c0872812..36574fdc 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -90,8 +90,7 @@ public void testReport_shouldEvaluateReportWithCorrectData() throws Exception { for (Iterator itr = data.getDataSets().get("MSPP Family Planning").iterator(); itr.hasNext();) { DataSetRow row = itr.next(); - System.out.println("Printing MSPPFamilyPlanningReportManagerTest " + row.getColumnValues().toString()); - + Cohort existentMicrolutFemaleLT25 = (Cohort) row.getColumnValue("existentMicrolutFemaleLT25.Total"); assertNotNull(existentMicrolutFemaleLT25); assertEquals(1, existentMicrolutFemaleLT25.getSize()); From 18c5d8577558cf056f8bcad7e21266d4fd8afdcc Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Thu, 15 Jan 2026 13:18:24 +0530 Subject: [PATCH 15/15] Minnor fix --- .../reports/MSPPFamilyPlanningReportManagerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java index 36574fdc..f28505e8 100644 --- a/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java +++ b/api/src/test/java/org/openmrs/module/commonreports/reports/MSPPFamilyPlanningReportManagerTest.java @@ -31,7 +31,6 @@ public class MSPPFamilyPlanningReportManagerTest extends BaseModuleContextSensit public MSPPFamilyPlanningReportManagerTest() throws SQLException { super(); - // TODO Auto-generated constructor stub } @Autowired