/
servicedefinition.go
107 lines (99 loc) · 5.57 KB
/
servicedefinition.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2011-2017, HL7, Inc & The MITRE Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of HL7 nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
package models
import (
"encoding/json"
"errors"
"fmt"
)
type ServiceDefinition struct {
DomainResource `bson:",inline"`
Url string `bson:"url,omitempty" json:"url,omitempty"`
Identifier []Identifier `bson:"identifier,omitempty" json:"identifier,omitempty"`
Version string `bson:"version,omitempty" json:"version,omitempty"`
Name string `bson:"name,omitempty" json:"name,omitempty"`
Title string `bson:"title,omitempty" json:"title,omitempty"`
Status string `bson:"status,omitempty" json:"status,omitempty"`
Experimental *bool `bson:"experimental,omitempty" json:"experimental,omitempty"`
Date *FHIRDateTime `bson:"date,omitempty" json:"date,omitempty"`
Publisher string `bson:"publisher,omitempty" json:"publisher,omitempty"`
Description string `bson:"description,omitempty" json:"description,omitempty"`
Purpose string `bson:"purpose,omitempty" json:"purpose,omitempty"`
Usage string `bson:"usage,omitempty" json:"usage,omitempty"`
ApprovalDate *FHIRDateTime `bson:"approvalDate,omitempty" json:"approvalDate,omitempty"`
LastReviewDate *FHIRDateTime `bson:"lastReviewDate,omitempty" json:"lastReviewDate,omitempty"`
EffectivePeriod *Period `bson:"effectivePeriod,omitempty" json:"effectivePeriod,omitempty"`
UseContext []UsageContext `bson:"useContext,omitempty" json:"useContext,omitempty"`
Jurisdiction []CodeableConcept `bson:"jurisdiction,omitempty" json:"jurisdiction,omitempty"`
Topic []CodeableConcept `bson:"topic,omitempty" json:"topic,omitempty"`
Contributor []Contributor `bson:"contributor,omitempty" json:"contributor,omitempty"`
Contact []ContactDetail `bson:"contact,omitempty" json:"contact,omitempty"`
Copyright string `bson:"copyright,omitempty" json:"copyright,omitempty"`
RelatedArtifact []RelatedArtifact `bson:"relatedArtifact,omitempty" json:"relatedArtifact,omitempty"`
Trigger []TriggerDefinition `bson:"trigger,omitempty" json:"trigger,omitempty"`
DataRequirement []DataRequirement `bson:"dataRequirement,omitempty" json:"dataRequirement,omitempty"`
OperationDefinition *Reference `bson:"operationDefinition,omitempty" json:"operationDefinition,omitempty"`
}
// Custom marshaller to add the resourceType property, as required by the specification
func (resource *ServiceDefinition) MarshalJSON() ([]byte, error) {
resource.ResourceType = "ServiceDefinition"
// Dereferencing the pointer to avoid infinite recursion.
// Passing in plain old x (a pointer to ServiceDefinition), would cause this same
// MarshallJSON function to be called again
return json.Marshal(*resource)
}
func (x *ServiceDefinition) GetBSON() (interface{}, error) {
x.ResourceType = "ServiceDefinition"
// See comment in MarshallJSON to see why we dereference
return *x, nil
}
// The "serviceDefinition" sub-type is needed to avoid infinite recursion in UnmarshalJSON
type serviceDefinition ServiceDefinition
// Custom unmarshaller to properly unmarshal embedded resources (represented as interface{})
func (x *ServiceDefinition) UnmarshalJSON(data []byte) (err error) {
x2 := serviceDefinition{}
if err = json.Unmarshal(data, &x2); err == nil {
if x2.Contained != nil {
for i := range x2.Contained {
x2.Contained[i], err = MapToResource(x2.Contained[i], true)
if err != nil {
return err
}
}
}
*x = ServiceDefinition(x2)
return x.checkResourceType()
}
return
}
func (x *ServiceDefinition) checkResourceType() error {
if x.ResourceType == "" {
x.ResourceType = "ServiceDefinition"
} else if x.ResourceType != "ServiceDefinition" {
return errors.New(fmt.Sprintf("Expected resourceType to be ServiceDefinition, instead received %s", x.ResourceType))
}
return nil
}