private boolean canUpdateVirtualFacilities(Facility newFacility, Facility oldFacility) { return (oldFacility == null || !(newFacility .getGeographicZone() .getCode() .equals(oldFacility.getGeographicZone().getCode())) || !(newFacility .getFacilityType() .getCode() .equals(oldFacility.getFacilityType().getCode()))); }
public List<Facility> getAllForDeliveryZoneAndProgram(Long deliveryZoneId, Long programId) { List<Facility> facilities = facilityRepository.getAllInDeliveryZoneFor(deliveryZoneId, programId); for (Facility facility : facilities) { facility .getSupportedPrograms() .add( programSupportedService.getFilledByFacilityIdAndProgramId( facility.getId(), programId)); } return facilities; }
public Facility getOperativeFacilityByCode(String facilityCode) { Facility facility = getFacilityByCode(facilityCode); Facility parentFacility = null; if (facility.getVirtualFacility()) { parentFacility = facilityRepository.getById(facility.getParentFacilityId()); } if (!facility.isValid(parentFacility)) { throw new DataException("error.facility.inoperative"); } return facility; }
public void save(Facility newFacility) { newFacility.validate(); Facility storedFacility = facilityRepository.getById(newFacility.getId()); facilityRepository.save(newFacility); if (!newFacility.equals(storedFacility)) { notify(asList(newFacility)); if (canUpdateVirtualFacilities(newFacility, storedFacility)) { updateAndNotifyForVirtualFacilities(newFacility); } } }
@Test public void shouldCreateCoverageLineItemWhenTargetGroupProductIsNotNull() { FacilityVisit facilityVisit = new FacilityVisit(); facilityVisit.setId(1L); Facility facility = mock(Facility.class); when(facility.getCatchmentPopulation()).thenReturn(100L); String productCode = "P10"; TargetGroupProduct targetGroupProduct = new TargetGroupProduct("BCG", productCode, true); when(facility.getWhoRatioFor(productCode)).thenReturn(67D); CoverageLineItem coverageLineItem = new CoverageLineItem(facilityVisit, facility, targetGroupProduct); assertThat(coverageLineItem.getFacilityVisitId(), is(facilityVisit.getId())); assertThat(coverageLineItem.getTargetGroup(), is(67)); }
public Facility getFacilityByCode(String facilityCode) { Facility facility; if ((facility = facilityRepository.getByCode(facilityCode)) == null) { throw new DataException(ERROR_FACILITY_CODE_INVALID); } facility.setSupportedPrograms( (List<ProgramSupported>) select( facility.getSupportedPrograms(), new Predicate() { @Override public boolean evaluate(Object o) { return ((ProgramSupported) o).getActive(); } })); return facility; }
private void notify(List<Facility> facilities) { // TODO newFacility doesn't have modifiedDate populated for (Facility facility : facilities) { try { Facility parentFacility = facilityRepository.getById(facility.getParentFacilityId()); FacilityFeedDTO facilityFeedDTO = new FacilityFeedDTO(facility, parentFacility); String content = facilityFeedDTO.getSerializedContents(); eventService.notify( new Event( UUID.randomUUID().toString(), FACILITY_TITLE, DateTime.now(), "", content, FACILITY_CATEGORY)); } catch (URISyntaxException e) { logger.error("Unable to generate facility event", e); } } }
public Facility getById(Long id) { Facility facility = facilityRepository.getById(id); facility.setSupportedPrograms(programSupportedService.getAllByFacilityId(id)); return facility; }
public Facility getByCode(Facility facility) { return facilityRepository.getByCode(facility.getCode()); }