Search in sources :

Example 46 with Address

use of org.hl7.fhir.dstu2.model.Address 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)

Example 47 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PractitionerTranslatorProviderImpl method toOpenmrsType.

@Override
public Provider toOpenmrsType(@Nonnull Provider existingProvider, @Nonnull Practitioner practitioner) {
    if (existingProvider == null) {
        return null;
    }
    if (practitioner == null) {
        return null;
    }
    existingProvider.setUuid(practitioner.getId());
    existingProvider.setIdentifier(practitioner.getIdentifierFirstRep().getValue());
    if (existingProvider.getPerson() == null) {
        existingProvider.setPerson(new Person());
    }
    if (practitioner.hasBirthDateElement()) {
        birthDateTranslator.toOpenmrsType(existingProvider.getPerson(), practitioner.getBirthDateElement());
    }
    for (HumanName name : practitioner.getName()) {
        existingProvider.getPerson().addName(nameTranslator.toOpenmrsType(name));
    }
    if (practitioner.hasGender()) {
        existingProvider.getPerson().setGender(genderTranslator.toOpenmrsType(practitioner.getGender()));
    }
    for (Address address : practitioner.getAddress()) {
        existingProvider.getPerson().addAddress(addressTranslator.toOpenmrsType(address));
    }
    practitioner.getTelecom().stream().map(contactPoint -> (ProviderAttribute) telecomTranslator.toOpenmrsType(new ProviderAttribute(), contactPoint)).filter(Objects::nonNull).forEach(existingProvider::addAttribute);
    return existingProvider;
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) ProviderAttribute(org.openmrs.ProviderAttribute) Person(org.openmrs.Person)

Example 48 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PractitionerTranslatorProviderImpl method toFhirResource.

@Override
public Practitioner toFhirResource(@Nonnull Provider provider) {
    if (provider == null) {
        return null;
    }
    Practitioner practitioner = new Practitioner();
    Identifier identifier = new Identifier();
    identifier.setSystem(FhirConstants.OPENMRS_FHIR_EXT_PROVIDER_IDENTIFIER);
    identifier.setValue(provider.getIdentifier());
    practitioner.addIdentifier(identifier);
    practitioner.setId(provider.getUuid());
    practitioner.setActive(provider.getRetired());
    practitioner.setTelecom(getProviderContactDetails(provider));
    if (provider.getPerson() != null) {
        practitioner.setBirthDateElement(birthDateTranslator.toFhirResource(provider.getPerson()));
        practitioner.setGender(genderTranslator.toFhirResource(provider.getPerson().getGender()));
        for (PersonName name : provider.getPerson().getNames()) {
            practitioner.addName(nameTranslator.toFhirResource(name));
        }
        for (PersonAddress address : provider.getPerson().getAddresses()) {
            practitioner.addAddress(addressTranslator.toFhirResource(address));
        }
    }
    practitioner.getMeta().setLastUpdated(provider.getDateChanged());
    practitioner.addContained(provenanceTranslator.getCreateProvenance(provider));
    practitioner.addContained(provenanceTranslator.getUpdateProvenance(provider));
    return practitioner;
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) PersonName(org.openmrs.PersonName) Identifier(org.hl7.fhir.r4.model.Identifier) PersonAddress(org.openmrs.PersonAddress)

Example 49 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PractitionerTranslatorUserImpl method toFhirResource.

@Override
public Practitioner toFhirResource(@Nonnull User user) {
    notNull(user, "The User object should not be null");
    Practitioner practitioner = new Practitioner();
    practitioner.setId(user.getUuid());
    Identifier userIdentifier = new Identifier();
    userIdentifier.setSystem(FhirConstants.OPENMRS_FHIR_EXT_USER_IDENTIFIER);
    userIdentifier.setValue(user.getSystemId());
    practitioner.addIdentifier(userIdentifier);
    if (user.getPerson() != null) {
        practitioner.setBirthDateElement(birthDateTranslator.toFhirResource(user.getPerson()));
        practitioner.setGender(genderTranslator.toFhirResource(user.getPerson().getGender()));
        for (PersonName name : user.getPerson().getNames()) {
            practitioner.addName(nameTranslator.toFhirResource(name));
        }
        for (PersonAddress address : user.getPerson().getAddresses()) {
            practitioner.addAddress(addressTranslator.toFhirResource(address));
        }
    }
    practitioner.getMeta().setLastUpdated(user.getDateChanged());
    return practitioner;
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) PersonName(org.openmrs.PersonName) Identifier(org.hl7.fhir.r4.model.Identifier) PersonAddress(org.openmrs.PersonAddress)

Example 50 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldSearchForExistingLocationsAsJson.

@Test
public void shouldSearchForExistingLocationsAsJson() throws Exception {
    MockHttpServletResponse response = get("/Location").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    List<Bundle.BundleEntryComponent> entries = results.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Location/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(Location.class))));
    assertThat(entries, everyItem(hasResource(validResource())));
    response = get("/Location?address-city=Kerio&partof=" + PARENT_LOCATION_UUID + "&_sort=name").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    entries = results.getEntry();
    assertThat(entries, everyItem(hasResource(hasProperty("address", hasProperty("city", equalTo("Kerio"))))));
    assertThat(entries, everyItem(hasResource(hasProperty("partOf", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARENT_LOCATION_UUID)))))));
    assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("name", equalTo("Test location 6"))), hasResource(hasProperty("name", equalTo("Test location 8")))));
    assertThat(entries, everyItem(hasResource(validResource())));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Aggregations

Address (org.hl7.fhir.r4.model.Address)75 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)31 Patient (org.hl7.fhir.r4.model.Patient)30 PersonAddress (org.openmrs.PersonAddress)27 HumanName (org.hl7.fhir.r4.model.HumanName)24 Identifier (org.hl7.fhir.r4.model.Identifier)23 ArrayList (java.util.ArrayList)22 Address (org.hl7.fhir.dstu3.model.Address)22 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)19 Location (org.hl7.fhir.r4.model.Location)13 Organization (org.hl7.fhir.r4.model.Organization)13 InputStream (java.io.InputStream)12 IdType (org.hl7.fhir.dstu3.model.IdType)12 Patient (org.hl7.fhir.dstu3.model.Patient)12 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12