Search in sources :

Example 26 with HumanName

use of org.hl7.fhir.dstu2016may.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));
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) Test(org.junit.Test)

Example 27 with HumanName

use of org.hl7.fhir.dstu2016may.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));
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Test(org.junit.Test)

Example 28 with HumanName

use of org.hl7.fhir.dstu2016may.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));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) HumanName(org.hl7.fhir.r4.model.HumanName) PersonName(org.openmrs.PersonName) Identifier(org.hl7.fhir.r4.model.Identifier) Practitioner(org.hl7.fhir.r4.model.Practitioner) Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 29 with HumanName

use of org.hl7.fhir.dstu2016may.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;
}
Also used : FhirPersonDao(org.openmrs.module.fhir2.api.dao.FhirPersonDao) Setter(lombok.Setter) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Autowired(org.springframework.beans.factory.annotation.Autowired) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) Address(org.hl7.fhir.r4.model.Address) AccessLevel(lombok.AccessLevel) HumanName(org.hl7.fhir.r4.model.HumanName) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Nonnull(javax.annotation.Nonnull) PatientIdentifierTranslator(org.openmrs.module.fhir2.api.translators.PatientIdentifierTranslator) PatientTranslator(org.openmrs.module.fhir2.api.translators.PatientTranslator) Patient(org.hl7.fhir.r4.model.Patient) PersonAddress(org.openmrs.PersonAddress) PersonName(org.openmrs.PersonName) PatientIdentifier(org.openmrs.PatientIdentifier) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) PersonAttribute(org.openmrs.PersonAttribute) BirthDateTranslator(org.openmrs.module.fhir2.api.translators.BirthDateTranslator) PersonNameTranslator(org.openmrs.module.fhir2.api.translators.PersonNameTranslator) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Component(org.springframework.stereotype.Component) GenderTranslator(org.openmrs.module.fhir2.api.translators.GenderTranslator) Validate.notNull(org.apache.commons.lang3.Validate.notNull) FHIRException(org.hl7.fhir.exceptions.FHIRException) PersonAddressTranslator(org.openmrs.module.fhir2.api.translators.PersonAddressTranslator) HumanName(org.hl7.fhir.r4.model.HumanName) Identifier(org.hl7.fhir.r4.model.Identifier) PatientIdentifier(org.openmrs.PatientIdentifier) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) FHIRException(org.hl7.fhir.exceptions.FHIRException) PatientIdentifier(org.openmrs.PatientIdentifier) PersonAttribute(org.openmrs.PersonAttribute)

Example 30 with HumanName

use of org.hl7.fhir.dstu2016may.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;
}
Also used : Person(org.openmrs.Person) Setter(lombok.Setter) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) PersonAttribute(org.openmrs.PersonAttribute) BirthDateTranslator(org.openmrs.module.fhir2.api.translators.BirthDateTranslator) Autowired(org.springframework.beans.factory.annotation.Autowired) PersonNameTranslator(org.openmrs.module.fhir2.api.translators.PersonNameTranslator) Objects(java.util.Objects) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) Address(org.hl7.fhir.r4.model.Address) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) FhirPatientDao(org.openmrs.module.fhir2.api.dao.FhirPatientDao) Component(org.springframework.stereotype.Component) AccessLevel(lombok.AccessLevel) GenderTranslator(org.openmrs.module.fhir2.api.translators.GenderTranslator) HumanName(org.hl7.fhir.r4.model.HumanName) PatientReferenceTranslator(org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator) Validate.notNull(org.apache.commons.lang3.Validate.notNull) Nonnull(javax.annotation.Nonnull) PersonAddressTranslator(org.openmrs.module.fhir2.api.translators.PersonAddressTranslator) PersonTranslator(org.openmrs.module.fhir2.api.translators.PersonTranslator) PersonAddress(org.openmrs.PersonAddress) PersonName(org.openmrs.PersonName) HumanName(org.hl7.fhir.r4.model.HumanName) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) PersonAttribute(org.openmrs.PersonAttribute)

Aggregations

HumanName (org.hl7.fhir.r4.model.HumanName)84 HumanName (org.hl7.fhir.dstu3.model.HumanName)37 Patient (org.hl7.fhir.r4.model.Patient)37 Test (org.junit.jupiter.api.Test)29 ArrayList (java.util.ArrayList)27 Patient (org.hl7.fhir.dstu3.model.Patient)27 Test (org.junit.Test)26 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)23 Address (org.hl7.fhir.r4.model.Address)20 Identifier (org.hl7.fhir.r4.model.Identifier)20 PersonName (org.openmrs.PersonName)17 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 GET (javax.ws.rs.GET)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)15 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 StringType (org.hl7.fhir.r4.model.StringType)14 Date (java.util.Date)13