lnogueir commented on code in PR #22152:
URL: https://github.com/apache/beam/pull/22152#discussion_r919359288


##########
sdks/go/pkg/beam/io/fhirio/deidentify.go:
##########
@@ -0,0 +1,93 @@
+// 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 fhirio provides an API for reading and writing resources to Google
+// Cloud Healthcare Fhir stores.
+// Experimental.
+package fhirio
+
+import (
+       "context"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/log"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/register"
+       "google.golang.org/api/healthcare/v1"
+)
+
+func init() {
+       register.DoFn3x0[context.Context, string, 
func(string)]((*deidentifyFn)(nil))
+       register.Emitter1[string]()
+}
+
+type deidentifyFn struct {
+       fnCommonVariables
+       DestinationStorePath  string
+       DeidentifyConfig      *healthcare.DeidentifyConfig
+       operationErrorCount   beam.Counter
+       operationSuccessCount beam.Counter
+}
+
+func (fn deidentifyFn) String() string {
+       return "deidentifyFn"
+}
+
+func (fn *deidentifyFn) Setup() {
+       fn.fnCommonVariables.setup(fn.String())
+       fn.operationErrorCount = beam.NewCounter(fn.String(), 
operationErrorCounterName)
+       fn.operationSuccessCount = beam.NewCounter(fn.String(), 
operationSuccessCounterName)
+}
+
+func (fn *deidentifyFn) ProcessElement(ctx context.Context, srcStorePath 
string, emitDstStore func(string)) {
+       result, err := executeAndRecordLatency(ctx, &fn.latencyMs, func() 
(operationResults, error) {
+               return fn.client.deidentify(srcStorePath, 
fn.DestinationStorePath, fn.DeidentifyConfig)
+       })
+       if err != nil {
+               log.Warnf(ctx, "Deidentify operation failed. Reason: %v", err)
+               fn.operationErrorCount.Inc(ctx, 1)
+               return
+       }
+
+       fn.operationSuccessCount.Inc(ctx, 1)
+       fn.resourcesSuccessCount.Inc(ctx, result.Successes)
+       fn.resourcesErrorCount.Inc(ctx, result.Failures)
+       emitDstStore(fn.DestinationStorePath)
+}
+
+// Deidentify transform de-identifies sensitive data in resources located in a
+// Google Cloud FHIR store. It receives a source and destination store paths as
+// well as de-identification configuration (
+// 
https://cloud.google.com/healthcare-api/docs/reference/rest/v1/DeidentifyConfig#FhirConfig).
+// It performs de-identification on the source store using the provided
+// configuration and applies the result in the destination store. It outputs a
+// PCollection containing the destination store path if de-identification was
+// performed successfully, otherwise it returns an empty PCollection.
+// See: https://cloud.google.com/healthcare-api/docs/how-tos/fhir-deidentify
+func Deidentify(s beam.Scope, srcStore, dstStore string, config 
*healthcare.DeidentifyConfig) beam.PCollection {
+       s = s.Scope("fhirio.Deidentify")
+       return deidentify(s, srcStore, dstStore, config, nil)
+}
+
+func deidentify(s beam.Scope, srcStore, dstStore string, config 
*healthcare.DeidentifyConfig, client fhirStoreClient) beam.PCollection {
+       return beam.ParDo(
+               s,
+               &deidentifyFn{
+                       fnCommonVariables:    fnCommonVariables{client: client},
+                       DestinationStorePath: dstStore,
+                       DeidentifyConfig:     config,
+               },
+               beam.Create(s, srcStore),

Review Comment:
   Yes, this transform is meant to be a Source. Thanks for pointing it out 
about the `Impulse` transform, I wasn't aware of it.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to