HibernateDHIS2ReportingDAO implements DHIS2ReportingDAO { @Override public String evaluateDataValueTemplate(DataValueTemplate dvt, Period period, Location location, boolean priority) throws DHIS2ReportingException { String queryString = dvt.getQuery(); queryString = queryString.replaceAll("\t", " "); queryString = queryString.replaceAll("\n", " "); queryString = queryString.trim(); String mappedUuid = dvt.getMappeddefinitionuuid(); if (queryString == null || queryString.isEmpty() || (priority && mappedUuid != null)) { org.openmrs.module.reporting.report.definition.ReportDefinition rrd = Context .getService(ReportDefinitionService.class) .getDefinitionByUuid(dvt.getMappeddefinitionuuid()); try { return getReport(rrd, dvt.getMappeddefinitionlabel(), location, period).toString(); } catch (EvaluationException ex) { log.debug("Evaluation Exception : " + ex.getMessage()); } } if (dvt.potentialUpdateDelete()) { throw new DHIS2ReportingException( "Attempt to execute potential update/delete query for " + dvt.getDataelement().getName() + " : " + dvt.getDisaggregation().getName()); } Query query = getCurrentSession().createSQLQuery(queryString); List<String> parameters = new ArrayList<String>(Arrays.asList(query .getNamedParameters())); if (parameters.contains("locationId")) { query.setParameter("locationId", location.getId().toString()); } query.setParameter("startOfPeriod", period.getStartDate()); query.setParameter("endOfPeriod", period.getEndDate()); return query.uniqueResult().toString(); }  void setSessionFactory(SessionFactory sessionFactory); SessionFactory getSessionFactory(); @Override DataElement getDataElement(Integer id); @Override DataElement saveDataElement(DataElement de); @Override void deleteDataElement(DataElement de); @Override Disaggregation getDisaggregation(Integer id); @Override Disaggregation saveDisaggregation(Disaggregation disagg); @Override ReportDefinition getReportDefinition(Integer id); @Override ReportDefinition saveReportDefinition(ReportDefinition rd); @Override Collection<DataElement> getAllDataElements(); @Override Collection<Disaggregation> getAllDisaggregations(); @Override void deleteDisaggregation(Disaggregation disagg); @Override Collection<ReportDefinition> getAllReportDefinitions(); @Override void deleteReportDefinition(ReportDefinition rd); @Override String evaluateDataValueTemplate(DataValueTemplate dvt,
			Period period, Location location, boolean priority); Identifiable getObjectByUid(String uid, Class<?> clazz); @Transactional Identifiable saveReportDefinitionObject(ReportDefinition object); @Transactional Identifiable saveDataElementObject(DataElement object); @Transactional Identifiable saveObject(Identifiable object); @Override DataElement getDataElementByUid(String uid); @Override Disaggregation getDisaggregationByUid(String uid); @Override ReportDefinition getReportDefinitionByUid(String uid); @Override ReportDefinition getReportDefinitionByCode(String code); @Override DataValueTemplate getDataValueTemplate(Integer id); @Override DataValueTemplate saveDataValueTemplate(DataValueTemplate dvt); @Override DataValueTemplate saveDataValueTemplateTest(DataValueTemplate dvt); @Override Location getLocationByOU_Code(String OU_Code); @Override DataElement getDataElementByCode(String code);  }
@Test public void shouldevaluateDataValueTemplate() throws DHIS2ReportingException, JAXBException, IOException, ParseException { 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) { for (DataValueTemplate r : rd.getDataValueTemplates()) { String dvs = dao.evaluateDataValueTemplate(r, period, location, false); assertEquals("3", dvs); } } }