@Test public void testGetConflictMedicationsFromComplexTherapy3() { final ConstantComplexTherapyDto therapy = new ConstantComplexTherapyDto(); final MedicationDto medication1 = new MedicationDto(); medication1.setId(1L); medication1.setName("medication1"); final InfusionIngredientDto ingredient1 = new InfusionIngredientDto(); ingredient1.setMedication(medication1); therapy.getIngredientsList().add(ingredient1); final MedicationDto medication2 = new MedicationDto(); medication2.setId(2L); medication2.setName("medication2"); therapy.getMedications().add(medication2); final InfusionIngredientDto ingredient2 = new InfusionIngredientDto(); ingredient2.setMedication(medication2); therapy.getIngredientsList().add(ingredient2); final MedicationDto medication3 = new MedicationDto(); medication3.setId(3L); medication3.setName("medication3"); therapy.getMedications().add(medication3); final InfusionIngredientDto ingredient3 = new InfusionIngredientDto(); ingredient3.setMedication(medication3); therapy.getIngredientsList().add(ingredient3); final MedicationDto medication4 = new MedicationDto(); medication4.setId(4L); medication4.setName("medication4"); therapy.getMedications().add(medication4); final InfusionIngredientDto ingredient4 = new InfusionIngredientDto(); ingredient4.setMedication(medication4); therapy.getIngredientsList().add(ingredient4); final List<MedicationRouteDto> routes = new ArrayList<>(); therapy.setRoutes(routes); final MedicationRouteDto route1 = new MedicationRouteDto(); route1.setId(1L); route1.setName("route1"); routes.add(route1); final MedicationRouteDto route2 = new MedicationRouteDto(); route2.setId(2L); route2.setName("route2"); routes.add(route2); final MedicationRouteDto route3 = new MedicationRouteDto(); route3.setId(3L); route3.setName("route3"); routes.add(route3); final SetMultimap<Long, Long> medicationsWithRoutes = HashMultimap.create(); medicationsWithRoutes.put(1L, 4L); medicationsWithRoutes.put(1L, 5L); medicationsWithRoutes.put(1L, 6L); medicationsWithRoutes.put(2L, 4L); medicationsWithRoutes.put(3L, 1L); medicationsWithRoutes.put(3L, 2L); medicationsWithRoutes.put(4L, 3L); medicationsWithRoutes.put(4L, 4L); final List<NamedExternalDto> conflictMedicationIds = mentalHealthAdditionalWarningsProvider.getConflictMedications( therapy, new MentalHealthAllowedMedicationsDo(medicationsWithRoutes, Collections.emptySet())); Assert.assertEquals(2, conflictMedicationIds.size()); Assert.assertTrue(conflictMedicationIds.contains(new NamedExternalDto("1", "medication1"))); Assert.assertTrue(conflictMedicationIds.contains(new NamedExternalDto("2", "medication2"))); }
List<NamedExternalDto> getConflictMedications( final TherapyDto therapy, final MentalHealthAllowedMedicationsDo allowedMedications) { final List<Long> routeIds = therapy.getRoutes().stream().map(MedicationRouteDto::getId).collect(Collectors.toList()); return therapy.getMedications() .stream() .filter(m -> m.getId() != null) .filter(m -> medicationsBo.isMentalHealthMedication(m.getId())) .filter(mentalHealthWarningsHandler.isMedicationWithRoutesAllowed(routeIds, allowedMedications).negate()) .map(m -> new NamedExternalDto(String.valueOf(m.getId()), m.getName())) .collect(Collectors.toList()); }
MentalHealthAdditionalWarningsProvider implements AdditionalWarningsProvider { List<NamedExternalDto> getConflictMedications( final TherapyDto therapy, final MentalHealthAllowedMedicationsDo allowedMedications) { final List<Long> routeIds = therapy.getRoutes().stream().map(MedicationRouteDto::getId).collect(Collectors.toList()); return therapy.getMedications() .stream() .filter(m -> m.getId() != null) .filter(m -> medicationsBo.isMentalHealthMedication(m.getId())) .filter(mentalHealthWarningsHandler.isMedicationWithRoutesAllowed(routeIds, allowedMedications).negate()) .map(m -> new NamedExternalDto(String.valueOf(m.getId()), m.getName())) .collect(Collectors.toList()); } }
MentalHealthAdditionalWarningsProvider implements AdditionalWarningsProvider { List<NamedExternalDto> getConflictMedications( final TherapyDto therapy, final MentalHealthAllowedMedicationsDo allowedMedications) { final List<Long> routeIds = therapy.getRoutes().stream().map(MedicationRouteDto::getId).collect(Collectors.toList()); return therapy.getMedications() .stream() .filter(m -> m.getId() != null) .filter(m -> medicationsBo.isMentalHealthMedication(m.getId())) .filter(mentalHealthWarningsHandler.isMedicationWithRoutesAllowed(routeIds, allowedMedications).negate()) .map(m -> new NamedExternalDto(String.valueOf(m.getId()), m.getName())) .collect(Collectors.toList()); }  }
MentalHealthAdditionalWarningsProvider implements AdditionalWarningsProvider { List<NamedExternalDto> getConflictMedications( final TherapyDto therapy, final MentalHealthAllowedMedicationsDo allowedMedications) { final List<Long> routeIds = therapy.getRoutes().stream().map(MedicationRouteDto::getId).collect(Collectors.toList()); return therapy.getMedications() .stream() .filter(m -> m.getId() != null) .filter(m -> medicationsBo.isMentalHealthMedication(m.getId())) .filter(mentalHealthWarningsHandler.isMedicationWithRoutesAllowed(routeIds, allowedMedications).negate()) .map(m -> new NamedExternalDto(String.valueOf(m.getId()), m.getName())) .collect(Collectors.toList()); }  @Required void setMedicationsTasksProvider(final MedicationsTasksProvider medicationsTasksProvider); @Required void setMedicationsBo(final MedicationsBo medicationsBo); @Required void setMentalHealthFormProvider(final MentalHealthFormProvider mentalHealthFormProvider); @Required void setMentalHealthWarningsHandler(final MentalHealthWarningsHandler mentalHealthWarningsHandler); @Required void setMedicationsOpenEhrDao(final MedicationsOpenEhrDao medicationsOpenEhrDao); @Required void setProcessService(final ProcessService processService); @Override Opt<AdditionalWarningsDto> getAdditionalWarnings(
      @Nonnull final String patientId,
      @Nonnull final PatientDataForMedicationsDto patientData,
      @Nonnull final DateTime when,
      @Nonnull final Locale locale); }
MentalHealthAdditionalWarningsProvider implements AdditionalWarningsProvider { List<NamedExternalDto> getConflictMedications( final TherapyDto therapy, final MentalHealthAllowedMedicationsDo allowedMedications) { final List<Long> routeIds = therapy.getRoutes().stream().map(MedicationRouteDto::getId).collect(Collectors.toList()); return therapy.getMedications() .stream() .filter(m -> m.getId() != null) .filter(m -> medicationsBo.isMentalHealthMedication(m.getId())) .filter(mentalHealthWarningsHandler.isMedicationWithRoutesAllowed(routeIds, allowedMedications).negate()) .map(m -> new NamedExternalDto(String.valueOf(m.getId()), m.getName())) .collect(Collectors.toList()); }  @Required void setMedicationsTasksProvider(final MedicationsTasksProvider medicationsTasksProvider); @Required void setMedicationsBo(final MedicationsBo medicationsBo); @Required void setMentalHealthFormProvider(final MentalHealthFormProvider mentalHealthFormProvider); @Required void setMentalHealthWarningsHandler(final MentalHealthWarningsHandler mentalHealthWarningsHandler); @Required void setMedicationsOpenEhrDao(final MedicationsOpenEhrDao medicationsOpenEhrDao); @Required void setProcessService(final ProcessService processService); @Override Opt<AdditionalWarningsDto> getAdditionalWarnings(
      @Nonnull final String patientId,
      @Nonnull final PatientDataForMedicationsDto patientData,
      @Nonnull final DateTime when,
      @Nonnull final Locale locale);  }