[ 
https://issues.apache.org/jira/browse/BEAM-11073?focusedWorklogId=511092&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-511092
 ]

ASF GitHub Bot logged work on BEAM-11073:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Nov/20 22:32
            Start Date: 12/Nov/20 22:32
    Worklog Time Spent: 10m 
      Work Description: Aliraza-N commented on a change in pull request #13137:
URL: https://github.com/apache/beam/pull/13137#discussion_r522474275



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/DicomIO.java
##########
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.gcp.healthcare;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionTuple;
+import org.apache.beam.sdk.values.PInput;
+import org.apache.beam.sdk.values.POutput;
+import org.apache.beam.sdk.values.PValue;
+import org.apache.beam.sdk.values.TupleTag;
+import org.apache.beam.sdk.values.TupleTagList;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
+
+/**
+ * The DicomIO connectors allows Beam pipelines to make calls to the Dicom API 
of the Google Cloud
+ * Healthcare API 
(https://cloud.google.com/healthcare/docs/how-tos#dicom-guide).
+ *
+ * <h3>Reading Study-Level Metadata</h3>
+ *
+ * The study-level metadata for a dicom instance can be read with {@link 
ReadStudyMetadata}.
+ * Retrieve the metadata of a dicom instance given its store path as a string. 
This will return a
+ * {@link ReadStudyMetadata.Result}. You can fetch the successful calls using 
getReadResponse(), and
+ * any failed reads using getFailedReads().
+ *
+ * <h3>Example</h3>
+ *
+ * {@code Pipeline p = ... String webPath = ... 
DicomIO.ReadStudyMetadata.Result readMetadataResult
+ * = p .apply(Create.of(webPath)) PCollection<String> goodRead =
+ * readMetadataResult.getReadResponse() PCollection<String> failRead =
+ * readMetadataResult.getFailedReads() }
+ */
+public class DicomIO {
+
+  public static ReadStudyMetadata readStudyMetadata() {
+    return new ReadStudyMetadata();
+  }
+
+  /**
+   * This class makes a call to the retrieve metadata endpoint
+   * 
(https://cloud.google.com/healthcare/docs/how-tos/dicomweb#retrieving_metadata).
 It defines a
+   * function that can be used to process a Pubsub message from a DICOM store, 
read the DICOM study
+   * path and get the metadata of the specified study. You can learn how to 
configure PubSub
+   * messages to be published when an instance is stored by following:
+   * https://cloud.google.com/healthcare/docs/how-tos/pubsub. The connector 
will output a {@link
+   * ReadStudyMetadata.Result} which will contain metadata of the study 
encoded as a json array.
+   */
+  public static class ReadStudyMetadata
+      extends PTransform<PCollection<String>, ReadStudyMetadata.Result> {
+
+    private ReadStudyMetadata() {}
+
+    /** TupleTag for the main output. */
+    public static final TupleTag<String> METADATA = new TupleTag<String>() {};
+    /** TupleTag for any error response. */
+    public static final TupleTag<String> ERROR_MESSAGE = new 
TupleTag<String>() {};
+
+    public static class Result implements POutput, PInput {
+      private PCollection<String> readResponse;
+
+      private PCollection<String> failedReads;
+
+      /** Contains both the response and error outputs from the 
transformation. */
+      PCollectionTuple pct;
+
+      /**
+       * Create DicomIO.ReadStudyMetadata.Result from PCollectionTuple which 
contains the response
+       * (with METADATA and ERROR_MESSAGE tags).
+       *
+       * @param pct the pct
+       * @return the read result
+       * @throws IllegalArgumentException the illegal argument exception
+       */
+      static ReadStudyMetadata.Result of(PCollectionTuple pct) throws 
IllegalArgumentException {
+        if (pct.getAll()
+            .keySet()
+            .containsAll((Collection<?>) 
TupleTagList.of(METADATA).and(ERROR_MESSAGE))) {
+          return new ReadStudyMetadata.Result(pct);
+        } else {
+          throw new IllegalArgumentException(
+              "The PCollection tuple must have the 
DicomIO.ReadStudyMetadata.METADATA "
+                  + "and DicomIO.ReadStudyMetadata.ERROR_MESSAGE tuple tags");
+        }
+      }
+
+      private Result(PCollectionTuple pct) {
+        this.pct = pct;
+        this.readResponse = pct.get(METADATA);
+        this.failedReads = pct.get(ERROR_MESSAGE);
+      }
+
+      /**
+       * Gets failed reads.
+       *
+       * @return the failed reads
+       */
+      public PCollection<String> getFailedReads() {
+        return failedReads;
+      }
+
+      /**
+       * Gets resources.
+       *
+       * @return the resources
+       */
+      public PCollection<String> getReadResponse() {
+        return readResponse;
+      }
+
+      @Override
+      public Pipeline getPipeline() {
+        return this.pct.getPipeline();
+      }
+
+      @Override
+      public Map<TupleTag<?>, PValue> expand() {
+        return ImmutableMap.of(METADATA, readResponse);
+      }
+
+      @Override
+      public void finishSpecifyingOutput(
+          String transformName, PInput input, PTransform<?, ?> transform) {}
+    }
+
+    /**
+     * DoFn to fetch the metadata of a study from a Dicom store based on it's 
location and study id.
+     */
+    @SuppressWarnings({"nullness", "rawtypes"})
+    static class FetchStudyMetadataFn extends DoFn<String, String> {
+
+      private HealthcareApiClient dicomStore;

Review comment:
       Hmm I'm still failing compileJava. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 511092)
    Time Spent: 6.5h  (was: 6h 20m)

> GCP HCLS Api - Dicom IO Connector for Java
> ------------------------------------------
>
>                 Key: BEAM-11073
>                 URL: https://issues.apache.org/jira/browse/BEAM-11073
>             Project: Beam
>          Issue Type: New Feature
>          Components: io-java-gcp
>            Reporter: Aliraza Nagamia
>            Assignee: Aliraza Nagamia
>            Priority: P2
>          Time Spent: 6.5h
>  Remaining Estimate: 0h
>
> We are looking to create a new Java Pipeline Connector to help facilitate 
> Reading data from the Imaging API in GCP. Initially, this connector will be 
> used to read study level metadata of Dicom instances.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to