@Test public void shouldGetProductDoseForProgram() throws Exception { when(programProductRepository.getActiveByProgram(2L)).thenReturn(new ArrayList<ProgramProduct>()); when(repository.getAllDoses()).thenReturn(null); VaccineServiceConfigDTO dto = service.getProductDoseForProgram(2L); verify(programProductRepository).getActiveByProgram(2L); verify(repository, never()).getDosesForProduct(anyLong(), anyLong()); verify(repository).getAllDoses(); }
public VaccineServiceConfigDTO getProductDoseForProgram(Long programId) { VaccineServiceConfigDTO dto = new VaccineServiceConfigDTO(); List<ProductDoseDTO> productDoseDTOs = new ArrayList<>(); List<ProgramProduct> pp = programProductRepository.getActiveByProgram(programId); List<Product> products = new ArrayList<>(); for (ProgramProduct p : pp) { if (!p.getProduct().getFullSupply()) { continue; } List<VaccineProductDose> doses = repository.getDosesForProduct(programId, p.getProduct().getId()); if (!doses.isEmpty()) { ProductDoseDTO productDose = new ProductDoseDTO(); productDose.setProductId(p.getProduct().getId()); productDose.setProductName(p.getProduct().getPrimaryName()); productDose.setDoses(doses); productDoseDTOs.add(productDose); } else { products.add(p.getProduct()); } } dto.setPossibleDoses(repository.getAllDoses()); dto.setPossibleProducts(products); dto.setProtocols(productDoseDTOs); return dto; }
VaccineProductDoseService { public VaccineServiceConfigDTO getProductDoseForProgram(Long programId) { VaccineServiceConfigDTO dto = new VaccineServiceConfigDTO(); List<ProductDoseDTO> productDoseDTOs = new ArrayList<>(); List<ProgramProduct> pp = programProductRepository.getActiveByProgram(programId); List<Product> products = new ArrayList<>(); for (ProgramProduct p : pp) { if (!p.getProduct().getFullSupply()) { continue; } List<VaccineProductDose> doses = repository.getDosesForProduct(programId, p.getProduct().getId()); if (!doses.isEmpty()) { ProductDoseDTO productDose = new ProductDoseDTO(); productDose.setProductId(p.getProduct().getId()); productDose.setProductName(p.getProduct().getPrimaryName()); productDose.setDoses(doses); productDoseDTOs.add(productDose); } else { products.add(p.getProduct()); } } dto.setPossibleDoses(repository.getAllDoses()); dto.setPossibleProducts(products); dto.setProtocols(productDoseDTOs); return dto; } }
VaccineProductDoseService { public VaccineServiceConfigDTO getProductDoseForProgram(Long programId) { VaccineServiceConfigDTO dto = new VaccineServiceConfigDTO(); List<ProductDoseDTO> productDoseDTOs = new ArrayList<>(); List<ProgramProduct> pp = programProductRepository.getActiveByProgram(programId); List<Product> products = new ArrayList<>(); for (ProgramProduct p : pp) { if (!p.getProduct().getFullSupply()) { continue; } List<VaccineProductDose> doses = repository.getDosesForProduct(programId, p.getProduct().getId()); if (!doses.isEmpty()) { ProductDoseDTO productDose = new ProductDoseDTO(); productDose.setProductId(p.getProduct().getId()); productDose.setProductName(p.getProduct().getPrimaryName()); productDose.setDoses(doses); productDoseDTOs.add(productDose); } else { products.add(p.getProduct()); } } dto.setPossibleDoses(repository.getAllDoses()); dto.setPossibleProducts(products); dto.setProtocols(productDoseDTOs); return dto; }  }
VaccineProductDoseService { public VaccineServiceConfigDTO getProductDoseForProgram(Long programId) { VaccineServiceConfigDTO dto = new VaccineServiceConfigDTO(); List<ProductDoseDTO> productDoseDTOs = new ArrayList<>(); List<ProgramProduct> pp = programProductRepository.getActiveByProgram(programId); List<Product> products = new ArrayList<>(); for (ProgramProduct p : pp) { if (!p.getProduct().getFullSupply()) { continue; } List<VaccineProductDose> doses = repository.getDosesForProduct(programId, p.getProduct().getId()); if (!doses.isEmpty()) { ProductDoseDTO productDose = new ProductDoseDTO(); productDose.setProductId(p.getProduct().getId()); productDose.setProductName(p.getProduct().getPrimaryName()); productDose.setDoses(doses); productDoseDTOs.add(productDose); } else { products.add(p.getProduct()); } } dto.setPossibleDoses(repository.getAllDoses()); dto.setPossibleProducts(products); dto.setProtocols(productDoseDTOs); return dto; }  VaccineServiceConfigDTO getProductDoseForProgram(Long programId); List<VaccineProductDose> getForProgram(Long programId); void save(List<ProductDoseDTO> productDoseDTOs); }
VaccineProductDoseService { public VaccineServiceConfigDTO getProductDoseForProgram(Long programId) { VaccineServiceConfigDTO dto = new VaccineServiceConfigDTO(); List<ProductDoseDTO> productDoseDTOs = new ArrayList<>(); List<ProgramProduct> pp = programProductRepository.getActiveByProgram(programId); List<Product> products = new ArrayList<>(); for (ProgramProduct p : pp) { if (!p.getProduct().getFullSupply()) { continue; } List<VaccineProductDose> doses = repository.getDosesForProduct(programId, p.getProduct().getId()); if (!doses.isEmpty()) { ProductDoseDTO productDose = new ProductDoseDTO(); productDose.setProductId(p.getProduct().getId()); productDose.setProductName(p.getProduct().getPrimaryName()); productDose.setDoses(doses); productDoseDTOs.add(productDose); } else { products.add(p.getProduct()); } } dto.setPossibleDoses(repository.getAllDoses()); dto.setPossibleProducts(products); dto.setProtocols(productDoseDTOs); return dto; }  VaccineServiceConfigDTO getProductDoseForProgram(Long programId); List<VaccineProductDose> getForProgram(Long programId); void save(List<ProductDoseDTO> productDoseDTOs);  }