use of org.hl7.fhir.r5.model.HumanName in project openmrs-module-fhir2 by openmrs.
the class PersonNameTranslatorImplTest method shouldConvertFirstGivenNameToGivenName.
@Test
public void shouldConvertFirstGivenNameToGivenName() {
HumanName name = new HumanName();
name.addGiven(PERSON_GIVEN_NAME);
assertThat(personNameTranslator.toOpenmrsType(name).getGivenName(), equalTo(PERSON_GIVEN_NAME));
}
use of org.hl7.fhir.r5.model.HumanName in project openmrs-module-fhir2 by openmrs.
the class PersonTranslatorImplTest method shouldTranslateOpenmrsPersonNameToFhirPersonName.
@Test
public void shouldTranslateOpenmrsPersonNameToFhirPersonName() {
HumanName humanName = new HumanName();
humanName.addGiven(PERSON_GIVEN_NAME);
humanName.setFamily(PERSON_FAMILY_NAME);
when(nameTranslator.toFhirResource(argThat(allOf(hasProperty("givenName", equalTo(PERSON_GIVEN_NAME)), hasProperty("familyName", equalTo(PERSON_FAMILY_NAME)))))).thenReturn(humanName);
Person person = new Person();
PersonName name = new PersonName();
name.setGivenName(PERSON_GIVEN_NAME);
name.setFamilyName(PERSON_FAMILY_NAME);
person.addName(name);
org.hl7.fhir.r4.model.Person result = personTranslator.toFhirResource(person);
assertThat(result.getName(), not(empty()));
assertThat(result.getName().get(0), notNullValue());
assertThat(result.getName().get(0).getGivenAsSingleString(), equalTo(PERSON_GIVEN_NAME));
assertThat(result.getName().get(0).getFamily(), equalTo(PERSON_FAMILY_NAME));
}
use of org.hl7.fhir.r5.model.HumanName in project openmrs-module-fhir2 by openmrs.
the class PractitionerTranslatorProviderImplTest method shouldTranslateFhirNameToPersonName.
@Test
public void shouldTranslateFhirNameToPersonName() {
PersonName personName = new PersonName();
personName.setGivenName(GIVEN_NAME);
personName.setFamilyName(FAMILY_NAME);
org.hl7.fhir.r4.model.Practitioner practitioner = new org.hl7.fhir.r4.model.Practitioner();
practitioner.addIdentifier(new Identifier().setValue("349023n23b-t"));
HumanName name = practitioner.addName();
name.addGiven(GIVEN_NAME);
name.setFamily(FAMILY_NAME);
when(nameTranslator.toOpenmrsType(name)).thenReturn(personName);
Provider result = practitionerTranslator.toOpenmrsType(practitioner);
assertThat(result, notNullValue());
assertThat(result.getPerson().getGivenName(), equalTo(GIVEN_NAME));
assertThat(result.getPerson().getFamilyName(), equalTo(FAMILY_NAME));
}
use of org.hl7.fhir.r5.model.HumanName in project openmrs-module-fhir2 by openmrs.
the class PatientTranslatorImpl method toOpenmrsType.
@Override
public org.openmrs.Patient toOpenmrsType(@Nonnull org.openmrs.Patient currentPatient, @Nonnull Patient patient) {
notNull(currentPatient, "The existing Openmrs Patient object should not be null");
notNull(patient, "The Patient object should not be null");
currentPatient.setUuid(patient.getId());
for (Identifier identifier : patient.getIdentifier()) {
PatientIdentifier omrsIdentifier = identifierTranslator.toOpenmrsType(identifier);
if (omrsIdentifier != null) {
currentPatient.addIdentifier(omrsIdentifier);
}
}
for (HumanName name : patient.getName()) {
currentPatient.addName(nameTranslator.toOpenmrsType(name));
}
if (patient.hasGender()) {
currentPatient.setGender(genderTranslator.toOpenmrsType(patient.getGender()));
}
if (patient.hasBirthDateElement()) {
birthDateTranslator.toOpenmrsType(currentPatient, patient.getBirthDateElement());
}
if (patient.hasDeceased()) {
try {
patient.getDeceasedBooleanType();
currentPatient.setDead(patient.getDeceasedBooleanType().booleanValue());
} catch (FHIRException ignored) {
}
try {
patient.getDeceasedDateTimeType();
currentPatient.setDead(true);
currentPatient.setDeathDate(patient.getDeceasedDateTimeType().getValue());
} catch (FHIRException ignored) {
}
}
for (Address address : patient.getAddress()) {
currentPatient.addAddress(addressTranslator.toOpenmrsType(address));
}
patient.getTelecom().stream().map(contactPoint -> (PersonAttribute) telecomTranslator.toOpenmrsType(new PersonAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(currentPatient::addAttribute);
return currentPatient;
}
use of org.hl7.fhir.r5.model.HumanName in project openmrs-module-fhir2 by openmrs.
the class PersonTranslatorImpl method toOpenmrsType.
@Override
public Person toOpenmrsType(@Nonnull Person openmrsPerson, @Nonnull org.hl7.fhir.r4.model.Person person) {
notNull(openmrsPerson, "The existing Openmrs Person object should not be null");
notNull(person, "The Person object should not be null");
openmrsPerson.setUuid(person.getId());
for (HumanName name : person.getName()) {
openmrsPerson.addName(nameTranslator.toOpenmrsType(name));
}
if (person.hasGender()) {
openmrsPerson.setGender(genderTranslator.toOpenmrsType(person.getGender()));
}
if (person.hasBirthDateElement()) {
birthDateTranslator.toOpenmrsType(openmrsPerson, person.getBirthDateElement());
}
for (Address address : person.getAddress()) {
openmrsPerson.addAddress(addressTranslator.toOpenmrsType(address));
}
person.getTelecom().stream().map(contactPoint -> (PersonAttribute) telecomTranslator.toOpenmrsType(new PersonAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(openmrsPerson::addAttribute);
return openmrsPerson;
}
Aggregations