Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom schema in Healthcare HL7 V2 stores #3261

Merged
merged 21 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion products/healthcare/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,28 @@ objects:
at_least_one_of:
- parser_config.0.allow_null_header
- parser_config.0.segment_terminator
- parser_config.0.schema
description: |
Determines whether messages with no header are allowed.
- !ruby/object:Api::Type::String
name: segmentTerminator
at_least_one_of:
- parser_config.0.allow_null_header
- parser_config.0.segment_terminator
- parser_config.0.schema
description: |
Byte(s) to be used as the segment terminator. If this is unset, '\r' will be used as segment terminator.

A base64-encoded string.

- !ruby/object:Api::Type::String
name: schema
at_least_one_of:
- parser_config.0.allow_null_header
- parser_config.0.segment_terminator
- parser_config.0.schema
description: |
JSON encoded string for schemas used to parse messages in this
store if schematized parsing is desired.
- !ruby/object:Api::Type::KeyValuePairs
name: labels
required: false
Expand Down
17 changes: 15 additions & 2 deletions products/healthcare/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,28 @@ overrides: !ruby/object:Overrides::ResourceOverrides
examples:
- !ruby/object:Provider::Terraform::Examples
name: "healthcare_hl7_v2_store_basic"
skip_test: true
primary_resource_id: "default"
min_version: beta
primary_resource_id: "store"
vars:
dataset_name: "example-dataset"
hl7_v2_store_name: "example-hl7-v2-store"
pubsub_topic: "hl7-v2-notifications"
- !ruby/object:Provider::Terraform::Examples
name: "healthcare_hl7_v2_store_parser_config"
min_version: beta
primary_resource_id: "store"
vars:
dataset_name: "example-dataset"
hl7_v2_store_name: "example-hl7-v2-store"
properties:
creationTime: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
parserConfig.schema: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb'
custom_flatten: 'templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb'
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.ValidateJsonString'
selfLink: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%- # the license inside this block applies to this file
# Copyright 2020 Google Inc.
# Licensed 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.
-%>
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
b := []byte(v.(string))
if len(b) == 0 {
return nil, nil
}
m := make(map[string]interface{})
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
return m, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%# The license inside this block applies to this file.
# Copyright 2020 Google Inc.
# Licensed 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
b, err := json.Marshal(v)
if err != nil {
// TODO: return error once https://github.com/GoogleCloudPlatform/magic-modules/issues/3257 is fixed.
log.Printf("[ERROR] failed to marshal schema to JSON: %v", err)
}
return string(b)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ resource "google_healthcare_hl7_v2_store" "default" {
name = "<%= ctx[:vars]['hl7_v2_store_name'] %>"
dataset = google_healthcare_dataset.dataset.id

parser_config {
allow_null_header = false
segment_terminator = "Jw=="
}

notification_config {
pubsub_topic = google_pubsub_topic.topic.id
}

labels = {
label1 = "labelvalue1"
}

provider = google-beta
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
resource "google_healthcare_hl7_v2_store" "default" {
provider = google-beta
name = "<%= ctx[:vars]['hl7_v2_store_name'] %>"
dataset = google_healthcare_dataset.dataset.id

parser_config {
allow_null_header = false
segment_terminator = "Jw=="
schema = jsonencode({
umairidris marked this conversation as resolved.
Show resolved Hide resolved
"schemas": [{
"messageSchemaConfigs": {
"ADT_A01": {
"name": "ADT_A01",
"minOccurs": 1,
"maxOccurs": 1,
"members": [{
"segment": {
"type": "MSH",
"minOccurs": 1,
"maxOccurs": 1
}
},
{
"segment": {
"type": "EVN",
"minOccurs": 1,
"maxOccurs": 1
}
},
{
"segment": {
"type": "PID",
"minOccurs": 1,
"maxOccurs": 1
}
},
{
"segment": {
"type": "ZPD",
"minOccurs": 1,
"maxOccurs": 1
}
},
{
"segment": {
"type": "OBX"
}
},
{
"group": {
"name": "PROCEDURE",
"members": [{
"segment": {
"type": "PR1",
"minOccurs": 1,
"maxOccurs": 1
}
},
{
"segment": {
"type": "ROL"
}
}
]
}
},
{
"segment": {
"type": "PDA",
"maxOccurs": 1
}
}
]
}
}
}],
"types": [{
"type": [{
"name": "ZPD",
"primitive": "VARIES"
}

umairidris marked this conversation as resolved.
Show resolved Hide resolved
]
}],
"ignoreMinOccurs": true
})
}
}

resource "google_healthcare_dataset" "dataset" {
provider = google-beta
name = "<%= ctx[:vars]['dataset_name'] %>"
location = "us-central1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,6 @@ resource "google_pubsub_topic" "topic" {
`, hl7_v2StoreName, datasetName, pubsubTopic)
}

func testAccCheckHealthcareHl7V2StoreDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_healthcare_hl7_v2_store" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{HealthcareBasePath}}{{dataset}}/hl7V2Stores/{{name}}")
if err != nil {
return err
}

_, err = sendRequest(config, "GET", "", url, nil)
if err == nil {
return fmt.Errorf("HealthcareHl7V2Store still exists at %s", url)
}
}

return nil
}
}

func testAccCheckGoogleHealthcareHl7V2StoreUpdate(t *testing.T, pubsubTopic string) resource.TestCheckFunc {
return func(s *terraform.State) error {
var foundResource = false
Expand Down