Search in sources :

Example 21 with LocationDto

use of de.symeda.sormas.api.location.LocationDto in project SORMAS-Project by hzi-braunschweig.

the class ExposureDto method build.

public static ExposureDto build(ExposureType exposureType) {
    ExposureDto exposure = new ExposureDto();
    exposure.setUuid(DataHelper.createUuid());
    exposure.setExposureType(exposureType);
    LocationDto location = LocationDto.build();
    exposure.setLocation(location);
    return exposure;
}
Also used : LocationDto(de.symeda.sormas.api.location.LocationDto)

Example 22 with LocationDto

use of de.symeda.sormas.api.location.LocationDto in project SORMAS-Project by hzi-braunschweig.

the class PersonDtoHelper method fillInnerFromDto.

@Override
public void fillInnerFromDto(Person target, PersonDto source) {
    target.setFirstName(source.getFirstName());
    target.setLastName(source.getLastName());
    target.setSalutation(source.getSalutation());
    target.setOtherSalutation(source.getOtherSalutation());
    target.setBirthName(source.getBirthName());
    target.setNickname(source.getNickname());
    target.setMothersMaidenName(source.getMothersMaidenName());
    target.setSex(source.getSex());
    target.setBirthdateDD(source.getBirthdateDD());
    target.setBirthdateMM(source.getBirthdateMM());
    target.setBirthdateYYYY(source.getBirthdateYYYY());
    target.setApproximateAge(source.getApproximateAge());
    target.setApproximateAgeType(source.getApproximateAgeType());
    target.setApproximateAgeReferenceDate(source.getApproximateAgeReferenceDate());
    target.setPresentCondition(source.getPresentCondition());
    target.setDeathDate(source.getDeathDate());
    target.setAddress(locationHelper.fillOrCreateFromDto(target.getAddress(), source.getAddress()));
    target.setEducationType(source.getEducationType());
    target.setEducationDetails(source.getEducationDetails());
    target.setOccupationType(source.getOccupationType());
    target.setOccupationDetails(source.getOccupationDetails());
    target.setArmedForcesRelationType(source.getArmedForcesRelationType());
    target.setDeathPlaceType(source.getDeathPlaceType());
    target.setDeathPlaceDescription(source.getDeathPlaceDescription());
    target.setBurialDate(source.getBurialDate());
    target.setBurialPlaceDescription(source.getBurialPlaceDescription());
    target.setBurialConductor(source.getBurialConductor());
    target.setCauseOfDeath(source.getCauseOfDeath());
    target.setCauseOfDeathDisease(source.getCauseOfDeathDisease());
    target.setCauseOfDeathDetails(source.getCauseOfDeathDetails());
    target.setMothersName(source.getMothersName());
    target.setFathersName(source.getFathersName());
    target.setNamesOfGuardians(source.getNamesOfGuardians());
    target.setPlaceOfBirthRegion(DatabaseHelper.getRegionDao().getByReferenceDto(source.getPlaceOfBirthRegion()));
    target.setPlaceOfBirthDistrict(DatabaseHelper.getDistrictDao().getByReferenceDto(source.getPlaceOfBirthDistrict()));
    target.setPlaceOfBirthCommunity(DatabaseHelper.getCommunityDao().getByReferenceDto(source.getPlaceOfBirthCommunity()));
    target.setPlaceOfBirthFacility(DatabaseHelper.getFacilityDao().getByReferenceDto(source.getPlaceOfBirthFacility()));
    target.setPlaceOfBirthFacilityDetails(source.getPlaceOfBirthFacilityDetails());
    target.setGestationAgeAtBirth(source.getGestationAgeAtBirth());
    target.setBirthWeight(source.getBirthWeight());
    target.setPassportNumber(source.getPassportNumber());
    target.setNationalHealthId(source.getNationalHealthId());
    target.setPseudonymized(source.isPseudonymized());
    target.setPlaceOfBirthFacilityType(source.getPlaceOfBirthFacilityType());
    List<Location> addresses = new ArrayList<>();
    if (!source.getAddresses().isEmpty()) {
        for (LocationDto locationDto : source.getAddresses()) {
            Location location = locationHelper.fillOrCreateFromDto(null, locationDto);
            location.setPerson(target);
            addresses.add(location);
        }
    }
    target.setAddresses(addresses);
    List<PersonContactDetail> personContactDetails = new ArrayList<>();
    List<PersonContactDetailDto> personContactDetailDtos = source.getPersonContactDetails();
    if (!personContactDetailDtos.isEmpty()) {
        for (PersonContactDetailDto personContactDetailDto : personContactDetailDtos) {
            PersonContactDetail personContactDetail = personContactDetailDtoHelper.fillOrCreateFromDto(null, personContactDetailDto);
            personContactDetail.setPerson(target);
            personContactDetails.add(personContactDetail);
        }
    }
    target.setPersonContactDetails(personContactDetails);
    target.setExternalId(source.getExternalId());
    target.setExternalToken(source.getExternalToken());
    target.setInternalToken(source.getInternalToken());
    target.setBirthCountry(DatabaseHelper.getCountryDao().getByReferenceDto(source.getBirthCountry()));
    target.setCitizenship(DatabaseHelper.getCountryDao().getByReferenceDto(source.getCitizenship()));
    target.setAdditionalDetails(source.getAdditionalDetails());
}
Also used : PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) ArrayList(java.util.ArrayList) LocationDto(de.symeda.sormas.api.location.LocationDto) Location(de.symeda.sormas.app.backend.location.Location)

Example 23 with LocationDto

use of de.symeda.sormas.api.location.LocationDto in project SORMAS-Project by hzi-braunschweig.

the class PersonDtoHelper method fillInnerFromAdo.

@Override
public void fillInnerFromAdo(PersonDto target, Person source) {
    target.setFirstName(source.getFirstName());
    target.setLastName(source.getLastName());
    target.setSalutation(source.getSalutation());
    target.setOtherSalutation(source.getOtherSalutation());
    target.setBirthName(source.getBirthName());
    target.setNickname(source.getNickname());
    target.setMothersMaidenName(source.getMothersMaidenName());
    target.setSex(source.getSex());
    target.setPresentCondition(source.getPresentCondition());
    target.setDeathDate(source.getDeathDate());
    target.setDeathPlaceType(source.getDeathPlaceType());
    target.setDeathPlaceDescription(source.getDeathPlaceDescription());
    target.setBurialDate(source.getBurialDate());
    target.setBurialPlaceDescription(source.getBurialPlaceDescription());
    target.setBurialConductor(source.getBurialConductor());
    target.setBirthdateDD(source.getBirthdateDD());
    target.setBirthdateMM(source.getBirthdateMM());
    target.setBirthdateYYYY(source.getBirthdateYYYY());
    target.setApproximateAge(source.getApproximateAge());
    target.setApproximateAgeType(source.getApproximateAgeType());
    target.setApproximateAgeReferenceDate(source.getApproximateAgeReferenceDate());
    target.setCauseOfDeath(source.getCauseOfDeath());
    target.setCauseOfDeathDisease(source.getCauseOfDeathDisease());
    target.setCauseOfDeathDetails(source.getCauseOfDeathDetails());
    Location address = DatabaseHelper.getLocationDao().queryForId(source.getAddress().getId());
    target.setAddress(locationHelper.adoToDto(address));
    target.setEducationType(source.getEducationType());
    target.setEducationDetails(source.getEducationDetails());
    target.setOccupationType(source.getOccupationType());
    target.setOccupationDetails(source.getOccupationDetails());
    target.setArmedForcesRelationType(source.getArmedForcesRelationType());
    target.setMothersName(source.getMothersName());
    target.setFathersName(source.getFathersName());
    target.setNamesOfGuardians(source.getNamesOfGuardians());
    if (source.getPlaceOfBirthRegion() != null) {
        target.setPlaceOfBirthRegion(RegionDtoHelper.toReferenceDto(DatabaseHelper.getRegionDao().queryForId(source.getPlaceOfBirthRegion().getId())));
    } else {
        target.setPlaceOfBirthRegion(null);
    }
    if (source.getPlaceOfBirthDistrict() != null) {
        target.setPlaceOfBirthDistrict(DistrictDtoHelper.toReferenceDto(DatabaseHelper.getDistrictDao().queryForId(source.getPlaceOfBirthDistrict().getId())));
    } else {
        target.setPlaceOfBirthDistrict(null);
    }
    if (source.getPlaceOfBirthCommunity() != null) {
        target.setPlaceOfBirthCommunity(CommunityDtoHelper.toReferenceDto(DatabaseHelper.getCommunityDao().queryForId(source.getPlaceOfBirthCommunity().getId())));
    } else {
        target.setPlaceOfBirthCommunity(null);
    }
    if (source.getPlaceOfBirthFacility() != null) {
        target.setPlaceOfBirthFacility(FacilityDtoHelper.toReferenceDto(DatabaseHelper.getFacilityDao().queryForId(source.getPlaceOfBirthFacility().getId())));
    } else {
        target.setPlaceOfBirthFacility(null);
    }
    target.setPlaceOfBirthFacilityDetails(source.getPlaceOfBirthFacilityDetails());
    target.setGestationAgeAtBirth(source.getGestationAgeAtBirth());
    target.setBirthWeight(source.getBirthWeight());
    target.setPassportNumber(source.getPassportNumber());
    target.setNationalHealthId(source.getNationalHealthId());
    target.setPseudonymized(source.isPseudonymized());
    target.setPlaceOfBirthFacilityType(source.getPlaceOfBirthFacilityType());
    List<LocationDto> locationDtos = new ArrayList<>();
    // Necessary because the person is synchronized independently
    DatabaseHelper.getPersonDao().initLocations(source);
    for (Location location : source.getAddresses()) {
        LocationDto locationDto = locationHelper.adoToDto(location);
        locationDtos.add(locationDto);
    }
    target.setAddresses(locationDtos);
    List<PersonContactDetailDto> personContactDetailDtos = new ArrayList<>();
    // Necessary because the person is synchronized independently
    DatabaseHelper.getPersonDao().initPersonContactDetails(source);
    for (PersonContactDetail personContactDetail : source.getPersonContactDetails()) {
        PersonContactDetailDto personContactDetailDto = personContactDetailDtoHelper.adoToDto(personContactDetail);
        personContactDetailDtos.add(personContactDetailDto);
    }
    target.setPersonContactDetails(personContactDetailDtos);
    target.setExternalId(source.getExternalId());
    target.setExternalToken(source.getExternalToken());
    target.setInternalToken(source.getInternalToken());
    target.setBirthCountry(CountryDtoHelper.toReferenceDto(source.getBirthCountry()));
    target.setCitizenship(CountryDtoHelper.toReferenceDto(source.getCitizenship()));
    target.setAdditionalDetails(source.getAdditionalDetails());
}
Also used : PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) ArrayList(java.util.ArrayList) LocationDto(de.symeda.sormas.api.location.LocationDto) Location(de.symeda.sormas.app.backend.location.Location)

Example 24 with LocationDto

use of de.symeda.sormas.api.location.LocationDto in project SORMAS-Project by hzi-braunschweig.

the class LocationEditForm method discard.

@Override
public void discard() throws SourceException {
    super.discard();
    LocationDto locationDto = getValue();
    if (locationDto != null) {
        FacilityType facilityType = locationDto.getFacilityType();
        if (facilityType != null) {
            facilityTypeGroup.setValue(facilityType.getFacilityTypeGroup());
        } else {
            facilityTypeGroup.setValue(null);
        }
        facility.setValue(locationDto.getFacility());
        facility.setComponentError(null);
    }
}
Also used : LocationDto(de.symeda.sormas.api.location.LocationDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 25 with LocationDto

use of de.symeda.sormas.api.location.LocationDto in project SORMAS-Project by hzi-braunschweig.

the class ContactImporter method insertColumnEntryIntoData.

/**
 * Inserts the entry of a single cell into the contact or its person.
 */
private void insertColumnEntryIntoData(ContactDto contact, PersonDto person, String entry, String[] entryHeaderPath) throws InvalidColumnException, ImportErrorException {
    Object currentElement = contact;
    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 (ContactExportDto.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 contact 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(), contact, 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)) {
                    DistrictReferenceDto district = currentElement instanceof ContactDto ? ((ContactDto) currentElement).getDistrict() : (currentElement instanceof LocationDto ? ((LocationDto) currentElement).getDistrict() : null);
                    List<CommunityReferenceDto> community = FacadeProvider.getCommunityFacade().getByName(entry, district != null ? district : 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)) {
                    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 a contact: " + e.getMessage());
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importUnexpectedError));
        }
    }
    ImportLineResultDto<ContactDto> contactErrors = validateConstraints(contact);
    if (contactErrors.isError()) {
        throw new ImportErrorException(contactErrors.getMessage());
    }
    ImportLineResultDto<PersonDto> personErrors = validateConstraints(person);
    if (personErrors.isError()) {
        throw new ImportErrorException(personErrors.getMessage());
    }
}
Also used : FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) IntrospectionException(java.beans.IntrospectionException) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) List(java.util.List) ArrayList(java.util.ArrayList) LocationDto(de.symeda.sormas.api.location.LocationDto) PropertyDescriptor(java.beans.PropertyDescriptor) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) PersonDto(de.symeda.sormas.api.person.PersonDto) 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)

Aggregations

LocationDto (de.symeda.sormas.api.location.LocationDto)32 PersonDto (de.symeda.sormas.api.person.PersonDto)9 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)7 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Test (org.junit.Test)7 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)6 UserDto (de.symeda.sormas.api.user.UserDto)4 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)4 ContactDto (de.symeda.sormas.api.contact.ContactDto)3 EpiDataDto (de.symeda.sormas.api.epidata.EpiDataDto)3 EventDto (de.symeda.sormas.api.event.EventDto)3 ExposureDto (de.symeda.sormas.api.exposure.ExposureDto)3 PersonContactDetailDto (de.symeda.sormas.api.person.PersonContactDetailDto)3 SampleDto (de.symeda.sormas.api.sample.SampleDto)3 LocationEditForm (de.symeda.sormas.ui.location.LocationEditForm)3 Label (com.vaadin.ui.Label)2 CheckBox (com.vaadin.v7.ui.CheckBox)2 Disease (de.symeda.sormas.api.Disease)2 BirthDateDto (de.symeda.sormas.api.caze.BirthDateDto)2