diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImplTest.java index 78390a62d..eae554874 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PatientTranslatorImplTest.java @@ -66,6 +66,8 @@ public class PatientTranslatorImplTest { private static final String PATIENT_IDENTIFIER_UUID = "654321-fedcba-654321"; + private static final String PATIENT_NAME_UUID = "1fdb5469-57c7-435f-b009-3dcceb23b0a2"; + private static final String PATIENT_GIVEN_NAME = "Jean Claude"; private static final String PATIENT_FAMILY_NAME = "van Damme"; @@ -317,6 +319,27 @@ public void shouldTranslateFhirPatientNameToOpenmrsPatientName() { assertThat(result.getFamilyName(), equalTo(PATIENT_FAMILY_NAME)); } + @Test + public void shouldTranslateFhirPatientNameToExistingOpenmrsPatientName() { + PersonName personName = new PersonName(); + personName.setUuid(PATIENT_NAME_UUID); + personName.setGivenName(PATIENT_GIVEN_NAME); + personName.setFamilyName(PATIENT_FAMILY_NAME); + when(nameTranslator.toOpenmrsType(any(), any())).thenReturn(personName); + + Patient patient = new Patient(); + HumanName name = new HumanName(); + name.setId(PATIENT_NAME_UUID); + name.addGiven(PATIENT_GIVEN_NAME); + name.setFamily(PATIENT_FAMILY_NAME); + patient.addName(name); + + org.openmrs.Patient result = patientTranslator.toOpenmrsType(patient); + assertThat(result.getGivenName(), equalTo(PATIENT_GIVEN_NAME)); + assertThat(result.getFamilyName(), equalTo(PATIENT_FAMILY_NAME)); + assertThat(result.getPersonName().getUuid(), equalTo(PATIENT_NAME_UUID)); + } + @Test public void shouldTranslateFhirPatientGenderToOpenmrsGender() { when(genderTranslator.toOpenmrsType(Enumerations.AdministrativeGender.FEMALE)).thenReturn("F");