Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions sdks/python/apache_beam/io/gcp/dicomclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# limitations under the License.
#

import google.auth
import json
from google.auth import default
from google.auth.transport import requests


Expand All @@ -32,7 +31,7 @@ def get_session(self, credential):

# if the credential is not provided, use the default credential.
if not credential:
credential, _ = google.auth.default()
credential, _ = default()
new_seesion = requests.AuthorizedSession(credential)
self.session = new_seesion
return new_seesion
Expand Down
35 changes: 16 additions & 19 deletions sdks/python/apache_beam/io/gcp/dicomio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
#

import apache_beam as beam
import google.auth
import json
from dicomclient import DicomApiHttpClient
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.transforms import PTransform
from apache_beam.io.filesystem import BeamIOError
from apache_beam.transforms import PTransform
from dicomclient import DicomApiHttpClient


class DicomSearch(PTransform):
"""A ``PTransform`` for QIDO search metadata from Cloud DICOM api.
It takes Pcollection of dicts as input and return a Pcollection
It takes Pcollection of dicts as input and return a Pcollection
of dict as results:
INPUT:
The input dict represents DICOM web path parameter, which hasfollowing
The input dict represents DICOM web path parameter, which hasfollowing
string keys and values:
{
'project_id': str,
Expand All @@ -44,7 +41,7 @@ class DicomSearch(PTransform):
region: Region where the DICOM store resides. (Required)
dataset_id: Id of the dataset where DICOM store belongs to. (Required)
dicom_store_id: Id of the dicom store. (Required)
search_type: Which type of search it is, cloud only be one of the three
search_type: Which type of search it is, cloud only be one of the three
values: 'instances', 'series' or 'studies'. (Required)
params: A dict of Tag:value pairs used to refine QIDO search. (Optional)
Supported tags in three categories:
Expand All @@ -60,8 +57,7 @@ class DicomSearch(PTransform):
Modality
3. Instances: all study/series level search terms and
SOPInstanceUID
e.g. {"StudyInstanceUID":"1","SeriesInstanceUID":"2","SOPInstanceUID":"3"}

e.g. {"StudyInstanceUID":"1","SeriesInstanceUID":"2"}
OUTPUT:
The output dict encodes results as well as error messages:
{
Expand All @@ -74,7 +70,7 @@ class DicomSearch(PTransform):
def __init__(self, credential=None):
"""Initializes ``DicomSearch``.
Args:
credential: # type: Google credential object, if it isspecified, the
credential: # type: Google credential object, if it isspecified, the
Http client will use it instead of the default one.
"""
self.credential = credential
Expand Down Expand Up @@ -116,14 +112,15 @@ def process(self, element):
search_type, params, self.credential
)
else:
error_message = 'Search type can only be "studies", "instances" or "series"'
error_message = 'Search type can only be "studies",\
"instances" or "series"'

if not error_message:
out = {}
out['result'] = result
out['status'] = status_code
out['input'] = element
out['success'] = True if status_code == 200 else False
out['success'] = (status_code == 200)
return [out]

# when the input dict dose not meet the requirements.
Expand All @@ -137,7 +134,7 @@ def process(self, element):

class PubsubToQido(PTransform):
"""A ``PTransform`` for converting pubsub messages into search input dict.
Takes Pcollection of string as input and return a Pcollection of dict as
Takes Pcollection of string as input and return a Pcollection of dict as
result. Note that some pubsub messages may not be from DICOM api, which
will be records as failed conversions.
INPUT:
Expand All @@ -158,7 +155,7 @@ def __init__(self, credential=None):

"""Initializes ``PubsubToQido``.
Args:
credential: # type: Google credential object, if it isspecified, the
credential: # type: Google credential object, if it isspecified, the
Http client will use it instead of the default one.
"""
self.credential = credential
Expand Down Expand Up @@ -232,7 +229,7 @@ def process(self, element):

class DicomStoreInstance(PTransform):
"""A ``PTransform`` for storing instances to a DICOM store.
Takes Pcollection of byte[] as input and return a Pcollection of dict as
Takes Pcollection of byte[] as input and return a Pcollection of dict as
result. The input are normally dicom file in bytes format.
This sink needs to be initailzed by a destination dict:
{
Expand Down Expand Up @@ -261,7 +258,7 @@ def __init__(self, destination_dict, credential=None):
"""Initializes ``DicomStoreInstance``.
Args:
destination_dict: # type: python dict, more details in ConvertPubsubToQido.
credential: # type: Google credential object, if it isspecified, the
credential: # type: Google credential object, if it isspecified, the
Http client will use it instead of the default one.
"""
self.credential = credential
Expand All @@ -288,13 +285,13 @@ def process(self, element):
dataset_id = self.destination_dict['dataset_id']
dicom_store_id = self.destination_dict['dicom_store_id']

result, status_code = DicomApiHttpClient().dicomweb_store_instance(
_, status_code = DicomApiHttpClient().dicomweb_store_instance(
project_id, region, dataset_id, dicom_store_id, element,
self.credential
)

out = {}
out['status'] = status_code
out['input'] = None if status_code == 200 else element
out['success'] = True if status_code == 200 else False
out['success'] = (status_code == 200)
return [out]