@Test public void shouldSetFieldsToReportedValuesOtherwiseCopyFromInitiatedRnrLineItem() throws Exception { Program rnrProgram = new Program(PROGRAM_ID); ProgramRnrTemplate template = new ProgramRnrTemplate(getRnrColumns()); when(rnrTemplateService.fetchProgramTemplateForRequisition(PROGRAM_ID)).thenReturn(template); RnrLineItem reportedLineItem = new RnrLineItem(); reportedLineItem.setProductCode("P10"); reportedLineItem.setQuantityDispensed(100); Integer nullInteger = null; String nullString = null; RnrLineItem initiatedLineItem = make(a(defaultRnrLineItem, with(productCode, "P10"), with(stockInHand, nullInteger), with(quantityDispensed, nullInteger), with(beginningBalance, nullInteger), with(quantityReceived, nullInteger), with(totalLossesAndAdjustments, 0), with(newPatientCount, 0), with(stockOutDays, 0), with(quantityRequested, nullInteger), with(reasonForRequestedQuantity, nullString), with(remarks, nullString), with(skipped, false))); report.setProducts(asList(reportedLineItem)); when(programService.getValidatedProgramByCode(report.getProgramCode())).thenReturn(rnrProgram); Facility reportFacility = make(a(defaultFacility, with(virtualFacility, true))); when(facilityService.getOperativeFacilityByCode(report.getAgentCode())).thenReturn(reportFacility); Rnr rnr = make(a(RequisitionBuilder.defaultRequisition, with (RequisitionBuilder.facility, reportFacility), with(RequisitionBuilder.program, rnrProgram))); rnr.setFullSupplyLineItems(asList(initiatedLineItem)); when(requisitionService.initiate(reportFacility, rnrProgram, 3l, false, null)).thenReturn(rnr); service.submitReport(report, 3l); RnrLineItem rnrLineItem = rnr.getFullSupplyLineItems().get(0); assertThat(rnrLineItem.getStockInHand(), is(nullValue())); assertThat(rnrLineItem.getQuantityDispensed(), is(100)); assertThat(rnrLineItem.getBeginningBalance(), is(nullValue())); assertThat(rnrLineItem.getQuantityReceived(), is(nullValue())); assertThat(rnrLineItem.getTotalLossesAndAdjustments(), is(0)); assertThat(rnrLineItem.getNewPatientCount(), is(0)); assertThat(rnrLineItem.getStockOutDays(), is(0)); assertThat(rnrLineItem.getQuantityRequested(), is(nullValue())); assertThat(rnrLineItem.getReasonForRequestedQuantity(), is(nullValue())); assertThat(rnrLineItem.getRemarks(), is(nullValue())); assertThat(rnrLineItem.getSkipped(), is(false)); }
@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; }