@Test public void shouldCalculateNCIfReportingDaysAreLessThanZero() throws Exception { RnrLineItem lineItem = new RnrLineItem(); lineItem.setStockOutDays(30); lineItem.setQuantityDispensed(1); lineItem.setNewPatientCount(1); lineItem.setDosesPerMonth(30); lineItem.setDosesPerDispensingUnit(10); lineItem.setReportingDays(30); lineItem.calculateNormalizedConsumption(template); assertThat(lineItem.getNormalizedConsumption(), is(4)); }
public void calculateNormalizedConsumption(ProgramRnrTemplate template) { prepareFieldsForCalculation(); RnrColumn column = template.getRnrColumnsMap().get("normalizedConsumption"); String selectedColumnOption = DEFAULT; if (column != null) { selectedColumnOption = column.getCalculationOption(); } if (DISPENSED_PLUS_NEW_PATIENTS.equalsIgnoreCase(selectedColumnOption)) { normalizedConsumption = quantityDispensed + newPatientCount; } else if (DISPENSED_X_90.equalsIgnoreCase(selectedColumnOption)) { if (stockOutDays < 90) { normalizedConsumption = (new BigDecimal(90 * quantityDispensed) .divide( new BigDecimal(90 - stockOutDays) , MATH_CONTEXT) ).intValue(); } else { normalizedConsumption = (90 * quantityDispensed); } } else { BigDecimal dosesPerDispensingUnit = new BigDecimal(Math.max(1, this.dosesPerDispensingUnit)); normalizedConsumption = calculateNormalizedConsumption( new BigDecimal(stockOutDays), new BigDecimal(quantityDispensed), new BigDecimal(newPatientCount), new BigDecimal(dosesPerMonth), dosesPerDispensingUnit, reportingDays, template); } }
RnrLineItem extends LineItem { public void calculateNormalizedConsumption(ProgramRnrTemplate template) { prepareFieldsForCalculation(); RnrColumn column = template.getRnrColumnsMap().get("normalizedConsumption"); String selectedColumnOption = DEFAULT; if (column != null) { selectedColumnOption = column.getCalculationOption(); } if (DISPENSED_PLUS_NEW_PATIENTS.equalsIgnoreCase(selectedColumnOption)) { normalizedConsumption = quantityDispensed + newPatientCount; } else if (DISPENSED_X_90.equalsIgnoreCase(selectedColumnOption)) { if (stockOutDays < 90) { normalizedConsumption = (new BigDecimal(90 * quantityDispensed) .divide( new BigDecimal(90 - stockOutDays) , MATH_CONTEXT) ).intValue(); } else { normalizedConsumption = (90 * quantityDispensed); } } else { BigDecimal dosesPerDispensingUnit = new BigDecimal(Math.max(1, this.dosesPerDispensingUnit)); normalizedConsumption = calculateNormalizedConsumption( new BigDecimal(stockOutDays), new BigDecimal(quantityDispensed), new BigDecimal(newPatientCount), new BigDecimal(dosesPerMonth), dosesPerDispensingUnit, reportingDays, template); } } }
RnrLineItem extends LineItem { public void calculateNormalizedConsumption(ProgramRnrTemplate template) { prepareFieldsForCalculation(); RnrColumn column = template.getRnrColumnsMap().get("normalizedConsumption"); String selectedColumnOption = DEFAULT; if (column != null) { selectedColumnOption = column.getCalculationOption(); } if (DISPENSED_PLUS_NEW_PATIENTS.equalsIgnoreCase(selectedColumnOption)) { normalizedConsumption = quantityDispensed + newPatientCount; } else if (DISPENSED_X_90.equalsIgnoreCase(selectedColumnOption)) { if (stockOutDays < 90) { normalizedConsumption = (new BigDecimal(90 * quantityDispensed) .divide( new BigDecimal(90 - stockOutDays) , MATH_CONTEXT) ).intValue(); } else { normalizedConsumption = (90 * quantityDispensed); } } else { BigDecimal dosesPerDispensingUnit = new BigDecimal(Math.max(1, this.dosesPerDispensingUnit)); normalizedConsumption = calculateNormalizedConsumption( new BigDecimal(stockOutDays), new BigDecimal(quantityDispensed), new BigDecimal(newPatientCount), new BigDecimal(dosesPerMonth), dosesPerDispensingUnit, reportingDays, template); } } RnrLineItem(Long rnrId,
                     FacilityTypeApprovedProduct facilityTypeApprovedProduct,
                     Long modifiedBy,
                     Long createdBy); }
RnrLineItem extends LineItem { public void calculateNormalizedConsumption(ProgramRnrTemplate template) { prepareFieldsForCalculation(); RnrColumn column = template.getRnrColumnsMap().get("normalizedConsumption"); String selectedColumnOption = DEFAULT; if (column != null) { selectedColumnOption = column.getCalculationOption(); } if (DISPENSED_PLUS_NEW_PATIENTS.equalsIgnoreCase(selectedColumnOption)) { normalizedConsumption = quantityDispensed + newPatientCount; } else if (DISPENSED_X_90.equalsIgnoreCase(selectedColumnOption)) { if (stockOutDays < 90) { normalizedConsumption = (new BigDecimal(90 * quantityDispensed) .divide( new BigDecimal(90 - stockOutDays) , MATH_CONTEXT) ).intValue(); } else { normalizedConsumption = (90 * quantityDispensed); } } else { BigDecimal dosesPerDispensingUnit = new BigDecimal(Math.max(1, this.dosesPerDispensingUnit)); normalizedConsumption = calculateNormalizedConsumption( new BigDecimal(stockOutDays), new BigDecimal(quantityDispensed), new BigDecimal(newPatientCount), new BigDecimal(dosesPerMonth), dosesPerDispensingUnit, reportingDays, template); } } 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 calculateNormalizedConsumption(ProgramRnrTemplate template) { prepareFieldsForCalculation(); RnrColumn column = template.getRnrColumnsMap().get("normalizedConsumption"); String selectedColumnOption = DEFAULT; if (column != null) { selectedColumnOption = column.getCalculationOption(); } if (DISPENSED_PLUS_NEW_PATIENTS.equalsIgnoreCase(selectedColumnOption)) { normalizedConsumption = quantityDispensed + newPatientCount; } else if (DISPENSED_X_90.equalsIgnoreCase(selectedColumnOption)) { if (stockOutDays < 90) { normalizedConsumption = (new BigDecimal(90 * quantityDispensed) .divide( new BigDecimal(90 - stockOutDays) , MATH_CONTEXT) ).intValue(); } else { normalizedConsumption = (90 * quantityDispensed); } } else { BigDecimal dosesPerDispensingUnit = new BigDecimal(Math.max(1, this.dosesPerDispensingUnit)); normalizedConsumption = calculateNormalizedConsumption( new BigDecimal(stockOutDays), new BigDecimal(quantityDispensed), new BigDecimal(newPatientCount), new BigDecimal(dosesPerMonth), dosesPerDispensingUnit, reportingDays, template); } } 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; }