Search in sources :

Example 1 with CommunityReferenceDto

use of de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto 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 CommunityReferenceDto

use of de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantImporter method insertColumnEntryIntoData.

/**
 * Inserts the entry of a single cell into the eventparticipant or its person.
 */
private void insertColumnEntryIntoData(EventParticipantDto eventParticipant, PersonDto person, String entry, String[] entryHeaderPath) throws InvalidColumnException, ImportErrorException {
    Object currentElement = eventParticipant;
    for (int i = 0; i < entryHeaderPath.length; i++) {
        String headerPathElementName = entryHeaderPath[i];
        try {
            if (i != entryHeaderPath.length - 1) {
                currentElement = new PropertyDescriptor(headerPathElementName, currentElement.getClass()).getReadMethod().invoke(currentElement);
                // Set the current element to the created person
                if (currentElement instanceof PersonReferenceDto) {
                    currentElement = person;
                }
            } else if (EventParticipantExportDto.BIRTH_DATE.equals(headerPathElementName)) {
                BirthDateDto birthDateDto = PersonHelper.parseBirthdate(entry, currentUser.getLanguage());
                if (birthDateDto != null) {
                    person.setBirthdateDD(birthDateDto.getDateOfBirthDD());
                    person.setBirthdateMM(birthDateDto.getDateOfBirthMM());
                    person.setBirthdateYYYY(birthDateDto.getDateOfBirthYYYY());
                }
            } else {
                PropertyDescriptor pd = new PropertyDescriptor(headerPathElementName, currentElement.getClass());
                Class<?> propertyType = pd.getPropertyType();
                // according to the types of the eventparticipant or person fields
                if (executeDefaultInvoke(pd, currentElement, entry, entryHeaderPath)) {
                    continue;
                } else if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) {
                    List<DistrictReferenceDto> district = FacadeProvider.getDistrictFacade().getByName(entry, ImporterPersonHelper.getRegionBasedOnDistrict(pd.getName(), null, person, currentElement), false);
                    if (district.isEmpty()) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, entry, buildEntityProperty(entryHeaderPath)));
                    } else if (district.size() > 1) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pd.getWriteMethod().invoke(currentElement, district.get(0));
                    }
                } else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) {
                    List<CommunityReferenceDto> community = FacadeProvider.getCommunityFacade().getByName(entry, ImporterPersonHelper.getPersonDistrict(pd.getName(), person), false);
                    if (community.isEmpty()) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
                    } else if (community.size() > 1) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCommunityNotUnique, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pd.getWriteMethod().invoke(currentElement, community.get(0));
                    }
                } else if (propertyType.isAssignableFrom(FacilityReferenceDto.class)) {
                    DataHelper.Pair<DistrictReferenceDto, CommunityReferenceDto> infrastructureData = ImporterPersonHelper.getPersonDistrictAndCommunity(pd.getName(), person);
                    List<FacilityReferenceDto> facility = FacadeProvider.getFacilityFacade().getByNameAndType(entry, infrastructureData.getElement0(), infrastructureData.getElement1(), getTypeOfFacility(pd.getName(), currentElement), false);
                    if (facility.isEmpty()) {
                        if (infrastructureData.getElement1() != null) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrCommunity, entry, buildEntityProperty(entryHeaderPath)));
                        } else {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
                        }
                    } else if (facility.size() > 1 && infrastructureData.getElement1() == null) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importFacilityNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath)));
                    } else if (facility.size() > 1 && infrastructureData.getElement1() != null) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importFacilityNotUniqueInCommunity, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pd.getWriteMethod().invoke(currentElement, facility.get(0));
                    }
                } else {
                    throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
                }
            }
        } catch (IntrospectionException e) {
            throw new InvalidColumnException(buildEntityProperty(entryHeaderPath));
        } catch (InvocationTargetException | IllegalAccessException e) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importErrorInColumn, buildEntityProperty(entryHeaderPath)));
        } catch (IllegalArgumentException e) {
            throw new ImportErrorException(entry, buildEntityProperty(entryHeaderPath));
        } catch (ImportErrorException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error("Unexpected error when trying to import an eventparticipant: " + e.getMessage(), e);
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCasesUnexpectedError));
        }
    }
    ImportLineResultDto<EventParticipantDto> constraintErrors = validateConstraints(eventParticipant);
    if (constraintErrors.isError()) {
        throw new ImportErrorException(constraintErrors.getMessage());
    }
}
Also used : FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) IntrospectionException(java.beans.IntrospectionException) DataHelper(de.symeda.sormas.api.utils.DataHelper) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) ArrayList(java.util.ArrayList) PropertyDescriptor(java.beans.PropertyDescriptor) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) CsvValidationException(com.opencsv.exceptions.CsvValidationException) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) IOException(java.io.IOException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto)

Example 3 with CommunityReferenceDto

use of de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method applyDependenciesOnFieldChange.

@Override
protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueChangeEvent event) {
    super.applyDependenciesOnFieldChange(propertyId, event);
    final ImmunizationCriteria criteria = getValue();
    final ComboBox districtField = getField(ImmunizationCriteria.DISTRICT);
    final ComboBox communityField = getField(ImmunizationCriteria.COMMUNITY);
    final ComboBox facilityTypeGroupField = getField(ImmunizationCriteria.FACILITY_TYPE_GROUP);
    final ComboBox facilityTypeField = getField(ImmunizationCriteria.FACILITY_TYPE);
    final ComboBox facilityField = getField(ImmunizationCriteria.HEALTH_FACILITY);
    final UserDto user = currentUserDto();
    final DistrictReferenceDto currentDistrict = user.getDistrict() != null ? user.getDistrict() : (DistrictReferenceDto) districtField.getValue();
    switch(propertyId) {
        case ImmunizationCriteria.REGION:
            {
                final RegionReferenceDto region = user.getRegion() != null ? user.getRegion() : (RegionReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(region, criteria.getRegion())) {
                    if (region != null) {
                        enableFields(districtField);
                        FieldHelper.updateItems(districtField, FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
                    } else {
                        clearAndDisableFields(districtField);
                    }
                    clearAndDisableFields(communityField, facilityField, facilityTypeField, facilityTypeGroupField);
                }
                break;
            }
        case ImmunizationCriteria.DISTRICT:
            {
                final DistrictReferenceDto newDistrict = (DistrictReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(newDistrict, criteria.getDistrict())) {
                    if (newDistrict != null) {
                        enableFields(communityField, facilityTypeGroupField);
                        clearAndDisableFields(facilityField);
                        if (facilityTypeGroupField != null) {
                            if (facilityTypeGroupField.getValue() != null && facilityTypeField.getValue() != null) {
                                FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(newDistrict, (FacilityType) facilityTypeField.getValue(), true, false));
                                enableFields(facilityField);
                            } else {
                                FieldHelper.updateEnumData(facilityTypeGroupField, FacilityTypeGroup.getAccomodationGroups());
                            }
                        }
                        FieldHelper.updateItems(communityField, FacadeProvider.getCommunityFacade().getAllActiveByDistrict(newDistrict.getUuid()));
                    } else {
                        clearAndDisableFields(communityField, facilityField, facilityTypeField, facilityTypeGroupField);
                    }
                }
                break;
            }
        case ImmunizationCriteria.COMMUNITY:
            {
                CommunityReferenceDto community = (CommunityReferenceDto) event.getProperty().getValue();
                if (!DataHelper.equal(community, criteria.getCommunity())) {
                    if (facilityField != null) {
                        facilityField.setValue(null);
                    }
                    final FacilityType facilityType = facilityTypeField != null ? (FacilityType) facilityTypeField.getValue() : null;
                    if (facilityType == null && facilityField != null) {
                        facilityField.removeAllItems();
                    } else if (facilityField != null) {
                        if (community == null) {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(currentDistrict, facilityType, true, false));
                        } else {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                        }
                    }
                }
                break;
            }
        case ImmunizationCriteria.FACILITY_TYPE_GROUP:
            {
                FacilityTypeGroup typeGroup = (FacilityTypeGroup) event.getProperty().getValue();
                if (!DataHelper.equal(typeGroup, criteria.getFacilityTypeGroup())) {
                    if (typeGroup != null) {
                        enableFields(ImmunizationCriteria.FACILITY_TYPE);
                        FieldHelper.updateEnumData(facilityTypeField, FacilityType.getAccommodationTypes(typeGroup));
                        facilityField.setValue(null);
                    } else {
                        clearAndDisableFields(facilityTypeField, facilityField);
                    }
                }
                break;
            }
        case ImmunizationCriteria.FACILITY_TYPE:
            {
                FacilityType facilityType = (FacilityType) event.getProperty().getValue();
                if (!DataHelper.equal(facilityType, criteria.getFacilityType())) {
                    if (facilityType == null) {
                        clearAndDisableFields(facilityField);
                    } else {
                        enableFields(facilityField);
                        facilityField.setValue(null);
                        CommunityReferenceDto community = (CommunityReferenceDto) communityField.getValue();
                        if (community != null) {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                        } else if (currentDistrict != null) {
                            FieldHelper.updateItems(facilityField, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(currentDistrict, facilityType, true, false));
                        }
                    }
                }
                break;
            }
        case ImmunizationCriteria.BIRTHDATE_MM:
            {
                Integer birthMM = (Integer) event.getProperty().getValue();
                ComboBox birthDayDD = getField(ImmunizationCriteria.BIRTHDATE_DD);
                birthDayDD.setEnabled(birthMM != null);
                FieldHelper.updateItems(birthDayDD, DateHelper.getDaysInMonth((Integer) getField(ImmunizationCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue()));
                break;
            }
    }
}
Also used : CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ImmunizationCriteria(de.symeda.sormas.api.immunization.ImmunizationCriteria) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 4 with CommunityReferenceDto

use of de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method applyDependenciesOnNewValue.

@Override
protected void applyDependenciesOnNewValue(ImmunizationCriteria criteria) {
    final UserDto user = currentUserDto();
    UserProvider currentUserProvider = UserProvider.getCurrent();
    final JurisdictionLevel userJurisdictionLevel = currentUserProvider != null ? UserRole.getJurisdictionLevel(currentUserProvider.getUserRoles()) : null;
    final ComboBox districtField = getField(ImmunizationCriteria.DISTRICT);
    final ComboBox communityField = getField(ImmunizationCriteria.COMMUNITY);
    final ComboBox facilityTypeGroupField = getField(ImmunizationCriteria.FACILITY_TYPE_GROUP);
    final ComboBox facilityTypeField = getField(ImmunizationCriteria.FACILITY_TYPE);
    final ComboBox facilityField = getField(ImmunizationCriteria.HEALTH_FACILITY);
    // Disable all fields
    clearAndDisableFields(districtField, communityField, facilityTypeGroupField, facilityTypeField, facilityField);
    // Get initial field values according to user and criteria
    final RegionReferenceDto region = user.getRegion() == null ? criteria.getRegion() : user.getRegion();
    final DistrictReferenceDto district = user.getDistrict() == null ? criteria.getDistrict() : user.getDistrict();
    final CommunityReferenceDto community = user.getCommunity() == null ? criteria.getCommunity() : user.getCommunity();
    final FacilityTypeGroup facilityTypeGroup = criteria.getFacilityTypeGroup();
    final FacilityType facilityType = criteria.getFacilityType();
    // district
    if (region != null) {
        enableFields(districtField);
        districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        // community
        if (district != null) {
            districtField.setValue(district);
            communityField.addItems(FacadeProvider.getCommunityFacade().getAllActiveByDistrict(district.getUuid()));
            enableFields(communityField);
            if (community != null) {
                communityField.setValue(community);
            }
        } else {
            clearAndDisableFields(communityField);
        }
    } else {
        clearAndDisableFields(districtField, communityField);
    }
    // facility
    if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        facilityField.setValue(user.getHealthFacility());
        disableFields(facilityTypeGroupField, facilityTypeField, facilityField);
    } else if (facilityTypeGroupField != null && district != null) {
        enableFields(facilityTypeGroupField);
        FieldHelper.updateEnumData(facilityTypeGroupField, FacilityTypeGroup.getAccomodationGroups());
        if (facilityTypeGroup != null) {
            facilityTypeGroupField.setValue(facilityTypeGroup);
            enableFields(facilityTypeField);
            FieldHelper.updateEnumData(facilityTypeField, FacilityType.getAccommodationTypes(facilityTypeGroup));
            if (facilityType != null) {
                facilityTypeField.setValue(facilityType);
                enableFields(facilityField);
                if (community != null) {
                    facilityField.addItems(FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                } else {
                    facilityField.addItems(FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(district, facilityType, true, false));
                }
            } else {
                disableFields(facilityField);
            }
        } else {
            disableFields(facilityTypeField);
        }
    }
    // Disable fields according to user & jurisdiction
    if (userJurisdictionLevel == JurisdictionLevel.DISTRICT) {
        clearAndDisableFields(districtField);
    } else if (userJurisdictionLevel == JurisdictionLevel.COMMUNITY) {
        clearAndDisableFields(districtField, communityField);
    } else if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        clearAndDisableFields(districtField, communityField, facilityTypeGroupField, facilityTypeField, facilityField);
    }
    ComboBox birthDateDD = getField(ImmunizationCriteria.BIRTHDATE_DD);
    if (getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue() != null && getField(ImmunizationCriteria.BIRTHDATE_MM).getValue() != null) {
        birthDateDD.addItems(DateHelper.getDaysInMonth((Integer) getField(ImmunizationCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue()));
        birthDateDD.setEnabled(true);
    } else {
        birthDateDD.clear();
        birthDateDD.setEnabled(false);
    }
    // Date/Epi week filter
    HorizontalLayout dateFilterLayout = (HorizontalLayout) getMoreFiltersContainer().getComponent(WEEK_AND_DATE_FILTER);
    @SuppressWarnings("unchecked") EpiWeekAndDateFilterComponent<ImmunizationDateType> weekAndDateFilter = (EpiWeekAndDateFilterComponent<ImmunizationDateType>) dateFilterLayout.getComponent(0);
    ImmunizationDateType immunizationDateType = criteria.getImmunizationDateType();
    weekAndDateFilter.getDateTypeSelector().setValue(immunizationDateType);
    weekAndDateFilter.getDateFilterOptionFilter().setValue(criteria.getDateFilterOption());
    Date dateFrom = criteria.getFromDate();
    Date dateTo = criteria.getToDate();
    if (DateFilterOption.EPI_WEEK.equals(criteria.getDateFilterOption())) {
        weekAndDateFilter.getWeekFromFilter().setValue(dateFrom == null ? null : DateHelper.getEpiWeek(dateFrom));
        weekAndDateFilter.getWeekToFilter().setValue(dateTo == null ? null : DateHelper.getEpiWeek(dateTo));
    } else {
        weekAndDateFilter.getDateFromFilter().setValue(dateFrom);
        weekAndDateFilter.getDateToFilter().setValue(dateTo);
    }
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserProvider(de.symeda.sormas.ui.UserProvider) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ImmunizationDateType(de.symeda.sormas.api.immunization.ImmunizationDateType) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 5 with CommunityReferenceDto

use of de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method insertColumnEntryIntoData.

/**
 * Inserts the entry of a single cell into the case or its person.
 */
private void insertColumnEntryIntoData(CaseDataDto caze, PersonDto person, String entry, String[] entryHeaderPath) throws InvalidColumnException, ImportErrorException {
    Object currentElement = caze;
    for (int i = 0; i < entryHeaderPath.length; i++) {
        String headerPathElementName = entryHeaderPath[i];
        Language language = I18nProperties.getUserLanguage();
        try {
            if (i != entryHeaderPath.length - 1) {
                currentElement = new PropertyDescriptor(headerPathElementName, currentElement.getClass()).getReadMethod().invoke(currentElement);
                // Set the current element to the created person
                if (currentElement instanceof PersonReferenceDto) {
                    currentElement = person;
                }
            } else if (CaseExportDto.BIRTH_DATE.equals(headerPathElementName)) {
                BirthDateDto birthDateDto = PersonHelper.parseBirthdate(entry, language);
                if (birthDateDto != null) {
                    person.setBirthdateDD(birthDateDto.getDateOfBirthDD());
                    person.setBirthdateMM(birthDateDto.getDateOfBirthMM());
                    person.setBirthdateYYYY(birthDateDto.getDateOfBirthYYYY());
                }
            } else {
                PropertyDescriptor pd = new PropertyDescriptor(headerPathElementName, currentElement.getClass());
                Class<?> propertyType = pd.getPropertyType();
                // according to the types of the case or person fields
                if (importFacade.executeDefaultInvoke(pd, currentElement, entry, entryHeaderPath, false)) {
                    continue;
                } else if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) {
                    List<DistrictReferenceDto> district = districtFacade.getByName(entry, ImportHelper.getRegionBasedOnDistrict(pd.getName(), caze, null, null, person, currentElement), false);
                    if (district.isEmpty()) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, entry, buildEntityProperty(entryHeaderPath)));
                    } else if (district.size() > 1) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pd.getWriteMethod().invoke(currentElement, district.get(0));
                    }
                } else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) {
                    List<CommunityReferenceDto> community = communityFacade.getByName(entry, ImportHelper.getDistrictBasedOnCommunity(pd.getName(), caze, person, currentElement), false);
                    if (community.isEmpty()) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
                    } else if (community.size() > 1) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCommunityNotUnique, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pd.getWriteMethod().invoke(currentElement, community.get(0));
                    }
                } else if (propertyType.isAssignableFrom(FacilityReferenceDto.class)) {
                    DataHelper.Pair<DistrictReferenceDto, CommunityReferenceDto> infrastructureData = ImportHelper.getDistrictAndCommunityBasedOnFacility(pd.getName(), caze, person, currentElement);
                    if (I18nProperties.getPrefixCaption(FacilityDto.I18N_PREFIX, FacilityDto.OTHER_FACILITY).equals(entry)) {
                        entry = FacilityDto.OTHER_FACILITY;
                    }
                    if (I18nProperties.getPrefixCaption(FacilityDto.I18N_PREFIX, FacilityDto.NO_FACILITY).equals(entry)) {
                        entry = FacilityDto.NO_FACILITY;
                    }
                    List<FacilityReferenceDto> facilities = facilityFacade.getByNameAndType(entry, infrastructureData.getElement0(), infrastructureData.getElement1(), getTypeOfFacility(pd.getName(), currentElement), false);
                    if (facilities.isEmpty()) {
                        if (infrastructureData.getElement1() != null) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrCommunity, entry, buildEntityProperty(entryHeaderPath)));
                        } else {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
                        }
                    } else if (facilities.size() > 1 && infrastructureData.getElement1() == null) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importFacilityNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath)));
                    } else if (facilities.size() > 1 && infrastructureData.getElement1() != null) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importFacilityNotUniqueInCommunity, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pd.getWriteMethod().invoke(currentElement, facilities.get(0));
                    }
                } else if (propertyType.isAssignableFrom(PointOfEntryReferenceDto.class)) {
                    PointOfEntryReferenceDto pointOfEntryReference;
                    DistrictReferenceDto pointOfEntryDistrict = CaseLogic.getDistrictWithFallback(caze);
                    List<PointOfEntryReferenceDto> customPointsOfEntry = pointOfEntryFacade.getByName(entry, pointOfEntryDistrict, false);
                    if (customPointsOfEntry.isEmpty()) {
                        final String poeName = entry;
                        List<PointOfEntryDto> defaultPointOfEntries = pointOfEntryFacade.getByUuids(PointOfEntryDto.CONSTANT_POE_UUIDS);
                        Optional<PointOfEntryDto> defaultPointOfEntry = defaultPointOfEntries.stream().filter(defaultPoe -> InfrastructureHelper.buildPointOfEntryString(defaultPoe.getUuid(), defaultPoe.getName()).equals(poeName)).findFirst();
                        if (!defaultPointOfEntry.isPresent()) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
                        }
                        pointOfEntryReference = defaultPointOfEntry.get().toReference();
                    } else if (customPointsOfEntry.size() > 1) {
                        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importPointOfEntryNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath)));
                    } else {
                        pointOfEntryReference = customPointsOfEntry.get(0);
                    }
                    pd.getWriteMethod().invoke(currentElement, pointOfEntryReference);
                } else {
                    throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importCasesPropertyTypeNotAllowed, propertyType.getName()));
                }
            }
        } catch (IntrospectionException e) {
            throw new InvalidColumnException(buildEntityProperty(entryHeaderPath));
        } catch (InvocationTargetException | IllegalAccessException e) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importErrorInColumn, buildEntityProperty(entryHeaderPath)));
        } catch (IllegalArgumentException | EnumService.InvalidEnumCaptionException e) {
            throw new ImportErrorException(entry, buildEntityProperty(entryHeaderPath));
        } catch (ParseException e) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importInvalidDate, buildEntityProperty(entryHeaderPath), DateHelper.getAllowedDateFormats(language.getDateFormat())));
        } catch (ImportErrorException e) {
            throw e;
        } catch (Exception e) {
            LOGGER.error("Unexpected error when trying to import a case: " + e.getMessage(), e);
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCasesUnexpectedError));
        }
    }
}
Also used : FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) IntrospectionException(java.beans.IntrospectionException) DataHelper(de.symeda.sormas.api.utils.DataHelper) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) Language(de.symeda.sormas.api.Language) List(java.util.List) ArrayList(java.util.ArrayList) PropertyDescriptor(java.beans.PropertyDescriptor) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) Optional(java.util.Optional) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) ParseException(java.text.ParseException) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) ParseException(java.text.ParseException)

Aggregations

CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)47 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)42 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)25 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)18 UserDto (de.symeda.sormas.api.user.UserDto)15 List (java.util.List)15 ComboBox (com.vaadin.v7.ui.ComboBox)14 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)14 FacilityTypeGroup (de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)12 ArrayList (java.util.ArrayList)12 ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)9 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)9 District (de.symeda.sormas.backend.infrastructure.district.District)9 TextField (com.vaadin.v7.ui.TextField)7 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)7 Region (de.symeda.sormas.backend.infrastructure.region.Region)7 Disease (de.symeda.sormas.api.Disease)6 FacadeProvider (de.symeda.sormas.api.FacadeProvider)6 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)6 IntrospectionException (java.beans.IntrospectionException)6