use of de.symeda.sormas.api.contact.ContactExportDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testGetExportListWithoutRelevantVaccinations.
@Test
public void testGetExportListWithoutRelevantVaccinations() {
RDCFEntities rdcfEntities = creator.createRDCFEntities("Region", "District", "Community", "Facility");
RDCF rdcf = new RDCF(rdcfEntities);
UserDto user = useSurveillanceOfficerLogin(rdcf);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = createCaze(user, cazePerson, rdcfEntities);
ContactDto contact = createContact(user, caze, 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);
VaccinationDto vaccination = creator.createVaccinationWithDetails(caze.getReportingUser(), immunization.toReference(), HealthConditionsDto.build(), DateHelper.addDays(new Date(), 1), Vaccine.MRNA_1273, VaccineManufacturer.MODERNA, VaccinationInfoSource.UNKNOWN, "inn2", "456", "code456", "2");
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());
assertNull(exportDto.getFirstVaccinationDate());
assertNull(exportDto.getVaccineName());
assertNull(exportDto.getLastVaccinationDate());
assertNull(exportDto.getVaccinationInfoSource());
assertNull(exportDto.getVaccineInn());
assertNull(exportDto.getVaccineBatchNumber());
assertNull(exportDto.getVaccineAtcCode());
assertEquals(exportDto.getNumberOfDoses(), "");
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());
assertTrue(exportDto.getEventCount().equals(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);
assertEquals(results.size(), 1);
{
ContactExportDto dto = results.get(0);
assertEquals(dto.getLatestEventId(), event2.getUuid());
assertEquals(dto.getLatestEventTitle(), event2.getEventTitle());
assertTrue(dto.getEventCount().equals(2L));
}
}
use of de.symeda.sormas.api.contact.ContactExportDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method getExportList.
@Override
@RolesAllowed(UserRight._CONTACT_EXPORT)
public List<ContactExportDto> getExportList(ContactCriteria contactCriteria, Collection<String> selectedRows, int first, int max, ExportConfigurationDto exportConfiguration, Language userLanguage) {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<ContactExportDto> cq = cb.createQuery(ContactExportDto.class);
final Root<Contact> contact = cq.from(Contact.class);
final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
final ContactJoins joins = contactQueryContext.getJoins();
cq.multiselect(contact.get(Contact.ID), joins.getPerson().get(Person.ID), contact.get(Contact.UUID), joins.getCaze().get(Case.UUID), joins.getCaze().get(Case.CASE_CLASSIFICATION), contact.get(Contact.DISEASE), contact.get(Contact.DISEASE_DETAILS), contact.get(Contact.CONTACT_CLASSIFICATION), contact.get(Contact.MULTI_DAY_CONTACT), contact.get(Contact.FIRST_CONTACT_DATE), contact.get(Contact.LAST_CONTACT_DATE), contact.get(Contact.CREATION_DATE), joins.getPerson().get(Person.UUID), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), joins.getPerson().get(Person.SALUTATION), joins.getPerson().get(Person.OTHER_SALUTATION), joins.getPerson().get(Person.SEX), joins.getPerson().get(Person.BIRTHDATE_DD), joins.getPerson().get(Person.BIRTHDATE_MM), joins.getPerson().get(Person.BIRTHDATE_YYYY), joins.getPerson().get(Person.APPROXIMATE_AGE), joins.getPerson().get(Person.APPROXIMATE_AGE_TYPE), contact.get(Contact.REPORT_DATE_TIME), contact.get(Contact.CONTACT_IDENTIFICATION_SOURCE), contact.get(Contact.CONTACT_IDENTIFICATION_SOURCE_DETAILS), contact.get(Contact.TRACING_APP), contact.get(Contact.TRACING_APP_DETAILS), contact.get(Contact.CONTACT_PROXIMITY), contact.get(Contact.CONTACT_STATUS), contact.get(Contact.COMPLETENESS), contact.get(Contact.FOLLOW_UP_STATUS), contact.get(Contact.FOLLOW_UP_UNTIL), contact.get(Contact.QUARANTINE), contact.get(Contact.QUARANTINE_TYPE_DETAILS), contact.get(Contact.QUARANTINE_FROM), contact.get(Contact.QUARANTINE_TO), contact.get(Contact.QUARANTINE_HELP_NEEDED), contact.get(Contact.QUARANTINE_ORDERED_VERBALLY), contact.get(Contact.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT), contact.get(Contact.QUARANTINE_ORDERED_VERBALLY_DATE), contact.get(Contact.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE), contact.get(Contact.QUARANTINE_EXTENDED), contact.get(Contact.QUARANTINE_REDUCED), contact.get(Contact.QUARANTINE_OFFICIAL_ORDER_SENT), contact.get(Contact.QUARANTINE_OFFICIAL_ORDER_SENT_DATE), contact.get(Contact.PROHIBITION_TO_WORK), contact.get(Contact.PROHIBITION_TO_WORK_FROM), contact.get(Contact.PROHIBITION_TO_WORK_UNTIL), joins.getPerson().get(Person.PRESENT_CONDITION), joins.getPerson().get(Person.DEATH_DATE), joins.getAddressRegion().get(Region.NAME), joins.getAddressDistrict().get(District.NAME), joins.getAddressCommunity().get(Community.NAME), joins.getAddress().get(Location.CITY), joins.getAddress().get(Location.STREET), joins.getAddress().get(Location.HOUSE_NUMBER), joins.getAddress().get(Location.ADDITIONAL_INFORMATION), joins.getAddress().get(Location.POSTAL_CODE), joins.getAddressFacility().get(Facility.NAME), joins.getAddressFacility().get(Facility.UUID), joins.getAddress().get(Location.FACILITY_DETAILS), contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_PHONE_SUBQUERY), contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_PHONE_OWNER_SUBQUERY), contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_EMAIL_SUBQUERY), contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY), joins.getPerson().get(Person.OCCUPATION_TYPE), joins.getPerson().get(Person.OCCUPATION_DETAILS), joins.getPerson().get(Person.ARMED_FORCES_RELATION_TYPE), joins.getRegion().get(Region.NAME), joins.getDistrict().get(District.NAME), joins.getCommunity().get(Community.NAME), joins.getEpiData().get(EpiData.ID), joins.getEpiData().get(EpiData.CONTACT_WITH_SOURCE_CASE_KNOWN), contact.get(Contact.RETURNING_TRAVELER), contact.get(Contact.VACCINATION_STATUS), contact.get(Contact.EXTERNAL_ID), contact.get(Contact.EXTERNAL_TOKEN), contact.get(Contact.INTERNAL_TOKEN), joins.getPerson().get(Person.BIRTH_NAME), joins.getPersonBirthCountry().get(Country.ISO_CODE), joins.getPersonBirthCountry().get(Country.DEFAULT_NAME), joins.getPersonCitizenship().get(Country.ISO_CODE), joins.getPersonCitizenship().get(Country.DEFAULT_NAME), joins.getReportingDistrict().get(District.NAME), joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS), joins.getReportingUser().get(User.ID), joins.getFollowUpStatusChangeUser().get(User.ID), contact.get(Contact.PREVIOUS_QUARANTINE_TO), contact.get(Contact.QUARANTINE_CHANGE_COMMENT), jurisdictionSelector(contactQueryContext));
cq.distinct(true);
Predicate filter = listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext);
filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, contact.get(Contact.UUID));
if (filter != null) {
cq.where(filter);
}
cq.orderBy(cb.desc(contact.get(Contact.REPORT_DATE_TIME)), cb.desc(contact.get(Contact.ID)));
List<ContactExportDto> exportContacts = QueryHelper.getResultList(em, cq, first, max);
List<String> resultContactsUuids = exportContacts.stream().map(ContactExportDto::getUuid).collect(Collectors.toList());
if (!exportContacts.isEmpty()) {
List<Long> exportContactIds = exportContacts.stream().map(e -> e.getId()).collect(Collectors.toList());
List<VisitSummaryExportDetails> visitSummaries = null;
if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.NUMBER_OF_VISITS, ContactExportDto.LAST_COOPERATIVE_VISIT_DATE, ContactExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMATIC, ContactExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMS)) {
CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class);
Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
ContactJoins visitContactJoins = new ContactJoins(visitsCqRoot);
visitsCq.where(CriteriaBuilderHelper.and(cb, contact.get(AbstractDomainObject.ID).in(exportContactIds), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS))));
visitsCq.multiselect(visitsCqRoot.get(AbstractDomainObject.ID), visitContactJoins.getVisits().get(Visit.VISIT_DATE_TIME), visitContactJoins.getVisits().get(Visit.VISIT_STATUS), visitContactJoins.getVisitSymptoms(), jurisdictionSelector(new ContactQueryContext(cb, cq, visitsCqRoot)));
visitSummaries = em.createQuery(visitsCq).getResultList();
}
Map<Long, List<Exposure>> exposures = null;
if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.TRAVELED, ContactExportDto.TRAVEL_HISTORY, ContactExportDto.BURIAL_ATTENDED)) {
CriteriaQuery<Exposure> exposuresCq = cb.createQuery(Exposure.class);
Root<Exposure> exposuresRoot = exposuresCq.from(Exposure.class);
Join<Exposure, EpiData> exposuresEpiDataJoin = exposuresRoot.join(Exposure.EPI_DATA, JoinType.LEFT);
Expression<String> epiDataIdsExpr = exposuresEpiDataJoin.get(EpiData.ID);
Predicate exposuresPredicate = cb.and(epiDataIdsExpr.in(exportContacts.stream().map(ContactExportDto::getEpiDataId).collect(Collectors.toList())), cb.or(cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.TRAVEL), cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.BURIAL)));
exposuresCq.where(exposuresPredicate);
exposuresCq.orderBy(cb.asc(exposuresEpiDataJoin.get(EpiData.ID)));
List<Exposure> exposureList = em.createQuery(exposuresCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
exposures = exposureList.stream().collect(Collectors.groupingBy(e -> e.getEpiData().getId()));
}
Map<Long, List<Immunization>> immunizations = null;
if (ExportHelper.shouldExportFields(exportConfiguration, ExportHelper.getVaccinationExportProperties())) {
List<Immunization> immunizationList;
CriteriaQuery<Immunization> immunizationsCq = cb.createQuery(Immunization.class);
Root<Immunization> immunizationsCqRoot = immunizationsCq.from(Immunization.class);
Join<Immunization, Person> personJoin = immunizationsCqRoot.join(Immunization.PERSON, JoinType.LEFT);
Expression<String> personIdsExpr = personJoin.get(Person.ID);
immunizationsCq.where(CriteriaBuilderHelper.and(cb, cb.or(cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION), cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION_RECOVERY)), personIdsExpr.in(exportContacts.stream().map(ContactExportDto::getPersonId).collect(Collectors.toList()))));
immunizationList = em.createQuery(immunizationsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
immunizations = immunizationList.stream().collect(Collectors.groupingBy(i -> i.getPerson().getId()));
}
Map<String, List<ContactEventSummaryDetails>> eventSummaries = null;
if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.EVENT_COUNT, ContactExportDto.LATEST_EVENT_ID, ContactExportDto.LATEST_EVENT_TITLE)) {
// Load event count and latest events info per contact
eventSummaries = eventService.getEventSummaryDetailsByContacts(resultContactsUuids).stream().collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
}
Map<Long, UserReference> contactUsers = getContactUsersForExport(exportContacts, exportConfiguration);
// Adding a second query here is not perfect, but selecting the last cooperative visit with a criteria query
// doesn't seem to be possible and using a native query is not an option because of user filters
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
for (ContactExportDto exportContact : exportContacts) {
boolean inJurisdiction = exportContact.getInJurisdiction();
if (visitSummaries != null) {
List<VisitSummaryExportDetails> visits = visitSummaries.stream().filter(v -> v.getContactId() == exportContact.getId()).collect(Collectors.toList());
VisitSummaryExportDetails lastCooperativeVisit = visits.stream().filter(v -> v.getVisitStatus() == VisitStatus.COOPERATIVE).max(Comparator.comparing(VisitSummaryExportDetails::getVisitDateTime)).orElse(null);
exportContact.setNumberOfVisits(visits.size());
if (lastCooperativeVisit != null) {
SymptomsDto symptoms = SymptomsFacadeEjb.toDto(lastCooperativeVisit.getSymptoms());
pseudonymizer.pseudonymizeDto(SymptomsDto.class, symptoms, inJurisdiction, null);
exportContact.setLastCooperativeVisitDate(lastCooperativeVisit.getVisitDateTime());
exportContact.setLastCooperativeVisitSymptoms(SymptomsHelper.buildSymptomsHumanString(symptoms, true, userLanguage));
exportContact.setLastCooperativeVisitSymptomatic(symptoms.getSymptomatic() == null ? YesNoUnknown.UNKNOWN : (symptoms.getSymptomatic() ? YesNoUnknown.YES : YesNoUnknown.NO));
}
}
if (exposures != null) {
Optional.ofNullable(exposures.get(exportContact.getEpiDataId())).ifPresent(contactExposures -> {
StringBuilder travelHistoryBuilder = new StringBuilder();
if (contactExposures.stream().anyMatch(e -> ExposureType.BURIAL.equals(e.getExposureType()))) {
exportContact.setBurialAttended(true);
}
contactExposures.stream().filter(e -> ExposureType.TRAVEL.equals(e.getExposureType())).forEach(exposure -> {
travelHistoryBuilder.append(EpiDataHelper.buildDetailedTravelString(exposure.getLocation().toString(), exposure.getDescription(), exposure.getStartDate(), exposure.getEndDate(), userLanguage)).append(", ");
});
if (travelHistoryBuilder.length() > 0) {
exportContact.setTraveled(true);
travelHistoryBuilder.delete(travelHistoryBuilder.lastIndexOf(", "), travelHistoryBuilder.length());
}
exportContact.setTravelHistory(travelHistoryBuilder.toString());
});
}
if (immunizations != null) {
Optional.ofNullable(immunizations.get(exportContact.getPersonId())).ifPresent(contactImmunizations -> {
List<Immunization> filteredImmunizations = contactImmunizations.stream().filter(i -> i.getDisease() == exportContact.getDisease()).collect(Collectors.toList());
if (filteredImmunizations.size() > 0) {
filteredImmunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, false)));
Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();
List<Vaccination> relevantSortedVaccinations = getRelevantSortedVaccinations(exportContact.getUuid(), mostRecentImmunization.getVaccinations());
Vaccination firstVaccination = null;
Vaccination lastVaccination = null;
if (CollectionUtils.isNotEmpty(relevantSortedVaccinations)) {
firstVaccination = relevantSortedVaccinations.get(0);
lastVaccination = relevantSortedVaccinations.get(relevantSortedVaccinations.size() - 1);
exportContact.setFirstVaccinationDate(firstVaccination.getVaccinationDate());
exportContact.setLastVaccinationDate(lastVaccination.getVaccinationDate());
exportContact.setVaccineName(lastVaccination.getVaccineName());
exportContact.setOtherVaccineName(lastVaccination.getOtherVaccineName());
exportContact.setVaccineManufacturer(lastVaccination.getVaccineManufacturer());
exportContact.setOtherVaccineManufacturer(lastVaccination.getOtherVaccineManufacturer());
exportContact.setVaccinationInfoSource(lastVaccination.getVaccinationInfoSource());
exportContact.setVaccineAtcCode(lastVaccination.getVaccineAtcCode());
exportContact.setVaccineBatchNumber(lastVaccination.getVaccineBatchNumber());
exportContact.setVaccineUniiCode(lastVaccination.getVaccineUniiCode());
exportContact.setVaccineInn(lastVaccination.getVaccineInn());
}
exportContact.setNumberOfDoses(numberOfDoses != null ? String.valueOf(numberOfDoses) : getNumberOfDosesFromVaccinations(lastVaccination));
}
});
}
if (eventSummaries != null) {
List<ContactEventSummaryDetails> contactEvents = eventSummaries.getOrDefault(exportContact.getUuid(), Collections.emptyList());
exportContact.setEventCount((long) contactEvents.size());
contactEvents.stream().max(Comparator.comparing(ContactEventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
exportContact.setLatestEventId(eventSummary.getEventUuid());
exportContact.setLatestEventTitle(eventSummary.getEventTitle());
});
}
if (!contactUsers.isEmpty()) {
if (exportContact.getReportingUserId() != null) {
UserReference user = contactUsers.get(exportContact.getReportingUserId());
exportContact.setReportingUserName(user.getName());
exportContact.setReportingUserRoles(user.getUserRoles());
}
if (exportContact.getFollowUpStatusChangeUserId() != null) {
UserReference user = contactUsers.get(exportContact.getFollowUpStatusChangeUserId());
exportContact.setFollowUpStatusChangeUserName(user.getName());
exportContact.setFollowUpStatusChangeUserRoles(user.getUserRoles());
}
}
pseudonymizer.pseudonymizeDto(ContactExportDto.class, exportContact, inJurisdiction, null);
}
}
return exportContacts;
}
use of de.symeda.sormas.api.contact.ContactExportDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbPseudonymizationTest method testPseudonymizeExportData.
@Test
public void testPseudonymizeExportData() {
CaseDataDto caze = createCase(user1, rdcf1);
ContactDto contact1 = createContact(user2, caze, rdcf2);
// contact of case on other jurisdiction --> should be pseudonymized
ContactDto contact2 = creator.createContact(user1.toReference(), null, createPerson().toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
ContactCriteria contactCriteria = new ContactCriteria();
contactCriteria.setIncludeContactsFromOtherJurisdictions(true);
List<ContactExportDto> exportList = getContactFacade().getExportList(contactCriteria, Collections.emptySet(), 0, 100, null, Language.EN);
ContactExportDto index1 = exportList.stream().filter(c -> c.getUuid().equals(contact1.getUuid())).findFirst().get();
assertThat(index1.getFirstName(), is("James"));
assertThat(index1.getLastName(), is("Smith"));
assertThat(index1.getCity(), is("Test City"));
assertThat(index1.getStreet(), is("Test street"));
assertThat(index1.getHouseNumber(), is("Test number"));
assertThat(index1.getAdditionalInformation(), is("Test information"));
assertThat(index1.getPostalCode(), is("12345"));
ContactExportDto index2 = exportList.stream().filter(c -> c.getUuid().equals(contact2.getUuid())).findFirst().get();
assertThat(index2.getFirstName(), is("Confidential"));
assertThat(index2.getLastName(), is("Confidential"));
assertThat(index2.getCity(), is("Confidential"));
assertThat(index2.getStreet(), is("Confidential"));
assertThat(index2.getHouseNumber(), is("Confidential"));
assertThat(index2.getAdditionalInformation(), is("Confidential"));
assertThat(index2.getPostalCode(), is("123"));
}
use of de.symeda.sormas.api.contact.ContactExportDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testGetExportListWithRelevantVaccinations.
@Test
public void testGetExportListWithRelevantVaccinations() {
RDCFEntities rdcfEntities = creator.createRDCFEntities("Region", "District", "Community", "Facility");
RDCF rdcf = new RDCF(rdcfEntities);
UserDto user = useSurveillanceOfficerLogin(rdcf);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = createCaze(user, cazePerson, rdcfEntities);
ContactDto contact = createContact(user, caze, 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);
VaccinationDto secondVaccination = 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(firstVaccination.getVaccinationDate(), exportDto.getFirstVaccinationDate());
assertEquals(secondVaccination.getVaccineName(), exportDto.getVaccineName());
assertEquals(secondVaccination.getVaccinationDate(), exportDto.getLastVaccinationDate());
assertEquals(secondVaccination.getVaccinationInfoSource(), exportDto.getVaccinationInfoSource());
assertEquals(secondVaccination.getVaccineInn(), exportDto.getVaccineInn());
assertEquals(secondVaccination.getVaccineBatchNumber(), exportDto.getVaccineBatchNumber());
assertEquals(secondVaccination.getVaccineAtcCode(), exportDto.getVaccineAtcCode());
assertEquals(secondVaccination.getVaccineDose(), exportDto.getNumberOfDoses());
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());
assertTrue(exportDto.getEventCount().equals(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);
assertEquals(results.size(), 1);
{
ContactExportDto dto = results.get(0);
assertEquals(dto.getLatestEventId(), event2.getUuid());
assertEquals(dto.getLatestEventTitle(), event2.getEventTitle());
assertTrue(dto.getEventCount().equals(2L));
}
}
use of de.symeda.sormas.api.contact.ContactExportDto 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));
}
}
Aggregations