Search in sources :

Example 1 with HttpBody

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();
}
Also used : Search(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.Search) SearchResourcesRequest(com.google.api.services.healthcare.v1.model.SearchResourcesRequest)

Example 2 with HttpBody

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;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) HttpBody(com.google.api.services.healthcare.v1.model.HttpBody) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 3 with HttpBody

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;
}
Also used : JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) HttpBody(com.google.api.services.healthcare.v1.model.HttpBody) JsonObject(com.google.gson.JsonObject)

Aggregations

HttpBody (com.google.api.services.healthcare.v1.model.HttpBody)2 Search (com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.Search)1 SearchResourcesRequest (com.google.api.services.healthcare.v1.model.SearchResourcesRequest)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 StringEntity (org.apache.http.entity.StringEntity)1