Search in sources :

Example 1 with DateComparisonValidator

use of de.symeda.sormas.ui.utils.DateComparisonValidator in project SORMAS-Project by hzi-braunschweig.

the class HospitalizationForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    if (caze == null || viewMode == null) {
        return;
    }
    Label hospitalizationHeadingLabel = new Label(I18nProperties.getString(Strings.headingHospitalization));
    hospitalizationHeadingLabel.addStyleName(H3);
    getContent().addComponent(hospitalizationHeadingLabel, HOSPITALIZATION_HEADING_LOC);
    Label previousHospitalizationsHeadingLabel = new Label(I18nProperties.getString(Strings.headingPreviousHospitalizations));
    previousHospitalizationsHeadingLabel.addStyleName(H3);
    getContent().addComponent(previousHospitalizationsHeadingLabel, PREVIOUS_HOSPITALIZATIONS_HEADING_LOC);
    TextField facilityField = addCustomField(HEALTH_FACILITY, FacilityReferenceDto.class, TextField.class);
    FacilityReferenceDto healthFacility = caze.getHealthFacility();
    final boolean noneFacility = healthFacility == null || healthFacility.getUuid().equalsIgnoreCase(FacilityDto.NONE_FACILITY_UUID);
    facilityField.setValue(noneFacility || !FacilityType.HOSPITAL.equals(caze.getFacilityType()) ? null : healthFacility.toString());
    facilityField.setReadOnly(true);
    final NullableOptionGroup admittedToHealthFacilityField = addField(HospitalizationDto.ADMITTED_TO_HEALTH_FACILITY, NullableOptionGroup.class);
    final DateField admissionDateField = addField(HospitalizationDto.ADMISSION_DATE, DateField.class);
    final DateField dischargeDateField = addDateField(HospitalizationDto.DISCHARGE_DATE, DateField.class, 7);
    intensiveCareUnit = addField(HospitalizationDto.INTENSIVE_CARE_UNIT, NullableOptionGroup.class);
    intensiveCareUnitStart = addField(HospitalizationDto.INTENSIVE_CARE_UNIT_START, DateField.class);
    intensiveCareUnitStart.setVisible(false);
    intensiveCareUnitEnd = addField(HospitalizationDto.INTENSIVE_CARE_UNIT_END, DateField.class);
    intensiveCareUnitEnd.setVisible(false);
    FieldHelper.setVisibleWhen(intensiveCareUnit, Arrays.asList(intensiveCareUnitStart, intensiveCareUnitEnd), Arrays.asList(YesNoUnknown.YES), true);
    final Field isolationDateField = addField(HospitalizationDto.ISOLATION_DATE);
    final TextArea descriptionField = addField(HospitalizationDto.DESCRIPTION, TextArea.class);
    descriptionField.setRows(4);
    final NullableOptionGroup isolatedField = addField(HospitalizationDto.ISOLATED, NullableOptionGroup.class);
    final NullableOptionGroup leftAgainstAdviceField = addField(HospitalizationDto.LEFT_AGAINST_ADVICE, NullableOptionGroup.class);
    final ComboBox hospitalizationReason = addField(HospitalizationDto.HOSPITALIZATION_REASON);
    final TextField otherHospitalizationReason = addField(HospitalizationDto.OTHER_HOSPITALIZATION_REASON, TextField.class);
    NullableOptionGroup hospitalizedPreviouslyField = addField(HospitalizationDto.HOSPITALIZED_PREVIOUSLY, NullableOptionGroup.class);
    CssStyles.style(hospitalizedPreviouslyField, CssStyles.ERROR_COLOR_PRIMARY);
    PreviousHospitalizationsField previousHospitalizationsField = addField(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, PreviousHospitalizationsField.class);
    FieldHelper.setEnabledWhen(admittedToHealthFacilityField, Arrays.asList(YesNoUnknown.YES, YesNoUnknown.NO, YesNoUnknown.UNKNOWN), Arrays.asList(facilityField, admissionDateField, dischargeDateField, intensiveCareUnit, intensiveCareUnitStart, intensiveCareUnitEnd, isolationDateField, descriptionField, isolatedField, leftAgainstAdviceField, hospitalizationReason, otherHospitalizationReason), false);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (isVisibleAllowed(HospitalizationDto.ISOLATION_DATE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.ISOLATION_DATE, HospitalizationDto.ISOLATED, Arrays.asList(YesNoUnknown.YES), true);
    }
    if (isVisibleAllowed(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, HospitalizationDto.HOSPITALIZED_PREVIOUSLY, Arrays.asList(YesNoUnknown.YES), true);
    }
    FieldHelper.setVisibleWhen(getFieldGroup(), HospitalizationDto.OTHER_HOSPITALIZATION_REASON, HospitalizationDto.HOSPITALIZATION_REASON, Collections.singletonList(HospitalizationReasonType.OTHER), true);
    // Validations
    // Add a visual-only validator to check if symptomonsetdate<admissiondate, as saving should be possible either way
    admissionDateField.addValueChangeListener(event -> {
        if (caze.getSymptoms().getOnsetDate() != null && DateTimeComparator.getDateOnlyInstance().compare(admissionDateField.getValue(), caze.getSymptoms().getOnsetDate()) < 0) {
            admissionDateField.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getValidationError(Validations.afterDateSoft, admissionDateField.getCaption(), I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
                }
            });
        } else {
            // remove all invalidity-indicators and re-evaluate field
            admissionDateField.setComponentError(null);
            admissionDateField.markAsDirty();
        }
        // re-evaluate validity of dischargeDate (necessary because discharge has to be after admission)
        dischargeDateField.markAsDirty();
    });
    admissionDateField.addValidator(new DateComparisonValidator(admissionDateField, dischargeDateField, true, false, I18nProperties.getValidationError(Validations.beforeDate, admissionDateField.getCaption(), dischargeDateField.getCaption())));
    dischargeDateField.addValidator(new DateComparisonValidator(dischargeDateField, admissionDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, dischargeDateField.getCaption(), admissionDateField.getCaption())));
    // re-evaluate admission date for consistent validation of all fields
    dischargeDateField.addValueChangeListener(event -> admissionDateField.markAsDirty());
    intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, admissionDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitStart.getCaption(), admissionDateField.getCaption())));
    intensiveCareUnitStart.addValidator(new DateComparisonValidator(intensiveCareUnitStart, intensiveCareUnitEnd, true, false, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitStart.getCaption(), intensiveCareUnitEnd.getCaption())));
    intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, intensiveCareUnitStart, false, false, I18nProperties.getValidationError(Validations.afterDate, intensiveCareUnitEnd.getCaption(), intensiveCareUnitStart.getCaption())));
    intensiveCareUnitEnd.addValidator(new DateComparisonValidator(intensiveCareUnitEnd, dischargeDateField, true, false, I18nProperties.getValidationError(Validations.beforeDate, intensiveCareUnitEnd.getCaption(), dischargeDateField.getCaption())));
    intensiveCareUnitStart.addValueChangeListener(event -> intensiveCareUnitEnd.markAsDirty());
    intensiveCareUnitEnd.addValueChangeListener(event -> intensiveCareUnitStart.markAsDirty());
    hospitalizedPreviouslyField.addValueChangeListener(e -> updatePrevHospHint(hospitalizedPreviouslyField, previousHospitalizationsField));
    previousHospitalizationsField.addValueChangeListener(e -> updatePrevHospHint(hospitalizedPreviouslyField, previousHospitalizationsField));
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) DateField(com.vaadin.v7.ui.DateField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) TextField(com.vaadin.v7.ui.TextField) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) DateField(com.vaadin.v7.ui.DateField) ErrorMessage(com.vaadin.server.ErrorMessage)

Example 2 with DateComparisonValidator

use of de.symeda.sormas.ui.utils.DateComparisonValidator in project SORMAS-Project by hzi-braunschweig.

the class PortHealthInfoForm method addAirportFields.

private void addAirportFields() {
    addFields(PortHealthInfoDto.AIRLINE_NAME, PortHealthInfoDto.FLIGHT_NUMBER, PortHealthInfoDto.DEPARTURE_AIRPORT, PortHealthInfoDto.SEAT_NUMBER, PortHealthInfoDto.TRANSIT_STOP_DETAILS_1, PortHealthInfoDto.TRANSIT_STOP_DETAILS_2, PortHealthInfoDto.TRANSIT_STOP_DETAILS_3, PortHealthInfoDto.TRANSIT_STOP_DETAILS_4, PortHealthInfoDto.TRANSIT_STOP_DETAILS_5);
    DateTimeField dfDepartureDateTime = addField(PortHealthInfoDto.DEPARTURE_DATE_TIME, DateTimeField.class);
    DateTimeField dfArrivalDateTime = addField(PortHealthInfoDto.ARRIVAL_DATE_TIME, DateTimeField.class);
    addField(PortHealthInfoDto.FREE_SEATING, NullableOptionGroup.class);
    ComboBox cbNumberOfTransitStops = addField(PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, ComboBox.class);
    cbNumberOfTransitStops.addItems(DataHelper.buildIntegerList(0, 5));
    // Visibility
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_1, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(1, 2, 3, 4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_2, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(2, 3, 4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_3, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(3, 4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_4, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(4, 5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.TRANSIT_STOP_DETAILS_5, PortHealthInfoDto.NUMBER_OF_TRANSIT_STOPS, Arrays.asList(5), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PortHealthInfoDto.SEAT_NUMBER, PortHealthInfoDto.FREE_SEATING, Arrays.asList(YesNoUnknown.NO), true);
    // Validations
    dfDepartureDateTime.addValidator(new DateComparisonValidator(dfDepartureDateTime, dfArrivalDateTime, true, false, I18nProperties.getValidationError(Validations.beforeDate, dfDepartureDateTime.getCaption(), dfArrivalDateTime.getCaption())));
    dfArrivalDateTime.addValidator(new DateComparisonValidator(dfArrivalDateTime, dfDepartureDateTime, false, false, I18nProperties.getValidationError(Validations.afterDate, dfArrivalDateTime.getCaption(), dfDepartureDateTime.getCaption())));
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Example 3 with DateComparisonValidator

use of de.symeda.sormas.ui.utils.DateComparisonValidator in project SORMAS-Project by hzi-braunschweig.

the class SampleController method addPathogenTestComponent.

/**
 * @param sampleComponent
 *            to add the pathogen test create component to.
 * @param pathogenTest
 *            the preset values to insert. May be null.
 * @param caseSampleCount
 *            describes how many samples already exist for a case related to the pathogen test's sample (if a case exists, otherwise 0
 *            is valid).
 * @param callback
 *            use it to define additional actions that need to be taken after the pathogen test is saved (e.g. refresh the UI)
 * @return the pathogen test create component added.
 */
public PathogenTestForm addPathogenTestComponent(CommitDiscardWrapperComponent<? extends AbstractSampleForm> sampleComponent, PathogenTestDto pathogenTest, int caseSampleCount, Runnable callback) {
    // add horizontal rule to clearly distinguish the component
    Label horizontalRule = new Label("<br><hr /><br>", ContentMode.HTML);
    horizontalRule.setWidth(100f, Unit.PERCENTAGE);
    sampleComponent.addComponent(horizontalRule, sampleComponent.getComponentCount() - 1);
    PathogenTestForm pathogenTestForm = new PathogenTestForm(sampleComponent.getWrappedComponent().getValue(), true, caseSampleCount, false);
    // prefill fields
    if (pathogenTest != null) {
        pathogenTestForm.setValue(pathogenTest);
        // show typingId field when it has a preset value
        if (pathogenTest.getTypingId() != null && !"".equals(pathogenTest.getTypingId())) {
            pathogenTestForm.getField(PathogenTestDto.TYPING_ID).setVisible(true);
        }
    } else {
        pathogenTestForm.setValue(PathogenTestDto.build(sampleComponent.getWrappedComponent().getValue(), UserProvider.getCurrent().getUser()));
        // remove value invalid for newly created pathogen tests
        ComboBox pathogenTestResultField = pathogenTestForm.getField(PathogenTestDto.TEST_RESULT);
        pathogenTestResultField.removeItem(PathogenTestResultType.NOT_DONE);
        pathogenTestResultField.setValue(PathogenTestResultType.PENDING);
        ComboBox testDiseaseField = pathogenTestForm.getField(PathogenTestDto.TESTED_DISEASE);
        testDiseaseField.setValue(FacadeProvider.getDiseaseConfigurationFacade().getDefaultDisease());
    }
    // setup field updates
    Field testLabField = pathogenTestForm.getField(PathogenTestDto.LAB);
    NullableOptionGroup samplePurposeField = sampleComponent.getWrappedComponent().getField(SampleDto.SAMPLE_PURPOSE);
    Runnable updateTestLabFieldRequired = () -> testLabField.setRequired(!SamplePurpose.INTERNAL.equals(samplePurposeField.getValue()));
    updateTestLabFieldRequired.run();
    samplePurposeField.addValueChangeListener(e -> updateTestLabFieldRequired.run());
    // validate pathogen test create component before saving the sample
    sampleComponent.addFieldGroups(pathogenTestForm.getFieldGroup());
    CommitDiscardWrapperComponent.CommitListener savePathogenTest = () -> {
        ControllerProvider.getPathogenTestController().savePathogenTest(pathogenTestForm.getValue(), null, true, true);
        if (callback != null) {
            callback.run();
        }
    };
    sampleComponent.addCommitListener(savePathogenTest);
    // Discard button configuration
    Button discardButton = ButtonHelper.createButton(I18nProperties.getCaption(Captions.pathogenTestRemove));
    VerticalLayout buttonLayout = new VerticalLayout(discardButton);
    buttonLayout.setComponentAlignment(discardButton, Alignment.TOP_LEFT);
    // add the discard button above the overall discard and commit buttons
    sampleComponent.addComponent(buttonLayout, sampleComponent.getComponentCount() - 1);
    discardButton.addClickListener(o -> {
        sampleComponent.removeComponent(horizontalRule);
        sampleComponent.removeComponent(buttonLayout);
        sampleComponent.removeComponent(pathogenTestForm);
        sampleComponent.removeFieldGroups(pathogenTestForm.getFieldGroup());
        sampleComponent.removeCommitListener(savePathogenTest);
        pathogenTestForm.discard();
    });
    // Country specific configuration
    boolean germanInstance = FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY);
    pathogenTestForm.getField(PathogenTestDto.REPORT_DATE).setVisible(germanInstance);
    pathogenTestForm.getField(PathogenTestDto.EXTERNAL_ID).setVisible(germanInstance);
    pathogenTestForm.getField(PathogenTestDto.EXTERNAL_ORDER_ID).setVisible(germanInstance);
    pathogenTestForm.getField(PathogenTestDto.VIA_LIMS).setVisible(germanInstance);
    // Sample creation specific configuration
    final DateTimeField sampleDateField = sampleComponent.getWrappedComponent().getField(SampleDto.SAMPLE_DATE_TIME);
    final DateTimeField testDateField = pathogenTestForm.getField(PathogenTestDto.TEST_DATE_TIME);
    testDateField.addValidator(new DateComparisonValidator(testDateField, sampleDateField, false, false, I18nProperties.getValidationError(Validations.afterDate, testDateField.getCaption(), sampleDateField.getCaption())));
    // add the pathogenTestForm above the overall discard and commit buttons
    sampleComponent.addComponent(pathogenTestForm, sampleComponent.getComponentCount() - 1);
    return pathogenTestForm;
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) Field(com.vaadin.v7.ui.Field) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 4 with DateComparisonValidator

use of de.symeda.sormas.ui.utils.DateComparisonValidator 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)

Example 5 with DateComparisonValidator

use of de.symeda.sormas.ui.utils.DateComparisonValidator in project SORMAS-Project by hzi-braunschweig.

the class AdditionalTestForm method addFields.

@Override
protected void addFields() {
    if (sample == null) {
        return;
    }
    Label bloodGasHeadingLabel = new Label(I18nProperties.getPrefixCaption(AdditionalTestDto.I18N_PREFIX, AdditionalTestDto.ARTERIAL_VENOUS_BLOOD_GAS));
    bloodGasHeadingLabel.addStyleName(H4);
    getContent().addComponent(bloodGasHeadingLabel, BLOOD_GAS_HEADING_LOC);
    DateTimeField testDateTimeField = addField(AdditionalTestDto.TEST_DATE_TIME, DateTimeField.class);
    testDateTimeField.setRequired(true);
    testDateTimeField.addValidator(new DateComparisonValidator(testDateTimeField, sample.getSampleDateTime(), false, false, I18nProperties.getValidationError(Validations.afterDate, testDateTimeField.getCaption(), I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, SampleDto.SAMPLE_DATE_TIME))));
    addField(AdditionalTestDto.HAEMOGLOBINURIA, ComboBox.class);
    addField(AdditionalTestDto.PROTEINURIA, ComboBox.class);
    addField(AdditionalTestDto.HEMATURIA, ComboBox.class);
    TextField bloodGasPHField = addField(AdditionalTestDto.ARTERIAL_VENOUS_GAS_PH, TextField.class);
    bloodGasPHField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, bloodGasPHField.getCaption()));
    TextField bloodGasPco2Field = addField(AdditionalTestDto.ARTERIAL_VENOUS_GAS_PCO2, TextField.class);
    bloodGasPco2Field.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, bloodGasPco2Field.getCaption()));
    TextField bloodGasPao2Field = addField(AdditionalTestDto.ARTERIAL_VENOUS_GAS_PAO2, TextField.class);
    bloodGasPao2Field.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, bloodGasPao2Field.getCaption()));
    TextField bloodGasHco3Field = addField(AdditionalTestDto.ARTERIAL_VENOUS_GAS_HCO3, TextField.class);
    bloodGasHco3Field.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, bloodGasHco3Field.getCaption()));
    TextField gasOxygenTherapyField = addField(AdditionalTestDto.GAS_OXYGEN_THERAPY, TextField.class);
    gasOxygenTherapyField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, gasOxygenTherapyField.getCaption()));
    TextField altSgptField = addField(AdditionalTestDto.ALT_SGPT, TextField.class);
    altSgptField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, altSgptField.getCaption()));
    TextField astSgotField = addField(AdditionalTestDto.AST_SGOT, TextField.class);
    astSgotField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, astSgotField.getCaption()));
    TextField creatinineField = addField(AdditionalTestDto.CREATININE, TextField.class);
    creatinineField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, creatinineField.getCaption()));
    TextField potassiumField = addField(AdditionalTestDto.POTASSIUM, TextField.class);
    potassiumField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, potassiumField.getCaption()));
    TextField ureaField = addField(AdditionalTestDto.UREA, TextField.class);
    ureaField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, ureaField.getCaption()));
    TextField haemoglobinField = addField(AdditionalTestDto.HAEMOGLOBIN, TextField.class);
    haemoglobinField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, haemoglobinField.getCaption()));
    TextField totalBilirubinField = addField(AdditionalTestDto.TOTAL_BILIRUBIN, TextField.class);
    totalBilirubinField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, totalBilirubinField.getCaption()));
    TextField conjBilirubinField = addField(AdditionalTestDto.CONJ_BILIRUBIN, TextField.class);
    conjBilirubinField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, conjBilirubinField.getCaption()));
    TextField wbcCountField = addField(AdditionalTestDto.WBC_COUNT, TextField.class);
    wbcCountField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, wbcCountField.getCaption()));
    TextField plateletsField = addField(AdditionalTestDto.PLATELETS, TextField.class);
    plateletsField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, plateletsField.getCaption()));
    TextField prothrombinTimeField = addField(AdditionalTestDto.PROTHROMBIN_TIME, TextField.class);
    prothrombinTimeField.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed, prothrombinTimeField.getCaption()));
    addField(AdditionalTestDto.OTHER_TEST_RESULTS, TextArea.class).setRows(6);
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) Label(com.vaadin.ui.Label) TextField(com.vaadin.v7.ui.TextField) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Aggregations

DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)19 ComboBox (com.vaadin.v7.ui.ComboBox)13 Label (com.vaadin.ui.Label)12 TextArea (com.vaadin.v7.ui.TextArea)12 DateField (com.vaadin.v7.ui.DateField)11 TextField (com.vaadin.v7.ui.TextField)11 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)10 Field (com.vaadin.v7.ui.Field)8 DateTimeField (de.symeda.sormas.ui.utils.DateTimeField)8 CheckBox (com.vaadin.v7.ui.CheckBox)6 Disease (de.symeda.sormas.api.Disease)6 FacadeProvider (de.symeda.sormas.api.FacadeProvider)6 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)6 Validations (de.symeda.sormas.api.i18n.Validations)6 Strings (de.symeda.sormas.api.i18n.Strings)5 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)5 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)5 UiFieldAccessCheckers (de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers)5 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)5 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)5