示例#1
0
 private boolean canUpdateVirtualFacilities(Facility newFacility, Facility oldFacility) {
   return (oldFacility == null
       || !(newFacility
           .getGeographicZone()
           .getCode()
           .equals(oldFacility.getGeographicZone().getCode()))
       || !(newFacility
           .getFacilityType()
           .getCode()
           .equals(oldFacility.getFacilityType().getCode())));
 }
示例#2
0
 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;
 }
示例#3
0
  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;
  }
示例#4
0
  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));
  }
示例#6
0
  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;
  }
示例#7
0
 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);
     }
   }
 }
示例#8
0
 public Facility getById(Long id) {
   Facility facility = facilityRepository.getById(id);
   facility.setSupportedPrograms(programSupportedService.getAllByFacilityId(id));
   return facility;
 }
示例#9
0
 public Facility getByCode(Facility facility) {
   return facilityRepository.getByCode(facility.getCode());
 }