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

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

                Author: ASF GitHub Bot
            Created on: 15/Mar/20 03:03
            Start Date: 15/Mar/20 03:03
    Worklog Time Spent: 10m 
      Work Description: jaketf commented on pull request #11107: [BEAM-9468] 
[WIP] add HL7v2IO and FhirIO
URL: https://github.com/apache/beam/pull/11107#discussion_r392636894
 
 

 ##########
 File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java
 ##########
 @@ -0,0 +1,187 @@
+/*
+ * 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 com.google.api.services.healthcare.v1alpha2.model.HttpBody;
+import com.google.auto.value.AutoValue;
+import java.io.IOException;
+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.PDone;
+
+/**
+ * {@link FhirIO} provides an API for writing resources to <a
+ * href="https://cloud.google.com/healthcare/docs/concepts/fhir";>Google Cloud 
Healthcare Fhir API.
+ * </a>
+ */
+public class FhirIO {
+
+  /** The type Write. */
+  @AutoValue
+  public abstract static class Write extends PTransform<PCollection<HttpBody>, 
PDone> {
+
+    /** The enum Write method. */
+    public enum WriteMethod {
+      /**
+       * Execute Bundle Method executes a batch of requests as a single 
transaction @see <a
+       * 
href=https://cloud.google.com/healthcare/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/executeBundle></a>.
+       */
+      EXECUTE_BUNDLE,
+      /**
+       * Create Method creates a single FHIR resource @see <a
+       * 
href=https://cloud.google.com/healthcare/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/create></a>.
+       */
+      CREATE
+    }
+
+    /**
+     * Gets Fhir store.
+     *
+     * @return the Fhir store
+     */
+    abstract String getFhirStore();
+
+    /**
+     * Gets write method.
+     *
+     * @return the write method
+     */
+    abstract WriteMethod getWriteMethod();
+
+    /** The type Builder. */
+    @AutoValue.Builder
+    abstract static class Builder {
+
+      /**
+       * Sets Fhir store.
+       *
+       * @param fhirStore the Fhir store
+       * @return the Fhir store
+       */
+      abstract Builder setFhirStore(String fhirStore);
+
+      /**
+       * Sets write method.
+       *
+       * @param writeMethod the write method
+       * @return the write method
+       */
+      abstract Builder setWriteMethod(WriteMethod writeMethod);
+
+      /**
+       * Build write.
+       *
+       * @return the write
+       */
+      abstract Write build();
+    }
+
+    private static Write.Builder write(String fhirStore) {
+      return new AutoValue_FhirIO_Write.Builder().setFhirStore(fhirStore);
+    }
+
+    /**
+     * Create Method creates a single FHIR resource. @see <a
+     * 
href=https://cloud.google.com/healthcare/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/create></a>
+     *
+     * @param fhirStore the hl 7 v 2 store
+     * @return the write
+     */
+    public static Write create(String fhirStore) {
+      return new AutoValue_FhirIO_Write.Builder()
+          .setFhirStore(fhirStore)
+          .setWriteMethod(Write.WriteMethod.CREATE)
+          .build();
+    }
+
+    /**
+     * Execute Bundle Method executes a batch of requests as a single 
transaction @see <a
+     * 
href=https://cloud.google.com/healthcare/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/executeBundle></a>.
+     *
+     * @param fhirStore the hl 7 v 2 store
+     * @return the write
+     */
+    public static Write executeBundles(String fhirStore) {
+      return new AutoValue_FhirIO_Write.Builder()
+          .setFhirStore(fhirStore)
+          .setWriteMethod(WriteMethod.EXECUTE_BUNDLE)
+          .build();
+    }
+
+    @Override
+    public PDone expand(PCollection<HttpBody> messages) {
+      messages.apply(ParDo.of(new WriteFhirFn(this.getFhirStore(), 
this.getWriteMethod())));
+      return PDone.in(messages.getPipeline());
+    }
+  }
+
+  /** The type Write Fhir fn. */
+  static class WriteFhirFn extends DoFn<HttpBody, PDone> {
+    // TODO when the healthcare API releases a bulk import method this should 
use that to improve
+    // throughput.
+
+    private transient HealthcareApiClient client;
 
 Review comment:
   The lifecycle of a DoFn (IMHO described best in this [SO 
Post](https://stackoverflow.com/questions/45985753/what-is-the-difference-between-dofn-setup-and-dofn-startbundle))
 tells us that a JVM process responsible for running this DoFn, the `@Setup` 
annotated method initClient will always be called before the the 
`@ProcessElement` annotated method.
   
   I will look out for NPEs here as I write the integration tests.
 
----------------------------------------------------------------
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: 403524)
    Time Spent: 1h 10m  (was: 1h)

> Add Google Cloud Healthcare API IO Connectors
> ---------------------------------------------
>
>                 Key: BEAM-9468
>                 URL: https://issues.apache.org/jira/browse/BEAM-9468
>             Project: Beam
>          Issue Type: New Feature
>          Components: io-java-gcp
>            Reporter: Jacob Ferriero
>            Priority: Minor
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> Add IO Transforms for the HL7v2, FHIR and DICOM stores in the [Google Cloud 
> Healthcare API|https://cloud.google.com/healthcare/docs/]
> HL7v2IO
> FHIRIO
> DICOMĀ 



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

Reply via email to