Skip to content

Commit 2d2417d

Browse files
committed
Added additional handling for multiple contact updates.
1 parent ac3b15e commit 2d2417d

File tree

3 files changed

+59
-34
lines changed

3 files changed

+59
-34
lines changed

sormas-ui/src/main/java/de/symeda/sormas/ui/externalmessage/doctordeclaration/DoctorDeclarationMessageProcessingFlow.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import de.symeda.sormas.api.i18n.I18nProperties;
6363
import de.symeda.sormas.api.i18n.Strings;
6464
import de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto;
65-
import de.symeda.sormas.api.person.PersonContext;
6665
import de.symeda.sormas.api.person.PersonDto;
6766
import de.symeda.sormas.api.person.notifier.NotifierDto;
6867
import de.symeda.sormas.api.sample.PathogenTestDto;
@@ -298,15 +297,21 @@ protected void handlePickOrCreateEntry(
298297
@Override
299298
public void done(PickOrCreateEntryResult result) {
300299
if (result.getCaze() != null) {
301-
applyPersonUpdates(PersonContext.CASE, result.getCaze().getUuid());
302300
CaseDataDto caze = FacadeProvider.getCaseFacade().getByUuid(result.getCaze().getUuid());
303-
if (caze != null) {
301+
if (caze != null && caze.getPerson() != null) {
302+
applyPersonUpdates(caze.getPerson().getUuid());
304303
applyNotifierUpdate(caze, externalMessage);
305304
}
306305
} else if (result.getContact() != null) {
307-
applyPersonUpdates(PersonContext.CONTACT, result.getContact().getUuid());
306+
ContactDto contact = FacadeProvider.getContactFacade().getByUuid(result.getContact().getUuid());
307+
if (contact != null && contact.getPerson() != null) {
308+
applyPersonUpdates(contact.getPerson().getUuid());
309+
}
308310
} else if (result.getEventParticipant() != null) {
309-
applyPersonUpdates(PersonContext.EVENT_PARTICIPANT, result.getEventParticipant().getUuid());
311+
EventParticipantDto ep = FacadeProvider.getEventParticipantFacade().getByUuid(result.getEventParticipant().getUuid());
312+
if (ep != null && ep.getPerson() != null) {
313+
applyPersonUpdates(ep.getPerson().getUuid());
314+
}
310315
}
311316

312317
callback.done(result);
@@ -318,8 +323,9 @@ public void cancel() {
318323
}
319324
};
320325

321-
ProcessingUiHelper
322-
.showPickOrCreateEntryWindow(new EntrySelectionComponentForExternalMessage(externalMessage, optionsBuilder.build()), postUpdateCallback);
326+
ProcessingUiHelper.showPickOrCreateEntryWindow(
327+
new EntrySelectionComponentForExternalMessage(externalMessage, optionsBuilder.build()),
328+
postUpdateCallback);
323329
} else {
324330
// If only one option is available, directly proceed with it
325331
callback.done(optionsBuilder.getSingleAvailableCreateResult());
@@ -346,7 +352,9 @@ protected void handleCreateCase(CaseDataDto caze, PersonDto person, ExternalMess
346352

347353
@Override
348354
public void done(CaseDataDto result) {
349-
applyPersonUpdates(PersonContext.CASE, result.getUuid());
355+
if (result.getPerson() != null) {
356+
applyPersonUpdates(result.getPerson().getUuid());
357+
}
350358
callback.done(applyNotifierUpdate(result, externalMessage));
351359
}
352360

@@ -358,17 +366,19 @@ public void cancel() {
358366
}
359367

360368
/**
361-
* Fetches the person associated with the given entity, applies all relevant external message data
369+
* Fetches the person by UUID, applies all relevant external message data
362370
* (address, contact details, guardian, occupation), then persists the person in a single save.
363371
*
364-
* @param personContext
365-
* The context used to look up the person (e.g. CASE, CONTACT).
366-
* @param entityUuid
367-
* The UUID of the owning entity.
372+
* @param personUuid
373+
* The UUID of the person to update.
368374
*/
369-
private void applyPersonUpdates(PersonContext personContext, String entityUuid) {
375+
private void applyPersonUpdates(String personUuid) {
370376

371-
PersonDto person = getExternalMessageProcessingFacade().getPersonByContext(personContext, entityUuid);
377+
if (personUuid == null) {
378+
return;
379+
}
380+
381+
final PersonDto person = FacadeProvider.getPersonFacade().getByUuid(personUuid);
372382

373383
if (person == null) {
374384
return;
@@ -444,7 +454,9 @@ protected void handleCreateContact(
444454

445455
contactCreateComponent.addCommitListener(() -> {
446456
ContactDto createdContact = contactCreateComponent.getWrappedComponent().getValue();
447-
applyPersonUpdates(PersonContext.CONTACT, createdContact.getUuid());
457+
if (createdContact.getPerson() != null) {
458+
applyPersonUpdates(createdContact.getPerson().getUuid());
459+
}
448460
callback.done(createdContact);
449461
});
450462
contactCreateComponent.addDiscardListener(callback::cancel);
@@ -586,6 +598,10 @@ protected void handleCreateEventParticipant(
586598
EventParticipantDto savedDto = FacadeProvider.getEventParticipantFacade().save(dto);
587599
Notification.show(I18nProperties.getString(Strings.messageEventParticipantCreated), Notification.Type.ASSISTIVE_NOTIFICATION);
588600

601+
if (savedDto.getPerson() != null) {
602+
applyPersonUpdates(savedDto.getPerson().getUuid());
603+
}
604+
589605
callback.done(savedDto);
590606
}
591607
});

sormas-ui/src/main/java/de/symeda/sormas/ui/externalmessage/labmessage/LabMessageProcessingFlow.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,7 @@ public void done(PickOrCreateEntryResult result) {
163163
personUuid = eventParticipant != null && eventParticipant.getPerson() != null ? eventParticipant.getPerson().getUuid() : null;
164164
}
165165

166-
final PersonDto processedPerson = FacadeProvider.getPersonFacade().getByUuid(personUuid);
167-
168-
if (processedPerson == null) {
169-
callback.done(result);
170-
return;
171-
}
172-
173-
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(processedPerson, getMapper());
166+
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(personUuid, getMapper());
174167

175168
callback.done(result);
176169
}
@@ -199,8 +192,9 @@ public void done(CaseDataDto result) {
199192
// compared to automatic processing the person is processed by the case controller
200193
// @see{CaseController#getCaseCreateComponent} methods
201194
// we need to load the person again from the database to get the updates following case form changes
202-
final PersonDto processedPerson = FacadeProvider.getPersonFacade().getByUuid(result.getPerson().getUuid());
203-
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(processedPerson, getMapper());
195+
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(
196+
result.getPerson() != null ? result.getPerson().getUuid() : null,
197+
getMapper());
204198

205199
callback.done(result);
206200
}
@@ -263,8 +257,9 @@ protected void handleCreateContact(ContactDto contact, PersonDto person, Externa
263257
// we need to load the person again from the database to get the updates following contact form changes
264258
// ofc. here we have another way to do it because whoever did it was too lazy to fix the contact controller
265259
final ContactDto processedContact = contactCreateComponent.getWrappedComponent().getValue();
266-
final PersonDto processedPerson = FacadeProvider.getPersonFacade().getByUuid(processedContact.getPerson().getUuid());
267-
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(processedPerson, getMapper());
260+
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(
261+
processedContact.getPerson() != null ? processedContact.getPerson().getUuid() : null,
262+
getMapper());
268263

269264
callback.done(processedContact);
270265
});
@@ -365,6 +360,10 @@ protected void handleCreateEventParticipant(
365360
EventParticipantDto savedDto = FacadeProvider.getEventParticipantFacade().save(dto);
366361
Notification.show(I18nProperties.getString(Strings.messageEventParticipantCreated), Notification.Type.ASSISTIVE_NOTIFICATION);
367362

363+
ExternalMessageProcessingUIHelper.updateAddressAndSavePerson(
364+
savedDto.getPerson() != null ? savedDto.getPerson().getUuid() : null,
365+
getMapper());
366+
368367
callback.done(savedDto);
369368
}
370369
});

sormas-ui/src/main/java/de/symeda/sormas/ui/externalmessage/processing/ExternalMessageProcessingUIHelper.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,26 @@ public static void showCreateCaseWindow(
161161
}
162162

163163
/**
164-
* Merges person address and contact details from the external message mapper and saves the person.
165-
* This should be called after a case or contact is created, because the case/contact controller
166-
* processes the person data independently and we need to ensure the external message data is applied.
164+
* Loads the person by UUID, merges address and contact details from the external message mapper, and saves the person.
165+
* This should be called after a case, contact or event participant is created, because the respective controllers
166+
* process the person data independently and we need to ensure the external message data is applied.
167+
* Does nothing if {@code personUuid} is {@code null} or no person with that UUID exists.
167168
*
168-
* @param person
169-
* the person to update (should be freshly loaded from the database)
169+
* @param personUuid
170+
* the UUID of the person to update
170171
* @param mapper
171172
* the external message mapper providing the address/contact data
172173
*/
173-
public static void updateAddressAndSavePerson(PersonDto person, ExternalMessageMapper mapper) {
174+
public static void updateAddressAndSavePerson(String personUuid, ExternalMessageMapper mapper) {
175+
if (personUuid == null) {
176+
return;
177+
}
178+
179+
final PersonDto person = FacadeProvider.getPersonFacade().getByUuid(personUuid);
180+
if (person == null) {
181+
return;
182+
}
183+
174184
mapper.mergePersonAddress(person);
175185
mapper.mergePersonContactDetails(person);
176186
// finally it is safe to save even if no changes were actually made

0 commit comments

Comments
 (0)