@Test @DatabaseSetup("HibernateMedicationsDaoTest.testLoadMedicationWarnings.xml") public void testGetMedicationWarningsEmptyMedicationList() { final Collection<MedicationsWarningDto> customWarningsForMedication = medicationsDao.getCustomWarningsForMedication( Collections.emptySet(), DateTime.now()); assertTrue(customWarningsForMedication.isEmpty()); }
@Override public Collection<MedicationsWarningDto> getCustomWarningsForMedication( @Nonnull final Set<Long> medicationIds, @Nonnull final DateTime when) { Preconditions.checkNotNull(medicationIds, "medicationIds must not be null!"); Preconditions.checkNotNull(when, "when must not be null!"); if (medicationIds.isEmpty()) { return Collections.emptyList(); } return getHibernateTemplate().execute( session -> new Hql() .select( medicationWarning.get("description"), medicationWarning.get("severity"), medication.id(), medicationVersion.get("name") ) .from( medicationWarning.innerJoin("medication").as(medication), medication.innerJoin("versions").as(medicationVersion) ) .where( medication.id().in(medicationIds), effectiveEntities(medicationVersion, medicationWarning).notDeletedAndEffectiveAt(when) ) .buildQuery(session, Object[].class) .list( new TupleProcessor<MedicationsWarningDto>() { @Override protected MedicationsWarningDto process(final boolean hasNextTuple) throws ProcessingException { final String description = nextString(); final WarningSeverity severity = next(WarningSeverity.class); final Long medicationId = nextLong(); final String medicationName = nextString(); final MedicationsWarningDto warningDto = new MedicationsWarningDto(); warningDto.setDescription(description); warningDto.setSeverity(severity); warningDto.setType(WarningType.CUSTOM); warningDto.setMedications(Collections.singletonList(new NamedExternalDto( String.valueOf(medicationId), medicationName))); return warningDto; } })); }
HibernateMedicationsDao extends HibernateDaoSupport implements MedicationsDao { @Override public Collection<MedicationsWarningDto> getCustomWarningsForMedication( @Nonnull final Set<Long> medicationIds, @Nonnull final DateTime when) { Preconditions.checkNotNull(medicationIds, "medicationIds must not be null!"); Preconditions.checkNotNull(when, "when must not be null!"); if (medicationIds.isEmpty()) { return Collections.emptyList(); } return getHibernateTemplate().execute( session -> new Hql() .select( medicationWarning.get("description"), medicationWarning.get("severity"), medication.id(), medicationVersion.get("name") ) .from( medicationWarning.innerJoin("medication").as(medication), medication.innerJoin("versions").as(medicationVersion) ) .where( medication.id().in(medicationIds), effectiveEntities(medicationVersion, medicationWarning).notDeletedAndEffectiveAt(when) ) .buildQuery(session, Object[].class) .list( new TupleProcessor<MedicationsWarningDto>() { @Override protected MedicationsWarningDto process(final boolean hasNextTuple) throws ProcessingException { final String description = nextString(); final WarningSeverity severity = next(WarningSeverity.class); final Long medicationId = nextLong(); final String medicationName = nextString(); final MedicationsWarningDto warningDto = new MedicationsWarningDto(); warningDto.setDescription(description); warningDto.setSeverity(severity); warningDto.setType(WarningType.CUSTOM); warningDto.setMedications(Collections.singletonList(new NamedExternalDto( String.valueOf(medicationId), medicationName))); return warningDto; } })); } }
HibernateMedicationsDao extends HibernateDaoSupport implements MedicationsDao { @Override public Collection<MedicationsWarningDto> getCustomWarningsForMedication( @Nonnull final Set<Long> medicationIds, @Nonnull final DateTime when) { Preconditions.checkNotNull(medicationIds, "medicationIds must not be null!"); Preconditions.checkNotNull(when, "when must not be null!"); if (medicationIds.isEmpty()) { return Collections.emptyList(); } return getHibernateTemplate().execute( session -> new Hql() .select( medicationWarning.get("description"), medicationWarning.get("severity"), medication.id(), medicationVersion.get("name") ) .from( medicationWarning.innerJoin("medication").as(medication), medication.innerJoin("versions").as(medicationVersion) ) .where( medication.id().in(medicationIds), effectiveEntities(medicationVersion, medicationWarning).notDeletedAndEffectiveAt(when) ) .buildQuery(session, Object[].class) .list( new TupleProcessor<MedicationsWarningDto>() { @Override protected MedicationsWarningDto process(final boolean hasNextTuple) throws ProcessingException { final String description = nextString(); final WarningSeverity severity = next(WarningSeverity.class); final Long medicationId = nextLong(); final String medicationName = nextString(); final MedicationsWarningDto warningDto = new MedicationsWarningDto(); warningDto.setDescription(description); warningDto.setSeverity(severity); warningDto.setType(WarningType.CUSTOM); warningDto.setMedications(Collections.singletonList(new NamedExternalDto( String.valueOf(medicationId), medicationName))); return warningDto; } })); }  }
HibernateMedicationsDao extends HibernateDaoSupport implements MedicationsDao { @Override public Collection<MedicationsWarningDto> getCustomWarningsForMedication( @Nonnull final Set<Long> medicationIds, @Nonnull final DateTime when) { Preconditions.checkNotNull(medicationIds, "medicationIds must not be null!"); Preconditions.checkNotNull(when, "when must not be null!"); if (medicationIds.isEmpty()) { return Collections.emptyList(); } return getHibernateTemplate().execute( session -> new Hql() .select( medicationWarning.get("description"), medicationWarning.get("severity"), medication.id(), medicationVersion.get("name") ) .from( medicationWarning.innerJoin("medication").as(medication), medication.innerJoin("versions").as(medicationVersion) ) .where( medication.id().in(medicationIds), effectiveEntities(medicationVersion, medicationWarning).notDeletedAndEffectiveAt(when) ) .buildQuery(session, Object[].class) .list( new TupleProcessor<MedicationsWarningDto>() { @Override protected MedicationsWarningDto process(final boolean hasNextTuple) throws ProcessingException { final String description = nextString(); final WarningSeverity severity = next(WarningSeverity.class); final Long medicationId = nextLong(); final String medicationName = nextString(); final MedicationsWarningDto warningDto = new MedicationsWarningDto(); warningDto.setDescription(description); warningDto.setSeverity(severity); warningDto.setType(WarningType.CUSTOM); warningDto.setMedications(Collections.singletonList(new NamedExternalDto( String.valueOf(medicationId), medicationName))); return warningDto; } })); }  @Required void setCatalogDao(final CatalogDao catalogDao); @Required void setDoseFormDtoMapper(final DoseFormDtoMapper doseFormDtoMapper); @Required void setMedicationsBo(final MedicationsBo medicationsBo); @Required void setTherapyDisplayProvider(final TherapyDisplayProvider therapyDisplayProvider); @Override Map<Long, MedicationHolderDto> loadMedicationsMap(final DateTime when); @Override MedicationDataDto getMedicationData(
      final long medicationId,
      final String careProviderId,
      @Nonnull final DateTime when); @Override Map<Long, MedicationDataDto> getMedicationDataMap(
      @Nonnull final Set<Long> medicationIds,
      final String careProviderId,
      @Nonnull final DateTime when); @Override List<Long> getMedicationIdsWithIngredientId(final long ingredientId, final DateTime when); @Override Set<Long> getMedicationIdsWithIngredientRule(
      final MedicationRuleEnum medicationRuleEnum,
      final DateTime when); @Override List<MedicationRouteDto> getMedicationRoutes(final long medicationId, final DateTime when); @Override String getMedicationExternalId(final String externalSystem, final long medicationId, final DateTime when); @Override Set<Long> findSimilarMedicationsIds(
      final long medicationId,
      @Nonnull final Collection<Long> routeIds,
      @Nonnull final DateTime when); @Override boolean isProductBasedMedication(final long medicationId); @Override List<MedicationSupplyCandidateDto> getMedicationSupplyCandidates(
      final long medicationId,
      final long routeId,
      final DateTime when); @Override List<MedicationDto> getMedicationChildProducts(
      final long medicationId,
      @Nonnull final Collection<Long> routeIds,
      @Nonnull final DateTime when); @Override MedicationDto getMedicationById(final Long medicationId, final DateTime when); @Override Map<Long, MedicationDto> getMedicationsMap(final Set<Long> medicationIds, final DateTime when); @Override DoseFormDto getDoseFormByCode(final String doseFormCode, final DateTime when); @Override Map<String, String> getMedicationExternalValues(
      final String externalSystem, final MedicationsExternalValueType valueType, final Set<String> valuesSet); @Override List<MedicationRouteDto> getRoutes(final DateTime when); @Override List<DoseFormDto> getDoseForms(final DateTime when); @Override List<String> getMedicationBasicUnits(); @Override Map<Long, Pair<String, Integer>> getCustomGroupNameSortOrderMap(
      final String careProviderId, final Set<Long> medicationIds); @Override List<String> getCustomGroupNames(final String careProviderId); @Override TherapyTemplatesDto getTherapyTemplates(
      @Nonnull final String patientId,
      @Nonnull final String userId,
      @Nonnull final TherapyTemplateModeEnum templateMode,
      final String careProviderId,
      final Double referenceWeight,
      final Double patientHeight,
      @Nonnull final Locale locale); @Override long saveTherapyTemplate(
      final TherapyTemplateDto templateDto,
      final TherapyTemplateModeEnum templateMode,
      final String userId); @Override void deleteTherapyTemplate(final long templateId); @Override Map<Long, MedicationLevelEnum> getMedicationsLevels(final Set<Long> medicationIds); @Override String getPatientLastLinkName(final long patientId); @Override void savePatientLastLinkName(final long patientId, final String lastLinkName); @Override Map<ActionReasonType, List<CodedNameDto>> getActionReasons(
      @Nonnull final DateTime when,
      final ActionReasonType type); @Override List<MentalHealthTemplateDto> getMentalHealthTemplates(); @Override List<MentalHealthTemplateMemberDto> getMentalHealthTemplateMembers(@Nonnull final Collection<Long> mentalHealthTemplateIds); @Override Map<Long, MedicationRouteDto> loadRoutesMap(final DateTime when); @Override Collection<MedicationsWarningDto> getCustomWarningsForMedication(
      @Nonnull final Set<Long> medicationIds,
      @Nonnull final DateTime when); @Override Long getMedicationIdForBarcode(@Nonnull final String barcode); }
HibernateMedicationsDao extends HibernateDaoSupport implements MedicationsDao { @Override public Collection<MedicationsWarningDto> getCustomWarningsForMedication( @Nonnull final Set<Long> medicationIds, @Nonnull final DateTime when) { Preconditions.checkNotNull(medicationIds, "medicationIds must not be null!"); Preconditions.checkNotNull(when, "when must not be null!"); if (medicationIds.isEmpty()) { return Collections.emptyList(); } return getHibernateTemplate().execute( session -> new Hql() .select( medicationWarning.get("description"), medicationWarning.get("severity"), medication.id(), medicationVersion.get("name") ) .from( medicationWarning.innerJoin("medication").as(medication), medication.innerJoin("versions").as(medicationVersion) ) .where( medication.id().in(medicationIds), effectiveEntities(medicationVersion, medicationWarning).notDeletedAndEffectiveAt(when) ) .buildQuery(session, Object[].class) .list( new TupleProcessor<MedicationsWarningDto>() { @Override protected MedicationsWarningDto process(final boolean hasNextTuple) throws ProcessingException { final String description = nextString(); final WarningSeverity severity = next(WarningSeverity.class); final Long medicationId = nextLong(); final String medicationName = nextString(); final MedicationsWarningDto warningDto = new MedicationsWarningDto(); warningDto.setDescription(description); warningDto.setSeverity(severity); warningDto.setType(WarningType.CUSTOM); warningDto.setMedications(Collections.singletonList(new NamedExternalDto( String.valueOf(medicationId), medicationName))); return warningDto; } })); }  @Required void setCatalogDao(final CatalogDao catalogDao); @Required void setDoseFormDtoMapper(final DoseFormDtoMapper doseFormDtoMapper); @Required void setMedicationsBo(final MedicationsBo medicationsBo); @Required void setTherapyDisplayProvider(final TherapyDisplayProvider therapyDisplayProvider); @Override Map<Long, MedicationHolderDto> loadMedicationsMap(final DateTime when); @Override MedicationDataDto getMedicationData(
      final long medicationId,
      final String careProviderId,
      @Nonnull final DateTime when); @Override Map<Long, MedicationDataDto> getMedicationDataMap(
      @Nonnull final Set<Long> medicationIds,
      final String careProviderId,
      @Nonnull final DateTime when); @Override List<Long> getMedicationIdsWithIngredientId(final long ingredientId, final DateTime when); @Override Set<Long> getMedicationIdsWithIngredientRule(
      final MedicationRuleEnum medicationRuleEnum,
      final DateTime when); @Override List<MedicationRouteDto> getMedicationRoutes(final long medicationId, final DateTime when); @Override String getMedicationExternalId(final String externalSystem, final long medicationId, final DateTime when); @Override Set<Long> findSimilarMedicationsIds(
      final long medicationId,
      @Nonnull final Collection<Long> routeIds,
      @Nonnull final DateTime when); @Override boolean isProductBasedMedication(final long medicationId); @Override List<MedicationSupplyCandidateDto> getMedicationSupplyCandidates(
      final long medicationId,
      final long routeId,
      final DateTime when); @Override List<MedicationDto> getMedicationChildProducts(
      final long medicationId,
      @Nonnull final Collection<Long> routeIds,
      @Nonnull final DateTime when); @Override MedicationDto getMedicationById(final Long medicationId, final DateTime when); @Override Map<Long, MedicationDto> getMedicationsMap(final Set<Long> medicationIds, final DateTime when); @Override DoseFormDto getDoseFormByCode(final String doseFormCode, final DateTime when); @Override Map<String, String> getMedicationExternalValues(
      final String externalSystem, final MedicationsExternalValueType valueType, final Set<String> valuesSet); @Override List<MedicationRouteDto> getRoutes(final DateTime when); @Override List<DoseFormDto> getDoseForms(final DateTime when); @Override List<String> getMedicationBasicUnits(); @Override Map<Long, Pair<String, Integer>> getCustomGroupNameSortOrderMap(
      final String careProviderId, final Set<Long> medicationIds); @Override List<String> getCustomGroupNames(final String careProviderId); @Override TherapyTemplatesDto getTherapyTemplates(
      @Nonnull final String patientId,
      @Nonnull final String userId,
      @Nonnull final TherapyTemplateModeEnum templateMode,
      final String careProviderId,
      final Double referenceWeight,
      final Double patientHeight,
      @Nonnull final Locale locale); @Override long saveTherapyTemplate(
      final TherapyTemplateDto templateDto,
      final TherapyTemplateModeEnum templateMode,
      final String userId); @Override void deleteTherapyTemplate(final long templateId); @Override Map<Long, MedicationLevelEnum> getMedicationsLevels(final Set<Long> medicationIds); @Override String getPatientLastLinkName(final long patientId); @Override void savePatientLastLinkName(final long patientId, final String lastLinkName); @Override Map<ActionReasonType, List<CodedNameDto>> getActionReasons(
      @Nonnull final DateTime when,
      final ActionReasonType type); @Override List<MentalHealthTemplateDto> getMentalHealthTemplates(); @Override List<MentalHealthTemplateMemberDto> getMentalHealthTemplateMembers(@Nonnull final Collection<Long> mentalHealthTemplateIds); @Override Map<Long, MedicationRouteDto> loadRoutesMap(final DateTime when); @Override Collection<MedicationsWarningDto> getCustomWarningsForMedication(
      @Nonnull final Set<Long> medicationIds,
      @Nonnull final DateTime when); @Override Long getMedicationIdForBarcode(@Nonnull final String barcode);  }