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


##########
sdks/go/pkg/beam/io/fhirio/common.go:
##########
@@ -91,18 +98,61 @@ func (c *fhirStoreClientImpl) search(storePath, 
resourceType string, queries map
        }
 
        searchRequest := &healthcare.SearchResourcesRequest{}
+       fhirService := 
c.healthcareService.Projects.Locations.Datasets.FhirStores.Fhir
+
        if resourceType == "" {
-               return c.fhirService.Search(storePath, 
searchRequest).Do(queryParams...)
+               return fhirService.Search(storePath, 
searchRequest).Do(queryParams...)
+       }
+       return fhirService.SearchType(storePath, resourceType, 
searchRequest).Do(queryParams...)
+}
+
+func (c *fhirStoreClientImpl) deidentify(srcStorePath, dstStorePath string, 
deidConfig *healthcare.DeidentifyConfig) (operationResults, error) {
+       deidRequest := &healthcare.DeidentifyFhirStoreRequest{
+               Config:           deidConfig,
+               DestinationStore: dstStorePath,
+       }
+       operation, err := 
c.healthcareService.Projects.Locations.Datasets.FhirStores.Deidentify(srcStorePath,
 deidRequest).Do()
+       if err != nil {
+               return operationResults{}, err
+       }
+       return c.waitTillCompleteAndCollectResults(operation)
+}
+
+func (c *fhirStoreClientImpl) waitTillCompleteAndCollectResults(operation 
*healthcare.Operation) (operationResults, error) {
+       var err error
+       for !operation.Done {
+               time.Sleep(5 * time.Second)

Review Comment:
   You should poll for longer between checking the operation - these operations 
run for a while usually, so we're wasting time. 
   
   You can see a PR I did this in for Java: 
https://github.com/apache/beam/pull/15921, looks like I chose 15 seconds so 
that should be fine.



##########
sdks/go/pkg/beam/io/fhirio/utils_test.go:
##########
@@ -118,19 +127,23 @@ func (m *fakeReaderCloser) Read(b []byte) (int, error) {
        return m.fakeRead(b)
 }
 
-func validateCounter(pipelineResult beam.PipelineResult, expectedCounterName 
string, expectedCount int) error {
-       counterResults := pipelineResult.Metrics().AllMetrics().Counters()
-       if len(counterResults) != 1 {
-               return fmt.Errorf("counterResults got length %v, expected %v", 
len(counterResults), 1)
+func validateCounter(t *testing.T, pipelineResult beam.PipelineResult, 
expectedCounterName string, expectedCount int) {
+       t.Helper()
+
+       counterResults := pipelineResult.Metrics().Query(func(mr 
beam.MetricResult) bool {
+               return mr.Name() == expectedCounterName
+       }).Counters()
+
+       if expectedCount == 0 && len(counterResults) == 0 {
+               return
        }
-       counterResult := counterResults[0]
 
-       if counterResult.Name() != expectedCounterName {
-               return fmt.Errorf("counterResult.Name() is '%v', expected 
'%v'", counterResult.Name(), expectedCounterName)
+       if len(counterResults) != 1 {
+               t.Fatalf("counter %v got length %v, expected %v", 
expectedCounterName, len(counterResults), 1)

Review Comment:
   It looks like this error string should be something like `got %v counters 
with name %v, expected 1`, correct? Am I understanding this? The error message 
kind of looks like you're saying we got the wrong results for the counter.



##########
sdks/go/pkg/beam/io/fhirio/common.go:
##########
@@ -91,18 +98,61 @@ func (c *fhirStoreClientImpl) search(storePath, 
resourceType string, queries map
        }
 
        searchRequest := &healthcare.SearchResourcesRequest{}
+       fhirService := 
c.healthcareService.Projects.Locations.Datasets.FhirStores.Fhir
+
        if resourceType == "" {
-               return c.fhirService.Search(storePath, 
searchRequest).Do(queryParams...)
+               return fhirService.Search(storePath, 
searchRequest).Do(queryParams...)
+       }
+       return fhirService.SearchType(storePath, resourceType, 
searchRequest).Do(queryParams...)
+}
+
+func (c *fhirStoreClientImpl) deidentify(srcStorePath, dstStorePath string, 
deidConfig *healthcare.DeidentifyConfig) (operationResults, error) {
+       deidRequest := &healthcare.DeidentifyFhirStoreRequest{
+               Config:           deidConfig,
+               DestinationStore: dstStorePath,
+       }
+       operation, err := 
c.healthcareService.Projects.Locations.Datasets.FhirStores.Deidentify(srcStorePath,
 deidRequest).Do()
+       if err != nil {
+               return operationResults{}, err
+       }
+       return c.waitTillCompleteAndCollectResults(operation)
+}
+
+func (c *fhirStoreClientImpl) waitTillCompleteAndCollectResults(operation 
*healthcare.Operation) (operationResults, error) {

Review Comment:
   nit till->til and wait->poll



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