use of de.symeda.sormas.api.contact.ContactReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method convertToReferenceDto.
private ContactReferenceDto convertToReferenceDto(Contact source) {
ContactReferenceDto dto = toReferenceDto(source);
if (source != null && dto != null) {
final ContactJurisdictionFlagsDto contactJurisdictionFlagsDto = service.inJurisdictionOrOwned(source);
boolean isInJurisdiction = contactJurisdictionFlagsDto.getInJurisdiction();
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
pseudonymizer.pseudonymizeDto(ContactReferenceDto.class, dto, isInJurisdiction, (c) -> {
if (source.getCaze() != null) {
pseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, c.getCaseName(), contactJurisdictionFlagsDto.getCaseInJurisdiction(), null);
}
pseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, c.getContactName(), isInJurisdiction, null);
});
}
return dto;
}
use of de.symeda.sormas.api.contact.ContactReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class VisitFacadeEjbTest method testCreateExternalVisit.
@Test
public void testCreateExternalVisit() {
TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Ext", "Vis", UserRole.REST_EXTERNAL_VISITS_USER);
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);
final ExternalVisitDto externalVisitDto = new ExternalVisitDto();
externalVisitDto.setPersonUuid(contactPerson.getUuid());
externalVisitDto.setDisease(contact.getDisease());
externalVisitDto.setVisitDateTime(new Date());
externalVisitDto.setVisitStatus(VisitStatus.COOPERATIVE);
final String visitRemarks = "Everything good";
externalVisitDto.setVisitRemarks(visitRemarks);
final ExternalVisitDto externalVisitDto2 = new ExternalVisitDto();
externalVisitDto2.setPersonUuid(cazePerson.getUuid());
externalVisitDto2.setDisease(caze.getDisease());
externalVisitDto2.setVisitDateTime(new Date());
externalVisitDto2.setVisitStatus(VisitStatus.COOPERATIVE);
final String visitRemarks2 = "Everything good 2";
externalVisitDto2.setVisitRemarks(visitRemarks2);
final VisitFacade visitFacade = getVisitFacade();
visitFacade.saveExternalVisit(externalVisitDto);
visitFacade.saveExternalVisit(externalVisitDto2);
final VisitCriteria visitCriteria = new VisitCriteria();
final List<VisitIndexDto> visitIndexList = visitFacade.getIndexList(visitCriteria.contact(new ContactReferenceDto(contact.getUuid())), 0, 100, null);
assertNotNull(visitIndexList);
assertEquals(1, visitIndexList.size());
VisitIndexDto visitIndexDto = visitIndexList.get(0);
assertNotNull(visitIndexDto.getVisitDateTime());
assertEquals(VisitStatus.COOPERATIVE, visitIndexDto.getVisitStatus());
assertEquals(visitRemarks, visitIndexDto.getVisitRemarks());
assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
final VisitCriteria visitCriteria2 = new VisitCriteria();
final List<VisitIndexDto> visitIndexList2 = visitFacade.getIndexList(visitCriteria2.caze(new CaseReferenceDto(caze.getUuid())), 0, 100, null);
assertNotNull(visitIndexList2);
assertEquals(1, visitIndexList2.size());
VisitIndexDto visitIndexDto2 = visitIndexList2.get(0);
assertNotNull(visitIndexDto2.getVisitDateTime());
assertEquals(VisitStatus.COOPERATIVE, visitIndexDto2.getVisitStatus());
assertEquals(visitRemarks2, visitIndexDto2.getVisitRemarks());
assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
}
use of de.symeda.sormas.api.contact.ContactReferenceDto 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.contact.ContactReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class SampleController method getDiseaseOf.
public Disease getDiseaseOf(SampleDto sample) {
CaseReferenceDto cazeRef = sample.getAssociatedCase();
if (cazeRef != null) {
return FacadeProvider.getCaseFacade().getByUuid(cazeRef.getUuid()).getDisease();
}
ContactReferenceDto contactRef = sample.getAssociatedContact();
if (contactRef != null) {
return FacadeProvider.getContactFacade().getByUuid(contactRef.getUuid()).getDisease();
}
EventParticipantReferenceDto eventPartRef = sample.getAssociatedEventParticipant();
if (eventPartRef != null) {
EventReferenceDto eventRef = FacadeProvider.getEventParticipantFacade().getByUuid(eventPartRef.getUuid()).getEvent();
if (eventRef != null) {
return FacadeProvider.getEventFacade().getEventByUuid(eventRef.getUuid(), false).getDisease();
}
}
return null;
}
use of de.symeda.sormas.api.contact.ContactReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class SampleDataView method initView.
@Override
protected void initView(String params) {
setHeightUndefined();
String htmlLayout = LayoutUtil.fluidRow(LayoutUtil.fluidColumnLoc(8, 0, 12, 0, EDIT_LOC), LayoutUtil.fluidColumnLoc(4, 0, 6, 0, CASE_LOC), LayoutUtil.fluidColumnLoc(4, 0, 6, 0, CONTACT_LOC), LayoutUtil.fluidColumnLoc(4, 0, 6, 0, EVENT_PARTICIPANT_LOC), LayoutUtil.fluidColumnLoc(4, 0, 6, 0, PATHOGEN_TESTS_LOC), LayoutUtil.fluidColumnLoc(4, 0, 6, 0, ADDITIONAL_TESTS_LOC), LayoutUtil.fluidColumnLoc(4, 0, 6, 0, SORMAS_TO_SORMAS_LOC));
DetailSubComponentWrapper container = new DetailSubComponentWrapper(() -> editComponent);
container.setWidth(100, Unit.PERCENTAGE);
container.setMargin(true);
setSubComponent(container);
CustomLayout layout = new CustomLayout();
layout.addStyleName(CssStyles.ROOT_COMPONENT);
layout.setTemplateContents(htmlLayout);
layout.setWidth(100, Unit.PERCENTAGE);
layout.setHeightUndefined();
container.addComponent(layout);
SampleDto sampleDto = FacadeProvider.getSampleFacade().getSampleByUuid(getSampleRef().getUuid());
Disease disease = null;
final CaseReferenceDto associatedCase = sampleDto.getAssociatedCase();
if (associatedCase != null) {
final CaseDataDto caseDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(associatedCase.getUuid());
disease = caseDto.getDisease();
final CaseInfoLayout caseInfoLayout = new CaseInfoLayout(caseDto);
caseInfoLayout.addStyleName(CssStyles.SIDE_COMPONENT);
layout.addComponent(caseInfoLayout, CASE_LOC);
}
final ContactReferenceDto associatedContact = sampleDto.getAssociatedContact();
if (associatedContact != null) {
final ContactDto contactDto = FacadeProvider.getContactFacade().getByUuid(associatedContact.getUuid());
disease = contactDto.getDisease();
final ContactInfoLayout contactInfoLayout = new ContactInfoLayout(contactDto, UiFieldAccessCheckers.getDefault(contactDto.isPseudonymized()));
contactInfoLayout.addStyleName(CssStyles.SIDE_COMPONENT);
layout.addComponent(contactInfoLayout, CONTACT_LOC);
}
final EventParticipantReferenceDto associatedEventParticipant = sampleDto.getAssociatedEventParticipant();
if (associatedEventParticipant != null) {
final EventParticipantDto eventParticipantDto = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(associatedEventParticipant.getUuid());
final EventDto eventDto = FacadeProvider.getEventFacade().getEventByUuid(eventParticipantDto.getEvent().getUuid(), false);
disease = eventDto.getDisease();
final EventParticipantInfoLayout eventParticipantInfoLayout = new EventParticipantInfoLayout(eventParticipantDto, eventDto, UiFieldAccessCheckers.getDefault(eventParticipantDto.isPseudonymized()));
eventParticipantInfoLayout.addStyleName(CssStyles.SIDE_COMPONENT);
layout.addComponent(eventParticipantInfoLayout, EVENT_PARTICIPANT_LOC);
}
SampleController sampleController = ControllerProvider.getSampleController();
editComponent = sampleController.getSampleEditComponent(getSampleRef().getUuid(), sampleDto.isPseudonymized(), disease, true);
Consumer<Disease> createReferral = (relatedDisease) -> {
// save changes before referral creation
editComponent.commit();
SampleDto committedSample = editComponent.getWrappedComponent().getValue();
sampleController.createReferral(committedSample, relatedDisease);
};
Consumer<SampleDto> openReferredSample = referredSample -> sampleController.navigateToData(referredSample.getUuid());
sampleController.addReferOrLinkToOtherLabButton(editComponent, disease, createReferral, openReferredSample);
Consumer<SampleDto> navigate = targetSampleDto -> sampleController.navigateToData(targetSampleDto.getUuid());
sampleController.addReferredFromButton(editComponent, navigate);
editComponent.setMargin(new MarginInfo(false, false, true, false));
editComponent.setWidth(100, Unit.PERCENTAGE);
editComponent.getWrappedComponent().setWidth(100, Unit.PERCENTAGE);
editComponent.addStyleName(CssStyles.MAIN_COMPONENT);
layout.addComponent(editComponent, EDIT_LOC);
BiConsumer<PathogenTestDto, Runnable> onSavedPathogenTest = (pathogenTestDto, callback) -> callback.run();
// why? if(sampleDto.getSamplePurpose() !=null && sampleDto.getSamplePurpose().equals(SamplePurpose.EXTERNAL)) {
Supplier<Boolean> createOrEditAllowedCallback = () -> editComponent.getWrappedComponent().getFieldGroup().isValid();
SampleReferenceDto sampleReferenceDto = getSampleRef();
PathogenTestListComponent pathogenTestListComponent = new PathogenTestListComponent(sampleReferenceDto);
pathogenTestListComponent.addSideComponentCreateEventListener(e -> showNavigationConfirmPopupIfDirty(() -> {
if (createOrEditAllowedCallback.get()) {
ControllerProvider.getPathogenTestController().create(sampleReferenceDto, 0, pathogenTestListComponent::reload, onSavedPathogenTest);
} else {
Notification.show(null, I18nProperties.getString(Strings.messageFormHasErrorsPathogenTest), Notification.Type.ERROR_MESSAGE);
}
}));
pathogenTestListComponent.addSideComponentEditEventListener(e -> showNavigationConfirmPopupIfDirty(() -> {
String uuid = e.getUuid();
if (createOrEditAllowedCallback.get()) {
ControllerProvider.getPathogenTestController().edit(uuid, pathogenTestListComponent::reload, onSavedPathogenTest);
} else {
Notification.show(null, I18nProperties.getString(Strings.messageFormHasErrorsPathogenTest), Notification.Type.ERROR_MESSAGE);
}
}));
layout.addComponent(new SideComponentLayout(pathogenTestListComponent), PATHOGEN_TESTS_LOC);
if (UserProvider.getCurrent() != null && UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.ADDITIONAL_TESTS)) {
AdditionalTestListComponent additionalTestList = new AdditionalTestListComponent(sampleReferenceDto.getUuid());
additionalTestList.addStyleName(CssStyles.SIDE_COMPONENT);
layout.addComponent(additionalTestList, ADDITIONAL_TESTS_LOC);
}
boolean sormasToSormasEnabled = FacadeProvider.getSormasToSormasFacade().isSharingCasesContactsAndSamplesEnabledForUser();
if (sormasToSormasEnabled || sampleDto.getSormasToSormasOriginInfo() != null) {
VerticalLayout sormasToSormasLocLayout = new VerticalLayout();
sormasToSormasLocLayout.setMargin(false);
sormasToSormasLocLayout.setSpacing(false);
SormasToSormasListComponent sormasToSormasListComponent = new SormasToSormasListComponent(sampleDto);
sormasToSormasListComponent.addStyleNames(CssStyles.SIDE_COMPONENT);
sormasToSormasLocLayout.addComponent(sormasToSormasListComponent);
layout.addComponent(sormasToSormasLocLayout, SORMAS_TO_SORMAS_LOC);
}
// }
setSampleEditPermission(container);
}
Aggregations