Skip to content

Commit d72064f

Browse files
authored
Merge pull request #140 from patientsknowbest/feature/15574-implement-structure-definition
Implement StructureDefinition PHR-15574
2 parents d4e3a83 + b0f2b90 commit d72064f

File tree

10 files changed

+568
-4
lines changed

10 files changed

+568
-4
lines changed

aidbox/structure_definition.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package aidbox
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
)
7+
8+
// StructureDefinition Represents a subset of the FHIR R4 spec "StructureDefinition", this is not a full support
9+
// for the resource. Used only to allow testing and temporarily support defining profiles
10+
type StructureDefinition struct {
11+
ResourceBase
12+
ResourceType string `json:"resourceType,omitempty"`
13+
Name string `json:"name"`
14+
Url string `json:"url"`
15+
BaseDefinition string `json:"baseDefinition"`
16+
Derivation string `json:"derivation"`
17+
Abstract bool `json:"abstract"`
18+
Type string `json:"type"`
19+
Status string `json:"status"`
20+
Kind string `json:"kind"`
21+
Version string `json:"version"`
22+
// Deliberately not doing more validation than "is json?" or adding a custom type as it's unnecessarily complex
23+
// to handle Element given the intention here is temporary and partial support. This leaves more chance for user
24+
// error, however we will print the details about any issues related to this property received from the server, so
25+
// the user can correct it anyway
26+
Differential *json.RawMessage `json:"differential"`
27+
}
28+
29+
func (*StructureDefinition) GetResourcePath() string {
30+
return "fhir/StructureDefinition"
31+
}
32+
33+
func (apiClient *ApiClient) CreateStructureDefinition(ctx context.Context, structureDefinition *StructureDefinition) (*StructureDefinition, error) {
34+
response := &StructureDefinition{}
35+
return response, apiClient.createResource(ctx, structureDefinition, response)
36+
}
37+
38+
func (apiClient *ApiClient) GetStructureDefinition(ctx context.Context, id string) (*StructureDefinition, error) {
39+
response := &StructureDefinition{}
40+
return response, apiClient.getResource(ctx, id, response)
41+
}
42+
43+
func (apiClient *ApiClient) UpdateStructureDefinition(ctx context.Context, q *StructureDefinition) (*StructureDefinition, error) {
44+
response := &StructureDefinition{}
45+
return response, apiClient.updateResource(ctx, q, response)
46+
}
47+
48+
func (apiClient *ApiClient) DeleteStructureDefinition(ctx context.Context, id string) error {
49+
return apiClient.deleteResource(ctx, id, &StructureDefinition{})
50+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "aidbox_structure_definition Resource - terraform-provider-aidbox"
4+
subcategory: ""
5+
description: |-
6+
FHIR R4 SearchParameter https://hl7.org/fhir/R4/searchparameter.html
7+
---
8+
9+
# aidbox_structure_definition (Resource)
10+
11+
FHIR R4 SearchParameter https://hl7.org/fhir/R4/searchparameter.html
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "aidbox_structure_definition" "patient_profile" {
17+
name = "patient-profile"
18+
url = "https://fhir.yourcompany.com/structuredefinition/patient"
19+
base_definition = "http://hl7.org/fhir/StructureDefinition/Patient"
20+
derivation = "constraint"
21+
abstract = false
22+
type = "Patient"
23+
status = "active"
24+
kind = "resource"
25+
version = "0.0.1"
26+
differential = <<-EOT
27+
{
28+
"element": [
29+
{
30+
"id": "Patient",
31+
"path": "Patient",
32+
"constraint": [
33+
{
34+
"key": "unique-system",
35+
"severity": "error",
36+
"human": "System must be unique among identifiers",
37+
"expression": "Patient.identifier.system.count() = Patient.identifier.system.distinct().count()"
38+
}
39+
]
40+
},
41+
{
42+
"id": "Patient.identifier",
43+
"path": "Patient.identifier",
44+
"min": 1
45+
},
46+
{
47+
"id": "Patient.identifier.system",
48+
"path": "Patient.identifier.system",
49+
"min": 1
50+
},
51+
{
52+
"id": "Patient.identifier.value",
53+
"path": "Patient.identifier.value",
54+
"min": 1
55+
},
56+
{
57+
"id": "Patient.managingOrganization",
58+
"path": "Patient.managingOrganization",
59+
"min": 1
60+
},
61+
{
62+
"id": "Patient.managingOrganization.reference",
63+
"path": "Patient.managingOrganization.reference",
64+
"min": 1
65+
}
66+
]
67+
}
68+
EOT
69+
}
70+
```
71+
72+
<!-- schema generated by tfplugindocs -->
73+
## Schema
74+
75+
### Required
76+
77+
- `abstract` (Boolean) Whether the structure is abstract
78+
- `base_definition` (String) Definition that this type is constrained/specialized from
79+
- `derivation` (String) Value of specialization | constraint
80+
- `differential` (String) The value of StructureDefinition.differential expressed as a raw JSON string value
81+
- `kind` (String) Value of primitive-type | complex-type | resource | logical
82+
- `name` (String) Computer friendly name of the resource
83+
- `status` (String) Value of draft | active | retired | unknown
84+
- `type` (String) The FHIR type defined or constrained by this structure
85+
- `url` (String) Canonical URL that's unique to this StructureDefinition
86+
- `version` (String) Business version of the structure definition
87+
88+
### Read-Only
89+
90+
- `id` (String) The ID of this resource.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
resource "aidbox_structure_definition" "patient_profile" {
2+
name = "patient-profile"
3+
url = "https://fhir.yourcompany.com/structuredefinition/patient"
4+
base_definition = "http://hl7.org/fhir/StructureDefinition/Patient"
5+
derivation = "constraint"
6+
abstract = false
7+
type = "Patient"
8+
status = "active"
9+
kind = "resource"
10+
version = "0.0.1"
11+
differential = <<-EOT
12+
{
13+
"element": [
14+
{
15+
"id": "Patient",
16+
"path": "Patient",
17+
"constraint": [
18+
{
19+
"key": "unique-system",
20+
"severity": "error",
21+
"human": "System must be unique among identifiers",
22+
"expression": "Patient.identifier.system.count() = Patient.identifier.system.distinct().count()"
23+
}
24+
]
25+
},
26+
{
27+
"id": "Patient.identifier",
28+
"path": "Patient.identifier",
29+
"min": 1
30+
},
31+
{
32+
"id": "Patient.identifier.system",
33+
"path": "Patient.identifier.system",
34+
"min": 1
35+
},
36+
{
37+
"id": "Patient.identifier.value",
38+
"path": "Patient.identifier.value",
39+
"min": 1
40+
},
41+
{
42+
"id": "Patient.managingOrganization",
43+
"path": "Patient.managingOrganization",
44+
"min": 1
45+
},
46+
{
47+
"id": "Patient.managingOrganization.reference",
48+
"path": "Patient.managingOrganization.reference",
49+
"min": 1
50+
}
51+
]
52+
}
53+
EOT
54+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/hashicorp/terraform-plugin-docs v0.22.0
1010
github.com/hashicorp/terraform-plugin-log v0.9.0
1111
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
12+
github.com/stretchr/testify v1.8.3
1213
)
1314

1415
require (
@@ -24,6 +25,7 @@ require (
2425
github.com/bgentry/speakeasy v0.1.0 // indirect
2526
github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect
2627
github.com/cloudflare/circl v1.6.1 // indirect
28+
github.com/davecgh/go-spew v1.1.1 // indirect
2729
github.com/fatih/color v1.17.0 // indirect
2830
github.com/golang/protobuf v1.5.4 // indirect
2931
github.com/google/go-cmp v0.7.0 // indirect
@@ -58,6 +60,7 @@ require (
5860
github.com/mitchellh/mapstructure v1.5.0 // indirect
5961
github.com/mitchellh/reflectwalk v1.0.2 // indirect
6062
github.com/oklog/run v1.1.0 // indirect
63+
github.com/pmezard/go-difflib v1.0.0 // indirect
6164
github.com/posener/complete v1.2.3 // indirect
6265
github.com/shopspring/decimal v1.3.1 // indirect
6366
github.com/spf13/cast v1.5.0 // indirect

internal/provider/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
"github.com/patientsknowbest/terraform-provider-aidbox/aidbox"
@@ -61,6 +62,7 @@ func New(apiClient *aidbox.ApiClient) func() *schema.Provider {
6162
"aidbox_aidbox_subscription_topic": resourceAidboxSubscriptionTopic(),
6263
"aidbox_aidbox_topic_destination": resourceAidboxTopicDestination(),
6364
"aidbox_identity_provider": resourceIdentityProvider(),
65+
"aidbox_structure_definition": resourceStructureDefinition(),
6466
},
6567
}
6668

internal/provider/resource_search_parameter_v2_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ func TestAccResourceSearchParameterV2_elementNameAndPatternFilterInExpression(t
1313
{
1414
Config: testAccResourceSearchParameterV2_elementNameAndPatternFilterInExpression,
1515
Check: resource.ComposeTestCheckFunc(
16-
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_phone", "id", "Patient.phone-number"),
1716
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_phone", "name", "phone-number"),
1817
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_phone", "type", "string"),
1918
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_phone", "base.0", "Patient"),
@@ -36,7 +35,6 @@ func TestAccResourceSearchParameterV2_elementNameAndIndexInExpression(t *testing
3635
{
3736
Config: testAccResourceSearchParameterV2_elementNameAndIndexInExpression,
3837
Check: resource.ComposeTestCheckFunc(
39-
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_name", "id", "Patient.first-name"),
4038
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_name", "name", "first-name"),
4139
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_name", "type", "string"),
4240
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_name", "base.0", "Patient"),
@@ -59,7 +57,6 @@ func TestAccResourceSearchParameterV2_extension(t *testing.T) {
5957
{
6058
Config: testAccResourceSearchParameterV2_extension,
6159
Check: resource.ComposeTestCheckFunc(
62-
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_extension", "id", "Appointment.custom-date"),
6360
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_extension", "name", "custom-date"),
6461
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_extension", "type", "date"),
6562
resource.TestCheckResourceAttr("aidbox_fhir_search_parameter.example_extension", "base.0", "Appointment"),

0 commit comments

Comments
 (0)