コード例 #1
0
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
 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
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
 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
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
  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
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
  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);
      }
    }
  }
コード例 #5
0
  @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
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
  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
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
 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
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
 public Facility getById(Long id) {
   Facility facility = facilityRepository.getById(id);
   facility.setSupportedPrograms(programSupportedService.getAllByFacilityId(id));
   return facility;
 }
コード例 #9
0
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
 public Facility getByCode(Facility facility) {
   return facilityRepository.getByCode(facility.getCode());
 }