@Test public void shouldAuthorizeRnr() throws Exception { String facilityCode = "agent"; String programCode = "program"; Facility facility = new Facility(); Program program = new Program(1l); Report report = make(a(defaultReport, with(agentCode, facilityCode), with(ReportBuilder.programCode, programCode))); when(facilityService.getOperativeFacilityByCode(facilityCode)).thenReturn(facility); when(programService.getValidatedProgramByCode(programCode)).thenReturn(program); Rnr rnr = new Rnr(facility, program, new ProcessingPeriod()); when(requisitionService.initiate(facility, program, 3l, false, null)).thenReturn(rnr); when(requisitionService.submit(rnr)).thenReturn(rnr); when(requisitionService.authorize(rnr)).thenReturn(rnr); Rnr authorizedRequisition = service.submitReport(report, 3l); verify(requisitionService).authorize(rnr); assertThat(authorizedRequisition, is(rnr)); }
@Transactional public Rnr submitReport(Report report, Long userId) { report.validate(); Facility reportingFacility = facilityService.getOperativeFacilityByCode(report.getAgentCode()); Program reportingProgram = programService.getValidatedProgramByCode(report.getProgramCode()); restRequisitionCalculator.validatePeriod(reportingFacility, reportingProgram); Rnr rnr = requisitionService.initiate(reportingFacility, reportingProgram, userId, EMERGENCY, null); restRequisitionCalculator.validateProducts(report.getProducts(), rnr); markSkippedLineItems(rnr, report); if (reportingFacility.getVirtualFacility()) restRequisitionCalculator.setDefaultValues(rnr); copyRegimens(rnr, report); requisitionService.save(rnr); updateClientFields(report, rnr); insertPatientQuantificationLineItems(report, rnr); insertRnrSignatures(report, rnr, userId); rnr = requisitionService.submit(rnr); return requisitionService.authorize(rnr); }
RestRequisitionService { @Transactional public Rnr submitReport(Report report, Long userId) { report.validate(); Facility reportingFacility = facilityService.getOperativeFacilityByCode(report.getAgentCode()); Program reportingProgram = programService.getValidatedProgramByCode(report.getProgramCode()); restRequisitionCalculator.validatePeriod(reportingFacility, reportingProgram); Rnr rnr = requisitionService.initiate(reportingFacility, reportingProgram, userId, EMERGENCY, null); restRequisitionCalculator.validateProducts(report.getProducts(), rnr); markSkippedLineItems(rnr, report); if (reportingFacility.getVirtualFacility()) restRequisitionCalculator.setDefaultValues(rnr); copyRegimens(rnr, report); requisitionService.save(rnr); updateClientFields(report, rnr); insertPatientQuantificationLineItems(report, rnr); insertRnrSignatures(report, rnr, userId); rnr = requisitionService.submit(rnr); return requisitionService.authorize(rnr); } }
RestRequisitionService { @Transactional public Rnr submitReport(Report report, Long userId) { report.validate(); Facility reportingFacility = facilityService.getOperativeFacilityByCode(report.getAgentCode()); Program reportingProgram = programService.getValidatedProgramByCode(report.getProgramCode()); restRequisitionCalculator.validatePeriod(reportingFacility, reportingProgram); Rnr rnr = requisitionService.initiate(reportingFacility, reportingProgram, userId, EMERGENCY, null); restRequisitionCalculator.validateProducts(report.getProducts(), rnr); markSkippedLineItems(rnr, report); if (reportingFacility.getVirtualFacility()) restRequisitionCalculator.setDefaultValues(rnr); copyRegimens(rnr, report); requisitionService.save(rnr); updateClientFields(report, rnr); insertPatientQuantificationLineItems(report, rnr); insertRnrSignatures(report, rnr, userId); rnr = requisitionService.submit(rnr); return requisitionService.authorize(rnr); }  }
RestRequisitionService { @Transactional public Rnr submitReport(Report report, Long userId) { report.validate(); Facility reportingFacility = facilityService.getOperativeFacilityByCode(report.getAgentCode()); Program reportingProgram = programService.getValidatedProgramByCode(report.getProgramCode()); restRequisitionCalculator.validatePeriod(reportingFacility, reportingProgram); Rnr rnr = requisitionService.initiate(reportingFacility, reportingProgram, userId, EMERGENCY, null); restRequisitionCalculator.validateProducts(report.getProducts(), rnr); markSkippedLineItems(rnr, report); if (reportingFacility.getVirtualFacility()) restRequisitionCalculator.setDefaultValues(rnr); copyRegimens(rnr, report); requisitionService.save(rnr); updateClientFields(report, rnr); insertPatientQuantificationLineItems(report, rnr); insertRnrSignatures(report, rnr, userId); rnr = requisitionService.submit(rnr); return requisitionService.authorize(rnr); }  @Transactional Rnr submitReport(Report report, Long userId); @Transactional Rnr submitSdpReport(Report report, Long userId); @Transactional void approve(Report report, Long requisitionId, Long userId); ReplenishmentDTO getReplenishmentDetails(Long id); List<Report> getRequisitionsByFacility(String facilityCode); }
RestRequisitionService { @Transactional public Rnr submitReport(Report report, Long userId) { report.validate(); Facility reportingFacility = facilityService.getOperativeFacilityByCode(report.getAgentCode()); Program reportingProgram = programService.getValidatedProgramByCode(report.getProgramCode()); restRequisitionCalculator.validatePeriod(reportingFacility, reportingProgram); Rnr rnr = requisitionService.initiate(reportingFacility, reportingProgram, userId, EMERGENCY, null); restRequisitionCalculator.validateProducts(report.getProducts(), rnr); markSkippedLineItems(rnr, report); if (reportingFacility.getVirtualFacility()) restRequisitionCalculator.setDefaultValues(rnr); copyRegimens(rnr, report); requisitionService.save(rnr); updateClientFields(report, rnr); insertPatientQuantificationLineItems(report, rnr); insertRnrSignatures(report, rnr, userId); rnr = requisitionService.submit(rnr); return requisitionService.authorize(rnr); }  @Transactional Rnr submitReport(Report report, Long userId); @Transactional Rnr submitSdpReport(Report report, Long userId); @Transactional void approve(Report report, Long requisitionId, Long userId); ReplenishmentDTO getReplenishmentDetails(Long id); List<Report> getRequisitionsByFacility(String facilityCode); static final boolean EMERGENCY; }