use of org.hl7.fhir.r4b.model.Address in project openmrs-module-fhir2 by openmrs.
the class PersonTranslatorImplTest method shouldTranslateOpenmrsAddressToFhirAddress.
@Test
public void shouldTranslateOpenmrsAddressToFhirAddress() {
Address address = new Address();
address.setId(ADDRESS_UUID);
address.setCity(ADDRESS_CITY);
when(addressTranslator.toFhirResource(argThat(allOf(hasProperty("uuid", equalTo(ADDRESS_UUID)), hasProperty("cityVillage", equalTo(ADDRESS_CITY)))))).thenReturn(address);
Person person = new Person();
PersonAddress personAddress = new PersonAddress();
personAddress.setUuid(ADDRESS_UUID);
personAddress.setCityVillage(ADDRESS_CITY);
person.addAddress(personAddress);
org.hl7.fhir.r4.model.Person result = personTranslator.toFhirResource(person);
assertThat(result.getAddress(), notNullValue());
assertThat(result.getAddress(), not(empty()));
assertThat(result.getAddress().get(0), equalTo(address));
}
use of org.hl7.fhir.r4b.model.Address in project openmrs-module-fhir2 by openmrs.
the class LocationAddressTranslatorImpl method toFhirResource.
@Override
public Address toFhirResource(@Nonnull Location omrsLocation) {
Address address = null;
if (omrsLocation != null) {
address = new Address();
address.setId(null);
address.setCity(omrsLocation.getCityVillage());
address.setState(omrsLocation.getStateProvince());
address.setCountry(omrsLocation.getCountry());
address.setPostalCode(omrsLocation.getPostalCode());
addAddressExtensions(address, omrsLocation);
}
return address;
}
use of org.hl7.fhir.r4b.model.Address in project openmrs-module-fhir2 by openmrs.
the class PatientTranslatorImpl method toFhirResource.
@Override
public Patient toFhirResource(@Nonnull org.openmrs.Patient openmrsPatient) {
notNull(openmrsPatient, "The Openmrs Patient object should not be null");
Patient patient = new Patient();
patient.setId(openmrsPatient.getUuid());
patient.setActive(!openmrsPatient.getVoided());
for (PatientIdentifier identifier : openmrsPatient.getActiveIdentifiers()) {
patient.addIdentifier(identifierTranslator.toFhirResource(identifier));
}
for (PersonName name : openmrsPatient.getNames()) {
patient.addName(nameTranslator.toFhirResource(name));
}
if (openmrsPatient.getGender() != null) {
patient.setGender(genderTranslator.toFhirResource(openmrsPatient.getGender()));
}
patient.setBirthDateElement(birthDateTranslator.toFhirResource(openmrsPatient));
if (openmrsPatient.getDead()) {
if (openmrsPatient.getDeathDate() != null) {
patient.setDeceased(new DateTimeType(openmrsPatient.getDeathDate()));
} else {
patient.setDeceased(new BooleanType(true));
}
} else {
patient.setDeceased(new BooleanType(false));
}
for (PersonAddress address : openmrsPatient.getAddresses()) {
patient.addAddress(addressTranslator.toFhirResource(address));
}
patient.setTelecom(getPatientContactDetails(openmrsPatient));
patient.getMeta().setLastUpdated(openmrsPatient.getDateChanged());
patient.addContained(provenanceTranslator.getCreateProvenance(openmrsPatient));
patient.addContained(provenanceTranslator.getUpdateProvenance(openmrsPatient));
return patient;
}
use of org.hl7.fhir.r4b.model.Address 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.r4b.model.Address in project openmrs-module-fhir2 by openmrs.
the class PersonAddressTranslatorImpl method toFhirResource.
@Override
public Address toFhirResource(@Nonnull PersonAddress address) {
if (address == null || address.getVoided()) {
return null;
}
Address fhirAddress = new Address();
fhirAddress.setId(address.getUuid());
fhirAddress.setCity(address.getCityVillage());
fhirAddress.setState(address.getStateProvince());
fhirAddress.setCountry(address.getCountry());
fhirAddress.setPostalCode(address.getPostalCode());
// TODO is this the right mapping?
if (address.getPreferred() != null) {
if (address.getPreferred()) {
fhirAddress.setUse(Address.AddressUse.HOME);
} else {
fhirAddress.setUse(Address.AddressUse.OLD);
}
}
addAddressExtensions(fhirAddress, address);
return fhirAddress;
}
Aggregations