Search in sources :

Example 1 with EpiData

use of de.symeda.sormas.backend.epidata.EpiData in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method getExportList.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<CaseExportDto> getExportList(CaseCriteria caseCriteria, Collection<String> selectedRows, CaseExportType exportType, int first, int max, ExportConfigurationDto exportConfiguration, Language userLanguage) {
    Boolean previousCaseManagementDataCriteria = caseCriteria.getMustHaveCaseManagementData();
    if (CaseExportType.CASE_MANAGEMENT == exportType) {
        caseCriteria.setMustHaveCaseManagementData(Boolean.TRUE);
    }
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CaseExportDto> cq = cb.createQuery(CaseExportDto.class);
    Root<Case> caseRoot = cq.from(Case.class);
    final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caseRoot);
    final CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
    // Events count subquery
    Subquery<Long> eventCountSq = cq.subquery(Long.class);
    Root<EventParticipant> eventCountRoot = eventCountSq.from(EventParticipant.class);
    Join<EventParticipant, Event> event = eventCountRoot.join(EventParticipant.EVENT, JoinType.INNER);
    Join<EventParticipant, Case> resultingCase = eventCountRoot.join(EventParticipant.RESULTING_CASE, JoinType.INNER);
    eventCountSq.where(cb.and(cb.equal(resultingCase.get(Case.ID), caseRoot.get(Case.ID)), cb.isFalse(event.get(Event.DELETED)), cb.isFalse(event.get(Event.ARCHIVED)), cb.isFalse(eventCountRoot.get(EventParticipant.DELETED))));
    eventCountSq.select(cb.countDistinct(event.get(Event.ID)));
    // @formatter:off
    cq.multiselect(caseRoot.get(Case.ID), joins.getPerson().get(Person.ID), joins.getPersonAddress().get(Location.ID), joins.getEpiData().get(EpiData.ID), joins.getSymptoms().get(Symptoms.ID), joins.getHospitalization().get(Hospitalization.ID), joins.getHealthConditions().get(HealthConditions.ID), caseRoot.get(Case.UUID), caseRoot.get(Case.EPID_NUMBER), caseRoot.get(Case.DISEASE), caseRoot.get(Case.DISEASE_VARIANT), caseRoot.get(Case.DISEASE_DETAILS), caseRoot.get(Case.DISEASE_VARIANT_DETAILS), joins.getPerson().get(Person.UUID), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), joins.getPerson().get(Person.SALUTATION), joins.getPerson().get(Person.OTHER_SALUTATION), joins.getPerson().get(Person.SEX), caseRoot.get(Case.PREGNANT), joins.getPerson().get(Person.APPROXIMATE_AGE), joins.getPerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getPerson().get(Person.BIRTHDATE_DD), joins.getPerson().get(Person.BIRTHDATE_MM), joins.getPerson().get(Person.BIRTHDATE_YYYY), caseRoot.get(Case.REPORT_DATE), joins.getRegion().get(Region.NAME), joins.getDistrict().get(District.NAME), joins.getCommunity().get(Community.NAME), caseRoot.get(Case.FACILITY_TYPE), joins.getFacility().get(Facility.NAME), joins.getFacility().get(Facility.UUID), caseRoot.get(Case.HEALTH_FACILITY_DETAILS), joins.getPointOfEntry().get(PointOfEntry.NAME), joins.getPointOfEntry().get(PointOfEntry.UUID), caseRoot.get(Case.POINT_OF_ENTRY_DETAILS), caseRoot.get(Case.CASE_CLASSIFICATION), caseRoot.get(Case.CLINICAL_CONFIRMATION), caseRoot.get(Case.EPIDEMIOLOGICAL_CONFIRMATION), caseRoot.get(Case.LABORATORY_DIAGNOSTIC_CONFIRMATION), caseRoot.get(Case.NOT_A_CASE_REASON_NEGATIVE_TEST), caseRoot.get(Case.NOT_A_CASE_REASON_PHYSICIAN_INFORMATION), caseRoot.get(Case.NOT_A_CASE_REASON_DIFFERENT_PATHOGEN), caseRoot.get(Case.NOT_A_CASE_REASON_OTHER), caseRoot.get(Case.NOT_A_CASE_REASON_DETAILS), caseRoot.get(Case.INVESTIGATION_STATUS), caseRoot.get(Case.INVESTIGATED_DATE), caseRoot.get(Case.OUTCOME), caseRoot.get(Case.OUTCOME_DATE), caseRoot.get(Case.SEQUELAE), caseRoot.get(Case.SEQUELAE_DETAILS), caseRoot.get(Case.BLOOD_ORGAN_OR_TISSUE_DONATED), caseRoot.get(Case.FOLLOW_UP_STATUS), caseRoot.get(Case.FOLLOW_UP_UNTIL), caseRoot.get(Case.NOSOCOMIAL_OUTBREAK), caseRoot.get(Case.INFECTION_SETTING), caseRoot.get(Case.PROHIBITION_TO_WORK), caseRoot.get(Case.PROHIBITION_TO_WORK_FROM), caseRoot.get(Case.PROHIBITION_TO_WORK_UNTIL), caseRoot.get(Case.RE_INFECTION), caseRoot.get(Case.PREVIOUS_INFECTION_DATE), caseRoot.get(Case.REINFECTION_STATUS), caseRoot.get(Case.REINFECTION_DETAILS), // quarantine
    caseRoot.get(Case.QUARANTINE), caseRoot.get(Case.QUARANTINE_TYPE_DETAILS), caseRoot.get(Case.QUARANTINE_FROM), caseRoot.get(Case.QUARANTINE_TO), caseRoot.get(Case.QUARANTINE_HELP_NEEDED), caseRoot.get(Case.QUARANTINE_ORDERED_VERBALLY), caseRoot.get(Case.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT), caseRoot.get(Case.QUARANTINE_ORDERED_VERBALLY_DATE), caseRoot.get(Case.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE), caseRoot.get(Case.QUARANTINE_EXTENDED), caseRoot.get(Case.QUARANTINE_REDUCED), caseRoot.get(Case.QUARANTINE_OFFICIAL_ORDER_SENT), caseRoot.get(Case.QUARANTINE_OFFICIAL_ORDER_SENT_DATE), joins.getHospitalization().get(Hospitalization.ADMITTED_TO_HEALTH_FACILITY), joins.getHospitalization().get(Hospitalization.ADMISSION_DATE), joins.getHospitalization().get(Hospitalization.DISCHARGE_DATE), joins.getHospitalization().get(Hospitalization.LEFT_AGAINST_ADVICE), joins.getPerson().get(Person.PRESENT_CONDITION), joins.getPerson().get(Person.DEATH_DATE), joins.getPerson().get(Person.BURIAL_DATE), joins.getPerson().get(Person.BURIAL_CONDUCTOR), joins.getPerson().get(Person.BURIAL_PLACE_DESCRIPTION), // address
    joins.getPersonAddressRegion().get(Region.NAME), joins.getPersonAddressDistrict().get(District.NAME), joins.getPersonAddressCommunity().get(Community.NAME), joins.getPersonAddress().get(Location.CITY), joins.getPersonAddress().get(Location.STREET), joins.getPersonAddress().get(Location.HOUSE_NUMBER), joins.getPersonAddress().get(Location.ADDITIONAL_INFORMATION), joins.getPersonAddress().get(Location.POSTAL_CODE), joins.getPersonAddressFacility().get(Facility.NAME), joins.getPersonAddressFacility().get(Facility.UUID), joins.getPersonAddress().get(Location.FACILITY_DETAILS), // phone
    caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_PHONE_SUBQUERY), caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_PHONE_OWNER_SUBQUERY), caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_EMAIL_SUBQUERY), caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY), joins.getPerson().get(Person.EDUCATION_TYPE), joins.getPerson().get(Person.EDUCATION_DETAILS), joins.getPerson().get(Person.OCCUPATION_TYPE), joins.getPerson().get(Person.OCCUPATION_DETAILS), joins.getPerson().get(Person.ARMED_FORCES_RELATION_TYPE), joins.getEpiData().get(EpiData.CONTACT_WITH_SOURCE_CASE_KNOWN), caseRoot.get(Case.VACCINATION_STATUS), caseRoot.get(Case.POSTPARTUM), caseRoot.get(Case.TRIMESTER), eventCountSq, caseRoot.get(Case.EXTERNAL_ID), caseRoot.get(Case.EXTERNAL_TOKEN), caseRoot.get(Case.INTERNAL_TOKEN), joins.getPerson().get(Person.BIRTH_NAME), joins.getPersonBirthCountry().get(Country.ISO_CODE), joins.getPersonBirthCountry().get(Country.DEFAULT_NAME), joins.getPersonCitizenship().get(Country.ISO_CODE), joins.getPersonCitizenship().get(Country.DEFAULT_NAME), caseRoot.get(Case.CASE_IDENTIFICATION_SOURCE), caseRoot.get(Case.SCREENING_TYPE), // responsible jurisdiction
    joins.getResponsibleRegion().get(Region.NAME), joins.getResponsibleDistrict().get(District.NAME), joins.getResponsibleCommunity().get(Community.NAME), caseRoot.get(Case.CLINICIAN_NAME), caseRoot.get(Case.CLINICIAN_PHONE), caseRoot.get(Case.CLINICIAN_EMAIL), joins.getReportingUser().get(User.ID), joins.getFollowUpStatusChangeUser().get(User.ID), caseRoot.get(Case.PREVIOUS_QUARANTINE_TO), caseRoot.get(Case.QUARANTINE_CHANGE_COMMENT), JurisdictionHelper.booleanSelector(cb, service.inJurisdictionOrOwned(caseQueryContext)));
    // @formatter:on
    cq.distinct(true);
    Predicate filter = service.createUserFilter(cb, cq, caseRoot);
    if (caseCriteria != null) {
        Predicate criteriaFilter = service.createCriteriaFilter(caseCriteria, caseQueryContext);
        filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
    }
    filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, caseRoot.get(Case.UUID));
    if (filter != null) {
        cq.where(filter);
    }
    /*
		 * Sort by report date DESC, but also by id for stable Sorting in case of equal report dates.
		 * Since this method supports paging, values might jump between pages when sorting is unstable.
		 */
    cq.orderBy(cb.desc(caseRoot.get(Case.REPORT_DATE)), cb.desc(caseRoot.get(Case.ID)));
    List<CaseExportDto> resultList = QueryHelper.getResultList(em, cq, first, max);
    List<Long> resultCaseIds = resultList.stream().map(CaseExportDto::getId).collect(Collectors.toList());
    if (!resultList.isEmpty()) {
        Map<Long, Symptoms> symptoms = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, CaseDataDto.SYMPTOMS)) {
            List<Symptoms> symptomsList = null;
            CriteriaQuery<Symptoms> symptomsCq = cb.createQuery(Symptoms.class);
            Root<Symptoms> symptomsRoot = symptomsCq.from(Symptoms.class);
            Expression<String> symptomsIdsExpr = symptomsRoot.get(Symptoms.ID);
            symptomsCq.where(symptomsIdsExpr.in(resultList.stream().map(CaseExportDto::getSymptomsId).collect(Collectors.toList())));
            symptomsList = em.createQuery(symptomsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            symptoms = symptomsList.stream().collect(Collectors.toMap(Symptoms::getId, Function.identity()));
        }
        Map<Long, Location> personAddresses = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, PersonDto.ADDRESS, CaseExportDto.ADDRESS_GPS_COORDINATES)) {
            CriteriaQuery<Location> personAddressesCq = cb.createQuery(Location.class);
            Root<Location> personAddressesRoot = personAddressesCq.from(Location.class);
            Expression<String> personAddressesIdsExpr = personAddressesRoot.get(Location.ID);
            personAddressesCq.where(personAddressesIdsExpr.in(resultList.stream().map(CaseExportDto::getPersonAddressId).collect(Collectors.toList())));
            List<Location> personAddressesList = em.createQuery(personAddressesCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            personAddresses = personAddressesList.stream().collect(Collectors.toMap(Location::getId, Function.identity()));
        }
        Map<Long, Integer> prescriptionCounts = null;
        Map<Long, Integer> treatmentCounts = null;
        Map<Long, Integer> clinicalVisitCounts = null;
        Map<Long, HealthConditions> healthConditions = null;
        if (exportType == null || exportType == CaseExportType.CASE_MANAGEMENT) {
            if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.NUMBER_OF_PRESCRIPTIONS)) {
                prescriptionCounts = prescriptionService.getPrescriptionCountByCases(resultCaseIds).stream().collect(Collectors.toMap(e -> (Long) e[0], e -> ((Long) e[1]).intValue()));
            }
            if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.NUMBER_OF_TREATMENTS)) {
                treatmentCounts = treatmentService.getTreatmentCountByCases(resultCaseIds).stream().collect(Collectors.toMap(e -> (Long) e[0], e -> ((Long) e[1]).intValue()));
            }
            if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.NUMBER_OF_CLINICAL_VISITS)) {
                clinicalVisitCounts = clinicalVisitService.getClinicalVisitCountByCases(resultCaseIds).stream().collect(Collectors.toMap(e -> (Long) e[0], e -> ((Long) e[1]).intValue()));
            }
            if (ExportHelper.shouldExportFields(exportConfiguration, CaseDataDto.HEALTH_CONDITIONS)) {
                List<HealthConditions> healthConditionsList = null;
                CriteriaQuery<HealthConditions> healthConditionsCq = cb.createQuery(HealthConditions.class);
                Root<HealthConditions> healthConditionsRoot = healthConditionsCq.from(HealthConditions.class);
                Expression<String> healthConditionsIdsExpr = healthConditionsRoot.get(HealthConditions.ID);
                healthConditionsCq.where(healthConditionsIdsExpr.in(resultList.stream().map(CaseExportDto::getHealthConditionsId).collect(Collectors.toList())));
                healthConditionsList = em.createQuery(healthConditionsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
                healthConditions = healthConditionsList.stream().collect(Collectors.toMap(HealthConditions::getId, Function.identity()));
            }
        }
        Map<Long, PreviousHospitalization> firstPreviousHospitalizations = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.INITIAL_DETECTION_PLACE)) {
            List<PreviousHospitalization> prevHospsList = null;
            CriteriaQuery<PreviousHospitalization> prevHospsCq = cb.createQuery(PreviousHospitalization.class);
            Root<PreviousHospitalization> prevHospsRoot = prevHospsCq.from(PreviousHospitalization.class);
            Join<PreviousHospitalization, Hospitalization> prevHospsHospitalizationJoin = prevHospsRoot.join(PreviousHospitalization.HOSPITALIZATION, JoinType.LEFT);
            Expression<String> hospitalizationIdsExpr = prevHospsHospitalizationJoin.get(Hospitalization.ID);
            prevHospsCq.where(hospitalizationIdsExpr.in(resultList.stream().map(CaseExportDto::getHospitalizationId).collect(Collectors.toList())));
            prevHospsCq.orderBy(cb.asc(prevHospsRoot.get(PreviousHospitalization.ADMISSION_DATE)));
            prevHospsList = em.createQuery(prevHospsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            firstPreviousHospitalizations = prevHospsList.stream().collect(Collectors.toMap(p -> p.getHospitalization().getId(), Function.identity(), (id1, id2) -> id1));
        }
        Map<Long, CaseClassification> sourceCaseClassifications = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.MAX_SOURCE_CASE_CLASSIFICATION)) {
            sourceCaseClassifications = contactService.getSourceCaseClassifications(resultCaseIds).stream().collect(Collectors.toMap(e -> (Long) e[0], e -> (CaseClassification) e[1], (c1, c2) -> c1.getSeverity() >= c2.getSeverity() ? c1 : c2));
        }
        List<Long> caseIdsWithOutbreak = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.ASSOCIATED_WITH_OUTBREAK)) {
            caseIdsWithOutbreak = outbreakService.getCaseIdsWithOutbreak(resultCaseIds);
        }
        Map<Long, List<Exposure>> exposures = null;
        if ((exportType == null || exportType == CaseExportType.CASE_SURVEILLANCE) && ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.TRAVELED, CaseExportDto.TRAVEL_HISTORY, CaseExportDto.BURIAL_ATTENDED)) {
            CriteriaQuery<Exposure> exposuresCq = cb.createQuery(Exposure.class);
            Root<Exposure> exposuresRoot = exposuresCq.from(Exposure.class);
            Join<Exposure, EpiData> exposuresEpiDataJoin = exposuresRoot.join(Exposure.EPI_DATA, JoinType.LEFT);
            Expression<String> epiDataIdsExpr = exposuresEpiDataJoin.get(EpiData.ID);
            Predicate exposuresPredicate = cb.and(epiDataIdsExpr.in(resultList.stream().map(CaseExportDto::getEpiDataId).collect(Collectors.toList())), cb.or(cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.TRAVEL), cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.BURIAL)));
            exposuresCq.where(exposuresPredicate);
            exposuresCq.orderBy(cb.asc(exposuresEpiDataJoin.get(EpiData.ID)));
            List<Exposure> exposureList = em.createQuery(exposuresCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            exposures = exposureList.stream().collect(Collectors.groupingBy(e -> e.getEpiData().getId()));
        }
        Map<Long, List<Sample>> samples = null;
        if ((exportType == null || exportType == CaseExportType.CASE_SURVEILLANCE) && ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.SAMPLE_INFORMATION)) {
            List<Sample> samplesList = null;
            CriteriaQuery<Sample> samplesCq = cb.createQuery(Sample.class);
            Root<Sample> samplesRoot = samplesCq.from(Sample.class);
            Join<Sample, Case> samplesCaseJoin = samplesRoot.join(Sample.ASSOCIATED_CASE, JoinType.LEFT);
            Expression<String> caseIdsExpr = samplesCaseJoin.get(Case.ID);
            samplesCq.where(caseIdsExpr.in(resultCaseIds));
            samplesList = em.createQuery(samplesCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            samples = samplesList.stream().collect(Collectors.groupingBy(s -> s.getAssociatedCase().getId()));
        }
        List<VisitSummaryExportDetails> visitSummaries = null;
        if (featureConfigurationFacade.isFeatureEnabled(FeatureType.CASE_FOLLOWUP) && ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.NUMBER_OF_VISITS, CaseExportDto.LAST_COOPERATIVE_VISIT_DATE, CaseExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMATIC, CaseExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMS)) {
            CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class);
            Root<Case> visitsCqRoot = visitsCq.from(Case.class);
            Join<Case, Visit> visitsJoin = visitsCqRoot.join(Case.VISITS, JoinType.LEFT);
            Join<Visit, Symptoms> visitSymptomsJoin = visitsJoin.join(Visit.SYMPTOMS, JoinType.LEFT);
            visitsCq.where(CriteriaBuilderHelper.and(cb, visitsCqRoot.get(AbstractDomainObject.ID).in(resultCaseIds), cb.isNotEmpty(visitsCqRoot.get(Case.VISITS))));
            visitsCq.multiselect(visitsCqRoot.get(AbstractDomainObject.ID), visitsJoin.get(Visit.VISIT_DATE_TIME), visitsJoin.get(Visit.VISIT_STATUS), visitSymptomsJoin);
            visitSummaries = em.createQuery(visitsCq).getResultList();
        }
        Map<Long, List<Immunization>> immunizations = null;
        if ((exportType == null || exportType == CaseExportType.CASE_SURVEILLANCE) && (exportConfiguration == null || exportConfiguration.getProperties().stream().anyMatch(p -> StringUtils.equalsAny(p, ExportHelper.getVaccinationExportProperties())))) {
            List<Immunization> immunizationList;
            CriteriaQuery<Immunization> immunizationsCq = cb.createQuery(Immunization.class);
            Root<Immunization> immunizationsCqRoot = immunizationsCq.from(Immunization.class);
            Join<Immunization, Person> personJoin = immunizationsCqRoot.join(Immunization.PERSON, JoinType.LEFT);
            Expression<String> personIdsExpr = personJoin.get(Person.ID);
            immunizationsCq.where(CriteriaBuilderHelper.and(cb, cb.or(cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION), cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION_RECOVERY)), personIdsExpr.in(resultList.stream().map(CaseExportDto::getPersonId).collect(Collectors.toList()))));
            immunizationsCq.select(immunizationsCqRoot);
            immunizationList = em.createQuery(immunizationsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            immunizations = immunizationList.stream().collect(Collectors.groupingBy(i -> i.getPerson().getId()));
        }
        // Load latest events info
        // Adding a second query here is not perfect, but selecting the last event with a criteria query
        // doesn't seem to be possible and using a native query is not an option because of user filters
        List<EventSummaryDetails> eventSummaries = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, CaseExportDto.LATEST_EVENT_ID, CaseExportDto.LATEST_EVENT_STATUS, CaseExportDto.LATEST_EVENT_TITLE)) {
            eventSummaries = eventService.getEventSummaryDetailsByCases(resultCaseIds);
        }
        Map<Long, UserReference> caseUsers = getCaseUsersForExport(resultList, exportConfiguration);
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        for (CaseExportDto exportDto : resultList) {
            final boolean inJurisdiction = exportDto.getInJurisdiction();
            if (exportConfiguration == null || exportConfiguration.getProperties().contains(CaseExportDto.COUNTRY)) {
                exportDto.setCountry(configFacade.getEpidPrefix());
            }
            if (symptoms != null) {
                Optional.ofNullable(symptoms.get(exportDto.getSymptomsId())).ifPresent(symptom -> exportDto.setSymptoms(SymptomsFacadeEjb.toDto(symptom)));
            }
            if (personAddresses != null || exportConfiguration.getProperties().contains(CaseExportDto.ADDRESS_GPS_COORDINATES)) {
                Optional.ofNullable(personAddresses.get(exportDto.getPersonAddressId())).ifPresent(personAddress -> exportDto.setAddressGpsCoordinates(personAddress.buildGpsCoordinatesCaption()));
            }
            if (prescriptionCounts != null) {
                Optional.ofNullable(prescriptionCounts.get(exportDto.getId())).ifPresent(prescriptionCount -> exportDto.setNumberOfPrescriptions(prescriptionCount));
            }
            if (treatmentCounts != null) {
                Optional.ofNullable(treatmentCounts.get(exportDto.getId())).ifPresent(treatmentCount -> exportDto.setNumberOfTreatments(treatmentCount));
            }
            if (clinicalVisitCounts != null) {
                Optional.ofNullable(clinicalVisitCounts.get(exportDto.getId())).ifPresent(clinicalVisitCount -> exportDto.setNumberOfClinicalVisits(clinicalVisitCount));
            }
            if (healthConditions != null) {
                Optional.ofNullable(healthConditions.get(exportDto.getHealthConditionsId())).ifPresent(healthCondition -> exportDto.setHealthConditions(healthConditionsMapper.toDto(healthCondition)));
            }
            if (firstPreviousHospitalizations != null) {
                Optional.ofNullable(firstPreviousHospitalizations.get(exportDto.getHospitalizationId())).ifPresent(firstPreviousHospitalization -> {
                    if (firstPreviousHospitalization.getHealthFacility() != null) {
                        exportDto.setInitialDetectionPlace(FacilityHelper.buildFacilityString(firstPreviousHospitalization.getHealthFacility().getUuid(), firstPreviousHospitalization.getHealthFacility().getName(), firstPreviousHospitalization.getHealthFacilityDetails()));
                    } else {
                        exportDto.setInitialDetectionPlace(I18nProperties.getCaption(Captions.unknown));
                    }
                });
                if (StringUtils.isEmpty(exportDto.getInitialDetectionPlace())) {
                    if (!StringUtils.isEmpty(exportDto.getHealthFacility())) {
                        exportDto.setInitialDetectionPlace(exportDto.getHealthFacility());
                    } else {
                        exportDto.setInitialDetectionPlace(exportDto.getPointOfEntry());
                    }
                }
            }
            if (sourceCaseClassifications != null) {
                Optional.ofNullable(sourceCaseClassifications.get(exportDto.getId())).ifPresent(sourceCaseClassification -> exportDto.setMaxSourceCaseClassification(sourceCaseClassification));
            }
            if (caseIdsWithOutbreak != null) {
                exportDto.setAssociatedWithOutbreak(caseIdsWithOutbreak.contains(exportDto.getId()));
            }
            if (exposures != null) {
                Optional.ofNullable(exposures.get(exportDto.getEpiDataId())).ifPresent(caseExposures -> {
                    StringBuilder travelHistoryBuilder = new StringBuilder();
                    if (caseExposures.stream().anyMatch(e -> ExposureType.BURIAL.equals(e.getExposureType()))) {
                        exportDto.setBurialAttended(true);
                    }
                    caseExposures.stream().filter(e -> ExposureType.TRAVEL.equals(e.getExposureType())).forEach(exposure -> travelHistoryBuilder.append(EpiDataHelper.buildDetailedTravelString(exposure.getLocation().toString(), exposure.getDescription(), exposure.getStartDate(), exposure.getEndDate(), userLanguage)).append(", "));
                    if (travelHistoryBuilder.length() > 0) {
                        exportDto.setTraveled(true);
                        travelHistoryBuilder.delete(travelHistoryBuilder.lastIndexOf(", "), travelHistoryBuilder.length() - 1);
                    }
                    exportDto.setTravelHistory(travelHistoryBuilder.toString());
                });
            }
            if (samples != null) {
                Optional.ofNullable(samples.get(exportDto.getId())).ifPresent(caseSamples -> {
                    int count = 0;
                    caseSamples.sort((o1, o2) -> o2.getSampleDateTime().compareTo(o1.getSampleDateTime()));
                    for (Sample sample : caseSamples) {
                        EmbeddedSampleExportDto sampleDto = new EmbeddedSampleExportDto(sample.getUuid(), sample.getSampleDateTime(), sample.getLab() != null ? FacilityHelper.buildFacilityString(sample.getLab().getUuid(), sample.getLab().getName(), sample.getLabDetails()) : null, sample.getPathogenTestResult());
                        switch(++count) {
                            case 1:
                                exportDto.setSample1(sampleDto);
                                break;
                            case 2:
                                exportDto.setSample2(sampleDto);
                                break;
                            case 3:
                                exportDto.setSample3(sampleDto);
                                break;
                            default:
                                exportDto.addOtherSample(sampleDto);
                        }
                    }
                });
            }
            if (immunizations != null) {
                Optional.ofNullable(immunizations.get(exportDto.getPersonId())).ifPresent(caseImmunizations -> {
                    List<Immunization> filteredImmunizations = caseImmunizations.stream().filter(i -> i.getDisease() == exportDto.getDisease()).collect(Collectors.toList());
                    if (!filteredImmunizations.isEmpty()) {
                        filteredImmunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, false)));
                        Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
                        Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();
                        exportDto.setNumberOfDoses(numberOfDoses != null ? String.valueOf(numberOfDoses) : "");
                        if (CollectionUtils.isNotEmpty(mostRecentImmunization.getVaccinations())) {
                            List<Vaccination> sortedVaccinations = mostRecentImmunization.getVaccinations().stream().sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison)).collect(Collectors.toList());
                            Vaccination firstVaccination = sortedVaccinations.get(0);
                            Vaccination lastVaccination = sortedVaccinations.get(sortedVaccinations.size() - 1);
                            exportDto.setFirstVaccinationDate(firstVaccination.getVaccinationDate());
                            exportDto.setLastVaccinationDate(lastVaccination.getVaccinationDate());
                            exportDto.setVaccineName(lastVaccination.getVaccineName());
                            exportDto.setOtherVaccineName(lastVaccination.getOtherVaccineName());
                            exportDto.setVaccineManufacturer(lastVaccination.getVaccineManufacturer());
                            exportDto.setOtherVaccineManufacturer(lastVaccination.getOtherVaccineManufacturer());
                            exportDto.setVaccinationInfoSource(lastVaccination.getVaccinationInfoSource());
                            exportDto.setVaccineAtcCode(lastVaccination.getVaccineAtcCode());
                            exportDto.setVaccineBatchNumber(lastVaccination.getVaccineBatchNumber());
                            exportDto.setVaccineUniiCode(lastVaccination.getVaccineUniiCode());
                            exportDto.setVaccineInn(lastVaccination.getVaccineInn());
                        }
                    }
                });
            }
            if (visitSummaries != null) {
                List<VisitSummaryExportDetails> visits = visitSummaries.stream().filter(v -> v.getContactId() == exportDto.getId()).collect(Collectors.toList());
                VisitSummaryExportDetails lastCooperativeVisit = visits.stream().filter(v -> v.getVisitStatus() == VisitStatus.COOPERATIVE).max(Comparator.comparing(VisitSummaryExportDetails::getVisitDateTime)).orElse(null);
                exportDto.setNumberOfVisits(visits.size());
                if (lastCooperativeVisit != null) {
                    exportDto.setLastCooperativeVisitDate(lastCooperativeVisit.getVisitDateTime());
                    SymptomsDto visitSymptoms = SymptomsFacadeEjb.toDto(lastCooperativeVisit.getSymptoms());
                    pseudonymizer.pseudonymizeDto(SymptomsDto.class, visitSymptoms, inJurisdiction, null);
                    exportDto.setLastCooperativeVisitSymptoms(SymptomsHelper.buildSymptomsHumanString(visitSymptoms, true, userLanguage));
                    exportDto.setLastCooperativeVisitSymptomatic(visitSymptoms.getSymptomatic() == null ? YesNoUnknown.UNKNOWN : (visitSymptoms.getSymptomatic() ? YesNoUnknown.YES : YesNoUnknown.NO));
                }
            }
            if (eventSummaries != null && exportDto.getEventCount() != 0) {
                eventSummaries.stream().filter(v -> v.getCaseId() == exportDto.getId()).max(Comparator.comparing(EventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
                    exportDto.setLatestEventId(eventSummary.getEventUuid());
                    exportDto.setLatestEventStatus(eventSummary.getEventStatus());
                    exportDto.setLatestEventTitle(eventSummary.getEventTitle());
                });
            }
            if (!caseUsers.isEmpty()) {
                if (exportDto.getReportingUserId() != null) {
                    UserReference user = caseUsers.get(exportDto.getReportingUserId());
                    exportDto.setReportingUserName(user.getName());
                    exportDto.setReportingUserRoles(user.getUserRoles());
                }
                if (exportDto.getFollowUpStatusChangeUserId() != null) {
                    UserReference user = caseUsers.get(exportDto.getFollowUpStatusChangeUserId());
                    exportDto.setFollowUpStatusChangeUserName(user.getName());
                    exportDto.setFollowUpStatusChangeUserRoles(user.getUserRoles());
                }
            }
            pseudonymizer.pseudonymizeDto(CaseExportDto.class, exportDto, inJurisdiction, c -> {
                pseudonymizer.pseudonymizeDto(BirthDateDto.class, c.getBirthdate(), inJurisdiction, null);
                pseudonymizer.pseudonymizeDto(EmbeddedSampleExportDto.class, c.getSample1(), inJurisdiction, null);
                pseudonymizer.pseudonymizeDto(EmbeddedSampleExportDto.class, c.getSample2(), inJurisdiction, null);
                pseudonymizer.pseudonymizeDto(EmbeddedSampleExportDto.class, c.getSample3(), inJurisdiction, null);
                pseudonymizer.pseudonymizeDtoCollection(EmbeddedSampleExportDto.class, c.getOtherSamples(), s -> inJurisdiction, null);
                pseudonymizer.pseudonymizeDto(BurialInfoDto.class, c.getBurialInfo(), inJurisdiction, null);
                pseudonymizer.pseudonymizeDto(SymptomsDto.class, c.getSymptoms(), inJurisdiction, null);
            });
        }
    }
    caseCriteria.setMustHaveCaseManagementData(previousCaseManagementDataCriteria);
    return resultList;
}
Also used : VisitService(de.symeda.sormas.backend.visit.VisitService) PlagueType(de.symeda.sormas.api.caze.PlagueType) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) TaskHelper(de.symeda.sormas.api.task.TaskHelper) AbstractCoreFacadeEjb(de.symeda.sormas.backend.common.AbstractCoreFacadeEjb) TransactionAttributeType(javax.ejb.TransactionAttributeType) CaseExportDto(de.symeda.sormas.api.caze.CaseExportDto) Duration(java.time.Duration) Map(java.util.Map) TreatmentFacadeEjb(de.symeda.sormas.backend.therapy.TreatmentFacadeEjb) DocumentRelatedEntityType(de.symeda.sormas.api.document.DocumentRelatedEntityType) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) OutbreakService(de.symeda.sormas.backend.outbreak.OutbreakService) DiseaseHelper(de.symeda.sormas.api.DiseaseHelper) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) FacilityHelper(de.symeda.sormas.api.infrastructure.facility.FacilityHelper) Resource(javax.annotation.Resource) TaskPriority(de.symeda.sormas.api.task.TaskPriority) NotNull(javax.validation.constraints.NotNull) CaseIndexDetailedDto(de.symeda.sormas.api.caze.CaseIndexDetailedDto) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) SampleService(de.symeda.sormas.backend.sample.SampleService) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) Sample(de.symeda.sormas.backend.sample.Sample) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) ManualMessageLogDto(de.symeda.sormas.api.messaging.ManualMessageLogDto) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) TypedQuery(javax.persistence.TypedQuery) VisitFacadeEjbLocal(de.symeda.sormas.backend.visit.VisitFacadeEjb.VisitFacadeEjbLocal) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) CaseListEntryDto(de.symeda.sormas.api.caze.CaseListEntryDto) Calendar(java.util.Calendar) PreviousHospitalizationDto(de.symeda.sormas.api.hospitalization.PreviousHospitalizationDto) SampleFacadeEjb(de.symeda.sormas.backend.sample.SampleFacadeEjb) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) ExportHelper(de.symeda.sormas.backend.importexport.ExportHelper) EJB(javax.ejb.EJB) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) ManualMessageLogService(de.symeda.sormas.backend.common.messaging.ManualMessageLogService) HospitalizationFacadeEjbLocal(de.symeda.sormas.backend.hospitalization.HospitalizationFacadeEjb.HospitalizationFacadeEjbLocal) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) AgeAndBirthDateDto(de.symeda.sormas.api.caze.AgeAndBirthDateDto) PersonService(de.symeda.sormas.backend.person.PersonService) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) PrescriptionFacadeEjb(de.symeda.sormas.backend.therapy.PrescriptionFacadeEjb) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) VisitDto(de.symeda.sormas.api.visit.VisitDto) HealthConditions(de.symeda.sormas.backend.clinicalcourse.HealthConditions) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) PortHealthInfoFacadeEjbLocal(de.symeda.sormas.backend.caze.porthealthinfo.PortHealthInfoFacadeEjb.PortHealthInfoFacadeEjbLocal) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) SurveillanceReportService(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReportService) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Join(javax.persistence.criteria.Join) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) PopulationDataFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.PopulationDataFacadeEjb.PopulationDataFacadeEjbLocal) Random(java.util.Random) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) PortHealthInfoDto(de.symeda.sormas.api.caze.porthealthinfo.PortHealthInfoDto) PrescriptionService(de.symeda.sormas.backend.therapy.PrescriptionService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) CriteriaBuilderHelper.or(de.symeda.sormas.backend.common.CriteriaBuilderHelper.or) CaseClassificationFacadeEjbLocal(de.symeda.sormas.backend.caze.classification.CaseClassificationFacadeEjb.CaseClassificationFacadeEjbLocal) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) VisitSummaryExportDetails(de.symeda.sormas.backend.contact.VisitSummaryExportDetails) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) InfrastructureHelper(de.symeda.sormas.api.infrastructure.InfrastructureHelper) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) Person(de.symeda.sormas.backend.person.Person) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) PrescriptionFacadeEjbLocal(de.symeda.sormas.backend.therapy.PrescriptionFacadeEjb.PrescriptionFacadeEjbLocal) Instant(java.time.Instant) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Language(de.symeda.sormas.api.Language) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) PatchHelper(de.symeda.sormas.backend.util.PatchHelper) Objects(java.util.Objects) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) SurveillanceReportFacadeEjb(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReportFacadeEjb) ExportConfigurationDto(de.symeda.sormas.api.importexport.ExportConfigurationDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) PreviousHospitalization(de.symeda.sormas.backend.hospitalization.PreviousHospitalization) ContactDto(de.symeda.sormas.api.contact.ContactDto) LocalDate(java.time.LocalDate) Order(javax.persistence.criteria.Order) ClinicalCourseDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseDto) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) CoreEntityType(de.symeda.sormas.backend.deletionconfiguration.CoreEntityType) Function(java.util.function.Function) VisitOrigin(de.symeda.sormas.api.VisitOrigin) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) AdditionalTestFacadeEjbLocal(de.symeda.sormas.backend.sample.AdditionalTestFacadeEjb.AdditionalTestFacadeEjbLocal) Inject(javax.inject.Inject) ReinfectionDetail(de.symeda.sormas.api.caze.ReinfectionDetail) PreviousCaseDto(de.symeda.sormas.api.caze.PreviousCaseDto) TransactionAttribute(javax.ejb.TransactionAttribute) TaskStatus(de.symeda.sormas.api.task.TaskStatus) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) CriteriaBuilderHelper.and(de.symeda.sormas.backend.common.CriteriaBuilderHelper.and) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) LocationDto(de.symeda.sormas.api.location.LocationDto) TaskContext(de.symeda.sormas.api.task.TaskContext) Logger(org.slf4j.Logger) HospitalizationFacadeEjb(de.symeda.sormas.backend.hospitalization.HospitalizationFacadeEjb) Document(de.symeda.sormas.backend.document.Document) TherapyFacadeEjbLocal(de.symeda.sormas.backend.therapy.TherapyFacadeEjb.TherapyFacadeEjbLocal) VisitLogic.getVisitResult(de.symeda.sormas.backend.visit.VisitLogic.getVisitResult) DateTime(org.joda.time.DateTime) UserReference(de.symeda.sormas.backend.user.UserReference) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) PresentCondition(de.symeda.sormas.api.person.PresentCondition) UserRight(de.symeda.sormas.api.user.UserRight) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Comparator(java.util.Comparator) Arrays(java.util.Arrays) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) EmbeddedSampleExportDto(de.symeda.sormas.api.caze.EmbeddedSampleExportDto) SymptomsFacadeEjbLocal(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb.SymptomsFacadeEjbLocal) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) Valid(javax.validation.Valid) BigDecimal(java.math.BigDecimal) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Page(de.symeda.sormas.api.common.Page) FollowUpDto(de.symeda.sormas.api.followup.FollowUpDto) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) JsonNode(com.fasterxml.jackson.databind.JsonNode) Visit(de.symeda.sormas.backend.visit.Visit) EpiData(de.symeda.sormas.backend.epidata.EpiData) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) TherapyDto(de.symeda.sormas.api.therapy.TherapyDto) Set(java.util.Set) SampleFacadeEjbLocal(de.symeda.sormas.backend.sample.SampleFacadeEjb.SampleFacadeEjbLocal) DistrictFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb.DistrictFacadeEjbLocal) PointOfEntryService(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryService) UserService(de.symeda.sormas.backend.user.UserService) MaternalHistoryDto(de.symeda.sormas.api.caze.maternalhistory.MaternalHistoryDto) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) HealthConditionsDto(de.symeda.sormas.api.clinicalcourse.HealthConditionsDto) FollowUpPeriodDto(de.symeda.sormas.api.followup.FollowUpPeriodDto) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseMeasure(de.symeda.sormas.api.CaseMeasure) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) PathogenTest(de.symeda.sormas.backend.sample.PathogenTest) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) ClinicalVisitFacadeEjb(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitFacadeEjb) EpiDataFacadeEjb(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) LocalBean(javax.ejb.LocalBean) CountryHelper(de.symeda.sormas.api.CountryHelper) Root(javax.persistence.criteria.Root) PersonFacadeEjbLocal(de.symeda.sormas.backend.person.PersonFacadeEjb.PersonFacadeEjbLocal) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) MessageType(de.symeda.sormas.api.messaging.MessageType) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) MaternalHistoryFacadeEjbLocal(de.symeda.sormas.backend.caze.maternalhistory.MaternalHistoryFacadeEjb.MaternalHistoryFacadeEjbLocal) CaseFacade(de.symeda.sormas.api.caze.CaseFacade) Captions(de.symeda.sormas.api.i18n.Captions) Exposure(de.symeda.sormas.backend.exposure.Exposure) Treatment(de.symeda.sormas.backend.therapy.Treatment) CaseBulkEditData(de.symeda.sormas.api.caze.CaseBulkEditData) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) ContactService(de.symeda.sormas.backend.contact.ContactService) SampleDto(de.symeda.sormas.api.sample.SampleDto) Subquery(javax.persistence.criteria.Subquery) SymptomsFacadeEjb(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) SurveillanceReport(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) FeatureType(de.symeda.sormas.api.feature.FeatureType) TherapyFacadeEjb(de.symeda.sormas.backend.therapy.TherapyFacadeEjb) EventService(de.symeda.sormas.backend.event.EventService) PointOfEntryFacadeEjb(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryFacadeEjb) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) ClinicalVisitService(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitService) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) InfoProvider(de.symeda.sormas.api.utils.InfoProvider) LoggerFactory(org.slf4j.LoggerFactory) ExposureType(de.symeda.sormas.api.exposure.ExposureType) HealthConditionsMapper(de.symeda.sormas.backend.clinicalcourse.HealthConditionsMapper) CauseOfDeath(de.symeda.sormas.api.person.CauseOfDeath) CommunityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb.CommunityFacadeEjbLocal) ExposureService(de.symeda.sormas.backend.exposure.ExposureService) ExternalShareInfoCountAndLatestDate(de.symeda.sormas.backend.share.ExternalShareInfoCountAndLatestDate) SormasToSormasCaseFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.caze.SormasToSormasCaseFacadeEjb.SormasToSormasCaseFacadeEjbLocal) NotificationService(de.symeda.sormas.backend.common.NotificationService) TreatmentFacadeEjbLocal(de.symeda.sormas.backend.therapy.TreatmentFacadeEjb.TreatmentFacadeEjbLocal) UserRole(de.symeda.sormas.api.user.UserRole) Path(javax.persistence.criteria.Path) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) PortHealthInfoFacadeEjb(de.symeda.sormas.backend.caze.porthealthinfo.PortHealthInfoFacadeEjb) DocumentService(de.symeda.sormas.backend.document.DocumentService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) AdditionalTest(de.symeda.sormas.backend.sample.AdditionalTest) SormasToSormasFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.SormasToSormasFacadeEjb.SormasToSormasFacadeEjbLocal) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) TaskType(de.symeda.sormas.api.task.TaskType) EventSummaryDetails(de.symeda.sormas.backend.event.EventSummaryDetails) List(java.util.List) MaternalHistoryFacadeEjb(de.symeda.sormas.backend.caze.maternalhistory.MaternalHistoryFacadeEjb) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) Optional(java.util.Optional) EpiDataHelper(de.symeda.sormas.api.epidata.EpiDataHelper) Location(de.symeda.sormas.backend.location.Location) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) ClinicalCourseFacadeEjb(de.symeda.sormas.backend.clinicalcourse.ClinicalCourseFacadeEjb) VaccinationFacadeEjb(de.symeda.sormas.backend.vaccination.VaccinationFacadeEjb) TaskService(de.symeda.sormas.backend.task.TaskService) HashMap(java.util.HashMap) PathogenTestFacadeEjbLocal(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb.PathogenTestFacadeEjbLocal) SurveillanceReportDto(de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto) CaseExportType(de.symeda.sormas.api.caze.CaseExportType) CollectionUtils(org.apache.commons.collections.CollectionUtils) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) FacilityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb.FacilityFacadeEjbLocal) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) TreatmentService(de.symeda.sormas.backend.therapy.TreatmentService) Expression(javax.persistence.criteria.Expression) BurialInfoDto(de.symeda.sormas.api.caze.BurialInfoDto) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) EpiDataService(de.symeda.sormas.backend.epidata.EpiDataService) CaseJoins(de.symeda.sormas.utils.CaseJoins) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) EpiDataFacadeEjbLocal(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb.EpiDataFacadeEjbLocal) Validations(de.symeda.sormas.api.i18n.Validations) ClinicalVisitFacadeEjbLocal(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitFacadeEjb.ClinicalVisitFacadeEjbLocal) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) Pair(de.symeda.sormas.api.utils.DataHelper.Pair) PathogenTestService(de.symeda.sormas.backend.sample.PathogenTestService) MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) TimeUnit(java.util.concurrent.TimeUnit) Event(de.symeda.sormas.backend.event.Event) NotificationType(de.symeda.sormas.api.user.NotificationType) MessagingService(de.symeda.sormas.backend.common.messaging.MessagingService) Country(de.symeda.sormas.backend.infrastructure.country.Country) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ClinicalCourseFacadeEjbLocal(de.symeda.sormas.backend.clinicalcourse.ClinicalCourseFacadeEjb.ClinicalCourseFacadeEjbLocal) Strings(de.symeda.sormas.api.i18n.Strings) ExternalSurveillanceToolGatewayFacadeEjbLocal(de.symeda.sormas.backend.externalsurveillancetool.ExternalSurveillanceToolGatewayFacadeEjb.ExternalSurveillanceToolGatewayFacadeEjbLocal) Collections(java.util.Collections) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) TreatmentDto(de.symeda.sormas.api.therapy.TreatmentDto) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Predicate(javax.persistence.criteria.Predicate) ArrayList(java.util.ArrayList) List(java.util.List) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Exposure(de.symeda.sormas.backend.exposure.Exposure) UserReference(de.symeda.sormas.backend.user.UserReference) EventSummaryDetails(de.symeda.sormas.backend.event.EventSummaryDetails) AtomicLong(java.util.concurrent.atomic.AtomicLong) PreviousHospitalization(de.symeda.sormas.backend.hospitalization.PreviousHospitalization) Person(de.symeda.sormas.backend.person.Person) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) Visit(de.symeda.sormas.backend.visit.Visit) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) VisitSummaryExportDetails(de.symeda.sormas.backend.contact.VisitSummaryExportDetails) EpiData(de.symeda.sormas.backend.epidata.EpiData) CaseJoins(de.symeda.sormas.utils.CaseJoins) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) Sample(de.symeda.sormas.backend.sample.Sample) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) PreviousHospitalization(de.symeda.sormas.backend.hospitalization.PreviousHospitalization) HealthConditions(de.symeda.sormas.backend.clinicalcourse.HealthConditions) CaseExportDto(de.symeda.sormas.api.caze.CaseExportDto) EmbeddedSampleExportDto(de.symeda.sormas.api.caze.EmbeddedSampleExportDto) Event(de.symeda.sormas.backend.event.Event) Location(de.symeda.sormas.backend.location.Location) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with EpiData

use of de.symeda.sormas.backend.epidata.EpiData in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method mergeCase.

private void mergeCase(CaseDataDto leadCaseData, CaseDataDto otherCaseData, boolean cloning) {
    // 1 Merge Dtos
    // 1.1 Case
    copyDtoValues(leadCaseData, otherCaseData, cloning);
    save(leadCaseData, !cloning, true, true, false);
    // 1.2 Person - Only merge when the persons have different UUIDs
    if (!cloning && !DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid())) {
        PersonDto leadPerson = personFacade.getPersonByUuid(leadCaseData.getPerson().getUuid());
        PersonDto otherPerson = personFacade.getPersonByUuid(otherCaseData.getPerson().getUuid());
        personFacade.mergePerson(leadPerson, otherPerson);
    } else {
        assert (DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid()));
    }
    // 2 Change CaseReference
    Case leadCase = service.getByUuid(leadCaseData.getUuid());
    Case otherCase = service.getByUuid(otherCaseData.getUuid());
    // 2.1 Contacts
    List<Contact> contacts = contactService.findBy(new ContactCriteria().caze(otherCase.toReference()), null);
    for (Contact contact : contacts) {
        if (cloning) {
            ContactDto newContact = ContactDto.build(leadCase.toReference(), leadCase.getDisease(), leadCase.getDiseaseDetails(), leadCase.getDiseaseVariant());
            newContact.setPerson(new PersonReferenceDto(contact.getPerson().getUuid()));
            DtoHelper.copyDtoValues(newContact, contactFacade.toDto(contact), cloning);
            contactFacade.save(newContact, false, false);
        } else {
            // simply move existing entities to the merge target
            contact.setCaze(leadCase);
            contactService.ensurePersisted(contact);
        }
    }
    // 2.2 Samples
    List<Sample> samples = sampleService.findBy(new SampleCriteria().caze(otherCase.toReference()), null);
    for (Sample sample : samples) {
        if (cloning) {
            SampleDto newSample = SampleDto.build(sample.getReportingUser().toReference(), leadCase.toReference());
            DtoHelper.copyDtoValues(newSample, SampleFacadeEjb.toDto(sample), cloning);
            sampleFacade.saveSample(newSample, false, true, true);
            // 2.2.1 Pathogen Tests
            for (PathogenTest pathogenTest : sample.getPathogenTests()) {
                PathogenTestDto newPathogenTest = PathogenTestDto.build(newSample.toReference(), pathogenTest.getLabUser().toReference());
                DtoHelper.copyDtoValues(newPathogenTest, PathogenTestFacadeEjbLocal.toDto(pathogenTest), cloning);
                sampleTestFacade.savePathogenTest(newPathogenTest);
            }
            for (AdditionalTest additionalTest : sample.getAdditionalTests()) {
                AdditionalTestDto newAdditionalTest = AdditionalTestDto.build(newSample.toReference());
                DtoHelper.copyDtoValues(newAdditionalTest, AdditionalTestFacadeEjbLocal.toDto(additionalTest), cloning);
                additionalTestFacade.saveAdditionalTest(newAdditionalTest);
            }
        } else {
            // simply move existing entities to the merge target
            sample.setAssociatedCase(leadCase);
            sampleService.ensurePersisted(sample);
        }
    }
    // 2.3 Tasks
    if (!cloning) {
        // simply move existing entities to the merge target
        List<Task> tasks = taskService.findBy(new TaskCriteria().caze(new CaseReferenceDto(otherCase.getUuid())), true);
        for (Task task : tasks) {
            task.setCaze(leadCase);
            taskService.ensurePersisted(task);
        }
    }
    // 3 Change Therapy Reference
    // 3.1 Treatments
    List<Treatment> treatments = treatmentService.findBy(new TreatmentCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
    TherapyReferenceDto leadCaseTherapyReference = new TherapyReferenceDto(leadCase.getTherapy().getUuid());
    for (Treatment treatment : treatments) {
        if (cloning) {
            TreatmentDto newTreatment = TreatmentDto.build(leadCaseTherapyReference);
            DtoHelper.copyDtoValues(newTreatment, TreatmentFacadeEjb.toDto(treatment), cloning);
            treatmentFacade.saveTreatment(newTreatment);
        } else {
            // simply move existing entities to the merge target
            treatment.setTherapy(leadCase.getTherapy());
            treatmentService.ensurePersisted(treatment);
        }
    }
    // 3.2 Prescriptions
    List<Prescription> prescriptions = prescriptionService.findBy(new PrescriptionCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
    for (Prescription prescription : prescriptions) {
        if (cloning) {
            PrescriptionDto newPrescription = PrescriptionDto.buildPrescription(leadCaseTherapyReference);
            DtoHelper.copyDtoValues(newPrescription, PrescriptionFacadeEjb.toDto(prescription), cloning);
            prescriptionFacade.savePrescription(newPrescription);
        } else {
            // simply move existing entities to the merge target
            prescription.setTherapy(leadCase.getTherapy());
            prescriptionService.ensurePersisted(prescription);
        }
    }
    // 4 Change Clinical Course Reference
    // 4.1 Clinical Visits
    List<ClinicalVisit> clinicalVisits = clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(new ClinicalCourseReferenceDto(otherCase.getClinicalCourse().getUuid())));
    for (ClinicalVisit clinicalVisit : clinicalVisits) {
        if (cloning) {
            ClinicalVisitDto newClinicalVisit = ClinicalVisitDto.build(leadCaseData.getClinicalCourse().toReference(), leadCase.getDisease());
            DtoHelper.copyDtoValues(newClinicalVisit, ClinicalVisitFacadeEjb.toDto(clinicalVisit), cloning);
            clinicalVisitFacade.saveClinicalVisit(newClinicalVisit, leadCase.getUuid(), false);
        } else {
            // simply move existing entities to the merge target
            clinicalVisit.setClinicalCourse(leadCase.getClinicalCourse());
            clinicalVisitService.ensurePersisted(clinicalVisit);
        }
    }
    // (set the person and the disease of the visit, saveVisit does the rest)
    for (VisitDto otherVisit : otherCase.getVisits().stream().map(VisitFacadeEjb::toDto).collect(Collectors.toList())) {
        otherVisit.setPerson(leadCaseData.getPerson());
        otherVisit.setDisease(leadCaseData.getDisease());
        visitFacade.saveVisit(otherVisit);
    }
    // 6 Documents
    List<Document> documents = documentService.getRelatedToEntity(DocumentRelatedEntityType.CASE, otherCase.getUuid());
    for (Document document : documents) {
        document.setRelatedEntityUuid(leadCaseData.getUuid());
        documentService.ensurePersisted(document);
    }
    // 7 Persist Event links through eventparticipants
    Set<EventParticipant> eventParticipants = otherCase.getEventParticipants();
    for (EventParticipant eventParticipant : eventParticipants) {
        eventParticipant.setResultingCase(leadCase);
        eventParticipantService.ensurePersisted(eventParticipant);
    }
    otherCase.getEventParticipants().clear();
    // 8 Exposures - Make sure there are no two probable infection environments
    // if there are more than 2 exposures marked as probable infection environment, find the one that originates from the otherCase and set it to false
    // the one originating from the otherCase should always be found at the higher index
    List<Exposure> probableExposuresList = leadCase.getEpiData().getExposures().stream().filter(Exposure::isProbableInfectionEnvironment).collect(Collectors.toList());
    while (probableExposuresList.size() >= 2) {
        // should never be > 2, but still make sure to set all but one exposures to false
        probableExposuresList.get(probableExposuresList.size() - 1).setProbableInfectionEnvironment(false);
        exposureService.ensurePersisted(probableExposuresList.get(probableExposuresList.size() - 1));
        probableExposuresList.remove(probableExposuresList.size() - 1);
    }
    // 9 Reports
    List<SurveillanceReport> surveillanceReports = surveillanceReportService.getByCaseUuids(Collections.singletonList(otherCase.getUuid()));
    surveillanceReports.forEach(surveillanceReport -> {
        SurveillanceReportDto surveillanceReportDto = SurveillanceReportFacadeEjb.toDto(surveillanceReport);
        surveillanceReportDto.setCaze(leadCase.toReference());
        surveillanceReportFacade.saveSurveillanceReport(surveillanceReportDto);
    });
    // 10 Activity as case
    final EpiData otherEpiData = otherCase.getEpiData();
    if (otherEpiData != null && YesNoUnknown.YES == otherEpiData.getActivityAsCaseDetailsKnown() && CollectionUtils.isNotEmpty(otherEpiData.getActivitiesAsCase())) {
        final EpiData leadEpiData = leadCase.getEpiData();
        leadEpiData.setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
        epiDataService.ensurePersisted(leadEpiData);
    }
    // Travel entries reference
    List<TravelEntry> travelEntries = travelEntryService.getAllByResultingCase(otherCase);
    travelEntries.forEach(t -> {
        t.setResultingCase(leadCase);
        travelEntryService.ensurePersisted(t);
    });
}
Also used : AdditionalTest(de.symeda.sormas.backend.sample.AdditionalTest) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) Task(de.symeda.sormas.backend.task.Task) SurveillanceReport(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) Document(de.symeda.sormas.backend.document.Document) TreatmentDto(de.symeda.sormas.api.therapy.TreatmentDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) EpiData(de.symeda.sormas.backend.epidata.EpiData) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) PersonDto(de.symeda.sormas.api.person.PersonDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) Sample(de.symeda.sormas.backend.sample.Sample) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) Exposure(de.symeda.sormas.backend.exposure.Exposure) PathogenTest(de.symeda.sormas.backend.sample.PathogenTest) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) Contact(de.symeda.sormas.backend.contact.Contact) Treatment(de.symeda.sormas.backend.therapy.Treatment) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) SurveillanceReportDto(de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto)

Example 3 with EpiData

use of de.symeda.sormas.backend.epidata.EpiData in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method restorePseudonymizedDto.

public void restorePseudonymizedDto(CaseDataDto dto, CaseDataDto existingCaseDto, Case caze, Pseudonymizer pseudonymizer) {
    if (existingCaseDto != null) {
        boolean inJurisdiction = service.inJurisdictionOrOwned(caze);
        User currentUser = userService.getCurrentUser();
        pseudonymizer.restoreUser(caze.getReportingUser(), currentUser, dto, dto::setReportingUser);
        pseudonymizer.restoreUser(caze.getClassificationUser(), currentUser, dto, dto::setClassificationUser);
        pseudonymizer.restorePseudonymizedValues(CaseDataDto.class, dto, existingCaseDto, inJurisdiction);
        EpiDataDto epiData = dto.getEpiData();
        EpiDataDto existingEpiData = existingCaseDto.getEpiData();
        pseudonymizer.restorePseudonymizedValues(EpiDataDto.class, epiData, existingEpiData, inJurisdiction);
        epiData.getExposures().forEach(exposure -> {
            ExposureDto existingExposure = existingEpiData.getExposures().stream().filter(exp -> DataHelper.isSame(exposure, exp)).findFirst().orElse(null);
            if (existingExposure != null) {
                pseudonymizer.restorePseudonymizedValues(ExposureDto.class, exposure, existingExposure, inJurisdiction);
                pseudonymizer.restorePseudonymizedValues(LocationDto.class, exposure.getLocation(), existingExposure.getLocation(), inJurisdiction);
            }
        });
        pseudonymizer.restorePseudonymizedValues(HealthConditionsDto.class, dto.getHealthConditions(), existingCaseDto.getHealthConditions(), inJurisdiction);
        dto.getHospitalization().getPreviousHospitalizations().forEach(previousHospitalization -> existingCaseDto.getHospitalization().getPreviousHospitalizations().stream().filter(eh -> DataHelper.isSame(previousHospitalization, eh)).findFirst().ifPresent(existingPreviousHospitalization -> pseudonymizer.restorePseudonymizedValues(PreviousHospitalizationDto.class, previousHospitalization, existingPreviousHospitalization, inJurisdiction)));
        pseudonymizer.restorePseudonymizedValues(SymptomsDto.class, dto.getSymptoms(), existingCaseDto.getSymptoms(), inJurisdiction);
        pseudonymizer.restorePseudonymizedValues(MaternalHistoryDto.class, dto.getMaternalHistory(), existingCaseDto.getMaternalHistory(), inJurisdiction);
    }
}
Also used : VisitService(de.symeda.sormas.backend.visit.VisitService) PlagueType(de.symeda.sormas.api.caze.PlagueType) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) TaskHelper(de.symeda.sormas.api.task.TaskHelper) AbstractCoreFacadeEjb(de.symeda.sormas.backend.common.AbstractCoreFacadeEjb) TransactionAttributeType(javax.ejb.TransactionAttributeType) CaseExportDto(de.symeda.sormas.api.caze.CaseExportDto) Duration(java.time.Duration) Map(java.util.Map) TreatmentFacadeEjb(de.symeda.sormas.backend.therapy.TreatmentFacadeEjb) DocumentRelatedEntityType(de.symeda.sormas.api.document.DocumentRelatedEntityType) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) OutbreakService(de.symeda.sormas.backend.outbreak.OutbreakService) DiseaseHelper(de.symeda.sormas.api.DiseaseHelper) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) FacilityHelper(de.symeda.sormas.api.infrastructure.facility.FacilityHelper) Resource(javax.annotation.Resource) TaskPriority(de.symeda.sormas.api.task.TaskPriority) NotNull(javax.validation.constraints.NotNull) CaseIndexDetailedDto(de.symeda.sormas.api.caze.CaseIndexDetailedDto) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) SampleService(de.symeda.sormas.backend.sample.SampleService) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) Sample(de.symeda.sormas.backend.sample.Sample) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) ManualMessageLogDto(de.symeda.sormas.api.messaging.ManualMessageLogDto) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) TypedQuery(javax.persistence.TypedQuery) VisitFacadeEjbLocal(de.symeda.sormas.backend.visit.VisitFacadeEjb.VisitFacadeEjbLocal) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) CaseListEntryDto(de.symeda.sormas.api.caze.CaseListEntryDto) Calendar(java.util.Calendar) PreviousHospitalizationDto(de.symeda.sormas.api.hospitalization.PreviousHospitalizationDto) SampleFacadeEjb(de.symeda.sormas.backend.sample.SampleFacadeEjb) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) ExportHelper(de.symeda.sormas.backend.importexport.ExportHelper) EJB(javax.ejb.EJB) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) ManualMessageLogService(de.symeda.sormas.backend.common.messaging.ManualMessageLogService) HospitalizationFacadeEjbLocal(de.symeda.sormas.backend.hospitalization.HospitalizationFacadeEjb.HospitalizationFacadeEjbLocal) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) AgeAndBirthDateDto(de.symeda.sormas.api.caze.AgeAndBirthDateDto) PersonService(de.symeda.sormas.backend.person.PersonService) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) PrescriptionFacadeEjb(de.symeda.sormas.backend.therapy.PrescriptionFacadeEjb) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) VisitDto(de.symeda.sormas.api.visit.VisitDto) HealthConditions(de.symeda.sormas.backend.clinicalcourse.HealthConditions) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) PortHealthInfoFacadeEjbLocal(de.symeda.sormas.backend.caze.porthealthinfo.PortHealthInfoFacadeEjb.PortHealthInfoFacadeEjbLocal) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) SurveillanceReportService(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReportService) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Join(javax.persistence.criteria.Join) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) PopulationDataFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.PopulationDataFacadeEjb.PopulationDataFacadeEjbLocal) Random(java.util.Random) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) PortHealthInfoDto(de.symeda.sormas.api.caze.porthealthinfo.PortHealthInfoDto) PrescriptionService(de.symeda.sormas.backend.therapy.PrescriptionService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) CriteriaBuilderHelper.or(de.symeda.sormas.backend.common.CriteriaBuilderHelper.or) CaseClassificationFacadeEjbLocal(de.symeda.sormas.backend.caze.classification.CaseClassificationFacadeEjb.CaseClassificationFacadeEjbLocal) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) VisitSummaryExportDetails(de.symeda.sormas.backend.contact.VisitSummaryExportDetails) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) InfrastructureHelper(de.symeda.sormas.api.infrastructure.InfrastructureHelper) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) Person(de.symeda.sormas.backend.person.Person) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) PrescriptionFacadeEjbLocal(de.symeda.sormas.backend.therapy.PrescriptionFacadeEjb.PrescriptionFacadeEjbLocal) Instant(java.time.Instant) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Language(de.symeda.sormas.api.Language) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) PatchHelper(de.symeda.sormas.backend.util.PatchHelper) Objects(java.util.Objects) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) SurveillanceReportFacadeEjb(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReportFacadeEjb) ExportConfigurationDto(de.symeda.sormas.api.importexport.ExportConfigurationDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) PreviousHospitalization(de.symeda.sormas.backend.hospitalization.PreviousHospitalization) ContactDto(de.symeda.sormas.api.contact.ContactDto) LocalDate(java.time.LocalDate) Order(javax.persistence.criteria.Order) ClinicalCourseDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseDto) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) CoreEntityType(de.symeda.sormas.backend.deletionconfiguration.CoreEntityType) Function(java.util.function.Function) VisitOrigin(de.symeda.sormas.api.VisitOrigin) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) AdditionalTestFacadeEjbLocal(de.symeda.sormas.backend.sample.AdditionalTestFacadeEjb.AdditionalTestFacadeEjbLocal) Inject(javax.inject.Inject) ReinfectionDetail(de.symeda.sormas.api.caze.ReinfectionDetail) PreviousCaseDto(de.symeda.sormas.api.caze.PreviousCaseDto) TransactionAttribute(javax.ejb.TransactionAttribute) TaskStatus(de.symeda.sormas.api.task.TaskStatus) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) CriteriaBuilderHelper.and(de.symeda.sormas.backend.common.CriteriaBuilderHelper.and) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) LocationDto(de.symeda.sormas.api.location.LocationDto) TaskContext(de.symeda.sormas.api.task.TaskContext) Logger(org.slf4j.Logger) HospitalizationFacadeEjb(de.symeda.sormas.backend.hospitalization.HospitalizationFacadeEjb) Document(de.symeda.sormas.backend.document.Document) TherapyFacadeEjbLocal(de.symeda.sormas.backend.therapy.TherapyFacadeEjb.TherapyFacadeEjbLocal) VisitLogic.getVisitResult(de.symeda.sormas.backend.visit.VisitLogic.getVisitResult) DateTime(org.joda.time.DateTime) UserReference(de.symeda.sormas.backend.user.UserReference) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) PresentCondition(de.symeda.sormas.api.person.PresentCondition) UserRight(de.symeda.sormas.api.user.UserRight) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Comparator(java.util.Comparator) Arrays(java.util.Arrays) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) EmbeddedSampleExportDto(de.symeda.sormas.api.caze.EmbeddedSampleExportDto) SymptomsFacadeEjbLocal(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb.SymptomsFacadeEjbLocal) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) Valid(javax.validation.Valid) BigDecimal(java.math.BigDecimal) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Page(de.symeda.sormas.api.common.Page) FollowUpDto(de.symeda.sormas.api.followup.FollowUpDto) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) JsonNode(com.fasterxml.jackson.databind.JsonNode) Visit(de.symeda.sormas.backend.visit.Visit) EpiData(de.symeda.sormas.backend.epidata.EpiData) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) TherapyDto(de.symeda.sormas.api.therapy.TherapyDto) Set(java.util.Set) SampleFacadeEjbLocal(de.symeda.sormas.backend.sample.SampleFacadeEjb.SampleFacadeEjbLocal) DistrictFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb.DistrictFacadeEjbLocal) PointOfEntryService(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryService) UserService(de.symeda.sormas.backend.user.UserService) MaternalHistoryDto(de.symeda.sormas.api.caze.maternalhistory.MaternalHistoryDto) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) HealthConditionsDto(de.symeda.sormas.api.clinicalcourse.HealthConditionsDto) FollowUpPeriodDto(de.symeda.sormas.api.followup.FollowUpPeriodDto) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseMeasure(de.symeda.sormas.api.CaseMeasure) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) PathogenTest(de.symeda.sormas.backend.sample.PathogenTest) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) ClinicalVisitFacadeEjb(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitFacadeEjb) EpiDataFacadeEjb(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) LocalBean(javax.ejb.LocalBean) CountryHelper(de.symeda.sormas.api.CountryHelper) Root(javax.persistence.criteria.Root) PersonFacadeEjbLocal(de.symeda.sormas.backend.person.PersonFacadeEjb.PersonFacadeEjbLocal) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) MessageType(de.symeda.sormas.api.messaging.MessageType) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) MaternalHistoryFacadeEjbLocal(de.symeda.sormas.backend.caze.maternalhistory.MaternalHistoryFacadeEjb.MaternalHistoryFacadeEjbLocal) CaseFacade(de.symeda.sormas.api.caze.CaseFacade) Captions(de.symeda.sormas.api.i18n.Captions) Exposure(de.symeda.sormas.backend.exposure.Exposure) Treatment(de.symeda.sormas.backend.therapy.Treatment) CaseBulkEditData(de.symeda.sormas.api.caze.CaseBulkEditData) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) ContactService(de.symeda.sormas.backend.contact.ContactService) SampleDto(de.symeda.sormas.api.sample.SampleDto) Subquery(javax.persistence.criteria.Subquery) SymptomsFacadeEjb(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) SurveillanceReport(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) FeatureType(de.symeda.sormas.api.feature.FeatureType) TherapyFacadeEjb(de.symeda.sormas.backend.therapy.TherapyFacadeEjb) EventService(de.symeda.sormas.backend.event.EventService) PointOfEntryFacadeEjb(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryFacadeEjb) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) ClinicalVisitService(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitService) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) InfoProvider(de.symeda.sormas.api.utils.InfoProvider) LoggerFactory(org.slf4j.LoggerFactory) ExposureType(de.symeda.sormas.api.exposure.ExposureType) HealthConditionsMapper(de.symeda.sormas.backend.clinicalcourse.HealthConditionsMapper) CauseOfDeath(de.symeda.sormas.api.person.CauseOfDeath) CommunityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb.CommunityFacadeEjbLocal) ExposureService(de.symeda.sormas.backend.exposure.ExposureService) ExternalShareInfoCountAndLatestDate(de.symeda.sormas.backend.share.ExternalShareInfoCountAndLatestDate) SormasToSormasCaseFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.caze.SormasToSormasCaseFacadeEjb.SormasToSormasCaseFacadeEjbLocal) NotificationService(de.symeda.sormas.backend.common.NotificationService) TreatmentFacadeEjbLocal(de.symeda.sormas.backend.therapy.TreatmentFacadeEjb.TreatmentFacadeEjbLocal) UserRole(de.symeda.sormas.api.user.UserRole) Path(javax.persistence.criteria.Path) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) PortHealthInfoFacadeEjb(de.symeda.sormas.backend.caze.porthealthinfo.PortHealthInfoFacadeEjb) DocumentService(de.symeda.sormas.backend.document.DocumentService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) AdditionalTest(de.symeda.sormas.backend.sample.AdditionalTest) SormasToSormasFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.SormasToSormasFacadeEjb.SormasToSormasFacadeEjbLocal) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) TaskType(de.symeda.sormas.api.task.TaskType) EventSummaryDetails(de.symeda.sormas.backend.event.EventSummaryDetails) List(java.util.List) MaternalHistoryFacadeEjb(de.symeda.sormas.backend.caze.maternalhistory.MaternalHistoryFacadeEjb) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) Optional(java.util.Optional) EpiDataHelper(de.symeda.sormas.api.epidata.EpiDataHelper) Location(de.symeda.sormas.backend.location.Location) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) ClinicalCourseFacadeEjb(de.symeda.sormas.backend.clinicalcourse.ClinicalCourseFacadeEjb) VaccinationFacadeEjb(de.symeda.sormas.backend.vaccination.VaccinationFacadeEjb) TaskService(de.symeda.sormas.backend.task.TaskService) HashMap(java.util.HashMap) PathogenTestFacadeEjbLocal(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb.PathogenTestFacadeEjbLocal) SurveillanceReportDto(de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto) CaseExportType(de.symeda.sormas.api.caze.CaseExportType) CollectionUtils(org.apache.commons.collections.CollectionUtils) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) FacilityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb.FacilityFacadeEjbLocal) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) TreatmentService(de.symeda.sormas.backend.therapy.TreatmentService) Expression(javax.persistence.criteria.Expression) BurialInfoDto(de.symeda.sormas.api.caze.BurialInfoDto) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) EpiDataService(de.symeda.sormas.backend.epidata.EpiDataService) CaseJoins(de.symeda.sormas.utils.CaseJoins) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) EpiDataFacadeEjbLocal(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb.EpiDataFacadeEjbLocal) Validations(de.symeda.sormas.api.i18n.Validations) ClinicalVisitFacadeEjbLocal(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitFacadeEjb.ClinicalVisitFacadeEjbLocal) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) Pair(de.symeda.sormas.api.utils.DataHelper.Pair) PathogenTestService(de.symeda.sormas.backend.sample.PathogenTestService) MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) TimeUnit(java.util.concurrent.TimeUnit) Event(de.symeda.sormas.backend.event.Event) NotificationType(de.symeda.sormas.api.user.NotificationType) MessagingService(de.symeda.sormas.backend.common.messaging.MessagingService) Country(de.symeda.sormas.backend.infrastructure.country.Country) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ClinicalCourseFacadeEjbLocal(de.symeda.sormas.backend.clinicalcourse.ClinicalCourseFacadeEjb.ClinicalCourseFacadeEjbLocal) Strings(de.symeda.sormas.api.i18n.Strings) ExternalSurveillanceToolGatewayFacadeEjbLocal(de.symeda.sormas.backend.externalsurveillancetool.ExternalSurveillanceToolGatewayFacadeEjb.ExternalSurveillanceToolGatewayFacadeEjbLocal) Collections(java.util.Collections) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) TreatmentDto(de.symeda.sormas.api.therapy.TreatmentDto) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) User(de.symeda.sormas.backend.user.User) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto)

Example 4 with EpiData

use of de.symeda.sormas.backend.epidata.EpiData in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method getExportList.

@Override
public List<ContactExportDto> getExportList(ContactCriteria contactCriteria, Collection<String> selectedRows, int first, int max, ExportConfigurationDto exportConfiguration, Language userLanguage) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<ContactExportDto> cq = cb.createQuery(ContactExportDto.class);
    final Root<Contact> contact = cq.from(Contact.class);
    final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
    final ContactJoins<Contact> joins = (ContactJoins) contactQueryContext.getJoins();
    cq.multiselect(contact.get(Contact.ID), joins.getPerson().get(Person.ID), contact.get(Contact.UUID), joins.getCaze().get(Case.UUID), joins.getCaze().get(Case.CASE_CLASSIFICATION), contact.get(Contact.DISEASE), contact.get(Contact.DISEASE_DETAILS), contact.get(Contact.CONTACT_CLASSIFICATION), contact.get(Contact.MULTI_DAY_CONTACT), contact.get(Contact.FIRST_CONTACT_DATE), contact.get(Contact.LAST_CONTACT_DATE), contact.get(Contact.CREATION_DATE), joins.getPerson().get(Person.UUID), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), joins.getPerson().get(Person.SALUTATION), joins.getPerson().get(Person.OTHER_SALUTATION), joins.getPerson().get(Person.SEX), joins.getPerson().get(Person.BIRTHDATE_DD), joins.getPerson().get(Person.BIRTHDATE_MM), joins.getPerson().get(Person.BIRTHDATE_YYYY), joins.getPerson().get(Person.APPROXIMATE_AGE), joins.getPerson().get(Person.APPROXIMATE_AGE_TYPE), contact.get(Contact.REPORT_DATE_TIME), contact.get(Contact.CONTACT_IDENTIFICATION_SOURCE), contact.get(Contact.CONTACT_IDENTIFICATION_SOURCE_DETAILS), contact.get(Contact.TRACING_APP), contact.get(Contact.TRACING_APP_DETAILS), contact.get(Contact.CONTACT_PROXIMITY), contact.get(Contact.CONTACT_STATUS), contact.get(Contact.COMPLETENESS), contact.get(Contact.FOLLOW_UP_STATUS), contact.get(Contact.FOLLOW_UP_UNTIL), contact.get(Contact.QUARANTINE), contact.get(Contact.QUARANTINE_TYPE_DETAILS), contact.get(Contact.QUARANTINE_FROM), contact.get(Contact.QUARANTINE_TO), contact.get(Contact.QUARANTINE_HELP_NEEDED), contact.get(Contact.QUARANTINE_ORDERED_VERBALLY), contact.get(Contact.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT), contact.get(Contact.QUARANTINE_ORDERED_VERBALLY_DATE), contact.get(Contact.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE), contact.get(Contact.QUARANTINE_EXTENDED), contact.get(Contact.QUARANTINE_REDUCED), contact.get(Contact.QUARANTINE_OFFICIAL_ORDER_SENT), contact.get(Contact.QUARANTINE_OFFICIAL_ORDER_SENT_DATE), contact.get(Contact.PROHIBITION_TO_WORK), contact.get(Contact.PROHIBITION_TO_WORK_FROM), contact.get(Contact.PROHIBITION_TO_WORK_UNTIL), joins.getPerson().get(Person.PRESENT_CONDITION), joins.getPerson().get(Person.DEATH_DATE), joins.getAddressRegion().get(Region.NAME), joins.getAddressDistrict().get(District.NAME), joins.getAddressCommunity().get(Community.NAME), joins.getAddress().get(Location.CITY), joins.getAddress().get(Location.STREET), joins.getAddress().get(Location.HOUSE_NUMBER), joins.getAddress().get(Location.ADDITIONAL_INFORMATION), joins.getAddress().get(Location.POSTAL_CODE), joins.getAddressFacility().get(Facility.NAME), joins.getAddressFacility().get(Facility.UUID), joins.getAddress().get(Location.FACILITY_DETAILS), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_PHONE_SUBQUERY)), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_PHONE_OWNER_SUBQUERY)), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_EMAIL_SUBQUERY)), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY)), joins.getPerson().get(Person.OCCUPATION_TYPE), joins.getPerson().get(Person.OCCUPATION_DETAILS), joins.getPerson().get(Person.ARMED_FORCES_RELATION_TYPE), joins.getRegion().get(Region.NAME), joins.getDistrict().get(District.NAME), joins.getCommunity().get(Community.NAME), joins.getEpiData().get(EpiData.ID), joins.getEpiData().get(EpiData.CONTACT_WITH_SOURCE_CASE_KNOWN), contact.get(Contact.RETURNING_TRAVELER), contact.get(Contact.VACCINATION_STATUS), contact.get(Contact.EXTERNAL_ID), contact.get(Contact.EXTERNAL_TOKEN), contact.get(Contact.INTERNAL_TOKEN), joins.getPerson().get(Person.BIRTH_NAME), joins.getPersonBirthCountry().get(Country.ISO_CODE), joins.getPersonBirthCountry().get(Country.DEFAULT_NAME), joins.getPersonCitizenship().get(Country.ISO_CODE), joins.getPersonCitizenship().get(Country.DEFAULT_NAME), joins.getReportingDistrict().get(District.NAME), joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS), joins.getReportingUser().get(User.ID), joins.getFollowUpStatusChangeUser().get(User.ID), contact.get(Contact.PREVIOUS_QUARANTINE_TO), contact.get(Contact.QUARANTINE_CHANGE_COMMENT), jurisdictionSelector(contactQueryContext));
    cq.distinct(true);
    Predicate filter = listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext);
    filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, contact.get(Contact.UUID));
    if (filter != null) {
        cq.where(filter);
    }
    cq.orderBy(cb.desc(contact.get(Contact.REPORT_DATE_TIME)), cb.desc(contact.get(Contact.ID)));
    List<ContactExportDto> exportContacts = QueryHelper.getResultList(em, cq, first, max);
    List<String> resultContactsUuids = exportContacts.stream().map(ContactExportDto::getUuid).collect(Collectors.toList());
    if (!exportContacts.isEmpty()) {
        List<Long> exportContactIds = exportContacts.stream().map(e -> e.getId()).collect(Collectors.toList());
        List<VisitSummaryExportDetails> visitSummaries = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.NUMBER_OF_VISITS, ContactExportDto.LAST_COOPERATIVE_VISIT_DATE, ContactExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMATIC, ContactExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMS)) {
            CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class);
            Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
            ContactJoins<Contact> visitContactJoins = new ContactJoins(visitsCqRoot);
            visitsCq.where(CriteriaBuilderHelper.and(cb, contact.get(AbstractDomainObject.ID).in(exportContactIds), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS))));
            visitsCq.multiselect(visitsCqRoot.get(AbstractDomainObject.ID), visitContactJoins.getVisits().get(Visit.VISIT_DATE_TIME), visitContactJoins.getVisits().get(Visit.VISIT_STATUS), visitContactJoins.getVisitSymptoms(), jurisdictionSelector(new ContactQueryContext(cb, cq, visitsCqRoot)));
            visitSummaries = em.createQuery(visitsCq).getResultList();
        }
        Map<Long, List<Exposure>> exposures = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.TRAVELED, ContactExportDto.TRAVEL_HISTORY, ContactExportDto.BURIAL_ATTENDED)) {
            CriteriaQuery<Exposure> exposuresCq = cb.createQuery(Exposure.class);
            Root<Exposure> exposuresRoot = exposuresCq.from(Exposure.class);
            Join<Exposure, EpiData> exposuresEpiDataJoin = exposuresRoot.join(Exposure.EPI_DATA, JoinType.LEFT);
            Expression<String> epiDataIdsExpr = exposuresEpiDataJoin.get(EpiData.ID);
            Predicate exposuresPredicate = cb.and(epiDataIdsExpr.in(exportContacts.stream().map(ContactExportDto::getEpiDataId).collect(Collectors.toList())), cb.or(cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.TRAVEL), cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.BURIAL)));
            exposuresCq.where(exposuresPredicate);
            exposuresCq.orderBy(cb.asc(exposuresEpiDataJoin.get(EpiData.ID)));
            List<Exposure> exposureList = em.createQuery(exposuresCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            exposures = exposureList.stream().collect(Collectors.groupingBy(e -> e.getEpiData().getId()));
        }
        Map<Long, List<Immunization>> immunizations = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ExportHelper.getVaccinationExportProperties())) {
            List<Immunization> immunizationList;
            CriteriaQuery<Immunization> immunizationsCq = cb.createQuery(Immunization.class);
            Root<Immunization> immunizationsCqRoot = immunizationsCq.from(Immunization.class);
            Join<Immunization, Person> personJoin = immunizationsCqRoot.join(Immunization.PERSON, JoinType.LEFT);
            Expression<String> personIdsExpr = personJoin.get(Person.ID);
            immunizationsCq.where(CriteriaBuilderHelper.and(cb, cb.or(cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION), cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION_RECOVERY)), personIdsExpr.in(exportContacts.stream().map(ContactExportDto::getPersonId).collect(Collectors.toList()))));
            immunizationList = em.createQuery(immunizationsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            immunizations = immunizationList.stream().collect(Collectors.groupingBy(i -> i.getPerson().getId()));
        }
        Map<String, List<ContactEventSummaryDetails>> eventSummaries = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.EVENT_COUNT, ContactExportDto.LATEST_EVENT_ID, ContactExportDto.LATEST_EVENT_TITLE)) {
            // Load event count and latest events info per contact
            eventSummaries = eventService.getEventSummaryDetailsByContacts(resultContactsUuids).stream().collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
        }
        Map<Long, UserReference> contactUsers = getContactUsersForExport(exportContacts, exportConfiguration);
        // Adding a second query here is not perfect, but selecting the last cooperative visit with a criteria query
        // doesn't seem to be possible and using a native query is not an option because of user filters
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        for (ContactExportDto exportContact : exportContacts) {
            boolean inJurisdiction = exportContact.getInJurisdiction();
            if (visitSummaries != null) {
                List<VisitSummaryExportDetails> visits = visitSummaries.stream().filter(v -> v.getContactId() == exportContact.getId()).collect(Collectors.toList());
                VisitSummaryExportDetails lastCooperativeVisit = visits.stream().filter(v -> v.getVisitStatus() == VisitStatus.COOPERATIVE).max(Comparator.comparing(VisitSummaryExportDetails::getVisitDateTime)).orElse(null);
                exportContact.setNumberOfVisits(visits.size());
                if (lastCooperativeVisit != null) {
                    SymptomsDto symptoms = SymptomsFacadeEjb.toDto(lastCooperativeVisit.getSymptoms());
                    pseudonymizer.pseudonymizeDto(SymptomsDto.class, symptoms, inJurisdiction, null);
                    exportContact.setLastCooperativeVisitDate(lastCooperativeVisit.getVisitDateTime());
                    exportContact.setLastCooperativeVisitSymptoms(SymptomsHelper.buildSymptomsHumanString(symptoms, true, userLanguage));
                    exportContact.setLastCooperativeVisitSymptomatic(symptoms.getSymptomatic() == null ? YesNoUnknown.UNKNOWN : (symptoms.getSymptomatic() ? YesNoUnknown.YES : YesNoUnknown.NO));
                }
            }
            if (exposures != null) {
                Optional.ofNullable(exposures.get(exportContact.getEpiDataId())).ifPresent(contactExposures -> {
                    StringBuilder travelHistoryBuilder = new StringBuilder();
                    if (contactExposures.stream().anyMatch(e -> ExposureType.BURIAL.equals(e.getExposureType()))) {
                        exportContact.setBurialAttended(true);
                    }
                    contactExposures.stream().filter(e -> ExposureType.TRAVEL.equals(e.getExposureType())).forEach(exposure -> {
                        travelHistoryBuilder.append(EpiDataHelper.buildDetailedTravelString(exposure.getLocation().toString(), exposure.getDescription(), exposure.getStartDate(), exposure.getEndDate(), userLanguage)).append(", ");
                    });
                    if (travelHistoryBuilder.length() > 0) {
                        exportContact.setTraveled(true);
                        travelHistoryBuilder.delete(travelHistoryBuilder.lastIndexOf(", "), travelHistoryBuilder.length());
                    }
                    exportContact.setTravelHistory(travelHistoryBuilder.toString());
                });
            }
            if (immunizations != null) {
                Optional.ofNullable(immunizations.get(exportContact.getPersonId())).ifPresent(contactImmunizations -> {
                    List<Immunization> filteredImmunizations = contactImmunizations.stream().filter(i -> i.getDisease() == exportContact.getDisease()).collect(Collectors.toList());
                    if (filteredImmunizations.size() > 0) {
                        filteredImmunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, false)));
                        Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
                        Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();
                        exportContact.setNumberOfDoses(numberOfDoses != null ? String.valueOf(numberOfDoses) : "");
                        if (CollectionUtils.isNotEmpty(mostRecentImmunization.getVaccinations())) {
                            List<Vaccination> sortedVaccinations = mostRecentImmunization.getVaccinations().stream().sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison)).collect(Collectors.toList());
                            Vaccination firstVaccination = sortedVaccinations.get(0);
                            Vaccination lastVaccination = sortedVaccinations.get(sortedVaccinations.size() - 1);
                            exportContact.setFirstVaccinationDate(firstVaccination.getVaccinationDate());
                            exportContact.setLastVaccinationDate(lastVaccination.getVaccinationDate());
                            exportContact.setVaccineName(lastVaccination.getVaccineName());
                            exportContact.setOtherVaccineName(lastVaccination.getOtherVaccineName());
                            exportContact.setVaccineManufacturer(lastVaccination.getVaccineManufacturer());
                            exportContact.setOtherVaccineManufacturer(lastVaccination.getOtherVaccineManufacturer());
                            exportContact.setVaccinationInfoSource(lastVaccination.getVaccinationInfoSource());
                            exportContact.setVaccineAtcCode(lastVaccination.getVaccineAtcCode());
                            exportContact.setVaccineBatchNumber(lastVaccination.getVaccineBatchNumber());
                            exportContact.setVaccineUniiCode(lastVaccination.getVaccineUniiCode());
                            exportContact.setVaccineInn(lastVaccination.getVaccineInn());
                        }
                    }
                });
            }
            if (eventSummaries != null) {
                List<ContactEventSummaryDetails> contactEvents = eventSummaries.getOrDefault(exportContact.getUuid(), Collections.emptyList());
                exportContact.setEventCount((long) contactEvents.size());
                contactEvents.stream().max(Comparator.comparing(ContactEventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
                    exportContact.setLatestEventId(eventSummary.getEventUuid());
                    exportContact.setLatestEventTitle(eventSummary.getEventTitle());
                });
            }
            if (!contactUsers.isEmpty()) {
                if (exportContact.getReportingUserId() != null) {
                    UserReference user = contactUsers.get(exportContact.getReportingUserId());
                    exportContact.setReportingUserName(user.getName());
                    exportContact.setReportingUserRoles(user.getUserRoles());
                }
                if (exportContact.getFollowUpStatusChangeUserId() != null) {
                    UserReference user = contactUsers.get(exportContact.getFollowUpStatusChangeUserId());
                    exportContact.setFollowUpStatusChangeUserName(user.getName());
                    exportContact.setFollowUpStatusChangeUserRoles(user.getUserRoles());
                }
            }
            pseudonymizer.pseudonymizeDto(ContactExportDto.class, exportContact, inJurisdiction, null);
        }
    }
    return exportContacts;
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) VisitService(de.symeda.sormas.backend.visit.VisitService) Arrays(java.util.Arrays) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) PersonDto(de.symeda.sormas.api.person.PersonDto) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) Valid(javax.validation.Valid) AbstractCoreFacadeEjb(de.symeda.sormas.backend.common.AbstractCoreFacadeEjb) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Page(de.symeda.sormas.api.common.Page) FollowUpDto(de.symeda.sormas.api.followup.FollowUpDto) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) BigInteger(java.math.BigInteger) DocumentRelatedEntityType(de.symeda.sormas.api.document.DocumentRelatedEntityType) Visit(de.symeda.sormas.backend.visit.Visit) EpiData(de.symeda.sormas.backend.epidata.EpiData) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ContactExportDto(de.symeda.sormas.api.contact.ContactExportDto) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) Resource(javax.annotation.Resource) Set(java.util.Set) SampleFacadeEjbLocal(de.symeda.sormas.backend.sample.SampleFacadeEjb.SampleFacadeEjbLocal) TaskPriority(de.symeda.sormas.api.task.TaskPriority) NotNull(javax.validation.constraints.NotNull) DashboardContactDto(de.symeda.sormas.api.dashboard.DashboardContactDto) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) SampleService(de.symeda.sormas.backend.sample.SampleService) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Sample(de.symeda.sormas.backend.sample.Sample) ContactFacade(de.symeda.sormas.api.contact.ContactFacade) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) Community(de.symeda.sormas.backend.infrastructure.community.Community) FollowUpPeriodDto(de.symeda.sormas.api.followup.FollowUpPeriodDto) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) LocalDateTime(java.time.LocalDateTime) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Selection(javax.persistence.criteria.Selection) VisitFacadeEjbLocal(de.symeda.sormas.backend.visit.VisitFacadeEjb.VisitFacadeEjbLocal) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) MergeContactIndexDto(de.symeda.sormas.api.contact.MergeContactIndexDto) Case(de.symeda.sormas.backend.caze.Case) EpiDataFacadeEjb(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb) LocalBean(javax.ejb.LocalBean) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) ExportHelper(de.symeda.sormas.backend.importexport.ExportHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ContactSimilarityCriteria(de.symeda.sormas.api.contact.ContactSimilarityCriteria) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) PersonService(de.symeda.sormas.backend.person.PersonService) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) TaskCreationException(de.symeda.sormas.backend.common.TaskCreationException) Exposure(de.symeda.sormas.backend.exposure.Exposure) DAYS(java.time.temporal.ChronoUnit.DAYS) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) VisitDto(de.symeda.sormas.api.visit.VisitDto) DateHelper8(de.symeda.sormas.backend.util.DateHelper8) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) SymptomsFacadeEjb(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) EventService(de.symeda.sormas.backend.event.EventService) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) ExposureType(de.symeda.sormas.api.exposure.ExposureType) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) HealthConditionsMapper(de.symeda.sormas.backend.clinicalcourse.HealthConditionsMapper) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) SormasToSormasContactFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.contact.SormasToSormasContactFacadeEjb.SormasToSormasContactFacadeEjbLocal) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) UserRole(de.symeda.sormas.api.user.UserRole) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) ContactFollowUpDto(de.symeda.sormas.api.contact.ContactFollowUpDto) Stateless(javax.ejb.Stateless) DocumentService(de.symeda.sormas.backend.document.DocumentService) CaseService(de.symeda.sormas.backend.caze.CaseService) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) Person(de.symeda.sormas.backend.person.Person) Collection(java.util.Collection) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Language(de.symeda.sormas.api.Language) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) SormasToSormasFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.SormasToSormasFacadeEjb.SormasToSormasFacadeEjbLocal) TaskType(de.symeda.sormas.api.task.TaskType) Objects(java.util.Objects) ExportConfigurationDto(de.symeda.sormas.api.importexport.ExportConfigurationDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) Query(javax.persistence.Query) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) ContactDto(de.symeda.sormas.api.contact.ContactDto) LocalDate(java.time.LocalDate) Order(javax.persistence.criteria.Order) Optional(java.util.Optional) EpiDataHelper(de.symeda.sormas.api.epidata.EpiDataHelper) Location(de.symeda.sormas.backend.location.Location) VisitSummaryExportDto(de.symeda.sormas.api.visit.VisitSummaryExportDto) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) ClinicalCourseFacadeEjb(de.symeda.sormas.backend.clinicalcourse.ClinicalCourseFacadeEjb) VaccinationFacadeEjb(de.symeda.sormas.backend.vaccination.VaccinationFacadeEjb) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) CoreEntityType(de.symeda.sormas.backend.deletionconfiguration.CoreEntityType) Function(java.util.function.Function) VisitOrigin(de.symeda.sormas.api.VisitOrigin) Inject(javax.inject.Inject) CollectionUtils(org.apache.commons.collections.CollectionUtils) TransactionAttribute(javax.ejb.TransactionAttribute) TaskStatus(de.symeda.sormas.api.task.TaskStatus) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) LocationDto(de.symeda.sormas.api.location.LocationDto) TaskContext(de.symeda.sormas.api.task.TaskContext) ContactListEntryDto(de.symeda.sormas.api.contact.ContactListEntryDto) EpiDataFacadeEjbLocal(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb.EpiDataFacadeEjbLocal) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) Document(de.symeda.sormas.backend.document.Document) VisitLogic.getVisitResult(de.symeda.sormas.backend.visit.VisitLogic.getVisitResult) UserReference(de.symeda.sormas.backend.user.UserReference) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) TimeUnit(java.util.concurrent.TimeUnit) UserRight(de.symeda.sormas.api.user.UserRight) VisitSummaryExportDetailsDto(de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) Country(de.symeda.sormas.backend.infrastructure.country.Country) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Predicate(javax.persistence.criteria.Predicate) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Exposure(de.symeda.sormas.backend.exposure.Exposure) UserReference(de.symeda.sormas.backend.user.UserReference) Person(de.symeda.sormas.backend.person.Person) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) ContactExportDto(de.symeda.sormas.api.contact.ContactExportDto) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) EpiData(de.symeda.sormas.backend.epidata.EpiData) BigInteger(java.math.BigInteger) Expression(javax.persistence.criteria.Expression)

Aggregations

CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)4 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)4 ContactDto (de.symeda.sormas.api.contact.ContactDto)4 Disease (de.symeda.sormas.api.Disease)3 CasePersonDto (de.symeda.sormas.api.caze.CasePersonDto)3 SurveillanceReportDto (de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto)3 ClinicalCourseReferenceDto (de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto)3 ClinicalVisitCriteria (de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria)3 ClinicalVisitDto (de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto)3 PersonDto (de.symeda.sormas.api.person.PersonDto)3 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)3 AdditionalTestDto (de.symeda.sormas.api.sample.AdditionalTestDto)3 PathogenTestDto (de.symeda.sormas.api.sample.PathogenTestDto)3 SampleCriteria (de.symeda.sormas.api.sample.SampleCriteria)3 SampleDto (de.symeda.sormas.api.sample.SampleDto)3 TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)3 PrescriptionCriteria (de.symeda.sormas.api.therapy.PrescriptionCriteria)3 PrescriptionDto (de.symeda.sormas.api.therapy.PrescriptionDto)3 TherapyReferenceDto (de.symeda.sormas.api.therapy.TherapyReferenceDto)3 TreatmentCriteria (de.symeda.sormas.api.therapy.TreatmentCriteria)3