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;
}
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());
}
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());
}
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);
}
}
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());
}
}
Aggregations