DHIS2ReportingServiceImpl extends BaseOpenmrsService implements
			DHIS2ReportingService { @Override public Location getLocationByOrgUnitCode(String orgUnitCode) { List<Location> locationList = new ArrayList<Location>(); locationList.addAll(Context.getLocationService().getAllLocations()); for (Location l : locationList) { for (LocationAttribute la : l.getActiveAttributes()) { if (la.getAttributeType().getName().equals("CODE")) { if ((la.getValue().toString()).equals(orgUnitCode)) { return l; } } } } return null; }  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 shouldgetLocationByOrgUnitCode() throws Exception { Location loc = new Location(); loc.setName("testing"); loc.setDescription("desc"); loc.setAddress1("123"); loc.setAddress1("456"); loc.setCityVillage("city"); loc.setStateProvince("state"); loc.setCountry("country"); loc.setPostalCode("post"); loc.setLatitude("lat"); loc.setLongitude("lon"); LocationAttributeType attributetype = new LocationAttributeType(); attributetype.setName("CODE"); attributetype .setDescription("Corresponding Value of ORG UNITS for DHIS"); attributetype.setMinOccurs(0); attributetype.setMaxOccurs(1); attributetype .setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype"); Context.getLocationService().saveLocationAttributeType(attributetype); LocationAttribute locationAttribute = new LocationAttribute(); locationAttribute.setAttributeType(attributetype); locationAttribute.setValue("dhis2OrgUnitCode"); loc.setAttribute(locationAttribute); Context.getLocationService().saveLocation(loc); Location l = dhis2ReportingService .getLocationByOrgUnitCode("dhis2OrgUnitCode"); assertEquals(loc, l); assertTrue(loc.equals(l)); assertEquals("testing", l.getName()); assertEquals("country", l.getCountry()); }