|
44 | 44 | import de.symeda.sormas.api.caze.CaseSelectionDto; |
45 | 45 | import de.symeda.sormas.api.contact.ContactDto; |
46 | 46 | import de.symeda.sormas.api.contact.SimilarContactDto; |
| 47 | +import de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException; |
47 | 48 | import de.symeda.sormas.api.event.EventDto; |
48 | 49 | import de.symeda.sormas.api.event.EventIndexDto; |
49 | 50 | import de.symeda.sormas.api.event.EventParticipantDto; |
|
62 | 63 | import de.symeda.sormas.api.i18n.I18nProperties; |
63 | 64 | import de.symeda.sormas.api.i18n.Strings; |
64 | 65 | import de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto; |
| 66 | +import de.symeda.sormas.api.person.OccupationType; |
| 67 | +import de.symeda.sormas.api.person.PersonContactDetailDto; |
| 68 | +import de.symeda.sormas.api.person.PersonContactDetailType; |
| 69 | +import de.symeda.sormas.api.person.PersonContext; |
65 | 70 | import de.symeda.sormas.api.person.PersonDto; |
66 | 71 | import de.symeda.sormas.api.person.notifier.NotifierDto; |
67 | 72 | import de.symeda.sormas.api.sample.PathogenTestDto; |
@@ -353,8 +358,100 @@ public void cancel() { |
353 | 358 | } |
354 | 359 | }; |
355 | 360 |
|
| 361 | + HandlerCallback<CaseDataDto> postUpdatePersonCallback = new HandlerCallback<CaseDataDto>() { |
| 362 | + |
| 363 | + @Override |
| 364 | + public void done(CaseDataDto result) { |
| 365 | + // Additional person processing after case creation (needed for fields that are not visible in the person creation form) |
| 366 | + |
| 367 | + PersonDto casePerson = getExternalMessageProcessingFacade().getPersonByContext(PersonContext.CASE, result.getUuid()); |
| 368 | + |
| 369 | + if (casePerson == null) { |
| 370 | + updateNotifierCallback.done(result); |
| 371 | + return; |
| 372 | + } |
| 373 | + |
| 374 | + boolean doUpdate = false; |
| 375 | + |
| 376 | + final String nameOfGuardian = |
| 377 | + String |
| 378 | + .format( |
| 379 | + "%s %s", |
| 380 | + externalMessage.getPersonGuardianFirstName() != null ? externalMessage.getPersonGuardianFirstName() : "", |
| 381 | + externalMessage.getPersonGuardianLastName() != null ? externalMessage.getPersonGuardianLastName() : "") |
| 382 | + .trim(); |
| 383 | + |
| 384 | + if (!nameOfGuardian.isBlank()) { |
| 385 | + casePerson.setNamesOfGuardians(nameOfGuardian); |
| 386 | + // we need to set both the incapacitated and emancipated fields, otherwise the person will not be shown in the UI |
| 387 | + casePerson.setIncapacitated(true); |
| 388 | + casePerson.setEmancipated(false); |
| 389 | + doUpdate = true; |
| 390 | + } |
| 391 | + |
| 392 | + if (externalMessage.getPersonGuardianEmail() != null && !externalMessage.getPersonGuardianEmail().isBlank()) { |
| 393 | + List<PersonContactDetailDto> contactDetails = casePerson.getPersonContactDetails(); |
| 394 | + |
| 395 | + if (contactDetails.stream().noneMatch(pc -> externalMessage.getPersonGuardianEmail().equals(pc.getContactInformation()))) { |
| 396 | + final PersonContactDetailDto pcd = new PersonContactDetailDto(); |
| 397 | + pcd.setPerson(casePerson.toReference()); |
| 398 | + pcd.setPrimaryContact(false); |
| 399 | + pcd.setPersonContactDetailType(PersonContactDetailType.EMAIL); |
| 400 | + pcd.setContactInformation(externalMessage.getPersonGuardianEmail()); |
| 401 | + pcd.setThirdParty(true); |
| 402 | + pcd.setThirdPartyRole(externalMessage.getPersonGuardianRelationship()); |
| 403 | + pcd.setThirdPartyName(nameOfGuardian); |
| 404 | + |
| 405 | + contactDetails.add(pcd); |
| 406 | + doUpdate = true; |
| 407 | + } |
| 408 | + } |
| 409 | + |
| 410 | + if (externalMessage.getPersonGuardianPhone() != null && !externalMessage.getPersonGuardianPhone().isBlank()) { |
| 411 | + List<PersonContactDetailDto> contactDetails = casePerson.getPersonContactDetails(); |
| 412 | + |
| 413 | + if (contactDetails.stream().noneMatch(pc -> externalMessage.getPersonGuardianPhone().equals(pc.getContactInformation()))) { |
| 414 | + final PersonContactDetailDto pcd = new PersonContactDetailDto(); |
| 415 | + pcd.setPerson(casePerson.toReference()); |
| 416 | + pcd.setPrimaryContact(false); |
| 417 | + pcd.setPersonContactDetailType(PersonContactDetailType.PHONE); |
| 418 | + pcd.setContactInformation(externalMessage.getPersonGuardianPhone()); |
| 419 | + pcd.setThirdParty(true); |
| 420 | + pcd.setThirdPartyRole(externalMessage.getPersonGuardianRelationship()); |
| 421 | + pcd.setThirdPartyName(nameOfGuardian); |
| 422 | + |
| 423 | + contactDetails.add(pcd); |
| 424 | + doUpdate = true; |
| 425 | + } |
| 426 | + } |
| 427 | + |
| 428 | + if (externalMessage.getPersonOccupation() != null && !externalMessage.getPersonOccupation().isBlank()) { |
| 429 | + try { |
| 430 | + final OccupationType occupationTypeOther = getExternalMessageProcessingFacade().getOccupationTypeOther(); |
| 431 | + casePerson.setOccupationType(occupationTypeOther); |
| 432 | + casePerson.setOccupationDetails(externalMessage.getPersonOccupation()); |
| 433 | + doUpdate = true; |
| 434 | + } catch (CustomEnumNotFoundException e) { |
| 435 | + // do nothing if OccupationType OTHER custom enum is not found |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + if (doUpdate) { |
| 440 | + getExternalMessageProcessingFacade().updatePerson(casePerson); |
| 441 | + } |
| 442 | + // Chain to the notifier callback |
| 443 | + updateNotifierCallback.done(result); |
| 444 | + } |
| 445 | + |
| 446 | + @Override |
| 447 | + public void cancel() { |
| 448 | + // Handle cancellation of the operation |
| 449 | + updateNotifierCallback.cancel(); |
| 450 | + } |
| 451 | + }; |
| 452 | + |
356 | 453 | // Show the create case window with the provided data and callback |
357 | | - ExternalMessageProcessingUIHelper.showCreateCaseWindow(caze, person, externalMessage, getMapper(), updateNotifierCallback); |
| 454 | + ExternalMessageProcessingUIHelper.showCreateCaseWindow(caze, person, externalMessage, getMapper(), postUpdatePersonCallback); |
358 | 455 | } |
359 | 456 |
|
360 | 457 | /** |
|
0 commit comments