Search in sources :

Example 1 with FacilityDto

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

the class LocationEditForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addressType = addField(LocationDto.ADDRESS_TYPE, ComboBox.class);
    addressType.setVisible(false);
    final PersonAddressType[] personAddressTypeValues = PersonAddressType.getValues(FacadeProvider.getConfigFacade().getCountryCode());
    if (!isConfiguredServer("ch")) {
        addressType.removeAllItems();
        addressType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
        addressType.addItems(personAddressTypeValues);
    }
    TextField addressTypeDetails = addField(LocationDto.ADDRESS_TYPE_DETAILS, TextField.class);
    addressTypeDetails.setVisible(false);
    FieldHelper.setVisibleWhen(getFieldGroup(), LocationDto.ADDRESS_TYPE_DETAILS, addressType, Arrays.stream(personAddressTypeValues).filter(pat -> !pat.equals(PersonAddressType.HOME)).collect(Collectors.toList()), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), addressType, Arrays.asList(LocationDto.ADDRESS_TYPE_DETAILS), Arrays.asList(PersonAddressType.OTHER_ADDRESS));
    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);
    facilityType = addField(LocationDto.FACILITY_TYPE);
    facility = addInfrastructureField(LocationDto.FACILITY);
    facility.setImmediate(true);
    facilityDetails = addField(LocationDto.FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    addressType.addValueChangeListener(e -> {
        FacilityTypeGroup oldGroup = (FacilityTypeGroup) facilityTypeGroup.getValue();
        FacilityType oldType = (FacilityType) facilityType.getValue();
        FacilityReferenceDto oldFacility = (FacilityReferenceDto) facility.getValue();
        String oldDetails = facilityDetails.getValue();
        if (PersonAddressType.HOME.equals(addressType.getValue())) {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        } else {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.values());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        }
    });
    TextField streetField = addField(LocationDto.STREET, TextField.class);
    TextField houseNumberField = addField(LocationDto.HOUSE_NUMBER, TextField.class);
    TextField additionalInformationField = addField(LocationDto.ADDITIONAL_INFORMATION, TextField.class);
    addField(LocationDto.DETAILS, TextField.class);
    TextField cityField = addField(LocationDto.CITY, TextField.class);
    TextField postalCodeField = addField(LocationDto.POSTAL_CODE, TextField.class);
    ComboBox areaType = addField(LocationDto.AREA_TYPE, ComboBox.class);
    areaType.setDescription(I18nProperties.getDescription(getPropertyI18nPrefix() + "." + LocationDto.AREA_TYPE));
    contactPersonFirstName = addField(LocationDto.CONTACT_PERSON_FIRST_NAME, TextField.class);
    contactPersonLastName = addField(LocationDto.CONTACT_PERSON_LAST_NAME, TextField.class);
    contactPersonPhone = addField(LocationDto.CONTACT_PERSON_PHONE, TextField.class);
    contactPersonPhone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactPersonPhone.getCaption())));
    contactPersonEmail = addField(LocationDto.CONTACT_PERSON_EMAIL, TextField.class);
    contactPersonEmail.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactPersonEmail.getCaption())));
    final AccessibleTextField tfLatitude = addField(LocationDto.LATITUDE, AccessibleTextField.class);
    final AccessibleTextField tfLongitude = addField(LocationDto.LONGITUDE, AccessibleTextField.class);
    final AccessibleTextField tfAccuracy = addField(LocationDto.LAT_LON_ACCURACY, AccessibleTextField.class);
    final StringToAngularLocationConverter stringToAngularLocationConverter = new StringToAngularLocationConverter();
    tfLatitude.setConverter(stringToAngularLocationConverter);
    tfLongitude.setConverter(stringToAngularLocationConverter);
    tfAccuracy.setConverter(stringToAngularLocationConverter);
    continent = addInfrastructureField(LocationDto.CONTINENT);
    subcontinent = addInfrastructureField(LocationDto.SUB_CONTINENT);
    country = addInfrastructureField(LocationDto.COUNTRY);
    ComboBox region = addInfrastructureField(LocationDto.REGION);
    ComboBox district = addInfrastructureField(LocationDto.DISTRICT);
    ComboBox community = addInfrastructureField(LocationDto.COMMUNITY);
    continent.setVisible(false);
    subcontinent.setVisible(false);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!isEditableAllowed(LocationDto.COMMUNITY)) {
        setEnabled(false, LocationDto.COUNTRY, LocationDto.REGION, LocationDto.DISTRICT);
    }
    ValueChangeListener continentValueListener = e -> {
        if (continent.isVisible()) {
            ContinentReferenceDto continentReferenceDto = (ContinentReferenceDto) e.getProperty().getValue();
            if (subcontinent.getValue() == null) {
                FieldHelper.updateItems(country, continentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getCountryFacade().getAllActiveAsReference());
                country.setValue(null);
            }
            subcontinent.setValue(null);
            FieldHelper.updateItems(subcontinent, continentReferenceDto != null ? FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getSubcontinentFacade().getAllActiveAsReference());
        }
    };
    ValueChangeListener subContinentValueListener = e -> {
        if (subcontinent.isVisible()) {
            SubcontinentReferenceDto subcontinentReferenceDto = (SubcontinentReferenceDto) e.getProperty().getValue();
            if (subcontinentReferenceDto != null) {
                continent.removeValueChangeListener(continentValueListener);
                continent.setValue(FacadeProvider.getContinentFacade().getBySubcontinent(subcontinentReferenceDto));
                continent.addValueChangeListener(continentValueListener);
            }
            country.setValue(null);
            ContinentReferenceDto continentValue = (ContinentReferenceDto) continent.getValue();
            FieldHelper.updateItems(country, subcontinentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(subcontinentReferenceDto.getUuid()) : continentValue == null ? FacadeProvider.getCountryFacade().getAllActiveAsReference() : FacadeProvider.getCountryFacade().getAllActiveByContinent(continentValue.getUuid()));
        }
    };
    continent.addValueChangeListener(continentValueListener);
    subcontinent.addValueChangeListener(subContinentValueListener);
    skipCountryValueChange = false;
    country.addValueChangeListener(e -> {
        if (!skipCountryValueChange) {
            CountryReferenceDto countryDto = (CountryReferenceDto) e.getProperty().getValue();
            if (countryDto != null) {
                final ContinentReferenceDto countryContinent = FacadeProvider.getContinentFacade().getByCountry(countryDto);
                final SubcontinentReferenceDto countrySubcontinent = FacadeProvider.getSubcontinentFacade().getByCountry(countryDto);
                if (countryContinent != null) {
                    continent.removeValueChangeListener(continentValueListener);
                    if (continent.isVisible()) {
                        skipCountryValueChange = true;
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    continent.setValue(countryContinent);
                    continent.addValueChangeListener(continentValueListener);
                }
                if (countrySubcontinent != null) {
                    subcontinent.removeValueChangeListener(subContinentValueListener);
                    if (subcontinent.isVisible()) {
                        skipCountryValueChange = true;
                        if (countryContinent != null) {
                            FieldHelper.updateItems(subcontinent, FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        }
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(countrySubcontinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    subcontinent.setValue(countrySubcontinent);
                    subcontinent.addValueChangeListener(subContinentValueListener);
                }
            }
        }
    });
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    district.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        if (districtDto == null) {
            FieldHelper.removeItems(facility);
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

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

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        } else if (facilityType.getValue() != null) {
            facility.setComponentError(null);
            facility.markAsDirty();
            FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    community.addValueChangeListener(e -> {
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facility, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, true) : district.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    skipFacilityTypeUpdate = false;
    facilityTypeGroup.addValueChangeListener(e -> {
        if (!skipFacilityTypeUpdate) {
            FieldHelper.removeItems(facility);
            FieldHelper.updateEnumData(facilityType, FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
            facilityType.setRequired(facilityTypeGroup.getValue() != null);
        }
    });
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        facility.setComponentError(null);
        facility.markAsDirty();
        if (facilityType.getValue() != null && facilityTypeGroup.getValue() == null) {
            facilityTypeGroup.setValue(((FacilityType) facilityType.getValue()).getFacilityTypeGroup());
        }
        if (facilityType.getValue() != null && district.getValue() != null) {
            if (community.getValue() != null) {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) community.getValue(), (FacilityType) facilityType.getValue(), true, false));
            } else {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false));
            }
        } else if (facilityType.getValue() != null && district.getValue() == null) {
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

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

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        }
        // Only show contactperson-details if at least a faciltytype has been set
        if (facilityType.getValue() != null) {
            setFacilityContactPersonFieldsVisible(true, true);
        } else {
            setFacilityContactPersonFieldsVisible(false, true);
        }
    });
    facility.addValueChangeListener(e -> {
        if (facility.getValue() != null) {
            boolean visibleAndRequired = areFacilityDetailsRequired();
            facilityDetails.setVisible(visibleAndRequired);
            facilityDetails.setRequired(visibleAndRequired);
            if (!visibleAndRequired) {
                facilityDetails.clear();
            } else {
                String facilityDetailsValue = getValue() != null ? getValue().getFacilityDetails() : null;
                facilityDetails.setValue(facilityDetailsValue);
            }
        } else {
            facilityDetails.setVisible(false);
            facilityDetails.setRequired(false);
            facilityDetails.clear();
        }
        // value because of this field dependencies to other fields and the way updateEnumValues works
        if (facility.isAttached() && !disableFacilityAddressCheck) {
            if (facility.getValue() != null) {
                FacilityDto facilityDto = FacadeProvider.getFacilityFacade().getByUuid(((FacilityReferenceDto) getField(LocationDto.FACILITY).getValue()).getUuid());
                // Only if the facility's address is set
                if (StringUtils.isNotEmpty(facilityDto.getCity()) || StringUtils.isNotEmpty(facilityDto.getPostalCode()) || StringUtils.isNotEmpty(facilityDto.getStreet()) || StringUtils.isNotEmpty(facilityDto.getHouseNumber()) || StringUtils.isNotEmpty(facilityDto.getAdditionalInformation()) || facilityDto.getAreaType() != null || facilityDto.getLatitude() != null || facilityDto.getLongitude() != null || (StringUtils.isNotEmpty(facilityDto.getContactPersonFirstName()) && StringUtils.isNotEmpty(facilityDto.getContactPersonLastName()))) {
                    // Show a confirmation popup if the location's address is already set and different from the facility one
                    if ((StringUtils.isNotEmpty(cityField.getValue()) && !cityField.getValue().equals(facilityDto.getCity())) || (StringUtils.isNotEmpty(postalCodeField.getValue()) && !postalCodeField.getValue().equals(facilityDto.getPostalCode())) || (StringUtils.isNotEmpty(streetField.getValue()) && !streetField.getValue().equals(facilityDto.getStreet())) || (StringUtils.isNotEmpty(houseNumberField.getValue()) && !houseNumberField.getValue().equals(facilityDto.getHouseNumber())) || (StringUtils.isNotEmpty(additionalInformationField.getValue()) && !additionalInformationField.getValue().equals(facilityDto.getAdditionalInformation())) || (areaType.getValue() != null && areaType.getValue() != facilityDto.getAreaType()) || (StringUtils.isNotEmpty(contactPersonFirstName.getValue()) && StringUtils.isNotEmpty(contactPersonLastName.getValue())) || (tfLatitude.getConvertedValue() != null && Double.compare((Double) tfLatitude.getConvertedValue(), facilityDto.getLatitude()) != 0) || (tfLongitude.getConvertedValue() != null && Double.compare((Double) tfLongitude.getConvertedValue(), facilityDto.getLongitude()) != 0)) {
                        VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingLocation), new Label(I18nProperties.getString(Strings.confirmationLocationFacilityAddressOverride)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 640, confirmationEvent -> {
                            if (confirmationEvent) {
                                overrideLocationDetailsWithFacilityOnes(facilityDto);
                            }
                        });
                    } else {
                        overrideLocationDetailsWithFacilityOnes(facilityDto);
                    }
                }
            }
        }
    });
    final List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getAllActiveAsReference();
    if (continents.isEmpty()) {
        continent.setVisible(false);
        continent.clear();
    } else {
        continent.addItems(continents);
    }
    final List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getAllActiveAsReference();
    if (subcontinents.isEmpty()) {
        subcontinent.setVisible(false);
        subcontinent.clear();
    } else {
        subcontinent.addItems(subcontinents);
    }
    country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
    updateRegionCombo(region, country);
    country.addValueChangeListener(e -> {
        updateRegionCombo(region, country);
        region.setValue(null);
    });
    Stream.of(LocationDto.LATITUDE, LocationDto.LONGITUDE).<Field<?>>map(this::getField).forEach(f -> f.addValueChangeListener(e -> this.updateLeafletMapContent()));
    // Set initial visiblity of facility-contactperson-details (should only be visible if at least a facilityType has been selected)
    setFacilityContactPersonFieldsVisible(facilityType.getValue() != null, true);
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LeafletMarker(de.symeda.sormas.ui.map.LeafletMarker) StringUtils(org.apache.commons.lang3.StringUtils) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) LeafletMap(de.symeda.sormas.ui.map.LeafletMap) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) LayoutUtil.divs(de.symeda.sormas.ui.utils.LayoutUtil.divs) PopupView(com.vaadin.ui.PopupView) 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) List(java.util.List) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) Stream(java.util.stream.Stream) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ContinentCriteria(de.symeda.sormas.api.infrastructure.continent.ContinentCriteria) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) CustomLayout(com.vaadin.ui.CustomLayout) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Label(com.vaadin.ui.Label) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) LocationDto(de.symeda.sormas.api.location.LocationDto) ContentMode(com.vaadin.shared.ui.ContentMode) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ErrorMessage(com.vaadin.server.ErrorMessage) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Button(com.vaadin.ui.Button) MarkerIcon(de.symeda.sormas.ui.map.MarkerIcon) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) Component(com.vaadin.ui.Component) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Label(com.vaadin.ui.Label) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) TextField(com.vaadin.v7.ui.TextField) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ErrorMessage(com.vaadin.server.ErrorMessage) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 2 with FacilityDto

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

the class FacilityDtoHelper method pullEntities.

/**
 * Pulls the data chunkwise per region
 *
 * @param markAsRead
 * @param context
 * @throws DaoException
 * @throws SQLException
 * @throws IOException
 */
@Override
public void pullEntities(final boolean markAsRead, Context context) throws DaoException, ServerCommunicationException, ServerConnectionException, NoConnectionException {
    try {
        final FacilityDao facilityDao = DatabaseHelper.getFacilityDao();
        List<Region> regions = DatabaseHelper.getRegionDao().queryForAll();
        for (Region region : regions) {
            Date maxModifiedDate = facilityDao.getLatestChangeDateByRegion(region);
            long maxModifiedTime = maxModifiedDate != null ? maxModifiedDate.getTime() : 0;
            databaseWasEmpty = maxModifiedDate == null;
            Call<List<FacilityDto>> dtoCall = pullAllByRegionSince(region, maxModifiedTime);
            if (dtoCall == null) {
                return;
            }
            handlePullResponse(markAsRead, facilityDao, dtoCall.execute());
        }
        {
            // Pull 'Other' health facility which has no region set
            Date maxModifiedDate = facilityDao.getLatestChangeDateByRegion(null);
            long maxModifiedTime = maxModifiedDate != null ? maxModifiedDate.getTime() : 0;
            databaseWasEmpty = maxModifiedDate == null;
            Call<List<FacilityDto>> dtoCall = pullAllWithoutRegionSince(maxModifiedTime);
            if (dtoCall == null) {
                return;
            }
            handlePullResponse(markAsRead, facilityDao, dtoCall.execute());
        }
    } catch (IOException e) {
        throw new ServerCommunicationException(e);
    } finally {
        databaseWasEmpty = false;
    }
}
Also used : ServerCommunicationException(de.symeda.sormas.app.rest.ServerCommunicationException) Call(retrofit2.Call) Region(de.symeda.sormas.app.backend.region.Region) List(java.util.List) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) IOException(java.io.IOException) Date(java.util.Date)

Example 3 with FacilityDto

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

the class SormasToSormasEventFacadeEjbTest method testSaveSharedEventsWithSamples.

@Test
public void testSaveSharedEventsWithSamples() throws SormasToSormasException, SormasToSormasValidationException {
    FacilityDto remoteLab = FacilityDto.build();
    remoteLab.setName("Test Lab");
    FacilityDto localLab = creator.createFacility("Test Lab", rdcf.region, rdcf.district, null, FacilityType.LABORATORY);
    EventDto event = createEventDto(rdcf);
    UserDto sampleUser = UserDto.build();
    EventParticipantDto eventParticipant = createEventParticipantDto(event.toReference(), sampleUser.toReference(), rdcf);
    SampleDto sample = createSample(eventParticipant.toReference(), sampleUser.toReference(), remoteLab.toReference());
    sample.setLabSampleID("Test lab sample id");
    PathogenTestDto pathogenTest = PathogenTestDto.build(sample, sampleUser);
    pathogenTest.setTestDateTime(new Date());
    pathogenTest.setLab(remoteLab.toReference());
    pathogenTest.setTestType(PathogenTestType.RAPID_TEST);
    pathogenTest.setTestResult(PathogenTestResultType.PENDING);
    AdditionalTestDto additionalTest = AdditionalTestDto.build(sample.toReference());
    additionalTest.setTestDateTime(new Date());
    additionalTest.setHaemoglobin(0.2F);
    additionalTest.setConjBilirubin(0.3F);
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
    shareData.setEvents(Collections.singletonList(new SormasToSormasEventDto(event)));
    shareData.setEventParticipants(Collections.singletonList(new SormasToSormasEventParticipantDto(eventParticipant)));
    shareData.setSamples(Collections.singletonList(new SormasToSormasSampleDto(sample, Collections.singletonList(pathogenTest), Collections.singletonList(additionalTest))));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasEventFacade().saveSharedEntities(encryptedData);
    SampleDto savedSample = getSampleFacade().getSampleByUuid(sample.getUuid());
    assertThat(savedSample, is(notNullValue()));
    assertThat(savedSample.getAssociatedEventParticipant(), is(eventParticipant.toReference()));
    assertThat(savedSample.getSampleMaterial(), is(SampleMaterial.BLOOD));
    assertThat(savedSample.getLab(), is(localLab.toReference()));
    assertThat(savedSample.getLabSampleID(), is("Test lab sample id"));
    assertThat(savedSample.getSormasToSormasOriginInfo().getOrganizationId(), is(DEFAULT_SERVER_ID));
    assertThat(savedSample.getSormasToSormasOriginInfo().getSenderName(), is("John doe"));
    PathogenTestDto savedPathogenTest = getPathogenTestFacade().getByUuid(pathogenTest.getUuid());
    assertThat(savedPathogenTest, is(notNullValue()));
    assertThat(savedPathogenTest.getLab(), is(localLab.toReference()));
    assertThat(savedPathogenTest.getTestType(), is(PathogenTestType.RAPID_TEST));
    assertThat(savedPathogenTest.getTestResult(), is(PathogenTestResultType.PENDING));
    AdditionalTestDto savedAdditionalTest = getAdditionalTestFacade().getByUuid(additionalTest.getUuid());
    assertThat(savedAdditionalTest, is(notNullValue()));
    assertThat(savedAdditionalTest.getHaemoglobin(), is(0.2F));
    assertThat(savedAdditionalTest.getConjBilirubin(), is(0.3F));
}
Also used : SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) Date(java.util.Date) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 4 with FacilityDto

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

the class SormasToSormasEventFacadeEjbTest method testSaveReturnedEvent.

@Test
public void testSaveReturnedEvent() throws SormasToSormasException, SormasToSormasValidationException {
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    EventDto event = creator.createEvent(officer);
    EventParticipantDto eventParticipant = creator.createEventParticipant(event.toReference(), creator.createPerson(), officer);
    EventParticipantDto newEventParticipant = createEventParticipantDto(event.toReference(), UserDto.build().toReference(), rdcf);
    FacilityDto lab = creator.createFacility("Test Lab", rdcf.region, rdcf.district, null, FacilityType.LABORATORY);
    SampleDto newSample = createSample(newEventParticipant.toReference(), officer, lab.toReference());
    User officerUser = getUserService().getByReferenceDto(officer);
    ShareRequestInfo shareRequestInfo = createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setEvent(getEventService().getByReferenceDto(event.toReference())));
    shareRequestInfo.setWithEventParticipants(true);
    shareRequestInfo.getShares().add(createShareInfo(DEFAULT_SERVER_ID, true, i -> i.setEventParticipant(getEventParticipantService().getByReferenceDto(eventParticipant.toReference()))));
    getShareRequestInfoService().persist(shareRequestInfo);
    event.setEventDesc("Test updated description");
    eventParticipant.getPerson().setBirthName("Test birth name");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(event.getChangeDate());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    event.setChangeDate(calendar.getTime());
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true));
    shareData.setEvents(Collections.singletonList(new SormasToSormasEventDto(event)));
    shareData.setEventParticipants(Arrays.asList(new SormasToSormasEventParticipantDto(eventParticipant), new SormasToSormasEventParticipantDto(newEventParticipant)));
    shareData.setSamples(Collections.singletonList(new SormasToSormasSampleDto(newSample, Collections.emptyList(), Collections.emptyList())));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasEventFacade().saveSharedEntities(encryptedData);
    EventDto returnedEvent = getEventFacade().getEventByUuid(event.getUuid(), false);
    assertThat(returnedEvent.getEventDesc(), is("Test updated description"));
    assertThat(returnedEvent.getReportingUser(), is(officer));
    List<SormasToSormasShareInfoDto> eventShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().event(event.toReference()), 0, 100);
    assertThat(eventShares.get(0).isOwnershipHandedOver(), is(false));
    assertThat(getEventParticipantFacade().getEventParticipantByUuid(eventParticipant.getUuid()).getPerson().getBirthName(), is("Test birth name"));
    List<SormasToSormasShareInfoDto> eventParticipantShares = getSormasToSormasShareInfoFacade().getIndexList(new SormasToSormasShareInfoCriteria().eventParticipant(eventParticipant.toReference()), 0, 100);
    assertThat(eventParticipantShares.get(0).isOwnershipHandedOver(), is(false));
    EventParticipantDto returnedNewEventParticipant = getEventParticipantFacade().getEventParticipantByUuid(newEventParticipant.getUuid());
    assertThat(returnedNewEventParticipant.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
    SampleDto returnedNewSample = getSampleFacade().getSampleByUuid(newSample.getUuid());
    assertThat(returnedNewSample.getSormasToSormasOriginInfo().isOwnershipHandedOver(), is(true));
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) Matchers.nullValue(org.hamcrest.Matchers.nullValue) EventInvestigationStatus(de.symeda.sormas.api.event.EventInvestigationStatus) UserRole(de.symeda.sormas.api.user.UserRole) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) EventDto(de.symeda.sormas.api.event.EventDto) RiskLevel(de.symeda.sormas.api.event.RiskLevel) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) Matchers.is(org.hamcrest.Matchers.is) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) MockProducer(de.symeda.sormas.backend.MockProducer) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) EventStatus(de.symeda.sormas.api.event.EventStatus) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) DataHelper(de.symeda.sormas.api.utils.DataHelper) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) UserDto(de.symeda.sormas.api.user.UserDto) Test(org.junit.Test) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventSourceType(de.symeda.sormas.api.event.EventSourceType) Collections(java.util.Collections) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) Calendar(java.util.Calendar) EventDto(de.symeda.sormas.api.event.EventDto) SormasToSormasEventDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasEventParticipantDto(de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventParticipantDto) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 5 with FacilityDto

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

the class FacilityFacadeEjb method toDto.

@Override
public FacilityDto toDto(Facility entity) {
    if (entity == null) {
        return null;
    }
    FacilityDto dto = new FacilityDto();
    DtoHelper.fillDto(dto, entity);
    dto.setName(entity.getName());
    dto.setType(entity.getType());
    dto.setPublicOwnership(entity.isPublicOwnership());
    dto.setRegion(RegionFacadeEjb.toReferenceDto(entity.getRegion()));
    dto.setDistrict(DistrictFacadeEjb.toReferenceDto(entity.getDistrict()));
    dto.setCommunity(CommunityFacadeEjb.toReferenceDto(entity.getCommunity()));
    dto.setCity(entity.getCity());
    dto.setPostalCode(entity.getPostalCode());
    dto.setStreet(entity.getStreet());
    dto.setHouseNumber(entity.getHouseNumber());
    dto.setAdditionalInformation(entity.getAdditionalInformation());
    dto.setAreaType(entity.getAreaType());
    dto.setContactPersonFirstName(entity.getContactPersonFirstName());
    dto.setContactPersonLastName(entity.getContactPersonLastName());
    dto.setContactPersonPhone(entity.getContactPersonPhone());
    dto.setContactPersonEmail(entity.getContactPersonEmail());
    dto.setLatitude(entity.getLatitude());
    dto.setLongitude(entity.getLongitude());
    dto.setArchived(entity.isArchived());
    dto.setExternalID(entity.getExternalID());
    dto.setCentrallyManaged(entity.isCentrallyManaged());
    return dto;
}
Also used : FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto)

Aggregations

FacilityDto (de.symeda.sormas.api.infrastructure.facility.FacilityDto)19 Date (java.util.Date)6 List (java.util.List)5 Test (org.junit.Test)5 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)3 ContentMode (com.vaadin.shared.ui.ContentMode)2 Alignment (com.vaadin.ui.Alignment)2 Button (com.vaadin.ui.Button)2 Component (com.vaadin.ui.Component)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 Window (com.vaadin.ui.Window)2 ValoTheme (com.vaadin.ui.themes.ValoTheme)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 EventDto (de.symeda.sormas.api.event.EventDto)2 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)2 CommunityDto (de.symeda.sormas.api.infrastructure.community.CommunityDto)2 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)2 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)2