forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom schema in Healthcare HL7 V2 stores (GoogleCloudPlatfor…
…m#3261) * add schema field and custom expander * rename * fix custom expand file ref * add custom flatten * actually add the files * rm extra file * add state and validate funcs * single line * shorter var * don't return error on flatten * Update templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb Co-Authored-By: Dana Hoffman <[email protected]> * Apply suggestions from code review Co-Authored-By: Dana Hoffman <[email protected]> * enable test for parser config * add schema eample * rm dup func, enable basic hl7 test * min version beta * fix examples * fix flatten * heredoc Co-authored-by: Dana Hoffman <[email protected]>
- Loading branch information
1 parent
3ff3649
commit 16fe512
Showing
7 changed files
with
173 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
25 changes: 25 additions & 0 deletions
25
templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
templates/terraform/examples/healthcare_hl7_v2_store_parser_config.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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 = <<EOF | ||
{ | ||
"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" | ||
} | ||
|
||
] | ||
}], | ||
"ignoreMinOccurs": true | ||
} | ||
EOF | ||
} | ||
} | ||
|
||
resource "google_healthcare_dataset" "dataset" { | ||
provider = google-beta | ||
name = "<%= ctx[:vars]['dataset_name'] %>" | ||
location = "us-central1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters