use of de.symeda.sormas.api.person.PersonContactDetailDto in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjb method toDto.
public static PersonDto toDto(Person source) {
if (source == null) {
return null;
}
PersonDto target = new PersonDto();
DtoHelper.fillDto(target, source);
target.setFirstName(source.getFirstName());
target.setLastName(source.getLastName());
target.setSalutation(source.getSalutation());
target.setOtherSalutation(source.getOtherSalutation());
target.setSex(source.getSex());
target.setPresentCondition(source.getPresentCondition());
target.setBirthdateDD(source.getBirthdateDD());
target.setBirthdateMM(source.getBirthdateMM());
target.setBirthdateYYYY(source.getBirthdateYYYY());
if (source.getBirthdateYYYY() != null) {
// calculate the approximate age based on the birth date
// still not sure whether this is a good solution
Pair<Integer, ApproximateAgeType> pair = ApproximateAgeHelper.getApproximateAge(source.getBirthdateYYYY(), source.getBirthdateMM(), source.getBirthdateDD(), source.getDeathDate());
target.setApproximateAge(pair.getElement0());
target.setApproximateAgeType(pair.getElement1());
target.setApproximateAgeReferenceDate(source.getDeathDate() != null ? source.getDeathDate() : new Date());
} else {
target.setApproximateAge(source.getApproximateAge());
target.setApproximateAgeType(source.getApproximateAgeType());
target.setApproximateAgeReferenceDate(source.getApproximateAgeReferenceDate());
}
target.setCauseOfDeath(source.getCauseOfDeath());
target.setCauseOfDeathDetails(source.getCauseOfDeathDetails());
target.setCauseOfDeathDisease(source.getCauseOfDeathDisease());
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.setBirthName(source.getBirthName());
target.setNickname(source.getNickname());
target.setMothersMaidenName(source.getMothersMaidenName());
target.setAddress(LocationFacadeEjb.toDto(source.getAddress()));
List<LocationDto> locations = new ArrayList<>();
for (Location location : source.getAddresses()) {
LocationDto locationDto = LocationFacadeEjb.toDto(location);
locations.add(locationDto);
}
target.setAddresses(locations);
if (!CollectionUtils.isEmpty(source.getPersonContactDetails())) {
target.setPersonContactDetails(source.getPersonContactDetails().stream().map(entity -> {
final PersonContactDetailDto personContactDetailDto = PersonContactDetailDto.build(source.toReference(), entity.isPrimaryContact(), entity.getPersonContactDetailType(), entity.getPhoneNumberType(), entity.getDetails(), entity.getContactInformation(), entity.getAdditionalInformation(), entity.isThirdParty(), entity.getThirdPartyRole(), entity.getThirdPartyName());
DtoHelper.fillDto(personContactDetailDto, entity);
return personContactDetailDto;
}).collect(Collectors.toList()));
}
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());
target.setPlaceOfBirthRegion(RegionFacadeEjb.toReferenceDto(source.getPlaceOfBirthRegion()));
target.setPlaceOfBirthDistrict(DistrictFacadeEjb.toReferenceDto(source.getPlaceOfBirthDistrict()));
target.setPlaceOfBirthCommunity(CommunityFacadeEjb.toReferenceDto(source.getPlaceOfBirthCommunity()));
target.setPlaceOfBirthFacility(FacilityFacadeEjb.toReferenceDto(source.getPlaceOfBirthFacility()));
target.setPlaceOfBirthFacilityDetails(source.getPlaceOfBirthFacilityDetails());
target.setGestationAgeAtBirth(source.getGestationAgeAtBirth());
target.setBirthWeight(source.getBirthWeight());
target.setPassportNumber(source.getPassportNumber());
target.setNationalHealthId(source.getNationalHealthId());
target.setPlaceOfBirthFacilityType(source.getPlaceOfBirthFacilityType());
target.setSymptomJournalStatus(source.getSymptomJournalStatus());
target.setHasCovidApp(source.isHasCovidApp());
target.setCovidCodeDelivered(source.isCovidCodeDelivered());
target.setExternalId(source.getExternalId());
target.setExternalToken(source.getExternalToken());
target.setInternalToken(source.getInternalToken());
target.setBirthCountry(CountryFacadeEjb.toReferenceDto(source.getBirthCountry()));
target.setCitizenship(CountryFacadeEjb.toReferenceDto(source.getCitizenship()));
target.setAdditionalDetails(source.getAdditionalDetails());
return target;
}
use of de.symeda.sormas.api.person.PersonContactDetailDto in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjb method mergePerson.
@Override
public void mergePerson(PersonDto leadPerson, PersonDto otherPerson) {
// Make sure the resulting person does not have multiple primary contact details
Set primaryContactDetailTypes = new HashSet<>();
for (PersonContactDetailDto contactDetailDto : leadPerson.getPersonContactDetails()) {
if (contactDetailDto.isPrimaryContact()) {
primaryContactDetailTypes.add(contactDetailDto.getPersonContactDetailType());
}
}
for (PersonContactDetailDto contactDetailDto : otherPerson.getPersonContactDetails()) {
if (contactDetailDto.isPrimaryContact() && primaryContactDetailTypes.contains(contactDetailDto.getPersonContactDetailType())) {
contactDetailDto.setPrimaryContact(false);
}
}
if (!leadPerson.getUuid().equals(otherPerson.getUuid())) {
for (ImmunizationDto immunizationDto : immunizationFacade.getByPersonUuids(Collections.singletonList(otherPerson.getUuid()))) {
immunizationFacade.copyImmunizationsToLeadPerson(immunizationDto, leadPerson);
}
}
DtoHelper.copyDtoValues(leadPerson, otherPerson, false);
savePerson(leadPerson);
}
use of de.symeda.sormas.api.person.PersonContactDetailDto in project SORMAS-Project by hzi-braunschweig.
the class PersonContactDetailsField method editEntry.
@Override
protected void editEntry(PersonContactDetailDto entry, boolean create, Consumer<PersonContactDetailDto> commitCallback) {
if (create && entry.getUuid() == null) {
entry.setUuid(DataHelper.createUuid());
}
PersonContactDetailEditForm editForm = new PersonContactDetailEditForm(fieldVisibilityCheckers, fieldAccessCheckers);
editForm.setValue(entry);
final CommitDiscardWrapperComponent<PersonContactDetailEditForm> editView = new CommitDiscardWrapperComponent<>(editForm, true, editForm.getFieldGroup());
editView.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.entityPersonContactDetail));
editView.addCommitListener(() -> {
if (!editForm.getFieldGroup().isModified()) {
final Predicate<PersonContactDetailDto> sameTypePrimaryPredicate = pcd -> pcd.getPersonContactDetailType() == entry.getPersonContactDetailType() && !entry.getUuid().equals(pcd.getUuid()) && pcd.isPrimaryContact();
if (entry.isPrimaryContact()) {
Optional<PersonContactDetailDto> existingPrimaryContactDetails = getContainer().getItemIds().stream().filter(sameTypePrimaryPredicate).findFirst();
if (existingPrimaryContactDetails.isPresent()) {
VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingUpdatePersonContactDetails), new Label(I18nProperties.getString(Strings.messagePersonContactDetailsPrimaryDuplicate)), questionWindow -> {
ConfirmationComponent confirmationComponent = new ConfirmationComponent(false) {
private static final long serialVersionUID = 1L;
@Override
protected void onConfirm() {
existingPrimaryContactDetails.get().setPrimaryContact(false);
commitCallback.accept(editForm.getValue());
questionWindow.close();
}
@Override
protected void onCancel() {
entry.setPrimaryContact(false);
commitCallback.accept(editForm.getValue());
questionWindow.close();
}
};
confirmationComponent.getConfirmButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
confirmationComponent.getCancelButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
return confirmationComponent;
}, null);
} else {
commitCallback.accept(editForm.getValue());
}
} else {
commitCallback.accept(editForm.getValue());
}
}
});
if (!isEmpty(entry)) {
editView.addDeleteListener(() -> {
popupWindow.close();
PersonContactDetailsField.this.removeEntry(entry);
}, I18nProperties.getCaption(PersonContactDetailDto.I18N_PREFIX));
}
}
use of de.symeda.sormas.api.person.PersonContactDetailDto in project SORMAS-Project by hzi-braunschweig.
the class ExternalJournalServiceTest method givenMultipleNonPrimaryEmailsWithPhoneOnlyAccepted.
@Test
public /*
* If you need to change this test to make it pass, you probably changed the behaviour of the ExternalVisitsResource.
* Please note that other system used alongside with SORMAS are depending on this, so that their developers must be notified of any
* relevant API changes some time before they go into any test and productive system. Please inform the SORMAS core development team at
* https://gitter.im/SORMAS-Project!
*/
void givenMultipleNonPrimaryEmailsWithPhoneOnlyAccepted() {
PatientDiaryQueryResponse response = new PatientDiaryQueryResponse();
response.setCount(0);
PersonDto person = PersonDto.build();
person.setFirstName("James");
List<PersonContactDetailDto> contactDetails = new ArrayList<>();
PersonContactDetailDto nonPrimaryMail1 = creator.createPersonContactDetail(person.toReference(), false, PersonContactDetailType.EMAIL, "test1@test.de");
PersonContactDetailDto nonPrimaryMail2 = creator.createPersonContactDetail(person.toReference(), false, PersonContactDetailType.EMAIL, "test2@test.de");
contactDetails.add(nonPrimaryMail1);
contactDetails.add(nonPrimaryMail2);
person.setPersonContactDetails(contactDetails);
ExternalJournalValidation result;
// phone == null
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.SEVERAL_PHONES_OR_EMAILS.getErrorLanguageKey()));
// phone == non primary
person.setAdditionalPhone("+49 621 121 849-0");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertTrue(result.isValid());
assertTrue(result.getMessage().isEmpty());
// phone == multiple non primary
person.setAdditionalPhone("+49 621 121 849-1");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.SEVERAL_PHONES_OR_EMAILS.getErrorLanguageKey()));
// phone == valid primary
person.setPhone("+49 621 121 849-2");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertTrue(result.isValid());
assertTrue(result.getMessage().isEmpty());
// phone == invalid non primary
removePhoneContactDetails(person);
person.setAdditionalPhone("0");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_PHONE.getErrorLanguageKey()));
// phone == invalid primary
person.setPhone("0");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_PHONE.getErrorLanguageKey()));
// phone taken
// this number is pretended to be already in use (see @Before)
person.setPhone("+49 621 121 849-3");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.PHONE_TAKEN.getErrorLanguageKey()));
}
use of de.symeda.sormas.api.person.PersonContactDetailDto in project SORMAS-Project by hzi-braunschweig.
the class ExternalJournalServiceTest method givenInvalidNonPrimaryEmailWithPhoneOnlyAccepted.
@Test
public /*
* If you need to change this test to make it pass, you probably changed the behaviour of the ExternalVisitsResource.
* Please note that other system used alongside with SORMAS are depending on this, so that their developers must be notified of any
* relevant API changes some time before they go into any test and productive system. Please inform the SORMAS core development team at
* https://gitter.im/SORMAS-Project!
*/
void givenInvalidNonPrimaryEmailWithPhoneOnlyAccepted() {
PatientDiaryQueryResponse response = new PatientDiaryQueryResponse();
response.setCount(0);
PersonDto person = PersonDto.build();
person.setFirstName("James");
PersonContactDetailDto contactDetail = creator.createPersonContactDetail(person.toReference(), false, PersonContactDetailType.EMAIL, "test@test");
person.setPersonContactDetails(new ArrayList<>(Collections.singletonList(contactDetail)));
ExternalJournalValidation result;
// phone == null
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()));
// phone == non primary
person.setAdditionalPhone("+49 621 121 849-0");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()));
// phone == multiple non primary
person.setAdditionalPhone("+49 621 121 849-1");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()));
// phone == valid primary
person.setPhone("+49 621 121 849-2");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()));
// phone == invalid non primary
removePhoneContactDetails(person);
person.setAdditionalPhone("0");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()) + "\n" + I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_PHONE.getErrorLanguageKey()));
// phone == invalid primary
person.setPhone("0");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()) + "\n" + I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_PHONE.getErrorLanguageKey()));
// phone taken
// this number is pretended to be already in use (see @Before)
person.setPhone("+49 621 121 849-3");
result = getExternalJournalService().validatePatientDiaryPerson(person);
assertFalse(result.isValid());
assertEquals(result.getMessage(), I18nProperties.getValidationError(PatientDiaryValidationError.INVALID_EMAIL.getErrorLanguageKey()) + "\n" + I18nProperties.getValidationError(PatientDiaryValidationError.PHONE_TAKEN.getErrorLanguageKey()));
}
Aggregations