HibernateMedicationsDao extends HibernateDaoSupport implements MedicationsDao { @Override public List<String> getCustomGroupNames(final String careProviderId) { return getHibernateTemplate().execute( session -> new Hql() .select( medicationCustomGroup.get("name"), medicationCustomGroup.get("sortOrder") ) .distinct() .from( medicationCustomGroupMember.innerJoin("medicationCustomGroup").as(medicationCustomGroup) ) .where( medicationCustomGroup.get("careProviderId").eq(careProviderId) ) .orderBy(medicationCustomGroup.get("sortOrder")) .buildQuery(session, Object[].class) .list( new TupleProcessor<String>() { @Override protected String process(final boolean hasNextTuple) throws ProcessingException { return next(); } }) ); }  @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);  }
@Test @DatabaseSetup("HibernateMedicationsDaoTest.testCustomGroups.xml") public void testGetCustomGroupNames() { final Set<Long> medicationCodes = new HashSet<>(); medicationCodes.add(1L); medicationCodes.add(2L); medicationCodes.add(3L); medicationCodes.add(4L); final Map<Long, Pair<String, Integer>> resultMapPek = medicationsDao.getCustomGroupNameSortOrderMap("1", medicationCodes); assertEquals(1L, (long)resultMapPek.size()); assertEquals("Paracetamol Kardio Hosp", resultMapPek.get(1L).getFirst()); assertEquals(Integer.valueOf(2), resultMapPek.get(1L).getSecond()); final Map<Long, Pair<String, Integer>> resultMapKookit = medicationsDao.getCustomGroupNameSortOrderMap("2", medicationCodes); assertEquals(4L, (long)resultMapKookit.size()); assertEquals("Paracetamol KOOKIT EIT", resultMapKookit.get(1L).getFirst()); assertEquals(Integer.valueOf(1), resultMapKookit.get(1L).getSecond()); }