You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/28 16:03:27 UTC

[GitHub] [beam] lnogueir commented on a diff in pull request #21979: Add Search transform to Go FhirIO

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


##########
sdks/go/pkg/beam/io/fhirio/search.go:
##########
@@ -0,0 +1,165 @@
+// 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"
+	"encoding/json"
+	"net/url"
+	"strings"
+
+	"github.com/apache/beam/sdks/v2/go/pkg/beam"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/register"
+)
+
+func init() {
+	register.DoFn4x0[context.Context, SearchQuery, func(string, []string), func(string)]((*searchResourcesFn)(nil))
+	register.Emitter1[string]()
+	register.Emitter2[string, []string]()
+}
+
+// SearchQuery concisely represents a FHIR search query, and should be used as
+// input type for the Search transform.
+type SearchQuery struct {
+	// An identifier for the query, if there is source information to propagate
+	// through the pipeline.
+	Identifier string
+	// Search will be performed only on resources of type ResourceType. If not set
+	// (i.e. ""), the search is performed across all resources.
+	ResourceType string
+	// Query parameters for a FHIR search request as per https://www.hl7.org/fhir/search.html.
+	Parameters map[string]string
+}
+
+type responseLinkFields struct {
+	Relation string `json:"relation"`
+	Url      string `json:"url"`
+}
+
+type searchResourcesFn struct {
+	fnCommonVariables
+	// Path to FHIR store where search will be performed.
+	FhirStorePath string
+}
+
+func (fn searchResourcesFn) String() string {
+	return "searchResourcesFn"
+}
+
+func (fn *searchResourcesFn) Setup() {
+	fn.fnCommonVariables.setup(fn.String())
+}
+
+func (fn *searchResourcesFn) ProcessElement(ctx context.Context, query SearchQuery, emitFoundResources func(string, []string), emitDeadLetter func(string)) {
+	resourcesFound, err := executeAndRecordLatency(ctx, &fn.latencyMs, func() ([]string, error) {
+		return fn.searchResources(query)
+	})
+	if err != nil {
+		fn.resourcesErrorCount.Inc(ctx, 1)
+		emitDeadLetter(errors.Wrapf(err, "error occurred while performing search for query: [%v]", query).Error())
+		return
+	}
+
+	fn.resourcesSuccessCount.Inc(ctx, 1)
+	emitFoundResources(query.Identifier, resourcesFound)
+}
+
+func (fn *searchResourcesFn) searchResources(query SearchQuery) ([]string, error) {
+	var (
+		allResources, resourcesInPage []string
+		nextPageToken                 string
+		err                           error
+	)
+	for resourcesInPage, nextPageToken, err = fn.searchResourcesPaginated(query, ""); nextPageToken != ""; resourcesInPage, nextPageToken, err = fn.searchResourcesPaginated(query, nextPageToken) {

Review Comment:
   Agreed. This line was bothering me too. Changed to while loop style



-- 
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: github-unsubscribe@beam.apache.org

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