Skip to content

Commit e36af45

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

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public class PatientTranslatorImplTest {
6666

6767
private static final String PATIENT_IDENTIFIER_UUID = "654321-fedcba-654321";
6868

69+
private static final String PATIENT_NAME_UUID = "1fdb5469-57c7-435f-b009-3dcceb23b0a2";
70+
6971
private static final String PATIENT_GIVEN_NAME = "Jean Claude";
7072

7173
private static final String PATIENT_FAMILY_NAME = "van Damme";
@@ -317,6 +319,27 @@ public void shouldTranslateFhirPatientNameToOpenmrsPatientName() {
317319
assertThat(result.getFamilyName(), equalTo(PATIENT_FAMILY_NAME));
318320
}
319321

322+
@Test
323+
public void shouldTranslateFhirPatientNameToExistingOpenmrsPatientName() {
324+
PersonName personName = new PersonName();
325+
personName.setUuid(PATIENT_NAME_UUID);
326+
personName.setGivenName(PATIENT_GIVEN_NAME);
327+
personName.setFamilyName(PATIENT_FAMILY_NAME);
328+
when(nameTranslator.toOpenmrsType(any(), any())).thenReturn(personName);
329+
330+
Patient patient = new Patient();
331+
HumanName name = new HumanName();
332+
name.setId(PATIENT_NAME_UUID);
333+
name.addGiven(PATIENT_GIVEN_NAME);
334+
name.setFamily(PATIENT_FAMILY_NAME);
335+
patient.addName(name);
336+
337+
org.openmrs.Patient result = patientTranslator.toOpenmrsType(patient);
338+
assertThat(result.getGivenName(), equalTo(PATIENT_GIVEN_NAME));
339+
assertThat(result.getFamilyName(), equalTo(PATIENT_FAMILY_NAME));
340+
assertThat(result.getPersonName().getUuid(), equalTo(PATIENT_NAME_UUID));
341+
}
342+
320343
@Test
321344
public void shouldTranslateFhirPatientGenderToOpenmrsGender() {
322345
when(genderTranslator.toOpenmrsType(Enumerations.AdministrativeGender.FEMALE)).thenReturn("F");

0 commit comments

Comments
 (0)