use of com.google.api.services.actions_fulfillment.v2.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderTest method findLocationsByState_shouldReturnMatchingBundleOfLocations.
@Test
public void findLocationsByState_shouldReturnMatchingBundleOfLocations() {
StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE)));
when(locationService.searchForLocations(isNull(), isNull(), isNull(), isNull(), argThat(Matchers.is(stateParam)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(location), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchLocations(null, null, null, null, stateParam, null, null, null, null, null, null, null);
assertThat(results, notNullValue());
List<Location> resultList = get(results);
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList.get(0).fhirType(), is(FhirConstants.LOCATION));
assertThat(resultList.get(0).getAddress().getState(), equalTo(STATE));
}
use of com.google.api.services.actions_fulfillment.v2.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationTranslatorImpl method toFhirResource.
/**
* @see org.openmrs.module.fhir2.api.translators.LocationTranslator#toFhirResource(org.openmrs.Location)
*/
@Override
public Location toFhirResource(@Nonnull org.openmrs.Location openmrsLocation) {
if (openmrsLocation == null) {
return null;
}
Location fhirLocation = new Location();
Location.LocationPositionComponent position = new Location.LocationPositionComponent();
fhirLocation.setId(openmrsLocation.getUuid());
fhirLocation.setName(getMetadataTranslation(openmrsLocation));
fhirLocation.setDescription(openmrsLocation.getDescription());
fhirLocation.setAddress(locationAddressTranslator.toFhirResource(openmrsLocation));
double latitude = NumberUtils.toDouble(openmrsLocation.getLatitude(), -1.0d);
if (latitude >= 0.0d) {
position.setLatitude(latitude);
}
double longitude = NumberUtils.toDouble(openmrsLocation.getLongitude(), -1.0d);
if (longitude >= 0.0d) {
position.setLongitude(longitude);
}
fhirLocation.setPosition(position);
if (!openmrsLocation.getRetired()) {
fhirLocation.setStatus(Location.LocationStatus.ACTIVE);
}
if (openmrsLocation.getRetired()) {
fhirLocation.setStatus(Location.LocationStatus.INACTIVE);
}
fhirLocation.setTelecom(getLocationContactDetails(openmrsLocation));
if (openmrsLocation.getTags() != null) {
for (LocationTag tag : openmrsLocation.getTags()) {
fhirLocation.getMeta().addTag(FhirConstants.OPENMRS_FHIR_EXT_LOCATION_TAG, tag.getName(), tag.getDescription());
}
}
if (openmrsLocation.getParentLocation() != null) {
fhirLocation.setPartOf(createLocationReference(openmrsLocation.getParentLocation()));
}
fhirLocation.getMeta().setLastUpdated(openmrsLocation.getDateChanged());
fhirLocation.addContained(provenanceTranslator.getCreateProvenance(openmrsLocation));
fhirLocation.addContained(provenanceTranslator.getUpdateProvenance(openmrsLocation));
return fhirLocation;
}
use of com.google.api.services.actions_fulfillment.v2.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationTranslatorImpl method toOpenmrsType.
/**
* @see org.openmrs.module.fhir2.api.translators.LocationTranslator#toOpenmrsType(org.openmrs.Location,
* org.hl7.fhir.r4.model.Location)
*/
@Override
public org.openmrs.Location toOpenmrsType(@Nonnull org.openmrs.Location openmrsLocation, @Nonnull Location fhirLocation) {
notNull(openmrsLocation, "The existing Openmrs location should not be null");
notNull(fhirLocation, "The Location object should not be null");
openmrsLocation.setUuid(fhirLocation.getIdElement().getIdPart());
openmrsLocation.setName(fhirLocation.getName());
openmrsLocation.setDescription(fhirLocation.getDescription());
if (fhirLocation.getAddress() != null) {
openmrsLocation.setCityVillage(fhirLocation.getAddress().getCity());
openmrsLocation.setStateProvince(fhirLocation.getAddress().getState());
openmrsLocation.setCountry(fhirLocation.getAddress().getCountry());
openmrsLocation.setPostalCode(fhirLocation.getAddress().getPostalCode());
}
if (fhirLocation.getPosition().hasLatitude()) {
openmrsLocation.setLatitude(fhirLocation.getPosition().getLatitude().toString());
}
if (fhirLocation.getPosition().hasLongitude()) {
openmrsLocation.setLongitude(fhirLocation.getPosition().getLongitude().toString());
}
fhirLocation.getTelecom().stream().map(contactPoint -> (LocationAttribute) telecomTranslator.toOpenmrsType(new LocationAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(openmrsLocation::addAttribute);
if (fhirLocation.getMeta().hasTag()) {
for (Coding tag : fhirLocation.getMeta().getTag()) {
openmrsLocation.addTag(locationTagTranslator.toOpenmrsType(tag));
}
}
openmrsLocation.setParentLocation(getOpenmrsParentLocation(fhirLocation.getPartOf()));
return openmrsLocation;
}
use of com.google.api.services.actions_fulfillment.v2.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderWebTest method shouldGetLocationHistoryById.
@Test
public void shouldGetLocationHistoryById() throws IOException, ServletException {
Provenance provenance = new Provenance();
provenance.setId(new IdType(FhirUtils.newUuid()));
provenance.setRecorded(new Date());
provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.Location();
location.setId(LOCATION_UUID);
location.addContained(provenance);
when(locationService.get(LOCATION_UUID)).thenReturn(location);
MockHttpServletResponse response = getLocationHistoryByIdRequest();
Bundle results = readBundleResponse(response);
assertThat(results, Matchers.notNullValue());
assertThat(results.hasEntry(), is(true));
assertThat(results.getEntry().get(0).getResource(), Matchers.notNullValue());
assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
use of com.google.api.services.actions_fulfillment.v2.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderWebTest method shouldVerifyGetLocationHistoryByIdUri.
@Test
public void shouldVerifyGetLocationHistoryByIdUri() throws Exception {
org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.Location();
location.setId(LOCATION_UUID);
when(locationService.get(LOCATION_UUID)).thenReturn(location);
MockHttpServletResponse response = getLocationHistoryByIdRequest();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Aggregations