blob: f5a94c1ac4d5d9a990d38848faaeedd011092364 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>apache_beam.io.gcp.dicomio module &mdash; Apache Beam documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="apache_beam.io.gcp.gce_metadata_util module" href="apache_beam.io.gcp.gce_metadata_util.html" />
<link rel="prev" title="apache_beam.io.gcp.dicomclient module" href="apache_beam.io.gcp.dicomclient.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Apache Beam
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="apache_beam.coders.html">apache_beam.coders package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.dataframe.html">apache_beam.dataframe package</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="apache_beam.io.html">apache_beam.io package</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="apache_beam.io.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.aws.html">apache_beam.io.aws package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.azure.html">apache_beam.io.azure package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.external.html">apache_beam.io.external package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.flink.html">apache_beam.io.flink package</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="apache_beam.io.gcp.html">apache_beam.io.gcp package</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="apache_beam.io.gcp.html#subpackages">Subpackages</a></li>
<li class="toctree-l4 current"><a class="reference internal" href="apache_beam.io.gcp.html#submodules">Submodules</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="apache_beam.io.html#submodules">Submodules</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.metrics.html">apache_beam.metrics package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.ml.html">apache_beam.ml package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.options.html">apache_beam.options package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.portability.html">apache_beam.portability package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.runners.html">apache_beam.runners package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.transforms.html">apache_beam.transforms package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.typehints.html">apache_beam.typehints package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.utils.html">apache_beam.utils package</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.error.html">apache_beam.error module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.pipeline.html">apache_beam.pipeline module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.pvalue.html">apache_beam.pvalue module</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Apache Beam</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li><a href="apache_beam.io.html">apache_beam.io package</a> &raquo;</li>
<li><a href="apache_beam.io.gcp.html">apache_beam.io.gcp package</a> &raquo;</li>
<li>apache_beam.io.gcp.dicomio module</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/apache_beam.io.gcp.dicomio.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="module-apache_beam.io.gcp.dicomio">
<span id="apache-beam-io-gcp-dicomio-module"></span><h1>apache_beam.io.gcp.dicomio module<a class="headerlink" href="#module-apache_beam.io.gcp.dicomio" title="Permalink to this headline"></a></h1>
<p>DICOM IO connector
This module implements several tools to facilitate the interaction between
a Google Cloud Healthcare DICOM store and a Beam pipeline.</p>
<p>For more details on DICOM store and API:
<a class="reference external" href="https://cloud.google.com/healthcare/docs/how-tos/dicom">https://cloud.google.com/healthcare/docs/how-tos/dicom</a></p>
<p>The DICOM IO connector can be used to search metadata or write DICOM files
to DICOM store.</p>
<p>When used together with Google Pubsub message connector, the
<cite>FormatToQido</cite> PTransform implemented in this module can be used
to convert Pubsub messages to search requests.</p>
<p>Since Traceability is crucial for healthcare
API users, every input or error message will be recorded in the output of
the DICOM IO connector. As a result, every PTransform in this module will
return a PCollection of dict that encodes results and detailed error messages.</p>
<div class="section" id="search-instance-s-metadata-qido-request">
<h2>Search instance’s metadata (QIDO request)<a class="headerlink" href="#search-instance-s-metadata-qido-request" title="Permalink to this headline"></a></h2>
<p>DicomSearch() wraps the QIDO request client and supports 3 levels of search.
Users should specify the level by setting the ‘search_type’ entry in the input
dict. They can also refine the search by adding tags to filter the results using
the ‘params’ entry. Here is a sample usage:</p>
<blockquote>
<div><dl class="docutils">
<dt>with Pipeline() as p:</dt>
<dd><dl class="first docutils">
<dt>input_dict = p | beam.Create(</dt>
<dd>[{‘project_id’: ‘abc123’, ‘type’: ‘instances’,…},
{‘project_id’: ‘dicom_go’, ‘type’: ‘series’,…}])</dd>
</dl>
<p>results = input_dict | io.gcp.DicomSearch()
results | ‘print successful search’ &gt;&gt; beam.Map(
lambda x: print(x[‘result’] if x[‘success’] else None))</p>
<p class="last">results | ‘print failed search’ &gt;&gt; beam.Map(
lambda x: print(x[‘result’] if not x[‘success’] else None))</p>
</dd>
</dl>
</div></blockquote>
<p>In the example above, successful qido search results and error messages for
failed requests are printed. When used in real life, user can choose to filter
those data and output them to wherever they want.</p>
</div>
<div class="section" id="convert-dicom-pubsub-message-to-qido-search-request">
<h2>Convert DICOM Pubsub message to Qido search request<a class="headerlink" href="#convert-dicom-pubsub-message-to-qido-search-request" title="Permalink to this headline"></a></h2>
<p>Healthcare API users might read messages from Pubsub to monitor the store
operations (e.g. new file) in a DICOM storage. Pubsub message encode
DICOM as a web store path as well as instance ids. If users are interested in
getting new instance’s metadata, they can use the <cite>FormatToQido</cite> transform
to convert the message into Qido Search dict then use the <cite>DicomSearch</cite>
transform. Here is a sample usage:</p>
<blockquote>
<div>pipeline_options = PipelineOptions()
pipeline_options.view_as(StandardOptions).streaming = True
p = beam.Pipeline(options=pipeline_options)
pubsub = p | beam.io.ReadStringFromPubsub(subscription=’a_dicom_store’)
results = pubsub | FormatToQido()
success = results | ‘filter message’ &gt;&gt; beam.Filter(lambda x: x[‘success’])
qido_dict = success | ‘get qido request’ &gt;&gt; beam.Map(lambda x: x[‘result’])
metadata = qido_dict | DicomSearch()</div></blockquote>
<p>In the example above, the pipeline is listening to a pubsub topic and waiting
for messages from DICOM API. When a new DICOM file comes into the storage, the
pipeline will receive a pubsub message, convert it to a Qido request dict and
feed it to DicomSearch() PTransform. As a result, users can get the metadata for
every new DICOM file. Note that not every pubsub message received is from DICOM
API, so we to filter the results first.</p>
</div>
<div class="section" id="store-a-dicom-file-in-a-dicom-storage">
<h2>Store a DICOM file in a DICOM storage<a class="headerlink" href="#store-a-dicom-file-in-a-dicom-storage" title="Permalink to this headline"></a></h2>
<p>UploadToDicomStore() wraps store request API and users can use it to send a
DICOM file to a DICOM store. It supports two types of input: 1.file data in
byte[] 2.fileio object. Users should set the ‘input_type’ when initialzing
this PTransform. Here are the examples:</p>
<blockquote>
<div><dl class="docutils">
<dt>with Pipeline() as p:</dt>
<dd>input_dict = {‘project_id’: ‘abc123’, ‘type’: ‘instances’,…}
path = “gcs://bucketname/something/a.dcm”
match = p | fileio.MatchFiles(path)
fileio_obj = match | fileio.ReadAll()
results = fileio_obj | UploadToDicomStore(input_dict, ‘fileio’)</dd>
<dt>with Pipeline() as p:</dt>
<dd>input_dict = {‘project_id’: ‘abc123’, ‘type’: ‘instances’,…}
f = open(“abc.dcm”, “rb”)
dcm_file = f.read()
byte_file = p | ‘create byte file’ &gt;&gt; beam.Create([dcm_file])
results = byte_file | UploadToDicomStore(input_dict, ‘bytes’)</dd>
</dl>
</div></blockquote>
<p>The first example uses a PCollection of fileio objects as input.
UploadToDicomStore will read DICOM files from the objects and send them
to a DICOM storage.
The second example uses a PCollection of byte[] as input. UploadToDicomStore
will directly send those DICOM files to a DICOM storage.
Users can also get the operation results in the output PCollection if they want
to handle the failed store requests.</p>
<dl class="class">
<dt id="apache_beam.io.gcp.dicomio.DicomSearch">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.dicomio.</code><code class="descname">DicomSearch</code><span class="sig-paren">(</span><em>buffer_size=8</em>, <em>max_workers=5</em>, <em>client=None</em>, <em>credential=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/dicomio.html#DicomSearch"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.dicomio.DicomSearch" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.ptransform.html#apache_beam.transforms.ptransform.PTransform" title="apache_beam.transforms.ptransform.PTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.ptransform.PTransform</span></code></a></p>
<p>A PTransform used for retrieving DICOM instance metadata from Google
Cloud DICOM store. It takes a PCollection of dicts as input and return
a PCollection of dict as results:
INPUT:
The input dict represents DICOM web path parameters, which has the following
string keys and values:
{
‘project_id’: str,
‘region’: str,
‘dataset_id’: str,
‘dicom_store_id’: str,
‘search_type’: str,
‘params’: dict(str,str) (Optional),
}</p>
<dl class="docutils">
<dt>Key-value pairs:</dt>
<dd><p class="first">project_id: Id of the project in which the DICOM store is
located. (Required)
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, could only be one of the three
values: ‘instances’, ‘series’, or ‘studies’. (Required)
params: A dict of str:str pairs used to refine QIDO search. (Optional)
Supported tags in three categories:
1.Studies:
* StudyInstanceUID,
* PatientName,
* PatientID,
* AccessionNumber,
* ReferringPhysicianName,
* StudyDate,
2.Series: all study level search terms and
* SeriesInstanceUID,
* Modality,
3.Instances: all study/series level search terms and
* SOPInstanceUID,</p>
<p class="last">e.g. {“StudyInstanceUID”:”1”,”SeriesInstanceUID”:”2”}</p>
</dd>
</dl>
<p>OUTPUT:
The output dict wraps results as well as error messages:
{
‘result’: a list of dicts in JSON style.
‘success’: boolean value telling whether the operation is successful.
‘input’: detail ids and dicomweb path for this retrieval.
‘status’: status code from the server, used as error message.
}</p>
<p>Initializes DicomSearch.
:param buffer_size: # type: Int. Size of the request buffer.
:param max_workers: # type: Int. Maximum number of threads a worker can
:param create. If it is set to one, all the request will be processed:
:param sequentially in a worker.:
:param client: # type: object. If it is specified, all the Api calls will
:param made by this client instead of the default one:
:type made by this client instead of the default one: DicomApiHttpClient
:param credential: # type: Google credential object, if it is specified, the
:param Http client will use it to create sessions instead of the default.:</p>
<dl class="method">
<dt id="apache_beam.io.gcp.dicomio.DicomSearch.expand">
<code class="descname">expand</code><span class="sig-paren">(</span><em>pcoll</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/dicomio.html#DicomSearch.expand"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.dicomio.DicomSearch.expand" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.dicomio.FormatToQido">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.dicomio.</code><code class="descname">FormatToQido</code><span class="sig-paren">(</span><em>credential=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/dicomio.html#FormatToQido"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.dicomio.FormatToQido" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.ptransform.html#apache_beam.transforms.ptransform.PTransform" title="apache_beam.transforms.ptransform.PTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.ptransform.PTransform</span></code></a></p>
<p>A PTransform for converting pubsub messages into search input dict.
Takes PCollection of string as input and returns a PCollection of dict as
results. Note that some pubsub messages may not be from DICOM API, which
will be recorded as failed conversions.
INPUT:
The input are normally strings from Pubsub topic:
“projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/
dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID/
series/SERIES_UID/instances/INSTANCE_UID”</p>
<p>OUTPUT:
The output dict encodes results as well as error messages:
{
‘result’: a dict representing instance level qido search request.
‘success’: boolean value telling whether the conversion is successful.
‘input’: input pubsub message string.
}</p>
<p>Initializes FormatToQido.
:param credential: # type: Google credential object, if it is specified, the
:param Http client will use it instead of the default one.:</p>
<dl class="method">
<dt id="apache_beam.io.gcp.dicomio.FormatToQido.expand">
<code class="descname">expand</code><span class="sig-paren">(</span><em>pcoll</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/dicomio.html#FormatToQido.expand"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.dicomio.FormatToQido.expand" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.dicomio.UploadToDicomStore">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.dicomio.</code><code class="descname">UploadToDicomStore</code><span class="sig-paren">(</span><em>destination_dict</em>, <em>input_type</em>, <em>buffer_size=8</em>, <em>max_workers=5</em>, <em>client=None</em>, <em>credential=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/dicomio.html#UploadToDicomStore"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.dicomio.UploadToDicomStore" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.ptransform.html#apache_beam.transforms.ptransform.PTransform" title="apache_beam.transforms.ptransform.PTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.ptransform.PTransform</span></code></a></p>
<p>A PTransform for storing instances to a DICOM store.
Takes PCollection of byte[] as input and return a PCollection of dict as
results. The inputs are normally DICOM file in bytes or str filename.
INPUT:
This PTransform supports two types of input:
1. Byte[]: representing dicom file.
2. Fileio object: stream file object.</p>
<p>OUTPUT:
The output dict encodes status as well as error messages:
{
‘success’: boolean value telling whether the store is successful.
‘input’: undeliverable data. Exactly the same as the input,
only set if the operation is failed.
‘status’: status code from the server, used as error messages.
}</p>
<p>Initializes UploadToDicomStore.
:param destination_dict: # type: python dict, encodes DICOM endpoint information:
:param {:
:param ‘project_id’: str,
:param ‘region’: str,
:param ‘dataset_id’: str,
:param ‘dicom_store_id’: str,
:param }:
:param Key-value pairs:
:param * project_id: Id of the project in which DICOM store locates. (Required)
:param * region: Region where the DICOM store resides. (Required)
:param * dataset_id: Id of the dataset where DICOM store belongs to. (Required)
:param * dicom_store_id: Id of the dicom store. (Required)
:param input_type: # type: string, could only be ‘bytes’ or ‘fileio’
:param buffer_size: # type: Int. Size of the request buffer.
:param max_workers: # type: Int. Maximum number of threads a worker can
:param create. If it is set to one, all the request will be processed:
:param sequentially in a worker.:
:param client: # type: object. If it is specified, all the Api calls will
:param made by this client instead of the default one:
:type made by this client instead of the default one: DicomApiHttpClient
:param credential: # type: Google credential object, if it is specified, the
:param Http client will use it instead of the default one.:</p>
<dl class="method">
<dt id="apache_beam.io.gcp.dicomio.UploadToDicomStore.expand">
<code class="descname">expand</code><span class="sig-paren">(</span><em>pcoll</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/dicomio.html#UploadToDicomStore.expand"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.dicomio.UploadToDicomStore.expand" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="apache_beam.io.gcp.gce_metadata_util.html" class="btn btn-neutral float-right" title="apache_beam.io.gcp.gce_metadata_util module" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="apache_beam.io.gcp.dicomclient.html" class="btn btn-neutral float-left" title="apache_beam.io.gcp.dicomclient module" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>