Search in sources :

Example 1 with ApproximateAgeType

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

the class PersonFacadeEjb method toDto.

public static PersonDto toDto(Person source) {
    if (source == null) {
        return null;
    }
    PersonDto target = new PersonDto();
    DtoHelper.fillDto(target, source);
    target.setFirstName(source.getFirstName());
    target.setLastName(source.getLastName());
    target.setSalutation(source.getSalutation());
    target.setOtherSalutation(source.getOtherSalutation());
    target.setSex(source.getSex());
    target.setPresentCondition(source.getPresentCondition());
    target.setBirthdateDD(source.getBirthdateDD());
    target.setBirthdateMM(source.getBirthdateMM());
    target.setBirthdateYYYY(source.getBirthdateYYYY());
    if (source.getBirthdateYYYY() != null) {
        // calculate the approximate age based on the birth date
        // still not sure whether this is a good solution
        Pair<Integer, ApproximateAgeType> pair = ApproximateAgeHelper.getApproximateAge(source.getBirthdateYYYY(), source.getBirthdateMM(), source.getBirthdateDD(), source.getDeathDate());
        target.setApproximateAge(pair.getElement0());
        target.setApproximateAgeType(pair.getElement1());
        target.setApproximateAgeReferenceDate(source.getDeathDate() != null ? source.getDeathDate() : new Date());
    } else {
        target.setApproximateAge(source.getApproximateAge());
        target.setApproximateAgeType(source.getApproximateAgeType());
        target.setApproximateAgeReferenceDate(source.getApproximateAgeReferenceDate());
    }
    target.setCauseOfDeath(source.getCauseOfDeath());
    target.setCauseOfDeathDetails(source.getCauseOfDeathDetails());
    target.setCauseOfDeathDisease(source.getCauseOfDeathDisease());
    target.setDeathDate(source.getDeathDate());
    target.setDeathPlaceType(source.getDeathPlaceType());
    target.setDeathPlaceDescription(source.getDeathPlaceDescription());
    target.setBurialDate(source.getBurialDate());
    target.setBurialPlaceDescription(source.getBurialPlaceDescription());
    target.setBurialConductor(source.getBurialConductor());
    target.setBirthName(source.getBirthName());
    target.setNickname(source.getNickname());
    target.setMothersMaidenName(source.getMothersMaidenName());
    target.setAddress(LocationFacadeEjb.toDto(source.getAddress()));
    List<LocationDto> locations = new ArrayList<>();
    for (Location location : source.getAddresses()) {
        LocationDto locationDto = LocationFacadeEjb.toDto(location);
        locations.add(locationDto);
    }
    target.setAddresses(locations);
    if (!CollectionUtils.isEmpty(source.getPersonContactDetails())) {
        target.setPersonContactDetails(source.getPersonContactDetails().stream().map(entity -> {
            final PersonContactDetailDto personContactDetailDto = PersonContactDetailDto.build(source.toReference(), entity.isPrimaryContact(), entity.getPersonContactDetailType(), entity.getPhoneNumberType(), entity.getDetails(), entity.getContactInformation(), entity.getAdditionalInformation(), entity.isThirdParty(), entity.getThirdPartyRole(), entity.getThirdPartyName());
            DtoHelper.fillDto(personContactDetailDto, entity);
            return personContactDetailDto;
        }).collect(Collectors.toList()));
    }
    target.setEducationType(source.getEducationType());
    target.setEducationDetails(source.getEducationDetails());
    target.setOccupationType(source.getOccupationType());
    target.setOccupationDetails(source.getOccupationDetails());
    target.setArmedForcesRelationType(source.getArmedForcesRelationType());
    target.setMothersName(source.getMothersName());
    target.setFathersName(source.getFathersName());
    target.setNamesOfGuardians(source.getNamesOfGuardians());
    target.setPlaceOfBirthRegion(RegionFacadeEjb.toReferenceDto(source.getPlaceOfBirthRegion()));
    target.setPlaceOfBirthDistrict(DistrictFacadeEjb.toReferenceDto(source.getPlaceOfBirthDistrict()));
    target.setPlaceOfBirthCommunity(CommunityFacadeEjb.toReferenceDto(source.getPlaceOfBirthCommunity()));
    target.setPlaceOfBirthFacility(FacilityFacadeEjb.toReferenceDto(source.getPlaceOfBirthFacility()));
    target.setPlaceOfBirthFacilityDetails(source.getPlaceOfBirthFacilityDetails());
    target.setGestationAgeAtBirth(source.getGestationAgeAtBirth());
    target.setBirthWeight(source.getBirthWeight());
    target.setPassportNumber(source.getPassportNumber());
    target.setNationalHealthId(source.getNationalHealthId());
    target.setPlaceOfBirthFacilityType(source.getPlaceOfBirthFacilityType());
    target.setSymptomJournalStatus(source.getSymptomJournalStatus());
    target.setHasCovidApp(source.isHasCovidApp());
    target.setCovidCodeDelivered(source.isCovidCodeDelivered());
    target.setExternalId(source.getExternalId());
    target.setExternalToken(source.getExternalToken());
    target.setInternalToken(source.getInternalToken());
    target.setBirthCountry(CountryFacadeEjb.toReferenceDto(source.getBirthCountry()));
    target.setCitizenship(CountryFacadeEjb.toReferenceDto(source.getCitizenship()));
    target.setAdditionalDetails(source.getAdditionalDetails());
    return target;
}
Also used : PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) ArrayList(java.util.ArrayList) Date(java.util.Date) LocationDto(de.symeda.sormas.api.location.LocationDto) Location(de.symeda.sormas.backend.location.Location)

Example 2 with ApproximateAgeType

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

the class PersonFacadeEjb method onPersonChanged.

public void onPersonChanged(PersonDto existingPerson, Person newPerson, boolean syncShares) {
    List<Case> personCases = null;
    // Do not bother to update existing cases/contacts/eventparticipants on new Persons, as none should exist yet
    if (existingPerson != null) {
        personCases = caseService.findBy(new CaseCriteria().person(new PersonReferenceDto(newPerson.getUuid())), true);
        // Attention: this may lead to infinite recursion when not properly implemented
        for (Case personCase : personCases) {
            CaseDataDto existingCase = caseFacade.toDto(personCase);
            caseFacade.onCaseChanged(existingCase, personCase, syncShares);
        }
        List<Contact> personContacts = contactService.findBy(new ContactCriteria().setPerson(new PersonReferenceDto(newPerson.getUuid())), null);
        // Attention: this may lead to infinite recursion when not properly implemented
        for (Contact personContact : personContacts) {
            contactFacade.onContactChanged(contactFacade.toDto(personContact), syncShares);
        }
        List<EventParticipant> personEventParticipants = eventParticipantService.findBy(new EventParticipantCriteria().withPerson(new PersonReferenceDto(newPerson.getUuid())), null);
        // Attention: this may lead to infinite recursion when not properly implemented
        for (EventParticipant personEventParticipant : personEventParticipants) {
            eventParticipantFacade.onEventParticipantChanged(eventFacade.toDto(personEventParticipant.getEvent()), eventParticipantFacade.toDto(personEventParticipant), personEventParticipant, syncShares);
        }
        // get the updated personCases
        personCases = caseService.findBy(new CaseCriteria().person(new PersonReferenceDto(newPerson.getUuid())), true);
        // sort cases based on recency
        Collections.sort(personCases, (c1, c2) -> CaseLogic.getStartDate(c1.getSymptoms().getOnsetDate(), c1.getReportDate()).before(CaseLogic.getStartDate(c2.getSymptoms().getOnsetDate(), c2.getReportDate())) ? 1 : -1);
        if (newPerson.getPresentCondition() != null && existingPerson.getPresentCondition() != newPerson.getPresentCondition()) {
            // get the latest case with disease==causeofdeathdisease
            Case personCase = personCases.stream().filter(caze -> caze.getDisease() == newPerson.getCauseOfDeathDisease()).findFirst().orElse(null);
            if (newPerson.getPresentCondition().isDeceased() && newPerson.getDeathDate() != null && newPerson.getCauseOfDeath() == CauseOfDeath.EPIDEMIC_DISEASE && newPerson.getCauseOfDeathDisease() != null) {
                // update the latest associated case
                if (personCase != null && personCase.getOutcome() != CaseOutcome.DECEASED && (personCase.getReportDate().before(DateHelper.addDays(newPerson.getDeathDate(), 30)) && personCase.getReportDate().after(DateHelper.subtractDays(newPerson.getDeathDate(), 30)))) {
                    CaseDataDto existingCase = caseFacade.toDto(personCase);
                    personCase.setOutcome(CaseOutcome.DECEASED);
                    personCase.setOutcomeDate(newPerson.getDeathDate());
                    caseFacade.onCaseChanged(existingCase, personCase, syncShares);
                }
            } else if (!newPerson.getPresentCondition().isDeceased() && (existingPerson.getPresentCondition() == PresentCondition.DEAD || existingPerson.getPresentCondition() == PresentCondition.BURIED)) {
                // Person was put "back alive"
                // make sure other values are set to null
                newPerson.setCauseOfDeath(null);
                newPerson.setCauseOfDeathDisease(null);
                newPerson.setDeathPlaceDescription(null);
                newPerson.setDeathPlaceType(null);
                newPerson.setBurialDate(null);
                newPerson.setCauseOfDeathDisease(null);
                // update the latest associated case, if it was set to deceased && and if the case-disease was also the causeofdeath-disease
                if (personCase != null && personCase.getOutcome() == CaseOutcome.DECEASED) {
                    CaseDataDto existingCase = caseFacade.toDto(personCase);
                    personCase.setOutcome(CaseOutcome.NO_OUTCOME);
                    personCase.setOutcomeDate(null);
                    caseFacade.onCaseChanged(existingCase, personCase, syncShares);
                }
            }
        } else if (newPerson.getPresentCondition() != null && newPerson.getPresentCondition().isDeceased() && !Objects.equals(newPerson.getDeathDate(), existingPerson.getDeathDate()) && newPerson.getDeathDate() != null) {
            // only Deathdate has changed
            // update the latest associated case to the new deathdate, if causeOfDeath matches
            Case personCase = personCases.isEmpty() ? null : personCases.get(0);
            if (personCase != null && personCase.getOutcome() == CaseOutcome.DECEASED && newPerson.getCauseOfDeath() == CauseOfDeath.EPIDEMIC_DISEASE) {
                CaseDataDto existingCase = caseFacade.toDto(personCase);
                personCase.setOutcomeDate(newPerson.getDeathDate());
                caseFacade.onCaseChanged(existingCase, personCase, syncShares);
            }
        }
    }
    // Set approximate age if it hasn't been set before
    if (newPerson.getApproximateAge() == null && newPerson.getBirthdateYYYY() != null) {
        Pair<Integer, ApproximateAgeType> pair = ApproximateAgeHelper.getApproximateAge(newPerson.getBirthdateYYYY(), newPerson.getBirthdateMM(), newPerson.getBirthdateDD(), newPerson.getDeathDate());
        newPerson.setApproximateAge(pair.getElement0());
        newPerson.setApproximateAgeType(pair.getElement1());
        newPerson.setApproximateAgeReferenceDate(newPerson.getDeathDate() != null ? newPerson.getDeathDate() : new Date());
    }
    // Update caseAge of all associated cases when approximateAge has changed
    if (existingPerson != null && existingPerson.getApproximateAge() != newPerson.getApproximateAge()) {
        // Update case list after previous onCaseChanged
        personCases = caseService.findBy(new CaseCriteria().person(new PersonReferenceDto(newPerson.getUuid())), true);
        for (Case personCase : personCases) {
            CaseDataDto existingCase = caseFacade.toDto(personCase);
            if (newPerson.getApproximateAge() == null) {
                personCase.setCaseAge(null);
            } else if (newPerson.getApproximateAgeType() == ApproximateAgeType.MONTHS) {
                personCase.setCaseAge(0);
            } else {
                Date now = new Date();
                personCase.setCaseAge(newPerson.getApproximateAge() - DateHelper.getYearsBetween(personCase.getReportDate(), now));
                if (personCase.getCaseAge() < 0) {
                    personCase.setCaseAge(0);
                }
            }
            caseFacade.onCaseChanged(existingCase, personCase, syncShares);
        }
    }
    // For newly created persons, assume no registration in external journals
    if (existingPerson == null && newPerson.getSymptomJournalStatus() == null) {
        newPerson.setSymptomJournalStatus(SymptomJournalStatus.UNREGISTERED);
    }
    cleanUp(newPerson);
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Date(java.util.Date) Case(de.symeda.sormas.backend.caze.Case) Contact(de.symeda.sormas.backend.contact.Contact) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant)

Example 3 with ApproximateAgeType

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

the class PersonService method toSimilarPersonDto.

private SimilarPersonDto toSimilarPersonDto(Person entity) {
    Integer approximateAge = entity.getApproximateAge();
    ApproximateAgeType approximateAgeType = entity.getApproximateAgeType();
    if (entity.getBirthdateYYYY() != null) {
        DataHelper.Pair<Integer, ApproximateAgeType> pair = ApproximateAgeType.ApproximateAgeHelper.getApproximateAge(entity.getBirthdateYYYY(), entity.getBirthdateMM(), entity.getBirthdateDD(), entity.getDeathDate());
        approximateAge = pair.getElement0();
        approximateAgeType = pair.getElement1();
    }
    SimilarPersonDto similarPersonDto = new SimilarPersonDto();
    similarPersonDto.setUuid(entity.getUuid());
    similarPersonDto.setFirstName(entity.getFirstName());
    similarPersonDto.setLastName(entity.getLastName());
    similarPersonDto.setNickname(entity.getNickname());
    similarPersonDto.setAgeAndBirthDate(PersonHelper.getAgeAndBirthdateString(approximateAge, approximateAgeType, entity.getBirthdateDD(), entity.getBirthdateMM(), entity.getBirthdateYYYY()));
    similarPersonDto.setSex(entity.getSex());
    similarPersonDto.setPresentCondition(entity.getPresentCondition());
    similarPersonDto.setPhone(entity.getPhone());
    similarPersonDto.setDistrictName(entity.getAddress().getDistrict() != null ? entity.getAddress().getDistrict().getName() : null);
    similarPersonDto.setCommunityName(entity.getAddress().getCommunity() != null ? entity.getAddress().getCommunity().getName() : null);
    similarPersonDto.setPostalCode(entity.getAddress().getPostalCode());
    similarPersonDto.setCity(entity.getAddress().getCity());
    similarPersonDto.setStreet(entity.getAddress().getStreet());
    similarPersonDto.setHouseNumber(entity.getAddress().getHouseNumber());
    similarPersonDto.setNationalHealthId(entity.getNationalHealthId());
    similarPersonDto.setPassportNumber(entity.getPassportNumber());
    return similarPersonDto;
}
Also used : ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) DataHelper(de.symeda.sormas.api.utils.DataHelper) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 4 with ApproximateAgeType

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

the class ControlTextReadField method setAgeWithDateValue.

// Age with date
@BindingAdapter(value = { "ageWithDateValue", "valueFormat", "defaultValue", "showDay" }, requireAll = false)
public static void setAgeWithDateValue(ControlTextReadField textField, Person person, String valueFormat, String defaultValue, Boolean showDay) {
    if (valueFormat == null) {
        valueFormat = ResourceUtils.getString(textField.getContext(), R.string.age_with_birth_date_format);
    }
    if (showDay == null) {
        showDay = true;
    }
    if (person == null || person.getApproximateAge() == null) {
        setValue(textField, (String) null, valueFormat, defaultValue);
    } else {
        String age = person.getApproximateAge().toString();
        ApproximateAgeType ageType = person.getApproximateAgeType();
        String dateOfBirth = DateFormatHelper.formatBirthdate(showDay ? person.getBirthdateDD() : null, person.getBirthdateMM(), person.getBirthdateYYYY());
        StringBuilder ageWithDateBuilder = new StringBuilder().append(age).append(" ").append(ageType != null ? ageType.toString() : "").append(" (").append(dateOfBirth).append(")");
        textField.setValue(ageWithDateBuilder.toString());
    }
}
Also used : ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) BindingAdapter(androidx.databinding.BindingAdapter)

Example 5 with ApproximateAgeType

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

the class PersonEditForm method addFields.

@Override
protected void addFields() {
    personInformationHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonInformation));
    personInformationHeadingLabel.addStyleName(H3);
    getContent().addComponent(personInformationHeadingLabel, PERSON_INFORMATION_HEADING_LOC);
    addField(PersonDto.UUID).setReadOnly(true);
    firstNameField = addField(PersonDto.FIRST_NAME, TextField.class);
    lastNameField = addField(PersonDto.LAST_NAME, TextField.class);
    addFields(PersonDto.SALUTATION, PersonDto.OTHER_SALUTATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.OTHER_SALUTATION, PersonDto.SALUTATION, Salutation.OTHER, true);
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.BIRTH_NAME, TextField.class);
    addField(PersonDto.NICKNAME, TextField.class);
    addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
    addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
    addFields(PersonDto.NAMES_OF_GUARDIANS);
    ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
    birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    birthDateDay.setCaption("");
    ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    birthDateMonth.setCaption("");
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, 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()));
    DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
    TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
    approximateAgeField.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, approximateAgeField.getCaption()));
    ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
    addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);
    approximateAgeField.addValidator(new ApproximateAgeValidator(approximateAgeField, approximateAgeTypeField, I18nProperties.getValidationError(Validations.softApproximateAgeTooHigh)));
    TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
    tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfGestationAgeAtBirth.getCaption()));
    TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
    tfBirthWeight.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfBirthWeight.getCaption()));
    AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
    deathPlaceType.setNullSelectionAllowed(true);
    TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
    DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
    TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
    ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
    addField(PersonDto.ADDRESS, LocationEditForm.class).setCaption(null);
    addField(PersonDto.ADDRESSES, LocationsField.class).setCaption(null);
    PersonContactDetailsField personContactDetailsField = new PersonContactDetailsField(getValue(), fieldVisibilityCheckers, fieldAccessCheckers);
    personContactDetailsField.setId(PersonDto.PERSON_CONTACT_DETAILS);
    personContactDetailsField.setPseudonymized(isPseudonymized);
    getFieldGroup().bind(personContactDetailsField, PersonDto.PERSON_CONTACT_DETAILS);
    getContent().addComponent(personContactDetailsField, PersonDto.PERSON_CONTACT_DETAILS);
    addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.ARMED_FORCES_RELATION_TYPE, PersonDto.EDUCATION_TYPE, PersonDto.EDUCATION_DETAILS);
    List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getAllActiveAsReference();
    addInfrastructureField(PersonDto.BIRTH_COUNTRY).addItems(countries);
    addInfrastructureField(PersonDto.CITIZENSHIP).addItems(countries);
    addFields(PersonDto.PASSPORT_NUMBER, PersonDto.NATIONAL_HEALTH_ID);
    Field externalId = addField(PersonDto.EXTERNAL_ID);
    if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        externalId.setEnabled(false);
    }
    TextField externalTokenField = addField(PersonDto.EXTERNAL_TOKEN);
    Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messagePersonExternalTokenWarning));
    externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
    getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
    addField(PersonDto.INTERNAL_TOKEN);
    addField(PersonDto.HAS_COVID_APP).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    addField(PersonDto.COVID_CODE_DELIVERED).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    if (personContext != PersonContext.CASE) {
        setVisible(false, PersonDto.HAS_COVID_APP, PersonDto.COVID_CODE_DELIVERED);
    }
    ComboBox cbPlaceOfBirthRegion = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_REGION);
    ComboBox cbPlaceOfBirthDistrict = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_DISTRICT);
    ComboBox cbPlaceOfBirthCommunity = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_COMMUNITY);
    ComboBox placeOfBirthFacilityType = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_TYPE);
    FieldHelper.removeItems(placeOfBirthFacilityType);
    placeOfBirthFacilityType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
    placeOfBirthFacilityType.addItems(FacilityType.getPlaceOfBirthTypes());
    cbPlaceOfBirthFacility = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_FACILITY);
    TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS, TextField.class);
    causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
    causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
    causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
    // Set requirements that don't need visibility changes and read only status
    setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
    setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
    setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE, PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION, PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS, PersonDto.CAUSE_OF_DEATH_DISEASE);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE, Arrays.asList(EducationType.OTHER), true);
    FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType, causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc, burialConductor);
    // Set initial visibilities
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.ARMED_FORCES_RELATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
        occupationHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESS).isVisible())
        addressHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESSES).isVisible())
        addressesHeader.setVisible(false);
    // Add listeners
    FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE, PersonDto.APPROXIMATE_AGE_TYPE);
    addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
        @SuppressWarnings("unchecked") Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(PersonDto.APPROXIMATE_AGE_TYPE);
        if (!ageTypeField.isReadOnly()) {
            if (e.getProperty().getValue() == null) {
                ageTypeField.clear();
            } else {
                if (ageTypeField.isEmpty()) {
                    ageTypeField.setValue(ApproximateAgeType.YEARS);
                }
            }
        }
    });
    addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
    addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
        updateOccupationFieldCaptions();
        toogleOccupationMetaFields();
    });
    addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity, placeOfBirthFacilityType, cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails, true);
    cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    addFieldListeners(PersonDto.PRESENT_CONDITION, e -> toogleDeathAndBurialFields());
    causeOfDeathField.addValueChangeListener(e -> {
        toggleCauseOfDeathFields(presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
    });
    causeOfDeathDiseaseField.addValueChangeListener(e -> {
        toggleCauseOfDeathFields(presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
    });
    addValueChangeListener(e -> {
        fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc);
    });
    deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(), birthDateYear.getCaption())));
    burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));
    // 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();
    });
    addValueChangeListener((e) -> {
        ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getPersonFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
        personContactDetailsField.setThisPerson((PersonDto) e.getProperty().getValue());
    });
    Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS));
    generalCommentLabel.addStyleName(H3);
    getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
    TextArea additionalDetails = addField(PersonDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>(false));
    additionalDetails.setRows(6);
    additionalDetails.setDescription(I18nProperties.getPrefixDescription(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) ApproximateAgeValidator(de.symeda.sormas.ui.utils.ApproximateAgeValidator)

Aggregations

ApproximateAgeType (de.symeda.sormas.api.person.ApproximateAgeType)10 Date (java.util.Date)4 BindingAdapter (androidx.databinding.BindingAdapter)2 AbstractSelect (com.vaadin.v7.ui.AbstractSelect)2 TextField (com.vaadin.v7.ui.TextField)2 AgeAndBirthDateDto (de.symeda.sormas.api.caze.AgeAndBirthDateDto)2 SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)2 DataHelper (de.symeda.sormas.api.utils.DataHelper)2 Label (com.vaadin.ui.Label)1 ComboBox (com.vaadin.v7.ui.ComboBox)1 DateField (com.vaadin.v7.ui.DateField)1 Field (com.vaadin.v7.ui.Field)1 TextArea (com.vaadin.v7.ui.TextArea)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CaseSelectionDto (de.symeda.sormas.api.caze.CaseSelectionDto)1 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)1 EventParticipantCriteria (de.symeda.sormas.api.event.EventParticipantCriteria)1 ImmunizationIndexDto (de.symeda.sormas.api.immunization.ImmunizationIndexDto)1 CountryReferenceDto (de.symeda.sormas.api.infrastructure.country.CountryReferenceDto)1