Search in sources :

Example 1 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method savePersonWithoutNotifyingExternalJournal.

/**
 * Saves the received person.
 * This method always checks if the given source person data is outdated
 * The approximate age reference date is calculated and set on the person object to be saved. In case the case classification was
 * changed by saving the person,
 * If the person is enrolled in the external journal, the relevant data is validated,but the external journal is not notified. The task
 * of notifying the external journals falls to the caller of this method.
 * Also, in case the case classification was changed, the new classification will be returned.
 *
 * @param source
 *            the person dto object to be saved
 * @return a pair of objects containing:
 *         - the new case classification or null if it was not changed
 *         - the old person data from the database
 * @throws ValidationRuntimeException
 *             if the passed source person to be saved contains invalid data
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Pair<CaseClassification, PersonDto> savePersonWithoutNotifyingExternalJournal(@Valid PersonDto source) throws ValidationRuntimeException {
    Person existingPerson = personService.getByUuid(source.getUuid());
    PersonDto existingPersonDto = toDto(existingPerson);
    List<CaseDataDto> personCases = caseFacade.getAllCasesOfPerson(source.getUuid());
    computeApproximateAgeReferenceDate(existingPersonDto, source);
    restorePseudonymizedDto(source, existingPerson, existingPersonDto);
    validate(source);
    if (existingPersonDto != null && existingPersonDto.isEnrolledInExternalJournal()) {
        externalJournalService.validateExternalJournalPerson(source);
    }
    existingPerson = fillOrBuildEntity(source, existingPerson, true);
    personService.ensurePersisted(existingPerson);
    onPersonChanged(existingPersonDto, existingPerson);
    CaseClassification newClassification = getNewCaseClassification(personCases);
    return Pair.createPair(newClassification, existingPersonDto);
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with PersonDto

use of de.symeda.sormas.api.person.PersonDto 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 3 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method savePerson.

/**
 * Saves the received person.
 * If checkChangedDate is specified, it checks whether the the person from the database has a higher timestamp than the source object,
 * so it prevents overwriting with obsolete data.
 * If the person to be saved is enrolled in the external journal, the relevant data is validated and, if changed, the external journal
 * is notified.
 *
 * @param source
 *            the person dto object to be saved
 * @param checkChangeDate
 *            a boolean specifying whether to check if the source data is outdated
 * @return the newly saved person
 * @throws ValidationRuntimeException
 *             if the passed source person to be saved contains invalid data
 */
public PersonDto savePerson(@Valid PersonDto source, boolean checkChangeDate, boolean syncShares, boolean skipValidation) throws ValidationRuntimeException {
    Person person = personService.getByUuid(source.getUuid());
    PersonDto existingPerson = toDto(person);
    restorePseudonymizedDto(source, person, existingPerson);
    if (!skipValidation) {
        validate(source);
    }
    if (existingPerson != null && existingPerson.isEnrolledInExternalJournal()) {
        if (source.isEnrolledInExternalJournal()) {
            externalJournalService.validateExternalJournalPerson(source);
        }
        externalJournalService.handleExternalJournalPersonUpdateAsync(source.toReference());
    }
    person = fillOrBuildEntity(source, person, checkChangeDate);
    personService.ensurePersisted(person);
    onPersonChanged(existingPerson, person, syncShares);
    return convertToDto(person, Pseudonymizer.getDefault(userService::hasRight), existingPerson == null || personService.inJurisdictionOrOwned(person));
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto)

Example 4 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method convertToDto.

public PersonDto convertToDto(Person p, Pseudonymizer pseudonymizer, boolean inJurisdiction) {
    final PersonDto personDto = toDto(p);
    pseudonymizeDto(personDto, pseudonymizer, inJurisdiction);
    return personDto;
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto)

Example 5 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testGetAllActiveUuids.

@Test
public void testGetAllActiveUuids() throws ExternalSurveillanceToolException {
    TestDataCreator.RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto person = creator.createPerson();
    PersonDto person2 = creator.createPerson();
    PersonDto person3 = creator.createPerson();
    PersonDto person4 = creator.createPerson();
    PersonDto person5 = creator.createPerson();
    // contacts
    creator.createContact(user.toReference(), person.toReference());
    creator.createContact(user.toReference(), person5.toReference());
    ContactDto deletedContact = creator.createContact(user.toReference(), person2.toReference());
    getContactFacade().deleteContact(deletedContact.getUuid());
    // cases
    creator.createCase(user.toReference(), person.toReference(), rdcf);
    creator.createCase(user.toReference(), person3.toReference(), rdcf);
    CaseDataDto deletedCase = creator.createCase(user.toReference(), person4.toReference(), rdcf);
    getCaseFacade().deleteCase(deletedCase.getUuid());
    // Attached to case and contact
    creator.createVisit(person.toReference());
    // Attached to contact only
    creator.createVisit(person5.toReference());
    // Attached to case only
    creator.createVisit(person3.toReference());
    VisitDto visitOfDeletedContact = creator.createVisit(person2.toReference());
    VisitDto visitOfDeletedCase = creator.createVisit(person4.toReference());
    List<String> visitUuids = getVisitFacade().getAllActiveUuids();
    assertThat(visitUuids, hasSize(3));
    assertThat(visitUuids, not(contains(visitOfDeletedContact.getUuid())));
    assertThat(visitUuids, not(contains(visitOfDeletedCase.getUuid())));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonDto (de.symeda.sormas.api.person.PersonDto)332 Test (org.junit.Test)241 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)178 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)171 Date (java.util.Date)165 UserDto (de.symeda.sormas.api.user.UserDto)152 ContactDto (de.symeda.sormas.api.contact.ContactDto)93 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 LocalDate (java.time.LocalDate)59 SampleDto (de.symeda.sormas.api.sample.SampleDto)54 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)51 EventDto (de.symeda.sormas.api.event.EventDto)45 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)43 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)39 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)38 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)37 Disease (de.symeda.sormas.api.Disease)36 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)36 ArrayList (java.util.ArrayList)35 List (java.util.List)32