Skip to content

Commit 8fac782

Browse files
Merge pull request #13872 from SORMAS-Foundation/bugfix-13625-add_handling_person_multiple_contact_info
Bugfix 13625 add handling person multiple contact info
2 parents e7a0d70 + 2d2417d commit 8fac782

File tree

14 files changed

+1558
-278
lines changed

14 files changed

+1558
-278
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public class ExternalMessageDto extends SormasToSormasShareableDto {
109109
public static final String DIAGNOSTIC_DATE = "diagnosticDate";
110110
public static final String ACTIVITIES_AS_CASE = "activitiesAsCase";
111111
public static final String EXPOSURES = "exposures";
112+
public static final String ADDITIONAL_PERSON_CONTACT_DETAILS = "additionalPersonContactDetails";
113+
public static final String ADDITIONAL_PERSON_ADDRESSES = "additionalPersonAddresses";
112114
public static final String RADIOGRAPHY_COMPATIBILITY = "radiographyCompatibility";
113115
public static final String OTHER_DIAGNOSTIC_CRITERIA = "otherDiagnosticCriteria";
114116
public static final String TUBERCULOSIS = "tuberculosis";
@@ -246,6 +248,8 @@ public class ExternalMessageDto extends SormasToSormasShareableDto {
246248

247249
private String activitiesAsCase;
248250
private String exposures;
251+
private String additionalPersonContactDetails;
252+
private String additionalPersonAddresses;
249253

250254
private RadiographyCompatibility radiographyCompatibility;
251255
@Size(max = FieldConstraints.CHARACTER_LIMIT_DEFAULT, message = Validations.textTooLong)
@@ -836,6 +840,22 @@ public void setActivitiesAsCase(String activitiesAsCase) {
836840
this.activitiesAsCase = activitiesAsCase;
837841
}
838842

843+
public String getAdditionalPersonContactDetails() {
844+
return additionalPersonContactDetails;
845+
}
846+
847+
public void setAdditionalPersonContactDetails(String additionalPersonContactDetails) {
848+
this.additionalPersonContactDetails = additionalPersonContactDetails;
849+
}
850+
851+
public String getAdditionalPersonAddresses() {
852+
return additionalPersonAddresses;
853+
}
854+
855+
public void setAdditionalPersonAddresses(String additionalPersonAddresses) {
856+
this.additionalPersonAddresses = additionalPersonAddresses;
857+
}
858+
839859
public String getExposures() {
840860
return exposures;
841861
}

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

Lines changed: 17 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,11 @@
4646
import de.symeda.sormas.api.externalmessage.processing.labmessage.LabMessageProcessingHelper;
4747
import de.symeda.sormas.api.externalmessage.processing.labmessage.SampleAndPathogenTests;
4848
import de.symeda.sormas.api.feature.FeatureType;
49-
import de.symeda.sormas.api.infrastructure.country.CountryReferenceDto;
5049
import de.symeda.sormas.api.infrastructure.facility.FacilityDto;
5150
import de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto;
5251
import de.symeda.sormas.api.infrastructure.facility.FacilityType;
53-
import de.symeda.sormas.api.location.LocationDto;
54-
import de.symeda.sormas.api.person.PersonContactDetailDto;
55-
import de.symeda.sormas.api.person.PersonContactDetailType;
5652
import de.symeda.sormas.api.person.PersonDto;
5753
import de.symeda.sormas.api.person.PersonReferenceDto;
58-
import de.symeda.sormas.api.person.PhoneNumberType;
5954
import de.symeda.sormas.api.sample.PathogenTestDto;
6055
import de.symeda.sormas.api.sample.SampleCriteria;
6156
import de.symeda.sormas.api.sample.SampleDto;
@@ -1051,12 +1046,18 @@ protected abstract void markExternalMessageAsProcessed(
10511046
ProcessingResult<ExternalMessageProcessingResult> result,
10521047
SurveillanceReportDto surveillanceReport);
10531048

1054-
protected void doPersonUpdates(EntitySelection<PersonDto> personSelection) {
1055-
// requested for #13589
1056-
// TODO: we need to find a better way to handle this
1049+
@Override
1050+
protected CompletionStage<ProcessingResult<ExternalMessageProcessingResult>> pickOrCreatePerson(ExternalMessageProcessingResult previousResult) {
1051+
return super.pickOrCreatePerson(previousResult).thenCompose(result -> {
1052+
if (!result.getStatus().isCanceled() && result.getData() != null) {
1053+
mergePerson(result.getData().getSelectedPerson());
1054+
}
1055+
return result.asCompletedFuture();
1056+
});
1057+
}
10571058

1058-
if (personSelection.isNew()) {
1059-
// no updates for new persons
1059+
protected void mergePerson(EntitySelection<PersonDto> personSelection) {
1060+
if (personSelection == null) {
10601061
return;
10611062
}
10621063

@@ -1065,124 +1066,14 @@ protected void doPersonUpdates(EntitySelection<PersonDto> personSelection) {
10651066
return;
10661067
}
10671068

1068-
boolean doUpdate = false;
1069-
1070-
final LocationDto personAddress = person.getAddress();
1071-
1072-
if (personAddress != null) {
1073-
final String houseNumber = getExternalMessage().getPersonHouseNumber();
1074-
if (houseNumber != null) {
1075-
personAddress.setHouseNumber(houseNumber);
1076-
}
1077-
final String street = getExternalMessage().getPersonStreet();
1078-
if (street != null) {
1079-
personAddress.setStreet(street);
1080-
}
1081-
final String city = getExternalMessage().getPersonCity();
1082-
if (city != null) {
1083-
personAddress.setCity(city);
1084-
}
1085-
final String postalCode = getExternalMessage().getPersonPostalCode();
1086-
if (postalCode != null) {
1087-
personAddress.setPostalCode(postalCode);
1088-
}
1089-
final CountryReferenceDto country = getExternalMessage().getPersonCountry();
1090-
if (country != null) {
1091-
personAddress.setCountry(country);
1092-
}
1093-
1094-
doUpdate = true;
1095-
}
1096-
1097-
final List<PersonContactDetailDto> personContactDetails = person.getPersonContactDetails();
1098-
1099-
final String phoneNumber = getExternalMessage().getPersonPhone();
1100-
final PhoneNumberType phoneNumberType = getExternalMessage().getPersonPhoneNumberType();
1101-
1102-
if (phoneNumber != null && !phoneNumber.isBlank()) {
1103-
final PersonContactDetailDto primaryPhone = personContactDetails.stream()
1104-
.filter(pdc -> pdc.getPersonContactDetailType() == PersonContactDetailType.PHONE && !pdc.isThirdParty() && pdc.isPrimaryContact())
1105-
.findFirst()
1106-
.orElse(null);
1107-
1108-
final PersonContactDetailDto existingPhone = personContactDetails.stream()
1109-
.filter(pdc -> pdc.getPersonContactDetailType() == PersonContactDetailType.PHONE && !pdc.isThirdParty() && phoneNumber.equals(pdc.getContactInformation()))
1110-
.findFirst()
1111-
.orElse(null);
1112-
1113-
if(existingPhone != null) {
1114-
// if we have a existing phone number maybe it is not the new one
1115-
// make the primary phone not primary anymore and set the primary on the existing one
1116-
// coincidentally the existing one may be the primary one so set it to false first just in case
1117-
if(primaryPhone != null) {
1118-
primaryPhone.setPrimaryContact(false);
1119-
}
1120-
existingPhone.setPrimaryContact(true);
1121-
} else {
1122-
// we do not have the new phone number in the list so we need to create a new one
1123-
final PersonContactDetailDto personContactDetail = new PersonContactDetailDto();
1124-
personContactDetail.setPerson(person.toReference());
1125-
personContactDetail.setPrimaryContact(true);
1126-
personContactDetail.setPersonContactDetailType(PersonContactDetailType.PHONE);
1127-
personContactDetail.setPrimaryContact(true);
1128-
personContactDetail.setPhoneNumberType(phoneNumberType);
1129-
personContactDetail.setContactInformation(phoneNumber);
1130-
personContactDetail.setThirdParty(false);
1131-
personContactDetails.add(personContactDetail);
1132-
1133-
// we need to set the old primary to false
1134-
if(primaryPhone != null) {
1135-
primaryPhone.setPrimaryContact(false);
1136-
}
1137-
}
1138-
1139-
doUpdate = true;
1140-
}
1141-
1142-
final String emailAddress = getExternalMessage().getPersonEmail();
1143-
1144-
if (emailAddress != null && !emailAddress.isBlank()) {
1145-
final PersonContactDetailDto primaryEmail = personContactDetails.stream()
1146-
.filter(pdc -> pdc.getPersonContactDetailType() == PersonContactDetailType.EMAIL && !pdc.isThirdParty() && pdc.isPrimaryContact())
1147-
.findFirst()
1148-
.orElse(null);
1149-
1150-
final PersonContactDetailDto existingEmail = personContactDetails.stream()
1151-
.filter(pdc -> pdc.getPersonContactDetailType() == PersonContactDetailType.EMAIL && !pdc.isThirdParty() && emailAddress.equals(pdc.getContactInformation()))
1152-
.findFirst()
1153-
.orElse(null);
1154-
1155-
if(existingEmail != null) {
1156-
// if we have a existing email address maybe it is not the new one
1157-
// make the primary email not primary anymore and set the primary on the existing one
1158-
// coincidentally the existing one may be the primary one so set it to false first just in case
1159-
if(primaryEmail != null) {
1160-
primaryEmail.setPrimaryContact(false);
1161-
}
1162-
existingEmail.setPrimaryContact(true);
1163-
} else {
1164-
// we do not have the new email address in the list so we need to create a new one
1165-
final PersonContactDetailDto personContactDetail = new PersonContactDetailDto();
1166-
personContactDetail.setPerson(person.toReference());
1167-
personContactDetail.setPrimaryContact(true);
1168-
personContactDetail.setPersonContactDetailType(PersonContactDetailType.EMAIL);
1169-
personContactDetail.setPrimaryContact(true);
1170-
personContactDetail.setContactInformation(emailAddress);
1171-
personContactDetail.setThirdParty(false);
1172-
personContactDetails.add(personContactDetail);
1173-
1174-
// we need to set the old primary to false
1175-
if(primaryEmail != null) {
1176-
primaryEmail.setPrimaryContact(false);
1177-
}
1178-
}
1179-
1180-
doUpdate = true;
1069+
if (personSelection.isNew()) {
1070+
// no merges for new person
1071+
// additional contacts will be handled by {@link AbstractProcessingFlow#buildPerson()}
1072+
return;
11811073
}
11821074

1183-
if (doUpdate) {
1184-
getExternalMessageProcessingFacade().updatePerson(person);
1185-
}
1075+
getMapper().mergePersonAddress(person);
1076+
getMapper().mergePersonContactDetails(person);
11861077
}
11871078

11881079
/**

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ protected CompletionStage<ProcessingResult<ExternalMessageProcessingResult>> pic
151151

152152
return mapHandlerResult(callback, previousResult, personSelection -> {
153153
logger.debug("[MESSAGE PROCESSING] Continue processing with person: {}", personSelection);
154-
155-
// requested for #13589
156-
doPersonUpdates(personSelection);
157-
158154
return previousResult.withPerson(personSelection.getEntity(), personSelection.isNew());
159155
});
160156
}
@@ -175,14 +171,14 @@ protected <T> CompletionStage<ProcessingResult<ExternalMessageProcessingResult>>
175171

176172
protected abstract void handlePickOrCreatePerson(PersonDto person, HandlerCallback<EntitySelection<PersonDto>> callback);
177173

178-
protected abstract void doPersonUpdates(EntitySelection<PersonDto> personSelection);
179-
180174
private PersonDto buildPerson() {
181175

182176
final PersonDto personDto = PersonDto.build();
183177

184178
mapper.mapToPerson(personDto);
185179
mapper.mapToLocation(personDto.getAddress());
180+
mapper.mapAdditionalPersonContactDetails(personDto);
181+
mapper.mapAdditionalPersonAddresses(personDto);
186182

187183
return personDto;
188184
}

0 commit comments

Comments
 (0)