001package ca.uhn.fhir.model.api; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2017 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import org.apache.commons.lang3.Validate; 024import org.apache.commons.lang3.builder.ToStringBuilder; 025import org.apache.commons.lang3.builder.ToStringStyle; 026 027import ca.uhn.fhir.model.primitive.BoundCodeDt; 028import ca.uhn.fhir.model.primitive.CodeDt; 029import ca.uhn.fhir.model.primitive.DecimalDt; 030import ca.uhn.fhir.model.primitive.IdDt; 031import ca.uhn.fhir.model.primitive.InstantDt; 032import ca.uhn.fhir.model.primitive.StringDt; 033import ca.uhn.fhir.model.primitive.XhtmlDt; 034import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; 035import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; 036import ca.uhn.fhir.util.ElementUtil; 037 038public class BundleEntry extends BaseBundle { 039 040 private static final long serialVersionUID = 2635639739195593736L; 041 //@formatter:off 042 /* **************************************************** 043 * NB: add any new fields to the isEmpty() method!!! 044 *****************************************************/ 045 //@formatter:on 046 private TagList myCategories; 047 private InstantDt myDeletedAt; 048 private StringDt myDeletedByEmail; 049 private StringDt myDeletedByName; 050 private StringDt myDeletedComment; 051 private IdDt myDeletedResourceId; 052 private CodeDt myDeletedResourceType; 053 private StringDt myDeletedResourceVersion; 054 private StringDt myLinkAlternate; 055 private StringDt myLinkBase; 056 private StringDt myLinkSearch; 057 private StringDt myLinkSelf; 058 private InstantDt myPublished; 059 private IResource myResource; 060 private DecimalDt myScore; 061 private BoundCodeDt<BundleEntrySearchModeEnum> mySearchMode; 062 private BoundCodeDt<BundleEntryTransactionMethodEnum> myTransactionOperation; 063 private XhtmlDt mySummary; 064 private StringDt myTitle; 065 private InstantDt myUpdated; 066 067 /** 068 * @deprecated Tags wil become immutable in a future release of HAPI, so 069 * {@link #addCategory(String, String, String)} should be used instead 070 */ 071 @Deprecated 072 public Tag addCategory() { 073 Tag retVal = new Tag(); 074 getCategories().add(retVal); 075 return retVal; 076 } 077 078 public void addCategory(String theScheme, String theTerm, String theLabel) { 079 getCategories().add(new Tag(theScheme, theTerm, theLabel)); 080 } 081 082 public void addCategory(Tag theTag) { 083 getCategories().add(theTag); 084 } 085 086 public TagList getCategories() { 087 if (myCategories == null) { 088 myCategories = new TagList(); 089 } 090 return myCategories; 091 } 092 093 /** 094 * Gets the date/time that thius entry was deleted. 095 */ 096 public InstantDt getDeletedAt() { 097 if (myDeletedAt == null) { 098 myDeletedAt = new InstantDt(); 099 } 100 return myDeletedAt; 101 } 102 103 public StringDt getDeletedByEmail() { 104 if (myDeletedByEmail == null) { 105 myDeletedByEmail = new StringDt(); 106 } 107 return myDeletedByEmail; 108 } 109 110 public StringDt getDeletedByName() { 111 if (myDeletedByName == null) { 112 myDeletedByName = new StringDt(); 113 } 114 return myDeletedByName; 115 } 116 117 public StringDt getDeletedComment() { 118 if (myDeletedComment == null) { 119 myDeletedComment = new StringDt(); 120 } 121 return myDeletedComment; 122 } 123 124 public IdDt getDeletedResourceId() { 125 if (myDeletedResourceId == null) { 126 myDeletedResourceId = new IdDt(); 127 } 128 return myDeletedResourceId; 129 } 130 131 public CodeDt getDeletedResourceType() { 132 if (myDeletedResourceType == null) { 133 myDeletedResourceType = new CodeDt(); 134 } 135 return myDeletedResourceType; 136 } 137 138 public StringDt getDeletedResourceVersion() { 139 if (myDeletedResourceVersion == null) { 140 myDeletedResourceVersion = new StringDt(); 141 } 142 return myDeletedResourceVersion; 143 } 144 145 /** 146 * @deprecated Setting IDs on bundle entries is redundant since resources already have an ID field. Instead of 147 * providing an ID using this method, set the ID on the resource using {@link IResource#setId(IdDt)} or 148 * if this entry represents a deleted resource, use {@link #setDeletedResourceId(IdDt)}. 149 */ 150 @Override 151 @Deprecated 152 public IdDt getId() { 153 return super.getId(); 154 } 155 156 public StringDt getLinkAlternate() { 157 if (myLinkAlternate == null) { 158 myLinkAlternate = new StringDt(); 159 } 160 return myLinkAlternate; 161 } 162 163 /** 164 * @deprecated Use resource ID to determine base URL 165 */ 166 @Deprecated 167 public StringDt getLinkBase() { 168 if (myLinkBase == null) { 169 myLinkBase = new StringDt(); 170 } 171 return myLinkBase; 172 } 173 174 public StringDt getLinkSearch() { 175 if (myLinkSearch == null) { 176 myLinkSearch = new StringDt(); 177 } 178 return myLinkSearch; 179 } 180 181 public StringDt getLinkSelf() { 182 if (myLinkSelf == null) { 183 myLinkSelf = new StringDt(); 184 } 185 return myLinkSelf; 186 } 187 188 public InstantDt getPublished() { 189 if (myPublished == null) { 190 myPublished = new InstantDt(); 191 } 192 return myPublished; 193 } 194 195 public IResource getResource() { 196 return myResource; 197 } 198 199 public DecimalDt getScore() { 200 if (myScore == null) { 201 myScore = new DecimalDt(); 202 } 203 return myScore; 204 } 205 206 207 public XhtmlDt getSummary() { 208 if (mySummary == null) { 209 mySummary = new XhtmlDt(); 210 } 211 return mySummary; 212 } 213 214 public StringDt getTitle() { 215 if (myTitle == null) { 216 myTitle = new StringDt(); 217 } 218 return myTitle; 219 } 220 221 /** 222 * @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata 223 * has been moved to the resource <meta/> element so it is redundant here). In preparation for 224 * DSTU2, it is recommended that you migrate code away from using this method and over to using resource 225 * metadata instead. 226 */ 227 @Deprecated 228 public InstantDt getUpdated() { 229 if (myUpdated == null) { 230 myUpdated = new InstantDt(); 231 } 232 if (myUpdated.isEmpty() && myResource != null) { 233 InstantDt resourceUpdated = ResourceMetadataKeyEnum.UPDATED.get(myResource); 234 if (resourceUpdated != null && !resourceUpdated.isEmpty()) { 235 return resourceUpdated; 236 } 237 } 238 return myUpdated; 239 } 240 241 @Override 242 public boolean isEmpty() { 243 //@formatter:off 244 return super.isEmpty() && 245 ElementUtil.isEmpty( 246 myDeletedResourceId, myDeletedResourceType, myDeletedResourceVersion, myDeletedAt, 247 myScore, mySearchMode, myTransactionOperation, myCategories, 248 myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary, 249 myTitle, myUpdated, myDeletedByEmail, myDeletedByName, myDeletedComment); 250 //@formatter:on 251 } 252 253 /** 254 * Sets the date/time that this entry was deleted. 255 */ 256 public void setDeleted(InstantDt theDeletedAt) { 257 myDeletedAt = theDeletedAt; 258 } 259 260 public void setDeletedByEmail(StringDt theDeletedByEmail) { 261 myDeletedByEmail = theDeletedByEmail; 262 } 263 264 public void setDeletedByName(StringDt theDeletedByName) { 265 if (myDeletedByName == null) { 266 myDeletedByName = new StringDt(); 267 } 268 myDeletedByName = theDeletedByName; 269 } 270 271 public void setDeletedComment(StringDt theDeletedComment) { 272 myDeletedComment = theDeletedComment; 273 } 274 275 public void setDeletedResourceId(IdDt theDeletedResourceId) { 276 myDeletedResourceId = theDeletedResourceId; 277 } 278 279 public void setDeletedResourceType(CodeDt theDeletedResourceType) { 280 myDeletedResourceType = theDeletedResourceType; 281 } 282 283 public void setDeletedResourceVersion(StringDt theDeletedResourceVersion) { 284 myDeletedResourceVersion = theDeletedResourceVersion; 285 } 286 287 /** 288 * @deprecated Bundle entries no longer have an ID in DSTU2, as ID is explicitly stated in the resource itself. 289 */ 290 @Override 291 @Deprecated 292 public void setId(IdDt theId) { 293 super.setId(theId); 294 } 295 296 public void setLinkAlternate(StringDt theLinkAlternate) { 297 myLinkAlternate = theLinkAlternate; 298 } 299 300 /** 301 * @deprecated Use resource ID to determine base URL 302 */ 303 @Deprecated 304 public void setLinkBase(StringDt theLinkBase) { 305 myLinkBase = theLinkBase; 306 } 307 308 public void setLinkSearch(StringDt theLinkSearch) { 309 myLinkSearch = theLinkSearch; 310 } 311 312 public void setLinkSelf(StringDt theLinkSelf) { 313 if (myLinkSelf == null) { 314 myLinkSelf = new StringDt(); 315 } 316 myLinkSelf = theLinkSelf; 317 } 318 319 public void setPublished(InstantDt thePublished) { 320 Validate.notNull(thePublished, "Published may not be null"); 321 myPublished = thePublished; 322 } 323 324 public void setResource(IResource theResource) { 325 myResource = theResource; 326 } 327 328 public void setScore(DecimalDt theScore) { 329 myScore = theScore; 330 } 331 332 333 /** 334 * @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata 335 * has been moved to the resource <meta/> element so it is redundant here). In preparation for 336 * DSTU2, it is recommended that you migrate code away from using this method and over to using resource 337 * metadata instead. 338 */ 339 @Deprecated 340 public void setUpdated(InstantDt theUpdated) { 341 Validate.notNull(theUpdated, "Updated may not be null"); 342 myUpdated = theUpdated; 343 } 344 345 @Override 346 public String toString() { 347 ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); 348 if (getResource() != null) { 349 b.append("type", getResource().getClass().getSimpleName()); 350 } else { 351 b.append("No resource"); 352 } 353 b.append("id", getId()); 354 return b.toString(); 355 } 356 357 public BoundCodeDt<BundleEntrySearchModeEnum> getSearchMode() { 358 if (mySearchMode == null) { 359 mySearchMode = new BoundCodeDt<BundleEntrySearchModeEnum>(BundleEntrySearchModeEnum.VALUESET_BINDER); 360 } 361 return mySearchMode; 362 } 363 364 public void setSearchMode(BoundCodeDt<BundleEntrySearchModeEnum> theSearchMode) { 365 mySearchMode = theSearchMode; 366 } 367 368 public BoundCodeDt<BundleEntryTransactionMethodEnum> getTransactionMethod() { 369 if (myTransactionOperation == null) { 370 myTransactionOperation = new BoundCodeDt<BundleEntryTransactionMethodEnum>(BundleEntryTransactionMethodEnum.VALUESET_BINDER); 371 } 372 return myTransactionOperation; 373 } 374 375 public void setTransactionMethod(BoundCodeDt<BundleEntryTransactionMethodEnum> theTransactionOperation) { 376 myTransactionOperation = theTransactionOperation; 377 } 378 379 380 381 382}