Search in sources :

Example 1 with Sex

use of de.symeda.sormas.api.person.Sex in project SORMAS-Project by hzi-braunschweig.

the class CaseService method getCasesForDuplicateMerging.

public List<CaseIndexDto[]> getCasesForDuplicateMerging(CaseCriteria criteria, boolean ignoreRegion, double nameSimilarityThreshold) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    Root<Case> root = cq.from(Case.class);
    final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, root);
    final CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
    Root<Case> root2 = cq.from(Case.class);
    Join<Case, Person> person = joins.getPerson();
    Join<Case, Person> person2 = root2.join(Case.PERSON, JoinType.LEFT);
    Join<Case, Region> responsibleRegion = joins.getResponsibleRegion();
    Join<Case, Region> responsibleRegion2 = root2.join(Case.RESPONSIBLE_REGION, JoinType.LEFT);
    Join<Case, Region> region = joins.getRegion();
    Join<Case, Region> region2 = root2.join(Case.REGION, JoinType.LEFT);
    Join<Case, Symptoms> symptoms = joins.getSymptoms();
    Join<Case, Symptoms> symptoms2 = root2.join(Case.SYMPTOMS, JoinType.LEFT);
    cq.distinct(true);
    // similarity:
    // * first & last name concatenated with whitespace. Similarity function with default threshold of 0.65D
    // uses postgres pg_trgm: https://www.postgresql.org/docs/9.6/pgtrgm.html
    // * same disease
    // * same region (optional)
    // * report date within 30 days of each other
    // * same sex or same birth date (when defined)
    // * same birth date (when fully defined)
    // * onset date within 30 days of each other (when defined)
    Predicate userFilter = createUserFilter(cb, cq, root);
    Predicate criteriaFilter = criteria != null ? createCriteriaFilter(criteria, caseQueryContext) : null;
    Expression<String> nameSimilarityExpr = cb.concat(person.get(Person.FIRST_NAME), " ");
    nameSimilarityExpr = cb.concat(nameSimilarityExpr, person.get(Person.LAST_NAME));
    Expression<String> nameSimilarityExpr2 = cb.concat(person2.get(Person.FIRST_NAME), " ");
    nameSimilarityExpr2 = cb.concat(nameSimilarityExpr2, person2.get(Person.LAST_NAME));
    Predicate nameSimilarityFilter = cb.gt(cb.function("similarity", double.class, nameSimilarityExpr, nameSimilarityExpr2), nameSimilarityThreshold);
    Predicate diseaseFilter = cb.equal(root.get(Case.DISEASE), root2.get(Case.DISEASE));
    Predicate regionFilter = cb.and(cb.equal(responsibleRegion.get(Region.ID), responsibleRegion2.get(Region.ID)), cb.or(cb.and(cb.isNull(region)), cb.equal(region.get(Region.ID), region2.get(Region.ID))));
    Predicate reportDateFilter = cb.lessThanOrEqualTo(cb.abs(cb.diff(cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), root.get(Case.REPORT_DATE)), cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), root2.get(Case.REPORT_DATE)))), SECONDS_30_DAYS);
    // // todo this should use PersonService.buildSimilarityCriteriaFilter
    // Sex filter: only when sex is filled in for both cases
    Predicate sexFilter = cb.or(cb.or(cb.isNull(person.get(Person.SEX)), cb.isNull(person2.get(Person.SEX))), cb.or(cb.equal(person.get(Person.SEX), Sex.UNKNOWN), cb.equal(person2.get(Person.SEX), Sex.UNKNOWN)), cb.equal(person.get(Person.SEX), person2.get(Person.SEX)));
    // Birth date filter: only when birth date is filled in for both cases
    Predicate birthDateFilter = cb.or(cb.or(cb.isNull(person.get(Person.BIRTHDATE_DD)), cb.isNull(person.get(Person.BIRTHDATE_MM)), cb.isNull(person.get(Person.BIRTHDATE_YYYY)), cb.isNull(person2.get(Person.BIRTHDATE_DD)), cb.isNull(person2.get(Person.BIRTHDATE_MM)), cb.isNull(person2.get(Person.BIRTHDATE_YYYY))), cb.and(cb.equal(person.get(Person.BIRTHDATE_DD), person2.get(Person.BIRTHDATE_DD)), cb.equal(person.get(Person.BIRTHDATE_MM), person2.get(Person.BIRTHDATE_MM)), cb.equal(person.get(Person.BIRTHDATE_YYYY), person2.get(Person.BIRTHDATE_YYYY))));
    // Onset date filter: only when onset date is filled in for both cases
    Predicate onsetDateFilter = cb.or(cb.or(cb.isNull(symptoms.get(Symptoms.ONSET_DATE)), cb.isNull(symptoms2.get(Symptoms.ONSET_DATE))), cb.lessThanOrEqualTo(cb.abs(cb.diff(cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), symptoms.get(Symptoms.ONSET_DATE)), cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), symptoms2.get(Symptoms.ONSET_DATE)))), SECONDS_30_DAYS));
    Predicate creationDateFilter = cb.or(cb.lessThan(root.get(Case.CREATION_DATE), root2.get(Case.CREATION_DATE)), cb.or(cb.lessThanOrEqualTo(root2.get(Case.CREATION_DATE), DateHelper.getStartOfDay(criteria.getCreationDateFrom())), cb.greaterThanOrEqualTo(root2.get(Case.CREATION_DATE), DateHelper.getEndOfDay(criteria.getCreationDateTo()))));
    Predicate filter = cb.and(createDefaultFilter(cb, root), createDefaultFilter(cb, root2));
    if (userFilter != null) {
        filter = cb.and(filter, userFilter);
    }
    if (filter != null) {
        filter = cb.and(filter, criteriaFilter);
    } else {
        filter = criteriaFilter;
    }
    if (filter != null) {
        filter = cb.and(filter, nameSimilarityFilter);
    } else {
        filter = nameSimilarityFilter;
    }
    filter = cb.and(filter, diseaseFilter);
    if (!ignoreRegion) {
        filter = cb.and(filter, regionFilter);
    }
    filter = cb.and(filter, reportDateFilter);
    filter = cb.and(filter, cb.and(sexFilter, birthDateFilter));
    filter = cb.and(filter, onsetDateFilter);
    filter = cb.and(filter, creationDateFilter);
    filter = cb.and(filter, cb.notEqual(root.get(Case.ID), root2.get(Case.ID)));
    cq.where(filter);
    cq.multiselect(root.get(Case.ID), root2.get(Case.ID), root.get(Case.CREATION_DATE));
    cq.orderBy(cb.desc(root.get(Case.CREATION_DATE)));
    List<Object[]> foundIds = em.createQuery(cq).setParameter("date_type", "epoch").getResultList();
    List<CaseIndexDto[]> resultList = new ArrayList<>();
    if (!foundIds.isEmpty()) {
        CriteriaQuery<CaseIndexDto> indexCasesCq = cb.createQuery(CaseIndexDto.class);
        Root<Case> indexRoot = indexCasesCq.from(Case.class);
        selectIndexDtoFields(new CaseQueryContext(cb, indexCasesCq, indexRoot));
        indexCasesCq.where(indexRoot.get(Case.ID).in(foundIds.stream().map(a -> Arrays.copyOf(a, 2)).flatMap(Arrays::stream).collect(Collectors.toSet())));
        Map<Long, CaseIndexDto> indexCases = em.createQuery(indexCasesCq).getResultStream().collect(Collectors.toMap(c -> c.getId(), Function.identity()));
        for (Object[] idPair : foundIds) {
            try {
                // Cloning is necessary here to allow us to add the same CaseIndexDto to the grid multiple times
                CaseIndexDto parent = (CaseIndexDto) indexCases.get(idPair[0]).clone();
                CaseIndexDto child = (CaseIndexDto) indexCases.get(idPair[1]).clone();
                if (parent.getCompleteness() == null && child.getCompleteness() == null || parent.getCompleteness() != null && (child.getCompleteness() == null || (parent.getCompleteness() >= child.getCompleteness()))) {
                    resultList.add(new CaseIndexDto[] { parent, child });
                } else {
                    resultList.add(new CaseIndexDto[] { child, parent });
                }
            } catch (CloneNotSupportedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return resultList;
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) NoResultException(javax.persistence.NoResultException) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) Visit(de.symeda.sormas.backend.visit.Visit) From(javax.persistence.criteria.From) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) Transactional(javax.transaction.Transactional) NotNull(javax.validation.constraints.NotNull) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) SampleService(de.symeda.sormas.backend.sample.SampleService) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Sample(de.symeda.sormas.backend.sample.Sample) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) CaseListEntryDto(de.symeda.sormas.api.caze.CaseListEntryDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) LocalBean(javax.ejb.LocalBean) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) Treatment(de.symeda.sormas.backend.therapy.Treatment) Disease(de.symeda.sormas.api.Disease) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) ContactService(de.symeda.sormas.backend.contact.ContactService) FollowUpLogic(de.symeda.sormas.api.followup.FollowUpLogic) CaseSelectionDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseSelectionDtoResultTransformer) Subquery(javax.persistence.criteria.Subquery) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Join(javax.persistence.criteria.Join) ClinicalVisitService(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitService) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) Fetch(javax.persistence.criteria.Fetch) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) PrescriptionService(de.symeda.sormas.backend.therapy.PrescriptionService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) UserRole(de.symeda.sormas.api.user.UserRole) ExternalShareDateType(de.symeda.sormas.api.utils.criteria.ExternalShareDateType) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) List(java.util.List) ExtendedPostgreSQL94Dialect(de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) ClinicalCourse(de.symeda.sormas.backend.clinicalcourse.ClinicalCourse) Location(de.symeda.sormas.backend.location.Location) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) Function(java.util.function.Function) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) CollectionUtils(org.apache.commons.collections.CollectionUtils) PreviousCaseDto(de.symeda.sormas.api.caze.PreviousCaseDto) TransactionAttribute(javax.ejb.TransactionAttribute) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) TreatmentService(de.symeda.sormas.backend.therapy.TreatmentService) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) 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) MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) ImmunizationService(de.symeda.sormas.backend.immunization.ImmunizationService) Event(de.symeda.sormas.backend.event.Event) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) Comparator(java.util.Comparator) Collections(java.util.Collections) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) CaseListEntryDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseListEntryDtoResultTransformer) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) CaseJoins(de.symeda.sormas.utils.CaseJoins) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Person(de.symeda.sormas.backend.person.Person) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms)

Example 2 with Sex

use of de.symeda.sormas.api.person.Sex in project SORMAS-Project by hzi-braunschweig.

the class CaseCreateForm method addFields.

@Override
protected void addFields() {
    NullableOptionGroup ogCaseOrigin = addField(CaseDataDto.CASE_ORIGIN, NullableOptionGroup.class);
    ogCaseOrigin.setRequired(true);
    TextField epidField = addField(CaseDataDto.EPID_NUMBER, TextField.class);
    epidField.setInvalidCommitted(true);
    style(epidField, ERROR_COLOR_PRIMARY);
    if (!FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        TextField externalIdField = addField(CaseDataDto.EXTERNAL_ID, TextField.class);
        style(externalIdField, ERROR_COLOR_PRIMARY);
    } else {
        CheckBox dontShareCheckbox = addField(CaseDataDto.DONT_SHARE_WITH_REPORTING_TOOL, CheckBox.class);
        CaseFormHelper.addDontShareWithReportingTool(getContent(), () -> dontShareCheckbox, DONT_SHARE_WARNING_LOC);
    }
    addField(CaseDataDto.REPORT_DATE, DateField.class);
    ComboBox diseaseField = addDiseaseField(CaseDataDto.DISEASE, false, true);
    ComboBox diseaseVariantField = addField(CaseDataDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantDetailsField = addField(CaseDataDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    diseaseVariantField.setNullSelectionAllowed(true);
    diseaseVariantField.setVisible(false);
    addField(CaseDataDto.DISEASE_DETAILS, TextField.class);
    NullableOptionGroup plagueType = addField(CaseDataDto.PLAGUE_TYPE, NullableOptionGroup.class);
    addField(CaseDataDto.DENGUE_FEVER_TYPE, NullableOptionGroup.class);
    addField(CaseDataDto.RABIES_TYPE, NullableOptionGroup.class);
    addCustomField(PersonDto.FIRST_NAME, String.class, TextField.class);
    addCustomField(PersonDto.LAST_NAME, String.class, TextField.class);
    if (showPersonSearchButton) {
        searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
        getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
    }
    TextField nationalHealthIdField = addCustomField(PersonDto.NATIONAL_HEALTH_ID, String.class, TextField.class);
    TextField passportNumberField = addCustomField(PersonDto.PASSPORT_NUMBER, String.class, TextField.class);
    if (CountryHelper.isCountry(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY)) {
        nationalHealthIdField.setVisible(false);
    }
    if (CountryHelper.isInCountries(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY, CountryHelper.COUNTRY_CODE_FRANCE)) {
        passportNumberField.setVisible(false);
    }
    birthDateDay = addCustomField(PersonDto.BIRTH_DATE_DD, Integer.class, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.addStyleName(FORCE_CAPTION);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    ComboBox birthDateMonth = addCustomField(PersonDto.BIRTH_DATE_MM, Integer.class, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    birthDateMonth.addStyleName(FORCE_CAPTION);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addCustomField(PersonDto.BIRTH_DATE_YYYY, Integer.class, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
    });
    ComboBox sex = addCustomField(PersonDto.SEX, Sex.class, ComboBox.class);
    sex.setCaption(I18nProperties.getCaption(Captions.Person_sex));
    ComboBox presentCondition = addCustomField(PersonDto.PRESENT_CONDITION, PresentCondition.class, ComboBox.class);
    presentCondition.setCaption(I18nProperties.getCaption(Captions.Person_presentCondition));
    addCustomField(SymptomsDto.ONSET_DATE, Date.class, DateField.class, I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
    TextField phone = addCustomField(PersonDto.PHONE, String.class, TextField.class);
    phone.setCaption(I18nProperties.getCaption(Captions.Person_phone));
    TextField email = addCustomField(PersonDto.EMAIL_ADDRESS, String.class, TextField.class);
    email.setCaption(I18nProperties.getCaption(Captions.Person_emailAddress));
    phone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, phone.getCaption())));
    email.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, email.getCaption())));
    differentPlaceOfStayJurisdiction = addCustomField(DIFFERENT_PLACE_OF_STAY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPlaceOfStayJurisdiction.addStyleName(VSPACE_3);
    Label placeOfStayHeadingLabel = new Label(I18nProperties.getCaption(Captions.casePlaceOfStay));
    placeOfStayHeadingLabel.addStyleName(H3);
    getContent().addComponent(placeOfStayHeadingLabel, PLACE_OF_STAY_HEADING_LOC);
    ComboBox region = addInfrastructureField(CaseDataDto.REGION);
    districtCombo = addInfrastructureField(CaseDataDto.DISTRICT);
    communityCombo = addInfrastructureField(CaseDataDto.COMMUNITY);
    communityCombo.setNullSelectionAllowed(true);
    // jurisdictionfields
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingCaseResponsibleJurisidction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    ComboBox responsibleRegion = addInfrastructureField(CaseDataDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    responsibleDistrictCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_DISTRICT);
    responsibleDistrictCombo.setRequired(true);
    responsibleCommunityCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunityCombo.setNullSelectionAllowed(true);
    responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
    differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
    ComboBox pointOfEntryRegionCombo = addCustomField(POINT_OF_ENTRY_REGION, RegionReferenceDto.class, ComboBox.class);
    pointOfEntryDistrictCombo = addCustomField(POINT_OF_ENTRY_DISTRICT, DistrictReferenceDto.class, ComboBox.class);
    InfrastructureFieldsHelper.initInfrastructureFields(pointOfEntryRegionCombo, pointOfEntryDistrictCombo, null);
    pointOfEntryDistrictCombo.addValueChangeListener(e -> updatePOEs());
    if (showHomeAddressForm) {
        addHomeAddressForm();
    }
    FieldHelper.setVisibleWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo, communityCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(pointOfEntryRegionCombo, pointOfEntryDistrictCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setRequiredWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
    ogCaseOrigin.addValueChangeListener(e -> {
        boolean pointOfEntryRegionDistrictVisible = CaseOrigin.POINT_OF_ENTRY.equals(ogCaseOrigin.getValue()) && Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue());
        pointOfEntryRegionCombo.setVisible(pointOfEntryRegionDistrictVisible);
        pointOfEntryDistrictCombo.setVisible(pointOfEntryRegionDistrictVisible);
    });
    facilityOrHome = addCustomField(FACILITY_OR_HOME_LOC, TypeOfPlace.class, NullableOptionGroup.class, I18nProperties.getCaption(Captions.casePlaceOfStay));
    facilityOrHome.removeAllItems();
    for (TypeOfPlace place : TypeOfPlace.FOR_CASES) {
        facilityOrHome.addItem(place);
        facilityOrHome.setItemCaption(place, I18nProperties.getEnumCaption(place));
    }
    facilityOrHome.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
    facilityOrHome.setId("facilityOrHome");
    facilityOrHome.setWidth(100, Unit.PERCENTAGE);
    CssStyles.style(facilityOrHome, ValoTheme.OPTIONGROUP_HORIZONTAL);
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    facilityTypeGroup.setId("typeGroup");
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    facilityType = ComboBoxHelper.createComboBoxV7();
    facilityType.setId("type");
    facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
    facilityType.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(facilityType, CaseDataDto.FACILITY_TYPE);
    facilityCombo = addInfrastructureField(CaseDataDto.HEALTH_FACILITY);
    facilityCombo.setImmediate(true);
    TextField facilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    ComboBox cbPointOfEntry = addInfrastructureField(CaseDataDto.POINT_OF_ENTRY);
    cbPointOfEntry.setImmediate(true);
    TextField tfPointOfEntryDetails = addField(CaseDataDto.POINT_OF_ENTRY_DETAILS, TextField.class);
    tfPointOfEntryDetails.setVisible(false);
    if (convertedTravelEntry != null) {
        differentPointOfEntryJurisdiction.setValue(true);
        RegionReferenceDto regionReferenceDto = convertedTravelEntry.getPointOfEntryRegion() != null ? convertedTravelEntry.getPointOfEntryRegion() : convertedTravelEntry.getResponsibleRegion();
        pointOfEntryRegionCombo.setValue(regionReferenceDto);
        DistrictReferenceDto districtReferenceDto = convertedTravelEntry.getPointOfEntryDistrict() != null ? convertedTravelEntry.getPointOfEntryDistrict() : convertedTravelEntry.getResponsibleDistrict();
        pointOfEntryDistrictCombo.setValue(districtReferenceDto);
        differentPointOfEntryJurisdiction.setReadOnly(true);
        pointOfEntryRegionCombo.setReadOnly(true);
        pointOfEntryDistrictCombo.setReadOnly(true);
        updatePOEs();
        cbPointOfEntry.setReadOnly(true);
        tfPointOfEntryDetails.setReadOnly(true);
        ogCaseOrigin.setReadOnly(true);
    }
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    districtCombo.addValueChangeListener(e -> {
        FieldHelper.removeItems(communityCombo);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(communityCombo, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        updateFacility();
        if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
            updatePOEs();
        }
    });
    communityCombo.addValueChangeListener(e -> {
        updateFacility();
    });
    facilityOrHome.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        if (TypeOfPlace.FACILITY.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.FACILITY.equals(facilityOrHome.getNullableValue()))) {
            if (facilityTypeGroup.getValue() == null) {
                facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
            }
            if (facilityType.getValue() == null && FacilityTypeGroup.MEDICAL_FACILITY.equals(facilityTypeGroup.getValue())) {
                facilityType.setValue(FacilityType.HOSPITAL);
            }
            if (facilityType.getValue() != null) {
                updateFacility();
            }
            if (CaseOrigin.IN_COUNTRY.equals(ogCaseOrigin.getValue())) {
                facilityCombo.setRequired(true);
            }
            updateFacilityFields(facilityCombo, facilityDetails);
        } else if (TypeOfPlace.HOME.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.HOME.equals(facilityOrHome.getNullableValue()))) {
            setNoneFacility();
        } else {
            facilityCombo.removeAllItems();
            facilityCombo.setValue(null);
            updateFacilityFields(facilityCombo, facilityDetails);
        }
    });
    facilityTypeGroup.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
    });
    facilityType.addValueChangeListener(e -> updateFacility());
    region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    JurisdictionLevel userJurisdictionLevel = UserRole.getJurisdictionLevel(UserProvider.getCurrent().getUserRoles());
    if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        region.setReadOnly(true);
        responsibleRegion.setReadOnly(true);
        districtCombo.setReadOnly(true);
        responsibleDistrictCombo.setReadOnly(true);
        communityCombo.setReadOnly(true);
        responsibleCommunityCombo.setReadOnly(true);
        differentPlaceOfStayJurisdiction.setVisible(false);
        differentPlaceOfStayJurisdiction.setEnabled(false);
        facilityOrHome.setImmediate(true);
        // [FACILITY]
        facilityOrHome.setValue(Sets.newHashSet(TypeOfPlace.FACILITY));
        facilityOrHome.setReadOnly(true);
        facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
        facilityTypeGroup.setReadOnly(true);
        facilityType.setValue(FacilityType.HOSPITAL);
        facilityType.setReadOnly(true);
        facilityCombo.setValue(UserProvider.getCurrent().getUser().getHealthFacility());
        facilityCombo.setReadOnly(true);
    }
    if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
        ogCaseOrigin.addValueChangeListener(ev -> {
            if (ev.getProperty().getValue() == CaseOrigin.IN_COUNTRY) {
                setVisible(false, CaseDataDto.POINT_OF_ENTRY, CaseDataDto.POINT_OF_ENTRY_DETAILS);
                differentPointOfEntryJurisdiction.setVisible(false);
                setRequired(true, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
                setRequired(false, CaseDataDto.POINT_OF_ENTRY);
                updateFacilityFields(facilityCombo, facilityDetails);
            } else {
                setVisible(true, CaseDataDto.POINT_OF_ENTRY);
                differentPointOfEntryJurisdiction.setVisible(true);
                setRequired(true, CaseDataDto.POINT_OF_ENTRY);
                if (userJurisdictionLevel != JurisdictionLevel.HEALTH_FACILITY) {
                    facilityOrHome.clear();
                    setRequired(false, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
                }
                updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
            }
        });
    }
    // jurisdiction field valuechangelisteners
    responsibleDistrictCombo.addValueChangeListener(e -> {
        Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
        if (!Boolean.TRUE.equals(differentPlaceOfStay)) {
            updateFacility();
            if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
                updatePOEs();
            }
        }
    });
    responsibleCommunityCombo.addValueChangeListener((e) -> {
        Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
        if (differentPlaceOfStay == null || Boolean.FALSE.equals(differentPlaceOfStay)) {
            updateFacility();
        }
    });
    differentPlaceOfStayJurisdiction.addValueChangeListener(e -> {
        updateFacility();
        if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
            updatePOEs();
        }
    });
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, CaseDataDto.REPORT_DATE, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, CaseDataDto.DISEASE, PersonDto.SEX, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE);
    FieldHelper.addSoftRequiredStyle(plagueType, communityCombo, facilityDetails);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DISEASE_DETAILS), CaseDataDto.DISEASE, Arrays.asList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.DISEASE, Arrays.asList(CaseDataDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
    FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.HEALTH_FACILITY), Arrays.asList(CaseOrigin.IN_COUNTRY));
    FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.POINT_OF_ENTRY), Arrays.asList(CaseOrigin.POINT_OF_ENTRY));
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.PLAGUE_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.PLAGUE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DENGUE_FEVER_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.DENGUE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.RABIES_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.RABIES), true);
    FieldHelper.setVisibleWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false);
    FieldHelper.setRequiredWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false, null);
    facilityCombo.addValueChangeListener(e -> {
        updateFacilityFields(facilityCombo, facilityDetails);
        this.getValue().setFacilityType((FacilityType) facilityType.getValue());
    });
    cbPointOfEntry.addValueChangeListener(e -> {
        updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
    });
    addValueChangeListener(e -> {
        if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
            setVisible(false, CaseDataDto.CASE_ORIGIN, CaseDataDto.DISEASE, CaseDataDto.COMMUNITY, CaseDataDto.HEALTH_FACILITY);
            setVisible(true, CaseDataDto.POINT_OF_ENTRY);
        }
    });
    diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> {
        Disease disease = (Disease) valueChangeEvent.getProperty().getValue();
        List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
        FieldHelper.updateItems(diseaseVariantField, diseaseVariants);
        diseaseVariantField.setVisible(disease != null && isVisibleAllowed(CaseDataDto.DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) LayoutUtil.divsCss(de.symeda.sormas.ui.utils.LayoutUtil.divsCss) Date(java.util.Date) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LayoutUtil.locs(de.symeda.sormas.ui.utils.LayoutUtil.locs) PersonDto(de.symeda.sormas.api.person.PersonDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CssStyles(de.symeda.sormas.ui.utils.CssStyles) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) UserProvider(de.symeda.sormas.ui.UserProvider) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Sex(de.symeda.sormas.api.person.Sex) PersonDependentEditForm(de.symeda.sormas.ui.utils.PersonDependentEditForm) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Sets(com.google.common.collect.Sets) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) FacadeProvider(de.symeda.sormas.api.FacadeProvider) DateHelper(de.symeda.sormas.api.utils.DateHelper) Converter(com.vaadin.v7.data.util.converter.Converter) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) CollectionUtils(org.apache.commons.collections.CollectionUtils) Label(com.vaadin.ui.Label) CountryHelper(de.symeda.sormas.api.CountryHelper) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) LocationDto(de.symeda.sormas.api.location.LocationDto) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) Month(java.time.Month) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ItemCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Button(com.vaadin.ui.Button) Disease(de.symeda.sormas.api.Disease) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Label(com.vaadin.ui.Label) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) List(java.util.List)

Example 3 with Sex

use of de.symeda.sormas.api.person.Sex in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testGetMatchingNameDtos.

@Test
public void testGetMatchingNameDtos() {
    RDCFEntities rdcf = creator.createRDCFEntities();
    UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR);
    // 1-3 = Active persons; 4 = Person without reference; 5-7 = Inactive persons
    PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1);
    PersonDto person2 = creator.createPerson("James", "Smith", Sex.MALE, 1979, 5, 12);
    PersonDto person3 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 5);
    PersonDto person4 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, 12, 2);
    PersonDto person5 = creator.createPerson("Maria", "Garcia", Sex.UNKNOWN, 1984, 7, 12);
    PersonDto person6 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, null, null);
    PersonDto person7 = creator.createPerson("James", "Smith", Sex.MALE, null, null, null);
    CaseDataDto activeCase = creator.createCase(user.toReference(), person1.toReference(), rdcf);
    creator.createContact(user.toReference(), person2.toReference(), activeCase);
    EventDto activeEvent = creator.createEvent(user.toReference());
    creator.createEventParticipant(activeEvent.toReference(), person3, user.toReference());
    CaseDataDto inactiveCase = creator.createCase(user.toReference(), person5.toReference(), rdcf);
    creator.createContact(user.toReference(), person6.toReference(), inactiveCase);
    EventDto inactiveEvent = creator.createEvent(user.toReference());
    creator.createEventParticipant(inactiveEvent.toReference(), person7, user.toReference());
    getCaseFacade().archive(inactiveCase.getUuid(), null);
    getEventFacade().archive(inactiveEvent.getUuid(), null);
    // Only persons that have active case, contact or event participant associations should be retrieved
    List<String> relevantNameUuids = getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria()).stream().map(dto -> dto.getUuid()).collect(Collectors.toList());
    assertThat(relevantNameUuids, hasSize(6));
    assertThat(relevantNameUuids, containsInAnyOrder(person1.getUuid(), person2.getUuid(), person3.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid()));
    creator.createCase(user.toReference(), person4.toReference(), rdcf);
    getCaseFacade().dearchive(Collections.singletonList(inactiveCase.getUuid()), null);
    getEventFacade().dearchive(Collections.singletonList(inactiveEvent.getUuid()), null);
    PersonSimilarityCriteria criteria = new PersonSimilarityCriteria().sex(Sex.MALE).birthdateYYYY(1980).birthdateMM(1).birthdateDD(1);
    List<String> matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(2));
    assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person7.getUuid()));
    criteria.birthdateMM(null).birthdateDD(null);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(3));
    assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid()));
    criteria.sex(Sex.FEMALE).birthdateYYYY(1984);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(3));
    assertThat(matchingUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid()));
    criteria.sex(null);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(4));
    assertThat(matchingUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid()));
    final String passportNr = "passportNr";
    final String otherPassportNr = "otherPassportNr";
    final String healthId = "healthId";
    final String otherHealthId = "otherHealthId";
    PersonDto person8 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1, passportNr, healthId);
    PersonDto person9 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1, null, otherHealthId);
    PersonDto person10 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1970, 1, 1, passportNr, null);
    PersonDto person11 = creator.createPerson("John", "Doe", Sex.MALE, 1970, 1, 1, otherPassportNr, null);
    creator.createCase(user.toReference(), person8.toReference(), rdcf);
    creator.createCase(user.toReference(), person9.toReference(), rdcf);
    creator.createCase(user.toReference(), person10.toReference(), rdcf);
    creator.createCase(user.toReference(), person11.toReference(), rdcf);
    criteria.sex(Sex.MALE).birthdateYYYY(1980);
    criteria.passportNumber(passportNr);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(6));
    assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person8.getUuid(), person9.getUuid(), person10.getUuid()));
    criteria.nationalHealthId(healthId).passportNumber(null);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(4));
    assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person8.getUuid()));
    criteria.nationalHealthId(otherHealthId);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(4));
    assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person9.getUuid()));
    criteria.passportNumber(otherPassportNr);
    matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
    assertThat(matchingUuids, hasSize(5));
    assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person9.getUuid(), person11.getUuid()));
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) Date(java.util.Date) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Matchers.not(org.hamcrest.Matchers.not) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) PersonDto(de.symeda.sormas.api.person.PersonDto) EntityDto(de.symeda.sormas.api.EntityDto) PersonContext(de.symeda.sormas.api.person.PersonContext) UserRole(de.symeda.sormas.api.user.UserRole) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) EventDto(de.symeda.sormas.api.event.EventDto) Collectors(java.util.stream.Collectors) PhoneNumberType(de.symeda.sormas.api.person.PhoneNumberType) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) SymptomJournalStatus(de.symeda.sormas.api.person.SymptomJournalStatus) Optional(java.util.Optional) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) Matchers.is(org.hamcrest.Matchers.is) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) PersonFacade(de.symeda.sormas.api.person.PersonFacade) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationDto(de.symeda.sormas.api.location.LocationDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) Matchers.empty(org.hamcrest.Matchers.empty) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserDto(de.symeda.sormas.api.user.UserDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SortProperty(de.symeda.sormas.api.utils.SortProperty) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Assert.assertNull(org.junit.Assert.assertNull) Disease(de.symeda.sormas.api.Disease) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with Sex

use of de.symeda.sormas.api.person.Sex in project SORMAS-Project by hzi-braunschweig.

the class PersonService method buildSimilarityCriteriaFilter.

public Predicate buildSimilarityCriteriaFilter(PersonSimilarityCriteria criteria, CriteriaBuilder cb, From<?, Person> personFrom) {
    Predicate filter = null;
    if (!StringUtils.isBlank(criteria.getFirstName()) && !StringUtils.isBlank(criteria.getLastName())) {
        Expression<String> nameExpr = cb.concat(personFrom.get(Person.FIRST_NAME), " ");
        nameExpr = cb.concat(nameExpr, personFrom.get(Person.LAST_NAME));
        String name = criteria.getFirstName() + " " + criteria.getLastName();
        filter = and(cb, filter, cb.isTrue(cb.function(SIMILARITY_OPERATOR, boolean.class, nameExpr, cb.literal(name))));
    } else if (!StringUtils.isBlank(criteria.getFirstName())) {
        filter = and(cb, filter, cb.isTrue(cb.function(SIMILARITY_OPERATOR, boolean.class, personFrom.get(Person.FIRST_NAME), cb.literal(criteria.getFirstName()))));
    } else if (!StringUtils.isBlank(criteria.getLastName())) {
        filter = and(cb, filter, cb.isTrue(cb.function(SIMILARITY_OPERATOR, boolean.class, personFrom.get(Person.LAST_NAME), cb.literal(criteria.getLastName()))));
    }
    if (criteria.getSex() != null) {
        Expression<Sex> sexExpr = cb.literal(criteria.getSex());
        Predicate sexFilter = cb.or(cb.or(cb.isNull(personFrom.get(Person.SEX)), cb.isNull(sexExpr)), cb.or(cb.equal(personFrom.get(Person.SEX), Sex.UNKNOWN), cb.equal(sexExpr, Sex.UNKNOWN)), cb.equal(personFrom.get(Person.SEX), sexExpr));
        filter = and(cb, filter, sexFilter);
    }
    if (criteria.getBirthdateYYYY() != null) {
        filter = and(cb, filter, cb.or(cb.isNull(personFrom.get(Person.BIRTHDATE_YYYY)), cb.equal(personFrom.get(Person.BIRTHDATE_YYYY), criteria.getBirthdateYYYY())));
    }
    if (criteria.getBirthdateMM() != null) {
        filter = and(cb, filter, cb.or(cb.isNull(personFrom.get(Person.BIRTHDATE_MM)), cb.equal(personFrom.get(Person.BIRTHDATE_MM), criteria.getBirthdateMM())));
    }
    if (criteria.getBirthdateDD() != null) {
        filter = and(cb, filter, cb.or(cb.isNull(personFrom.get(Person.BIRTHDATE_DD)), cb.equal(personFrom.get(Person.BIRTHDATE_DD), criteria.getBirthdateDD())));
    }
    if (!StringUtils.isBlank(criteria.getNationalHealthId())) {
        filter = and(cb, filter, cb.or(cb.isNull(personFrom.get(Person.NATIONAL_HEALTH_ID)), cb.equal(personFrom.get(Person.NATIONAL_HEALTH_ID), criteria.getNationalHealthId())));
    }
    if (!StringUtils.isBlank(criteria.getPassportNumber())) {
        filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(personFrom.get(Person.PASSPORT_NUMBER), criteria.getPassportNumber()));
    }
    String uuidExternalIdExternalTokenLike = criteria.getUuidExternalIdExternalTokenLike();
    if (!StringUtils.isBlank(uuidExternalIdExternalTokenLike)) {
        Predicate uuidExternalIdExternalTokenFilter = CriteriaBuilderHelper.buildFreeTextSearchPredicate(cb, uuidExternalIdExternalTokenLike, (searchTerm) -> cb.or(CriteriaBuilderHelper.ilike(cb, personFrom.get(Person.UUID), searchTerm), CriteriaBuilderHelper.ilike(cb, personFrom.get(Person.EXTERNAL_ID), searchTerm), CriteriaBuilderHelper.ilike(cb, personFrom.get(Person.EXTERNAL_TOKEN), searchTerm)));
        filter = CriteriaBuilderHelper.or(cb, filter, uuidExternalIdExternalTokenFilter);
    }
    return filter;
}
Also used : Sex(de.symeda.sormas.api.person.Sex) Predicate(javax.persistence.criteria.Predicate)

Example 5 with Sex

use of de.symeda.sormas.api.person.Sex in project SORMAS-Project by hzi-braunschweig.

the class TravelEntryCreateForm method addFields.

@Override
protected void addFields() {
    addField(TravelEntryDto.REPORT_DATE, DateField.class);
    TextField externalIdField = addField(TravelEntryDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    ComboBox diseaseField = addDiseaseField(TravelEntryDto.DISEASE, false, true);
    ComboBox diseaseVariantField = addField(TravelEntryDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantField.setNullSelectionAllowed(true);
    diseaseVariantField.setVisible(false);
    addField(TravelEntryDto.DISEASE_DETAILS, TextField.class);
    TextField diseaseVariantDetailsField = addField(TravelEntryDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    responsibleRegion = addInfrastructureField(TravelEntryDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    responsibleDistrict = addInfrastructureField(TravelEntryDto.RESPONSIBLE_DISTRICT);
    responsibleDistrict.setRequired(true);
    responsibleCommunity = addInfrastructureField(TravelEntryDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunity.setNullSelectionAllowed(true);
    responsibleCommunity.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrict, responsibleCommunity);
    CheckBox differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
    Label placeOfStayHeadingLabel = new Label(I18nProperties.getCaption(Captions.travelEntryPointOfEntry));
    placeOfStayHeadingLabel.addStyleName(H3);
    getContent().addComponent(placeOfStayHeadingLabel, POINT_OF_ENTRY_HEADING_LOC);
    ComboBox regionCombo = addInfrastructureField(TravelEntryDto.REGION);
    districtCombo = addInfrastructureField(TravelEntryDto.DISTRICT);
    cbPointOfEntry = addInfrastructureField(TravelEntryDto.POINT_OF_ENTRY);
    cbPointOfEntry.setImmediate(true);
    TextField tfPointOfEntryDetails = addField(TravelEntryDto.POINT_OF_ENTRY_DETAILS, TextField.class);
    tfPointOfEntryDetails.setVisible(false);
    addCustomField(PersonDto.FIRST_NAME, String.class, TextField.class);
    addCustomField(PersonDto.LAST_NAME, String.class, TextField.class);
    Button searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
    getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
    TextField nationalHealthIdField = addCustomField(PersonDto.NATIONAL_HEALTH_ID, String.class, TextField.class);
    TextField passportNumberField = addCustomField(PersonDto.PASSPORT_NUMBER, String.class, TextField.class);
    if (CountryHelper.isCountry(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY)) {
        nationalHealthIdField.setVisible(false);
    }
    if (CountryHelper.isInCountries(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY, CountryHelper.COUNTRY_CODE_FRANCE)) {
        passportNumberField.setVisible(false);
    }
    birthDateDay = addCustomField(PersonDto.BIRTH_DATE_DD, Integer.class, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.addStyleName(FORCE_CAPTION);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    ComboBox birthDateMonth = addCustomField(PersonDto.BIRTH_DATE_MM, Integer.class, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    birthDateMonth.addStyleName(FORCE_CAPTION);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addCustomField(PersonDto.BIRTH_DATE_YYYY, Integer.class, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID_TOSTRING);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
    });
    ComboBox sex = addCustomField(PersonDto.SEX, Sex.class, ComboBox.class);
    sex.setCaption(I18nProperties.getCaption(Captions.Person_sex));
    ComboBox presentCondition = addCustomField(PersonDto.PRESENT_CONDITION, PresentCondition.class, ComboBox.class);
    presentCondition.setCaption(I18nProperties.getCaption(Captions.Person_presentCondition));
    TextField phone = addCustomField(PersonDto.PHONE, String.class, TextField.class);
    phone.setCaption(I18nProperties.getCaption(Captions.Person_phone));
    TextField email = addCustomField(PersonDto.EMAIL_ADDRESS, String.class, TextField.class);
    email.setCaption(I18nProperties.getCaption(Captions.Person_emailAddress));
    phone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, phone.getCaption())));
    email.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, email.getCaption())));
    regionCombo.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    regionCombo.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    districtCombo.addValueChangeListener(e -> {
        if (differentPointOfEntryJurisdiction.getValue()) {
            DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
            getPointsOfEntryForDistrict(districtDto);
        }
    });
    differentPointOfEntryJurisdiction.addValueChangeListener(v -> {
        if (differentPointOfEntryJurisdiction.getValue()) {
            cbPointOfEntry.removeAllItems();
        } else {
            getPointsOfEntryForDistrict((DistrictReferenceDto) responsibleDistrict.getValue());
        }
    });
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, TravelEntryDto.REPORT_DATE, TravelEntryDto.POINT_OF_ENTRY, TravelEntryDto.DISEASE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(TravelEntryDto.DISEASE_DETAILS), TravelEntryDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), TravelEntryDto.DISEASE, Collections.singletonList(TravelEntryDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    cbPointOfEntry.addValueChangeListener(e -> updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails));
    FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(regionCombo, districtCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setRequiredWhen(differentPointOfEntryJurisdiction, Arrays.asList(regionCombo, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
    responsibleDistrict.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        getPointsOfEntryForDistrict(districtDto);
    });
    diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> {
        Disease disease = (Disease) valueChangeEvent.getProperty().getValue();
        List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
        FieldHelper.updateItems(diseaseVariantField, diseaseVariants);
        diseaseVariantField.setVisible(disease != null && isVisibleAllowed(TravelEntryDto.DISEASE_VARIANT) && CollectionUtils.isNotEmpty(diseaseVariants));
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
    addValueChangeListener(e -> {
        if (personDto != null) {
            setVisible(false, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX, PersonDto.NATIONAL_HEALTH_ID, PersonDto.PASSPORT_NUMBER, PersonDto.BIRTH_DATE_DD, PersonDto.BIRTH_DATE_MM, PersonDto.BIRTH_DATE_YYYY, PersonDto.PRESENT_CONDITION, PersonDto.PHONE, PersonDto.EMAIL_ADDRESS);
            setReadOnly(false, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX, PersonDto.NATIONAL_HEALTH_ID, PersonDto.PASSPORT_NUMBER, PersonDto.BIRTH_DATE_DD, PersonDto.BIRTH_DATE_MM, PersonDto.BIRTH_DATE_YYYY, PersonDto.PRESENT_CONDITION, PersonDto.PHONE, PersonDto.EMAIL_ADDRESS);
            searchPersonButton.setVisible(false);
        } else {
            setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
        }
    });
}
Also used : H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DeaContentEntry(de.symeda.sormas.api.travelentry.DeaContentEntry) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) UserProvider(de.symeda.sormas.ui.UserProvider) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ComboBox(com.vaadin.v7.ui.ComboBox) Sex(de.symeda.sormas.api.person.Sex) PersonDependentEditForm(de.symeda.sormas.ui.utils.PersonDependentEditForm) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) FacadeProvider(de.symeda.sormas.api.FacadeProvider) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) Converter(com.vaadin.v7.data.util.converter.Converter) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) CollectionUtils(org.apache.commons.collections.CollectionUtils) Label(com.vaadin.ui.Label) CountryHelper(de.symeda.sormas.api.CountryHelper) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) DEAFormBuilder(de.symeda.sormas.ui.travelentry.DEAFormBuilder) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) Month(java.time.Month) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Button(com.vaadin.ui.Button) LayoutUtil(de.symeda.sormas.ui.utils.LayoutUtil) Disease(de.symeda.sormas.api.Disease) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) List(java.util.List)

Aggregations

Sex (de.symeda.sormas.api.person.Sex)8 Disease (de.symeda.sormas.api.Disease)5 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)5 UserRole (de.symeda.sormas.api.user.UserRole)5 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)4 PersonDto (de.symeda.sormas.api.person.PersonDto)4 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)3 PresentCondition (de.symeda.sormas.api.person.PresentCondition)3 DateHelper (de.symeda.sormas.api.utils.DateHelper)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Date (java.util.Date)3 List (java.util.List)3 Button (com.vaadin.ui.Button)2 Label (com.vaadin.ui.Label)2 Converter (com.vaadin.v7.data.util.converter.Converter)2 EmailValidator (com.vaadin.v7.data.validator.EmailValidator)2 AbstractSelect (com.vaadin.v7.ui.AbstractSelect)2 CheckBox (com.vaadin.v7.ui.CheckBox)2 ComboBox (com.vaadin.v7.ui.ComboBox)2