Search in sources :

Example 11 with DateField

use of com.vaadin.v7.ui.DateField in project SORMAS-Project by hzi-braunschweig.

the class SymptomsForm method addFields.

@Override
protected void addFields() {
    if (disease == null || symptomsContext == null) {
        // workaround to stop initialization until disease is set
        return;
    }
    // Add fields
    Label clinicalMeasurementsHeadingLabel = createLabel(I18nProperties.getString(Strings.headingClinicalMeasurements), H3, CLINICAL_MEASUREMENTS_HEADING_LOC);
    Label signsAndSymptomsHeadingLabel = createLabel(I18nProperties.getString(Strings.headingSignsAndSymptoms), H3, SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label generalSymptomsHeadingLabel = createLabel(SymptomGroup.GENERAL.toString(), H4, GENERAL_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label respiratorySymptomsHeadingLabel = createLabel(SymptomGroup.RESPIRATORY.toString(), H4, RESPIRATORY_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label cardiovascularSymptomsHeadingLabel = createLabel(SymptomGroup.CARDIOVASCULAR.toString(), H4, CARDIOVASCULAR_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label gastrointestinalSymptomsHeadingLabel = createLabel(SymptomGroup.GASTROINTESTINAL.toString(), H4, GASTROINTESTINAL_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label urinarySymptomsHeadingLabel = createLabel(SymptomGroup.URINARY.toString(), H4, URINARY_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label nervousSystemSymptomsHeadingLabel = createLabel(SymptomGroup.NERVOUS_SYSTEM.toString(), H4, NERVOUS_SYSTEM_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label skinSymptomsHeadingLabel = createLabel(SymptomGroup.SKIN.toString(), H4, SKIN_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    final Label otherSymptomsHeadingLabel = createLabel(SymptomGroup.OTHER.toString(), H4, OTHER_SIGNS_AND_SYMPTOMS_HEADING_LOC);
    DateField onsetDateField = addField(ONSET_DATE, DateField.class);
    ComboBox onsetSymptom = addField(ONSET_SYMPTOM, ComboBox.class);
    if (symptomsContext == SymptomsContext.CASE) {
        // If the symptom onset date is after the hospital admission date, show a warning but don't prevent the user from saving
        onsetDateField.addValueChangeListener(event -> {
            if (caze.getHospitalization().getAdmissionDate() != null && DateTimeComparator.getDateOnlyInstance().compare(caze.getHospitalization().getAdmissionDate(), onsetDateField.getValue()) < 0) {
                onsetDateField.setComponentError(new ErrorMessage() {

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

                    @Override
                    public String getFormattedHtmlMessage() {
                        return I18nProperties.getValidationError(Validations.beforeDateSoft, onsetDateField.getCaption(), I18nProperties.getPrefixCaption(HospitalizationDto.I18N_PREFIX, HospitalizationDto.ADMISSION_DATE));
                    }
                });
            } else if (onsetDateField.isValid()) {
                onsetDateField.setComponentError(null);
            }
        });
    }
    ComboBox temperature = addField(TEMPERATURE, ComboBox.class);
    temperature.setImmediate(true);
    for (Float temperatureValue : SymptomsHelper.getTemperatureValues()) {
        temperature.addItem(temperatureValue);
        temperature.setItemCaption(temperatureValue, SymptomsHelper.getTemperatureString(temperatureValue));
    }
    if (symptomsContext == SymptomsContext.CASE) {
        temperature.setCaption(I18nProperties.getCaption(Captions.symptomsMaxTemperature));
    }
    addField(TEMPERATURE_SOURCE);
    ComboBox bloodPressureSystolic = addField(BLOOD_PRESSURE_SYSTOLIC, ComboBox.class);
    bloodPressureSystolic.addItems(SymptomsHelper.getBloodPressureValues());
    ComboBox bloodPressureDiastolic = addField(BLOOD_PRESSURE_DIASTOLIC, ComboBox.class);
    bloodPressureDiastolic.addItems(SymptomsHelper.getBloodPressureValues());
    ComboBox heartRate = addField(HEART_RATE, ComboBox.class);
    heartRate.addItems(SymptomsHelper.getHeartRateValues());
    ComboBox respiratoryRate = addField(RESPIRATORY_RATE, ComboBox.class);
    respiratoryRate.addItems(SymptomsHelper.getRespiratoryRateValues());
    ComboBox weight = addField(WEIGHT, ComboBox.class);
    for (Integer weightValue : SymptomsHelper.getWeightValues()) {
        weight.addItem(weightValue);
        weight.setItemCaption(weightValue, SymptomsHelper.getDecimalString(weightValue));
    }
    ComboBox height = addField(HEIGHT, ComboBox.class);
    height.addItems(SymptomsHelper.getHeightValues());
    ComboBox midUpperArmCircumference = addField(MID_UPPER_ARM_CIRCUMFERENCE, ComboBox.class);
    for (Integer circumferenceValue : SymptomsHelper.getMidUpperArmCircumferenceValues()) {
        midUpperArmCircumference.addItem(circumferenceValue);
        midUpperArmCircumference.setItemCaption(circumferenceValue, SymptomsHelper.getDecimalString(circumferenceValue));
    }
    ComboBox glasgowComaScale = addField(GLASGOW_COMA_SCALE, ComboBox.class);
    glasgowComaScale.addItems(SymptomsHelper.getGlasgowComaScaleValues());
    addFields(VOMITING, DIARRHEA, BLOOD_IN_STOOL, NAUSEA, ABDOMINAL_PAIN, HEADACHE, MUSCLE_PAIN, FATIGUE_WEAKNESS, SKIN_RASH, NECK_STIFFNESS, SORE_THROAT, COUGH, COUGH_WITH_SPUTUM, COUGH_WITH_HEAMOPTYSIS, RUNNY_NOSE, DIFFICULTY_BREATHING, CHEST_PAIN, CONJUNCTIVITIS, EYE_PAIN_LIGHT_SENSITIVE, KOPLIKS_SPOTS, THROBOCYTOPENIA, OTITIS_MEDIA, HEARINGLOSS, DEHYDRATION, ANOREXIA_APPETITE_LOSS, REFUSAL_FEEDOR_DRINK, JOINT_PAIN, HICCUPS, BACKACHE, EYES_BLEEDING, JAUNDICE, DARK_URINE, STOMACH_BLEEDING, RAPID_BREATHING, SWOLLEN_GLANDS, UNEXPLAINED_BLEEDING, GUMS_BLEEDING, INJECTION_SITE_BLEEDING, NOSE_BLEEDING, BLOODY_BLACK_STOOL, RED_BLOOD_VOMIT, DIGESTED_BLOOD_VOMIT, COUGHING_BLOOD, BLEEDING_VAGINA, SKIN_BRUISING, BLOOD_URINE, OTHER_HEMORRHAGIC_SYMPTOMS, OTHER_HEMORRHAGIC_SYMPTOMS_TEXT, OTHER_NON_HEMORRHAGIC_SYMPTOMS, OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT, LESIONS, LESIONS_THAT_ITCH, LESIONS_SAME_STATE, LESIONS_SAME_SIZE, LESIONS_DEEP_PROFOUND, LESIONS_FACE, LESIONS_LEGS, LESIONS_SOLES_FEET, LESIONS_PALMS_HANDS, LESIONS_THORAX, LESIONS_ARMS, LESIONS_GENITALS, LESIONS_ALL_OVER_BODY, LYMPHADENOPATHY, LYMPHADENOPATHY_AXILLARY, LYMPHADENOPATHY_CERVICAL, LYMPHADENOPATHY_INGUINAL, CHILLS_SWEATS, BEDRIDDEN, ORAL_ULCERS, PAINFUL_LYMPHADENITIS, BLACKENING_DEATH_OF_TISSUE, BUBOES_GROIN_ARMPIT_NECK, BULGING_FONTANELLE, PHARYNGEAL_ERYTHEMA, PHARYNGEAL_EXUDATE, OEDEMA_FACE_NECK, OEDEMA_LOWER_EXTREMITY, LOSS_SKIN_TURGOR, PALPABLE_LIVER, PALPABLE_SPLEEN, MALAISE, SUNKEN_EYES_FONTANELLE, SIDE_PAIN, FLUID_IN_LUNG_CAVITY, TREMOR, BILATERAL_CATARACTS, UNILATERAL_CATARACTS, CONGENITAL_GLAUCOMA, CONGENITAL_HEART_DISEASE, PIGMENTARY_RETINOPATHY, RADIOLUCENT_BONE_DISEASE, SPLENOMEGALY, MICROCEPHALY, MENINGOENCEPHALITIS, PURPURIC_RASH, DEVELOPMENTAL_DELAY, CONGENITAL_HEART_DISEASE_TYPE, CONGENITAL_HEART_DISEASE_DETAILS, JAUNDICE_WITHIN_24_HOURS_OF_BIRTH, PATIENT_ILL_LOCATION, HYDROPHOBIA, OPISTHOTONUS, ANXIETY_STATES, DELIRIUM, UPROARIOUSNESS, PARASTHESIA_AROUND_WOUND, EXCESS_SALIVATION, INSOMNIA, PARALYSIS, EXCITATION, DYSPHAGIA, AEROPHOBIA, HYPERACTIVITY, PARESIS, AGITATION, ASCENDING_FLACCID_PARALYSIS, ERRATIC_BEHAVIOUR, COMA, CONVULSION, FLUID_IN_LUNG_CAVITY_AUSCULTATION, FLUID_IN_LUNG_CAVITY_XRAY, ABNORMAL_LUNG_XRAY_FINDINGS, CONJUNCTIVAL_INJECTION, ACUTE_RESPIRATORY_DISTRESS_SYNDROME, PNEUMONIA_CLINICAL_OR_RADIOLOGIC, LOSS_OF_TASTE, LOSS_OF_SMELL, WHEEZING, SKIN_ULCERS, INABILITY_TO_WALK, IN_DRAWING_OF_CHEST_WALL, FEELING_ILL, SHIVERING, RESPIRATORY_DISEASE_VENTILATION, FAST_HEART_RATE, OXYGEN_SATURATION_LOWER_94, FEVERISHFEELING, WEAKNESS, FATIGUE, COUGH_WITHOUT_SPUTUM, BREATHLESSNESS, CHEST_PRESSURE, BLUE_LIPS, BLOOD_CIRCULATION_PROBLEMS, PALPITATIONS, DIZZINESS_STANDING_UP, HIGH_OR_LOW_BLOOD_PRESSURE, URINARY_RETENTION, FEVER);
    addField(SYMPTOMS_COMMENTS, TextField.class).setDescription(I18nProperties.getPrefixDescription(I18N_PREFIX, SYMPTOMS_COMMENTS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    addField(LESIONS_ONSET_DATE, DateField.class);
    // complications
    addFields(ALTERED_CONSCIOUSNESS, CONFUSED_DISORIENTED, OTHER_COMPLICATIONS, OTHER_COMPLICATIONS_TEXT, HEMORRHAGIC_SYNDROME, HYPERGLYCEMIA, HYPOGLYCEMIA, MENINGEAL_SIGNS, SEIZURES, SEPSIS, SHOCK);
    monkeypoxImageFieldIds = Arrays.asList(LESIONS_RESEMBLE_IMG1, LESIONS_RESEMBLE_IMG2, LESIONS_RESEMBLE_IMG3, LESIONS_RESEMBLE_IMG4);
    for (String propertyId : monkeypoxImageFieldIds) {
        @SuppressWarnings("rawtypes") Field monkeypoxImageField = addField(propertyId);
        CssStyles.style(monkeypoxImageField, VSPACE_NONE);
    }
    // Set initial visibilities
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (symptomsContext != SymptomsContext.CLINICAL_VISIT) {
        setVisible(false, BLOOD_PRESSURE_SYSTOLIC, BLOOD_PRESSURE_DIASTOLIC, HEART_RATE, RESPIRATORY_RATE, WEIGHT, HEIGHT, MID_UPPER_ARM_CIRCUMFERENCE, GLASGOW_COMA_SCALE);
    } else {
        setVisible(false, ONSET_SYMPTOM, ONSET_DATE);
    }
    // Initialize lists
    conditionalBleedingSymptomFieldIds = Arrays.asList(GUMS_BLEEDING, INJECTION_SITE_BLEEDING, NOSE_BLEEDING, BLOODY_BLACK_STOOL, RED_BLOOD_VOMIT, DIGESTED_BLOOD_VOMIT, EYES_BLEEDING, COUGHING_BLOOD, BLEEDING_VAGINA, SKIN_BRUISING, STOMACH_BLEEDING, BLOOD_URINE, OTHER_HEMORRHAGIC_SYMPTOMS);
    lesionsFieldIds = Arrays.asList(LESIONS_SAME_STATE, LESIONS_SAME_SIZE, LESIONS_DEEP_PROFOUND, LESIONS_THAT_ITCH);
    lesionsLocationFieldIds = Arrays.asList(LESIONS_FACE, LESIONS_LEGS, LESIONS_SOLES_FEET, LESIONS_PALMS_HANDS, LESIONS_THORAX, LESIONS_ARMS, LESIONS_GENITALS, LESIONS_ALL_OVER_BODY);
    unconditionalSymptomFieldIds = Arrays.asList(FEVER, ABNORMAL_LUNG_XRAY_FINDINGS, CONJUNCTIVAL_INJECTION, ACUTE_RESPIRATORY_DISTRESS_SYNDROME, PNEUMONIA_CLINICAL_OR_RADIOLOGIC, VOMITING, DIARRHEA, BLOOD_IN_STOOL, NAUSEA, ABDOMINAL_PAIN, HEADACHE, MUSCLE_PAIN, FATIGUE_WEAKNESS, SKIN_RASH, NECK_STIFFNESS, SORE_THROAT, COUGH, COUGH_WITH_SPUTUM, COUGH_WITH_HEAMOPTYSIS, RUNNY_NOSE, DIFFICULTY_BREATHING, CHEST_PAIN, CONJUNCTIVITIS, EYE_PAIN_LIGHT_SENSITIVE, KOPLIKS_SPOTS, THROBOCYTOPENIA, OTITIS_MEDIA, HEARINGLOSS, DEHYDRATION, ANOREXIA_APPETITE_LOSS, REFUSAL_FEEDOR_DRINK, JOINT_PAIN, HICCUPS, BACKACHE, JAUNDICE, DARK_URINE, RAPID_BREATHING, SWOLLEN_GLANDS, UNEXPLAINED_BLEEDING, OTHER_NON_HEMORRHAGIC_SYMPTOMS, LESIONS, LYMPHADENOPATHY, LYMPHADENOPATHY_AXILLARY, LYMPHADENOPATHY_CERVICAL, LYMPHADENOPATHY_INGUINAL, CHILLS_SWEATS, BEDRIDDEN, ORAL_ULCERS, PAINFUL_LYMPHADENITIS, BLACKENING_DEATH_OF_TISSUE, BUBOES_GROIN_ARMPIT_NECK, BULGING_FONTANELLE, PHARYNGEAL_ERYTHEMA, PHARYNGEAL_EXUDATE, OEDEMA_FACE_NECK, OEDEMA_LOWER_EXTREMITY, LOSS_SKIN_TURGOR, PALPABLE_LIVER, PALPABLE_SPLEEN, MALAISE, SUNKEN_EYES_FONTANELLE, SIDE_PAIN, FLUID_IN_LUNG_CAVITY, FLUID_IN_LUNG_CAVITY_AUSCULTATION, FLUID_IN_LUNG_CAVITY_XRAY, TREMOR, BILATERAL_CATARACTS, UNILATERAL_CATARACTS, CONGENITAL_GLAUCOMA, CONGENITAL_HEART_DISEASE, RADIOLUCENT_BONE_DISEASE, SPLENOMEGALY, MICROCEPHALY, MENINGOENCEPHALITIS, DEVELOPMENTAL_DELAY, PURPURIC_RASH, PIGMENTARY_RETINOPATHY, CONVULSION, AEROPHOBIA, AGITATION, ANXIETY_STATES, ASCENDING_FLACCID_PARALYSIS, COMA, DELIRIUM, DYSPHAGIA, ERRATIC_BEHAVIOUR, EXCESS_SALIVATION, EXCITATION, HYDROPHOBIA, HYPERACTIVITY, INSOMNIA, OPISTHOTONUS, PARALYSIS, PARASTHESIA_AROUND_WOUND, PARESIS, UPROARIOUSNESS, LOSS_OF_TASTE, LOSS_OF_SMELL, WHEEZING, SKIN_ULCERS, INABILITY_TO_WALK, IN_DRAWING_OF_CHEST_WALL, OTHER_COMPLICATIONS, FEELING_ILL, SHIVERING, RESPIRATORY_DISEASE_VENTILATION, FAST_HEART_RATE, OXYGEN_SATURATION_LOWER_94, FEVERISHFEELING, WEAKNESS, FATIGUE, COUGH_WITHOUT_SPUTUM, BREATHLESSNESS, CHEST_PRESSURE, BLUE_LIPS, BLOOD_CIRCULATION_PROBLEMS, PALPITATIONS, DIZZINESS_STANDING_UP, HIGH_OR_LOW_BLOOD_PRESSURE, URINARY_RETENTION, // complications
    ALTERED_CONSCIOUSNESS, CONFUSED_DISORIENTED, HEMORRHAGIC_SYNDROME, HYPERGLYCEMIA, HYPOGLYCEMIA, MENINGEAL_SIGNS, SEIZURES, SEPSIS, SHOCK);
    // Set visibilities
    NullableOptionGroup feverField = (NullableOptionGroup) getFieldGroup().getField(FEVER);
    feverField.setImmediate(true);
    FieldHelper.setVisibleWhen(getFieldGroup(), conditionalBleedingSymptomFieldIds, UNEXPLAINED_BLEEDING, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), OTHER_HEMORRHAGIC_SYMPTOMS_TEXT, OTHER_HEMORRHAGIC_SYMPTOMS, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT, OTHER_NON_HEMORRHAGIC_SYMPTOMS, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), OTHER_COMPLICATIONS_TEXT, OTHER_COMPLICATIONS, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), lesionsFieldIds, LESIONS, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), lesionsLocationFieldIds, LESIONS, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), LESIONS_ONSET_DATE, LESIONS, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), CONGENITAL_HEART_DISEASE_TYPE, CONGENITAL_HEART_DISEASE, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), CONGENITAL_HEART_DISEASE_DETAILS, CONGENITAL_HEART_DISEASE_TYPE, Arrays.asList(CongenitalHeartDiseaseType.OTHER), true);
    if (isVisibleAllowed(getFieldGroup().getField(JAUNDICE_WITHIN_24_HOURS_OF_BIRTH))) {
        FieldHelper.setVisibleWhen(getFieldGroup(), JAUNDICE_WITHIN_24_HOURS_OF_BIRTH, JAUNDICE, Arrays.asList(SymptomState.YES), true);
    }
    FieldHelper.addSoftRequiredStyle(getField(LESIONS_ONSET_DATE));
    boolean isInfant = person != null && person.getApproximateAge() != null && ((person.getApproximateAge() <= 12 && person.getApproximateAgeType() == ApproximateAgeType.MONTHS) || person.getApproximateAge() <= 1);
    if (!isInfant) {
        getFieldGroup().getField(BULGING_FONTANELLE).setVisible(false);
    }
    // Handle visibility of lesions locations caption
    Label lesionsLocationsCaption = new Label(I18nProperties.getCaption(Captions.symptomsLesionsLocations));
    CssStyles.style(lesionsLocationsCaption, VSPACE_3);
    getContent().addComponent(lesionsLocationsCaption, LESIONS_LOCATIONS_LOC);
    getContent().getComponent(LESIONS_LOCATIONS_LOC).setVisible(FieldHelper.getNullableSourceFieldValue(getFieldGroup().getField(LESIONS)) == SymptomState.YES);
    getFieldGroup().getField(LESIONS).addValueChangeListener(e -> {
        getContent().getComponent(LESIONS_LOCATIONS_LOC).setVisible(FieldHelper.getNullableSourceFieldValue((Field) e.getProperty()) == SymptomState.YES);
    });
    // Symptoms hint text
    Label symptomsHint = new Label(I18nProperties.getString(symptomsContext == SymptomsContext.CASE ? Strings.messageSymptomsHint : Strings.messageSymptomsVisitHint), ContentMode.HTML);
    symptomsHint.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(symptomsHint, SYMPTOMS_HINT_LOC);
    if (disease == Disease.MONKEYPOX) {
        setUpMonkeypoxVisibilities();
    }
    if (symptomsContext != SymptomsContext.CASE) {
        getFieldGroup().getField(PATIENT_ILL_LOCATION).setVisible(false);
    }
    symptomGroupMap.forEach((location, strings) -> {
        final Component groupLabel = getContent().getComponent(location);
        final Optional<String> groupHasVisibleSymptom = strings.stream().filter(s -> getFieldGroup().getField(s).isVisible()).findAny();
        if (!groupHasVisibleSymptom.isPresent()) {
            groupLabel.setVisible(false);
        }
    });
    if (isEditableAllowed(OTHER_HEMORRHAGIC_SYMPTOMS_TEXT)) {
        FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(OTHER_HEMORRHAGIC_SYMPTOMS), Arrays.asList(OTHER_HEMORRHAGIC_SYMPTOMS_TEXT), Arrays.asList(SymptomState.YES), disease);
    }
    if (isEditableAllowed(OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT)) {
        FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(OTHER_NON_HEMORRHAGIC_SYMPTOMS), Arrays.asList(OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT), Arrays.asList(SymptomState.YES), disease);
    }
    if (isEditableAllowed(OTHER_COMPLICATIONS_TEXT)) {
        FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(OTHER_COMPLICATIONS), Arrays.asList(OTHER_COMPLICATIONS_TEXT), Arrays.asList(SymptomState.YES), disease);
    }
    FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(LESIONS), lesionsFieldIds, Arrays.asList(SymptomState.YES), disease);
    FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(LESIONS), monkeypoxImageFieldIds, Arrays.asList(SymptomState.YES), disease);
    addListenerForOnsetFields(onsetSymptom, onsetDateField);
    Button clearAllButton = ButtonHelper.createButton(Captions.actionClearAll, event -> {
        for (Object symptomId : unconditionalSymptomFieldIds) {
            getFieldGroup().getField(symptomId).setValue(null);
        }
        for (Object symptomId : conditionalBleedingSymptomFieldIds) {
            getFieldGroup().getField(symptomId).setValue(null);
        }
        for (Object symptomId : lesionsFieldIds) {
            getFieldGroup().getField(symptomId).setValue(null);
        }
        for (Object symptomId : lesionsLocationFieldIds) {
            getFieldGroup().getField(symptomId).setValue(null);
        }
        for (Object symptomId : monkeypoxImageFieldIds) {
            getFieldGroup().getField(symptomId).setValue(null);
        }
    }, ValoTheme.BUTTON_LINK);
    Button setEmptyToNoButton = createButtonSetClearedToSymptomState(Captions.symptomsSetClearedToNo, SymptomState.NO);
    Button setEmptyToUnknownButton = createButtonSetClearedToSymptomState(Captions.symptomsSetClearedToUnknown, SymptomState.UNKNOWN);
    // Complications heading - not displayed for Rubella (dirty, should be made generic)
    Label complicationsHeading = new Label(I18nProperties.getString(Strings.headingComplications));
    CssStyles.style(complicationsHeading, CssStyles.H3);
    if (disease != Disease.CONGENITAL_RUBELLA && !isConfiguredServer("de")) {
        getContent().addComponent(complicationsHeading, COMPLICATIONS_HEADING);
    }
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.addComponent(clearAllButton);
    buttonsLayout.addComponent(setEmptyToNoButton);
    buttonsLayout.addComponent(setEmptyToUnknownButton);
    buttonsLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    buttonsLayout.setMargin(new MarginInfo(true, false, true, true));
    getContent().addComponent(buttonsLayout, BUTTONS_LOC);
    if (feverField.isVisible()) {
        temperature.addValueChangeListener(e -> {
            toggleFeverComponentError(feverField, temperature);
        });
        feverField.addValueChangeListener(e -> {
            toggleFeverComponentError(feverField, temperature);
        });
    }
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) ThemeResource(com.vaadin.server.ThemeResource) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) H4(de.symeda.sormas.ui.utils.CssStyles.H4) ConversionException(com.vaadin.v7.data.util.converter.Converter.ConversionException) AbstractField(com.vaadin.v7.ui.AbstractField) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) Alignment(com.vaadin.ui.Alignment) PersonDto(de.symeda.sormas.api.person.PersonDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) Map(java.util.Map) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ViewMode(de.symeda.sormas.ui.utils.ViewMode) Predicate(java.util.function.Predicate) ComboBox(com.vaadin.v7.ui.ComboBox) Set(java.util.Set) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) DateTimeComparator(org.joda.time.DateTimeComparator) LayoutUtil.locsCss(de.symeda.sormas.ui.utils.LayoutUtil.locsCss) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) TextField(com.vaadin.v7.ui.TextField) Descriptions(de.symeda.sormas.api.i18n.Descriptions) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) LayoutUtil.fluidRowLocsCss(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocsCss) LayoutUtil.fluidRowCss(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowCss) FacadeProvider(de.symeda.sormas.api.FacadeProvider) OutbreakFieldVisibilityChecker(de.symeda.sormas.ui.utils.OutbreakFieldVisibilityChecker) HashMap(java.util.HashMap) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) SymptomsContext(de.symeda.sormas.api.symptoms.SymptomsContext) ArrayList(java.util.ArrayList) SymptomGrouping(de.symeda.sormas.api.utils.SymptomGrouping) LayoutUtil.loc(de.symeda.sormas.ui.utils.LayoutUtil.loc) Image(com.vaadin.ui.Image) SymptomState(de.symeda.sormas.api.symptoms.SymptomState) LayoutUtil.locCss(de.symeda.sormas.ui.utils.LayoutUtil.locCss) Label(com.vaadin.ui.Label) 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) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ContentMode(com.vaadin.shared.ui.ContentMode) Validations(de.symeda.sormas.api.i18n.Validations) VSPACE_NONE(de.symeda.sormas.ui.utils.CssStyles.VSPACE_NONE) SymptomGroup(de.symeda.sormas.api.utils.SymptomGroup) ErrorMessage(com.vaadin.server.ErrorMessage) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) Captions(de.symeda.sormas.api.i18n.Captions) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) Button(com.vaadin.ui.Button) Disease(de.symeda.sormas.api.Disease) HorizontalLayout(com.vaadin.ui.HorizontalLayout) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) HospitalizationDto(de.symeda.sormas.api.hospitalization.HospitalizationDto) CongenitalHeartDiseaseType(de.symeda.sormas.api.symptoms.CongenitalHeartDiseaseType) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Component(com.vaadin.ui.Component) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout) AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) Button(com.vaadin.ui.Button) MarginInfo(com.vaadin.shared.ui.MarginInfo) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ErrorMessage(com.vaadin.server.ErrorMessage) Component(com.vaadin.ui.Component)

Example 12 with DateField

use of com.vaadin.v7.ui.DateField in project SORMAS-Project by hzi-braunschweig.

the class PrescriptionForm method addFields.

@Override
protected void addFields() {
    ComboBox prescriptionTypeField = addField(PrescriptionDto.PRESCRIPTION_TYPE, ComboBox.class);
    prescriptionTypeField.setImmediate(true);
    TextField prescriptionDetailsField = addField(PrescriptionDto.PRESCRIPTION_DETAILS, TextField.class);
    addField(PrescriptionDto.TYPE_OF_DRUG, NullableOptionGroup.class);
    addField(PrescriptionDto.PRESCRIPTION_DATE, DateField.class);
    addField(PrescriptionDto.PRESCRIBING_CLINICIAN, TextField.class);
    DateField prescriptionStartField = addDateField(PrescriptionDto.PRESCRIPTION_START, DateField.class, -1);
    DateField prescriptionEndField = addDateField(PrescriptionDto.PRESCRIPTION_END, DateField.class, -1);
    prescriptionEndField.setImmediate(true);
    addField(PrescriptionDto.FREQUENCY, TextField.class);
    addField(PrescriptionDto.DOSE, TextField.class);
    ComboBox routeField = addField(PrescriptionDto.ROUTE, ComboBox.class);
    addField(PrescriptionDto.ROUTE_DETAILS, TextField.class);
    TextArea additionalNotes = addField(PrescriptionDto.ADDITIONAL_NOTES, TextArea.class);
    additionalNotes.setRows(6);
    additionalNotes.setDescription(I18nProperties.getPrefixDescription(PrescriptionDto.I18N_PREFIX, PrescriptionDto.ADDITIONAL_NOTES, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    initializeAccessAndAllowedAccesses();
    setRequired(true, PrescriptionDto.PRESCRIPTION_TYPE, PrescriptionDto.PRESCRIPTION_DATE);
    if (isEditableAllowed(PrescriptionDto.PRESCRIPTION_DETAILS)) {
        FieldHelper.setRequiredWhen(getFieldGroup(), prescriptionTypeField, Collections.singletonList(PrescriptionDto.PRESCRIPTION_DETAILS), Arrays.asList(TreatmentType.OTHER, TreatmentType.DRUG_INTAKE));
    }
    if (isEditableAllowed(PrescriptionDto.ROUTE_DETAILS)) {
        FieldHelper.setRequiredWhen(getFieldGroup(), routeField, Arrays.asList(PrescriptionDto.ROUTE_DETAILS), Arrays.asList(TreatmentRoute.OTHER));
    }
    FieldHelper.setVisibleWhen(getFieldGroup(), PrescriptionDto.ROUTE_DETAILS, PrescriptionDto.ROUTE, Arrays.asList(TreatmentRoute.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), PrescriptionDto.TYPE_OF_DRUG, PrescriptionDto.PRESCRIPTION_TYPE, Arrays.asList(TreatmentType.DRUG_INTAKE), true);
    prescriptionTypeField.addValueChangeListener(e -> {
        if (e.getProperty().getValue() == TreatmentType.DRUG_INTAKE) {
            prescriptionDetailsField.setCaption(I18nProperties.getPrefixCaption(PrescriptionDto.I18N_PREFIX, PrescriptionDto.DRUG_INTAKE_DETAILS));
        } else {
            prescriptionDetailsField.setCaption(I18nProperties.getPrefixCaption(PrescriptionDto.I18N_PREFIX, PrescriptionDto.PRESCRIPTION_DETAILS));
        }
    });
    prescriptionStartField.addValidator(new DateComparisonValidator(prescriptionStartField, prescriptionEndField, true, false, I18nProperties.getValidationError(Validations.beforeDate, prescriptionStartField.getCaption(), prescriptionEndField.getCaption())));
    prescriptionEndField.addValidator(new DateComparisonValidator(prescriptionEndField, prescriptionStartField, false, false, I18nProperties.getValidationError(Validations.afterDate, prescriptionEndField.getCaption(), prescriptionStartField.getCaption())));
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator)

Example 13 with DateField

use of com.vaadin.v7.ui.DateField in project SORMAS-Project by hzi-braunschweig.

the class SormasFieldGroupFieldFactory method createField.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T extends Field> T createField(Class<?> type, Class<T> fieldType) {
    if (type.isEnum()) {
        if (// no specific fieldType defined?
        fieldType.isAssignableFrom(Field.class) && (SymptomState.class.isAssignableFrom(type) || YesNoUnknown.class.isAssignableFrom(type))) {
            NullableOptionGroup field = new NullableOptionGroup();
            field.setImmediate(true);
            populateWithEnumData(field, (Class<? extends Enum>) type);
            CssStyles.style(field, ValoTheme.OPTIONGROUP_HORIZONTAL, CssStyles.OPTIONGROUP_CAPTION_INLINE);
            return (T) field;
        } else {
            if (Disease.class.isAssignableFrom(type)) {
                fieldType = (Class<T>) ComboBox.class;
                ComboBox field = ComboBoxHelper.createComboBoxV7();
                field.setImmediate(true);
                field.setNullSelectionAllowed(true);
                populateWithDiseaseData(field);
                return (T) field;
            } else {
                if (!AbstractSelect.class.isAssignableFrom(fieldType)) {
                    fieldType = (Class<T>) ComboBox.class;
                }
                T field = super.createField(type, fieldType);
                if (field instanceof OptionGroup) {
                    CssStyles.style(field, ValoTheme.OPTIONGROUP_HORIZONTAL);
                } else if (fieldType.isAssignableFrom(NullableOptionGroup.class)) {
                    NullableOptionGroup select = new NullableOptionGroup();
                    select.setImmediate(true);
                    populateWithEnumData(select, (Class<? extends Enum>) type);
                    CssStyles.style(select, ValoTheme.OPTIONGROUP_HORIZONTAL);
                    field = (T) select;
                } else if (field instanceof ComboBox) {
                    ((ComboBox) field).setFilteringMode(FilteringMode.CONTAINS);
                    ((ComboBox) field).setNullSelectionAllowed(true);
                }
                return field;
            }
        }
    } else if (Boolean.class.isAssignableFrom(type)) {
        fieldType = CheckBox.class.isAssignableFrom(fieldType) ? (Class<T>) CheckBox.class : (Class<T>) NullableOptionGroup.class;
        return createBooleanField(fieldType);
    } else if (ComboBox.class.isAssignableFrom(fieldType) || ComboBoxWithPlaceholder.class.isAssignableFrom(fieldType)) {
        ComboBoxWithPlaceholder combo = new ComboBoxWithPlaceholder();
        combo.setImmediate(true);
        return (T) combo;
    } else if (AbstractSelect.class.isAssignableFrom(fieldType)) {
        AbstractSelect field = createCompatibleSelect((Class<? extends AbstractSelect>) fieldType);
        field.setNullSelectionAllowed(true);
        return (T) field;
    } else if (LocationEditForm.class.isAssignableFrom(fieldType)) {
        return (T) new LocationEditForm(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (HealthConditionsForm.class.isAssignableFrom(fieldType)) {
        return (T) new HealthConditionsForm(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (DateTimeField.class.isAssignableFrom(fieldType)) {
        DateTimeField field = new DateTimeField();
        field.setConverter(new SormasDefaultConverterFactory().createDateConverter(Date.class));
        return (T) field;
    } else if (DateField.class.isAssignableFrom(fieldType)) {
        DateField field = super.createField(type, DateField.class);
        field.setDateFormat(DateFormatHelper.getDateFormatPattern());
        field.setLenient(true);
        field.setConverter(new SormasDefaultConverterFactory().createDateConverter(Date.class));
        return (T) field;
    } else if (PreviousHospitalizationsField.class.isAssignableFrom(fieldType)) {
        return (T) new PreviousHospitalizationsField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (ExposuresField.class.isAssignableFrom(fieldType)) {
        return (T) new ExposuresField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (ActivityAsCaseField.class.isAssignableFrom(fieldType)) {
        return (T) new ActivityAsCaseField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (LocationsField.class.isAssignableFrom(fieldType)) {
        return (T) new LocationsField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (PersonContactDetailsField.class.isAssignableFrom(fieldType)) {
        return (T) new PersonContactDetailsField(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (VaccinationsField.class.isAssignableFrom(fieldType)) {
        return (T) new VaccinationsField(fieldAccessCheckers);
    } else if (JsonForm.class.isAssignableFrom(fieldType)) {
        return (T) new JsonForm(fieldVisibilityCheckers, fieldAccessCheckers);
    } else if (fieldType.equals(Field.class)) {
        // no specific field type defined -> fallbacks
        if (Date.class.isAssignableFrom(type)) {
            DateField field = super.createField(type, DateField.class);
            field.setDateFormat(DateFormatHelper.getDateFormatPattern());
            field.setLenient(true);
            field.setConverter(new SormasDefaultConverterFactory().createDateConverter(Date.class));
            return (T) field;
        } else if (ReferenceDto.class.isAssignableFrom(type)) {
            return (T) ComboBoxHelper.createComboBoxV7();
        }
    } else if (MultiSelect.class.isAssignableFrom(fieldType)) {
        return (T) MultiSelect.create(type);
    }
    return super.createField(type, fieldType);
}
Also used : SymptomState(de.symeda.sormas.api.symptoms.SymptomState) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) ExposuresField(de.symeda.sormas.ui.exposure.ExposuresField) DateField(com.vaadin.v7.ui.DateField) PersonContactDetailsField(de.symeda.sormas.ui.person.PersonContactDetailsField) LocationsField(de.symeda.sormas.ui.person.LocationsField) Field(com.vaadin.v7.ui.Field) AbstractTextField(com.vaadin.v7.ui.AbstractTextField) ActivityAsCaseField(de.symeda.sormas.ui.ActivityAsCase.ActivityAsCaseField) PreviousHospitalizationsField(de.symeda.sormas.ui.hospitalization.PreviousHospitalizationsField) OptionGroup(com.vaadin.v7.ui.OptionGroup) HealthConditionsForm(de.symeda.sormas.ui.clinicalcourse.HealthConditionsForm) ExposuresField(de.symeda.sormas.ui.exposure.ExposuresField) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) ComboBox(com.vaadin.v7.ui.ComboBox) LocationsField(de.symeda.sormas.ui.person.LocationsField) Date(java.util.Date) PreviousHospitalizationsField(de.symeda.sormas.ui.hospitalization.PreviousHospitalizationsField) ActivityAsCaseField(de.symeda.sormas.ui.ActivityAsCase.ActivityAsCaseField) JsonForm(de.symeda.sormas.ui.utils.components.JsonForm) CheckBox(com.vaadin.v7.ui.CheckBox) PersonContactDetailsField(de.symeda.sormas.ui.person.PersonContactDetailsField) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) DateField(com.vaadin.v7.ui.DateField)

Example 14 with DateField

use of com.vaadin.v7.ui.DateField in project SORMAS-Project by hzi-braunschweig.

the class EventDataForm method addFields.

@Override
protected void addFields() {
    if (isCreateForm == null) {
        return;
    }
    Label eventDataHeadingLabel = new Label(I18nProperties.getString(Strings.headingEventData));
    eventDataHeadingLabel.addStyleName(H3);
    getContent().addComponent(eventDataHeadingLabel, EVENT_DATA_HEADING_LOC);
    Label informationSourceHeadingLabel = new Label(I18nProperties.getString(Strings.headingInformationSource));
    informationSourceHeadingLabel.addStyleName(H3);
    getContent().addComponent(informationSourceHeadingLabel, INFORMATION_SOURCE_HEADING_LOC);
    Label locationHeadingLabel = new Label(I18nProperties.getString(Strings.headingLocation));
    locationHeadingLabel.addStyleName(H3);
    getContent().addComponent(locationHeadingLabel, LOCATION_HEADING_LOC);
    addField(EventDto.UUID, TextField.class);
    ComboBox diseaseField = addDiseaseField(EventDto.DISEASE, false, isCreateForm);
    addField(EventDto.DISEASE_DETAILS, TextField.class);
    ComboBox diseaseVariantField = addField(EventDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantField.setNullSelectionAllowed(true);
    addFields(EventDto.EXTERNAL_ID);
    TextField diseaseVariantDetailsField = addField(EventDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    TextField externalTokenField = addField(EventDto.EXTERNAL_TOKEN);
    Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messageEventExternalTokenWarning));
    externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
    getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
    addField(EventDto.INTERNAL_TOKEN);
    DateTimeField startDate = addField(EventDto.START_DATE, DateTimeField.class);
    CheckBox multiDayCheckbox = addField(EventDto.MULTI_DAY_EVENT, CheckBox.class);
    DateTimeField endDate = addField(EventDto.END_DATE, DateTimeField.class);
    initEventDateValidation(startDate, endDate, multiDayCheckbox);
    addField(EventDto.EVENT_STATUS, NullableOptionGroup.class);
    addField(EventDto.RISK_LEVEL);
    ComboBox specificRiskField = addField(EventDto.SPECIFIC_RISK, ComboBox.class);
    specificRiskField.setNullSelectionAllowed(true);
    addField(EventDto.EVENT_MANAGEMENT_STATUS, NullableOptionGroup.class);
    addField(EventDto.EVENT_IDENTIFICATION_SOURCE, NullableOptionGroup.class);
    addField(EventDto.EVENT_INVESTIGATION_STATUS, NullableOptionGroup.class);
    addField(EventDto.EVENT_INVESTIGATION_START_DATE, DateField.class);
    addField(EventDto.EVENT_INVESTIGATION_END_DATE, DateField.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.EVENT_INVESTIGATION_START_DATE, EventDto.EVENT_INVESTIGATION_END_DATE), EventDto.EVENT_INVESTIGATION_STATUS, Arrays.asList(EventInvestigationStatus.ONGOING, EventInvestigationStatus.DONE, EventInvestigationStatus.DISCARDED), true);
    TextField title = addField(EventDto.EVENT_TITLE, TextField.class);
    title.addStyleName(CssStyles.SOFT_REQUIRED);
    TextArea descriptionField = addField(EventDto.EVENT_DESC, TextArea.class, new ResizableTextAreaWrapper<>());
    descriptionField.setRows(2);
    descriptionField.setDescription(I18nProperties.getPrefixDescription(EventDto.I18N_PREFIX, EventDto.EVENT_DESC, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    addField(EventDto.DISEASE_TRANSMISSION_MODE, ComboBox.class);
    addField(EventDto.NOSOCOMIAL, NullableOptionGroup.class);
    addFields(EventDto.HUMAN_TRANSMISSION_MODE, EventDto.INFECTION_PATH_CERTAINTY);
    addFields(EventDto.PARENTERAL_TRANSMISSION_MODE, EventDto.MEDICALLY_ASSOCIATED_TRANSMISSION_MODE);
    final NullableOptionGroup epidemiologicalEvidence = addField(EventDto.EPIDEMIOLOGICAL_EVIDENCE, NullableOptionGroup.class);
    final NullableOptionGroup laboratoryDiagnosticEvidence = addField(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE, NullableOptionGroup.class);
    epidemiologicalEvidenceCheckBoxTree = new EpidemiologicalEvidenceCheckBoxTree(Arrays.stream(EpidemiologicalEvidenceDetail.values()).map(epidemiologicalEvidenceDetail -> epidemiologicalEvidenceDetailToCheckBoxElement(epidemiologicalEvidenceDetail)).collect(Collectors.toList()));
    getContent().addComponent(epidemiologicalEvidenceCheckBoxTree, EventDto.EPIDEMIOLOGICAL_EVIDENCE_DETAILS);
    epidemiologicalEvidenceCheckBoxTree.setVisible(false);
    laboratoryDiagnosticEvidenceCheckBoxTree = new LaboratoryDiagnosticEvidenceCheckBoxTree(Arrays.stream(LaboratoryDiagnosticEvidenceDetail.values()).map(laboratoryDiagnosticEvidenceDetail -> laboratoryDiagnosticEvidenceDetailToCheckBoxElement(laboratoryDiagnosticEvidenceDetail)).collect(Collectors.toList()));
    getContent().addComponent(laboratoryDiagnosticEvidenceCheckBoxTree, EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE_DETAILS);
    laboratoryDiagnosticEvidenceCheckBoxTree.setVisible(false);
    DateField evolutionDateField = addField(EventDto.EVOLUTION_DATE, DateField.class);
    TextField evolutionCommentField = addField(EventDto.EVOLUTION_COMMENT, TextField.class);
    Field<?> statusField = getField(EventDto.EVENT_STATUS);
    statusField.addValueChangeListener(e -> {
        if (statusField.getValue() == null) {
            return;
        }
        EventStatus eventStatus = (EventStatus) statusField.getValue();
        // The status will be used to modify the caption of the field
        // However we don't want to have somthing like "Dropped evolution date"
        // So let's ignore the DROPPED status and use the Event entity caption instead
        String statusCaption;
        if (eventStatus == EventStatus.DROPPED) {
            statusCaption = I18nProperties.getCaption(EVENT_ENTITY);
        } else {
            statusCaption = I18nProperties.getEnumCaption(eventStatus);
        }
        evolutionDateField.setCaption(String.format(I18nProperties.getCaption(EVOLUTION_DATE_WITH_STATUS), statusCaption));
        evolutionCommentField.setCaption(String.format(I18nProperties.getCaption(EVOLUTION_COMMENT_WITH_STATUS), statusCaption));
    });
    FieldHelper.setVisibleWhenSourceNotNull(getFieldGroup(), Collections.singletonList(EventDto.EVOLUTION_COMMENT), EventDto.EVOLUTION_DATE, true);
    ComboBox typeOfPlace = addField(EventDto.TYPE_OF_PLACE, ComboBox.class);
    typeOfPlace.setNullSelectionAllowed(true);
    addField(EventDto.TYPE_OF_PLACE_TEXT, TextField.class);
    addField(EventDto.WORK_ENVIRONMENT);
    ComboBox meansOfTransport = addField(EventDto.MEANS_OF_TRANSPORT);
    TextField connectionNumber = addField(EventDto.CONNECTION_NUMBER);
    DateField travelDate = addField(EventDto.TRAVEL_DATE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.MEANS_OF_TRANSPORT), EventDto.TYPE_OF_PLACE, Collections.singletonList(TypeOfPlace.MEANS_OF_TRANSPORT), true);
    TextField meansOfTransportDetails = addField(EventDto.MEANS_OF_TRANSPORT_DETAILS);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.MEANS_OF_TRANSPORT_DETAILS), EventDto.MEANS_OF_TRANSPORT, Collections.singletonList(MeansOfTransport.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.CONNECTION_NUMBER, EventDto.TRAVEL_DATE), EventDto.TYPE_OF_PLACE, Collections.singletonList(TypeOfPlace.MEANS_OF_TRANSPORT), true);
    getField(EventDto.MEANS_OF_TRANSPORT).addValueChangeListener(e -> {
        if (e.getProperty().getValue() == MeansOfTransport.PLANE) {
            getField(EventDto.CONNECTION_NUMBER).setCaption(I18nProperties.getCaption(Captions.exposureFlightNumber));
        } else {
            getField(EventDto.CONNECTION_NUMBER).setCaption(I18nProperties.getPrefixCaption(EventDto.I18N_PREFIX, EventDto.CONNECTION_NUMBER));
        }
    });
    DateField reportDate = addField(EventDto.REPORT_DATE_TIME, DateField.class);
    addField(EventDto.REPORTING_USER, ComboBox.class);
    addField(EventDto.TRANSREGIONAL_OUTBREAK, NullableOptionGroup.class);
    ComboBox srcType = addField(EventDto.SRC_TYPE);
    TextField srcFirstName = addField(EventDto.SRC_FIRST_NAME, TextField.class);
    TextField srcLastName = addField(EventDto.SRC_LAST_NAME, TextField.class);
    TextField srcTelNo = addField(EventDto.SRC_TEL_NO, TextField.class);
    addField(EventDto.SRC_EMAIL, TextField.class);
    TextField srcMediaWebsite = addField(EventDto.SRC_MEDIA_WEBSITE, TextField.class);
    TextField srcMediaName = addField(EventDto.SRC_MEDIA_NAME, TextField.class);
    TextArea srcMediaDetails = addField(EventDto.SRC_MEDIA_DETAILS, TextArea.class);
    srcMediaDetails.setRows(4);
    ComboBox srcInstitutionalPartnerType = addField(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE), EventDto.SRC_TYPE, Collections.singletonList(EventSourceType.INSTITUTIONAL_PARTNER), true);
    TextField srcInstitutionalPartnerTypeDetails = addField(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE_DETAILS);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE_DETAILS), EventDto.SRC_INSTITUTIONAL_PARTNER_TYPE, Collections.singletonList(InstitutionalPartnerType.OTHER), true);
    addField(EventDto.EVENT_LOCATION, new LocationEditForm(fieldVisibilityCheckers, createFieldAccessCheckers(isPseudonymized, false))).setCaption(null);
    locationForm = (LocationEditForm) getFieldGroup().getField(EventDto.EVENT_LOCATION);
    locationForm.setDistrictRequiredOnDefaultCountry(true);
    ComboBox regionField = (ComboBox) locationForm.getFieldGroup().getField(LocationDto.REGION);
    ComboBox districtField = (ComboBox) locationForm.getFieldGroup().getField(LocationDto.DISTRICT);
    ComboBox responsibleUserField = addField(EventDto.RESPONSIBLE_USER, ComboBox.class);
    responsibleUserField.setNullSelectionAllowed(true);
    addField(EventDto.DELETION_REASON);
    addField(EventDto.OTHER_DELETION_REASON, TextArea.class).setRows(3);
    setVisible(false, EventDto.DELETION_REASON, EventDto.OTHER_DELETION_REASON);
    if (isCreateForm) {
        locationForm.hideValidationUntilNextCommit();
    }
    setReadOnly(true, EventDto.UUID, EventDto.REPORTING_USER);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.WORK_ENVIRONMENT, locationForm.getFacilityTypeGroup(), Collections.singletonList(FacilityTypeGroup.WORKING_PLACE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(EventDto.DISEASE_DETAILS), EventDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), EventDto.DISEASE, Collections.singletonList(EventDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    // Customizable enum fields visibilities
    diseaseVariantField.setVisible(false);
    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 && CollectionUtils.isNotEmpty(diseaseVariants));
        List<SpecificRisk> specificRiskValues = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.SPECIFIC_EVENT_RISK, disease);
        FieldHelper.updateItems(specificRiskField, specificRiskValues);
        specificRiskField.setVisible(isVisibleAllowed(EventDto.SPECIFIC_RISK) && CollectionUtils.isNotEmpty(specificRiskValues));
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
    setRequired(true, EventDto.EVENT_STATUS, EventDto.UUID, EventDto.EVENT_TITLE, EventDto.REPORT_DATE_TIME, EventDto.REPORTING_USER);
    reportDate.addValidator(new DateComparisonValidator(reportDate, startDate, false, false, I18nProperties.getValidationError(Validations.afterDate, reportDate.getCaption(), startDate.getCaption())));
    startDate.addValidator(new DateComparisonValidator(startDate, reportDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, startDate.getCaption(), reportDate.getCaption())));
    reportDate.addValueChangeListener(e -> startDate.setValidationVisible(!startDate.isValid()));
    startDate.addValueChangeListener(e -> reportDate.setValidationVisible(!reportDate.isValid()));
    FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.END_DATE, EventDto.MULTI_DAY_EVENT, Collections.singletonList(true), true);
    FieldHelper.setCaptionWhen(multiDayCheckbox, startDate, false, I18nProperties.getCaption(Captions.singleDayEventDate), I18nProperties.getCaption(Captions.Event_startDate));
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.NOSOCOMIAL, EventDto.TRANSREGIONAL_OUTBREAK, EventDto.DISEASE_TRANSMISSION_MODE), EventDto.EVENT_STATUS, Collections.singletonList(EventStatus.CLUSTER), true);
    if (isVisibleAllowed(EventDto.INFECTION_PATH_CERTAINTY)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.INFECTION_PATH_CERTAINTY, EventDto.NOSOCOMIAL, Collections.singletonList(YesNoUnknown.YES), true);
    }
    if (isVisibleAllowed(EventDto.HUMAN_TRANSMISSION_MODE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.HUMAN_TRANSMISSION_MODE, EventDto.DISEASE_TRANSMISSION_MODE, Collections.singletonList(DiseaseTransmissionMode.HUMAN_TO_HUMAN), true);
    }
    if (isVisibleAllowed(EventDto.PARENTERAL_TRANSMISSION_MODE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.PARENTERAL_TRANSMISSION_MODE, EventDto.HUMAN_TRANSMISSION_MODE, Collections.singletonList(HumanTransmissionMode.PARENTERAL), true);
    }
    if (isVisibleAllowed(EventDto.MEDICALLY_ASSOCIATED_TRANSMISSION_MODE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.MEDICALLY_ASSOCIATED_TRANSMISSION_MODE, EventDto.PARENTERAL_TRANSMISSION_MODE, Collections.singletonList(ParenteralTransmissionMode.MEDICALLY_ASSOCIATED), true);
    }
    if (isVisibleAllowed(EventDto.EPIDEMIOLOGICAL_EVIDENCE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.EPIDEMIOLOGICAL_EVIDENCE, EventDto.DISEASE_TRANSMISSION_MODE, Collections.singletonList(DiseaseTransmissionMode.HUMAN_TO_HUMAN), true);
        epidemiologicalEvidence.addValueChangeListener(valueChangeEvent -> {
            if (((NullableOptionGroup) valueChangeEvent.getProperty()).getNullableValue() == YesNoUnknown.YES) {
                epidemiologicalEvidenceCheckBoxTree.setVisible(true);
            } else {
                epidemiologicalEvidenceCheckBoxTree.clearCheckBoxTree();
                epidemiologicalEvidenceCheckBoxTree.setVisible(false);
            }
        });
    }
    if (isVisibleAllowed(EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.LABORATORY_DIAGNOSTIC_EVIDENCE, EventDto.DISEASE_TRANSMISSION_MODE, Collections.singletonList(DiseaseTransmissionMode.HUMAN_TO_HUMAN), true);
        laboratoryDiagnosticEvidence.addValueChangeListener(valueChangeEvent -> {
            if (((NullableOptionGroup) valueChangeEvent.getProperty()).getNullableValue() == YesNoUnknown.YES) {
                laboratoryDiagnosticEvidenceCheckBoxTree.setVisible(true);
            } else {
                laboratoryDiagnosticEvidenceCheckBoxTree.clearCheckBoxTree();
                laboratoryDiagnosticEvidenceCheckBoxTree.setVisible(false);
            }
        });
    }
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.SRC_FIRST_NAME, EventDto.SRC_LAST_NAME, EventDto.SRC_TEL_NO, EventDto.SRC_EMAIL), EventDto.SRC_TYPE, Arrays.asList(EventSourceType.HOTLINE_PERSON, EventSourceType.INSTITUTIONAL_PARTNER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(EventDto.SRC_MEDIA_WEBSITE, EventDto.SRC_MEDIA_NAME, EventDto.SRC_MEDIA_DETAILS), EventDto.SRC_TYPE, Collections.singletonList(EventSourceType.MEDIA_NEWS), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), EventDto.TYPE_OF_PLACE_TEXT, EventDto.TYPE_OF_PLACE, Collections.singletonList(TypeOfPlace.OTHER), true);
    setTypeOfPlaceTextRequirement();
    locationForm.setFacilityFieldsVisible(getField(EventDto.TYPE_OF_PLACE).getValue() == TypeOfPlace.FACILITY, true);
    typeOfPlace.addValueChangeListener(e -> locationForm.setFacilityFieldsVisible(e.getProperty().getValue() == TypeOfPlace.FACILITY, true));
    regionField.addValueChangeListener(e -> {
        RegionReferenceDto region = (RegionReferenceDto) regionField.getValue();
        if (region != null) {
            regionEventResponsibles = FacadeProvider.getUserFacade().getUsersByRegionAndRights(region, getValue().getDisease(), UserRight.EVENT_RESPONSIBLE);
        } else {
            regionEventResponsibles.clear();
        }
    });
    districtField.addValueChangeListener(e -> {
        DistrictReferenceDto district = (DistrictReferenceDto) districtField.getValue();
        if (district != null) {
            List<UserReferenceDto> districtEventResponsibles = FacadeProvider.getUserFacade().getUserRefsByDistrict(district, getValue().getDisease(), UserRight.EVENT_RESPONSIBLE);
            List<UserReferenceDto> responsibleUsers = new ArrayList<>();
            responsibleUsers.addAll(districtEventResponsibles);
            responsibleUsers.addAll(regionEventResponsibles);
            FieldHelper.updateItems(responsibleUserField, responsibleUsers);
        } else {
            responsibleUserField.removeAllItems();
        }
    });
    FieldHelper.addSoftRequiredStyle(startDate, endDate, typeOfPlace, meansOfTransport, meansOfTransportDetails, connectionNumber, travelDate, responsibleUserField, srcType, srcInstitutionalPartnerType, srcInstitutionalPartnerTypeDetails, srcFirstName, srcLastName, srcTelNo, srcMediaWebsite, srcMediaName);
    // Make external ID field read-only when SORMAS is connected to a SurvNet instance
    if (StringUtils.isNotEmpty(FacadeProvider.getConfigFacade().getExternalSurveillanceToolGatewayUrl())) {
        setEnabled(false, EventDto.EXTERNAL_ID);
        ((TextField) getField(EventDto.EXTERNAL_ID)).setInputPrompt(I18nProperties.getString(Strings.promptExternalIdExternalSurveillanceTool));
    }
    addValueChangeListener((e) -> {
        ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getEventFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
        epidemiologicalEvidenceCheckBoxTree.initCheckboxes();
        laboratoryDiagnosticEvidenceCheckBoxTree.initCheckboxes();
        // Initialize specific risk field if disease is null
        if (getValue().getDisease() == null) {
            List<SpecificRisk> specificRiskValues = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.SPECIFIC_EVENT_RISK, null);
            FieldHelper.updateItems(specificRiskField, specificRiskValues);
            specificRiskField.setVisible(isVisibleAllowed(EventDto.SPECIFIC_RISK) && CollectionUtils.isNotEmpty(specificRiskValues));
        }
    });
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) CheckBoxTree(de.symeda.sormas.ui.utils.CheckBoxTree) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) DiseaseTransmissionMode(de.symeda.sormas.api.event.DiseaseTransmissionMode) ValidationUtils(de.symeda.sormas.ui.utils.ValidationUtils) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LayoutUtil.locs(de.symeda.sormas.ui.utils.LayoutUtil.locs) StringUtils(org.apache.commons.lang3.StringUtils) SpecificRisk(de.symeda.sormas.api.event.SpecificRisk) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) EpidemiologicalEvidenceDetail(de.symeda.sormas.api.event.EpidemiologicalEvidenceDetail) HumanTransmissionMode(de.symeda.sormas.api.event.HumanTransmissionMode) CssStyles(de.symeda.sormas.ui.utils.CssStyles) EventInvestigationStatus(de.symeda.sormas.api.event.EventInvestigationStatus) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ComboBox(com.vaadin.v7.ui.ComboBox) LaboratoryDiagnosticEvidenceDetail(de.symeda.sormas.api.event.LaboratoryDiagnosticEvidenceDetail) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Field(com.vaadin.v7.ui.Field) EventDto(de.symeda.sormas.api.event.EventDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) InstitutionalPartnerType(de.symeda.sormas.api.event.InstitutionalPartnerType) TextField(com.vaadin.v7.ui.TextField) MeansOfTransport(de.symeda.sormas.api.event.MeansOfTransport) Descriptions(de.symeda.sormas.api.i18n.Descriptions) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) LABEL_WHITE_SPACE_NORMAL(de.symeda.sormas.ui.utils.CssStyles.LABEL_WHITE_SPACE_NORMAL) FacadeProvider(de.symeda.sormas.api.FacadeProvider) VerticalLayout(com.vaadin.ui.VerticalLayout) Converter(com.vaadin.v7.data.util.converter.Converter) EventStatus(de.symeda.sormas.api.event.EventStatus) ArrayList(java.util.ArrayList) 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) 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) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ResizableTextAreaWrapper(de.symeda.sormas.ui.utils.ResizableTextAreaWrapper) Captions(de.symeda.sormas.api.i18n.Captions) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ParenteralTransmissionMode(de.symeda.sormas.api.event.ParenteralTransmissionMode) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) Disease(de.symeda.sormas.api.Disease) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) EventSourceType(de.symeda.sormas.api.event.EventSourceType) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Disease(de.symeda.sormas.api.Disease) TextArea(com.vaadin.v7.ui.TextArea) Label(com.vaadin.ui.Label) EventStatus(de.symeda.sormas.api.event.EventStatus) ArrayList(java.util.ArrayList) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) TextField(com.vaadin.v7.ui.TextField) List(java.util.List) ArrayList(java.util.ArrayList) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) SpecificRisk(de.symeda.sormas.api.event.SpecificRisk) CheckBox(com.vaadin.v7.ui.CheckBox) DateField(com.vaadin.v7.ui.DateField)

Example 15 with DateField

use of com.vaadin.v7.ui.DateField in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationCreationForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addField(ImmunizationDto.REPORT_DATE, DateField.class);
    TextField externalIdField = addField(ImmunizationDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    ComboBox diseaseField = addDiseaseField(ImmunizationDto.DISEASE, false, true);
    addField(ImmunizationDto.DISEASE_DETAILS, TextField.class);
    ComboBox meansOfImmunizationField = addField(ImmunizationDto.MEANS_OF_IMMUNIZATION, ComboBox.class);
    addField(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS, TextField.class);
    CheckBox overwriteImmunizationManagementStatus = addCustomField(OVERWRITE_IMMUNIZATION_MANAGEMENT_STATUS, Boolean.class, CheckBox.class);
    overwriteImmunizationManagementStatus.addStyleName(VSPACE_3);
    ComboBox managementStatusField = addCustomField(ImmunizationDto.IMMUNIZATION_MANAGEMENT_STATUS, ImmunizationManagementStatus.class, ComboBox.class);
    managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
    managementStatusField.setEnabled(false);
    managementStatusField.setNullSelectionAllowed(false);
    ComboBox immunizationStatusField = addCustomField(ImmunizationDto.IMMUNIZATION_STATUS, ImmunizationStatus.class, ComboBox.class);
    immunizationStatusField.setValue(ImmunizationStatus.PENDING);
    immunizationStatusField.setEnabled(false);
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    ComboBox responsibleRegion = addInfrastructureField(ImmunizationDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    ComboBox responsibleDistrictCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_DISTRICT);
    responsibleDistrictCombo.setRequired(true);
    ComboBox responsibleCommunityCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunityCombo.setNullSelectionAllowed(true);
    responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
    ComboBox 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);
    ComboBox facilityType = ComboBoxHelper.createComboBoxV7();
    facilityType.setId("type");
    facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
    facilityType.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(facilityType, ImmunizationDto.FACILITY_TYPE);
    ComboBox facilityCombo = addInfrastructureField(ImmunizationDto.HEALTH_FACILITY);
    facilityCombo.setImmediate(true);
    TextField facilityDetails = addField(ImmunizationDto.HEALTH_FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    DateField startDate = addField(ImmunizationDto.START_DATE, DateField.class);
    DateField endDate = addDateField(ImmunizationDto.END_DATE, DateField.class, -1);
    DateComparisonValidator.addStartEndValidators(startDate, endDate);
    DateField validFrom = addDateField(ImmunizationDto.VALID_FROM, DateField.class, -1);
    DateField validUntil = addDateField(ImmunizationDto.VALID_UNTIL, DateField.class, -1);
    DateComparisonValidator.addStartEndValidators(validFrom, validUntil);
    Field numberOfDosesField = addField(ImmunizationDto.NUMBER_OF_DOSES);
    numberOfDosesField.addValidator(new NumberValidator(I18nProperties.getValidationError(Validations.vaccineDosesFormat), 1, 10, false));
    numberOfDosesField.setVisible(false);
    personCreateForm = new PersonCreateForm(false, true, false);
    personCreateForm.setWidth(100, Unit.PERCENTAGE);
    personCreateForm.setValue(new PersonDto());
    diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> personCreateForm.updatePresentConditionEnum((Disease) valueChangeEvent.getProperty().getValue()));
    getContent().addComponent(personCreateForm, TravelEntryDto.PERSON);
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, ImmunizationDto.REPORT_DATE, ImmunizationDto.MEANS_OF_IMMUNIZATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.DISEASE_DETAILS), ImmunizationDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), ImmunizationDto.DISEASE, Collections.singletonList(ImmunizationDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS), ImmunizationDto.MEANS_OF_IMMUNIZATION, Collections.singletonList(MeansOfImmunization.OTHER), true);
    overwriteImmunizationManagementStatus.addValueChangeListener(e -> {
        boolean selectedValue = (boolean) e.getProperty().getValue();
        if (!selectedValue) {
            managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
        }
        managementStatusField.setEnabled(selectedValue);
    });
    meansOfImmunizationField.addValueChangeListener(e -> {
        MeansOfImmunization meansOfImmunization = (MeansOfImmunization) e.getProperty().getValue();
        if (MeansOfImmunization.RECOVERY.equals(meansOfImmunization) || MeansOfImmunization.OTHER.equals(meansOfImmunization)) {
            managementStatusField.setValue(ImmunizationManagementStatus.COMPLETED);
        } else {
            managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
        }
        boolean isVaccinationVisible = MeansOfImmunization.VACCINATION.equals(meansOfImmunization) || MeansOfImmunization.VACCINATION_RECOVERY.equals(meansOfImmunization);
        numberOfDosesField.setVisible(isVaccinationVisible);
        if (!isVaccinationVisible) {
            numberOfDosesField.setValue(null);
        }
    });
    managementStatusField.addValueChangeListener(e -> {
        ImmunizationManagementStatus managementStatusValue = (ImmunizationManagementStatus) e.getProperty().getValue();
        switch(managementStatusValue) {
            case SCHEDULED:
            case ONGOING:
                immunizationStatusField.setValue(ImmunizationStatus.PENDING);
                break;
            case COMPLETED:
                immunizationStatusField.setValue(ImmunizationStatus.ACQUIRED);
                break;
            case CANCELED:
                immunizationStatusField.setValue(ImmunizationStatus.NOT_ACQUIRED);
                break;
            default:
                break;
        }
    });
    responsibleDistrictCombo.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        if (districtDto != null && facilityType.getValue() != null) {
            FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    responsibleCommunityCombo.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facilityCombo, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, false) : responsibleDistrictCombo.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    facilityTypeGroup.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
    });
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        if (facilityType.getValue() != null && responsibleDistrictCombo.getValue() != null) {
            if (responsibleCommunityCombo.getValue() != null) {
                FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) responsibleCommunityCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
            } else {
                FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
            }
        }
    });
    facilityCombo.addValueChangeListener(e -> {
        updateFacilityFields(facilityCombo, facilityDetails);
        this.getValue().setFacilityType((FacilityType) facilityType.getValue());
    });
    addValueChangeListener(e -> {
        if (disease != null) {
            setVisible(false, ImmunizationDto.DISEASE, ImmunizationDto.DISEASE_DETAILS);
            setReadOnly(false, ImmunizationDto.DISEASE, ImmunizationDto.DISEASE_DETAILS);
        } else {
            setRequired(true, ImmunizationDto.DISEASE);
        }
        if (personDto != null) {
            personCreateForm.setVisible(false);
            personCreateForm.setReadOnly(false);
        } else {
            personCreateForm.enablePersonFields(true);
        }
    });
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) H3(de.symeda.sormas.ui.utils.CssStyles.H3) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) CheckBox(com.vaadin.v7.ui.CheckBox) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) PersonDto(de.symeda.sormas.api.person.PersonDto) Label(com.vaadin.ui.Label) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) PersonCreateForm(de.symeda.sormas.ui.person.PersonCreateForm) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) 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) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) Disease(de.symeda.sormas.api.Disease) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) TextField(com.vaadin.v7.ui.TextField) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ComboBox(com.vaadin.v7.ui.ComboBox) PersonDto(de.symeda.sormas.api.person.PersonDto) Label(com.vaadin.ui.Label) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) PersonCreateForm(de.symeda.sormas.ui.person.PersonCreateForm) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) DateField(com.vaadin.v7.ui.DateField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) DateField(com.vaadin.v7.ui.DateField) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Aggregations

DateField (com.vaadin.v7.ui.DateField)15 TextField (com.vaadin.v7.ui.TextField)13 ComboBox (com.vaadin.v7.ui.ComboBox)12 Field (com.vaadin.v7.ui.Field)11 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)11 Label (com.vaadin.ui.Label)10 TextArea (com.vaadin.v7.ui.TextArea)10 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)8 CheckBox (com.vaadin.v7.ui.CheckBox)7 Disease (de.symeda.sormas.api.Disease)7 FacadeProvider (de.symeda.sormas.api.FacadeProvider)7 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)7 Strings (de.symeda.sormas.api.i18n.Strings)7 Validations (de.symeda.sormas.api.i18n.Validations)7 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)7 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)7 VSPACE_3 (de.symeda.sormas.ui.utils.CssStyles.VSPACE_3)7 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)7 LayoutUtil.fluidRowLocs (de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs)7 Date (java.util.Date)7