@Test public void shouldSetDefaultApprovedQuantityOnAuthorization() throws Exception { Rnr savedRnr = getFilledSavedRequisitionWithDefaultFacilityProgramPeriod(submittedRnr, AUTHORIZE_REQUISITION); ProgramRnrTemplate template = new ProgramRnrTemplate(rnrColumns); when(rnrTemplateService.fetchProgramTemplate(PROGRAM.getId())).thenReturn(template); doNothing().when(calculationService).perform(savedRnr, template); when(supervisoryNodeService.getApproverFor(FACILITY, PROGRAM)).thenReturn(new User()); SupervisoryNode approverNode = new SupervisoryNode(); when(supervisoryNodeService.getFor(FACILITY, PROGRAM)).thenReturn(approverNode); doNothing().when(savedRnr).setFieldsForApproval(); requisitionService.authorize(submittedRnr); verify(savedRnr).setFieldsForApproval(); }
@Transactional public Rnr authorize(Rnr rnr) { Rnr savedRnr = getFullRequisitionById(rnr.getId()); if (savedRnr.getStatus() != SUBMITTED) throw new DataException(new OpenLmisMessage(RNR_AUTHORIZATION_ERROR)); savedRnr.validateRegimenLineItems(regimenColumnService.getRegimenTemplateByProgramId(savedRnr.getProgram().getId())); if (!requisitionPermissionService.hasPermission(rnr.getModifiedBy(), savedRnr, AUTHORIZE_REQUISITION)) throw new DataException(RNR_OPERATION_UNAUTHORIZED); savedRnr.setAuditFieldsForRequisition(rnr.getModifiedBy(), AUTHORIZED); savedRnr.setSupervisoryNodeId(supervisoryNodeService.getFor(savedRnr.getFacility(), savedRnr.getProgram()).getId()); ProgramRnrTemplate template = rnrTemplateService.fetchProgramTemplate(savedRnr.getProgram().getId()); calculationService.perform(savedRnr, template); savedRnr.setFieldsForApproval(); return update(savedRnr); }
RequisitionService { @Transactional public Rnr authorize(Rnr rnr) { Rnr savedRnr = getFullRequisitionById(rnr.getId()); if (savedRnr.getStatus() != SUBMITTED) throw new DataException(new OpenLmisMessage(RNR_AUTHORIZATION_ERROR)); savedRnr.validateRegimenLineItems(regimenColumnService.getRegimenTemplateByProgramId(savedRnr.getProgram().getId())); if (!requisitionPermissionService.hasPermission(rnr.getModifiedBy(), savedRnr, AUTHORIZE_REQUISITION)) throw new DataException(RNR_OPERATION_UNAUTHORIZED); savedRnr.setAuditFieldsForRequisition(rnr.getModifiedBy(), AUTHORIZED); savedRnr.setSupervisoryNodeId(supervisoryNodeService.getFor(savedRnr.getFacility(), savedRnr.getProgram()).getId()); ProgramRnrTemplate template = rnrTemplateService.fetchProgramTemplate(savedRnr.getProgram().getId()); calculationService.perform(savedRnr, template); savedRnr.setFieldsForApproval(); return update(savedRnr); } }
RequisitionService { @Transactional public Rnr authorize(Rnr rnr) { Rnr savedRnr = getFullRequisitionById(rnr.getId()); if (savedRnr.getStatus() != SUBMITTED) throw new DataException(new OpenLmisMessage(RNR_AUTHORIZATION_ERROR)); savedRnr.validateRegimenLineItems(regimenColumnService.getRegimenTemplateByProgramId(savedRnr.getProgram().getId())); if (!requisitionPermissionService.hasPermission(rnr.getModifiedBy(), savedRnr, AUTHORIZE_REQUISITION)) throw new DataException(RNR_OPERATION_UNAUTHORIZED); savedRnr.setAuditFieldsForRequisition(rnr.getModifiedBy(), AUTHORIZED); savedRnr.setSupervisoryNodeId(supervisoryNodeService.getFor(savedRnr.getFacility(), savedRnr.getProgram()).getId()); ProgramRnrTemplate template = rnrTemplateService.fetchProgramTemplate(savedRnr.getProgram().getId()); calculationService.perform(savedRnr, template); savedRnr.setFieldsForApproval(); return update(savedRnr); }  }
RequisitionService { @Transactional public Rnr authorize(Rnr rnr) { Rnr savedRnr = getFullRequisitionById(rnr.getId()); if (savedRnr.getStatus() != SUBMITTED) throw new DataException(new OpenLmisMessage(RNR_AUTHORIZATION_ERROR)); savedRnr.validateRegimenLineItems(regimenColumnService.getRegimenTemplateByProgramId(savedRnr.getProgram().getId())); if (!requisitionPermissionService.hasPermission(rnr.getModifiedBy(), savedRnr, AUTHORIZE_REQUISITION)) throw new DataException(RNR_OPERATION_UNAUTHORIZED); savedRnr.setAuditFieldsForRequisition(rnr.getModifiedBy(), AUTHORIZED); savedRnr.setSupervisoryNodeId(supervisoryNodeService.getFor(savedRnr.getFacility(), savedRnr.getProgram()).getId()); ProgramRnrTemplate template = rnrTemplateService.fetchProgramTemplate(savedRnr.getProgram().getId()); calculationService.perform(savedRnr, template); savedRnr.setFieldsForApproval(); return update(savedRnr); }  @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 { @Transactional public Rnr authorize(Rnr rnr) { Rnr savedRnr = getFullRequisitionById(rnr.getId()); if (savedRnr.getStatus() != SUBMITTED) throw new DataException(new OpenLmisMessage(RNR_AUTHORIZATION_ERROR)); savedRnr.validateRegimenLineItems(regimenColumnService.getRegimenTemplateByProgramId(savedRnr.getProgram().getId())); if (!requisitionPermissionService.hasPermission(rnr.getModifiedBy(), savedRnr, AUTHORIZE_REQUISITION)) throw new DataException(RNR_OPERATION_UNAUTHORIZED); savedRnr.setAuditFieldsForRequisition(rnr.getModifiedBy(), AUTHORIZED); savedRnr.setSupervisoryNodeId(supervisoryNodeService.getFor(savedRnr.getFacility(), savedRnr.getProgram()).getId()); ProgramRnrTemplate template = rnrTemplateService.fetchProgramTemplate(savedRnr.getProgram().getId()); calculationService.perform(savedRnr, template); savedRnr.setFieldsForApproval(); return update(savedRnr); }  @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; }