use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveSharedPointOfEntryCaseWithInfrastructureName.
@Test
public void testSaveSharedPointOfEntryCaseWithInfrastructureName() throws SormasToSormasException, SormasToSormasValidationException {
PersonDto person = createPersonDto(rdcf);
CaseDataDto caze = CaseDataDto.build(person.toReference(), Disease.CORONAVIRUS);
caze.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
caze.setResponsibleRegion(rdcf.region);
caze.setResponsibleDistrict(rdcf.district);
caze.setResponsibleCommunity(rdcf.community);
caze.setPointOfEntry(rdcf.pointOfEntry);
PortHealthInfoDto portHealthInfo = PortHealthInfoDto.build();
portHealthInfo.setAirlineName("Test Airline");
caze.setPortHealthInfo(portHealthInfo);
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(savedCase.getResponsibleRegion(), is(rdcf.region));
assertThat(savedCase.getResponsibleDistrict(), is(rdcf.district));
assertThat(savedCase.getResponsibleCommunity(), is(rdcf.community));
assertThat(savedCase.getPointOfEntry(), is(rdcf.pointOfEntry));
assertThat(savedCase.getPortHealthInfo().getAirlineName(), is("Test Airline"));
}
use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveSharedCaseWithUnknownFacility.
@Test
public void testSaveSharedCaseWithUnknownFacility() throws SormasToSormasException, SormasToSormasValidationException {
PersonDto person = createPersonDto(rdcf);
person.setFirstName("James");
person.setLastName("Smith");
CaseDataDto caze = createRemoteCaseDto(rdcf, person);
caze.setHealthFacility(new FacilityReferenceDto("unknown", "Unknown facility", "unknown"));
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(savedCase, is(notNullValue()));
assertThat(savedCase.getHealthFacility().getUuid(), is(FacilityDto.OTHER_FACILITY_UUID));
assertThat(savedCase.getHealthFacilityDetails(), is("Unknown facility"));
}
use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjbTest method testCountAndGetIndexListWithAssociations.
/**
* Test all {@link PersonAssociation} variants if they work. Also serves to review the generated SQL.
*/
@Test
public void testCountAndGetIndexListWithAssociations() {
PersonFacade cut = getPersonFacade();
Integer offset = null;
Integer limit = null;
List<SortProperty> sortProperties = null;
RDCF rdcf = creator.createRDCF();
UserDto user = creator.createUser(rdcf.region.getUuid(), null, null, null, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
loginWith(user);
// 1a. Test for all available PersonAssociations
for (PersonAssociation pa : PersonAssociation.values()) {
PersonCriteria criteria = new PersonCriteria().personAssociation(pa);
assertThat("Failed for testing association on count: " + pa.name(), cut.count(criteria), equalTo(0L));
assertThat(criteria.getPersonAssociation(), equalTo(pa));
assertThat("Failed for testing association on getIndexList: " + pa.name(), cut.getIndexList(criteria, offset, limit, sortProperties), is(empty()));
assertThat(criteria.getPersonAssociation(), equalTo(pa));
}
// 1b. Test that calling with "null" as criteria also works
assertThat(cut.count(null), equalTo(0L));
assertThat(cut.getIndexList(null, offset, limit, sortProperties), is(empty()));
// 2. Test paging windows
final PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1920, 1, 1);
final CaseDataDto case1 = creator.createCase(user.toReference(), person1.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
final PersonDto person2 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1920, 1, 1);
final ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), person2.toReference(), null, new Date(), new Date(), Disease.EVD, rdcf);
// 2a. count
assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.ALL)), equalTo(2L));
assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CASE)), equalTo(1L));
assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CONTACT)), equalTo(1L));
// 2b. getIndexList with all persons in the paging window
assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
offset = 0;
limit = 2;
assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
offset = 0;
limit = 1;
assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
// 2c. getIndexList [PersonAssociation.ALL] with only the contact person in the paging window (default sorting by changeDate)
offset = 1;
limit = 2;
assertPersonsFound(null, null, Arrays.asList(contact2.getPerson()), cut, offset, limit, sortProperties);
}
use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjbTest method testGetFollowUpEndDatesCasesOnly.
@Test
public void testGetFollowUpEndDatesCasesOnly() {
RDCFEntities rdcfEntities = creator.createRDCFEntities();
UserDto user = creator.createUser(rdcfEntities, UserRole.REST_EXTERNAL_VISITS_USER);
// Person without contact
creator.createPerson();
final PersonDto person1 = creator.createPerson();
final PersonDto person2 = creator.createPerson();
final CaseDataDto case11 = creator.createCase(user.toReference(), person1.toReference(), rdcfEntities);
final CaseDataDto case12 = creator.createCase(user.toReference(), person1.toReference(), rdcfEntities);
final CaseDataDto case2 = creator.createCase(user.toReference(), person2.toReference(), rdcfEntities);
Date now = new Date();
case11.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 41));
case11.setOverwriteFollowUpUntil(true);
case12.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 29));
case12.setOverwriteFollowUpUntil(true);
case2.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 21));
case2.setOverwriteFollowUpUntil(true);
case11.setFollowUpUntil(DateHelper.subtractDays(now, 20));
case12.setFollowUpUntil(DateHelper.subtractDays(now, 8));
case2.setFollowUpUntil(now);
getCaseFacade().save(case11);
getCaseFacade().save(case12);
getCaseFacade().save(case2);
List<PersonFollowUpEndDto> followUpEndDtos = getPersonFacade().getLatestFollowUpEndDates(null, false);
assertThat(followUpEndDtos, hasSize(2));
Optional<PersonFollowUpEndDto> result1 = followUpEndDtos.stream().filter(p -> p.getPersonUuid().equals(person1.getUuid())).findFirst();
assertTrue(result1.isPresent());
assertTrue(DateHelper.isSameDay(result1.get().getLatestFollowUpEndDate(), DateHelper.subtractDays(now, 8)));
Optional<PersonFollowUpEndDto> result2 = followUpEndDtos.stream().filter(p -> p.getPersonUuid().equals(person2.getUuid())).findFirst();
assertTrue(result2.isPresent());
assertTrue(DateHelper.isSameDay(result2.get().getLatestFollowUpEndDate(), now));
Date result3 = getPersonFacade().getLatestFollowUpEndDateByUuid(person1.getUuid());
assertTrue(DateHelper.isSameDay(result3, DateHelper.subtractDays(now, 8)));
}
use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjbTest method testGetMostRelevantFollowUpStatusByUuid.
@Test
public void testGetMostRelevantFollowUpStatusByUuid() {
RDCFEntities rdcfEntities = creator.createRDCFEntities();
PersonDto person = creator.createPerson();
UserDto user = creator.createUser(rdcfEntities, UserRole.REST_EXTERNAL_VISITS_USER);
ContactDto contact1 = creator.createContact(user.toReference(), person.toReference());
for (FollowUpStatus status : FollowUpStatus.values()) {
contact1.setFollowUpStatus(status);
getContactFacade().save(contact1);
if (FollowUpStatus.COMPLETED.equals(status) || FollowUpStatus.NO_FOLLOW_UP.equals(status)) {
// In this case the status is automatically updated to FOLLOW_UP, because the end of the follow up period has not yet been reached.
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
continue;
}
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(status));
}
ContactDto contact2 = creator.createContact(user.toReference(), person.toReference());
CaseDataDto case1 = creator.createCase(user.toReference(), person.toReference(), rdcfEntities);
updateFollowUpStatus(contact1, FollowUpStatus.FOLLOW_UP);
for (FollowUpStatus status : FollowUpStatus.values()) {
updateFollowUpStatus(case1, status);
updateFollowUpStatus(contact2, status);
// Other states must not interfere one with ongoing follow up
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
updateFollowUpStatus(contact1, status);
if (FollowUpStatus.COMPLETED.equals(status) || FollowUpStatus.NO_FOLLOW_UP.equals(status)) {
// In this case the status is automatically updated to FOLLOW_UP, because the end of the follow up period has not yet been reached.
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
updateFollowUpStatus(contact1, FollowUpStatus.FOLLOW_UP);
continue;
}
// In that case one clear status can be calculated
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(status));
updateFollowUpStatus(case1, FollowUpStatus.FOLLOW_UP);
// Also ongoing case follow up must not be overwritten
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
updateFollowUpStatus(case1, status);
updateFollowUpStatus(contact1, FollowUpStatus.FOLLOW_UP);
}
updateFollowUpStatus(contact1, FollowUpStatus.LOST);
updateFollowUpStatus(contact2, FollowUpStatus.CANCELED);
updateFollowUpStatus(case1, FollowUpStatus.LOST);
assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.NO_FOLLOW_UP));
}
Aggregations