use of de.symeda.sormas.api.contact.ContactCriteria in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjb method onPersonChanged.
public void onPersonChanged(PersonDto existingPerson, Person newPerson, boolean syncShares) {
List<Case> personCases = null;
// Do not bother to update existing cases/contacts/eventparticipants on new Persons, as none should exist yet
if (existingPerson != null) {
personCases = caseService.findBy(new CaseCriteria().person(new PersonReferenceDto(newPerson.getUuid())), true);
// Attention: this may lead to infinite recursion when not properly implemented
for (Case personCase : personCases) {
CaseDataDto existingCase = caseFacade.toDto(personCase);
caseFacade.onCaseChanged(existingCase, personCase, syncShares);
}
List<Contact> personContacts = contactService.findBy(new ContactCriteria().setPerson(new PersonReferenceDto(newPerson.getUuid())), null);
// Attention: this may lead to infinite recursion when not properly implemented
for (Contact personContact : personContacts) {
contactFacade.onContactChanged(contactFacade.toDto(personContact), syncShares);
}
List<EventParticipant> personEventParticipants = eventParticipantService.findBy(new EventParticipantCriteria().withPerson(new PersonReferenceDto(newPerson.getUuid())), null);
// Attention: this may lead to infinite recursion when not properly implemented
for (EventParticipant personEventParticipant : personEventParticipants) {
eventParticipantFacade.onEventParticipantChanged(eventFacade.toDto(personEventParticipant.getEvent()), eventParticipantFacade.toDto(personEventParticipant), personEventParticipant, syncShares);
}
// get the updated personCases
personCases = caseService.findBy(new CaseCriteria().person(new PersonReferenceDto(newPerson.getUuid())), true);
// sort cases based on recency
Collections.sort(personCases, (c1, c2) -> CaseLogic.getStartDate(c1.getSymptoms().getOnsetDate(), c1.getReportDate()).before(CaseLogic.getStartDate(c2.getSymptoms().getOnsetDate(), c2.getReportDate())) ? 1 : -1);
if (newPerson.getPresentCondition() != null && existingPerson.getPresentCondition() != newPerson.getPresentCondition()) {
// get the latest case with disease==causeofdeathdisease
Case personCase = personCases.stream().filter(caze -> caze.getDisease() == newPerson.getCauseOfDeathDisease()).findFirst().orElse(null);
if (newPerson.getPresentCondition().isDeceased() && newPerson.getDeathDate() != null && newPerson.getCauseOfDeath() == CauseOfDeath.EPIDEMIC_DISEASE && newPerson.getCauseOfDeathDisease() != null) {
// update the latest associated case
if (personCase != null && personCase.getOutcome() != CaseOutcome.DECEASED && (personCase.getReportDate().before(DateHelper.addDays(newPerson.getDeathDate(), 30)) && personCase.getReportDate().after(DateHelper.subtractDays(newPerson.getDeathDate(), 30)))) {
CaseDataDto existingCase = caseFacade.toDto(personCase);
personCase.setOutcome(CaseOutcome.DECEASED);
personCase.setOutcomeDate(newPerson.getDeathDate());
caseFacade.onCaseChanged(existingCase, personCase, syncShares);
}
} else if (!newPerson.getPresentCondition().isDeceased() && (existingPerson.getPresentCondition() == PresentCondition.DEAD || existingPerson.getPresentCondition() == PresentCondition.BURIED)) {
// Person was put "back alive"
// make sure other values are set to null
newPerson.setCauseOfDeath(null);
newPerson.setCauseOfDeathDisease(null);
newPerson.setDeathPlaceDescription(null);
newPerson.setDeathPlaceType(null);
newPerson.setBurialDate(null);
newPerson.setCauseOfDeathDisease(null);
// update the latest associated case, if it was set to deceased && and if the case-disease was also the causeofdeath-disease
if (personCase != null && personCase.getOutcome() == CaseOutcome.DECEASED) {
CaseDataDto existingCase = caseFacade.toDto(personCase);
personCase.setOutcome(CaseOutcome.NO_OUTCOME);
personCase.setOutcomeDate(null);
caseFacade.onCaseChanged(existingCase, personCase, syncShares);
}
}
} else if (newPerson.getPresentCondition() != null && newPerson.getPresentCondition().isDeceased() && !Objects.equals(newPerson.getDeathDate(), existingPerson.getDeathDate()) && newPerson.getDeathDate() != null) {
// only Deathdate has changed
// update the latest associated case to the new deathdate, if causeOfDeath matches
Case personCase = personCases.isEmpty() ? null : personCases.get(0);
if (personCase != null && personCase.getOutcome() == CaseOutcome.DECEASED && newPerson.getCauseOfDeath() == CauseOfDeath.EPIDEMIC_DISEASE) {
CaseDataDto existingCase = caseFacade.toDto(personCase);
personCase.setOutcomeDate(newPerson.getDeathDate());
caseFacade.onCaseChanged(existingCase, personCase, syncShares);
}
}
}
// Set approximate age if it hasn't been set before
if (newPerson.getApproximateAge() == null && newPerson.getBirthdateYYYY() != null) {
Pair<Integer, ApproximateAgeType> pair = ApproximateAgeHelper.getApproximateAge(newPerson.getBirthdateYYYY(), newPerson.getBirthdateMM(), newPerson.getBirthdateDD(), newPerson.getDeathDate());
newPerson.setApproximateAge(pair.getElement0());
newPerson.setApproximateAgeType(pair.getElement1());
newPerson.setApproximateAgeReferenceDate(newPerson.getDeathDate() != null ? newPerson.getDeathDate() : new Date());
}
// Update caseAge of all associated cases when approximateAge has changed
if (existingPerson != null && existingPerson.getApproximateAge() != newPerson.getApproximateAge()) {
// Update case list after previous onCaseChanged
personCases = caseService.findBy(new CaseCriteria().person(new PersonReferenceDto(newPerson.getUuid())), true);
for (Case personCase : personCases) {
CaseDataDto existingCase = caseFacade.toDto(personCase);
if (newPerson.getApproximateAge() == null) {
personCase.setCaseAge(null);
} else if (newPerson.getApproximateAgeType() == ApproximateAgeType.MONTHS) {
personCase.setCaseAge(0);
} else {
Date now = new Date();
personCase.setCaseAge(newPerson.getApproximateAge() - DateHelper.getYearsBetween(personCase.getReportDate(), now));
if (personCase.getCaseAge() < 0) {
personCase.setCaseAge(0);
}
}
caseFacade.onCaseChanged(existingCase, personCase, syncShares);
}
}
// For newly created persons, assume no registration in external journals
if (existingPerson == null && newPerson.getSymptomJournalStatus() == null) {
newPerson.setSymptomJournalStatus(SymptomJournalStatus.UNREGISTERED);
}
cleanUp(newPerson);
}
use of de.symeda.sormas.api.contact.ContactCriteria in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method mergeCase.
private void mergeCase(CaseDataDto leadCaseData, CaseDataDto otherCaseData, boolean cloning) {
// 1 Merge Dtos
// 1.1 Case
copyDtoValues(leadCaseData, otherCaseData, cloning);
save(leadCaseData, !cloning, true, true, false);
// 1.2 Person - Only merge when the persons have different UUIDs
if (!cloning && !DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid())) {
PersonDto leadPerson = personFacade.getPersonByUuid(leadCaseData.getPerson().getUuid());
PersonDto otherPerson = personFacade.getPersonByUuid(otherCaseData.getPerson().getUuid());
personFacade.mergePerson(leadPerson, otherPerson);
} else {
assert (DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid()));
}
// 2 Change CaseReference
Case leadCase = service.getByUuid(leadCaseData.getUuid());
Case otherCase = service.getByUuid(otherCaseData.getUuid());
// 2.1 Contacts
List<Contact> contacts = contactService.findBy(new ContactCriteria().caze(otherCase.toReference()), null);
for (Contact contact : contacts) {
if (cloning) {
ContactDto newContact = ContactDto.build(leadCase.toReference(), leadCase.getDisease(), leadCase.getDiseaseDetails(), leadCase.getDiseaseVariant());
newContact.setPerson(new PersonReferenceDto(contact.getPerson().getUuid()));
DtoHelper.copyDtoValues(newContact, contactFacade.toDto(contact), cloning);
contactFacade.save(newContact, false, false);
} else {
// simply move existing entities to the merge target
contact.setCaze(leadCase);
contactService.ensurePersisted(contact);
}
}
// 2.2 Samples
List<Sample> samples = sampleService.findBy(new SampleCriteria().caze(otherCase.toReference()), null);
for (Sample sample : samples) {
if (cloning) {
SampleDto newSample = SampleDto.build(sample.getReportingUser().toReference(), leadCase.toReference());
DtoHelper.copyDtoValues(newSample, SampleFacadeEjb.toDto(sample), cloning);
sampleFacade.saveSample(newSample, false, true, true);
// 2.2.1 Pathogen Tests
for (PathogenTest pathogenTest : sample.getPathogenTests()) {
PathogenTestDto newPathogenTest = PathogenTestDto.build(newSample.toReference(), pathogenTest.getLabUser().toReference());
DtoHelper.copyDtoValues(newPathogenTest, PathogenTestFacadeEjbLocal.toDto(pathogenTest), cloning);
sampleTestFacade.savePathogenTest(newPathogenTest);
}
for (AdditionalTest additionalTest : sample.getAdditionalTests()) {
AdditionalTestDto newAdditionalTest = AdditionalTestDto.build(newSample.toReference());
DtoHelper.copyDtoValues(newAdditionalTest, AdditionalTestFacadeEjbLocal.toDto(additionalTest), cloning);
additionalTestFacade.saveAdditionalTest(newAdditionalTest);
}
} else {
// simply move existing entities to the merge target
sample.setAssociatedCase(leadCase);
sampleService.ensurePersisted(sample);
}
}
// 2.3 Tasks
if (!cloning) {
// simply move existing entities to the merge target
List<Task> tasks = taskService.findBy(new TaskCriteria().caze(new CaseReferenceDto(otherCase.getUuid())), true);
for (Task task : tasks) {
task.setCaze(leadCase);
taskService.ensurePersisted(task);
}
}
// 3 Change Therapy Reference
// 3.1 Treatments
List<Treatment> treatments = treatmentService.findBy(new TreatmentCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
TherapyReferenceDto leadCaseTherapyReference = new TherapyReferenceDto(leadCase.getTherapy().getUuid());
for (Treatment treatment : treatments) {
if (cloning) {
TreatmentDto newTreatment = TreatmentDto.build(leadCaseTherapyReference);
DtoHelper.copyDtoValues(newTreatment, TreatmentFacadeEjb.toDto(treatment), cloning);
treatmentFacade.saveTreatment(newTreatment);
} else {
// simply move existing entities to the merge target
treatment.setTherapy(leadCase.getTherapy());
treatmentService.ensurePersisted(treatment);
}
}
// 3.2 Prescriptions
List<Prescription> prescriptions = prescriptionService.findBy(new PrescriptionCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
for (Prescription prescription : prescriptions) {
if (cloning) {
PrescriptionDto newPrescription = PrescriptionDto.buildPrescription(leadCaseTherapyReference);
DtoHelper.copyDtoValues(newPrescription, PrescriptionFacadeEjb.toDto(prescription), cloning);
prescriptionFacade.savePrescription(newPrescription);
} else {
// simply move existing entities to the merge target
prescription.setTherapy(leadCase.getTherapy());
prescriptionService.ensurePersisted(prescription);
}
}
// 4 Change Clinical Course Reference
// 4.1 Clinical Visits
List<ClinicalVisit> clinicalVisits = clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(new ClinicalCourseReferenceDto(otherCase.getClinicalCourse().getUuid())));
for (ClinicalVisit clinicalVisit : clinicalVisits) {
if (cloning) {
ClinicalVisitDto newClinicalVisit = ClinicalVisitDto.build(leadCaseData.getClinicalCourse().toReference(), leadCase.getDisease());
DtoHelper.copyDtoValues(newClinicalVisit, ClinicalVisitFacadeEjb.toDto(clinicalVisit), cloning);
clinicalVisitFacade.saveClinicalVisit(newClinicalVisit, leadCase.getUuid(), false);
} else {
// simply move existing entities to the merge target
clinicalVisit.setClinicalCourse(leadCase.getClinicalCourse());
clinicalVisitService.ensurePersisted(clinicalVisit);
}
}
// (set the person and the disease of the visit, saveVisit does the rest)
for (VisitDto otherVisit : otherCase.getVisits().stream().map(VisitFacadeEjb::toDto).collect(Collectors.toList())) {
otherVisit.setPerson(leadCaseData.getPerson());
otherVisit.setDisease(leadCaseData.getDisease());
visitFacade.saveVisit(otherVisit);
}
// 6 Documents
List<Document> documents = documentService.getRelatedToEntity(DocumentRelatedEntityType.CASE, otherCase.getUuid());
for (Document document : documents) {
document.setRelatedEntityUuid(leadCaseData.getUuid());
documentService.ensurePersisted(document);
}
// 7 Persist Event links through eventparticipants
Set<EventParticipant> eventParticipants = otherCase.getEventParticipants();
for (EventParticipant eventParticipant : eventParticipants) {
eventParticipant.setResultingCase(leadCase);
eventParticipantService.ensurePersisted(eventParticipant);
}
otherCase.getEventParticipants().clear();
// 8 Exposures - Make sure there are no two probable infection environments
// if there are more than 2 exposures marked as probable infection environment, find the one that originates from the otherCase and set it to false
// the one originating from the otherCase should always be found at the higher index
List<Exposure> probableExposuresList = leadCase.getEpiData().getExposures().stream().filter(Exposure::isProbableInfectionEnvironment).collect(Collectors.toList());
while (probableExposuresList.size() >= 2) {
// should never be > 2, but still make sure to set all but one exposures to false
probableExposuresList.get(probableExposuresList.size() - 1).setProbableInfectionEnvironment(false);
exposureService.ensurePersisted(probableExposuresList.get(probableExposuresList.size() - 1));
probableExposuresList.remove(probableExposuresList.size() - 1);
}
// 9 Reports
List<SurveillanceReport> surveillanceReports = surveillanceReportService.getByCaseUuids(Collections.singletonList(otherCase.getUuid()));
surveillanceReports.forEach(surveillanceReport -> {
SurveillanceReportDto surveillanceReportDto = SurveillanceReportFacadeEjb.toDto(surveillanceReport);
surveillanceReportDto.setCaze(leadCase.toReference());
surveillanceReportFacade.saveSurveillanceReport(surveillanceReportDto);
});
// 10 Activity as case
final EpiData otherEpiData = otherCase.getEpiData();
if (otherEpiData != null && YesNoUnknown.YES == otherEpiData.getActivityAsCaseDetailsKnown() && CollectionUtils.isNotEmpty(otherEpiData.getActivitiesAsCase())) {
final EpiData leadEpiData = leadCase.getEpiData();
leadEpiData.setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
epiDataService.ensurePersisted(leadEpiData);
}
// Travel entries reference
List<TravelEntry> travelEntries = travelEntryService.getAllByResultingCase(otherCase);
travelEntries.forEach(t -> {
t.setResultingCase(leadCase);
travelEntryService.ensurePersisted(t);
});
}
use of de.symeda.sormas.api.contact.ContactCriteria in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method onCaseChanged.
public void onCaseChanged(CaseDataDto existingCase, Case newCase, boolean syncShares) {
// If its a new case and the case is new and the geo coordinates of the case's
// health facility are null, set its coordinates to the case's report
// coordinates, if available. Else if case report coordinates are null set them
// to the facility's coordinates
Facility facility = newCase.getHealthFacility();
if (existingCase == null && facility != null && !FacilityHelper.isOtherOrNoneHealthFacility(facility.getUuid())) {
if ((facility.getLatitude() == null || facility.getLongitude() == null) && newCase.getReportLat() != null && newCase.getReportLon() != null) {
facility.setLatitude(newCase.getReportLat());
facility.setLongitude(newCase.getReportLon());
facilityService.ensurePersisted(facility);
} else if (newCase.getReportLat() == null && newCase.getReportLon() == null && newCase.getReportLatLonAccuracy() == null) {
newCase.setReportLat(facility.getLatitude());
newCase.setReportLon(facility.getLongitude());
}
}
// Clear facility type if no facility or home was selected
if (newCase.getHealthFacility() == null || FacilityDto.NONE_FACILITY_UUID.equals(newCase.getHealthFacility().getUuid())) {
newCase.setFacilityType(null);
}
// Generate epid number if missing or incomplete
FieldVisibilityCheckers fieldVisibilityCheckers = FieldVisibilityCheckers.withCountry(configFacade.getCountryLocale());
if (fieldVisibilityCheckers.isVisible(CaseDataDto.class, CaseDataDto.EPID_NUMBER) && !CaseLogic.isCompleteEpidNumber(newCase.getEpidNumber())) {
newCase.setEpidNumber(generateEpidNumber(newCase.getEpidNumber(), newCase.getUuid(), newCase.getDisease(), newCase.getReportDate(), newCase.getResponsibleDistrict().getUuid()));
}
// update the plague type based on symptoms
if (newCase.getDisease() == Disease.PLAGUE) {
PlagueType plagueType = DiseaseHelper.getPlagueTypeForSymptoms(SymptomsFacadeEjb.toDto(newCase.getSymptoms()));
if (plagueType != newCase.getPlagueType() && plagueType != null) {
newCase.setPlagueType(plagueType);
}
}
District survOffDistrict = newCase.getSurveillanceOfficer() != null ? newCase.getSurveillanceOfficer().getDistrict() : null;
if (survOffDistrict == null || (!survOffDistrict.equals(newCase.getResponsibleDistrict()) && !survOffDistrict.equals(newCase.getDistrict()))) {
setResponsibleSurveillanceOfficer(newCase);
}
updateInvestigationByStatus(existingCase, newCase);
updatePersonAndCaseByOutcome(existingCase, newCase);
updateCaseAge(existingCase, newCase);
// Change the disease of all contacts if the case disease or disease details have changed
if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !StringUtils.equals(newCase.getDiseaseDetails(), existingCase.getDiseaseDetails()))) {
for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
if (contact.getDisease() != newCase.getDisease() || !StringUtils.equals(contact.getDiseaseDetails(), newCase.getDiseaseDetails())) {
// Only do the change if it hasn't been done in the mobile app before
contact.setDisease(newCase.getDisease());
contact.setDiseaseDetails(newCase.getDiseaseDetails());
contactService.ensurePersisted(contact);
}
}
}
if (existingCase != null && (newCase.getDisease() != existingCase.getDisease() || !Objects.equals(newCase.getReportDate(), existingCase.getReportDate()) || !Objects.equals(newCase.getSymptoms().getOnsetDate(), existingCase.getSymptoms().getOnsetDate()))) {
// Update follow-up until and status of all contacts
for (Contact contact : contactService.findBy(new ContactCriteria().caze(newCase.toReference()), null)) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
for (Contact contact : contactService.getAllByResultingCase(newCase)) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
}
updateTasksOnCaseChanged(newCase, existingCase);
// Update case classification if the feature is enabled
CaseClassification classification = null;
if (configFacade.isFeatureAutomaticCaseClassification()) {
if (newCase.getCaseClassification() != CaseClassification.NO_CASE) {
// calculate classification
CaseDataDto newCaseDto = toDto(newCase);
classification = caseClassificationFacade.getClassification(newCaseDto);
// only update when classification by system changes - user may overwrite this
if (classification != newCase.getSystemCaseClassification()) {
newCase.setSystemCaseClassification(classification);
// really a change? (user may have already set it)
if (classification != newCase.getCaseClassification()) {
newCase.setCaseClassification(classification);
newCase.setClassificationUser(null);
newCase.setClassificationDate(new Date());
}
}
}
}
// calculate reference definition for cases
if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
boolean fulfilled = evaluateFulfilledCondition(toDto(newCase), classification);
newCase.setCaseReferenceDefinition(fulfilled ? CaseReferenceDefinition.FULFILLED : CaseReferenceDefinition.NOT_FULFILLED);
}
// are not empty
if (!newCase.getHospitalization().getPreviousHospitalizations().isEmpty() && YesNoUnknown.YES != newCase.getHospitalization().getHospitalizedPreviously()) {
newCase.getHospitalization().setHospitalizedPreviously(YesNoUnknown.YES);
}
if (!newCase.getEpiData().getExposures().isEmpty() && !YesNoUnknown.YES.equals(newCase.getEpiData().getExposureDetailsKnown())) {
newCase.getEpiData().setExposureDetailsKnown(YesNoUnknown.YES);
}
// Update completeness value
newCase.setCompleteness(null);
// changed
if (existingCase != null && existingCase.getCaseClassification() != newCase.getCaseClassification()) {
try {
String message = String.format(I18nProperties.getString(MessageContents.CONTENT_CASE_CLASSIFICATION_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), newCase.getCaseClassification().toString());
notificationService.sendNotifications(NotificationType.CASE_CLASSIFICATION_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.CASE_CLASSIFICATION_CHANGED, message);
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case classification. ");
}
}
// Unspecified VHF case has changed
if (existingCase != null && existingCase.getDisease() == Disease.UNSPECIFIED_VHF && existingCase.getDisease() != newCase.getDisease()) {
try {
String message = String.format(I18nProperties.getString(MessageContents.CONTENT_DISEASE_CHANGED), DataHelper.getShortUuid(newCase.getUuid()), existingCase.getDisease().toString(), newCase.getDisease().toString());
notificationService.sendNotifications(NotificationType.DISEASE_CHANGED, JurisdictionHelper.getCaseRegions(newCase), null, MessageSubject.DISEASE_CHANGED, message);
} catch (NotificationDeliveryFailedException e) {
logger.error("NotificationDeliveryFailedException when trying to notify supervisors about the change of a case disease.");
}
}
// If the case is a newly created case or if it was not in a CONFIRMED status
// and now the case is in a CONFIRMED status, notify related surveillance officers
Set<CaseClassification> confirmedClassifications = CaseClassification.getConfirmedClassifications();
if ((existingCase == null || !confirmedClassifications.contains(existingCase.getCaseClassification())) && confirmedClassifications.contains(newCase.getCaseClassification())) {
sendConfirmedCaseNotificationsForEvents(newCase);
}
if (existingCase != null && syncShares && sormasToSormasFacade.isFeatureConfigured()) {
syncSharesAsync(new ShareTreeCriteria(existingCase.getUuid()));
}
// This logic should be consistent with CaseDataForm.onQuarantineEndChange
if (existingCase != null && existingCase.getQuarantineTo() != null && !existingCase.getQuarantineTo().equals(newCase.getQuarantineTo())) {
newCase.setPreviousQuarantineTo(existingCase.getQuarantineTo());
}
if (existingCase == null) {
vaccinationFacade.updateVaccinationStatuses(newCase);
}
// On German systems, correct and clean up reinfection data
if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
newCase.setReinfectionDetails(cleanUpReinfectionDetails(newCase.getReinfectionDetails()));
newCase.setReinfectionStatus(CaseLogic.calculateReinfectionStatus(newCase.getReinfectionDetails()));
}
}
use of de.symeda.sormas.api.contact.ContactCriteria in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testGetIndexDetailedList.
@Test
public void testGetIndexDetailedList() {
ContactCriteria contactCriteria = new ContactCriteria();
contactCriteria.setIncludeContactsFromOtherJurisdictions(true);
List<SortProperty> sortProperties = Collections.emptyList();
List<ContactIndexDetailedDto> result;
// 0. No data: empty list
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, is(empty()));
// Create needed structural data
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);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
UserReferenceDto reportingUser = new UserReferenceDto(user.getUuid());
EventDto event1 = creator.createEvent(reportingUser, DateHelper.subtractDays(new Date(), 1));
EventDto event2 = creator.createEvent(reportingUser, new Date());
PersonDto contactPerson = creator.createPerson("Contact", "Person");
ContactDto contact1 = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
// 1a. one Contact without Event
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(0L));
assertNull(dto.getLatestEventId());
assertNull(dto.getLatestEventTitle());
assertThat(dto.getVisitCount(), equalTo(0));
}
// 1b. one Contact with one Event
creator.createEventParticipant(new EventReferenceDto(event1.getUuid()), contactPerson, reportingUser);
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(1L));
assertThat(dto.getLatestEventId(), equalTo(event1.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event1.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(0));
}
// 1c. one Contact with two Events, second is leading
creator.createEventParticipant(new EventReferenceDto(event2.getUuid()), contactPerson, reportingUser);
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(2L));
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(0));
}
// 1d. one Contact with two Events and one visit
creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(2L));
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(1));
}
// 1e. one Contact with two Events and three visits
creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(2L));
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(3));
}
}
use of de.symeda.sormas.api.contact.ContactCriteria in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbPseudonymizationTest method testPseudonymizeIndexDetailedData.
@Test
public void testPseudonymizeIndexDetailedData() {
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<ContactIndexDetailedDto> indexList = getContactFacade().getIndexDetailedList(contactCriteria, null, null, Collections.emptyList());
ContactIndexDetailedDto index1 = indexList.stream().filter(c -> c.getUuid().equals(contact1.getUuid())).findFirst().get();
assertThat(index1.getFirstName(), is("James"));
assertThat(index1.getLastName(), is("Smith"));
assertThat(index1.getCaze().getFirstName(), is(is("Confidential")));
assertThat(index1.getCaze().getLastName(), is(is("Confidential")));
assertThat(index1.getReportingUser().getUuid(), is(user2.getUuid()));
ContactIndexDetailedDto index2 = indexList.stream().filter(c -> c.getUuid().equals(contact2.getUuid())).findFirst().get();
assertThat(index2.getFirstName(), is("Confidential"));
assertThat(index2.getLastName(), is("Confidential"));
assertThat(index2.getCaze().getFirstName(), is("Confidential"));
assertThat(index2.getCaze().getLastName(), is("Confidential"));
assertThat(index2.getReportingUser(), is(nullValue()));
}
Aggregations