@Test public void shouldGetAllPeriodsForInitiatingRequisitionWhenThereIsAtLeastOneExistingRequisitionInThePostSubmitFlow() throws Exception { DateTime date1 = new DateTime(); DateTime date2 = date1.minusMonths(1); DateTime date3 = date1.minusMonths(2); DateTime date4 = date1.minusMonths(3); PROGRAM.setPush(false); ProcessingPeriod processingPeriod1 = createProcessingPeriod(10L, date1); ProcessingPeriod processingPeriod2 = createProcessingPeriod(20L, date2); ProcessingPeriod processingPeriod3 = createProcessingPeriod(30L, date3); ProcessingPeriod processingPeriod4 = createProcessingPeriod(40L, date4); createRequisition(processingPeriod1.getId(), AUTHORIZED); Rnr rnr2 = createRequisition(processingPeriod2.getId(), APPROVED); createRequisition(processingPeriod3.getId(), INITIATED); when(programService.getProgramStartDate(FACILITY.getId(), PROGRAM.getId())).thenReturn(date1.toDate()); when(requisitionRepository.getLastRegularRequisitionToEnterThePostSubmitFlow(FACILITY.getId(), PROGRAM.getId())).thenReturn(rnr2); when(processingScheduleService.getAllPeriodsAfterDateAndPeriod(FACILITY.getId(), PROGRAM.getId(), date1.toDate(), processingPeriod2.getId())). thenReturn(Arrays.asList(processingPeriod3, processingPeriod4)); when(processingScheduleService.getOpenPeriods(FACILITY.getId(), PROGRAM.getId(), processingPeriod2.getId())).thenReturn(null); List<ProcessingPeriod> periods = requisitionService.getAllPeriodsForInitiatingRequisition(FACILITY.getId(), PROGRAM.getId()); assertThat(periods.size(), is(2)); }
public List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId) { Date programStartDate = programService.getProgramStartDate(facilityId, programId); Rnr lastRequisitionToEnterThePostSubmitFlow = requisitionRepository.getLastRegularRequisitionToEnterThePostSubmitFlow(facilityId, programId); Long periodIdOfLastRequisitionToEnterPostSubmitFlow = lastRequisitionToEnterThePostSubmitFlow == null ? null : lastRequisitionToEnterThePostSubmitFlow.getPeriod().getId(); List<ProcessingPeriod> periods = processingScheduleService.getAllPeriodsAfterDateAndPeriod(facilityId, programId, programStartDate, periodIdOfLastRequisitionToEnterPostSubmitFlow); List<ProcessingPeriod> rejected = processingScheduleService.getOpenPeriods(facilityId, programId, periodIdOfLastRequisitionToEnterPostSubmitFlow); if(periods == null || periods.isEmpty()){ periods = rejected; }else { if(rejected != null && !rejected.isEmpty()){ periods.addAll(rejected); } } Set<ProcessingPeriod> finalList = new HashSet<ProcessingPeriod> (periods); periods = new ArrayList<ProcessingPeriod>(finalList); Collections.sort(periods, new Comparator<ProcessingPeriod>() { public int compare(ProcessingPeriod o1, ProcessingPeriod o2) { return o1.getStartDate().compareTo(o2.getStartDate()); } }); return periods; }
RequisitionService { public List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId) { Date programStartDate = programService.getProgramStartDate(facilityId, programId); Rnr lastRequisitionToEnterThePostSubmitFlow = requisitionRepository.getLastRegularRequisitionToEnterThePostSubmitFlow(facilityId, programId); Long periodIdOfLastRequisitionToEnterPostSubmitFlow = lastRequisitionToEnterThePostSubmitFlow == null ? null : lastRequisitionToEnterThePostSubmitFlow.getPeriod().getId(); List<ProcessingPeriod> periods = processingScheduleService.getAllPeriodsAfterDateAndPeriod(facilityId, programId, programStartDate, periodIdOfLastRequisitionToEnterPostSubmitFlow); List<ProcessingPeriod> rejected = processingScheduleService.getOpenPeriods(facilityId, programId, periodIdOfLastRequisitionToEnterPostSubmitFlow); if(periods == null || periods.isEmpty()){ periods = rejected; }else { if(rejected != null && !rejected.isEmpty()){ periods.addAll(rejected); } } Set<ProcessingPeriod> finalList = new HashSet<ProcessingPeriod> (periods); periods = new ArrayList<ProcessingPeriod>(finalList); Collections.sort(periods, new Comparator<ProcessingPeriod>() { public int compare(ProcessingPeriod o1, ProcessingPeriod o2) { return o1.getStartDate().compareTo(o2.getStartDate()); } }); return periods; } }
RequisitionService { public List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId) { Date programStartDate = programService.getProgramStartDate(facilityId, programId); Rnr lastRequisitionToEnterThePostSubmitFlow = requisitionRepository.getLastRegularRequisitionToEnterThePostSubmitFlow(facilityId, programId); Long periodIdOfLastRequisitionToEnterPostSubmitFlow = lastRequisitionToEnterThePostSubmitFlow == null ? null : lastRequisitionToEnterThePostSubmitFlow.getPeriod().getId(); List<ProcessingPeriod> periods = processingScheduleService.getAllPeriodsAfterDateAndPeriod(facilityId, programId, programStartDate, periodIdOfLastRequisitionToEnterPostSubmitFlow); List<ProcessingPeriod> rejected = processingScheduleService.getOpenPeriods(facilityId, programId, periodIdOfLastRequisitionToEnterPostSubmitFlow); if(periods == null || periods.isEmpty()){ periods = rejected; }else { if(rejected != null && !rejected.isEmpty()){ periods.addAll(rejected); } } Set<ProcessingPeriod> finalList = new HashSet<ProcessingPeriod> (periods); periods = new ArrayList<ProcessingPeriod>(finalList); Collections.sort(periods, new Comparator<ProcessingPeriod>() { public int compare(ProcessingPeriod o1, ProcessingPeriod o2) { return o1.getStartDate().compareTo(o2.getStartDate()); } }); return periods; }  }
RequisitionService { public List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId) { Date programStartDate = programService.getProgramStartDate(facilityId, programId); Rnr lastRequisitionToEnterThePostSubmitFlow = requisitionRepository.getLastRegularRequisitionToEnterThePostSubmitFlow(facilityId, programId); Long periodIdOfLastRequisitionToEnterPostSubmitFlow = lastRequisitionToEnterThePostSubmitFlow == null ? null : lastRequisitionToEnterThePostSubmitFlow.getPeriod().getId(); List<ProcessingPeriod> periods = processingScheduleService.getAllPeriodsAfterDateAndPeriod(facilityId, programId, programStartDate, periodIdOfLastRequisitionToEnterPostSubmitFlow); List<ProcessingPeriod> rejected = processingScheduleService.getOpenPeriods(facilityId, programId, periodIdOfLastRequisitionToEnterPostSubmitFlow); if(periods == null || periods.isEmpty()){ periods = rejected; }else { if(rejected != null && !rejected.isEmpty()){ periods.addAll(rejected); } } Set<ProcessingPeriod> finalList = new HashSet<ProcessingPeriod> (periods); periods = new ArrayList<ProcessingPeriod>(finalList); Collections.sort(periods, new Comparator<ProcessingPeriod>() { public int compare(ProcessingPeriod o1, ProcessingPeriod o2) { return o1.getStartDate().compareTo(o2.getStartDate()); } }); return periods; }  @Autowired void setRequisitionSearchStrategyFactory(RequisitionSearchStrategyFactory requisitionSearchStrategyFactory); @Transactional Rnr initiate(Facility facility, Program program, Long modifiedBy, Boolean emergency, ProcessingPeriod proposedPeriod); void populateProductsPriceBasedOnPriceSchedule(Long facilityId, Long programId, List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts); @Transactional Rnr save(Rnr rnr); @Transactional Rnr submit(Rnr rnr); @Transactional Rnr authorize(Rnr rnr); @Transactional Rnr approve(Rnr requisition, String name); void releaseRequisitionsAsOrder(List<Rnr> requisitions, Long userId); List<Rnr> get(RequisitionSearchCriteria criteria); List<LossesAndAdjustmentsType> getLossesAndAdjustmentsTypes(); OpenLmisMessage getSubmitMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getAuthorizeMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getApproveMessageBasedOnParentNode(Rnr rnr); Rnr getFullRequisitionById(Long id); ProcessingPeriod getPeriodForInitiating(Facility facility, Program program); List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId); @Deprecated List<Rnr> listForApproval(Long userId); List<RnrDTO> listForApprovalDto(Long userId); List<RnrLineItem> getNRnrLineItems(String productCode, Rnr rnr, Integer n, Date startDate); Integer getCategoryCount(Rnr requisition, boolean fullSupply); void insertComment(Comment comment); List getCommentsByRnrId(Long rnrId); Rnr getLWById(Long rnrId); Date getOperationDateFor(Long rnrId, String status); ProcessingPeriod getCurrentPeriod(RequisitionSearchCriteria criteria); List<Rnr> getApprovedRequisitionsForCriteriaAndPageNumber(String searchType, String searchVal, Integer pageNumber,
                                                                   Integer totalNumberOfPages, Long userId, String rightName,
                                                                   String sortBy, String sortDirection); Integer getNumberOfPagesOfApprovedRequisitionsForCriteria(String searchType, String searchVal, Long userId, String rightName); List<ProcessingPeriod> getProcessingPeriods(RequisitionSearchCriteria criteria); List<Rnr> getRequisitionsFor(RequisitionSearchCriteria criteria, List<ProcessingPeriod> periodList); Long getFacilityId(Long id); RnrLineItem getNonSkippedLineItem(Long rnrId, String productCode); String deleteRnR(Long rnrId); void skipRnR(Long rnrId, Long userId); void reOpenRnR(Long rnrId, Long userId); void rejectRnR(Long rnrId, Long userId); Integer findM(ProcessingPeriod period); Long getProgramId(Long rnrId); @Transactional void updateClientFields(Rnr rnr); @Transactional void insertPatientQuantificationLineItems(Rnr rnr); List<Rnr> getRequisitionsByFacility(Facility facility); @Transactional void insertRnrSignatures(Rnr rnr); }
RequisitionService { public List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId) { Date programStartDate = programService.getProgramStartDate(facilityId, programId); Rnr lastRequisitionToEnterThePostSubmitFlow = requisitionRepository.getLastRegularRequisitionToEnterThePostSubmitFlow(facilityId, programId); Long periodIdOfLastRequisitionToEnterPostSubmitFlow = lastRequisitionToEnterThePostSubmitFlow == null ? null : lastRequisitionToEnterThePostSubmitFlow.getPeriod().getId(); List<ProcessingPeriod> periods = processingScheduleService.getAllPeriodsAfterDateAndPeriod(facilityId, programId, programStartDate, periodIdOfLastRequisitionToEnterPostSubmitFlow); List<ProcessingPeriod> rejected = processingScheduleService.getOpenPeriods(facilityId, programId, periodIdOfLastRequisitionToEnterPostSubmitFlow); if(periods == null || periods.isEmpty()){ periods = rejected; }else { if(rejected != null && !rejected.isEmpty()){ periods.addAll(rejected); } } Set<ProcessingPeriod> finalList = new HashSet<ProcessingPeriod> (periods); periods = new ArrayList<ProcessingPeriod>(finalList); Collections.sort(periods, new Comparator<ProcessingPeriod>() { public int compare(ProcessingPeriod o1, ProcessingPeriod o2) { return o1.getStartDate().compareTo(o2.getStartDate()); } }); return periods; }  @Autowired void setRequisitionSearchStrategyFactory(RequisitionSearchStrategyFactory requisitionSearchStrategyFactory); @Transactional Rnr initiate(Facility facility, Program program, Long modifiedBy, Boolean emergency, ProcessingPeriod proposedPeriod); void populateProductsPriceBasedOnPriceSchedule(Long facilityId, Long programId, List<FacilityTypeApprovedProduct> facilityTypeApprovedProducts); @Transactional Rnr save(Rnr rnr); @Transactional Rnr submit(Rnr rnr); @Transactional Rnr authorize(Rnr rnr); @Transactional Rnr approve(Rnr requisition, String name); void releaseRequisitionsAsOrder(List<Rnr> requisitions, Long userId); List<Rnr> get(RequisitionSearchCriteria criteria); List<LossesAndAdjustmentsType> getLossesAndAdjustmentsTypes(); OpenLmisMessage getSubmitMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getAuthorizeMessageBasedOnSupervisoryNode(Facility facility, Program program); OpenLmisMessage getApproveMessageBasedOnParentNode(Rnr rnr); Rnr getFullRequisitionById(Long id); ProcessingPeriod getPeriodForInitiating(Facility facility, Program program); List<ProcessingPeriod> getAllPeriodsForInitiatingRequisition(Long facilityId, Long programId); @Deprecated List<Rnr> listForApproval(Long userId); List<RnrDTO> listForApprovalDto(Long userId); List<RnrLineItem> getNRnrLineItems(String productCode, Rnr rnr, Integer n, Date startDate); Integer getCategoryCount(Rnr requisition, boolean fullSupply); void insertComment(Comment comment); List getCommentsByRnrId(Long rnrId); Rnr getLWById(Long rnrId); Date getOperationDateFor(Long rnrId, String status); ProcessingPeriod getCurrentPeriod(RequisitionSearchCriteria criteria); List<Rnr> getApprovedRequisitionsForCriteriaAndPageNumber(String searchType, String searchVal, Integer pageNumber,
                                                                   Integer totalNumberOfPages, Long userId, String rightName,
                                                                   String sortBy, String sortDirection); Integer getNumberOfPagesOfApprovedRequisitionsForCriteria(String searchType, String searchVal, Long userId, String rightName); List<ProcessingPeriod> getProcessingPeriods(RequisitionSearchCriteria criteria); List<Rnr> getRequisitionsFor(RequisitionSearchCriteria criteria, List<ProcessingPeriod> periodList); Long getFacilityId(Long id); RnrLineItem getNonSkippedLineItem(Long rnrId, String productCode); String deleteRnR(Long rnrId); void skipRnR(Long rnrId, Long userId); void reOpenRnR(Long rnrId, Long userId); void rejectRnR(Long rnrId, Long userId); Integer findM(ProcessingPeriod period); Long getProgramId(Long rnrId); @Transactional void updateClientFields(Rnr rnr); @Transactional void insertPatientQuantificationLineItems(Rnr rnr); List<Rnr> getRequisitionsByFacility(Facility facility); @Transactional void insertRnrSignatures(Rnr rnr); static final String RNR_AUTHORIZATION_ERROR; static final String RNR_SUBMISSION_ERROR; static final String RNR_OPERATION_UNAUTHORIZED; static final String RNR_AUTHORIZED_SUCCESSFULLY; static final String RNR_SUBMITTED_SUCCESSFULLY; static final String RNR_AUTHORIZED_SUCCESSFULLY_WITHOUT_SUPERVISOR; static final String RNR_APPROVED_SUCCESSFULLY_WITHOUT_SUPERVISOR; static final String NO_SUPERVISORY_NODE_CONTACT_ADMIN; static final String RNR_APPROVED_SUCCESSFULLY; static final String APPROVAL_NOT_ALLOWED; static final String SEARCH_ALL; static final String SEARCH_PROGRAM_NAME; static final String SEARCH_FACILITY_CODE; static final String SEARCH_FACILITY_NAME; static final String SEARCH_SUPPLYING_DEPOT_NAME; static final String CONVERT_TO_ORDER_PAGE_SIZE; static final String NUMBER_OF_PAGES; }