diff --git a/api/src/main/java/org/openmrs/module/rwandareports/Dictionary.java b/api/src/main/java/org/openmrs/module/rwandareports/Dictionary.java new file mode 100644 index 00000000..31c59484 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/Dictionary.java @@ -0,0 +1,61 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports; + +import java.util.ArrayList; +import java.util.List; + +import org.openmrs.Concept; +import org.openmrs.module.rwandareports.util.MetadataLookup; + +/** + * Dictionary for concepts used by rwandareports + */ +public class Dictionary { + + /** + * Gets a concept by an identifier (mapping or UUID) + * + * @param identifier the identifier + * @return the concept + * @throws IllegalArgumentException if the concept could not be found + */ + public static Concept getConcept(String identifier) { + return MetadataLookup.getConcept(identifier); + } + + /** + * Convenience method to fetch a list of concepts + * + * @param identifiers the concept identifiers + * @return the concepts + * @throws IllegalArgumentException if a concept could not be found + */ + public static List getConcepts(String... identifiers) { + List concepts = new ArrayList(); + for (String identifier : identifiers) { + concepts.add(getConcept(identifier)); + } + return concepts; + } + + // Concept identifiers (A-Z) + public static final String ADULT_HIV_PROGRAM = "372a7cd8-7dca-4032-a094-6afcce5c8559"; + + public static final String PEDI_HIV_PROGRAM = "3ce67698-26fe-102b-80cb-0017a47871b2"; + + public static final String PMTCT_PREGNANCY_PROGRAM = "3cdc8138-26fe-102b-80cb-0017a47871b2"; + + public static final String PMTCT_COMBINED_MOTHER_PROGRAM = "b00f1d61-a37c-451c-ac7f-c5fc0f231091"; +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/metadata/CommonMetadata.java b/api/src/main/java/org/openmrs/module/rwandareports/metadata/CommonMetadata.java new file mode 100644 index 00000000..8c6c4aa6 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/metadata/CommonMetadata.java @@ -0,0 +1,39 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.metadata; + +import org.openmrs.module.metadatadeploy.bundle.AbstractMetadataBundle; +import org.springframework.stereotype.Component; + +/** + * Common metadata bundle + */ +@Component +public class CommonMetadata extends AbstractMetadataBundle { + + public static final class _Location { + + public static final String UNKNOWN = "8d6c993e-c2cc-11de-8d13-0010c6dffd0f"; + } + + /** + * @see org.openmrs.module.metadatadeploy.bundle.MetadataBundle#install() + */ + @Override + public void install() { + // TODO Auto-generated method stub + + } + +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/metadata/HivMetadata.java b/api/src/main/java/org/openmrs/module/rwandareports/metadata/HivMetadata.java new file mode 100644 index 00000000..bd7dc98e --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/metadata/HivMetadata.java @@ -0,0 +1,52 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.metadata; + +import org.openmrs.module.metadatadeploy.bundle.AbstractMetadataBundle; +import org.openmrs.module.metadatadeploy.bundle.Requires; +import org.openmrs.module.rwandareports.Dictionary; +import org.springframework.stereotype.Component; + +import static org.openmrs.module.metadatadeploy.bundle.CoreConstructors.*; + + + +/** + * HIV metadata bundle + */ +@Component +@Requires({ CommonMetadata.class }) +public class HivMetadata extends AbstractMetadataBundle { + + public static final class _Program { + public final static String ADULT_HIV_PROGRAM = "cf7c0e30-2700-102b-80cb-0017a47871b2"; + public final static String PEDI_HIV_PROGRAM = "cf7c16e6-2700-102b-80cb-0017a47871b2"; + public final static String PMTCT_PREGNANCY_PROGRAM = "cf7c13da-2700-102b-80cb-0017a47871b2"; + public final static String PMTCT_COMBINED_MOTHER_PROGRAM = "2f7506b4-21e6-445d-ba73-2c782a6ecbee"; + } + + /** + * @see org.openmrs.module.metadatadeploy.bundle.MetadataBundle#install() + */ + @Override + public void install() { + + install(program("Adult HIV program", "PIH Adult HIV program", Dictionary.ADULT_HIV_PROGRAM, _Program.ADULT_HIV_PROGRAM)); + install(program("Pedi HIV program", "PIH Pediatric HIV program", Dictionary.PEDI_HIV_PROGRAM, _Program.PEDI_HIV_PROGRAM)); + install(program("PMTCT Pregnancy program", "PIH PMTCT Pregnancy program", Dictionary.PMTCT_PREGNANCY_PROGRAM, _Program.PMTCT_PREGNANCY_PROGRAM)); + install(program("PMTCT Combined Mother program", "PIH PMTCT Combined Mother program", Dictionary.PMTCT_COMBINED_MOTHER_PROGRAM, _Program.PMTCT_COMBINED_MOTHER_PROGRAM)); + + } + +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/common/DataQualityIndicatorReportBuilder.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/common/DataQualityIndicatorReportBuilder.java new file mode 100644 index 00000000..1caf0a2b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/common/DataQualityIndicatorReportBuilder.java @@ -0,0 +1,42 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.builder.common; + +import org.openmrs.module.reporting.report.definition.ReportDefinition; + + +/** + * + */ +public class DataQualityIndicatorReportBuilder implements ReportBuilder { + + /** + * @see org.openmrs.module.rwandareports.reporting.builder.common.ReportBuilder#build() + */ + @Override + public ReportDefinition build() { + // TODO Auto-generated method stub + return null; + } + + /** + * @see org.openmrs.module.rwandareports.reporting.builder.common.ReportBuilder#delete() + */ + @Override + public void delete() { + // TODO Auto-generated method stub + + } + +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/common/ReportBuilder.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/common/ReportBuilder.java new file mode 100644 index 00000000..e8748f48 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/common/ReportBuilder.java @@ -0,0 +1,32 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.builder.common; + +import org.openmrs.module.reporting.report.definition.ReportDefinition; + +/** + * Interface for a class that can build/delete a report + */ +public interface ReportBuilder { + + /** + * Builds a report definition for the given report + */ + ReportDefinition build(); + + /** + * Deletes a report + */ + void delete(); +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/hiv/QuarterlyCrossSiteIndicatorByDistrictReportBuilder.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/hiv/QuarterlyCrossSiteIndicatorByDistrictReportBuilder.java new file mode 100644 index 00000000..f21e53ad --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/builder/hiv/QuarterlyCrossSiteIndicatorByDistrictReportBuilder.java @@ -0,0 +1,121 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.builder.hiv; + +import java.util.Date; +import java.util.Properties; + +import org.openmrs.api.context.Context; +import org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition; +import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.reporting.evaluation.parameter.ParameterizableUtil; +import org.openmrs.module.reporting.report.ReportDesign; +import org.openmrs.module.reporting.report.definition.ReportDefinition; +import org.openmrs.module.reporting.report.service.ReportService; +import org.openmrs.module.rwandareports.dataset.LocationHierachyIndicatorDataSetDefinition; +import org.openmrs.module.rwandareports.reporting.Helper; +import org.openmrs.module.rwandareports.reporting.builder.common.ReportBuilder; +import org.openmrs.module.rwandareports.reporting.library.shared.hiv.HivIndicatorLibrary; +import org.openmrs.module.rwandareports.util.ReportUtils; +import org.openmrs.module.rwandareports.widget.AllLocation; +import org.openmrs.module.rwandareports.widget.LocationHierarchy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * PIH-Boston Indicators-Quarterly + */ +@Component +public class QuarterlyCrossSiteIndicatorByDistrictReportBuilder implements ReportBuilder { + + @Autowired + private HivIndicatorLibrary hivIndicators; + + /** + * @see org.openmrs.module.rwandareports.reporting.builder.common.ReportBuilder#build() + */ + @Override + public ReportDefinition build() { + // PIH Quarterly Cross Site Indicator Report + ReportDefinition rd = new ReportDefinition(); + rd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + rd.addParameter(new Parameter("endDate", "End Date", Date.class)); + + Properties properties = new Properties(); + properties.setProperty("hierarchyFields", "countyDistrict:District"); + rd.addParameter(new Parameter("location", "Location", AllLocation.class, properties)); + + rd.setName("PIH-Boston Indicators-Quarterly"); + + rd.addDataSetDefinition(createDataSet(), + ParameterizableUtil.createParameterMappings("startDate=${startDate},endDate=${endDate},location=${location}")); + + Helper.saveReportDefinition(rd); + return null; + } + + /** + * @see org.openmrs.module.rwandareports.reporting.builder.common.ReportBuilder#delete() + */ + @Override + public void delete() { + + ReportService rs = Context.getService(ReportService.class); + for (ReportDesign rd : rs.getAllReportDesigns(false)) { + if ("PIH Quarterly Indicator Form (Excel)_".equals(rd.getName()) + || "PIH Quarterly Indicator Graph (Excel)_".equals(rd.getName())) { + rs.purgeReportDesign(rd); + } + } + Helper.purgeReportDefinition("PIH-Boston Indicators-Quarterly"); + + } + + /** + * Creates the LocationHierachyIndicatorDataSetDefinition dataset which has a + * CohortIndicatorDataSetDefinition on it. + * + * @return the dataset + */ + private DataSetDefinition createDataSet() { + + LocationHierachyIndicatorDataSetDefinition ldsd = new LocationHierachyIndicatorDataSetDefinition(createBaseDataSet()); + ldsd.setName("PIH_Quarterly_Individual_District_Indicator Data Set"); + ldsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + ldsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + ldsd.addParameter(new Parameter("location", "District", LocationHierarchy.class)); + + return ldsd; + } + + /** + * Creates a CohortIndicatorDataSetDefinition + * + * @return the dataset + */ + private CohortIndicatorDataSetDefinition createBaseDataSet() { + CohortIndicatorDataSetDefinition dsd = new CohortIndicatorDataSetDefinition(); + dsd.setName("PIH_Quarterly_Individual_District_Indicator Cohort Data Set"); + dsd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dsd.addParameter(new Parameter("endDate", "End Date", Date.class)); + + String indParams = "startDate=${startDate},endDate=${endDate}"; + + dsd.addColumn("1", "In All HIV Programs Over 15", ReportUtils.map(hivIndicators.inAllHIVProgramsOver15(), indParams), ""); + + return dsd; + } + +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/common/CommonCohortLibrary.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/common/CommonCohortLibrary.java new file mode 100644 index 00000000..68518ccc --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/common/CommonCohortLibrary.java @@ -0,0 +1,97 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.library.shared.common; + +import java.util.Date; +import java.util.List; + +import org.openmrs.Program; +import org.openmrs.module.reporting.cohort.definition.AgeCohortDefinition; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.cohort.definition.GenderCohortDefinition; +import org.openmrs.module.reporting.cohort.definition.InProgramCohortDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.springframework.stereotype.Component; + +/** + * Library of common cohort definitions + */ +@Component +public class CommonCohortLibrary { + + /** + * Patients who are female + * + * @return the cohort definition + */ + public CohortDefinition females() { + GenderCohortDefinition cd = new GenderCohortDefinition(); + cd.setName("females"); + cd.setFemaleIncluded(true); + return cd; + } + + /** + * Patients who are male + * + * @return the cohort definition + */ + public CohortDefinition males() { + GenderCohortDefinition cd = new GenderCohortDefinition(); + cd.setName("males"); + cd.setMaleIncluded(true); + return cd; + } + + /** + * Patients who at most maxAge years old on ${effectiveDate} + * + * @return the cohort definition + */ + public CohortDefinition agedAtMost(int maxAge) { + AgeCohortDefinition cd = new AgeCohortDefinition(); + cd.setName("aged at most"); + cd.addParameter(new Parameter("effectiveDate", "Effective Date", Date.class)); + cd.setMaxAge(maxAge); + return cd; + } + + /** + * Patients who are at least minAge years old on ${effectiveDate} + * + * @return the cohort definition + */ + public CohortDefinition agedAtLeast(int minAge) { + AgeCohortDefinition cd = new AgeCohortDefinition(); + cd.setName("aged at least"); + cd.addParameter(new Parameter("effectiveDate", "Effective Date", Date.class)); + cd.setMinAge(minAge); + return cd; + } + + public InProgramCohortDefinition inProgram(String name, List programs) { + InProgramCohortDefinition inProgram = new InProgramCohortDefinition(); + inProgram.setName(name); + + inProgram.setPrograms(programs); + + return inProgram; + } + + public InProgramCohortDefinition inProgramParameterizableByDate(String name, List programs, String parameterName) { + InProgramCohortDefinition inProgram = inProgram(name, programs); + inProgram.addParameter(new Parameter(parameterName, parameterName, Date.class)); + return inProgram; + } +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/common/CommonIndicatorLibrary.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/common/CommonIndicatorLibrary.java new file mode 100644 index 00000000..8739ceb7 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/common/CommonIndicatorLibrary.java @@ -0,0 +1,25 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.library.shared.common; + +import org.springframework.stereotype.Component; + + +/** + * Library of common indicator definitions. + */ +@Component +public class CommonIndicatorLibrary { + +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/hiv/HivCohortLibrary.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/hiv/HivCohortLibrary.java new file mode 100644 index 00000000..c47b9cda --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/hiv/HivCohortLibrary.java @@ -0,0 +1,69 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.library.shared.hiv; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.openmrs.Program; +import org.openmrs.module.reporting.cohort.definition.CohortDefinition; +import org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition; +import org.openmrs.module.reporting.cohort.definition.InProgramCohortDefinition; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.rwandareports.metadata.HivMetadata; +import org.openmrs.module.rwandareports.reporting.library.shared.common.CommonCohortLibrary; +import org.openmrs.module.rwandareports.util.MetadataLookup; +import org.openmrs.module.rwandareports.util.ReportUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Library of HIV related cohort definitions + */ +@Component +public class HivCohortLibrary { + + @Autowired + private CommonCohortLibrary commonCohorts; + + /** + * Auto generated method comment + * + * @return + */ + public CohortDefinition inHIVOver15() { + + CohortDefinition over15Cohort = commonCohorts.agedAtLeast(15); + + List hivPrograms = new ArrayList(); + + hivPrograms.add(MetadataLookup.getProgram(HivMetadata._Program.ADULT_HIV_PROGRAM)); + hivPrograms.add(MetadataLookup.getProgram(HivMetadata._Program.PEDI_HIV_PROGRAM)); + hivPrograms.add(MetadataLookup.getProgram(HivMetadata._Program.PMTCT_PREGNANCY_PROGRAM)); + hivPrograms.add(MetadataLookup.getProgram(HivMetadata._Program.PMTCT_COMBINED_MOTHER_PROGRAM)); + + InProgramCohortDefinition inAnyHIVProgram = commonCohorts.inProgramParameterizableByDate( + "hivQD: In All HIV Programs", hivPrograms, "onOrBefore"); + + CompositionCohortDefinition inHIVOver15 = new CompositionCohortDefinition(); + inHIVOver15.setName("hivQD: In all programs over 15"); + inHIVOver15.addParameter(new Parameter("endDate", "endDate", Date.class)); + inHIVOver15.addSearch("1", ReportUtils.map(over15Cohort, "effectiveDate=${endDate}")); + inHIVOver15.addSearch("2", ReportUtils.map(inAnyHIVProgram, "onOrBefore=${endDate}")); + inHIVOver15.setCompositionString("1 AND 2"); + + return inHIVOver15; + } +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/hiv/HivIndicatorLibrary.java b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/hiv/HivIndicatorLibrary.java new file mode 100644 index 00000000..049416b2 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/reporting/library/shared/hiv/HivIndicatorLibrary.java @@ -0,0 +1,36 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.rwandareports.reporting.library.shared.hiv; + +import static org.openmrs.module.rwandareports.util.Indicators.newCountIndicator; + +import org.openmrs.module.reporting.evaluation.parameter.ParameterizableUtil; +import org.openmrs.module.reporting.indicator.CohortIndicator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +/** + * Library of HIV related indicator definitions. + */ +@Component +public class HivIndicatorLibrary { + + @Autowired + private HivCohortLibrary hivCohorts; + + public CohortIndicator inAllHIVProgramsOver15() { + return newCountIndicator("hivQD: In all programs over 15_", hivCohorts.inHIVOver15(),ParameterizableUtil.createParameterMappings("endDate=${endDate}")); + } +} diff --git a/api/src/main/java/org/openmrs/module/rwandareports/util/ReportUtils.java b/api/src/main/java/org/openmrs/module/rwandareports/util/ReportUtils.java new file mode 100644 index 00000000..80c2dbc3 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/rwandareports/util/ReportUtils.java @@ -0,0 +1,79 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ + +package org.openmrs.module.rwandareports.util; + +import org.openmrs.module.reporting.evaluation.parameter.Mapped; +import org.openmrs.module.reporting.evaluation.parameter.Parameterizable; +import org.openmrs.module.reporting.evaluation.parameter.ParameterizableUtil; + +import java.util.HashMap; +import java.util.Map; + +/** + * Utility methods for reporting + */ +public class ReportUtils { + + /** + * Maps a parameterizable item with no parameters + * @param parameterizable the parameterizable item + * @param + * @return the mapped item + */ + public static Mapped map(T parameterizable) { + if (parameterizable == null) { + throw new IllegalArgumentException("Parameterizable cannot be null"); + } + return new Mapped(parameterizable, null); + } + + /** + * Maps a parameterizable item using a string list of parameters and values + * @param parameterizable the parameterizable item + * @param mappings the string list of mappings + * @param + * @return the mapped item + */ + public static Mapped map(T parameterizable, String mappings) { + if (parameterizable == null) { + throw new IllegalArgumentException("Parameterizable cannot be null"); + } + if (mappings == null) { + mappings = ""; // probably not necessary, just to be safe + } + return new Mapped(parameterizable, ParameterizableUtil.createParameterMappings(mappings)); + } + + /** + * Maps a parameterizable item using a string list of parameters and values + * @param parameterizable the parameterizable item + * @param mappings the string list of mappings + * @param + * @return the mapped item + */ + public static Mapped map(T parameterizable, Object ... mappings) { + if (parameterizable == null) { + throw new IllegalArgumentException("Parameterizable cannot be null"); + } + + Map paramMap = new HashMap(); + for (int m = 0; m < mappings.length; m += 2) { + String param = (String) mappings[m]; + Object value = mappings[m + 1]; + paramMap.put(param, value); + } + return new Mapped(parameterizable, paramMap); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/rwandareports/DictionaryTest.java b/api/src/test/java/org/openmrs/module/rwandareports/DictionaryTest.java new file mode 100644 index 00000000..282769f4 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/rwandareports/DictionaryTest.java @@ -0,0 +1,82 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ + +package org.openmrs.module.rwandareports; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openmrs.Concept; +import org.openmrs.api.context.Context; +import org.openmrs.test.BaseModuleContextSensitiveTest; + +/** + * Tests for {@link Dictionary} + */ +public class DictionaryTest extends BaseModuleContextSensitiveTest { + + /** + * Setup each test + */ + @Before + public void setup() throws Exception { + executeDataSet("dataset/test-concepts.xml"); + } + + @Test + public void integration() { + new Dictionary(); + } + + /** + * @see Dictionary#getConcept(String) + */ + @Test + public void getConcept_shouldFetchByMappingOrUuid() { + // Check lookup by UUID + Concept adultHivProgramConcept = Context.getConceptService().getConceptByUuid(Dictionary.ADULT_HIV_PROGRAM); + Concept fetched = Dictionary.getConcept(Dictionary.ADULT_HIV_PROGRAM); + Assert.assertThat(fetched, is(adultHivProgramConcept)); + } + + /** + * @see Dictionary#getConcept(String) + */ + @Test(expected = IllegalArgumentException.class) + public void getConcept_shouldThrowExceptionForNonExistent() { + Dictionary.getConcept("PIH:XXXXXXXXXXXXXXX"); + } + + /** + * @see Dictionary#getConcepts(String...) + */ + @Test + public void getConcepts_shouldFetchByMappingOrUuid() { + // Check lookup by UUID + Concept adultHivProgramConcept = Context.getConceptService().getConceptByUuid(Dictionary.ADULT_HIV_PROGRAM); + Concept pediHivProgramConcept = Context.getConceptService().getConceptByUuid(Dictionary.PEDI_HIV_PROGRAM); + Assert.assertThat(Dictionary.getConcepts(Dictionary.ADULT_HIV_PROGRAM, Dictionary.PEDI_HIV_PROGRAM), contains(adultHivProgramConcept, pediHivProgramConcept)); + } + + /** + * @see Dictionary#getConcepts(String...) + */ + @Test(expected = IllegalArgumentException.class) + public void getConcepts_shouldThrowExceptionForNonExistent() { + Dictionary.getConcepts(Dictionary.ADULT_HIV_PROGRAM, "PIH:XXXXXXXXXXXXXXX"); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/rwandareports/metadata/CommonMetadataTest.java b/api/src/test/java/org/openmrs/module/rwandareports/metadata/CommonMetadataTest.java new file mode 100644 index 00000000..eeac6190 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/rwandareports/metadata/CommonMetadataTest.java @@ -0,0 +1,45 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ + +package org.openmrs.module.rwandareports.metadata; + +import org.junit.Before; +import org.junit.Test; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Tests for {@link CommonMetadata} + */ +public class CommonMetadataTest extends BaseModuleContextSensitiveTest { + + @Autowired + private CommonMetadata commonMetadata; + + /** + * Setup each test + */ + @Before + public void setup() throws Exception { + executeDataSet("dataset/test-concepts.xml"); + } + + /** + * @see CommonMetadata#install() + */ + @Test + public void install_shouldInstallAllMetadata() { + commonMetadata.install(); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/rwandareports/metadata/HivMetadataTest.java b/api/src/test/java/org/openmrs/module/rwandareports/metadata/HivMetadataTest.java new file mode 100644 index 00000000..45120e7d --- /dev/null +++ b/api/src/test/java/org/openmrs/module/rwandareports/metadata/HivMetadataTest.java @@ -0,0 +1,49 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ + +package org.openmrs.module.rwandareports.metadata; + +import org.junit.Before; +import org.junit.Test; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Tests for {@link HivMetadata} + */ +public class HivMetadataTest extends BaseModuleContextSensitiveTest { + + @Autowired + private CommonMetadata commonMetadata; + + @Autowired + private HivMetadata hivMetadata; + + /** + * Setup each test + */ + @Before + public void setup() throws Exception { + executeDataSet("dataset/test-concepts.xml"); + } + + /** + * @see HivMetadata#install() + */ + @Test + public void install_shouldInstallAllMetadata() { + commonMetadata.install(); + hivMetadata.install(); + } +} \ No newline at end of file diff --git a/api/src/test/resources/dataset/test-concepts.xml b/api/src/test/resources/dataset/test-concepts.xml new file mode 100644 index 00000000..9a4e1a5a --- /dev/null +++ b/api/src/test/resources/dataset/test-concepts.xml @@ -0,0 +1,3055 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8388b254..fbca1e1e 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 2.0.7-SNAPSHOT 2.2 0.5.2 + 0.2 UTF-8 ${project.parent.artifactId} ${project.parent.name} @@ -192,7 +193,16 @@ commons-dbutils 1.5 - + + + org.openmrs.module + metadatadeploy-api + ${metadatadeployVersion} + provided + + + + ch.vorburger.mariaDB4j mariaDB4j @@ -200,6 +210,14 @@ test + + org.hamcrest + hamcrest-all + 1.3 + + + +