Search in sources :

Example 1 with ImmunizationManagementStatus

use of de.symeda.sormas.api.immunization.ImmunizationManagementStatus in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationDataForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    TextField immunizationUuuidField = addField(ImmunizationDto.UUID, TextField.class);
    immunizationUuuidField.setReadOnly(true);
    TextField externalIdField = addField(ImmunizationDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    addField(ImmunizationDto.REPORT_DATE, DateField.class);
    addField(ImmunizationDto.REPORTING_USER, ComboBox.class);
    ComboBox cbDisease = addDiseaseField(ImmunizationDto.DISEASE, false);
    addField(ImmunizationDto.DISEASE_DETAILS, TextField.class);
    ComboBox meansOfImmunizationField = addField(ImmunizationDto.MEANS_OF_IMMUNIZATION, ComboBox.class);
    addField(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS, TextField.class);
    overwriteImmunizationManagementStatus = addCustomField(OVERWRITE_IMMUNIZATION_MANAGEMENT_STATUS, Boolean.class, CheckBox.class);
    overwriteImmunizationManagementStatus.addStyleName(VSPACE_3);
    ComboBox managementStatusField = addField(ImmunizationDto.IMMUNIZATION_MANAGEMENT_STATUS, ComboBox.class);
    managementStatusField.setNullSelectionAllowed(false);
    managementStatusField.setEnabled(false);
    ComboBox immunizationStatusField = addField(ImmunizationDto.IMMUNIZATION_STATUS, ComboBox.class);
    immunizationStatusField.setEnabled(false);
    addField(ImmunizationDto.PREVIOUS_INFECTION, NullableOptionGroup.class);
    addField(ImmunizationDto.LAST_INFECTION_DATE, DateField.class);
    ComboBox country = addInfrastructureField(ImmunizationDto.COUNTRY);
    country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
    TextArea descriptionField = addField(ImmunizationDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>());
    descriptionField.setRows(2);
    descriptionField.setDescription(I18nProperties.getPrefixDescription(ImmunizationDto.I18N_PREFIX, ImmunizationDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    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);
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    facilityTypeGroup.setId("typeGroup");
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.values());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    ComboBox facilityType = addField(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);
    MeansOfImmunization meansOfImmunizationValue = (MeansOfImmunization) meansOfImmunizationField.getValue();
    boolean isVaccinationVisibleInitial = shouldShowVaccinationFields(meansOfImmunizationValue);
    Label vaccinationHeadingLabel = new Label(I18nProperties.getString(Strings.headingVaccination));
    vaccinationHeadingLabel.addStyleName(H3);
    getContent().addComponent(vaccinationHeadingLabel, VACCINATION_HEADING_LOC);
    vaccinationHeadingLabel.setVisible(isVaccinationVisibleInitial);
    Field numberOfDosesField = addField(ImmunizationDto.NUMBER_OF_DOSES);
    numberOfDosesField.addValidator(new NumberValidator(I18nProperties.getValidationError(Validations.vaccineDosesFormat), 1, 10, false));
    numberOfDosesField.setVisible(isVaccinationVisibleInitial);
    Field numberOfDosesDetailsField = addField(ImmunizationDto.NUMBER_OF_DOSES_DETAILS);
    numberOfDosesDetailsField.setReadOnly(true);
    numberOfDosesDetailsField.setVisible(isVaccinationVisibleInitial && getValue().getNumberOfDosesDetails() != null);
    VaccinationsField vaccinationsField = addField(ImmunizationDto.VACCINATIONS, VaccinationsField.class);
    FieldHelper.setVisibleWhen(getFieldGroup(), ImmunizationDto.VACCINATIONS, ImmunizationDto.MEANS_OF_IMMUNIZATION, Arrays.asList(MeansOfImmunization.VACCINATION, MeansOfImmunization.VACCINATION_RECOVERY), false);
    cbDisease.addValueChangeListener(e -> vaccinationsField.setDisease((Disease) cbDisease.getValue()));
    Label recoveryHeadingLabel = new Label(I18nProperties.getString(Strings.headingRecovery));
    recoveryHeadingLabel.addStyleName(H3);
    getContent().addComponent(recoveryHeadingLabel, RECOVERY_HEADING_LOC);
    recoveryHeadingLabel.setVisible(shouldShowRecoveryFields(meansOfImmunizationValue));
    DateField positiveTestResultDate = addField(ImmunizationDto.POSITIVE_TEST_RESULT_DATE, DateField.class);
    DateField recoveryDate = addField(ImmunizationDto.RECOVERY_DATE, DateField.class);
    Button linkImmunizationToCaseButton;
    if (relatedCase != null) {
        linkImmunizationToCaseButton = ButtonHelper.createButton(Captions.openLinkedCaseToImmunizationButton, e -> ControllerProvider.getCaseController().navigateToCase(relatedCase.getUuid()), ValoTheme.BUTTON_PRIMARY, FORCE_CAPTION);
    } else {
        linkImmunizationToCaseButton = ButtonHelper.createButton(Captions.linkImmunizationToCaseButton, e -> buildAndOpenSearchSpecificCaseWindow(), ValoTheme.BUTTON_PRIMARY, FORCE_CAPTION);
    }
    getContent().addComponent(linkImmunizationToCaseButton, LINK_IMMUNIZATION_TO_CASE_BTN_LOC);
    linkImmunizationToCaseButton.setVisible(shouldShowRecoveryFields(meansOfImmunizationValue));
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, ImmunizationDto.REPORT_DATE, ImmunizationDto.DISEASE, ImmunizationDto.MEANS_OF_IMMUNIZATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(ImmunizationDto.DISEASE_DETAILS), ImmunizationDto.DISEASE, Arrays.asList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), ImmunizationDto.DISEASE, Arrays.asList(ImmunizationDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS), ImmunizationDto.MEANS_OF_IMMUNIZATION, Collections.singletonList(MeansOfImmunization.OTHER), true);
    overwriteImmunizationManagementStatus.addValueChangeListener(valueChangeEvent -> {
        boolean selectedValue = (boolean) valueChangeEvent.getProperty().getValue();
        if (!selectedValue) {
            ImmunizationManagementStatus value = getValue().getImmunizationManagementStatus();
            managementStatusField.setValue(value);
        }
        managementStatusField.setEnabled(selectedValue);
        ignoreMeansOfImmunizationChange = selectedValue;
    });
    meansOfImmunizationField.addValueChangeListener(valueChangeEvent -> {
        MeansOfImmunization meansOfImmunization = (MeansOfImmunization) valueChangeEvent.getProperty().getValue();
        boolean isVaccinationVisible = shouldShowVaccinationFields(meansOfImmunization);
        boolean isRecoveryVisible = shouldShowRecoveryFields(meansOfImmunization);
        if (!ignoreMeansOfImmunizationChange) {
            if (MeansOfImmunization.RECOVERY.equals(meansOfImmunization) || MeansOfImmunization.OTHER.equals(meansOfImmunization)) {
                managementStatusField.setValue(ImmunizationManagementStatus.COMPLETED);
                if (CollectionUtils.isNotEmpty(vaccinationsField.getValue())) {
                    VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingDeleteVaccinations), new Label(I18nProperties.getString(Strings.messageDeleteImmunizationVaccinations)), questionWindow -> {
                        ConfirmationComponent confirmationComponent = new ConfirmationComponent(false) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            protected void onConfirm() {
                                vaccinationsField.clear();
                                previousMeansOfImmunization = meansOfImmunization;
                                if (!isVaccinationVisible) {
                                    numberOfDosesField.setValue(null);
                                }
                                questionWindow.close();
                            }

                            @Override
                            protected void onCancel() {
                                ignoreMeansOfImmunizationChange = true;
                                meansOfImmunizationField.setValue(previousMeansOfImmunization);
                                ignoreMeansOfImmunizationChange = false;
                                questionWindow.close();
                            }
                        };
                        confirmationComponent.getConfirmButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
                        confirmationComponent.getCancelButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
                        return confirmationComponent;
                    }, null);
                } else {
                    previousMeansOfImmunization = meansOfImmunization;
                }
            } else {
                previousMeansOfImmunization = meansOfImmunization;
            }
        }
        vaccinationHeadingLabel.setVisible(isVaccinationVisible);
        numberOfDosesField.setVisible(isVaccinationVisible);
        numberOfDosesDetailsField.setVisible(isVaccinationVisible && getValue().getNumberOfDosesDetails() != null);
        recoveryHeadingLabel.setVisible(isRecoveryVisible);
        positiveTestResultDate.setVisible(isRecoveryVisible);
        recoveryDate.setVisible(isRecoveryVisible);
    });
    managementStatusField.addValueChangeListener(valueChangeEvent -> {
        ImmunizationManagementStatus managementStatusValue = (ImmunizationManagementStatus) valueChangeEvent.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;
        }
    });
    setReadOnly(true, ImmunizationDto.REPORTING_USER);
    FieldHelper.setVisibleWhen(getFieldGroup(), ImmunizationDto.LAST_INFECTION_DATE, ImmunizationDto.PREVIOUS_INFECTION, Collections.singletonList(YesNoUnknown.YES), true);
    meansOfImmunizationField.addValueChangeListener(e -> {
        if (shouldShowRecoveryFields((MeansOfImmunization) e.getProperty().getValue())) {
            positiveTestResultDate.setVisible(true);
            recoveryDate.setVisible(true);
            linkImmunizationToCaseButton.setVisible(true);
        } else {
            positiveTestResultDate.setVisible(false);
            recoveryDate.setVisible(false);
            linkImmunizationToCaseButton.setVisible(false);
        }
    });
    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 -> {
        if (facilityTypeGroup.getValue() == null) {
            facilityType.clear();
        }
        FieldHelper.updateEnumData(facilityType, facilityTypeGroup.getValue() != null ? FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()) : Arrays.stream(FacilityType.values()).collect(Collectors.toList()));
    });
    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);
    });
    addValueChangeListener(e -> {
        FacilityType facilityTypeValue = getValue().getFacilityType();
        if (facilityTypeValue != null) {
            facilityTypeGroup.setValue(facilityTypeValue.getFacilityTypeGroup());
            facilityCombo.setValue(getValue().getHealthFacility());
            facilityDetails.setValue(getValue().getHealthFacilityDetails());
        }
    });
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) UI(com.vaadin.ui.UI) Window(com.vaadin.ui.Window) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) FORCE_CAPTION(de.symeda.sormas.ui.utils.CssStyles.FORCE_CAPTION) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) Descriptions(de.symeda.sormas.api.i18n.Descriptions) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) SearchSpecificLayout(de.symeda.sormas.ui.SearchSpecificLayout) FacadeProvider(de.symeda.sormas.api.FacadeProvider) Converter(com.vaadin.v7.data.util.converter.Converter) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) CollectionUtils(org.apache.commons.collections.CollectionUtils) SormasUI(de.symeda.sormas.ui.SormasUI) Label(com.vaadin.ui.Label) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) 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) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ResizableTextAreaWrapper(de.symeda.sormas.ui.utils.ResizableTextAreaWrapper) 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) Button(com.vaadin.ui.Button) Disease(de.symeda.sormas.api.Disease) TextArea(com.vaadin.v7.ui.TextArea) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) 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) Disease(de.symeda.sormas.api.Disease) TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) VaccinationsField(de.symeda.sormas.ui.vaccination.VaccinationsField) DateField(com.vaadin.v7.ui.DateField) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 2 with ImmunizationManagementStatus

use of de.symeda.sormas.api.immunization.ImmunizationManagementStatus in project SORMAS-Project by hzi-braunschweig.

the class DatabaseHelper method migrateVaccinationInfo.

private void migrateVaccinationInfo() throws SQLException {
    // Retrieve all new unsynchronized cases with vaccinationStatus == VACCINATED from the database
    GenericRawResults<Object[]> caseInfoResult = getDao(Case.class).queryRaw("SELECT cases.id, person_id, disease, diseaseDetails, reportDate, reportingUser_id, responsibleRegion_id, responsibleDistrict_id, " + "responsibleCommunity_id, COALESCE(symptoms.onsetDate, cases.reportDate), firstVaccinationDate, vaccinationDate, vaccinationDoses, vaccineName, otherVaccineName, vaccine, " + "vaccineManufacturer, otherVaccineManufacturer, vaccinationInfoSource, vaccineInn, vaccineBatchNumber, vaccineUniiCode, vaccineAtcCode," + "pregnant, trimester, healthConditions_id FROM cases LEFT JOIN clinicalCourse ON cases.clinicalCourse_id = clinicalCourse.id " + "LEFT JOIN symptoms ON cases.symptoms_id = symptoms.id WHERE cases.snapshot = 0 AND cases.changeDate = 0 AND vaccination = 'VACCINATED';", new DataType[] { // 0: cases.id
    DataType.BIG_INTEGER, // 1: person_id
    DataType.BIG_INTEGER, // 2: disease
    DataType.ENUM_STRING, // 3: diseaseDetails
    DataType.STRING, // 4: reportDate
    DataType.DATE_LONG, // 5: reportingUser_id
    DataType.BIG_INTEGER, // 6: responsibleRegion_id
    DataType.BIG_INTEGER, // 7: responsibleDistrict_id
    DataType.BIG_INTEGER, // 8: responsibleCommunity_id
    DataType.BIG_INTEGER, // 9: symptoms.onsetDate OR cases.reportDate
    DataType.DATE_LONG, // 10: firstVaccinationDate
    DataType.DATE_LONG, // 11: vaccinationDate
    DataType.DATE_LONG, // 12: vaccinationDoses
    DataType.STRING, // 13: vaccineName
    DataType.ENUM_STRING, // 14: otherVaccineName
    DataType.STRING, // 15: vaccine
    DataType.STRING, // 16: vaccineManufacturer
    DataType.ENUM_STRING, // 17: otherVaccineManufacturer
    DataType.STRING, // 18: vaccinationInfoSource
    DataType.ENUM_STRING, // 19: vaccineInn
    DataType.STRING, // 20: vaccineBatchNumber
    DataType.STRING, // 21: vaccineUniiCode
    DataType.STRING, // 22: vaccineAtcCode
    DataType.STRING, // 23: pregnant
    DataType.ENUM_STRING, // 24: trimester
    DataType.ENUM_STRING, // 25: healthConditions_id
    DataType.BIG_INTEGER });
    List<Object[]> caseInfoList = caseInfoResult.getResults();
    for (Object[] caseInfo : caseInfoList) {
        doNullCheckOnString(caseInfo, 3);
        doNullCheckOnString(caseInfo, 14);
        doNullCheckOnString(caseInfo, 15);
        doNullCheckOnString(caseInfo, 17);
        doNullCheckOnString(caseInfo, 19);
        doNullCheckOnString(caseInfo, 20);
        doNullCheckOnString(caseInfo, 21);
        doNullCheckOnString(caseInfo, 22);
        formatRawResultDate(caseInfo, 4);
        formatRawResultDate(caseInfo, 9);
        formatRawResultDate(caseInfo, 10);
        formatRawResultDate(caseInfo, 11);
        if (DataHelper.isNullOrEmpty((String) caseInfo[12])) {
            Array.set(caseInfo, 12, null);
        } else {
            try {
                Array.set(caseInfo, 12, new Integer((String) caseInfo[12]));
            } catch (NumberFormatException e) {
                Array.set(caseInfo, 12, 1);
            }
        }
    }
    // Retrieve earlier cases of each person for each disease
    Comparator<Object[]> comparator = Comparator.comparing(c -> new Date((Long) c[9]));
    List<Object[]> filteredCaseInfo = new ArrayList<>();
    Map<Disease, List<Object[]>> caseInfoByDisease = caseInfoList.stream().collect(Collectors.groupingBy(c -> Disease.valueOf((String) c[2])));
    caseInfoByDisease.keySet().forEach(d -> {
        filteredCaseInfo.addAll(caseInfoByDisease.get(d).stream().sorted(comparator).collect(Collectors.collectingAndThen(Collectors.toMap(c -> ((BigInteger) c[1]), Function.identity(), (c1, c2) -> new Date((Long) c1[9]).after(new Date((Long) c2[9])) ? c1 : c2), r -> new ArrayList<>(r.values()))));
    });
    filteredCaseInfo.forEach(objects -> {
        // Retrieve all cases of the case person with the respective disease
        final Object caseId = objects[0];
        final Object personId = objects[1];
        final List<Object[]> objectList = caseInfoByDisease.get(Disease.valueOf((String) objects[2])).stream().filter(c -> ((BigInteger) c[0]).intValue() != ((BigInteger) caseId).intValue() && ((BigInteger) c[1]).intValue() == ((BigInteger) personId).intValue()).collect(Collectors.toList());
        // set earliest report date
        Comparator<Object[]> reportDateComparator = Comparator.comparing(c -> new Date((Long) c[4]));
        objectList.stream().min(reportDateComparator).ifPresent(earliestObject -> {
            objects[4] = earliestObject[4];
        });
        // set earliest first vaccination date
        if (objects[10] == null) {
            Comparator<Object[]> firstVacDateComparator = Comparator.comparing(c -> new Date((Long) c[10]));
            objectList.stream().filter(c -> c[10] != null).max(firstVacDateComparator).ifPresent(earliestObject -> {
                objects[10] = earliestObject[10];
            });
        }
        // set latest last vaccination date
        if (objects[11] == null) {
            Comparator<Object[]> lastVacDateComparator = Comparator.comparing(c -> new Date((Long) c[11]));
            objectList.stream().filter(c -> c[11] != null).min(lastVacDateComparator).ifPresent(earliestObject -> {
                objects[11] = earliestObject[11];
            });
        }
        // set latest available vaccine name
        if (objects[13] == null) {
            objectList.stream().filter(c -> c[13] != null).min(comparator).ifPresent(latestObject -> {
                objects[13] = latestObject[13];
                objects[14] = latestObject[14];
            });
        }
        // set latest available vaccine
        if (objects[15] == null) {
            objectList.stream().filter(c -> c[15] != null).min(comparator).ifPresent(latestObject -> objects[15] = latestObject[15]);
        }
        // set latest available vaccine manufacturer
        if (objects[16] == null) {
            objectList.stream().filter(c -> c[16] != null).min(comparator).ifPresent(latestObject -> {
                objects[16] = latestObject[16];
                objects[17] = latestObject[17];
            });
        }
        // set latest available vaccination info source
        if (objects[18] == null) {
            objectList.stream().filter(c -> c[18] != null).min(comparator).ifPresent(latestObject -> objects[18] = latestObject[18]);
        }
        // set latest available INN
        if (objects[19] == null) {
            objectList.stream().filter(c -> c[19] != null).min(comparator).ifPresent(latestObject -> objects[19] = latestObject[19]);
        }
        // set latest available batch number
        if (objects[20] == null) {
            objectList.stream().filter(c -> c[20] != null).min(comparator).ifPresent(latestObject -> objects[20] = latestObject[20]);
        }
        // set latest available UNII code
        if (objects[21] == null) {
            objectList.stream().filter(c -> c[21] != null).min(comparator).ifPresent(latestObject -> objects[21] = latestObject[21]);
        }
        // set latest available ATC code
        if (objects[22] == null) {
            objectList.stream().filter(c -> c[22] != null).min(comparator).ifPresent(latestObject -> objects[22] = latestObject[22]);
        }
    });
    // Create immunizations and vaccinations for each case
    for (Object[] caseInfo : filteredCaseInfo) {
        // Create immunization
        String immunizationInsertQuery = "INSERT INTO immunization " + "(" + "		uuid, changeDate, localChangeDate, creationDate, person_id," + "		disease, diseaseDetails, reportDate, reportingUser_id, immunizationStatus, meansOfImmunization, immunizationManagementStatus," + "		responsibleRegion_id, responsibleDistrict_id, responsibleCommunity_id, startDate, endDate, numberOfDoses, pseudonymized," + "		modified, snapshot" + ")" + "VALUES (?, ?, " + generateDateNowSQL() + ", " + generateDateNowSQL() + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        executeRaw(Immunization.class, immunizationInsertQuery, DataHelper.createUuid(), 0, caseInfo[1], caseInfo[2], caseInfo[3], caseInfo[4], caseInfo[5], ImmunizationStatus.ACQUIRED.name(), MeansOfImmunization.VACCINATION.name(), ImmunizationManagementStatus.COMPLETED.name(), caseInfo[6], caseInfo[7], caseInfo[8], caseInfo[10], caseInfo[11], caseInfo[12], 0, 1, 0);
        if (caseInfo[12] == null) {
            // No vaccination doses specified
            if (caseInfo[10] != null || caseInfo[11] == null) {
                cloneHealthConditions(caseInfo[25]);
                insertFirstVaccination(caseInfo, caseInfo[10]);
            }
            // Last vaccination
            if (caseInfo[11] != null || ("ASTRA_ZENECA_COMIRNATY".equals(caseInfo[13]) || "ASTRA_ZENECA_MRNA_1273".equals(caseInfo[13]))) {
                cloneHealthConditions(caseInfo[25]);
                insertVaccination(caseInfo, caseInfo[11]);
            }
        } else {
            // Vaccination doses specified
            int vaccinationDoses = (int) caseInfo[12];
            if (vaccinationDoses == 1) {
                cloneHealthConditions(caseInfo[25]);
                insertFirstVaccination(caseInfo, caseInfo[11] != null ? caseInfo[11] : caseInfo[10]);
            } else {
                cloneHealthConditions(caseInfo[25]);
                insertFirstVaccination(caseInfo, caseInfo[10]);
                for (int i = 2; i <= vaccinationDoses - 1; i++) {
                    cloneHealthConditions(caseInfo[25]);
                    insertVaccination(caseInfo, null);
                }
                cloneHealthConditions(caseInfo[25]);
                insertVaccination(caseInfo, caseInfo[11]);
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) AggregateReport(de.symeda.sormas.app.backend.report.AggregateReport) Vaccine(de.symeda.sormas.api.caze.Vaccine) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Region(de.symeda.sormas.app.backend.region.Region) StringUtils(org.apache.commons.lang3.StringUtils) CampaignDao(de.symeda.sormas.app.backend.campaign.CampaignDao) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) VaccineManufacturer(de.symeda.sormas.api.caze.VaccineManufacturer) ClinicalCourse(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourse) RegionDao(de.symeda.sormas.app.backend.region.RegionDao) Map(java.util.Map) BigInteger(java.math.BigInteger) AnimalContactType(de.symeda.sormas.api.exposure.AnimalContactType) TreatmentDao(de.symeda.sormas.app.backend.therapy.TreatmentDao) Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination) Log(android.util.Log) LbdsSync(de.symeda.sormas.app.backend.lbds.LbdsSync) SampleDao(de.symeda.sormas.app.backend.sample.SampleDao) WeeklyReportDao(de.symeda.sormas.app.backend.report.WeeklyReportDao) Campaign(de.symeda.sormas.app.backend.campaign.Campaign) Hospitalization(de.symeda.sormas.app.backend.hospitalization.Hospitalization) PersonDao(de.symeda.sormas.app.backend.person.PersonDao) HospitalizationDao(de.symeda.sormas.app.backend.hospitalization.HospitalizationDao) ConfigDao(de.symeda.sormas.app.backend.config.ConfigDao) Dao(com.j256.ormlite.dao.Dao) DataType(com.j256.ormlite.field.DataType) AreaDao(de.symeda.sormas.app.backend.region.AreaDao) Country(de.symeda.sormas.app.backend.region.Country) Stream(java.util.stream.Stream) DiseaseClassificationCriteria(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteria) District(de.symeda.sormas.app.backend.region.District) Visit(de.symeda.sormas.app.backend.visit.Visit) HealthConditionsDao(de.symeda.sormas.app.backend.clinicalcourse.HealthConditionsDao) LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) SubcontinentDao(de.symeda.sormas.app.backend.region.SubcontinentDao) Location(de.symeda.sormas.app.backend.location.Location) TypeOfAnimal(de.symeda.sormas.api.exposure.TypeOfAnimal) SyncLogDao(de.symeda.sormas.app.backend.synclog.SyncLogDao) FeatureConfiguration(de.symeda.sormas.app.backend.feature.FeatureConfiguration) CountryDao(de.symeda.sormas.app.backend.region.CountryDao) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) CampaignFormMetaDao(de.symeda.sormas.app.backend.campaign.form.CampaignFormMetaDao) EpiData(de.symeda.sormas.app.backend.epidata.EpiData) ArrayList(java.util.ArrayList) WeeklyReportEntry(de.symeda.sormas.app.backend.report.WeeklyReportEntry) SQLException(java.sql.SQLException) ConnectionSource(com.j256.ormlite.support.ConnectionSource) Contact(de.symeda.sormas.app.backend.contact.Contact) Therapy(de.symeda.sormas.app.backend.therapy.Therapy) AnimalCondition(de.symeda.sormas.api.epidata.AnimalCondition) PersonContactDetailDao(de.symeda.sormas.app.backend.person.PersonContactDetailDao) Event(de.symeda.sormas.app.backend.event.Event) Symptoms(de.symeda.sormas.app.backend.symptoms.Symptoms) SormasToSormasOriginInfoDao(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfoDao) ClinicalCourseDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourseDao) PointOfEntryDao(de.symeda.sormas.app.backend.infrastructure.PointOfEntryDao) DataHelper(de.symeda.sormas.api.utils.DataHelper) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) Continent(de.symeda.sormas.app.backend.region.Continent) ActivityAsCaseDao(de.symeda.sormas.app.backend.activityascase.ActivityAsCaseDao) TextUtils(android.text.TextUtils) PersonContactDetail(de.symeda.sormas.app.backend.person.PersonContactDetail) Outbreak(de.symeda.sormas.app.backend.outbreak.Outbreak) Disease(de.symeda.sormas.api.Disease) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) ClinicalVisitDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisitDao) PreviousHospitalizationDao(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalizationDao) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) SymptomsDao(de.symeda.sormas.app.backend.symptoms.SymptomsDao) HealthConditions(de.symeda.sormas.app.backend.clinicalcourse.HealthConditions) PrescriptionDao(de.symeda.sormas.app.backend.therapy.PrescriptionDao) ClinicalVisit(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit) ContactDao(de.symeda.sormas.app.backend.contact.ContactDao) FeatureConfigurationDao(de.symeda.sormas.app.backend.feature.FeatureConfigurationDao) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) ActivityAsCase(de.symeda.sormas.app.backend.activityascase.ActivityAsCase) MaternalHistory(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistory) Array(java.lang.reflect.Array) Community(de.symeda.sormas.app.backend.region.Community) Date(java.util.Date) ExposureDao(de.symeda.sormas.app.backend.exposure.ExposureDao) AggregateReportDao(de.symeda.sormas.app.backend.report.AggregateReportDao) ExposureType(de.symeda.sormas.api.exposure.ExposureType) Exposure(de.symeda.sormas.app.backend.exposure.Exposure) Facility(de.symeda.sormas.app.backend.facility.Facility) FacilityDao(de.symeda.sormas.app.backend.facility.FacilityDao) ContinentDao(de.symeda.sormas.app.backend.region.ContinentDao) UserRoleConfig(de.symeda.sormas.app.backend.user.UserRoleConfig) WeeklyReport(de.symeda.sormas.app.backend.report.WeeklyReport) VisitDao(de.symeda.sormas.app.backend.visit.VisitDao) GenericRawResults(com.j256.ormlite.dao.GenericRawResults) ConfigProvider(de.symeda.sormas.app.backend.config.ConfigProvider) TableUtils(com.j256.ormlite.table.TableUtils) SyncLog(de.symeda.sormas.app.backend.synclog.SyncLog) Task(de.symeda.sormas.app.backend.task.Task) DiseaseClassificationCriteriaDao(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteriaDao) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) EventDao(de.symeda.sormas.app.backend.event.EventDao) Case(de.symeda.sormas.app.backend.caze.Case) OutbreakDao(de.symeda.sormas.app.backend.outbreak.OutbreakDao) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) AdditionalTest(de.symeda.sormas.app.backend.sample.AdditionalTest) Collectors(java.util.stream.Collectors) CampaignFormMeta(de.symeda.sormas.app.backend.campaign.form.CampaignFormMeta) Objects(java.util.Objects) ImmunizationDao(de.symeda.sormas.app.backend.immunization.ImmunizationDao) List(java.util.List) DiseaseConfigurationDao(de.symeda.sormas.app.backend.disease.DiseaseConfigurationDao) OrmLiteSqliteOpenHelper(com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) LocationDao(de.symeda.sormas.app.backend.location.LocationDao) DiseaseConfiguration(de.symeda.sormas.app.backend.disease.DiseaseConfiguration) Context(android.content.Context) PointOfEntry(de.symeda.sormas.app.backend.infrastructure.PointOfEntry) PreviousHospitalization(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization) AdditionalTestDao(de.symeda.sormas.app.backend.sample.AdditionalTestDao) VaccinationDao(de.symeda.sormas.app.backend.vaccination.VaccinationDao) HashMap(java.util.HashMap) HabitationType(de.symeda.sormas.api.exposure.HabitationType) Treatment(de.symeda.sormas.app.backend.therapy.Treatment) Function(java.util.function.Function) User(de.symeda.sormas.app.backend.user.User) WeeklyReportEntryDao(de.symeda.sormas.app.backend.report.WeeklyReportEntryDao) EventParticipantDao(de.symeda.sormas.app.backend.event.EventParticipantDao) CampaignFormData(de.symeda.sormas.app.backend.campaign.data.CampaignFormData) Area(de.symeda.sormas.app.backend.region.Area) CustomizableEnumValueDao(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValueDao) Subcontinent(de.symeda.sormas.app.backend.region.Subcontinent) Cursor(android.database.Cursor) CampaignFormDataDao(de.symeda.sormas.app.backend.campaign.data.CampaignFormDataDao) UserRoleConfigDao(de.symeda.sormas.app.backend.user.UserRoleConfigDao) PortHealthInfoDao(de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfoDao) Person(de.symeda.sormas.app.backend.person.Person) CustomizableEnumValue(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValue) Config(de.symeda.sormas.app.backend.config.Config) SormasToSormasOriginInfo(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfo) CommunityDao(de.symeda.sormas.app.backend.region.CommunityDao) UserDao(de.symeda.sormas.app.backend.user.UserDao) Sample(de.symeda.sormas.app.backend.sample.Sample) EpiDataDao(de.symeda.sormas.app.backend.epidata.EpiDataDao) DistrictDao(de.symeda.sormas.app.backend.region.DistrictDao) PortHealthInfo(de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfo) Prescription(de.symeda.sormas.app.backend.therapy.Prescription) PathogenTestDao(de.symeda.sormas.app.backend.sample.PathogenTestDao) TherapyDao(de.symeda.sormas.app.backend.therapy.TherapyDao) Comparator(java.util.Comparator) MaternalHistoryDao(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistoryDao) Disease(de.symeda.sormas.api.Disease) ArrayList(java.util.ArrayList) Date(java.util.Date) ActivityAsCase(de.symeda.sormas.app.backend.activityascase.ActivityAsCase) Case(de.symeda.sormas.app.backend.caze.Case) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ImmunizationManagementStatus

use of de.symeda.sormas.api.immunization.ImmunizationManagementStatus 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);
    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);
    addCustomField(PersonDto.FIRST_NAME, String.class, TextField.class);
    addCustomField(PersonDto.LAST_NAME, String.class, TextField.class);
    Button searchPersonButton = createPersonSearchButton(PERSON_SEARCH_LOC);
    getContent().addComponent(searchPersonButton, PERSON_SEARCH_LOC);
    TextField nationalHealthIdField = addCustomField(PersonDto.NATIONAL_HEALTH_ID, String.class, TextField.class);
    TextField passportNumberField = addCustomField(PersonDto.PASSPORT_NUMBER, String.class, TextField.class);
    if (CountryHelper.isCountry(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY)) {
        nationalHealthIdField.setVisible(false);
    }
    if (CountryHelper.isInCountries(FacadeProvider.getConfigFacade().getCountryLocale(), CountryHelper.COUNTRY_CODE_GERMANY, CountryHelper.COUNTRY_CODE_FRANCE)) {
        passportNumberField.setVisible(false);
    }
    birthDateDay = addCustomField(PersonDto.BIRTH_DATE_DD, Integer.class, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.addStyleName(FORCE_CAPTION);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    ComboBox birthDateMonth = addCustomField(PersonDto.BIRTH_DATE_MM, Integer.class, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    birthDateMonth.addStyleName(FORCE_CAPTION);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addCustomField(PersonDto.BIRTH_DATE_YYYY, Integer.class, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID_TOSTRING);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
    });
    ComboBox sex = addCustomField(PersonDto.SEX, Sex.class, ComboBox.class);
    sex.setCaption(I18nProperties.getCaption(Captions.Person_sex));
    ComboBox presentCondition = addCustomField(PersonDto.PRESENT_CONDITION, PresentCondition.class, ComboBox.class);
    presentCondition.setCaption(I18nProperties.getCaption(Captions.Person_presentCondition));
    TextField phone = addCustomField(PersonDto.PHONE, String.class, TextField.class);
    phone.setCaption(I18nProperties.getCaption(Captions.Person_phone));
    TextField email = addCustomField(PersonDto.EMAIL_ADDRESS, String.class, TextField.class);
    email.setCaption(I18nProperties.getCaption(Captions.Person_emailAddress));
    phone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, phone.getCaption())));
    email.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, email.getCaption())));
    // 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) {
            setVisible(false, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX, PersonDto.NATIONAL_HEALTH_ID, PersonDto.PASSPORT_NUMBER, PersonDto.BIRTH_DATE_DD, PersonDto.BIRTH_DATE_MM, PersonDto.BIRTH_DATE_YYYY, PersonDto.PRESENT_CONDITION, PersonDto.PHONE, PersonDto.EMAIL_ADDRESS);
            setReadOnly(false, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX, PersonDto.NATIONAL_HEALTH_ID, PersonDto.PASSPORT_NUMBER, PersonDto.BIRTH_DATE_DD, PersonDto.BIRTH_DATE_MM, PersonDto.BIRTH_DATE_YYYY, PersonDto.PRESENT_CONDITION, PersonDto.PHONE, PersonDto.EMAIL_ADDRESS);
            searchPersonButton.setVisible(false);
        } else {
            setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
        }
    });
}
Also used : EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) Button(com.vaadin.ui.Button) 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

ImmunizationManagementStatus (de.symeda.sormas.api.immunization.ImmunizationManagementStatus)3 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)3 Button (com.vaadin.ui.Button)2 Label (com.vaadin.ui.Label)2 CheckBox (com.vaadin.v7.ui.CheckBox)2 ComboBox (com.vaadin.v7.ui.ComboBox)2 DateField (com.vaadin.v7.ui.DateField)2 Field (com.vaadin.v7.ui.Field)2 TextField (com.vaadin.v7.ui.TextField)2 Disease (de.symeda.sormas.api.Disease)2 ImmunizationStatus (de.symeda.sormas.api.immunization.ImmunizationStatus)2 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)2 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)2 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)2 FacilityTypeGroup (de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)2 YesNoUnknown (de.symeda.sormas.api.utils.YesNoUnknown)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 TextUtils (android.text.TextUtils)1