@Test public void shouldThrowErrorIfInvalidRegimenIsProvided() throws Exception { Program program = new Program(); report.setProducts(new ArrayList<RnrLineItem>()); RegimenLineItem reportRegimenLineItem = make(a(defaultRegimenLineItem, with(patientsOnTreatment, 10), with(patientsStoppedTreatment, 5))); report.setRegimens(asList(reportRegimenLineItem)); when(programService.getValidatedProgramByCode(report.getProgramCode())).thenReturn(program); Facility facility = make(a(FacilityBuilder.defaultFacility, with(FacilityBuilder.virtualFacility, true))); when(facilityService.getOperativeFacilityByCode(report.getAgentCode())).thenReturn(facility); Rnr rnr = new Rnr(); rnr.setProgram(program); when(requisitionService.initiate(facility, program, 3l, false, null)).thenReturn(rnr); when(rnrTemplateService.fetchProgramTemplateForRequisition(any(Long.class))).thenReturn(new ProgramRnrTemplate(new ArrayList<RnrColumn>())); expectedException.expect(DataException.class); expectedException.expectMessage("error.invalid.regimen"); service.submitReport(report, 3l); }
@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; }