Search in sources :

Example 1 with PersonContactDetailDto

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;
}
Also used : PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) ArrayList(java.util.ArrayList) Date(java.util.Date) LocationDto(de.symeda.sormas.api.location.LocationDto) Location(de.symeda.sormas.backend.location.Location)

Example 2 with PersonContactDetailDto

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);
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Set(java.util.Set) HashSet(java.util.HashSet) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) HashSet(java.util.HashSet)

Example 3 with PersonContactDetailDto

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));
    }
}
Also used : Window(com.vaadin.ui.Window) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent) ContentMode(com.vaadin.shared.ui.ContentMode) AbstractTableField(de.symeda.sormas.ui.caze.AbstractTableField) Table(com.vaadin.v7.ui.Table) DataHelper(de.symeda.sormas.api.utils.DataHelper) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) Predicate(java.util.function.Predicate) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Window(com.vaadin.ui.Window) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Captions(de.symeda.sormas.api.i18n.Captions) PersonDto(de.symeda.sormas.api.person.PersonDto) Consumer(java.util.function.Consumer) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) FieldAccessCellStyleGenerator(de.symeda.sormas.ui.utils.FieldAccessCellStyleGenerator) Label(com.vaadin.ui.Label) Optional(java.util.Optional) VaadinIcons(com.vaadin.icons.VaadinIcons) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) ConfirmationComponent(de.symeda.sormas.ui.utils.ConfirmationComponent)

Example 4 with PersonContactDetailDto

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()));
}
Also used : PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) PatientDiaryPersonDto(de.symeda.sormas.api.externaljournal.patientdiary.PatientDiaryPersonDto) ExternalJournalValidation(de.symeda.sormas.api.externaljournal.ExternalJournalValidation) ArrayList(java.util.ArrayList) PatientDiaryQueryResponse(de.symeda.sormas.api.externaljournal.patientdiary.PatientDiaryQueryResponse) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with PersonContactDetailDto

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()));
}
Also used : PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) PatientDiaryPersonDto(de.symeda.sormas.api.externaljournal.patientdiary.PatientDiaryPersonDto) ExternalJournalValidation(de.symeda.sormas.api.externaljournal.ExternalJournalValidation) PatientDiaryQueryResponse(de.symeda.sormas.api.externaljournal.patientdiary.PatientDiaryQueryResponse) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonContactDetailDto (de.symeda.sormas.api.person.PersonContactDetailDto)12 PersonDto (de.symeda.sormas.api.person.PersonDto)9 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)6 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ExternalJournalValidation (de.symeda.sormas.api.externaljournal.ExternalJournalValidation)4 PatientDiaryPersonDto (de.symeda.sormas.api.externaljournal.patientdiary.PatientDiaryPersonDto)4 PatientDiaryQueryResponse (de.symeda.sormas.api.externaljournal.patientdiary.PatientDiaryQueryResponse)4 LocationDto (de.symeda.sormas.api.location.LocationDto)3 VaadinIcons (com.vaadin.icons.VaadinIcons)2 ContentMode (com.vaadin.shared.ui.ContentMode)2 Label (com.vaadin.ui.Label)2 Window (com.vaadin.ui.Window)2 Table (com.vaadin.v7.ui.Table)2 Captions (de.symeda.sormas.api.i18n.Captions)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 Strings (de.symeda.sormas.api.i18n.Strings)2 DataHelper (de.symeda.sormas.api.utils.DataHelper)2 UiFieldAccessCheckers (de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers)2