19
19
20
20
import java .util .ArrayList ;
21
21
import java .util .Arrays ;
22
+ import java .util .Collections ;
23
+ import java .util .Comparator ;
22
24
import java .util .Date ;
23
25
import java .util .List ;
24
26
import java .util .Map ;
29
31
30
32
import org .apache .commons .lang3 .StringUtils ;
31
33
34
+ import com .vaadin .icons .VaadinIcons ;
32
35
import com .vaadin .navigator .Navigator ;
33
36
import com .vaadin .server .Page ;
37
+ import com .vaadin .server .Sizeable ;
34
38
import com .vaadin .server .Sizeable .Unit ;
35
39
import com .vaadin .shared .ui .ContentMode ;
36
40
import com .vaadin .ui .Alignment ;
37
41
import com .vaadin .ui .Button ;
38
42
import com .vaadin .ui .Grid ;
43
+ import com .vaadin .ui .HorizontalLayout ;
39
44
import com .vaadin .ui .Label ;
40
45
import com .vaadin .ui .Notification ;
41
46
import com .vaadin .ui .Notification .Type ;
48
53
import de .symeda .sormas .api .Disease ;
49
54
import de .symeda .sormas .api .FacadeProvider ;
50
55
import de .symeda .sormas .api .caze .CaseClassification ;
56
+ import de .symeda .sormas .api .caze .CaseDataDto ;
57
+ import de .symeda .sormas .api .caze .CaseOutcome ;
51
58
import de .symeda .sormas .api .event .EventParticipantSelectionDto ;
52
59
import de .symeda .sormas .api .event .EventReferenceDto ;
53
60
import de .symeda .sormas .api .externaljournal .ExternalJournalSyncResponseDto ;
54
61
import de .symeda .sormas .api .i18n .Captions ;
55
62
import de .symeda .sormas .api .i18n .I18nProperties ;
56
63
import de .symeda .sormas .api .i18n .Strings ;
57
64
import de .symeda .sormas .api .i18n .Validations ;
65
+ import de .symeda .sormas .api .person .CauseOfDeath ;
58
66
import de .symeda .sormas .api .person .PersonContext ;
59
67
import de .symeda .sormas .api .person .PersonCriteria ;
60
68
import de .symeda .sormas .api .person .PersonDto ;
61
69
import de .symeda .sormas .api .person .PersonFacade ;
62
70
import de .symeda .sormas .api .person .PersonHelper ;
63
71
import de .symeda .sormas .api .person .PersonIndexDto ;
64
72
import de .symeda .sormas .api .person .PersonReferenceDto ;
73
+ import de .symeda .sormas .api .person .PresentCondition ;
65
74
import de .symeda .sormas .api .person .SimilarPersonDto ;
66
75
import de .symeda .sormas .api .user .UserRight ;
67
76
import de .symeda .sormas .api .utils .DataHelper ;
75
84
import de .symeda .sormas .ui .utils .ButtonHelper ;
76
85
import de .symeda .sormas .ui .utils .CommitDiscardWrapperComponent ;
77
86
import de .symeda .sormas .ui .utils .ConfirmationComponent ;
87
+ import de .symeda .sormas .ui .utils .CssStyles ;
88
+ import de .symeda .sormas .ui .utils .DateFormatHelper ;
78
89
import de .symeda .sormas .ui .utils .VaadinUiUtil ;
79
90
import de .symeda .sormas .ui .utils .ViewMode ;
80
91
import de .symeda .sormas .ui .utils .components .page .title .TitleLayout ;
@@ -418,7 +429,7 @@ public CommitDiscardWrapperComponent<PersonEditForm> getPersonEditComponent(Stri
418
429
editView .addCommitListener (() -> {
419
430
if (!editForm .getFieldGroup ().isModified ()) {
420
431
PersonDto dto = editForm .getValue ();
421
- savePerson (dto );
432
+ savePersonWithPersonConditionChanged (dto );
422
433
}
423
434
});
424
435
@@ -443,7 +454,7 @@ public CommitDiscardWrapperComponent<PersonEditForm> getPersonEditComponent(
443
454
editView .addCommitListener (() -> {
444
455
if (!editForm .getFieldGroup ().isModified ()) {
445
456
PersonDto dto = editForm .getValue ();
446
- savePerson (dto );
457
+ savePersonWithPersonConditionChanged (dto );
447
458
}
448
459
});
449
460
@@ -478,16 +489,117 @@ public CommitDiscardWrapperComponent<PersonEditForm> getPersonEditComponent(
478
489
CommitDiscardWrapperComponent <PersonSelectionGrid > content =
479
490
(CommitDiscardWrapperComponent <PersonSelectionGrid >) editView .getWrappedComponent ().getWarningSimilarPersons ().getContent ();
480
491
content .getDiscardButton ().setVisible (true );
481
- content .addCommitListener (() -> savePerson (dto ));
492
+ content .addCommitListener (() -> savePersonWithPersonConditionChanged (dto ));
482
493
} else {
483
- savePerson (dto );
494
+ savePersonWithPersonConditionChanged (dto );
484
495
}
485
496
}
486
497
});
487
498
488
499
return editView ;
489
500
}
490
501
502
+ private void savePersonWithPersonConditionChanged (PersonDto editedPerson ) {
503
+
504
+ CaseDataDto lastCase ;
505
+ if (editedPerson .getCauseOfDeathDisease () != null ) {
506
+ List <CaseDataDto > personCases = FacadeProvider .getCaseFacade ()
507
+ .getAllCasesOfPerson (editedPerson .getUuid ())
508
+ .stream ()
509
+ .filter (caseDataDto -> caseDataDto .getDisease ().equals (editedPerson .getCauseOfDeathDisease ()))
510
+ .collect (Collectors .toList ());
511
+ lastCase = personCases .isEmpty () ? null : Collections .max (personCases , Comparator .comparing (CaseDataDto ::getReportDate ));
512
+ } else {
513
+ lastCase = null ;
514
+ }
515
+
516
+ PresentCondition editedPresentCondition = editedPerson .getPresentCondition ();
517
+ if (lastCase != null
518
+ && (Arrays .asList (PresentCondition .BURIED , PresentCondition .DEAD ).contains (editedPresentCondition ))
519
+ && editedPerson .getCauseOfDeath ().equals (CauseOfDeath .EPIDEMIC_DISEASE )) {
520
+
521
+ PersonDto initialPerson = FacadeProvider .getPersonFacade ().getByUuid (editedPerson .getUuid ());
522
+ PresentCondition initialPresentCondition = initialPerson .getPresentCondition ();
523
+
524
+ if (Arrays .asList (PresentCondition .BURIED , PresentCondition .DEAD ).contains (initialPresentCondition )
525
+ && lastCase .getOutcome ().equals (CaseOutcome .DECEASED )
526
+ && ((editedPerson .getDeathDate () == null && lastCase .getOutcomeDate () == null )
527
+ || (editedPerson .getDeathDate () != null && editedPerson .getDeathDate ().equals (lastCase .getOutcomeDate ())))) {
528
+
529
+ savePerson (editedPerson );
530
+ return ;
531
+ } else {
532
+ VerticalLayout warningLayout = new VerticalLayout ();
533
+ warningLayout .setSpacing (false );
534
+ CommitDiscardWrapperComponent <VerticalLayout > warningComponent = new CommitDiscardWrapperComponent <>(warningLayout );
535
+ warningComponent .setWidth (100 , Unit .PERCENTAGE );
536
+
537
+ Window popupWindow = VaadinUiUtil .showPopupWindow (warningComponent , I18nProperties .getString (Strings .warning ));
538
+ Label infoLabel = new Label (I18nProperties .getString (Strings .messageChangingPersonPresentCondition ));
539
+ CssStyles .style (infoLabel , CssStyles .LABEL_LARGE , CssStyles .LABEL_WHITE_SPACE_NORMAL );
540
+ warningLayout .addComponent (infoLabel );
541
+
542
+ // case information
543
+ warningLayout .addComponent (new Label (lastCase .buildCaption ()));
544
+
545
+ // confirmation message
546
+ Label confirmationMessage = new Label (I18nProperties .getString (Strings .messageReviewChangesAndConfirm ));
547
+ confirmationMessage .addStyleName (CssStyles .VSPACE_TOP_3 );
548
+ warningLayout .addComponent (confirmationMessage );
549
+
550
+ // changes listed
551
+ HorizontalLayout changesLayout = new HorizontalLayout ();
552
+ changesLayout .setMargin (false );
553
+ changesLayout .addStyleNames (CssStyles .VSPACE_TOP_1 , CssStyles .VSPACE_2 );
554
+
555
+ VerticalLayout fieldsLayout = new VerticalLayout ();
556
+ fieldsLayout .setMargin (false );
557
+ Label fieldsLabel = new Label (I18nProperties .getCaption (Captions .confirmChangesField ));
558
+ fieldsLayout .addComponent (fieldsLabel );
559
+ fieldsLabel .addStyleName (CssStyles .LABEL_SECONDARY );
560
+ fieldsLayout .addComponent (new Label (I18nProperties .getPrefixCaption (CaseDataDto .I18N_PREFIX , CaseDataDto .OUTCOME )));
561
+ fieldsLayout .addComponent (new Label (I18nProperties .getPrefixCaption (CaseDataDto .I18N_PREFIX , CaseDataDto .OUTCOME_DATE )));
562
+
563
+ VerticalLayout arrowsLayout = new VerticalLayout ();
564
+ arrowsLayout .setMargin (false );
565
+ arrowsLayout .addComponent (new Label ());
566
+ arrowsLayout .addComponent (new Label (VaadinIcons .ARROW_RIGHT .getHtml (), ContentMode .HTML ));
567
+ arrowsLayout .addComponent (new Label (VaadinIcons .ARROW_RIGHT .getHtml (), ContentMode .HTML ));
568
+
569
+ VerticalLayout valuesLayout = new VerticalLayout ();
570
+ valuesLayout .setMargin (false );
571
+
572
+ Label valuesLabel = new Label (I18nProperties .getCaption (Captions .confirmChangesValue ));
573
+ valuesLabel .addStyleName (CssStyles .LABEL_SECONDARY );
574
+ valuesLayout .addComponent (valuesLabel );
575
+
576
+ valuesLayout .addComponent (new Label (CaseOutcome .DECEASED .toString ()));
577
+ valuesLayout .addComponent (new Label (DateFormatHelper .formatDate (editedPerson .getDeathDate ())));
578
+
579
+ changesLayout .addComponent (fieldsLayout );
580
+ changesLayout .addComponent (arrowsLayout );
581
+ changesLayout .addComponent (valuesLayout );
582
+ warningLayout .addComponent (changesLayout );
583
+
584
+ // actions
585
+ warningComponent .addCommitListener (() -> {
586
+ savePerson (editedPerson );
587
+ popupWindow .close ();
588
+ });
589
+
590
+ warningComponent .addDiscardListener (() -> popupWindow .close ());
591
+
592
+ // popup configuration
593
+ popupWindow .addCloseListener (e -> popupWindow .close ());
594
+ popupWindow .setWidth (600 , Sizeable .Unit .PIXELS );
595
+
596
+ return ;
597
+ }
598
+ }
599
+
600
+ savePerson (editedPerson );
601
+ }
602
+
491
603
private void savePerson (PersonDto personDto ) {
492
604
DataHelper .Pair <CaseClassification , PersonDto > saveResult = personFacade .savePersonWithoutNotifyingExternalJournal (personDto );
493
605
0 commit comments