use of de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testGetVisitSummaryExportList.
@Test
public void testGetVisitSummaryExportList() {
RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
String userUuid = user.getUuid();
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
PersonDto contactPerson = creator.createPerson("Contact", "Person");
ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
// Create another contact that should have the same visits as the first one
ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
VisitDto visit11 = creator.createVisit(caze.getDisease(), contactPerson.toReference(), new Date(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
visit11.getSymptoms().setAbdominalPain(SymptomState.YES);
getVisitFacade().saveVisit(visit11);
VisitDto visit12 = creator.createVisit(caze.getDisease(), contactPerson.toReference(), DateHelper.subtractDays(new Date(), 1), VisitStatus.COOPERATIVE, VisitOrigin.USER);
visit12.getSymptoms().setChestPain(SymptomState.YES);
getVisitFacade().saveVisit(visit12);
PersonDto contactPersonWithoutFollowUp = creator.createPerson();
creator.createContact(user.toReference(), contactPersonWithoutFollowUp.toReference());
PersonDto contactPerson2 = creator.createPerson("Contact2", "Person2");
ContactDto contact3 = creator.createContact(user.toReference(), user.toReference(), contactPerson2.toReference(), caze, new Date(), null, null);
VisitDto visit21 = creator.createVisit(caze.getDisease(), contactPerson2.toReference(), new Date(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
visit21.getSymptoms().setBackache(SymptomState.YES);
getVisitFacade().saveVisit(visit21);
final List<VisitSummaryExportDto> results = getContactFacade().getVisitSummaryExportList(null, Collections.emptySet(), 0, 100, Language.EN);
assertNotNull(results);
assertEquals(3, results.size());
final VisitSummaryExportDto exportDto1 = results.get(0);
assertEquals("Contact", exportDto1.getFirstName());
assertEquals("Person", exportDto1.getLastName());
assertEquals(contact.getUuid(), exportDto1.getUuid());
final List<VisitSummaryExportDetailsDto> visitDetails = exportDto1.getVisitDetails();
assertNotNull(visitDetails);
assertEquals(2, visitDetails.size());
final VisitSummaryExportDetailsDto visitDetail11 = visitDetails.get(0);
assertEquals(VisitStatus.COOPERATIVE, visitDetail11.getVisitStatus());
assertNotNull(visitDetail11.getVisitDateTime());
assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.CHEST_PAIN), visitDetail11.getSymptoms());
final VisitSummaryExportDetailsDto visitDetail12 = visitDetails.get(1);
assertEquals(VisitStatus.COOPERATIVE, visitDetail12.getVisitStatus());
assertNotNull(visitDetail12.getVisitDateTime());
assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ABDOMINAL_PAIN), visitDetail12.getSymptoms());
final VisitSummaryExportDto exportDto2 = results.get(1);
assertEquals("Contact", exportDto2.getFirstName());
assertEquals("Person", exportDto2.getLastName());
assertEquals(contact2.getUuid(), exportDto2.getUuid());
final List<VisitSummaryExportDetailsDto> visitDetails2 = exportDto1.getVisitDetails();
assertNotNull(visitDetails2);
assertEquals(2, visitDetails2.size());
final VisitSummaryExportDetailsDto visitDetail21 = visitDetails2.get(0);
assertEquals(VisitStatus.COOPERATIVE, visitDetail21.getVisitStatus());
assertNotNull(visitDetail21.getVisitDateTime());
assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.CHEST_PAIN), visitDetail21.getSymptoms());
final VisitSummaryExportDetailsDto visitDetail22 = visitDetails2.get(1);
assertEquals(VisitStatus.COOPERATIVE, visitDetail22.getVisitStatus());
assertNotNull(visitDetail22.getVisitDateTime());
assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ABDOMINAL_PAIN), visitDetail22.getSymptoms());
final VisitSummaryExportDto exportDto3 = results.get(2);
assertEquals("Contact2", exportDto3.getFirstName());
assertEquals("Person2", exportDto3.getLastName());
assertEquals(contact3.getUuid(), exportDto3.getUuid());
final List<VisitSummaryExportDetailsDto> visitDetails3 = exportDto3.getVisitDetails();
assertNotNull(visitDetails3);
assertEquals(1, visitDetails3.size());
final VisitSummaryExportDetailsDto visitDetail31 = visitDetails3.get(0);
assertEquals(VisitStatus.COOPERATIVE, visitDetail31.getVisitStatus());
assertNotNull(visitDetail31.getVisitDateTime());
assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.BACKACHE), visitDetail31.getSymptoms());
}
use of de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method getVisitSummaryExportList.
@Override
@RolesAllowed(UserRight._VISIT_EXPORT)
public List<VisitSummaryExportDto> getVisitSummaryExportList(ContactCriteria contactCriteria, Collection<String> selectedRows, int first, int max, Language userLanguage) {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<VisitSummaryExportDto> cq = cb.createQuery(VisitSummaryExportDto.class);
final Root<Contact> contactRoot = cq.from(Contact.class);
final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contactRoot);
final ContactJoins contactJoins = contactQueryContext.getJoins();
final Join<Contact, Person> contactPerson = contactJoins.getPerson();
cq.multiselect(contactRoot.get(Contact.UUID), contactRoot.get(Contact.ID), contactPerson.get(Person.FIRST_NAME), contactPerson.get(Person.LAST_NAME), cb.<Date>selectCase().when(cb.isNotNull(contactRoot.get(Contact.LAST_CONTACT_DATE)), contactRoot.get(Contact.LAST_CONTACT_DATE)).otherwise(contactRoot.get(Contact.REPORT_DATE_TIME)), contactRoot.get(Contact.FOLLOW_UP_UNTIL));
Predicate filter = CriteriaBuilderHelper.and(cb, listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext), cb.isNotEmpty(contactRoot.get(Contact.VISITS)));
filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, contactRoot.get(Contact.UUID));
cq.where(filter);
cq.orderBy(cb.asc(contactRoot.get(Contact.REPORT_DATE_TIME)));
List<VisitSummaryExportDto> visitSummaries = QueryHelper.getResultList(em, cq, first, max);
if (!visitSummaries.isEmpty()) {
List<String> visitSummaryUuids = visitSummaries.stream().map(e -> e.getUuid()).collect(Collectors.toList());
CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class);
Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
ContactJoins joins = new ContactJoins(visitsCqRoot);
visitsCq.where(CriteriaBuilderHelper.and(cb, contactRoot.get(AbstractDomainObject.UUID).in(visitSummaryUuids), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS))));
visitsCq.multiselect(visitsCqRoot.get(AbstractDomainObject.ID), joins.getVisits().get(Visit.VISIT_DATE_TIME), joins.getVisits().get(Visit.VISIT_STATUS), joins.getVisitSymptoms(), jurisdictionSelector(new ContactQueryContext(cb, cq, visitsCqRoot)));
visitsCq.orderBy(cb.asc(joins.getVisits().get(Visit.VISIT_DATE_TIME)));
List<VisitSummaryExportDetails> visitSummaryDetails = em.createQuery(visitsCq).getResultList();
Map<Long, VisitSummaryExportDto> visitSummaryMap = visitSummaries.stream().collect(Collectors.toMap(VisitSummaryExportDto::getContactId, Function.identity()));
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
visitSummaryDetails.forEach(v -> {
SymptomsDto symptoms = SymptomsFacadeEjb.toDto(v.getSymptoms());
pseudonymizer.pseudonymizeDto(SymptomsDto.class, symptoms, v.getInJurisdiction(), null);
visitSummaryMap.get(v.getContactId()).getVisitDetails().add(new VisitSummaryExportDetailsDto(v.getVisitDateTime(), v.getVisitStatus(), SymptomsHelper.buildSymptomsHumanString(symptoms, true, userLanguage)));
});
}
return visitSummaries;
}
Aggregations