Search in sources :

Example 1 with JournalPersonDto

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

the class ExternalJournalService method handleExternalJournalPersonUpdateAsync.

public void handleExternalJournalPersonUpdateAsync(PersonReferenceDto person) {
    if (!configFacade.isExternalJournalActive()) {
        return;
    }
    /**
     * The .getPersonForJournal(...) here gets the person in the state it is (most likely) known to an external journal.
     * Changes of related data is assumed to be not yet persisted in the database.
     * 5 second delay added before notifying of update so that current transaction can complete and
     * new data can be retrieved from DB
     */
    JournalPersonDto existingPerson = personFacade.getPersonForJournal(person.getUuid());
    executorService.schedule((Runnable) () -> notifyExternalJournalPersonUpdate(existingPerson), 5, TimeUnit.SECONDS);
}
Also used : JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto)

Example 2 with JournalPersonDto

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

the class PersonFacadeEjbTest method testGetPersonForJournal.

@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 testGetPersonForJournal() {
    RDCFEntities rdcfEntities = creator.createRDCFEntities();
    UserDto user = creator.createUser(rdcfEntities, UserRole.CONTACT_SUPERVISOR);
    String phoneNumber = "+496211218490";
    String internationalPhoneNumber = "+49 621 1218490";
    final PersonDto person = creator.createPerson();
    person.setFirstName("Klaus");
    person.setLastName("Draufle");
    person.setSex(Sex.MALE);
    person.setEmailAddress("test@test.de");
    person.setPhone(phoneNumber);
    person.setBirthdateYYYY(2000);
    person.setBirthdateMM(6);
    person.setBirthdateDD(1);
    person.setSymptomJournalStatus(SymptomJournalStatus.REGISTERED);
    final ContactDto contact1 = creator.createContact(user.toReference(), person.toReference(), DateHelper.subtractDays(new Date(), 41));
    final ContactDto contact2 = creator.createContact(user.toReference(), person.toReference(), DateHelper.subtractDays(new Date(), 29));
    contact1.setOverwriteFollowUpUntil(true);
    contact2.setOverwriteFollowUpUntil(true);
    Date now = new Date();
    contact1.setFollowUpUntil(DateHelper.subtractDays(now, 20));
    contact2.setFollowUpUntil(DateHelper.subtractDays(now, 8));
    getPersonFacade().savePerson(person);
    getContactFacade().save(contact1);
    getContactFacade().save(contact2);
    JournalPersonDto exportPerson = getPersonFacade().getPersonForJournal(person.getUuid());
    assertEquals(person.getFirstName(), exportPerson.getFirstName());
    assertEquals(person.getLastName(), exportPerson.getLastName());
    assertEquals(person.getSex(), exportPerson.getSex());
    assertEquals(person.getEmailAddress(), exportPerson.getEmailAddress());
    assertEquals(internationalPhoneNumber, exportPerson.getPhone());
    assertEquals(person.getBirthdateYYYY(), exportPerson.getBirthdateYYYY());
    assertEquals(person.getBirthdateMM(), exportPerson.getBirthdateMM());
    assertEquals(person.getBirthdateDD(), exportPerson.getBirthdateDD());
    assertEquals(contact2.getFollowUpUntil(), exportPerson.getLatestFollowUpEndDate());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with JournalPersonDto

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

the class ExternalJournalServiceTest method givenRelevantChangeShouldNotify.

@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 givenRelevantChangeShouldNotify() {
    EntityManager entityManager = getEntityManager();
    PersonFacadeEjb.PersonFacadeEjbLocal personFacade = (PersonFacadeEjb.PersonFacadeEjbLocal) getPersonFacade();
    personFacade.setExternalJournalService(getExternalJournalService());
    PersonService personService = getPersonService();
    Person person = personService.createPerson();
    setPersonRelevantFields(person);
    // cannot use PersonFacade save since it also calls the method being tested
    EntityTransaction transaction = entityManager.getTransaction();
    transaction.begin();
    entityManager.persist(person);
    entityManager.flush();
    transaction.commit();
    // need to create a case with the person to avoid pseudonymization related errors
    creator.createCase(natUser.toReference(), new PersonReferenceDto(person.getUuid()), rdcf);
    JournalPersonDto journalPerson = personFacade.getPersonForJournal(person.getUuid());
    assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
    // Define relevant changes
    HashMap<String, Object> relevantChanges = new HashMap<String, Object>() {

        {
            put(Person.FIRST_NAME, "Heinz");
            put(Person.LAST_NAME, "Müller");
            put(Person.SEX, Sex.FEMALE);
            put(Person.BIRTHDATE_YYYY, 2001);
            put(Person.BIRTHDATE_MM, 7);
            put(Person.BIRTHDATE_DD, 2);
        }
    };
    person.setPhone("+496211218491");
    person.setEmailAddress("heinz@test.de");
    // Apply each change and make sure it makes notification considered necessary
    for (String propertyName : relevantChanges.keySet()) {
        journalPerson = personFacade.getPersonForJournal(person.getUuid());
        setPersonProperty(person, propertyName, relevantChanges.get(propertyName));
        person = entityManager.merge(person);
        assertTrue(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
        // Modify the SymptomJournalStatus of the original person
        journalPerson = personFacade.getPersonForJournal(person.getUuid());
        person.setSymptomJournalStatus(SymptomJournalStatus.DELETED);
        person = entityManager.merge(person);
        assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
        journalPerson = personFacade.getPersonForJournal(person.getUuid());
        person.setSymptomJournalStatus(SymptomJournalStatus.REJECTED);
        person = entityManager.merge(person);
        assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
        journalPerson = personFacade.getPersonForJournal(person.getUuid());
        person.setSymptomJournalStatus(SymptomJournalStatus.UNREGISTERED);
        person = entityManager.merge(person);
        assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
        journalPerson = personFacade.getPersonForJournal(person.getUuid());
        person.setSymptomJournalStatus(SymptomJournalStatus.ACCEPTED);
        person = entityManager.merge(person);
        assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
        // Apply any other relevant change and make sure notification is still considered necessary
        for (String secondPropertyName : relevantChanges.keySet()) {
            if (!secondPropertyName.equals(propertyName)) {
                journalPerson = personFacade.getPersonForJournal(person.getUuid());
                setPersonProperty(person, secondPropertyName, relevantChanges.get(secondPropertyName));
                person = entityManager.merge(person);
                assertTrue(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
            }
        }
        setPersonRelevantFields(person);
        person = entityManager.merge(person);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) HashMap(java.util.HashMap) PersonService(de.symeda.sormas.backend.person.PersonService) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) EntityManager(javax.persistence.EntityManager) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Person(de.symeda.sormas.backend.person.Person) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with JournalPersonDto

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

the class PersonFacadeEjb method getPersonForJournal.

public JournalPersonDto getPersonForJournal(PersonDto detailedPerson) {
    // only specific attributes of the person shall be returned:
    if (detailedPerson != null) {
        JournalPersonDto exportPerson = new JournalPersonDto();
        exportPerson.setUuid(detailedPerson.getUuid());
        exportPerson.setPseudonymized(detailedPerson.isPseudonymized());
        exportPerson.setFirstName(detailedPerson.getFirstName());
        exportPerson.setLastName(detailedPerson.getLastName());
        exportPerson.setBirthdateYYYY(detailedPerson.getBirthdateYYYY());
        exportPerson.setBirthdateMM(detailedPerson.getBirthdateMM());
        exportPerson.setBirthdateDD(detailedPerson.getBirthdateDD());
        exportPerson.setSex(detailedPerson.getSex());
        exportPerson.setLatestFollowUpEndDate(getLatestFollowUpEndDateByUuid(detailedPerson.getUuid()));
        exportPerson.setFollowUpStatus(getMostRelevantFollowUpStatusByUuid(detailedPerson.getUuid()));
        Pair<String, String> contactDetails = getContactDetails(detailedPerson);
        exportPerson.setEmailAddress(contactDetails.getElement0());
        exportPerson.setPhone(formatPhoneNumber(contactDetails.getElement1()));
        return exportPerson;
    } else {
        return null;
    }
}
Also used : JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto)

Aggregations

JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)4 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 Test (org.junit.Test)2 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)1 Person (de.symeda.sormas.backend.person.Person)1 PersonFacadeEjb (de.symeda.sormas.backend.person.PersonFacadeEjb)1 PersonService (de.symeda.sormas.backend.person.PersonService)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 EntityManager (javax.persistence.EntityManager)1 EntityTransaction (javax.persistence.EntityTransaction)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1