use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testGetExportList.
@Test
public void testGetExportList() {
TestDataCreator.RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
UserDto user = useSurveillanceOfficerLogin(rdcf);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
ContactDto contact = creator.createContact(user.toReference(), user.toReference(), creator.createPerson("Contact", "Person").toReference(), caze, new Date(), new Date(), null, rdcf);
PersonDto contactPerson = getPersonFacade().getPersonByUuid(contact.getPerson().getUuid());
VisitDto visit = creator.createVisit(caze.getDisease(), contactPerson.toReference(), new Date(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
EpiDataDto epiData = contact.getEpiData();
epiData.setExposureDetailsKnown(YesNoUnknown.YES);
List<ExposureDto> travels = new ArrayList<>();
ExposureDto exposure = ExposureDto.build(ExposureType.TRAVEL);
exposure.getLocation().setDetails("Mallorca");
exposure.setStartDate(DateHelper.subtractDays(new Date(), 15));
exposure.setEndDate(DateHelper.subtractDays(new Date(), 7));
caze.getEpiData().getExposures().add(exposure);
travels.add(exposure);
epiData.setExposures(travels);
contact.setEpiData(epiData);
getContactFacade().save(contact);
contactPerson.getAddress().setRegion(new RegionReferenceDto(rdcf.region.getUuid(), null, null));
contactPerson.getAddress().setDistrict(new DistrictReferenceDto(rdcf.district.getUuid(), null, null));
contactPerson.getAddress().setCity("City");
contactPerson.getAddress().setStreet("Test street");
contactPerson.getAddress().setHouseNumber("Test number");
contactPerson.getAddress().setAdditionalInformation("Test information");
contactPerson.getAddress().setPostalCode("1234");
getPersonFacade().savePerson(contactPerson);
visit.getSymptoms().setAbdominalPain(SymptomState.YES);
getVisitFacade().saveVisit(visit);
ImmunizationDto immunization = creator.createImmunization(contact.getDisease(), contact.getPerson(), contact.getReportingUser(), ImmunizationStatus.ACQUIRED, MeansOfImmunization.VACCINATION, ImmunizationManagementStatus.COMPLETED, rdcf, DateHelper.subtractDays(new Date(), 10), DateHelper.subtractDays(new Date(), 5), DateHelper.subtractDays(new Date(), 1), null);
creator.createImmunization(contact.getDisease(), contact.getPerson(), contact.getReportingUser(), ImmunizationStatus.ACQUIRED, MeansOfImmunization.VACCINATION, ImmunizationManagementStatus.COMPLETED, rdcf, DateHelper.subtractDays(new Date(), 8), DateHelper.subtractDays(new Date(), 7), null, null);
VaccinationDto firstVaccination = creator.createVaccination(contact.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), DateHelper.subtractDays(new Date(), 7), Vaccine.OXFORD_ASTRA_ZENECA, VaccineManufacturer.ASTRA_ZENECA);
creator.createVaccination(contact.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), DateHelper.subtractDays(new Date(), 4), Vaccine.MRNA_1273, VaccineManufacturer.MODERNA);
VaccinationDto thirdVaccination = creator.createVaccination(contact.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), new Date(), Vaccine.COMIRNATY, VaccineManufacturer.BIONTECH_PFIZER);
List<ContactExportDto> results;
results = getContactFacade().getExportList(null, Collections.emptySet(), 0, 100, null, Language.EN);
// Database should contain one contact, associated visit and task
assertEquals(1, results.size());
// Make sure that everything that is added retrospectively (address, last cooperative visit date and symptoms) is present
ContactExportDto exportDto = results.get(0);
assertEquals(rdcf.region.getCaption(), exportDto.getAddressRegion());
assertEquals(rdcf.district.getCaption(), exportDto.getAddressDistrict());
assertEquals("City", exportDto.getCity());
assertEquals("Test street", exportDto.getStreet());
assertEquals("Test number", exportDto.getHouseNumber());
assertEquals("Test information", exportDto.getAdditionalInformation());
assertEquals("1234", exportDto.getPostalCode());
assertEquals(VaccinationStatus.VACCINATED, exportDto.getVaccinationStatus());
assertEquals(thirdVaccination.getVaccineName(), exportDto.getVaccineName());
assertEquals(firstVaccination.getVaccinationDate(), exportDto.getFirstVaccinationDate());
assertEquals(thirdVaccination.getVaccinationDate(), exportDto.getLastVaccinationDate());
assertNotNull(exportDto.getLastCooperativeVisitDate());
assertTrue(StringUtils.isNotEmpty(exportDto.getLastCooperativeVisitSymptoms()));
assertEquals(YesNoUnknown.YES, exportDto.getLastCooperativeVisitSymptomatic());
assertNotNull(exportDto.getEpiDataId());
assertTrue(exportDto.isTraveled());
assertEquals(EpiDataHelper.buildDetailedTravelString(exposure.getLocation().toString(), exposure.getDescription(), exposure.getStartDate(), exposure.getEndDate(), Language.EN), exportDto.getTravelHistory());
assertThat(exportDto.getEventCount(), equalTo(0L));
// one Contact with 2 Events
UserReferenceDto reportingUser = new UserReferenceDto(user.getUuid());
EventDto event1 = creator.createEvent(reportingUser, DateHelper.subtractDays(new Date(), 1));
EventDto event2 = creator.createEvent(reportingUser, new Date());
creator.createEventParticipant(new EventReferenceDto(event2.getUuid()), contactPerson, reportingUser);
creator.createEventParticipant(new EventReferenceDto(event1.getUuid()), contactPerson, reportingUser);
results = getContactFacade().getExportList(null, Collections.emptySet(), 0, 100, null, Language.EN);
assertThat(results, hasSize(1));
{
ContactExportDto dto = results.get(0);
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getEventCount(), equalTo(2L));
}
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testMergeContact.
@Test
public void testMergeContact() throws IOException {
useNationalUserLogin();
// 1. Create
// Create leadContact
UserDto leadUser = creator.createUser("", "", "", "First", "User");
UserReferenceDto leadUserReference = new UserReferenceDto(leadUser.getUuid());
PersonDto leadPerson = creator.createPerson("Alex", "Miller");
PersonContactDetailDto leadContactDetail = creator.createPersonContactDetail(leadPerson.toReference(), true, PersonContactDetailType.PHONE, "123");
leadPerson.setPersonContactDetails(Collections.singletonList(leadContactDetail));
getPersonFacade().savePerson(leadPerson);
PersonReferenceDto leadPersonReference = new PersonReferenceDto(leadPerson.getUuid());
RDCF leadRdcf = creator.createRDCF();
CaseDataDto sourceCase = creator.createCase(leadUserReference, leadPersonReference, Disease.CORONAVIRUS, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), leadRdcf);
ContactDto leadContact = creator.createContact(leadUserReference, leadUserReference, leadPersonReference, sourceCase, new Date(), new Date(), Disease.CORONAVIRUS, leadRdcf, (c) -> {
c.setAdditionalDetails("Test additional details");
c.setFollowUpComment("Test followup comment");
});
getContactFacade().save(leadContact);
VisitDto leadVisit = creator.createVisit(leadContact.getDisease(), leadContact.getPerson(), leadContact.getReportDateTime());
getVisitFacade().saveVisit(leadVisit);
// Create otherContact
UserDto otherUser = creator.createUser("", "", "", "Some", "User");
UserReferenceDto otherUserReference = new UserReferenceDto(otherUser.getUuid());
PersonDto otherPerson = creator.createPerson("Max", "Smith");
PersonContactDetailDto otherContactDetail = creator.createPersonContactDetail(otherPerson.toReference(), true, PersonContactDetailType.PHONE, "456");
otherPerson.setPersonContactDetails(Collections.singletonList(otherContactDetail));
otherPerson.setBirthWeight(2);
getPersonFacade().savePerson(otherPerson);
PersonReferenceDto otherPersonReference = new PersonReferenceDto(otherPerson.getUuid());
RDCF otherRdcf = creator.createRDCF();
ContactDto otherContact = creator.createContact(otherUserReference, otherUserReference, otherPersonReference, sourceCase, new Date(), new Date(), Disease.CORONAVIRUS, otherRdcf, (c) -> {
c.setAdditionalDetails("Test other additional details");
c.setFollowUpComment("Test other followup comment");
});
ContactReferenceDto otherContactReference = getContactFacade().getReferenceByUuid(otherContact.getUuid());
ContactDto contact = creator.createContact(otherUserReference, otherUserReference, otherPersonReference, sourceCase, new Date(), new Date(), null);
Region region = creator.createRegion("");
District district = creator.createDistrict("", region);
Facility facility = creator.createFacility("", region, district, creator.createCommunity("", district));
SampleDto sample = creator.createSample(otherContactReference, otherUserReference, getFacilityFacade().getReferenceByUuid(facility.getUuid()), null);
TaskDto task = creator.createTask(TaskContext.CONTACT, TaskType.CONTACT_INVESTIGATION, TaskStatus.PENDING, null, otherContactReference, new EventReferenceDto(), new Date(), otherUserReference);
getContactFacade().save(otherContact);
VisitDto otherVisit = creator.createVisit(otherContact.getDisease(), otherContact.getPerson(), otherContact.getReportDateTime());
otherVisit.getSymptoms().setAbdominalPain(SymptomState.YES);
getVisitFacade().saveVisit(otherVisit);
DocumentDto document = creator.createDocument(leadUserReference, "document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CONTACT, leadContact.getUuid(), "content".getBytes(StandardCharsets.UTF_8));
DocumentDto otherDocument = creator.createDocument(leadUserReference, "other_document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CONTACT, otherContact.getUuid(), "other content".getBytes(StandardCharsets.UTF_8));
// 2. Merge
getContactFacade().mergeContact(leadContact.getUuid(), otherContact.getUuid());
// 3. Test
ContactDto mergedContact = getContactFacade().getByUuid(leadContact.getUuid());
PersonDto mergedPerson = getPersonFacade().getPersonByUuid(mergedContact.getPerson().getUuid());
// Check no values
assertNull(mergedPerson.getBirthdateDD());
// Check 'lead and other have different values'
assertEquals(leadContact.getPerson().getFirstName(), mergedPerson.getFirstName());
// Check 'lead has value, other has not'
assertEquals(leadContact.getPerson().getLastName(), mergedPerson.getLastName());
// Check 'lead has no value, other has'
assertEquals(otherPerson.getBirthWeight(), mergedPerson.getBirthWeight());
// Check merge comments
assertEquals(mergedContact.getAdditionalDetails(), "Test additional details Test other additional details");
assertEquals(mergedContact.getFollowUpComment(), "Test followup comment Test other followup comment");
// 4. Test Reference Changes
// 4.1 Samples
List<String> sampleUuids = new ArrayList<String>();
sampleUuids.add(sample.getUuid());
assertEquals(leadContact.getUuid(), getSampleFacade().getByUuids(sampleUuids).get(0).getAssociatedContact().getUuid());
// 4.2 Tasks
List<String> taskUuids = new ArrayList<String>();
taskUuids.add(task.getUuid());
assertEquals(leadContact.getUuid(), getTaskFacade().getByUuids(taskUuids).get(0).getContact().getUuid());
// 4.3 Visits;
List<String> mergedVisits = getVisitFacade().getIndexList(new VisitCriteria().contact(mergedContact.toReference()), null, null, null).stream().map(VisitIndexDto::getUuid).collect(Collectors.toList());
assertEquals(2, mergedVisits.size());
assertTrue(mergedVisits.contains(leadVisit.getUuid()));
assertTrue(mergedVisits.contains(otherVisit.getUuid()));
// 5 Documents
List<DocumentDto> mergedDocuments = getDocumentFacade().getDocumentsRelatedToEntity(DocumentRelatedEntityType.CONTACT, leadContact.getUuid());
assertEquals(mergedDocuments.size(), 2);
List<String> documentUuids = mergedDocuments.stream().map(DocumentDto::getUuid).collect(Collectors.toList());
assertTrue(documentUuids.contains(document.getUuid()));
assertTrue(documentUuids.contains(otherDocument.getUuid()));
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method mergeContact.
@Override
public void mergeContact(String leadUuid, String otherUuid) {
ContactDto leadContactDto = getContactWithoutPseudonyimizationByUuid(leadUuid);
ContactDto otherContactDto = getContactWithoutPseudonyimizationByUuid(otherUuid);
// 1 Merge Dtos
// 1.1 Contact
copyDtoValues(leadContactDto, otherContactDto);
save(leadContactDto);
// 1.2 Person - Only merge when the persons have different UUIDs
if (!DataHelper.equal(leadContactDto.getPerson().getUuid(), otherContactDto.getPerson().getUuid())) {
PersonDto leadPerson = personFacade.getPersonByUuid(leadContactDto.getPerson().getUuid());
PersonDto otherPerson = personFacade.getPersonByUuid(otherContactDto.getPerson().getUuid());
personFacade.mergePerson(leadPerson, otherPerson);
}
// 2 Change ContactReference
Contact leadContact = service.getByUuid(leadContactDto.getUuid());
Contact otherContact = service.getByUuid(otherContactDto.getUuid());
// 2.1 Tasks
List<Task> tasks = taskService.findBy(new TaskCriteria().contact(otherContactDto.toReference()), true);
for (Task task : tasks) {
// simply move existing entities to the merge target
task.setContact(leadContact);
taskService.ensurePersisted(task);
}
// 2.2 Samples
List<Sample> samples = sampleService.findBy(new SampleCriteria().contact(otherContactDto.toReference()), null);
for (Sample sample : samples) {
// simply move existing entities to the merge target
sample.setAssociatedContact(leadContact);
sampleService.ensurePersisted(sample);
}
// (set the person and the disease of the visit, saveVisit does the rest)
for (VisitDto otherVisit : otherContact.getVisits().stream().map(VisitFacadeEjb::toDto).collect(Collectors.toList())) {
otherVisit.setPerson(leadContactDto.getPerson());
otherVisit.setDisease(leadContactDto.getDisease());
visitFacade.saveVisit(otherVisit);
}
// 4 Documents
List<Document> documents = documentService.getRelatedToEntity(DocumentRelatedEntityType.CONTACT, otherContact.getUuid());
for (Document document : documents) {
document.setRelatedEntityUuid(leadContact.getUuid());
documentService.ensurePersisted(document);
}
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjbTest method testSymptomsUpdatedByVisit.
@Test
public void testSymptomsUpdatedByVisit() {
RDCF rdcf = creator.createRDCF();
UserReferenceDto user = creator.createUser(rdcf).toReference();
PersonReferenceDto cazePerson = creator.createPerson("Foo", "Bar").toReference();
CaseDataDto caze = creator.createCase(user, cazePerson, Disease.CORONAVIRUS, CaseClassification.NOT_CLASSIFIED, InvestigationStatus.PENDING, new Date(), rdcf);
caze.getSymptoms().setChestPain(SymptomState.YES);
// Add a new visit to the case
VisitDto visit = creator.createVisit(caze.getDisease(), caze.getPerson(), caze.getReportDate(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
visit.getSymptoms().setAbdominalPain(SymptomState.YES);
visit.getSymptoms().setChestPain(SymptomState.NO);
getCaseFacade().save(caze);
getVisitFacade().saveVisit(visit);
CaseDataDto updatedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertEquals(SymptomState.YES, updatedCase.getSymptoms().getChestPain());
assertEquals(SymptomState.YES, updatedCase.getSymptoms().getAbdominalPain());
// Update an existing visit
visit.getSymptoms().setAcuteRespiratoryDistressSyndrome(SymptomState.YES);
getVisitFacade().saveVisit(visit);
updatedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertEquals(SymptomState.YES, updatedCase.getSymptoms().getChestPain());
assertEquals(SymptomState.YES, updatedCase.getSymptoms().getAbdominalPain());
assertEquals(SymptomState.YES, updatedCase.getSymptoms().getAcuteRespiratoryDistressSyndrome());
assertTrue(updatedCase.getSymptoms().getSymptomatic());
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class TestDataCreator method createVisit.
public VisitDto createVisit(Disease disease, PersonReferenceDto person, Date visitDateTime, VisitStatus visitStatus, VisitOrigin visitOrigin, Consumer<VisitDto> customConfig) {
VisitDto visit = VisitDto.build(person, disease, visitOrigin);
visit.setVisitDateTime(visitDateTime);
visit.setVisitStatus(visitStatus);
if (customConfig != null) {
customConfig.accept(visit);
}
visit = beanTest.getVisitFacade().saveVisit(visit);
return visit;
}
Aggregations