1 package ca.uhn.fhir.model.api;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.apache.commons.lang3.Validate;
27 import org.apache.commons.lang3.builder.ToStringBuilder;
28 import org.apache.commons.lang3.builder.ToStringStyle;
29
30 import ca.uhn.fhir.model.api.annotation.Child;
31 import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
32 import ca.uhn.fhir.model.dstu.composite.ContainedDt;
33 import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
34 import ca.uhn.fhir.model.primitive.CodeDt;
35 import ca.uhn.fhir.model.primitive.IdDt;
36 import ca.uhn.fhir.util.ElementUtil;
37
38 public abstract class BaseResource extends BaseElement implements IResource {
39
40
41
42
43 @SearchParamDefinition(name="_language", path="", description="The language of the resource", type="string" )
44 public static final String SP_RES_LANGUAGE = "_language";
45
46
47
48
49
50 @SearchParamDefinition(name="_id", path="", description="The ID of the resource", type="string" )
51 public static final String SP_RES_ID = "_id";
52
53 @Child(name = "contained", order = 2, min = 0, max = 1)
54 private ContainedDt myContained;
55
56 private IdDt myId;
57
58 @Child(name = "language", order = 0, min = 0, max = Child.MAX_UNLIMITED)
59 private CodeDt myLanguage;
60
61 private Map<ResourceMetadataKeyEnum<?>, Object> myResourceMetadata;
62
63 @Child(name = "text", order = 1, min = 0, max = 1)
64 private NarrativeDt myText;
65
66 @Override
67 public ContainedDt getContained() {
68 if (myContained == null) {
69 myContained = new ContainedDt();
70 }
71 return myContained;
72 }
73
74 public IdDt getId() {
75 if (myId == null) {
76 myId = new IdDt();
77 }
78 return myId;
79 }
80
81 @Override
82 public CodeDt getLanguage() {
83 if (myLanguage == null) {
84 myLanguage = new CodeDt();
85 }
86 return myLanguage;
87 }
88
89 @Override
90 public Map<ResourceMetadataKeyEnum<?>, Object> getResourceMetadata() {
91 if (myResourceMetadata == null) {
92 myResourceMetadata = new HashMap<ResourceMetadataKeyEnum<?>, Object>();
93 }
94 return myResourceMetadata;
95 }
96
97 @Override
98 public NarrativeDt getText() {
99 if (myText == null) {
100 myText = new NarrativeDt();
101 }
102 return myText;
103 }
104
105 public void setContained(ContainedDt theContained) {
106 myContained = theContained;
107 }
108
109 public void setId(IdDt theId) {
110 myId = theId;
111 }
112
113 public void setId(String theId) {
114 if (theId == null) {
115 myId = null;
116 } else {
117 myId = new IdDt(theId);
118 }
119 }
120
121 @Override
122 public void setLanguage(CodeDt theLanguage) {
123 myLanguage = theLanguage;
124 }
125
126 @Override
127 public void setResourceMetadata(Map<ResourceMetadataKeyEnum<?>, Object> theMap) {
128 Validate.notNull(theMap, "The Map must not be null");
129 myResourceMetadata = theMap;
130 }
131
132 public void setText(NarrativeDt theText) {
133 myText = theText;
134 }
135
136 @Override
137 public String toString() {
138 ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
139 b.append("id", getId().toUnqualified());
140 return b.toString();
141 }
142
143
144
145
146
147 @Override
148 protected boolean isBaseEmpty() {
149 return super.isBaseEmpty() && ElementUtil.isEmpty(myLanguage, myText, myId);
150 }
151
152 }