View Javadoc
1   package ca.uhn.fhir.model.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.apache.commons.lang3.Validate;
24  import org.apache.commons.lang3.builder.ToStringBuilder;
25  import org.apache.commons.lang3.builder.ToStringStyle;
26  
27  import ca.uhn.fhir.model.primitive.InstantDt;
28  import ca.uhn.fhir.model.primitive.StringDt;
29  import ca.uhn.fhir.model.primitive.XhtmlDt;
30  import ca.uhn.fhir.util.ElementUtil;
31  
32  public class BundleEntry extends BaseBundle {
33  
34  	//@formatter:off
35  	/* ****************************************************
36  	 * NB: add any new fields to the isEmpty() method!!!
37  	 *****************************************************/
38  	//@formatter:on
39  	private TagList myCategories;
40  	private InstantDt myDeletedAt;
41  	private StringDt myDeletedByEmail;
42  	private StringDt myDeletedByName;
43  	private StringDt myDeletedComment;
44  	private StringDt myLinkAlternate;
45  	private StringDt myLinkSearch;
46  	private StringDt myLinkSelf;
47  	private InstantDt myPublished;
48  	private IResource myResource;
49  	private XhtmlDt mySummary;
50  	private StringDt myTitle;
51  	private InstantDt myUpdated;
52  
53  	/**
54  	 * @deprecated Tags wil become immutable in a future release of HAPI, so {@link #addCategory(String, String, String)} should be used instead
55  	 */
56  	public Tag addCategory() {
57  		Tag retVal = new Tag();
58  		getCategories().add(retVal);
59  		return retVal;
60  	}
61  
62  	public void addCategory(String theScheme, String theTerm, String theLabel) {
63  		getCategories().add(new Tag(theScheme, theTerm, theLabel));
64  	}
65  
66  	public void addCategory(Tag theTag) {
67  		getCategories().add(theTag);
68  	}
69  
70  	public TagList getCategories() {
71  		if (myCategories == null) {
72  			myCategories = new TagList();
73  		}
74  		return myCategories;
75  	}
76  
77  	/**
78  	 * Gets the date/time that thius entry was deleted.
79  	 */
80  	public InstantDt getDeletedAt() {
81  		if (myDeletedAt == null) {
82  			myDeletedAt = new InstantDt();
83  		}
84  		return myDeletedAt;
85  	}
86  
87  	public StringDt getDeletedByEmail() {
88  		if (myDeletedByEmail == null) {
89  			myDeletedByEmail = new StringDt();
90  		}
91  		return myDeletedByEmail;
92  	}
93  
94  	public StringDt getDeletedByName() {
95  		if (myDeletedByName == null) {
96  			myDeletedByName = new StringDt();
97  		}
98  		return myDeletedByName;
99  	}
100 
101 	public StringDt getDeletedComment() {
102 		if (myDeletedComment == null) {
103 			myDeletedComment = new StringDt();
104 		}
105 		return myDeletedComment;
106 	}
107 
108 	public StringDt getLinkAlternate() {
109 		if (myLinkAlternate == null) {
110 			myLinkAlternate = new StringDt();
111 		}
112 		return myLinkAlternate;
113 	}
114 
115 	public StringDt getLinkSearch() {
116 		if (myLinkSearch == null) {
117 			myLinkSearch = new StringDt();
118 		}
119 		return myLinkSearch;
120 	}
121 
122 	public StringDt getLinkSelf() {
123 		if (myLinkSelf == null) {
124 			myLinkSelf = new StringDt();
125 		}
126 		return myLinkSelf;
127 	}
128 
129 	public InstantDt getPublished() {
130 		if (myPublished == null) {
131 			myPublished = new InstantDt();
132 		}
133 		return myPublished;
134 	}
135 
136 	public IResource getResource() {
137 		return myResource;
138 	}
139 
140 	public XhtmlDt getSummary() {
141 		if (mySummary == null) {
142 			mySummary = new XhtmlDt();
143 		}
144 		return mySummary;
145 	}
146 
147 	public StringDt getTitle() {
148 		if (myTitle == null) {
149 			myTitle = new StringDt();
150 		}
151 		return myTitle;
152 	}
153 
154 	public InstantDt getUpdated() {
155 		if (myUpdated == null) {
156 			myUpdated = new InstantDt();
157 		}
158 		return myUpdated;
159 	}
160 
161 	@Override
162 	public boolean isEmpty() {
163 		//@formatter:off
164 		return super.isEmpty() && 
165 				ElementUtil.isEmpty(myCategories, myDeletedAt, myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary, myTitle, myUpdated, myDeletedByEmail, myDeletedByName, myDeletedComment);
166 		//@formatter:on
167 	}
168 
169 	/**
170 	 * Sets the date/time that this entry was deleted.
171 	 */
172 	public void setDeleted(InstantDt theDeletedAt) {
173 		myDeletedAt = theDeletedAt;
174 	}
175 
176 	public void setDeletedByEmail(StringDt theDeletedByEmail) {
177 		myDeletedByEmail = theDeletedByEmail;
178 	}
179 
180 	public void setDeletedByName(StringDt theDeletedByName) {
181 		if (myDeletedByName == null) {
182 			myDeletedByName = new StringDt();
183 		}
184 		myDeletedByName = theDeletedByName;
185 	}
186 
187 	public void setDeletedComment(StringDt theDeletedComment) {
188 		myDeletedComment = theDeletedComment;
189 	}
190 
191 	public void setLinkAlternate(StringDt theLinkAlternate) {
192 		myLinkAlternate = theLinkAlternate;
193 	}
194 
195 	public void setLinkSearch(StringDt theLinkSearch) {
196 		myLinkSearch = theLinkSearch;
197 	}
198 
199 	public void setLinkSelf(StringDt theLinkSelf) {
200 		if (myLinkSelf == null) {
201 			myLinkSelf = new StringDt();
202 		}
203 		myLinkSelf = theLinkSelf;
204 	}
205 
206 	public void setPublished(InstantDt thePublished) {
207 		Validate.notNull(thePublished, "Published may not be null");
208 		myPublished = thePublished;
209 	}
210 
211 	public void setResource(IResource theResource) {
212 		myResource = theResource;
213 	}
214 
215 	public void setUpdated(InstantDt theUpdated) {
216 		Validate.notNull(theUpdated, "Updated may not be null");
217 		myUpdated = theUpdated;
218 	}
219 
220 	@Override
221 	public String toString() {
222 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
223 		if (getResource() != null) {
224 			b.append("type", getResource().getClass().getSimpleName());
225 		} else {
226 			b.append("No resource");
227 		}
228 		b.append("id", getId());
229 		return b.toString();
230 	}
231 
232 }