Skip to content

healthcare API: update all FHIR v1beta1 samples to v1 #3384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 23, 2020
Merged

healthcare API: update all FHIR v1beta1 samples to v1 #3384

merged 16 commits into from
Apr 23, 2020

Conversation

noerog
Copy link
Contributor

@noerog noerog commented Apr 13, 2020

Originally from #3300 but split up here

@noerog noerog requested a review from a team as a code owner April 13, 2020 20:59
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 13, 2020
tmatsuo pushed a commit that referenced this pull request Apr 15, 2020
* healthcare API: update all v1beta1 samples to v1

* healthcare API: use v1 instead of v1beta1 endpoint

* healthcare API: remove FHIR conditional methods from v1 because they are only in v1beta1

* add requirements-test.txt files

* Change test response for searching for studies to 204

* fix missing param in execute_bundle.json causing test failures

* fix HL7v2 store failure. notificationConfig was deprecated in favor of notificationConfigs

* address review comments: use ADC and simplify credentials auth

* delete new FHIR files, they are now in #3384

* delete new DICOM files, they are now in #3387

* delete new HL7v2 files, they are now in #3388

* clean up test_dataset fixture

* remove try block from the sample

* more robust test setup and cleanup

Co-authored-by: Takashi Matsuo <tmatsuo@google.com>


def get_client():
"""Returns an authorized API client by discovering the Healthcare API and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Usually, we format long docstring like the following:

def get_client():
    """Returns an authorized API client.

    It assumes you set GOOGLE_APPLICATION_CREDENTIALS environment
    variable.
    """

Short summary, then long description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# [START healthcare_get_client_fhir]
def get_client_fhir():
"""Returns an authorized API client by discovering the Healthcare API and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code removed.


print("Created Encounter resource with ID {}".format(response["id"]))
print(json.dumps(response, indent=2))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and there, I'd remove these 2 empty lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A result of black as we discussed in the other PR. I'll try removing it when I remember to.

# limitations under the License.

import os
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put pytest import in the bottom below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the change. The import statements should be in 3 blocks; 1) standard libs 2) 3rd party libs 3) local libs

So they should be:

import os
import sys
import uuid

import backoff
from googleapiclient.errors import HttpError
import pytest

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "datasets"))  # noqa
import datasets
import fhir_stores
import fhir_resources

or something like that


@pytest.fixture(scope="module")
def test_dataset():
@retry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I replaced retrying with backoff in #3434.

It's up to you to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# The API returns 200 whether the resource exists or was
# successfully deleted or not, so only retry on
# unathorized exceptions.
if err.resp.status == 401:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code ignores the exception when the status is 401. Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I still see it


# [START healthcare_get_client]
def get_client():
"""Returns an authorized API client by discovering the Healthcare API and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short summary and long description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def test_import_fhir_store_gcs(test_dataset, test_fhir_store, capsys):
storage_client = storage.Client()
bucket = storage_client.get_bucket(gcs_uri)
blob = bucket.blob(source_file_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is very easy to create a fixture for blob. WDYT?
With the current code, it is not guaranteed to be deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a fixture.

Copy link
Contributor

@tmatsuo tmatsuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good modulo few more changes

resource_id,
):
"""
Deletes a FHIR resource. Regardless of whether the operation succeeds or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you format the docstring like:

    """Deletes a FHIR resource.

    Regardless of whether the operation succeeds or....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

base_url, project_id, cloud_region, dataset_id, fhir_store_id
):
"""
Searches resources in the given FHIR store using the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto:

    """Searches resources in the given FHIR store.

    It uses the ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# limitations under the License.

import os
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the change. The import statements should be in 3 blocks; 1) standard libs 2) 3rd party libs 3) local libs

So they should be:

import os
import sys
import uuid

import backoff
from googleapiclient.errors import HttpError
import pytest

# Add datasets for bootstrapping datasets for testing
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "datasets"))  # noqa
import datasets
import fhir_stores
import fhir_resources

or something like that

# The API returns 200 whether the resource exists or was
# successfully deleted or not, so only retry on
# unathorized exceptions.
if err.resp.status == 401:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I still see it


out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to print this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


import backoff
import pytest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove an empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@noerog noerog requested a review from kurtisvg April 21, 2020 20:02

out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't need this I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I don't know where these statements came from.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see print(out)


out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see this


out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@tmatsuo tmatsuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see print(out). Please confirm


out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see print(out)


out, _ = capsys.readouterr()

print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see this

@noerog
Copy link
Contributor Author

noerog commented Apr 22, 2020

I still see print(out). Please confirm

Please check again?

try:
datasets.delete_dataset(project_id, cloud_region, dataset_id)
except HttpError as err:
# The API returns 403 when the dataset doesn't exist.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expand this comment (similar to other PR)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

project_id, cloud_region, dataset_id, fhir_store_id
)
except HttpError as err:
# The API returns 403 when the FHIR store doesn't exist.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@noerog noerog merged commit 079d59c into GoogleCloudPlatform:master Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants