Skip to content

Commit ac091a0

Browse files
(chore) replace the existing name instead of creating a new name
1 parent a5f1900 commit ac091a0

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import javax.annotation.Nonnull;
1717

18-
import java.util.Date;
1918
import java.util.List;
2019
import java.util.Objects;
2120
import java.util.stream.Collectors;
@@ -148,16 +147,16 @@ public org.openmrs.Patient toOpenmrsType(@Nonnull org.openmrs.Patient currentPat
148147
}
149148
}
150149

151-
for (PersonName existingName : currentPatient.getNames()) {
152-
if (!existingName.getVoided()) {
153-
existingName.setVoided(true);
154-
existingName.setVoidReason("Updated with new name");
155-
existingName.setDateVoided(new Date());
156-
}
157-
}
158-
159150
for (HumanName name : patient.getName()) {
160-
currentPatient.addName(nameTranslator.toOpenmrsType(name));
151+
PersonName existingName;
152+
if (name.hasId()) {
153+
existingName = currentPatient.getNames().stream().filter(n -> n.getUuid().equals(name.getId())).findFirst()
154+
.orElse(null);
155+
} else {
156+
existingName = currentPatient.getPersonName();
157+
}
158+
PersonName pn = nameTranslator.toOpenmrsType(existingName != null ? existingName : new PersonName(), name);
159+
currentPatient.addName(pn);
161160
}
162161

163162
if (patient.hasGender()) {

api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void shouldTranslateFhirPatientNameToOpenmrsPatientName() {
304304
PersonName personName = new PersonName();
305305
personName.setGivenName(PATIENT_GIVEN_NAME);
306306
personName.setFamilyName(PATIENT_FAMILY_NAME);
307-
when(nameTranslator.toOpenmrsType(any())).thenReturn(personName);
307+
when(nameTranslator.toOpenmrsType(any(), any())).thenReturn(personName);
308308

309309
Patient patient = new Patient();
310310
HumanName name = new HumanName();

0 commit comments

Comments
 (0)