youngoli commented on code in PR #21979:
URL: https://github.com/apache/beam/pull/21979#discussion_r908028045
##########
sdks/go/test/integration/io/fhirio/fhirio_test.go:
##########
@@ -228,6 +229,101 @@ func TestFhirIO_ExecuteBundles(t *testing.T) {
ptest.RunAndValidate(t, p)
}
+func TestFhirIO_Search_SelectAll(t *testing.T) {
Review Comment:
Integration tests are expensive to spin up and test for each pipeline used,
so I would encourage limiting the number you have as much as possible. In this
situation I think you can probably consolidate all the stuff you're testing to
one pipeline since they all use the same FhirStore data, just use multiple
Search transforms, or consolidate testing coverage through one Search transform
(ex. testing ResourceType, parameters, and pagination all with one search
query). And if any of these tests work just fine as unit tests, that's a better
alternative (pagination for example strikes me as suited for a unit test).
##########
sdks/go/pkg/beam/io/fhirio/common.go:
##########
@@ -23,31 +23,33 @@ import (
"context"
"io"
"net/http"
- "regexp"
"time"
"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core"
"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors"
+ "google.golang.org/api/googleapi"
"google.golang.org/api/healthcare/v1"
"google.golang.org/api/option"
)
const (
- UserAgent = "apache-beam-io-google-cloud-platform-healthcare/" +
core.SdkVersion
- baseMetricPrefix = "fhirio/"
+ UserAgent =
"apache-beam-io-google-cloud-platform-healthcare/" + core.SdkVersion
+ baseMetricPrefix = "fhirio/"
+ pageTokenParameterKey = "_page_token"
)
-func executeRequestAndRecordLatency(ctx context.Context, latencyMs
*beam.Distribution, requestSupplier func() (*http.Response, error))
(*http.Response, error) {
+func executeAndRecordLatency[T any](ctx context.Context, latencyMs
*beam.Distribution, executionSupplier func() (T, error)) (T, error) {
Review Comment:
@lostluck Are we good to use generics in Go SDK IOs?
##########
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:
style nit: This line is so long it impacts legibility.
I think you should either split this apart to multiple lines (while loop
style) or use much shorter variable names (Go style conventions usually
recommend local variables of only a few letters anyway). I think renaming to
`res`, `pageRes`, and `token` is still equally descriptive.
--
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]