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;
}
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;
}
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;
}
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;
}
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())));
}
Aggregations