Skip to content

Commit a41d85e

Browse files
authored
Merge pull request #98 from roopesh83/main
Label definition datasource and resource added
2 parents faa9c8c + 98ec78c commit a41d85e

6 files changed

Lines changed: 405 additions & 1 deletion

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# hsdp_cdl_label_definition
2+
3+
Retrieve details on HSDP Clinical Data Lake Label Definition.
4+
5+
## Example Usage
6+
7+
```hcl
8+
data "hsdp_cdl_label_definition" "labeldef1" {
9+
cdl_endpoint = "https://{{CDL-HOST}}/store/cdl/{{ORG_ID}}"
10+
label_def_id = "277a5d14-86cd-4a99-92e2-7b8e898cffae"
11+
study_id = "a1467792-ef81-11eb-8ac2-477a9e3b09aa"
12+
}
13+
14+
output hsdp_cdl_label_definition{
15+
value = data.hsdp_cdl_label_definition.labeldef1
16+
}
17+
```
18+
19+
20+
## Argument Reference
21+
22+
The following arguments are supported:
23+
24+
* `cdl_endpoint` - (Required) The CDL instance endpoint to query
25+
* `label_def_id` - (Required) The ID of the label definition to look up
26+
* `study_id` - (Required) The ID of the Research Study which contains the label definition
27+
28+
## Attributes Reference
29+
30+
In addition to all arguments above, the following attributes are exported:
31+
32+
* `id` - The GUID of the Label definitions
33+
* `label_name` - The label name
34+
* `label_scope` - Use this parameter to specify for which CDL Data the LabelDefinition is applicable
35+
* `labels` - Use this parameter to specify your labels, or classes. Add one label for each class.
36+
* `label_def_name` - Name of the label definition
37+
* `type` - Use this parameter to define the label type. Supported Values : cdl/video-classification
38+
* `description` - Desciption of label definition
39+
* `created_by` - User who created this label definition
40+
* `created_on` - Timestamp when label definition was created
41+

docs/resources/cdl_data_type_definition.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ resource "hsdp_cdl_data_type_definition" "def_a" {
1010
name = "my CDL schema A"
1111
1212
json_schema = <<EOF
13-
{}
13+
{
14+
"required": [
15+
"email"
16+
],
17+
"properties": {
18+
"name": {
19+
"type": "string"
20+
},
21+
"email": {
22+
"type": "string"
23+
},
24+
"birthdate": {
25+
"type": "string"
26+
}
27+
}
28+
}
1429
EOF
1530
}
1631
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# hsdp_cdl_label_definition
2+
3+
Manages HSDP Clinical Data Lake Label Definitions.
4+
5+
## Example Usage
6+
7+
```hcl
8+
resource hsdp_cdl_label_definition "labeldef1" {
9+
cdl_endpoint = "https://cicd-datalake.cloud.pcftest.com/store/cdl/1f5be763-f896-4883-80fa-5593cd69556d"
10+
study_id = "a1467792-ef81-11eb-8ac2-477a9e3b09aa"
11+
label_def_name = "TF create Test4"
12+
description = "TF create desc"
13+
label_scope = "DataObject.DICOM"
14+
label_name = "videoQualityTF10"
15+
type = "cdl/video-classification"
16+
labels = ["good", "bad", "acceptable", "something", "something1"]
17+
}
18+
```
19+
20+
21+
## Argument Reference
22+
23+
The following arguments are supported:
24+
25+
* `cdl_endpoint` - (Required) The CDL instance endpoint to query
26+
* `study_id` - (Required) The research study id under which label definition has to be created
27+
* `label_name` - The label name
28+
* `label_scope` - Use this parameter to specify for which CDL Data the LabelDefinition is applicable
29+
* `labels` - Use this parameter to specify your labels, or classes. Add one label for each class.
30+
* `label_def_name` - Name of the label definition
31+
* `type` - Use this parameter to define the label type. Supported Values : cdl/video-classification
32+
* `description` - Desciption of label definition
33+
34+
## Attributes Reference
35+
36+
In addition to all arguments above, the following attributes are exported:
37+
38+
* `id` - The GUID of the label definition
39+
* `created_by` - User who created the label definition
40+
* `created_on` - Timestamp the label definition was created
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package hsdp
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
)
9+
10+
func dataSourceCDLLabelDefinition() *schema.Resource {
11+
return &schema.Resource{
12+
ReadContext: dataSourceCDLLabelDefinitionRead,
13+
Schema: map[string]*schema.Schema{
14+
"cdl_endpoint": {
15+
Type: schema.TypeString,
16+
Required: true,
17+
},
18+
"label_def_id": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
},
22+
"study_id": {
23+
Type: schema.TypeString,
24+
Required: true,
25+
},
26+
"label_def_name": {
27+
Type: schema.TypeString,
28+
Computed: true,
29+
},
30+
"description": {
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"label_scope": {
35+
Type: schema.TypeString,
36+
Computed: true,
37+
},
38+
"label_name": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
},
42+
"type": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
},
46+
"labels": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
},
50+
"created_by": {
51+
Type: schema.TypeString,
52+
Computed: true,
53+
},
54+
"created_on": {
55+
Type: schema.TypeString,
56+
Computed: true,
57+
},
58+
},
59+
}
60+
61+
}
62+
63+
func dataSourceCDLLabelDefinitionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
64+
config := m.(*Config)
65+
66+
var diags diag.Diagnostics
67+
68+
labelDefId := d.Get("label_def_id").(string)
69+
endpoint := d.Get("cdl_endpoint").(string)
70+
studyId := d.Get("study_id").(string)
71+
72+
client, err := config.getCDLClientFromEndpoint(endpoint)
73+
if err != nil {
74+
return diag.FromErr(err)
75+
}
76+
defer client.Close()
77+
78+
labelDefinition, _, err := client.LabelDefinition.GetLabelDefinitionByID(studyId, labelDefId)
79+
if err != nil {
80+
return diag.FromErr(err)
81+
}
82+
83+
labelScopeBytes, err := json.Marshal((*labelDefinition).LabelScope)
84+
if err != nil {
85+
return diag.FromErr(err)
86+
}
87+
88+
labelsBytes, err := json.Marshal((*labelDefinition).Labels)
89+
if err != nil {
90+
return diag.FromErr(err)
91+
}
92+
93+
d.SetId((*labelDefinition).ID)
94+
_ = d.Set("label_def_name", (*labelDefinition).LabelDefName)
95+
_ = d.Set("description", (*labelDefinition).Description)
96+
_ = d.Set("label_scope", string(labelScopeBytes))
97+
_ = d.Set("label_name", (*labelDefinition).Label)
98+
_ = d.Set("type", (*labelDefinition).Type)
99+
_ = d.Set("labels", string(labelsBytes))
100+
_ = d.Set("created_by", (*labelDefinition).CreatedBy)
101+
_ = d.Set("created_on", (*labelDefinition).CreatedOn)
102+
103+
return diags
104+
}

hsdp/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func Provider(build string) *schema.Provider {
192192
"hsdp_cdl_research_study": resourceCDLResearchStudy(),
193193
"hsdp_dicom_remote_node": resourceDICOMRemoteNode(),
194194
"hsdp_cdl_data_type_definition": resourceCDLDataTypeDefinition(),
195+
"hsdp_cdl_label_definition": resourceCDLLabelDefinition(),
195196
},
196197
DataSourcesMap: map[string]*schema.Resource{
197198
"hsdp_iam_introspect": dataSourceIAMIntrospect(),
@@ -221,6 +222,7 @@ func Provider(build string) *schema.Provider {
221222
"hsdp_container_host_instances": dataSourceContainerHostInstances(),
222223
"hsdp_cdl_data_type_definitions": dataSourceCDLDataTypeDefinitions(),
223224
"hsdp_cdl_data_type_definition": dataSourceCDLDataTypeDefinition(),
225+
"hsdp_cdl_label_definition": dataSourceCDLLabelDefinition(),
224226
},
225227
ConfigureContextFunc: providerConfigure(build),
226228
}

0 commit comments

Comments
 (0)