@Test public void shouldSaveFacilityProgramProductISAAndCalculateParents() { setupFacilityHierarchy(); when(facilityRepository.getByCode(any(String.class))).thenReturn(sdp1); when(programProductRepository.getByProgramAndProductCode(any(ProgramProduct.class))).thenReturn(programProduct); when(programRepository.getByCode(any(String.class))).thenReturn(program); when(estimateCategoryRepository.getByName(any(String.class))).thenReturn(category); ISA isa = new ISA(); isa.setWhoRatio(whoRatio); isa.setDosesPerYear(dosesPerYear); isa.setWastageFactor(wastageFactor); isa.setBufferPercentage(bufferPercentage); isa.setAdjustmentValue(adjustmentValue); isa.setPopulationSource(category.getId()); ProgramProductISA ppISA = new ProgramProductISA(programProduct.getId(), isa); FacilityProgramProduct fpp = new FacilityProgramProduct(); fpp.setFacilityId(sdp1.getId()); fpp.setId(programProduct.getId()); fpp.setProgramProductIsa(ppISA); fpp.setOverriddenIsa(isa); handler.save(fppISA); verify(facilityProgramProductRepository).save(fpp); isa.setWastageFactor(8.2); fpp.setFacilityId(dvs1.getId()); verify(facilityProgramProductRepository).save(fpp); isa.setWastageFactor(8.72); fpp.setFacilityId(rvs1.getId()); verify(facilityProgramProductRepository).save(fpp); isa.setWastageFactor(8.8); fpp.setFacilityId(cvs.getId()); verify(facilityProgramProductRepository).save(fpp); }
@Override protected void save(BaseModel record) { FacilityProgramProductISADTO fppISA = (FacilityProgramProductISADTO)record; Facility facility = facilityRepository.getByCode(fppISA.getFacility().getCode()); ProgramProduct pp = programProductRepository.getByProgramAndProductCode(new ProgramProduct(fppISA.getProgram(), fppISA.getProduct(), null, null)); Program program = programRepository.getByCode(fppISA.getProgram().getCode()); EstimateCategory category = estimateCategoryRepository.getByName(fppISA.getPopulationSourceName()); Long populationSourceId = (category != null) ? category.getId() : null; Double wastageFactor = fppISA.getWastageFactor(); if (wastageFactor == -1.0) { wastageFactor = repository.getOverriddenIsa(pp.getId(), facility.getId()).getWastageFactor(); } ISA isa = new ISA(); isa.setWhoRatio(fppISA.getWhoRatio()); isa.setDosesPerYear(fppISA.getDosesPerYear()); isa.setWastageFactor(wastageFactor); isa.setBufferPercentage(fppISA.getBufferPercentage()); isa.setMinimumValue(fppISA.getMinimumValue()); isa.setMaximumValue(fppISA.getMaximumValue()); isa.setAdjustmentValue(fppISA.getAdjustmentValue()); isa.setPopulationSource(populationSourceId); saveFacilityProgramProductWithISA(facility, pp, isa); saveWastageFactorForSupervisingFacilities(facility, pp, program, populationSourceId); }
FacilityProgramProductISAHandler extends AbstractModelPersistenceHandler { @Override protected void save(BaseModel record) { FacilityProgramProductISADTO fppISA = (FacilityProgramProductISADTO)record; Facility facility = facilityRepository.getByCode(fppISA.getFacility().getCode()); ProgramProduct pp = programProductRepository.getByProgramAndProductCode(new ProgramProduct(fppISA.getProgram(), fppISA.getProduct(), null, null)); Program program = programRepository.getByCode(fppISA.getProgram().getCode()); EstimateCategory category = estimateCategoryRepository.getByName(fppISA.getPopulationSourceName()); Long populationSourceId = (category != null) ? category.getId() : null; Double wastageFactor = fppISA.getWastageFactor(); if (wastageFactor == -1.0) { wastageFactor = repository.getOverriddenIsa(pp.getId(), facility.getId()).getWastageFactor(); } ISA isa = new ISA(); isa.setWhoRatio(fppISA.getWhoRatio()); isa.setDosesPerYear(fppISA.getDosesPerYear()); isa.setWastageFactor(wastageFactor); isa.setBufferPercentage(fppISA.getBufferPercentage()); isa.setMinimumValue(fppISA.getMinimumValue()); isa.setMaximumValue(fppISA.getMaximumValue()); isa.setAdjustmentValue(fppISA.getAdjustmentValue()); isa.setPopulationSource(populationSourceId); saveFacilityProgramProductWithISA(facility, pp, isa); saveWastageFactorForSupervisingFacilities(facility, pp, program, populationSourceId); } }
FacilityProgramProductISAHandler extends AbstractModelPersistenceHandler { @Override protected void save(BaseModel record) { FacilityProgramProductISADTO fppISA = (FacilityProgramProductISADTO)record; Facility facility = facilityRepository.getByCode(fppISA.getFacility().getCode()); ProgramProduct pp = programProductRepository.getByProgramAndProductCode(new ProgramProduct(fppISA.getProgram(), fppISA.getProduct(), null, null)); Program program = programRepository.getByCode(fppISA.getProgram().getCode()); EstimateCategory category = estimateCategoryRepository.getByName(fppISA.getPopulationSourceName()); Long populationSourceId = (category != null) ? category.getId() : null; Double wastageFactor = fppISA.getWastageFactor(); if (wastageFactor == -1.0) { wastageFactor = repository.getOverriddenIsa(pp.getId(), facility.getId()).getWastageFactor(); } ISA isa = new ISA(); isa.setWhoRatio(fppISA.getWhoRatio()); isa.setDosesPerYear(fppISA.getDosesPerYear()); isa.setWastageFactor(wastageFactor); isa.setBufferPercentage(fppISA.getBufferPercentage()); isa.setMinimumValue(fppISA.getMinimumValue()); isa.setMaximumValue(fppISA.getMaximumValue()); isa.setAdjustmentValue(fppISA.getAdjustmentValue()); isa.setPopulationSource(populationSourceId); saveFacilityProgramProductWithISA(facility, pp, isa); saveWastageFactorForSupervisingFacilities(facility, pp, program, populationSourceId); }  }
FacilityProgramProductISAHandler extends AbstractModelPersistenceHandler { @Override protected void save(BaseModel record) { FacilityProgramProductISADTO fppISA = (FacilityProgramProductISADTO)record; Facility facility = facilityRepository.getByCode(fppISA.getFacility().getCode()); ProgramProduct pp = programProductRepository.getByProgramAndProductCode(new ProgramProduct(fppISA.getProgram(), fppISA.getProduct(), null, null)); Program program = programRepository.getByCode(fppISA.getProgram().getCode()); EstimateCategory category = estimateCategoryRepository.getByName(fppISA.getPopulationSourceName()); Long populationSourceId = (category != null) ? category.getId() : null; Double wastageFactor = fppISA.getWastageFactor(); if (wastageFactor == -1.0) { wastageFactor = repository.getOverriddenIsa(pp.getId(), facility.getId()).getWastageFactor(); } ISA isa = new ISA(); isa.setWhoRatio(fppISA.getWhoRatio()); isa.setDosesPerYear(fppISA.getDosesPerYear()); isa.setWastageFactor(wastageFactor); isa.setBufferPercentage(fppISA.getBufferPercentage()); isa.setMinimumValue(fppISA.getMinimumValue()); isa.setMaximumValue(fppISA.getMaximumValue()); isa.setAdjustmentValue(fppISA.getAdjustmentValue()); isa.setPopulationSource(populationSourceId); saveFacilityProgramProductWithISA(facility, pp, isa); saveWastageFactorForSupervisingFacilities(facility, pp, program, populationSourceId); }  @Override String getMessageKey(); }
FacilityProgramProductISAHandler extends AbstractModelPersistenceHandler { @Override protected void save(BaseModel record) { FacilityProgramProductISADTO fppISA = (FacilityProgramProductISADTO)record; Facility facility = facilityRepository.getByCode(fppISA.getFacility().getCode()); ProgramProduct pp = programProductRepository.getByProgramAndProductCode(new ProgramProduct(fppISA.getProgram(), fppISA.getProduct(), null, null)); Program program = programRepository.getByCode(fppISA.getProgram().getCode()); EstimateCategory category = estimateCategoryRepository.getByName(fppISA.getPopulationSourceName()); Long populationSourceId = (category != null) ? category.getId() : null; Double wastageFactor = fppISA.getWastageFactor(); if (wastageFactor == -1.0) { wastageFactor = repository.getOverriddenIsa(pp.getId(), facility.getId()).getWastageFactor(); } ISA isa = new ISA(); isa.setWhoRatio(fppISA.getWhoRatio()); isa.setDosesPerYear(fppISA.getDosesPerYear()); isa.setWastageFactor(wastageFactor); isa.setBufferPercentage(fppISA.getBufferPercentage()); isa.setMinimumValue(fppISA.getMinimumValue()); isa.setMaximumValue(fppISA.getMaximumValue()); isa.setAdjustmentValue(fppISA.getAdjustmentValue()); isa.setPopulationSource(populationSourceId); saveFacilityProgramProductWithISA(facility, pp, isa); saveWastageFactorForSupervisingFacilities(facility, pp, program, populationSourceId); }  @Override String getMessageKey();  }