@Test public void shouldThrowExceptionIfCalculationForQuantityDispensedAndStockInHandNotValidAndFormulaValidatedTrue() throws Exception { lineItem.setBeginningBalance(10); lineItem.setQuantityReceived(3); List<LossesAndAdjustments> list = Arrays.asList(createLossAndAdjustment("CLINIC_RETURN", true, 1)); lineItem.setLossesAndAdjustments(list); lineItem.setStockInHand(4); lineItem.setQuantityDispensed(9); expectedException.expect(DataException.class); expectedException.expectMessage(RNR_VALIDATION_ERROR); lineItem.validateCalculatedFields(template); }
public void validateCalculatedFields(ProgramRnrTemplate template) { boolean validQuantityDispensed = true; RnrColumn rnrColumn = (RnrColumn) template.getColumns().get(0); if (rnrColumn.isFormulaValidationRequired()) { validQuantityDispensed = (quantityDispensed == (beginningBalance + quantityReceived + totalLossesAndAdjustments - stockInHand)); } boolean valid = quantityDispensed >= 0 && stockInHand >= 0 && validQuantityDispensed; if (!valid) throw new DataException(RNR_VALIDATION_ERROR); }
RnrLineItem extends LineItem { public void validateCalculatedFields(ProgramRnrTemplate template) { boolean validQuantityDispensed = true; RnrColumn rnrColumn = (RnrColumn) template.getColumns().get(0); if (rnrColumn.isFormulaValidationRequired()) { validQuantityDispensed = (quantityDispensed == (beginningBalance + quantityReceived + totalLossesAndAdjustments - stockInHand)); } boolean valid = quantityDispensed >= 0 && stockInHand >= 0 && validQuantityDispensed; if (!valid) throw new DataException(RNR_VALIDATION_ERROR); } }
RnrLineItem extends LineItem { public void validateCalculatedFields(ProgramRnrTemplate template) { boolean validQuantityDispensed = true; RnrColumn rnrColumn = (RnrColumn) template.getColumns().get(0); if (rnrColumn.isFormulaValidationRequired()) { validQuantityDispensed = (quantityDispensed == (beginningBalance + quantityReceived + totalLossesAndAdjustments - stockInHand)); } boolean valid = quantityDispensed >= 0 && stockInHand >= 0 && validQuantityDispensed; if (!valid) throw new DataException(RNR_VALIDATION_ERROR); } RnrLineItem(Long rnrId,
                     FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                     Long modifiedBy,
                     Long createdBy); }
RnrLineItem extends LineItem { public void validateCalculatedFields(ProgramRnrTemplate template) { boolean validQuantityDispensed = true; RnrColumn rnrColumn = (RnrColumn) template.getColumns().get(0); if (rnrColumn.isFormulaValidationRequired()) { validQuantityDispensed = (quantityDispensed == (beginningBalance + quantityReceived + totalLossesAndAdjustments - stockInHand)); } boolean valid = quantityDispensed >= 0 && stockInHand >= 0 && validQuantityDispensed; if (!valid) throw new DataException(RNR_VALIDATION_ERROR); } RnrLineItem(Long rnrId,
                     FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                     Long modifiedBy,
                     Long createdBy); void setFieldsForApproval(); void setBeginningBalanceWhenPreviousStockInHandAvailable(RnrLineItem previousLineItem,
                                                                  Boolean beginningBalanceVisible); void setSkippedValueWhenPreviousLineItemIsAvailable(RnrLineItem previousLineItem); void setLineItemFieldsAccordingToTemplate(ProgramRnrTemplate template); void validateForApproval(); void validateMandatoryFields(ProgramRnrTemplate template); void validateNonFullSupply(); void validateCalculatedFields(ProgramRnrTemplate template); void calculateForFullSupply(ProgramRnrTemplate template,
                                     RnrStatus rnrStatus,
                                     List<LossesAndAdjustmentsType> lossesAndAdjustmentsTypes, Integer numberOfMonths); void calculatePeriodNormalizedConsumption(Integer numberOfMonths); void calculateAmc(Integer numberOfMonths); void calculatePacksToShip(); void calculateMaxStockQuantity( ProgramRnrTemplate template); void calculateOrderQuantity(); void calculateNormalizedConsumption(ProgramRnrTemplate template); void calculateTotalLossesAndAdjustments(List<LossesAndAdjustmentsType> lossesAndAdjustmentsTypes); void calculateQuantityDispensed(); void calculateStockInHand(); Money calculateCost(); void copyCreatorEditableFieldsForFullSupply(RnrLineItem lineItem, ProgramRnrTemplate template); void copyCreatorEditableFieldsForNonFullSupply(RnrLineItem lineItem, ProgramRnrTemplate template); void copyApproverEditableFields(RnrLineItem lineItem, ProgramRnrTemplate template); void addLossesAndAdjustments(LossesAndAdjustments lossesAndAdjustments); @Override boolean compareCategory(LineItem lineItem); @Override String getCategoryName(); @Override String getValue(String columnName); @Override boolean isRnrLineItem(); }
RnrLineItem extends LineItem { public void validateCalculatedFields(ProgramRnrTemplate template) { boolean validQuantityDispensed = true; RnrColumn rnrColumn = (RnrColumn) template.getColumns().get(0); if (rnrColumn.isFormulaValidationRequired()) { validQuantityDispensed = (quantityDispensed == (beginningBalance + quantityReceived + totalLossesAndAdjustments - stockInHand)); } boolean valid = quantityDispensed >= 0 && stockInHand >= 0 && validQuantityDispensed; if (!valid) throw new DataException(RNR_VALIDATION_ERROR); } RnrLineItem(Long rnrId,
                     FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                     Long modifiedBy,
                     Long createdBy); void setFieldsForApproval(); void setBeginningBalanceWhenPreviousStockInHandAvailable(RnrLineItem previousLineItem,
                                                                  Boolean beginningBalanceVisible); void setSkippedValueWhenPreviousLineItemIsAvailable(RnrLineItem previousLineItem); void setLineItemFieldsAccordingToTemplate(ProgramRnrTemplate template); void validateForApproval(); void validateMandatoryFields(ProgramRnrTemplate template); void validateNonFullSupply(); void validateCalculatedFields(ProgramRnrTemplate template); void calculateForFullSupply(ProgramRnrTemplate template,
                                     RnrStatus rnrStatus,
                                     List<LossesAndAdjustmentsType> lossesAndAdjustmentsTypes, Integer numberOfMonths); void calculatePeriodNormalizedConsumption(Integer numberOfMonths); void calculateAmc(Integer numberOfMonths); void calculatePacksToShip(); void calculateMaxStockQuantity( ProgramRnrTemplate template); void calculateOrderQuantity(); void calculateNormalizedConsumption(ProgramRnrTemplate template); void calculateTotalLossesAndAdjustments(List<LossesAndAdjustmentsType> lossesAndAdjustmentsTypes); void calculateQuantityDispensed(); void calculateStockInHand(); Money calculateCost(); void copyCreatorEditableFieldsForFullSupply(RnrLineItem lineItem, ProgramRnrTemplate template); void copyCreatorEditableFieldsForNonFullSupply(RnrLineItem lineItem, ProgramRnrTemplate template); void copyApproverEditableFields(RnrLineItem lineItem, ProgramRnrTemplate template); void addLossesAndAdjustments(LossesAndAdjustments lossesAndAdjustments); @Override boolean compareCategory(LineItem lineItem); @Override String getCategoryName(); @Override String getValue(String columnName); @Override boolean isRnrLineItem(); static final BigDecimal NUMBER_OF_DAYS; static final MathContext MATH_CONTEXT; static final String DISPENSED_PLUS_NEW_PATIENTS; static final String DISPENSED_X_90; static final String DEFAULT; static final String DISPENSED_X_2; static final String CONSUMPTION_X_2; }