@@ -2204,15 +2204,23 @@ public void onCaseChanged(CaseDataDto existingCase, Case newCase, boolean syncSh
22042204 }
22052205 }
22062206
2207- if (Objects .nonNull (existingCase )) {
2208- // Contact with the source case known with the confirmed status. Github#13507 fix
2209- boolean isConfirmedCaseExists = contactService .getAllByResultingCase (caseService .getByUuid (existingCase .getUuid ())).stream ().anyMatch (e -> CaseClassification .CONFIRMED == e .getCaze ().getCaseClassification ());
2210- // If contact with source case is known by epidemiolist, && its classified as confirmed, then set epidemiological confirmation to YES
2211- // Otherwise set to No
2212- if ((YesNoUnknown .YES == newCase .getEpiData ().getContactWithSourceCaseKnown () && isConfirmedCaseExists )) {
2213- newCase .setEpidemiologicalConfirmation (YesNoUnknown .YES );
2214- } else {
2207+ if (existingCase != null && newCase .getEpiData () != null ) {
2208+ // If contact with source case is known and at least one source case (same disease) is confirmed, set YES.
2209+ final YesNoUnknown contactKnown = newCase .getEpiData ().getContactWithSourceCaseKnown ();
2210+ if (contactKnown == YesNoUnknown .YES ) {
2211+ // Check if at least one source case is confirmed
2212+ // We only check for contacts that have this case as resulting case
2213+ final boolean hasConfirmedSourceCase = contactService .getAllByResultingCase (caseService .getByUuid (existingCase .getUuid ())).stream ()
2214+ .map (Contact ::getCaze )
2215+ .filter (Objects ::nonNull )
2216+ .anyMatch (src ->
2217+ src .getDisease () == newCase .getDisease ()
2218+ && CaseClassification .getConfirmedClassifications ().contains (src .getCaseClassification ()));
2219+ newCase .setEpidemiologicalConfirmation (hasConfirmedSourceCase ? YesNoUnknown .YES : YesNoUnknown .NO );
2220+ } else if (contactKnown == YesNoUnknown .NO ) {
22152221 newCase .setEpidemiologicalConfirmation (YesNoUnknown .NO );
2222+ } else {
2223+ newCase .setEpidemiologicalConfirmation (YesNoUnknown .UNKNOWN );
22162224 }
22172225 }
22182226
0 commit comments