Skip to content

Commit

Permalink
#13211 - Update case when person's condition is set to "Dead" or "Bur…
Browse files Browse the repository at this point in the history
…ied"
  • Loading branch information
SergiuPacurariu committed Jan 27, 2025
1 parent dafe50a commit 5f9a396
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ public interface Strings {
String messageCaseTransfered = "messageCaseTransfered";
String messageChangePathogenTestResult = "messageChangePathogenTestResult";
String messageChangingCaseOutcome = "messageChangingCaseOutcome";
String messageChangingPersonPresentCondition = "messageChangingPersonPresentCondition";
String messageCheckInputData = "messageCheckInputData";
String messageClinicalCourseSaved = "messageClinicalCourseSaved";
String messageClinicalVisitCreated = "messageClinicalVisitCreated";
Expand Down
1 change: 1 addition & 0 deletions sormas-api/src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ messageSyncUsersFromAuthProviderConfigurationError=Syncing users from authentica
messageCountriesExcludedFromDataProtection=Countries excluded from data protection for this field:
messageChangingCaseOutcome=Changing this information will also affect the associated person.
messageReviewChangesAndConfirm=Please review the changes and confirm them:
messageChangingPersonPresentCondition = Changing this information will also affect the associated cases.

# Notifications
notificationCaseClassificationChanged = The classification of case %s has changed to %s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand All @@ -29,13 +31,16 @@

import org.apache.commons.lang3.StringUtils;

import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.Page;
import com.vaadin.server.Sizeable;
import com.vaadin.server.Sizeable.Unit;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
Expand All @@ -48,20 +53,24 @@
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.FacadeProvider;
import de.symeda.sormas.api.caze.CaseClassification;
import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.caze.CaseOutcome;
import de.symeda.sormas.api.event.EventParticipantSelectionDto;
import de.symeda.sormas.api.event.EventReferenceDto;
import de.symeda.sormas.api.externaljournal.ExternalJournalSyncResponseDto;
import de.symeda.sormas.api.i18n.Captions;
import de.symeda.sormas.api.i18n.I18nProperties;
import de.symeda.sormas.api.i18n.Strings;
import de.symeda.sormas.api.i18n.Validations;
import de.symeda.sormas.api.person.CauseOfDeath;
import de.symeda.sormas.api.person.PersonContext;
import de.symeda.sormas.api.person.PersonCriteria;
import de.symeda.sormas.api.person.PersonDto;
import de.symeda.sormas.api.person.PersonFacade;
import de.symeda.sormas.api.person.PersonHelper;
import de.symeda.sormas.api.person.PersonIndexDto;
import de.symeda.sormas.api.person.PersonReferenceDto;
import de.symeda.sormas.api.person.PresentCondition;
import de.symeda.sormas.api.person.SimilarPersonDto;
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.api.utils.DataHelper;
Expand All @@ -75,6 +84,8 @@
import de.symeda.sormas.ui.utils.ButtonHelper;
import de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent;
import de.symeda.sormas.ui.utils.ConfirmationComponent;
import de.symeda.sormas.ui.utils.CssStyles;
import de.symeda.sormas.ui.utils.DateFormatHelper;
import de.symeda.sormas.ui.utils.VaadinUiUtil;
import de.symeda.sormas.ui.utils.ViewMode;
import de.symeda.sormas.ui.utils.components.page.title.TitleLayout;
Expand Down Expand Up @@ -418,7 +429,7 @@ public CommitDiscardWrapperComponent<PersonEditForm> getPersonEditComponent(Stri
editView.addCommitListener(() -> {
if (!editForm.getFieldGroup().isModified()) {
PersonDto dto = editForm.getValue();
savePerson(dto);
savePersonWithPersonConditionChanged(dto);
}
});

Expand All @@ -443,7 +454,7 @@ public CommitDiscardWrapperComponent<PersonEditForm> getPersonEditComponent(
editView.addCommitListener(() -> {
if (!editForm.getFieldGroup().isModified()) {
PersonDto dto = editForm.getValue();
savePerson(dto);
savePersonWithPersonConditionChanged(dto);
}
});

Expand Down Expand Up @@ -478,16 +489,122 @@ public CommitDiscardWrapperComponent<PersonEditForm> getPersonEditComponent(
CommitDiscardWrapperComponent<PersonSelectionGrid> content =
(CommitDiscardWrapperComponent<PersonSelectionGrid>) editView.getWrappedComponent().getWarningSimilarPersons().getContent();
content.getDiscardButton().setVisible(true);
content.addCommitListener(() -> savePerson(dto));
content.addCommitListener(() -> savePersonWithPersonConditionChanged(dto));
} else {
savePerson(dto);
savePersonWithPersonConditionChanged(dto);
}
}
});

return editView;
}

private void savePersonWithPersonConditionChanged(PersonDto editedPerson) {
PersonDto initialPerson = personFacade.getByUuid(editedPerson.getUuid());
PresentCondition initialPresentCondition = initialPerson.getPresentCondition();

CaseDataDto lastCase;
if (editedPerson.getCauseOfDeathDisease() != null) {
List<CaseDataDto> personCases = FacadeProvider.getCaseFacade()
.getAllCasesOfPerson(editedPerson.getUuid())
.stream()
.filter(caseDataDto -> caseDataDto.getDisease().equals(editedPerson.getCauseOfDeathDisease()))
.collect(Collectors.toList());
lastCase = Collections.max(personCases, Comparator.comparing(CaseDataDto::getReportDate));
} else {
lastCase = null;
}

PresentCondition editedPresentCondition = editedPerson.getPresentCondition();
if (lastCase != null
&& (Arrays.asList(PresentCondition.BURIED, PresentCondition.DEAD).contains(editedPresentCondition))
&& !(Arrays.asList(PresentCondition.BURIED, PresentCondition.DEAD).contains(initialPresentCondition))
&& editedPerson.getCauseOfDeath().equals(CauseOfDeath.EPIDEMIC_DISEASE)) {

if (lastCase.getOutcome().equals(CaseOutcome.DECEASED)
&& editedPerson.getDeathDate() != null
&& editedPerson.getDeathDate().equals(lastCase.getOutcomeDate())) {
savePerson(editedPerson);
return;
} else {
VerticalLayout warningLayout = new VerticalLayout();
warningLayout.setSpacing(false);
CommitDiscardWrapperComponent<VerticalLayout> warningComponent = new CommitDiscardWrapperComponent<>(warningLayout);
warningComponent.setWidth(100, Unit.PERCENTAGE);

Window popupWindow = VaadinUiUtil.showPopupWindow(warningComponent, I18nProperties.getString(Strings.warning));
Label infoLabel = new Label(I18nProperties.getString(Strings.messageChangingPersonPresentCondition));
CssStyles.style(infoLabel, CssStyles.LABEL_LARGE, CssStyles.LABEL_WHITE_SPACE_NORMAL);
warningLayout.addComponent(infoLabel);

// case information
warningLayout.addComponent(new Label(lastCase.buildCaption()));

// confirmation message
Label confirmationMessage = new Label(I18nProperties.getString(Strings.messageReviewChangesAndConfirm));
confirmationMessage.addStyleName(CssStyles.VSPACE_TOP_3);
warningLayout.addComponent(confirmationMessage);

// changes listed
HorizontalLayout changesLayout = new HorizontalLayout();
changesLayout.setMargin(false);
changesLayout.addStyleNames(CssStyles.VSPACE_TOP_1, CssStyles.VSPACE_2);

VerticalLayout fieldsLayout = new VerticalLayout();
fieldsLayout.setMargin(false);
Label fieldsLabel = new Label(I18nProperties.getCaption(Captions.confirmChangesField));
fieldsLayout.addComponent(fieldsLabel);
fieldsLabel.addStyleName(CssStyles.LABEL_SECONDARY);
fieldsLayout.addComponent(new Label(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.OUTCOME)));
fieldsLayout.addComponent(new Label(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.OUTCOME_DATE)));

VerticalLayout arrowsLayout = new VerticalLayout();
arrowsLayout.setMargin(false);
arrowsLayout.addComponent(new Label());
arrowsLayout.addComponent(new Label(VaadinIcons.ARROW_RIGHT.getHtml(), ContentMode.HTML));
arrowsLayout.addComponent(new Label(VaadinIcons.ARROW_RIGHT.getHtml(), ContentMode.HTML));

VerticalLayout valuesLayout = new VerticalLayout();
valuesLayout.setMargin(false);

Label valuesLabel = new Label(I18nProperties.getCaption(Captions.confirmChangesValue));
valuesLabel.addStyleName(CssStyles.LABEL_SECONDARY);
valuesLayout.addComponent(valuesLabel);

valuesLayout.addComponent(new Label(CaseOutcome.DECEASED.toString()));
valuesLayout.addComponent(new Label(DateFormatHelper.formatDate(editedPerson.getDeathDate())));

changesLayout.addComponent(fieldsLayout);
changesLayout.addComponent(arrowsLayout);
changesLayout.addComponent(valuesLayout);
warningLayout.addComponent(changesLayout);

// actions
warningComponent.addCommitListener(() -> {
savePerson(editedPerson);
lastCase.setOutcome(CaseOutcome.DECEASED);
if (editedPerson.getDeathDate() != null) {
lastCase.setOutcomeDate(editedPerson.getDeathDate());
}
FacadeProvider.getCaseFacade().save(lastCase);
popupWindow.close();
});

warningComponent.addDiscardListener(() -> popupWindow.close());

// popup configuration
popupWindow.addCloseListener(e -> popupWindow.close());
popupWindow.setWidth(600, Sizeable.Unit.PIXELS);

return;
}

// savePerson(editedPerson);
}

savePerson(editedPerson);
}

private void savePerson(PersonDto personDto) {
DataHelper.Pair<CaseClassification, PersonDto> saveResult = personFacade.savePersonWithoutNotifyingExternalJournal(personDto);

Expand Down

0 comments on commit 5f9a396

Please sign in to comment.