Example #1
0
 public List<Facility> searchFacilitiesByCodeOrNameAndVirtualFacilityFlag(
     String query, Boolean virtualFacility) {
   if (virtualFacility == null) {
     return facilityRepository.searchFacilitiesByCodeOrName(query);
   }
   return facilityRepository.searchFacilitiesByCodeOrNameAndVirtualFacilityFlag(
       query, virtualFacility);
 }
Example #2
0
  public List<Facility> getForUserAndRights(Long userId, Right... rights) {
    List<SupervisoryNode> supervisoryNodesInHierarchy =
        supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rights);
    List<RequisitionGroup> requisitionGroups =
        requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy);
    final Set<Facility> userFacilities =
        new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups));
    final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rights);

    if (homeFacility != null) userFacilities.add(homeFacility);

    return new ArrayList<>(userFacilities);
  }
Example #3
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);
      }
    }
  }
Example #4
0
 public List<Facility> getUserSupervisedFacilities(Long userId, Long programId, Right... rights) {
   List<SupervisoryNode> supervisoryNodes =
       supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, rights);
   List<RequisitionGroup> requisitionGroups =
       requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes);
   return facilityRepository.getFacilitiesBy(programId, requisitionGroups);
 }
Example #5
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;
 }
Example #6
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;
  }
Example #7
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;
  }
Example #8
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);
     }
   }
 }
Example #9
0
 public List<FacilityOperator> getAllOperators() {
   return facilityRepository.getAllOperators();
 }
Example #10
0
 public List<FacilityType> getAllTypes() {
   return facilityRepository.getAllTypes();
 }
Example #11
0
 public List<Facility> getAll() {
   return facilityRepository.getAll();
 }
Example #12
0
 public List<Facility> getAllParentsByModifiedDate(Date modifiedDate) {
   return facilityRepository.getAllParentsByModifiedDate(modifiedDate);
 }
Example #13
0
 public Facility getByCode(Facility facility) {
   return facilityRepository.getByCode(facility.getCode());
 }
Example #14
0
 @Transactional
 public void updateEnabledAndActiveFor(Facility facility) {
   facility = facilityRepository.updateEnabledAndActiveFor(facility);
   notify(asList(facility));
 }
Example #15
0
 public void updateAndNotifyForVirtualFacilities(Facility parentFacility) {
   facilityRepository.updateVirtualFacilities(parentFacility);
   notify(getChildFacilities(parentFacility));
 }
Example #16
0
 public List<Facility> getEnabledWarehouses() {
   return facilityRepository.getEnabledWarehouses();
 }
Example #17
0
 public Facility getFacilityWithReferenceDataForCode(String facilityCode) {
   Long facilityId = facilityRepository.getIdForCode(facilityCode);
   return getById(facilityId);
 }
Example #18
0
 public List<Facility> getAllByProgramSupportedModifiedDate(Date dateModified) {
   return facilityRepository.getAllByProgramSupportedModifiedDate(dateModified);
 }
Example #19
0
 public Facility getHomeFacility(Long userId) {
   return facilityRepository.getHomeFacility(userId);
 }
Example #20
0
 public Facility getById(Long id) {
   Facility facility = facilityRepository.getById(id);
   facility.setSupportedPrograms(programSupportedService.getAllByFacilityId(id));
   return facility;
 }
Example #21
0
 public List<Facility> getChildFacilities(Facility facility) {
   return facilityRepository.getChildFacilities(facility);
 }
Example #22
0
 public List<Facility> getAllByRequisitionGroupMemberModifiedDate(Date modifiedDate) {
   return facilityRepository.getAllByRequisitionGroupMemberModifiedDate(modifiedDate);
 }
Example #23
0
 public FacilityType getFacilityTypeByCode(FacilityType facilityType) {
   return facilityRepository.getFacilityTypeByCode(facilityType);
 }