PrescriptionFacadeEjb implements PrescriptionFacade { @Override public List<PrescriptionIndexDto> getIndexList(PrescriptionCriteria criteria) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<PrescriptionIndexDto> cq = cb.createQuery(PrescriptionIndexDto.class); Root<Prescription> prescription = cq.from(Prescription.class); PrescriptionJoins joins = new PrescriptionJoins(prescription); cq.multiselect( Stream .concat( Stream.of( prescription.get(Prescription.UUID), prescription.get(Prescription.PRESCRIPTION_TYPE), prescription.get(Prescription.PRESCRIPTION_DETAILS), prescription.get(Prescription.TYPE_OF_DRUG), prescription.get(Prescription.PRESCRIPTION_DATE), prescription.get(Prescription.PRESCRIPTION_START), prescription.get(Prescription.PRESCRIPTION_END), prescription.get(Prescription.FREQUENCY), prescription.get(Prescription.DOSE), prescription.get(Prescription.ROUTE), prescription.get(Prescription.ROUTE_DETAILS), prescription.get(Prescription.PRESCRIBING_CLINICIAN)), getCaseJurisdictionSelections(joins)) .collect(Collectors.toList())); if (criteria != null) { cq.where(service.buildCriteriaFilter(criteria, cb, prescription)); } cq.orderBy(cb.desc(prescription.get(Prescription.PRESCRIPTION_DATE))); List<PrescriptionIndexDto> indexList = em.createQuery(cq).getResultList(); Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue)); pseudonymizer.pseudonymizeDtoCollection( PrescriptionIndexDto.class, indexList, p -> caseJurisdictionChecker.isInJurisdictionOrOwned(p.getCaseJurisdiction()), (p, inJurisdiction) -> { pseudonymizer.pseudonymizeDto(PrescriptionIndexDto.PrescriptionIndexType.class, p.getPrescriptionIndexType(), inJurisdiction, null); pseudonymizer.pseudonymizeDto(PrescriptionIndexDto.PrescriptionIndexRoute.class, p.getPrescriptionIndexRoute(), inJurisdiction, null); }); return indexList; }  @Override List<PrescriptionIndexDto> getIndexList(PrescriptionCriteria criteria); @Override PrescriptionDto getPrescriptionByUuid(String uuid); @Override PrescriptionDto savePrescription(PrescriptionDto prescription); @Override void deletePrescription(String prescriptionUuid); @Override List<PrescriptionDto> getAllActivePrescriptionsAfter(Date date); @Override List<PrescriptionDto> getByUuids(List<String> uuids); @Override List<String> getAllActiveUuids(); @Override List<PrescriptionExportDto> getExportList(CaseCriteria criteria, int first, int max); static PrescriptionDto toDto(Prescription source); static PrescriptionReferenceDto toReferenceDto(Prescription source); Prescription fromDto(@NotNull PrescriptionDto source, Prescription target);  }
@Test public void testPrescriptionIndexListGeneration() { 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.createPrescription(caze); List<PrescriptionIndexDto> results = getPrescriptionFacade().getIndexList(null); assertEquals(1, results.size()); }