DHIS2ReportingServiceImpl extends BaseOpenmrsService implements
			DHIS2ReportingService { @Override public DataValueSet evaluateReportDefinition( ReportDefinition reportDefinition, Period period, Location location, boolean priority) { Collection<DataValueTemplate> templates = reportDefinition .getDataValueTemplates(); DataValueSet dataValueSet = new DataValueSet(); dataValueSet.setDataElementIdScheme("code"); dataValueSet.setOrgUnitIdScheme("code"); dataValueSet.setPeriod(period.getAsIsoString()); dataValueSet.setDataSet(reportDefinition.getCode()); Collection<DataValue> dataValues = dataValueSet.getDataValues(); for (DataValueTemplate dvt : templates) { DataValue dataValue = new DataValue(); dataValue.setDataElement(dvt.getDataelement().getCode()); dataValue.setCategoryOptionCombo(dvt.getDisaggregation().getCode()); try { String value = dao.evaluateDataValueTemplate(dvt, period, location, priority); if (value != null) { dataValue.setValue(value); dataValues.add(dataValue); } } catch (DHIS2ReportingException ex) { log.warn(ex.getMessage()); } } return dataValueSet; }  void setDao(DHIS2ReportingDAO dao); DHIS2ReportingDAO getDao(); @Override HttpDhis2Server getDhis2Server(); @Override void setDhis2Server(HttpDhis2Server dhis2Server); @Override ReportDefinition fetchReportTemplates(); @Override ImportSummary postDataValueSet(DataValueSet dvset); @Override AdxImportSummary postAdxReport(AdxType adxReport); @Override DataElement getDataElement(Integer id); @Override DataElement getDataElementByUid(String uid); @Override DataElement getDataElementByCode(String code); @Override DataElement saveDataElement(DataElement de); @Override void purgeDataElement(DataElement de); @Override Disaggregation getDisaggregation(Integer id); @Override Disaggregation saveDisaggregation(Disaggregation disagg); @Override ReportDefinition getReportDefinition(Integer id); ReportDefinition getReportDefinitionByUId(String uid); ReportDefinition getReportDefinitionByCode(String code); @Override ReportDefinition saveReportDefinition(
			ReportDefinition reportDefinition); @Override Collection<DataElement> getAllDataElements(); @Override void purgeDisaggregation(Disaggregation disagg); @Override Collection<Disaggregation> getAllDisaggregations(); @Override void purgeReportDefinition(ReportDefinition rd); @Override Collection<ReportDefinition> getAllReportDefinitions(); @Override String evaluateDataValueTemplate(DataValueTemplate dv,
			Period period, Location location); @Override DataValueSet evaluateReportDefinition(
			ReportDefinition reportDefinition, Period period,
			Location location, boolean priority); @Override DataValueSet generateReportingReportDefinition(
			ReportDefinition reportDefinition, Period period, Location location); @Override void saveReportTemplates(ReportTemplates rt); void unMarshallandSaveReportTemplates(InputStream is); @Override ReportTemplates getReportTemplates(); @Override void marshallReportTemplates(OutputStream os, ReportTemplates rt); @Override DataValueTemplate getDataValueTemplate(Integer id); @Override void saveDataValueTemplate(DataValueTemplate dvt); @Override void saveDataValueTemplateTest(DataValueTemplate dvt); @Override Location getLocationByOU_Code(String OU_Code); @Override Location getLocationByOrgUnitCode(String orgUnitCode);  }
@Test public void evaluateReportDefinition_shouldEvaluateReportDefinition() throws Exception { ClassPathResource resource = new ClassPathResource( "reportDefinition.xml"); JAXBContext jaxbContext = JAXBContext .newInstance(ReportTemplates.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); ReportTemplates reportTemplates = (ReportTemplates) jaxbUnmarshaller .unmarshal(resource.getInputStream()); List<ReportDefinition> rds = reportTemplates.getReportDefinitions(); String timeperiod = "2016-06-28"; Location location = new Location(); location.setName("County General"); location.setDescription("desc"); location.setAddress1("address1"); location.setId(3); Period period = new MonthlyPeriod(new SimpleDateFormat("yyyy-MM-dd") .parse(timeperiod)); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); String start = "2016-06-28"; String end = "2016-06-30"; Date startDate = null; Date endDate = null; startDate = dateformat.parse(start); endDate = dateformat.parse(end); period.setStartDate(startDate); period.setEndDate(endDate); for (ReportDefinition rd : rds) { DataValueSet dvs = dhis2ReportingService.evaluateReportDefinition( rd, period, location, false); List<DataValue> datavalues = dvs.getDataValues(); for (DataValue dv : datavalues) { assertEquals("0", dv.getValue()); } } executeDataSet(INITIAL_OBS_XML); for (ReportDefinition rd : rds) { DataValueSet dvs = dhis2ReportingService.evaluateReportDefinition( rd, period, location, false); List<DataValue> datavalues = dvs.getDataValues(); for (DataValue dv : datavalues) { assertEquals("3", dv.getValue()); } } }