googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.78k stars 2.42k forks source link

Question: fhir.search() #862

Closed JoelV closed 4 years ago

JoelV commented 4 years ago

Referencing the following python example below and can be found here: https://cloud.google.com/healthcare/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/search

BEFORE RUNNING:
---------------
1. If not already done, enable the Cloud Healthcare API
   and check the quota for your project at
   https://console.developers.google.com/apis/api/healthcare
2. This sample uses Application Default Credentials for authentication.
   If not already done, install the gcloud CLI from
   https://cloud.google.com/sdk and run
   `gcloud beta auth application-default login`.
   For more information, see
   https://developers.google.com/identity/protocols/application-default-credentials
3. Install the Python client library for Google APIs by running
   `pip install --upgrade google-api-python-client`
"""
from pprint import pprint

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

service = discovery.build('healthcare', 'v1beta1', credentials=credentials)

# Name of the FHIR store to retrieve resources from.
parent = 'projects/my-project/locations/my-location/datasets/my-dataset/fhirStores/my-fhir-store'  # TODO: Update placeholder value.

search_resources_request_body = {
    # TODO: Add desired entries to the request body.
}

request = service.projects().locations().datasets().fhirStores().fhir().search(parent=parent, body=search_resources_request_body)
response = request.execute()

# TODO: Change code below to process the `response` dict:
pprint(response)

Question

I'm having trouble putting in search params into search_resources_request_body

for example i want to search all observations for a particular Observation.subject so the request would be something like this

'{base_url}/{parent}/fhir/Observation/_search?subject='123-123-123'

right now all I can do is narrow the search to return every Fhir observation

search_resources_request_body = {
    "resourceType": "Observation"
}

I've been digging through the code and it doesn't seem to be a way to add search criteria via query params.

Am I missing something.?

noerog commented 4 years ago

I think that the sample you're looking at is misleading and should be removed.

I'd recommend using the requests library and following our samples in https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/healthcare/api-client/fhir/fhir_resources.py. We also have documentation in https://cloud.google.com/healthcare/docs/how-tos/dicomweb#searching_using_dicom_tags for how to search using query parameters.

JoelV commented 4 years ago

Got it thanks!!!