|
18 | 18 | import java.util.ArrayList; |
19 | 19 | import java.util.Date; |
20 | 20 | import java.util.List; |
| 21 | +import java.util.Objects; |
21 | 22 | import java.util.concurrent.CompletionStage; |
22 | 23 | import java.util.function.BiFunction; |
23 | 24 | import java.util.function.Consumer; |
|
55 | 56 | import de.symeda.sormas.api.infrastructure.facility.FacilityType; |
56 | 57 | import de.symeda.sormas.api.person.PersonDto; |
57 | 58 | import de.symeda.sormas.api.sample.SampleSimilarityCriteria; |
| 59 | +import de.symeda.sormas.api.symptoms.SymptomsComparisonHelper; |
58 | 60 | import de.symeda.sormas.api.symptoms.SymptomsDto; |
59 | 61 | import de.symeda.sormas.api.user.UserDto; |
60 | 62 | import de.symeda.sormas.api.utils.DataHelper; |
@@ -285,6 +287,110 @@ protected void postBuildCaseSymptoms(CaseDataDto caseDto, ExternalMessageDto ext |
285 | 287 | } |
286 | 288 | } |
287 | 289 |
|
| 290 | + @Override |
| 291 | + protected boolean hasCaseSymptomsMismatch(CaseDataDto caze, ExternalMessageDto externalMessage) { |
| 292 | + boolean symptomsMismatch = SymptomsComparisonHelper.hasCaseSymptomsMismatch(caze.getSymptoms(), externalMessage.getCaseSymptoms()); |
| 293 | + |
| 294 | + if (symptomsMismatch) { |
| 295 | + logger.debug("[MESSAGE PROCESSING] Symptoms mismatch detected for existing case with UUID: {}", caze.getUuid()); |
| 296 | + } |
| 297 | + |
| 298 | + return symptomsMismatch; |
| 299 | + } |
| 300 | + |
| 301 | + @Override |
| 302 | + protected boolean hasCaseHospitalizationMismatch(CaseDataDto caze, ExternalMessageDto externalMessage) { |
| 303 | + // Check if there is hospitalization data in the external message |
| 304 | + if (externalMessage.getHospitalizationAdmissionDate() == null |
| 305 | + && externalMessage.getHospitalizationDischargeDate() == null |
| 306 | + && externalMessage.getAdmittedToHealthFacility() == null |
| 307 | + && externalMessage.getHospitalizationFacilityName() == null |
| 308 | + && externalMessage.getHospitalizationFacilityExternalId() == null) { |
| 309 | + return false; |
| 310 | + } |
| 311 | + |
| 312 | + // Compare with existing hospitalization data |
| 313 | + HospitalizationDto existingHospitalization = caze.getHospitalization(); |
| 314 | + if (existingHospitalization == null) { |
| 315 | + // If there's external hospitalization data but no existing hospitalization, it's a mismatch |
| 316 | + return true; |
| 317 | + } |
| 318 | + |
| 319 | + // Check for differences in key hospitalization fields |
| 320 | + boolean admissionDateMismatch = |
| 321 | + !Objects.equals(existingHospitalization.getAdmissionDate(), externalMessage.getHospitalizationAdmissionDate()); |
| 322 | + boolean dischargeDateMismatch = |
| 323 | + !Objects.equals(existingHospitalization.getDischargeDate(), externalMessage.getHospitalizationDischargeDate()); |
| 324 | + boolean admittedMismatch = |
| 325 | + !Objects.equals(existingHospitalization.getAdmittedToHealthFacility(), externalMessage.getAdmittedToHealthFacility()); |
| 326 | + |
| 327 | + boolean hospitalizationFacilityNameMismatch = |
| 328 | + !Objects.equals( |
| 329 | + caze.getHealthFacility() != null ? caze.getHealthFacility().getCaption() : null, |
| 330 | + externalMessage.getHospitalizationFacilityName()); |
| 331 | + boolean hospitalizationFacilityExternalIdMismatch = |
| 332 | + !Objects.equals( |
| 333 | + caze.getHealthFacility() != null ? caze.getHealthFacility().getExternalId() : null, |
| 334 | + externalMessage.getHospitalizationFacilityExternalId()); |
| 335 | + |
| 336 | + boolean mismatch = admissionDateMismatch || dischargeDateMismatch || admittedMismatch |
| 337 | + || hospitalizationFacilityNameMismatch || hospitalizationFacilityExternalIdMismatch; |
| 338 | + |
| 339 | + if (mismatch) { |
| 340 | + logger.debug("[MESSAGE PROCESSING] Hospitalization mismatch detected for existing case with UUID: {}", caze.getUuid()); |
| 341 | + } |
| 342 | + |
| 343 | + return mismatch; |
| 344 | + } |
| 345 | + |
| 346 | + @Override |
| 347 | + protected boolean hasCaseExposuresMismatch(CaseDataDto caze, ExternalMessageDto externalMessage) { |
| 348 | + // Check if there are exposures in the external message |
| 349 | + if (externalMessage.getExposures() == null || externalMessage.getExposures().isEmpty()) { |
| 350 | + return false; |
| 351 | + } |
| 352 | + |
| 353 | + // Check if the case already has exposures |
| 354 | + EpiDataDto epiData = caze.getEpiData(); |
| 355 | + if (epiData == null || epiData.getExposures() == null || epiData.getExposures().isEmpty()) { |
| 356 | + // If there are external exposures but no existing exposures, it's a mismatch |
| 357 | + return true; |
| 358 | + } |
| 359 | + |
| 360 | + // If both have exposures, consider it a mismatch (user should be informed to review) |
| 361 | + boolean mismatch = true; |
| 362 | + |
| 363 | + if (mismatch) { |
| 364 | + logger.debug("[MESSAGE PROCESSING] Exposures mismatch detected for existing case with UUID: {}", caze.getUuid()); |
| 365 | + } |
| 366 | + |
| 367 | + return mismatch; |
| 368 | + } |
| 369 | + |
| 370 | + @Override |
| 371 | + protected boolean hasCaseActivitiesAsCaseMismatch(CaseDataDto caze, ExternalMessageDto externalMessage) { |
| 372 | + // Check if there are activities as case in the external message |
| 373 | + if (externalMessage.getActivitiesAsCase() == null || externalMessage.getActivitiesAsCase().isEmpty()) { |
| 374 | + return false; |
| 375 | + } |
| 376 | + |
| 377 | + // Check if the case already has activities as case |
| 378 | + EpiDataDto epiData = caze.getEpiData(); |
| 379 | + if (epiData == null || epiData.getActivitiesAsCase() == null || epiData.getActivitiesAsCase().isEmpty()) { |
| 380 | + // If there are external activities but no existing activities, it's a mismatch |
| 381 | + return true; |
| 382 | + } |
| 383 | + |
| 384 | + // If both have activities, consider it a mismatch (user should be informed to review) |
| 385 | + boolean mismatch = true; |
| 386 | + |
| 387 | + if (mismatch) { |
| 388 | + logger.debug("[MESSAGE PROCESSING] Activities as case mismatch detected for existing case with UUID: {}", caze.getUuid()); |
| 389 | + } |
| 390 | + |
| 391 | + return mismatch; |
| 392 | + } |
| 393 | + |
288 | 394 | /** |
289 | 395 | * Sets the activities as case for the case from the external message, if present. |
290 | 396 | * <p> |
|
0 commit comments