TreatmentFacadeEjb implements TreatmentFacade { @Override public List<TreatmentIndexDto> getIndexList(TreatmentCriteria criteria) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<TreatmentIndexDto> cq = cb.createQuery(TreatmentIndexDto.class); Root<Treatment> treatment = cq.from(Treatment.class); TreatmentJoins joins = new TreatmentJoins(treatment); cq.multiselect( Stream .concat( Stream.of( treatment.get(Treatment.UUID), treatment.get(Treatment.TREATMENT_TYPE), treatment.get(Treatment.TREATMENT_DETAILS), treatment.get(Treatment.TYPE_OF_DRUG), treatment.get(Treatment.TREATMENT_DATE_TIME), treatment.get(Treatment.DOSE), treatment.get(Treatment.ROUTE), treatment.get(Treatment.ROUTE_DETAILS), treatment.get(Treatment.EXECUTING_CLINICIAN)), getCaseJurisdictionSelections(joins)) .collect(Collectors.toList())); if (criteria != null) { cq.where(service.buildCriteriaFilter(criteria, cb, treatment)); } cq.orderBy(cb.desc(treatment.get(Treatment.TREATMENT_DATE_TIME))); List<TreatmentIndexDto> indexList = em.createQuery(cq).getResultList(); Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue)); pseudonymizer.pseudonymizeDtoCollection( TreatmentIndexDto.class, indexList, t -> caseJurisdictionChecker.isInJurisdictionOrOwned(t.getCaseJurisdiction()), (t, inJurisdiction) -> { pseudonymizer.pseudonymizeDto(TreatmentIndexDto.TreatmentIndexType.class, t.getTreatmentIndexType(), inJurisdiction, null); pseudonymizer.pseudonymizeDto(TreatmentIndexDto.TreatmentIndexRoute.class, t.getTreatmentIndexRoute(), inJurisdiction, null); }); return indexList; }  @Override List<TreatmentIndexDto> getIndexList(TreatmentCriteria criteria); @Override TreatmentDto getTreatmentByUuid(String uuid); @Override TreatmentDto saveTreatment(TreatmentDto source); @Override void deleteTreatment(String treatmentUuid); @Override List<TreatmentDto> getAllActiveTreatmentsAfter(Date date); @Override List<TreatmentDto> getByUuids(List<String> uuids); @Override List<String> getAllActiveUuids(); @Override List<TreatmentExportDto> getExportList(CaseCriteria criteria, int first, int max); static TreatmentDto toDto(Treatment source); Treatment fromDto(@NotNull TreatmentDto source, Treatment target);  }
@Test public void testTreatmentIndexListGeneration() { RDCFEntities rdcf = creator.createRDCFEntities(); UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR, UserRole.CASE_SUPERVISOR); PersonDto casePerson = creator.createPerson("Case", "Person"); CaseDataDto caze = creator.createCase(user.toReference(), casePerson.toReference(), rdcf); creator.createTreatment(caze); List<TreatmentIndexDto> results = getTreatmentFacade().getIndexList(null); assertEquals(1, results.size()); }