001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017package ca.uhn.fhir.model.dstu2.composite; 018 019/* 020 * #%L 021 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) 022 * %% 023 * Copyright (C) 2014 - 2020 University Health Network 024 * %% 025 * Licensed under the Apache License, Version 2.0 (the "License"); 026 * you may not use this file except in compliance with the License. 027 * You may obtain a copy of the License at 028 * 029 * http://www.apache.org/licenses/LICENSE-2.0 030 * 031 * Unless required by applicable law or agreed to in writing, software 032 * distributed under the License is distributed on an "AS IS" BASIS, 033 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 034 * See the License for the specific language governing permissions and 035 * limitations under the License. 036 * #L% 037 */ 038 039import java.util.List; 040 041import org.hl7.fhir.instance.model.api.IIdType; 042 043import ca.uhn.fhir.model.api.ICompositeDatatype; 044import ca.uhn.fhir.model.api.IElement; 045import ca.uhn.fhir.model.api.IResource; 046import ca.uhn.fhir.model.api.annotation.Child; 047import ca.uhn.fhir.model.api.annotation.DatatypeDef; 048import ca.uhn.fhir.model.api.annotation.Description; 049import ca.uhn.fhir.model.api.annotation.SimpleSetter; 050import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; 051import ca.uhn.fhir.model.primitive.IdDt; 052import ca.uhn.fhir.model.primitive.StringDt; 053 054/** 055 * HAPI/FHIR <b>ResourceReferenceDt</b> Datatype 056 * (A reference from one resource to another) 057 * 058 * <p> 059 * <b>Definition:</b> 060 * A reference from one resource to another 061 * </p> 062 * 063 * <p> 064 * <b>Requirements:</b> 065 * 066 * </p> 067 */ 068@DatatypeDef(name="reference") 069public class ResourceReferenceDt 070 extends BaseResourceReferenceDt implements ICompositeDatatype 071{ 072 073 /** 074 * Constructor 075 */ 076 public ResourceReferenceDt() { 077 // nothing 078 } 079 080 /** 081 * Constructor which creates a resource reference containing the actual resource in question. 082 * <p> 083 * <b> When using this in a server:</b> Generally if this is serialized, it will be serialized as a contained 084 * resource, so this should not be used if the intent is not to actually supply the referenced resource. This is not 085 * a hard-and-fast rule however, as the server can be configured to not serialized this resource, or to load an ID 086 * and contain even if this constructor is not used. 087 * </p> 088 * 089 * @param theResource 090 * The resource instance 091 */ 092 @SimpleSetter() 093 public ResourceReferenceDt(IResource theResource) { 094 super(theResource); 095 } 096 097 /** 098 * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute 099 * URL) 100 * 101 * @param theId 102 * The reference itself 103 */ 104 public ResourceReferenceDt(String theId) { 105 setReference(new IdDt(theId)); 106 } 107 108 /** 109 * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute 110 * URL) 111 * 112 * @param theResourceId 113 * The reference itself 114 */ 115 public ResourceReferenceDt(IdDt theResourceId) { 116 setReference(theResourceId); 117 } 118 119 /** 120 * Constructor which accepts a reference directly (this can be an ID, a partial/relative URL or a complete/absolute 121 * URL) 122 * 123 * @param theResourceId 124 * The reference itself 125 */ 126 public ResourceReferenceDt(IIdType theResourceId) { 127 setReference(theResourceId); 128 } 129 130 @Child(name="reference", type=IdDt.class, order=0, min=0, max=1) 131 @Description( 132 shortDefinition="Relative, internal or absolute URL reference", 133 formalDefinition="A reference to a location at which the other resource is found. The reference may a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources" 134 ) 135 private IdDt myReference; 136 137 @Child(name="display", type=StringDt.class, order=1, min=0, max=1) 138 @Description( 139 shortDefinition="Text alternative for the resource", 140 formalDefinition="Plain text narrative that identifies the resource in addition to the resource reference" 141 ) 142 private StringDt myDisplay; 143 144 145 @Override 146 public boolean isEmpty() { 147 return super.isBaseEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty( myReference, myDisplay); 148 } 149 150 @Override 151 public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) { 152 return ca.uhn.fhir.util.ElementUtil.allPopulatedChildElements(theType, myReference, myDisplay); 153 } 154 155 /** 156 * Gets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference). 157 * creating it if it does 158 * not exist. Will not return <code>null</code>. 159 * 160 * <p> 161 * <b>Definition:</b> 162 * A reference to a location at which the other resource is found. The reference may a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources 163 * </p> 164 */ 165 @Override 166 public IdDt getReference() { 167 if (myReference == null) { 168 myReference = new IdDt(); 169 } 170 return myReference; 171 } 172 173 @Override 174 public IdDt getReferenceElement() { 175 return getReference(); 176 } 177 178 179 /** 180 * Sets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference) 181 * 182 * <p> 183 * <b>Definition:</b> 184 * A reference to a location at which the other resource is found. The reference may a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources 185 * </p> 186 */ 187 @Override 188 public ResourceReferenceDt setReference(IdDt theValue) { 189 myReference = theValue; 190 return this; 191 } 192 193 /** 194 * Sets the value for <b>reference</b> (Relative, internal or absolute URL reference) 195 * 196 * <p> 197 * <b>Definition:</b> 198 * A reference to a location at which the other resource is found. The reference may a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources 199 * </p> 200 */ 201 @Override 202 public ResourceReferenceDt setReference(String theId) { 203 myReference = new IdDt(theId); 204 return this; 205 } 206 207 208 /** 209 * Gets the value(s) for <b>display</b> (Text alternative for the resource). 210 * creating it if it does 211 * not exist. Will not return <code>null</code>. 212 * 213 * <p> 214 * <b>Definition:</b> 215 * Plain text narrative that identifies the resource in addition to the resource reference 216 * </p> 217 */ 218 public StringDt getDisplay() { 219 if (myDisplay == null) { 220 myDisplay = new StringDt(); 221 } 222 return myDisplay; 223 } 224 225 /** 226 * Sets the value(s) for <b>display</b> (Text alternative for the resource) 227 * 228 * <p> 229 * <b>Definition:</b> 230 * Plain text narrative that identifies the resource in addition to the resource reference 231 * </p> 232 */ 233 public ResourceReferenceDt setDisplay(StringDt theValue) { 234 myDisplay = theValue; 235 return this; 236 } 237 238 /** 239 * Sets the value for <b>display</b> (Text alternative for the resource) 240 * 241 * <p> 242 * <b>Definition:</b> 243 * Plain text narrative that identifies the resource in addition to the resource reference 244 * </p> 245 */ 246 @Override 247 public ResourceReferenceDt setDisplay(String theString) { 248 myDisplay = new StringDt(theString); 249 return this; 250 } 251 252 @Override 253 public StringDt getDisplayElement() { 254 return getDisplay(); 255 } 256 257 258 259 260}