@Test public void testGetConflictMedicationsFromSimple() { final long medication1Id = 2L; final String medication1Name = "medication2"; final ConstantSimpleTherapyDto therapy = new ConstantSimpleTherapyDto(); final MedicationDto medication = new MedicationDto(); therapy.setMedication(medication); medication.setId(medication1Id); medication.setName(medication1Name); final List<MedicationRouteDto> routes = new ArrayList<>(); therapy.setRoutes(routes); final MedicationRouteDto route1 = new MedicationRouteDto(); route1.setId(1L); route1.setName("route1"); routes.add(route1); final SetMultimap<Long, Long> medicationsWithRoutes = HashMultimap.create(); medicationsWithRoutes.put(1L, 3L); final List<NamedExternalDto> conflictMedicationIds = mentalHealthAdditionalWarningsProvider.getConflictMedications( therapy, new MentalHealthAllowedMedicationsDo(medicationsWithRoutes, Collections.emptySet())); Assert.assertTrue(conflictMedicationIds.contains(new NamedExternalDto(String.valueOf(medication1Id), medication1Name))); }
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);  }