Skip to content

Commit

Permalink
(chore) replace the existing name instead of creating a new name
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-jofrancisco committed Jul 25, 2024
1 parent a5f1900 commit ac091a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import javax.annotation.Nonnull;

import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -148,16 +147,16 @@ public org.openmrs.Patient toOpenmrsType(@Nonnull org.openmrs.Patient currentPat
}
}

for (PersonName existingName : currentPatient.getNames()) {
if (!existingName.getVoided()) {
existingName.setVoided(true);
existingName.setVoidReason("Updated with new name");
existingName.setDateVoided(new Date());
}
}

for (HumanName name : patient.getName()) {
currentPatient.addName(nameTranslator.toOpenmrsType(name));
PersonName existingName;
if (name.hasId()) {
existingName = currentPatient.getNames().stream().filter(n -> n.getUuid().equals(name.getId())).findFirst()
.orElse(null);

Check warning on line 154 in api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImpl.java#L153-L154

Added lines #L153 - L154 were not covered by tests
} else {
existingName = currentPatient.getPersonName();
}
PersonName pn = nameTranslator.toOpenmrsType(existingName != null ? existingName : new PersonName(), name);
currentPatient.addName(pn);
}

if (patient.hasGender()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void shouldTranslateFhirPatientNameToOpenmrsPatientName() {
PersonName personName = new PersonName();
personName.setGivenName(PATIENT_GIVEN_NAME);
personName.setFamilyName(PATIENT_FAMILY_NAME);
when(nameTranslator.toOpenmrsType(any())).thenReturn(personName);
when(nameTranslator.toOpenmrsType(any(), any())).thenReturn(personName);

Patient patient = new Patient();
HumanName name = new HumanName();
Expand Down

0 comments on commit ac091a0

Please sign in to comment.