Skip to content

Commit e992b39

Browse files
authored
Merge pull request #13792 from SORMAS-Foundation/bugfix-13717-external_message_missing_person_fields
#13717 - Added additional missing fields for person
2 parents 9396e70 + 5e013f4 commit e992b39

7 files changed

Lines changed: 139 additions & 5 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/externalmessage/ExternalMessageDto.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class ExternalMessageDto extends SormasToSormasShareableDto {
8888
public static final String PERSON_GUARDIAN_RELATIONSHIP = "personGuardianRelationship";
8989
public static final String PERSON_GUARDIAN_PHONE = "personGuardianPhone";
9090
public static final String PERSON_GUARDIAN_EMAIL = "personGuardianEmail";
91+
public static final String PERSON_OCCUPATION = "personOccupation";
9192
public static final String EXTERNAL_MESSAGE_DETAILS = "externalMessageDetails";
9293
public static final String PROCESSED = "processed";
9394
public static final String REPORT_ID = "reportId";
@@ -181,6 +182,8 @@ public class ExternalMessageDto extends SormasToSormasShareableDto {
181182
private String personGuardianPhone;
182183
@Size(max = FieldConstraints.CHARACTER_LIMIT_SMALL, message = Validations.textTooLong)
183184
private String personGuardianEmail;
185+
@Size(max = FieldConstraints.CHARACTER_LIMIT_DEFAULT, message = Validations.textTooLong)
186+
private String personOccupation;
184187
private YesNoUnknown treatmentStarted;
185188
private Boolean treatmentNotApplicable;
186189
private Date treatmentStartedDate;
@@ -539,6 +542,14 @@ public void setPersonGuardianEmail(String personGuardianEmail) {
539542
this.personGuardianEmail = personGuardianEmail;
540543
}
541544

545+
public String getPersonOccupation() {
546+
return personOccupation;
547+
}
548+
549+
public void setPersonOccupation(String personOccupation) {
550+
this.personOccupation = personOccupation;
551+
}
552+
542553
public String getExternalMessageDetails() {
543554
return externalMessageDetails;
544555
}

sormas-api/src/main/java/de/symeda/sormas/api/externalmessage/processing/ExternalMessageProcessingFacade.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto;
5454
import de.symeda.sormas.api.infrastructure.facility.FacilityType;
5555
import de.symeda.sormas.api.infrastructure.region.RegionFacade;
56+
import de.symeda.sormas.api.person.OccupationType;
5657
import de.symeda.sormas.api.person.PersonContext;
5758
import de.symeda.sormas.api.person.PersonDto;
5859
import de.symeda.sormas.api.person.PersonFacade;
@@ -241,6 +242,10 @@ public PersonDto getPersonByContext(PersonContext personContext, String personUu
241242
return personFacade.getByContext(personContext, personUuid);
242243
}
243244

245+
public OccupationType getOccupationTypeOther() throws CustomEnumNotFoundException {
246+
return customizableEnumFacade.getEnumValue(CustomizableEnumType.OCCUPATION_TYPE, "OTHER", null);
247+
}
248+
244249
public CaseDataDto updateAndSetCaseNotifier(String caseUuid, NotifierDto notifierDto) {
245250

246251
final CaseDataDto caseDto = caseFacade.getByUuid(caseUuid);
@@ -252,10 +257,10 @@ public CaseDataDto updateAndSetCaseNotifier(String caseUuid, NotifierDto notifie
252257
}
253258

254259
public void updatePerson(PersonDto personDto) {
255-
if(personFacade == null) {
260+
if (personFacade == null) {
256261
return;
257262
}
258-
if(personDto == null) {
263+
if (personDto == null) {
259264
return;
260265
}
261266

sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/ExternalMessage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class ExternalMessage extends AbstractDomainObject {
108108
public static final String PERSON_GUARDIAN_RELATIONSHIP = "personGuardianRelationship";
109109
public static final String PERSON_GUARDIAN_PHONE = "personGuardianPhone";
110110
public static final String PERSON_GUARDIAN_EMAIL = "personGuardianEmail";
111+
public static final String PERSON_OCCUPATION = "personOccupation";
111112
public static final String EXTERNAL_MESSAGE_DETAILS = "externalMessageDetails";
112113
public static final String STATUS = "status";
113114
public static final String REPORT_ID = "reportId";
@@ -171,6 +172,7 @@ public class ExternalMessage extends AbstractDomainObject {
171172
private String personGuardianRelationship;
172173
private String personGuardianPhone;
173174
private String personGuardianEmail;
175+
private String personOccupation;
174176
private YesNoUnknown treatmentStarted;
175177
private Boolean treatmentNotApplicable;
176178
private Date treatmentStartedDate;
@@ -552,6 +554,15 @@ public void setPersonGuardianEmail(String personGuardianEmail) {
552554
this.personGuardianEmail = personGuardianEmail;
553555
}
554556

557+
@Column(length = CHARACTER_LIMIT_DEFAULT)
558+
public String getPersonOccupation() {
559+
return personOccupation;
560+
}
561+
562+
public void setPersonOccupation(String personOccupation) {
563+
this.personOccupation = personOccupation;
564+
}
565+
555566
@Column
556567
public String getExternalMessageDetails() {
557568
return externalMessageDetails;

sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/ExternalMessageFacadeEjb.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ ExternalMessage fillOrBuildEntity(@NotNull ExternalMessageDto source, ExternalMe
202202
target.setPersonGuardianRelationship(source.getPersonGuardianRelationship());
203203
target.setPersonGuardianPhone(source.getPersonGuardianPhone());
204204
target.setPersonGuardianEmail(source.getPersonGuardianEmail());
205+
target.setPersonOccupation(source.getPersonOccupation());
205206

206207
target.setNotifierFirstName(source.getNotifierFirstName());
207208
target.setNotifierLastName(source.getNotifierLastName());
@@ -425,6 +426,7 @@ public ExternalMessageDto toDto(ExternalMessage source) {
425426
target.setPersonGuardianRelationship(source.getPersonGuardianRelationship());
426427
target.setPersonGuardianPhone(source.getPersonGuardianPhone());
427428
target.setPersonGuardianEmail(source.getPersonGuardianEmail());
429+
target.setPersonOccupation(source.getPersonOccupation());
428430

429431
target.setNotifierFirstName(source.getNotifierFirstName());
430432
target.setNotifierLastName(source.getNotifierLastName());

sormas-backend/src/main/java/de/symeda/sormas/backend/infrastructure/country/CountryFacadeEjb.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
import de.symeda.sormas.backend.util.RightsAllowed;
7070

7171
@Stateless(name = "CountryFacade")
72-
@RightsAllowed(UserRight._INFRASTRUCTURE_VIEW)
72+
@RightsAllowed({
73+
UserRight._INFRASTRUCTURE_VIEW,
74+
UserRight._SYSTEM })
7375
public class CountryFacadeEjb
7476
extends AbstractInfrastructureFacadeEjb<Country, CountryDto, CountryIndexDto, CountryReferenceDto, CountryService, CountryCriteria>
7577
implements CountryFacade {

sormas-backend/src/main/resources/sql/sormas_schema.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14127,7 +14127,7 @@ INSERT INTO systemconfigurationvalue(config_key, config_value, category_id, valu
1412714127
uuid)
1412814128
VALUES ('EMAIL_SENDER_ADDRESS', 'noreply@sormas.org', email_configuration_id, true,
1412914129
'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$', false, null,
14130-
'i18n/systemConfigurationValueValidationNotAEmail', now(), now(), nextval('entity_seq'),
14130+
'i18n/systemConfigurationValueInvalidValue', now(), now(), nextval('entity_seq'),
1413114131
generate_base32_uuid());
1413214132

1413314133
DELETE
@@ -15146,4 +15146,10 @@ ALTER TABLE therapy_history DROP COLUMN treatmentstartdate;
1514615146

1514715147
INSERT INTO schema_version (version_number, comment) VALUES (604, 'Move treatment fields from therapy to cases');
1514815148

15149+
-- external message person additional fields
15150+
ALTER TABLE externalmessage ADD COLUMN personoccupation character varying(255);
15151+
ALTER TABLE externalmessage_history ADD COLUMN personoccupation character varying(255);
15152+
15153+
INSERT INTO schema_version (version_number, comment) VALUES (605, 'External message person additional fields');
15154+
1514915155
-- *** Insert new sql commands BEFORE this line. Remember to always consider _history tables. ***

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

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import de.symeda.sormas.api.caze.CaseSelectionDto;
4545
import de.symeda.sormas.api.contact.ContactDto;
4646
import de.symeda.sormas.api.contact.SimilarContactDto;
47+
import de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException;
4748
import de.symeda.sormas.api.event.EventDto;
4849
import de.symeda.sormas.api.event.EventIndexDto;
4950
import de.symeda.sormas.api.event.EventParticipantDto;
@@ -62,6 +63,10 @@
6263
import de.symeda.sormas.api.i18n.I18nProperties;
6364
import de.symeda.sormas.api.i18n.Strings;
6465
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;
6570
import de.symeda.sormas.api.person.PersonDto;
6671
import de.symeda.sormas.api.person.notifier.NotifierDto;
6772
import de.symeda.sormas.api.sample.PathogenTestDto;
@@ -353,8 +358,100 @@ public void cancel() {
353358
}
354359
};
355360

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+
356453
// 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);
358455
}
359456

360457
/**

0 commit comments

Comments
 (0)