-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report Testing examples for rwandareports #8
base: master
Are you sure you want to change the base?
Changes from all commits
2838b6d
b88ea9a
a3a5df1
1c062d2
bdf28f4
5639c86
bd0c6c2
496e8a7
781ea88
1e3ab90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Concept> getConcepts(String... identifiers) { | ||
List<Concept> concepts = new ArrayList<Concept>(); | ||
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"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not personally a huge fan of classes that start with "_". Not sure why Rowan does this, but worth checking with him. I'd also probably also make such things enums rather than public static final classes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The _ convention is to avoid name conflicts with the actual classes. Enums would buy you some type safety but then it would be harder to implement a single MetadataUtils.getLocation(...) method. You'd have to find a way to associate the enum value with the UUID, and you'd have the problem of CommonMetadata._Location being a different class to HivMetadata._Location etc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had originally assumed this was the reason. But - maybe I'm missing something - but HivMetadata doesn't inherit from CommonMetadata, so I'm not sure how HivMetadata would expose the same ._Location class as the one used in CommonMetadata. I get your point with enums, though enums can implement interfaces, so you could do something like this: public interface LocationBuilder { public enum CoreLocations implements LocationBuilder { public enum HivLocations implements LocationBuilder { Then, in your install tools can do something like: public void install(LocationBuilder locationBuilder) { Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant about name conflicts is that HivMetadata.Location conflicts with org.openmrs.Location. I like your enum idea because it means that metadata identification isn't separate from description. Not entirely sure though how MetadataUtils.getLocation(LocationBuilder builder) {} would work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume it would just do: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've done a bit of experimenting with this approach but it gets verbose very quickly for one reason: Java doesn't support Enum super classes. So every builder class has to re-implement all the builder interface methods. It also doesn't lend itself to supporting different ways of deploying metadata. Currently bundles are completely agnostic about how metadata objects are created so you can implement whatever custom logic you need. In KenyaEMR, our location metadata bundle actually synchronises against a CSV list of locations. String constants aren't ideal but they are simple to work with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this could potentially be handled via injection though, right? i.e. instead of having a class hierarchy that provides these base methods, add another property on the enum that is a "Class<? extends MetadataBuilder> builder". Then there would just be a common method shared by all that simply instantiates a new builder and passes itself into the "build(...)" method. Possibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything is a possibility but currently String constants are working just fine :) Consider also that the MetadataUtils.getX() methods all throw exceptions if the requested item doesn't exist, so even if you did manage to type something like MetadataUtils.getLocation(HivMetadata._Form.REGISTRATION), you'd get a fairly clear exception right away. |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to install the unknown location? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see bundles as serving two purposes - deploying the metadata and providing identification of the metadata. So sometimes I reference metadata in a bundle which doesn't actually install it because it's standard metadata from core. Perhaps it would be better to move this to it's own class like "CoreMetadata". |
||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as with _Location |
||
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)); | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class looks a lot like the existing "SetupReport" class that all of the existing "SetupXYZ" classes implement. That's fine, but we might want to think about a gradual migration by refactoring the existing classes rather than setting up a completely new package structure in parallel. In Mirebalais, we have another variation on this: https://github.com/PIH/openmrs-module-mirebalaisreports/blob/master/api/src/main/java/org/openmrs/module/mirebalaisreports/definitions/ReportManager.java Not sure we've got it exactly right there either, but would be worth finding a common interface strategy for this, and putting it into the reporting module as a standard that everyone could use. |
||
* 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(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we have this "Dictionary" class. Wouldn't these constants go under the equivalent HivMetadata._Concept ? The utility methods should likely go into a set of shareable utils in a common module or jar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this was inspired by KenyaEMR code. We keep constants in separate Dictionary class because we generally treat them differently to other metadata objects. They are installed in production via a sql dump, and for testing we have a Groovy script to generate an XML dataset file from the Dictionary class. We could split them off into categorised bundle classes but frankly I find it easier to keep track of them if they are all in one file.