Search in sources :

Example 41 with VisitDto

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;
}
Also used : SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) Alignment(com.vaadin.ui.Alignment) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) ClinicalCourseForm(de.symeda.sormas.ui.clinicalcourse.ClinicalCourseForm) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) MaternalHistoryView(de.symeda.sormas.ui.caze.maternalhistory.MaternalHistoryView) CssStyles(de.symeda.sormas.ui.utils.CssStyles) Page(com.vaadin.server.Page) PortHealthInfoView(de.symeda.sormas.ui.caze.porthealthinfo.PortHealthInfoView) TextArea(com.vaadin.ui.TextArea) ValoTheme(com.vaadin.ui.themes.ValoTheme) DiseaseHelper(de.symeda.sormas.api.DiseaseHelper) Link(com.vaadin.ui.Link) HtmlHelper(de.symeda.sormas.api.utils.HtmlHelper) EpiDataForm(de.symeda.sormas.ui.epidata.EpiDataForm) Type(com.vaadin.ui.Notification.Type) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) DateHelper8(de.symeda.sormas.ui.utils.DateHelper8) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MaternalHistoryForm(de.symeda.sormas.ui.caze.maternalhistory.MaternalHistoryForm) CloseEvent(com.vaadin.ui.Window.CloseEvent) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) VerticalLayout(com.vaadin.ui.VerticalLayout) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) SymptomsContext(de.symeda.sormas.api.symptoms.SymptomsContext) ArrayList(java.util.ArrayList) ClassificationHtmlRenderer(de.symeda.sormas.api.caze.classification.ClassificationHtmlRenderer) ExternalSurveillanceServiceGateway(de.symeda.sormas.ui.externalsurveillanceservice.ExternalSurveillanceServiceGateway) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) CountryHelper(de.symeda.sormas.api.CountryHelper) SimilarEventParticipantDto(de.symeda.sormas.api.event.SimilarEventParticipantDto) TitleLayout(de.symeda.sormas.ui.utils.components.page.title.TitleLayout) ContactSimilarityCriteria(de.symeda.sormas.api.contact.ContactSimilarityCriteria) ContentMode(com.vaadin.shared.ui.ContentMode) MessageType(de.symeda.sormas.api.messaging.MessageType) DataHelper(de.symeda.sormas.api.utils.DataHelper) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CaseFacade(de.symeda.sormas.api.caze.CaseFacade) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) Captions(de.symeda.sormas.api.i18n.Captions) LineListingLayout(de.symeda.sormas.ui.caze.components.linelisting.LineListingLayout) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) Button(com.vaadin.ui.Button) CaseBulkEditData(de.symeda.sormas.api.caze.CaseBulkEditData) Disease(de.symeda.sormas.api.Disease) VisitDto(de.symeda.sormas.api.visit.VisitDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) DiseaseClassificationCriteriaDto(de.symeda.sormas.api.caze.classification.DiseaseClassificationCriteriaDto) FeatureType(de.symeda.sormas.api.feature.FeatureType) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) UI(com.vaadin.ui.UI) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) Window(com.vaadin.ui.Window) SymptomsForm(de.symeda.sormas.ui.symptoms.SymptomsForm) DetailSubComponentWrapper(de.symeda.sormas.ui.utils.DetailSubComponentWrapper) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) SmsComponent(de.symeda.sormas.ui.caze.messaging.SmsComponent) ViewModelProviders(de.symeda.sormas.ui.ViewModelProviders) CaseEpiDataView(de.symeda.sormas.ui.epidata.CaseEpiDataView) UserRole(de.symeda.sormas.api.user.UserRole) UserProvider(de.symeda.sormas.ui.UserProvider) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) CloseListener(com.vaadin.ui.Window.CloseListener) ViewMode(de.symeda.sormas.ui.utils.ViewMode) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Collection(java.util.Collection) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) Collectors(java.util.stream.Collectors) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) Objects(java.util.Objects) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) List(java.util.List) ExternalResource(com.vaadin.server.ExternalResource) TherapyView(de.symeda.sormas.ui.therapy.TherapyView) ContactDto(de.symeda.sormas.api.contact.ContactDto) Optional(java.util.Optional) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) DateHelper(de.symeda.sormas.api.utils.DateHelper) CollectionUtils(org.apache.commons.collections.CollectionUtils) Notification(com.vaadin.ui.Notification) SormasUI(de.symeda.sormas.ui.SormasUI) Label(com.vaadin.ui.Label) TitleLayoutHelper(de.symeda.sormas.ui.utils.components.page.title.TitleLayoutHelper) HospitalizationForm(de.symeda.sormas.ui.hospitalization.HospitalizationForm) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) AbstractView(de.symeda.sormas.ui.utils.AbstractView) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) PortHealthInfoForm(de.symeda.sormas.ui.caze.porthealthinfo.PortHealthInfoForm) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) UserDto(de.symeda.sormas.api.user.UserDto) HospitalizationView(de.symeda.sormas.ui.hospitalization.HospitalizationView) Sizeable(com.vaadin.server.Sizeable) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Consumer(java.util.function.Consumer) Navigator(com.vaadin.navigator.Navigator) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) ClinicalCourseView(de.symeda.sormas.ui.clinicalcourse.ClinicalCourseView) HospitalizationDto(de.symeda.sormas.api.hospitalization.HospitalizationDto) Unit(com.vaadin.server.Sizeable.Unit) Strings(de.symeda.sormas.api.i18n.Strings) Component(com.vaadin.ui.Component) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) EventDto(de.symeda.sormas.api.event.EventDto) SimilarEventParticipantDto(de.symeda.sormas.api.event.SimilarEventParticipantDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Example 42 with VisitDto

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);
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Example 43 with VisitDto

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()));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) InputStream(java.io.InputStream) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) StreamResource(com.vaadin.server.StreamResource) ContactDto(de.symeda.sormas.api.contact.ContactDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) VisitDto(de.symeda.sormas.api.visit.VisitDto) Collections(java.util.Collections) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 44 with VisitDto

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;
}
Also used : VisitDto(de.symeda.sormas.api.visit.VisitDto) Date(java.util.Date)

Aggregations

VisitDto (de.symeda.sormas.api.visit.VisitDto)44 PersonDto (de.symeda.sormas.api.person.PersonDto)27 Test (org.junit.Test)25 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)24 Date (java.util.Date)24 ContactDto (de.symeda.sormas.api.contact.ContactDto)22 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)20 UserDto (de.symeda.sormas.api.user.UserDto)19 ExternalVisitDto (de.symeda.sormas.api.visit.ExternalVisitDto)14 LocalDate (java.time.LocalDate)11 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)10 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)8 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)7 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)7 VisitCriteria (de.symeda.sormas.api.visit.VisitCriteria)7 ArrayList (java.util.ArrayList)7 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)6 ClinicalVisitDto (de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto)5 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)5 SampleDto (de.symeda.sormas.api.sample.SampleDto)4