use of com.google.api.services.healthcare.v1.model.HttpBody in project beam by apache.
the class HttpHealthcareApiClient method searchFhirResource.
@Override
public HttpBody searchFhirResource(String fhirStore, String resourceType, @Nullable Map<String, Object> parameters, String pageToken) throws IOException {
SearchResourcesRequest request = new SearchResourcesRequest().setResourceType(resourceType);
Search search = client.projects().locations().datasets().fhirStores().fhir().search(fhirStore, request);
if (parameters != null && !parameters.isEmpty()) {
parameters.forEach(search::set);
}
if (pageToken != null && !pageToken.isEmpty()) {
search.set("_page_token", URLDecoder.decode(pageToken, "UTF-8"));
}
return search.execute();
}
use of com.google.api.services.healthcare.v1.model.HttpBody in project beam by apache.
the class HttpHealthcareApiClient method executeFhirBundle.
@Override
public HttpBody executeFhirBundle(String fhirStore, String bundle) throws IOException, HealthcareHttpException {
if (httpClient == null || client == null) {
initClient();
}
credentials.refreshIfExpired();
StringEntity requestEntity = new StringEntity(bundle, ContentType.APPLICATION_JSON);
URI uri;
try {
uri = new URIBuilder(client.getRootUrl() + "v1/" + fhirStore + "/fhir").build();
} catch (URISyntaxException e) {
LOG.error("URL error when making executeBundle request to FHIR API. " + e.getMessage());
throw new IllegalArgumentException(e);
}
HttpUriRequest request = RequestBuilder.post().setUri(uri).setEntity(requestEntity).addHeader("Authorization", "Bearer " + credentials.getAccessToken().getTokenValue()).addHeader("User-Agent", USER_AGENT).addHeader("Content-Type", FHIRSTORE_HEADER_CONTENT_TYPE).addHeader("Accept-Charset", FHIRSTORE_HEADER_ACCEPT_CHARSET).addHeader("Accept", FHIRSTORE_HEADER_ACCEPT).build();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
String content = EntityUtils.toString(responseEntity);
// Check 2XX code.
int statusCode = response.getStatusLine().getStatusCode();
if (!(statusCode / 100 == 2)) {
throw HealthcareHttpException.of(statusCode, content);
}
HttpBody responseModel = new HttpBody();
responseModel.setData(content);
return responseModel;
}
use of com.google.api.services.healthcare.v1.model.HttpBody in project beam by apache.
the class FhirIOTestUtil method executeFhirBundles.
/**
* Populate the test resources into the FHIR store and returns a list of resource IDs.
*/
static List<String> executeFhirBundles(HealthcareApiClient client, String fhirStore, List<String> bundles) throws IOException, HealthcareHttpException {
List<String> resourceNames = new ArrayList<>();
for (String bundle : bundles) {
HttpBody resp = client.executeFhirBundle(fhirStore, bundle);
JsonObject jsonResponse = JsonParser.parseString(resp.getData()).getAsJsonObject();
for (JsonElement entry : jsonResponse.getAsJsonArray("entry")) {
String location = entry.getAsJsonObject().getAsJsonObject("response").getAsJsonPrimitive("location").getAsString();
String resourceName = location.substring(location.indexOf("project"), location.indexOf("/_history"));
resourceNames.add(resourceName);
}
}
return resourceNames;
}
Aggregations