use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class CaseController method getCaseCreateComponent.
public CommitDiscardWrapperComponent<CaseCreateForm> getCaseCreateComponent(ContactDto convertedContact, EventParticipantDto convertedEventParticipant, TravelEntryDto convertedTravelEntry, Disease unrelatedDisease, boolean createdFromLabMessage) {
assert ((convertedContact == null && convertedEventParticipant == null) || (convertedContact == null && convertedTravelEntry == null) || (convertedEventParticipant == null && convertedTravelEntry == null));
assert (unrelatedDisease == null || (convertedEventParticipant == null && convertedTravelEntry == null));
CaseCreateForm createForm;
if (createdFromLabMessage) {
createForm = new CaseCreateForm(true, false, null);
} else {
createForm = convertedContact == null && convertedEventParticipant == null && convertedTravelEntry == null && unrelatedDisease == null ? new CaseCreateForm() : new CaseCreateForm(convertedTravelEntry);
}
CaseDataDto caze;
PersonDto person;
SymptomsDto symptoms;
if (convertedContact != null) {
VisitDto lastVisit = FacadeProvider.getVisitFacade().getLastVisitByContact(convertedContact.toReference());
if (lastVisit != null) {
symptoms = lastVisit.getSymptoms();
} else {
symptoms = null;
}
person = FacadeProvider.getPersonFacade().getPersonByUuid(convertedContact.getPerson().getUuid());
if (unrelatedDisease == null) {
caze = CaseDataDto.buildFromContact(convertedContact);
caze.getEpiData().setContactWithSourceCaseKnown(YesNoUnknown.YES);
} else {
caze = CaseDataDto.buildFromUnrelatedContact(convertedContact, unrelatedDisease);
}
} else if (convertedEventParticipant != null) {
EventDto event = FacadeProvider.getEventFacade().getEventByUuid(convertedEventParticipant.getEvent().getUuid(), false);
symptoms = null;
person = convertedEventParticipant.getPerson();
if (unrelatedDisease == null) {
caze = CaseDataDto.buildFromEventParticipant(convertedEventParticipant, person, event.getDisease());
} else {
caze = CaseDataDto.buildFromEventParticipant(convertedEventParticipant, person, unrelatedDisease);
}
} else if (convertedTravelEntry != null) {
symptoms = null;
person = FacadeProvider.getPersonFacade().getPersonByUuid(convertedTravelEntry.getPerson().getUuid());
caze = CaseDataDto.buildFromTravelEntry(convertedTravelEntry, person);
} else {
symptoms = null;
person = null;
caze = CaseDataDto.build(null, null);
}
UserDto user = UserProvider.getCurrent().getUser();
UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
caze.setReportingUser(userReference);
if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
caze.setResponsibleRegion(user.getRegion());
caze.setResponsibleDistrict(user.getDistrict());
caze.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
caze.setDisease(Disease.UNDEFINED);
} else if (user.getHealthFacility() != null) {
FacilityDto healthFacility = FacadeProvider.getFacilityFacade().getByUuid(user.getHealthFacility().getUuid());
caze.setResponsibleRegion(healthFacility.getRegion());
caze.setResponsibleDistrict(healthFacility.getDistrict());
caze.setResponsibleCommunity(healthFacility.getCommunity());
caze.setHealthFacility(healthFacility.toReference());
} else if (convertedTravelEntry == null) {
caze.setResponsibleRegion(user.getRegion());
caze.setResponsibleDistrict(user.getDistrict());
caze.setResponsibleCommunity(user.getCommunity());
}
createForm.setValue(caze);
createForm.setPerson(person);
createForm.setSymptoms(symptoms);
if (convertedContact != null || convertedEventParticipant != null || convertedTravelEntry != null) {
createForm.setPersonalDetailsReadOnlyIfNotEmpty(true);
createForm.setDiseaseReadOnly(true);
}
final CommitDiscardWrapperComponent<CaseCreateForm> editView = new CommitDiscardWrapperComponent<CaseCreateForm>(createForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_CREATE), createForm.getFieldGroup());
if (createForm.getHomeAddressForm() != null) {
editView.addFieldGroups(createForm.getHomeAddressForm().getFieldGroup());
}
editView.addCommitListener(() -> {
if (!createForm.getFieldGroup().isModified()) {
final CaseDataDto dto = createForm.getValue();
if (dto.getHealthFacility() == null || FacilityDto.NONE_FACILITY_UUID.equals(dto.getHealthFacility().getUuid())) {
dto.setFacilityType(null);
}
if (convertedContact != null) {
int incubationPeriod = FacadeProvider.getDiseaseConfigurationFacade().getCaseFollowUpDuration(dto.getDisease());
List<VisitDto> visits = FacadeProvider.getVisitFacade().getVisitsByContactAndPeriod(convertedContact.toReference(), DateHelper.subtractDays(dto.getReportDate(), incubationPeriod), DateHelper.addDays(dto.getReportDate(), incubationPeriod));
for (VisitDto visit : visits) {
SymptomsHelper.updateSymptoms(visit.getSymptoms(), dto.getSymptoms());
}
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
dto.getSymptoms().setUuid(DataHelper.createUuid());
dto.getHealthConditions().setUuid(DataHelper.createUuid());
dto.getEpiData().setUuid(DataHelper.createUuid());
dto.getEpiData().getExposures().forEach(exposure -> {
exposure.setUuid(DataHelper.createUuid());
exposure.getLocation().setUuid(DataHelper.createUuid());
});
dto.setWasInQuarantineBeforeIsolation(YesNoUnknown.YES);
transferDataToPerson(createForm, person);
FacadeProvider.getPersonFacade().savePerson(person);
saveCase(dto);
// retrieve the contact just in case it has been changed during case saving
ContactDto updatedContact = FacadeProvider.getContactFacade().getByUuid(convertedContact.getUuid());
// automatically change the contact status to "converted"
updatedContact.setContactStatus(ContactStatus.CONVERTED);
// automatically change the contact classification to "confirmed"
updatedContact.setContactClassification(ContactClassification.CONFIRMED);
// set resulting case on contact and save it
updatedContact.setResultingCase(dto.toReference());
FacadeProvider.getContactFacade().save(updatedContact);
FacadeProvider.getCaseFacade().setSampleAssociations(updatedContact.toReference(), dto.toReference());
Notification.show(I18nProperties.getString(Strings.messageCaseCreated), Type.ASSISTIVE_NOTIFICATION);
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, dto.getUuid(), null);
}
} else if (convertedEventParticipant != null) {
selectOrCreateCase(dto, convertedEventParticipant.getPerson(), uuid -> {
if (uuid == null) {
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
saveCase(dto);
// retrieve the event participant just in case it has been changed during case saving
EventParticipantDto updatedEventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(convertedEventParticipant.getUuid());
if (unrelatedDisease == null) {
// set resulting case on event participant and save it
updatedEventParticipant.setResultingCase(dto.toReference());
FacadeProvider.getEventParticipantFacade().saveEventParticipant(updatedEventParticipant);
FacadeProvider.getCaseFacade().setSampleAssociations(updatedEventParticipant.toReference(), dto.toReference());
} else {
FacadeProvider.getCaseFacade().setSampleAssociationsUnrelatedDisease(updatedEventParticipant.toReference(), dto.toReference());
}
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, dto.getUuid(), null);
}
} else {
convertedEventParticipant.setResultingCase(FacadeProvider.getCaseFacade().getReferenceByUuid(uuid));
FacadeProvider.getEventParticipantFacade().saveEventParticipant(convertedEventParticipant);
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, uuid, null);
}
}
});
} else if (convertedTravelEntry != null) {
transferDataToPerson(createForm, person);
FacadeProvider.getPersonFacade().savePerson(person);
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
saveCase(dto);
// retrieve the travel entry just in case it has been changed during case saving
TravelEntryDto updatedTravelEntry = FacadeProvider.getTravelEntryFacade().getByUuid(convertedTravelEntry.getUuid());
// set resulting case on travel entry and save it
updatedTravelEntry.setResultingCase(dto.toReference());
FacadeProvider.getTravelEntryFacade().save(updatedTravelEntry);
Notification.show(I18nProperties.getString(Strings.messageCaseCreated), Type.ASSISTIVE_NOTIFICATION);
if (!createdFromLabMessage) {
navigateToView(CaseDataView.VIEW_NAME, dto.getUuid(), null);
}
} else if (createdFromLabMessage) {
PersonDto dbPerson = FacadeProvider.getPersonFacade().getPersonByUuid(dto.getPerson().getUuid());
if (dbPerson == null) {
PersonDto personDto = PersonDto.build();
transferDataToPerson(createForm, personDto);
FacadeProvider.getPersonFacade().savePerson(personDto);
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
dto.setPerson(personDto.toReference());
saveCase(dto);
} else {
transferDataToPerson(createForm, dbPerson);
FacadeProvider.getPersonFacade().savePerson(dbPerson);
dto.getSymptoms().setOnsetDate(createForm.getOnsetDate());
saveCase(dto);
}
} else {
PersonDto searchedPerson = createForm.getSearchedPerson();
if (searchedPerson != null) {
dto.setPerson(searchedPerson.toReference());
selectOrCreateCase(createForm, dto, searchedPerson.toReference());
} else {
// look for potential duplicate
final PersonDto duplicatePerson = PersonDto.build();
transferDataToPerson(createForm, duplicatePerson);
ControllerProvider.getPersonController().selectOrCreatePerson(duplicatePerson, I18nProperties.getString(Strings.infoSelectOrCreatePersonForCase), selectedPerson -> {
if (selectedPerson != null) {
dto.setPerson(selectedPerson);
selectOrCreateCase(createForm, dto, selectedPerson);
}
}, true);
}
}
}
});
return editView;
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class VisitController method createVisit.
public void createVisit(ContactReferenceDto contactRef, Consumer<VisitReferenceDto> doneConsumer) {
VisitDto visit = createNewVisit(contactRef);
ContactDto contact = FacadeProvider.getContactFacade().getByUuid(contactRef.getUuid());
PersonDto contactPerson = FacadeProvider.getPersonFacade().getPersonByUuid(contact.getPerson().getUuid());
VisitEditForm createForm = new VisitEditForm(visit.getDisease(), contact, contactPerson, true, true);
createForm.setValue(visit);
createVisit(createForm, doneConsumer);
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class DownloadUtilTest method testCreateVisitsExportStreamResource.
@Test
public void testCreateVisitsExportStreamResource() throws IOException {
TestDataCreator.RDCF rdcf = creator.createRDCF("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);
PersonDto contactPerson = creator.createPerson("Contact", "Person");
ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date());
VisitDto visit = creator.createVisit(caze.getDisease(), contactPerson.toReference(), new Date(), VisitStatus.COOPERATIVE);
visit.getSymptoms().setAbdominalPain(SymptomState.YES);
FacadeProvider.getVisitFacade().saveVisit(visit);
PersonDto contactPerson2 = creator.createPerson("Contact2", "Person2");
ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), contactPerson2.toReference(), caze, new Date(), null);
VisitDto visit21 = creator.createVisit(caze.getDisease(), contactPerson2.toReference(), new Date(), VisitStatus.COOPERATIVE);
visit21.getSymptoms().setAbdominalPain(SymptomState.YES);
FacadeProvider.getVisitFacade().saveVisit(visit21);
VisitDto visit22 = creator.createVisit(caze.getDisease(), contactPerson2.toReference(), new Date(), VisitStatus.COOPERATIVE);
visit22.getSymptoms().setAgitation(SymptomState.YES);
FacadeProvider.getVisitFacade().saveVisit(visit22);
// this visit is older than the allowed offset days - should not affect our export
VisitDto visit23 = creator.createVisit(caze.getDisease(), contactPerson2.toReference(), DateHelper.subtractDays(new Date(), FollowUpLogic.ALLOWED_DATE_OFFSET + 1), VisitStatus.COOPERATIVE);
visit23.getSymptoms().setAgitation(SymptomState.YES);
FacadeProvider.getVisitFacade().saveVisit(visit23);
PersonDto contactPerson3 = creator.createPerson("Contact3", "Person3");
ContactDto contact3 = creator.createContact(user.toReference(), user.toReference(), contactPerson3.toReference(), caze, new Date(), new Date());
for (int i = 0; i < 3; i++) {
creator.createVisit(caze.getDisease(), contactPerson3.toReference(), new Date(), VisitStatus.COOPERATIVE);
}
StreamResource contactVisitsExport = DownloadUtil.createVisitsExportStreamResource(new ContactCriteria(), Collections::emptySet, ExportEntityName.CONTACT_FOLLOW_UPS);
String expectedFileName = DownloadUtil.createFileNameWithCurrentDate(ExportEntityName.CONTACT_FOLLOW_UPS, ".csv");
Assert.assertNotNull(contactVisitsExport);
Assert.assertEquals(expectedFileName, contactVisitsExport.getStream().getFileName());
InputStream stream = contactVisitsExport.getStream().getStream();
final String shortDate = DateFormatHelper.formatDate(new Date());
Assert.assertEquals("\"Contact ID\",\"First name\",\"Last name\",\"Date and time of visit\",\"Person available and " + "cooperative?\",\"Symptoms\",\"Date and time of visit\",\"Person available and cooperative?\"," + "\"Symptoms\",\"Date and time of visit\",\"Person available and cooperative?\",\"Symptoms\"\n" + "\"\",\"\",\"\",\"Day 1\",\"Day 1\",\"Day 1\",\"Day 2\",\"Day 2\",\"Day 2\",\"Day 3\",\"Day 3\",\"Day" + " 3\"\n" + "\"" + contact.getUuid() + "\",\"Contact\",\"Person\",\"" + shortDate + "\",\"Available and cooperative\"," + "\"Abdominal pain\",,,,,,\n" + "\"" + contact2.getUuid() + "\",\"Contact2\",\"Person2\",\"" + shortDate + "\",\"Available and " + "cooperative\",\"Abdominal pain\",\"" + shortDate + "\",\"Available and cooperative\",\"\",,,\n" + "\"" + contact3.getUuid() + "\",\"Contact3\",\"Person3\",\"" + shortDate + "\",\"Available and " + "cooperative\",\"\",\"" + shortDate + "\",\"Available and cooperative\",\"\",\"" + shortDate + "\",\"Available and " + "cooperative\",\"\"\n", IOUtils.toString(stream, StandardCharsets.UTF_8.name()));
}
use of de.symeda.sormas.api.visit.VisitDto in project SORMAS-Project by hzi-braunschweig.
the class FollowUpLogic method calculateFollowUpUntilDate.
public static FollowUpPeriodDto calculateFollowUpUntilDate(FollowUpPeriodDto followUpPeriod, Date overwriteUntilDate, List<VisitDto> visits, int followUpDuration, boolean allowFreeOverwrite) {
Date standardUntilDate = DateHelper.addDays(followUpPeriod.getFollowUpStartDate(), followUpDuration);
Date untilDate = overwriteUntilDate != null ? overwriteUntilDate : standardUntilDate;
Date lastVisitDate = null;
boolean additionalVisitNeeded = true;
for (VisitDto visit : visits) {
if (lastVisitDate == null || DateHelper.getStartOfDay(visit.getVisitDateTime()).after(DateHelper.getStartOfDay(lastVisitDate))) {
lastVisitDate = visit.getVisitDateTime();
}
if (additionalVisitNeeded && !DateHelper.getStartOfDay(visit.getVisitDateTime()).before(DateHelper.getStartOfDay(untilDate)) && visit.getVisitStatus() == VisitStatus.COOPERATIVE) {
additionalVisitNeeded = false;
}
}
// Follow-up until needs to be extended to the date after the last visit if there is no cooperative visit after the follow-up until date
if (additionalVisitNeeded && lastVisitDate != null && untilDate.before(DateHelper.addDays(lastVisitDate, 1))) {
untilDate = DateHelper.addDays(lastVisitDate, 1);
}
// date or symptom onset date were changed), and allowFreeOverwrite is false, set it to the standard follow-up until date
if (!allowFreeOverwrite && DateHelper.getStartOfDay(untilDate).before(standardUntilDate)) {
untilDate = standardUntilDate;
}
followUpPeriod.setFollowUpEndDate(untilDate);
return followUpPeriod;
}
Aggregations