use of de.symeda.sormas.api.epidata.EpiDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method restorePseudonymizedDto.
public void restorePseudonymizedDto(CaseDataDto dto, CaseDataDto existingCaseDto, Case caze, Pseudonymizer pseudonymizer) {
if (existingCaseDto != null) {
boolean inJurisdiction = service.inJurisdictionOrOwned(caze);
User currentUser = userService.getCurrentUser();
pseudonymizer.restoreUser(caze.getReportingUser(), currentUser, dto, dto::setReportingUser);
pseudonymizer.restoreUser(caze.getClassificationUser(), currentUser, dto, dto::setClassificationUser);
pseudonymizer.restorePseudonymizedValues(CaseDataDto.class, dto, existingCaseDto, inJurisdiction);
EpiDataDto epiData = dto.getEpiData();
EpiDataDto existingEpiData = existingCaseDto.getEpiData();
pseudonymizer.restorePseudonymizedValues(EpiDataDto.class, epiData, existingEpiData, inJurisdiction);
epiData.getExposures().forEach(exposure -> {
ExposureDto existingExposure = existingEpiData.getExposures().stream().filter(exp -> DataHelper.isSame(exposure, exp)).findFirst().orElse(null);
if (existingExposure != null) {
pseudonymizer.restorePseudonymizedValues(ExposureDto.class, exposure, existingExposure, inJurisdiction);
pseudonymizer.restorePseudonymizedValues(LocationDto.class, exposure.getLocation(), existingExposure.getLocation(), inJurisdiction);
}
});
pseudonymizer.restorePseudonymizedValues(HealthConditionsDto.class, dto.getHealthConditions(), existingCaseDto.getHealthConditions(), inJurisdiction);
dto.getHospitalization().getPreviousHospitalizations().forEach(previousHospitalization -> existingCaseDto.getHospitalization().getPreviousHospitalizations().stream().filter(eh -> DataHelper.isSame(previousHospitalization, eh)).findFirst().ifPresent(existingPreviousHospitalization -> pseudonymizer.restorePseudonymizedValues(PreviousHospitalizationDto.class, previousHospitalization, existingPreviousHospitalization, inJurisdiction)));
pseudonymizer.restorePseudonymizedValues(SymptomsDto.class, dto.getSymptoms(), existingCaseDto.getSymptoms(), inJurisdiction);
pseudonymizer.restorePseudonymizedValues(MaternalHistoryDto.class, dto.getMaternalHistory(), existingCaseDto.getMaternalHistory(), inJurisdiction);
}
}
use of de.symeda.sormas.api.epidata.EpiDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjbTest method testMergeCase.
@Test
public void testMergeCase() throws IOException {
useNationalUserLogin();
// 1. Create
// Create leadCase
UserDto leadUser = creator.createUser("", "", "", "First", "User");
UserReferenceDto leadUserReference = new UserReferenceDto(leadUser.getUuid());
PersonDto leadPerson = creator.createPerson("Alex", "Miller");
PersonReferenceDto leadPersonReference = new PersonReferenceDto(leadPerson.getUuid());
RDCF leadRdcf = creator.createRDCF();
CaseDataDto leadCase = creator.createCase(leadUserReference, leadPersonReference, Disease.DENGUE, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), leadRdcf, (c) -> {
c.setAdditionalDetails("Test additional details");
c.setFollowUpComment("Test followup comment");
});
leadCase.setClinicianEmail("mail");
leadCase.getEpiData().setActivityAsCaseDetailsKnown(YesNoUnknown.NO);
getCaseFacade().save(leadCase);
VisitDto leadVisit = creator.createVisit(leadCase.getDisease(), leadCase.getPerson(), leadCase.getReportDate());
leadVisit.getSymptoms().setAnorexiaAppetiteLoss(SymptomState.YES);
getVisitFacade().saveVisit(leadVisit);
// Create otherCase
UserDto otherUser = creator.createUser("", "", "", "Second", "User");
UserReferenceDto otherUserReference = new UserReferenceDto(otherUser.getUuid());
PersonDto otherPerson = creator.createPerson("Max", "Smith");
otherPerson.setBirthWeight(2);
getPersonFacade().savePerson(otherPerson);
PersonReferenceDto otherPersonReference = new PersonReferenceDto(otherPerson.getUuid());
RDCF otherRdcf = creator.createRDCF("Reg2", "Dis2", "Comm2", "Fac2", "Poe2");
CaseDataDto otherCase = creator.createCase(otherUserReference, otherPersonReference, Disease.CHOLERA, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), otherRdcf, (c) -> {
c.setAdditionalDetails("Test other additional details");
c.setFollowUpComment("Test other followup comment");
});
otherCase.setClinicianName("name");
CaseReferenceDto otherCaseReference = getCaseFacade().getReferenceByUuid(otherCase.getUuid());
ContactDto contact = creator.createContact(otherUserReference, otherUserReference, otherPersonReference, otherCase, new Date(), new Date(), null);
Region region = creator.createRegion("");
District district = creator.createDistrict("", region);
SampleDto sample = creator.createSample(otherCaseReference, otherUserReference, creator.createFacility("", region, district, creator.createCommunity("", district)));
TaskDto task = creator.createTask(TaskContext.CASE, TaskType.CASE_INVESTIGATION, TaskStatus.PENDING, otherCaseReference, new ContactReferenceDto(), new EventReferenceDto(), new Date(), otherUserReference);
TreatmentDto treatment = creator.createTreatment(otherCase);
PrescriptionDto prescription = creator.createPrescription(otherCase);
ClinicalVisitDto visit = creator.createClinicalVisit(otherCase);
otherCase.getEpiData().setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
final ArrayList<ActivityAsCaseDto> otherActivitiesAsCase = new ArrayList<>();
ActivityAsCaseDto activityAsCaseDto = new ActivityAsCaseDto();
activityAsCaseDto.setActivityAsCaseType(ActivityAsCaseType.GATHERING);
otherActivitiesAsCase.add(activityAsCaseDto);
otherCase.getEpiData().setActivitiesAsCase(otherActivitiesAsCase);
getCaseFacade().save(otherCase);
VisitDto otherVisit = creator.createVisit(otherCase.getDisease(), otherCase.getPerson(), otherCase.getReportDate());
otherVisit.getSymptoms().setAbdominalPain(SymptomState.YES);
getVisitFacade().saveVisit(otherVisit);
EventDto event = creator.createEvent(otherUserReference);
event.setDisease(otherCase.getDisease());
getEventFacade().save(event);
EventParticipantDto otherCaseEventParticipant = creator.createEventParticipant(event.toReference(), otherPerson, otherUserReference);
otherCaseEventParticipant.setResultingCase(otherCaseReference);
getEventParticipantFacade().saveEventParticipant(otherCaseEventParticipant);
creator.createSurveillanceReport(otherUserReference, otherCaseReference);
TravelEntryDto travelEntry = creator.createTravelEntry(otherPersonReference, otherUserReference, otherCase.getDisease(), otherRdcf.region, otherRdcf.district, otherRdcf.pointOfEntry);
travelEntry.setResultingCase(otherCaseReference);
travelEntry = getTravelEntryFacade().save(travelEntry);
DocumentDto document = creator.createDocument(leadUserReference, "document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CASE, leadCase.getUuid(), "content".getBytes(StandardCharsets.UTF_8));
DocumentDto otherDocument = creator.createDocument(leadUserReference, "other_document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CASE, otherCase.getUuid(), "other content".getBytes(StandardCharsets.UTF_8));
// 2. Merge
getCaseFacade().mergeCase(leadCase.getUuid(), otherCase.getUuid());
// 3. Test
CaseDataDto mergedCase = getCaseFacade().getCaseDataByUuid(leadCase.getUuid());
// Check no values
assertNull(mergedCase.getClassificationComment());
// Check 'lead and other have different values'
assertEquals(leadCase.getDisease(), mergedCase.getDisease());
// Check 'lead has value, other has not'
assertEquals(leadCase.getClinicianEmail(), mergedCase.getClinicianEmail());
// Check 'lead has no value, other has'
assertEquals(otherCase.getClinicianName(), mergedCase.getClinicianName());
PersonDto mergedPerson = getPersonFacade().getPersonByUuid(mergedCase.getPerson().getUuid());
// Check no values
assertNull(mergedPerson.getBirthdateDD());
// Check 'lead and other have different values'
assertEquals(leadCase.getPerson().getFirstName(), mergedPerson.getFirstName());
// Check 'lead has value, other has not'
assertEquals(leadCase.getPerson().getLastName(), mergedPerson.getLastName());
// Check 'lead has no value, other has'
assertEquals(otherPerson.getBirthWeight(), mergedPerson.getBirthWeight());
// Check merge comments
assertEquals("Test additional details Test other additional details", mergedCase.getAdditionalDetails());
assertEquals("Test followup comment Test other followup comment", mergedCase.getFollowUpComment());
// 4. Test Reference Changes
// 4.1 Contacts
List<String> contactUuids = new ArrayList<>();
contactUuids.add(contact.getUuid());
assertEquals(leadCase.getUuid(), getContactFacade().getByUuids(contactUuids).get(0).getCaze().getUuid());
// 4.2 Samples
List<String> sampleUuids = new ArrayList<>();
sampleUuids.add(sample.getUuid());
assertEquals(leadCase.getUuid(), getSampleFacade().getByUuids(sampleUuids).get(0).getAssociatedCase().getUuid());
// 4.3 Tasks
List<String> taskUuids = new ArrayList<>();
taskUuids.add(task.getUuid());
assertEquals(leadCase.getUuid(), getTaskFacade().getByUuids(taskUuids).get(0).getCaze().getUuid());
// 4.4 Treatments
List<String> treatmentUuids = new ArrayList<>();
treatmentUuids.add(treatment.getUuid());
assertEquals(leadCase.getTherapy().getUuid(), getTreatmentFacade().getByUuids(treatmentUuids).get(0).getTherapy().getUuid());
// 4.5 Prescriptions
List<String> prescriptionUuids = new ArrayList<>();
prescriptionUuids.add(prescription.getUuid());
assertEquals(leadCase.getTherapy().getUuid(), getPrescriptionFacade().getByUuids(prescriptionUuids).get(0).getTherapy().getUuid());
// 4.6 Clinical Visits
List<String> visitUuids = new ArrayList<>();
visitUuids.add(visit.getUuid());
assertEquals(leadCase.getClinicalCourse().getUuid(), getClinicalVisitFacade().getByUuids(visitUuids).get(0).getClinicalCourse().getUuid());
// 4.7 Visits;
List<String> mergedVisits = getVisitFacade().getIndexList(new VisitCriteria().caze(mergedCase.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()));
// and symptoms
assertEquals(SymptomState.YES, mergedCase.getSymptoms().getAbdominalPain());
assertEquals(SymptomState.YES, mergedCase.getSymptoms().getAnorexiaAppetiteLoss());
assertTrue(mergedCase.getSymptoms().getSymptomatic());
// 4.8 Linked Events
assertEquals(1, getEventFacade().count(new EventCriteria().caze(mergedCase.toReference())));
// 4.8 Linked Surveillance Reports
List<SurveillanceReportDto> surveillanceReportList = getSurveillanceReportFacade().getByCaseUuids(Collections.singletonList(mergedCase.getUuid()));
MatcherAssert.assertThat(surveillanceReportList, hasSize(1));
// 5 Documents
List<DocumentDto> mergedDocuments = getDocumentFacade().getDocumentsRelatedToEntity(DocumentRelatedEntityType.CASE, leadCase.getUuid());
assertEquals(2, mergedDocuments.size());
List<String> documentUuids = mergedDocuments.stream().map(DocumentDto::getUuid).collect(Collectors.toList());
assertTrue(documentUuids.contains(document.getUuid()));
assertTrue(documentUuids.contains(otherDocument.getUuid()));
// 10 Activities as case
final EpiDataDto epiData = mergedCase.getEpiData();
assertEquals(YesNoUnknown.YES, epiData.getActivityAsCaseDetailsKnown());
final List<ActivityAsCaseDto> activitiesAsCase = epiData.getActivitiesAsCase();
assertEquals(1, activitiesAsCase.size());
assertEquals(ActivityAsCaseType.GATHERING, activitiesAsCase.get(0).getActivityAsCaseType());
// Travel entry
travelEntry = getTravelEntryFacade().getByUuid(travelEntry.getUuid());
assertEquals(mergedCase.toReference(), travelEntry.getResultingCase());
}
use of de.symeda.sormas.api.epidata.EpiDataDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjbTest method testCloneCaseActivityAsCaseIsCloned.
@Test
public void testCloneCaseActivityAsCaseIsCloned() {
useNationalUserLogin();
// 1. Create
// Create aCase
UserDto user = creator.createUser("", "", "", "", "");
UserReferenceDto userReferenceDto = new UserReferenceDto(user.getUuid());
PersonDto person = creator.createPerson("Max", "Smith");
person.setBirthWeight(2);
getPersonFacade().savePerson(person);
PersonReferenceDto personReferenceDto = new PersonReferenceDto(person.getUuid());
RDCF rdcf = creator.createRDCF();
CaseDataDto aCase = creator.createCase(userReferenceDto, personReferenceDto, Disease.CHOLERA, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), rdcf, (c) -> {
c.setAdditionalDetails("Test other additional details");
c.setFollowUpComment("Test other followup comment");
});
aCase.setClinicianName("name");
aCase.getEpiData().setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
final ArrayList<ActivityAsCaseDto> otherActivitiesAsCase = new ArrayList<>();
ActivityAsCaseDto activityAsCaseDto = new ActivityAsCaseDto();
activityAsCaseDto.setActivityAsCaseType(ActivityAsCaseType.GATHERING);
otherActivitiesAsCase.add(activityAsCaseDto);
aCase.getEpiData().setActivitiesAsCase(otherActivitiesAsCase);
CaseDataDto caseDataDto = getCaseFacade().save(aCase);
// 2. Clone
CaseDataDto clonedCase = getCaseFacade().cloneCase(caseDataDto);
final EpiDataDto epiData = clonedCase.getEpiData();
assertEquals(YesNoUnknown.YES, epiData.getActivityAsCaseDetailsKnown());
final List<ActivityAsCaseDto> activitiesAsCase = epiData.getActivitiesAsCase();
assertEquals(1, activitiesAsCase.size());
assertEquals(ActivityAsCaseType.GATHERING, activitiesAsCase.get(0).getActivityAsCaseType());
}
use of de.symeda.sormas.api.epidata.EpiDataDto in project SORMAS-Project by hzi-braunschweig.
the class EpiDataPseudonymizationTest method createCaseWEpiData.
private CaseDataDto createCaseWEpiData(UserDto user, TestDataCreator.RDCF rdcf) {
CaseDataDto caze = creator.createCase(user.toReference(), rdcf, c -> {
EpiDataDto epiData = c.getEpiData();
ExposureDto exposure = ExposureDto.build(ExposureType.ANIMAL_CONTACT);
exposure.setAnimalCondition(AnimalCondition.DEAD);
exposure.setDescription("Test description");
exposure.getLocation().setDetails("Test location details");
epiData.getExposures().add(exposure);
ExposureDto exposure2 = ExposureDto.build(ExposureType.ANIMAL_CONTACT);
exposure2.setTypeOfAnimal(TypeOfAnimal.OTHER);
exposure2.setTypeOfAnimalDetails("Test other animal details");
epiData.getExposures().add(exposure2);
ExposureDto exposure3 = ExposureDto.build(ExposureType.TRAVEL);
exposure3.setBodyOfWater(YesNoUnknown.YES);
exposure3.setWaterSource(WaterSource.OTHER);
exposure3.setWaterSourceDetails("Test water source details");
epiData.getExposures().add(exposure3);
ExposureDto exposure4 = ExposureDto.build(ExposureType.ANIMAL_CONTACT);
exposure4.setAnimalContactType(AnimalContactType.OTHER);
exposure4.setAnimalContactTypeDetails("Test animal contact type details");
epiData.getExposures().add(exposure4);
ExposureDto burial = ExposureDto.build(ExposureType.BURIAL);
burial.setDeceasedPersonName("John Smith");
burial.setDeceasedPersonRelation("Test burial relation");
LocationDto address = new LocationDto();
address.setRegion(rdcf.region);
address.setDistrict(rdcf.district);
address.setCommunity(rdcf.community);
address.setCity("Test City");
burial.setLocation(address);
epiData.getExposures().add(burial);
ExposureDto travel = ExposureDto.build(ExposureType.TRAVEL);
travel.getLocation().setDetails("Test travel destination");
epiData.getExposures().add(travel);
ExposureDto gathering = ExposureDto.build(ExposureType.GATHERING);
gathering.setLocation(address);
gathering.setDescription("Test gathering description");
epiData.getExposures().add(gathering);
});
return caze;
}
use of de.symeda.sormas.api.epidata.EpiDataDto in project SORMAS-Project by hzi-braunschweig.
the class EpiDataPseudonymizationTest method getEpiDataInJurisdiction.
@Test
public void getEpiDataInJurisdiction() {
CaseDataDto caseWEpiData = createCaseWEpiData(user2, rdcf2);
CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caseWEpiData.getUuid());
EpiDataDto epiData = savedCase.getEpiData();
assertThat(epiData.getExposures().get(0).getDescription(), is("Test description"));
assertThat(epiData.getExposures().get(0).getLocation().getDetails(), is("Test location details"));
assertThat(epiData.getExposures().get(1).getTypeOfAnimalDetails(), is("Test other animal details"));
assertThat(epiData.getExposures().get(2).getWaterSourceDetails(), is("Test water source details"));
assertThat(epiData.getExposures().get(3).getAnimalContactTypeDetails(), is("Test animal contact type details"));
ExposureDto burial = epiData.getExposures().get(4);
assertThat(burial.getDeceasedPersonName(), is("John Smith"));
assertThat(burial.getDeceasedPersonRelation(), is("Test burial relation"));
LocationDto burialAddress = burial.getLocation();
assertThat(burialAddress.getCommunity(), is(rdcf2.community));
assertThat(burialAddress.getCity(), is("Test City"));
ExposureDto travel = epiData.getExposures().get(5);
assertThat(travel.getLocation().getDetails(), is("Test travel destination"));
ExposureDto gathering = epiData.getExposures().get(6);
assertThat(gathering.getDescription(), is("Test gathering description"));
LocationDto gatheringAddress = gathering.getLocation();
assertThat(gatheringAddress.getCommunity(), is(rdcf2.community));
assertThat(gatheringAddress.getCity(), is("Test City"));
}
Aggregations