001package org.hl7.fhir.instance.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.*;
034
035import org.hl7.fhir.exceptions.FHIRException;
036
037import ca.uhn.fhir.model.api.annotation.*;
038/**
039 * Basic is used for handling concepts not yet defined in FHIR, narrative-only resources that don't map to an existing resource, and custom resources not appropriate for inclusion in the FHIR specification.
040 */
041@ResourceDef(name="Basic", profile="http://hl7.org/fhir/Profile/Basic")
042public class Basic extends DomainResource {
043
044    /**
045     * Identifier assigned to the resource for business purposes, outside the context of FHIR.
046     */
047    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
048    @Description(shortDefinition="Business identifier", formalDefinition="Identifier assigned to the resource for business purposes, outside the context of FHIR." )
049    protected List<Identifier> identifier;
050
051    /**
052     * Identifies the 'type' of resource - equivalent to the resource name for other resources.
053     */
054    @Child(name = "code", type = {CodeableConcept.class}, order=1, min=1, max=1, modifier=true, summary=true)
055    @Description(shortDefinition="Kind of Resource", formalDefinition="Identifies the 'type' of resource - equivalent to the resource name for other resources." )
056    protected CodeableConcept code;
057
058    /**
059     * Identifies the patient, practitioner, device or any other resource that is the "focus" of this resource.
060     */
061    @Child(name = "subject", type = {}, order=2, min=0, max=1, modifier=false, summary=true)
062    @Description(shortDefinition="Identifies the focus of this resource", formalDefinition="Identifies the patient, practitioner, device or any other resource that is the \"focus\" of this resource." )
063    protected Reference subject;
064
065    /**
066     * The actual object that is the target of the reference (Identifies the patient, practitioner, device or any other resource that is the "focus" of this resource.)
067     */
068    protected Resource subjectTarget;
069
070    /**
071     * Indicates who was responsible for creating the resource instance.
072     */
073    @Child(name = "author", type = {Practitioner.class, Patient.class, RelatedPerson.class}, order=3, min=0, max=1, modifier=false, summary=true)
074    @Description(shortDefinition="Who created", formalDefinition="Indicates who was responsible for creating the resource instance." )
075    protected Reference author;
076
077    /**
078     * The actual object that is the target of the reference (Indicates who was responsible for creating the resource instance.)
079     */
080    protected Resource authorTarget;
081
082    /**
083     * Identifies when the resource was first created.
084     */
085    @Child(name = "created", type = {DateType.class}, order=4, min=0, max=1, modifier=false, summary=true)
086    @Description(shortDefinition="When created", formalDefinition="Identifies when the resource was first created." )
087    protected DateType created;
088
089    private static final long serialVersionUID = 916539354L;
090
091  /*
092   * Constructor
093   */
094    public Basic() {
095      super();
096    }
097
098  /*
099   * Constructor
100   */
101    public Basic(CodeableConcept code) {
102      super();
103      this.code = code;
104    }
105
106    /**
107     * @return {@link #identifier} (Identifier assigned to the resource for business purposes, outside the context of FHIR.)
108     */
109    public List<Identifier> getIdentifier() { 
110      if (this.identifier == null)
111        this.identifier = new ArrayList<Identifier>();
112      return this.identifier;
113    }
114
115    public boolean hasIdentifier() { 
116      if (this.identifier == null)
117        return false;
118      for (Identifier item : this.identifier)
119        if (!item.isEmpty())
120          return true;
121      return false;
122    }
123
124    /**
125     * @return {@link #identifier} (Identifier assigned to the resource for business purposes, outside the context of FHIR.)
126     */
127    // syntactic sugar
128    public Identifier addIdentifier() { //3
129      Identifier t = new Identifier();
130      if (this.identifier == null)
131        this.identifier = new ArrayList<Identifier>();
132      this.identifier.add(t);
133      return t;
134    }
135
136    // syntactic sugar
137    public Basic addIdentifier(Identifier t) { //3
138      if (t == null)
139        return this;
140      if (this.identifier == null)
141        this.identifier = new ArrayList<Identifier>();
142      this.identifier.add(t);
143      return this;
144    }
145
146    /**
147     * @return {@link #code} (Identifies the 'type' of resource - equivalent to the resource name for other resources.)
148     */
149    public CodeableConcept getCode() { 
150      if (this.code == null)
151        if (Configuration.errorOnAutoCreate())
152          throw new Error("Attempt to auto-create Basic.code");
153        else if (Configuration.doAutoCreate())
154          this.code = new CodeableConcept(); // cc
155      return this.code;
156    }
157
158    public boolean hasCode() { 
159      return this.code != null && !this.code.isEmpty();
160    }
161
162    /**
163     * @param value {@link #code} (Identifies the 'type' of resource - equivalent to the resource name for other resources.)
164     */
165    public Basic setCode(CodeableConcept value) { 
166      this.code = value;
167      return this;
168    }
169
170    /**
171     * @return {@link #subject} (Identifies the patient, practitioner, device or any other resource that is the "focus" of this resource.)
172     */
173    public Reference getSubject() { 
174      if (this.subject == null)
175        if (Configuration.errorOnAutoCreate())
176          throw new Error("Attempt to auto-create Basic.subject");
177        else if (Configuration.doAutoCreate())
178          this.subject = new Reference(); // cc
179      return this.subject;
180    }
181
182    public boolean hasSubject() { 
183      return this.subject != null && !this.subject.isEmpty();
184    }
185
186    /**
187     * @param value {@link #subject} (Identifies the patient, practitioner, device or any other resource that is the "focus" of this resource.)
188     */
189    public Basic setSubject(Reference value) { 
190      this.subject = value;
191      return this;
192    }
193
194    /**
195     * @return {@link #subject} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (Identifies the patient, practitioner, device or any other resource that is the "focus" of this resource.)
196     */
197    public Resource getSubjectTarget() { 
198      return this.subjectTarget;
199    }
200
201    /**
202     * @param value {@link #subject} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (Identifies the patient, practitioner, device or any other resource that is the "focus" of this resource.)
203     */
204    public Basic setSubjectTarget(Resource value) { 
205      this.subjectTarget = value;
206      return this;
207    }
208
209    /**
210     * @return {@link #author} (Indicates who was responsible for creating the resource instance.)
211     */
212    public Reference getAuthor() { 
213      if (this.author == null)
214        if (Configuration.errorOnAutoCreate())
215          throw new Error("Attempt to auto-create Basic.author");
216        else if (Configuration.doAutoCreate())
217          this.author = new Reference(); // cc
218      return this.author;
219    }
220
221    public boolean hasAuthor() { 
222      return this.author != null && !this.author.isEmpty();
223    }
224
225    /**
226     * @param value {@link #author} (Indicates who was responsible for creating the resource instance.)
227     */
228    public Basic setAuthor(Reference value) { 
229      this.author = value;
230      return this;
231    }
232
233    /**
234     * @return {@link #author} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (Indicates who was responsible for creating the resource instance.)
235     */
236    public Resource getAuthorTarget() { 
237      return this.authorTarget;
238    }
239
240    /**
241     * @param value {@link #author} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (Indicates who was responsible for creating the resource instance.)
242     */
243    public Basic setAuthorTarget(Resource value) { 
244      this.authorTarget = value;
245      return this;
246    }
247
248    /**
249     * @return {@link #created} (Identifies when the resource was first created.). This is the underlying object with id, value and extensions. The accessor "getCreated" gives direct access to the value
250     */
251    public DateType getCreatedElement() { 
252      if (this.created == null)
253        if (Configuration.errorOnAutoCreate())
254          throw new Error("Attempt to auto-create Basic.created");
255        else if (Configuration.doAutoCreate())
256          this.created = new DateType(); // bb
257      return this.created;
258    }
259
260    public boolean hasCreatedElement() { 
261      return this.created != null && !this.created.isEmpty();
262    }
263
264    public boolean hasCreated() { 
265      return this.created != null && !this.created.isEmpty();
266    }
267
268    /**
269     * @param value {@link #created} (Identifies when the resource was first created.). This is the underlying object with id, value and extensions. The accessor "getCreated" gives direct access to the value
270     */
271    public Basic setCreatedElement(DateType value) { 
272      this.created = value;
273      return this;
274    }
275
276    /**
277     * @return Identifies when the resource was first created.
278     */
279    public Date getCreated() { 
280      return this.created == null ? null : this.created.getValue();
281    }
282
283    /**
284     * @param value Identifies when the resource was first created.
285     */
286    public Basic setCreated(Date value) { 
287      if (value == null)
288        this.created = null;
289      else {
290        if (this.created == null)
291          this.created = new DateType();
292        this.created.setValue(value);
293      }
294      return this;
295    }
296
297      protected void listChildren(List<Property> childrenList) {
298        super.listChildren(childrenList);
299        childrenList.add(new Property("identifier", "Identifier", "Identifier assigned to the resource for business purposes, outside the context of FHIR.", 0, java.lang.Integer.MAX_VALUE, identifier));
300        childrenList.add(new Property("code", "CodeableConcept", "Identifies the 'type' of resource - equivalent to the resource name for other resources.", 0, java.lang.Integer.MAX_VALUE, code));
301        childrenList.add(new Property("subject", "Reference(Any)", "Identifies the patient, practitioner, device or any other resource that is the \"focus\" of this resource.", 0, java.lang.Integer.MAX_VALUE, subject));
302        childrenList.add(new Property("author", "Reference(Practitioner|Patient|RelatedPerson)", "Indicates who was responsible for creating the resource instance.", 0, java.lang.Integer.MAX_VALUE, author));
303        childrenList.add(new Property("created", "date", "Identifies when the resource was first created.", 0, java.lang.Integer.MAX_VALUE, created));
304      }
305
306      @Override
307      public void setProperty(String name, Base value) throws FHIRException {
308        if (name.equals("identifier"))
309          this.getIdentifier().add(castToIdentifier(value));
310        else if (name.equals("code"))
311          this.code = castToCodeableConcept(value); // CodeableConcept
312        else if (name.equals("subject"))
313          this.subject = castToReference(value); // Reference
314        else if (name.equals("author"))
315          this.author = castToReference(value); // Reference
316        else if (name.equals("created"))
317          this.created = castToDate(value); // DateType
318        else
319          super.setProperty(name, value);
320      }
321
322      @Override
323      public Base addChild(String name) throws FHIRException {
324        if (name.equals("identifier")) {
325          return addIdentifier();
326        }
327        else if (name.equals("code")) {
328          this.code = new CodeableConcept();
329          return this.code;
330        }
331        else if (name.equals("subject")) {
332          this.subject = new Reference();
333          return this.subject;
334        }
335        else if (name.equals("author")) {
336          this.author = new Reference();
337          return this.author;
338        }
339        else if (name.equals("created")) {
340          throw new FHIRException("Cannot call addChild on a primitive type Basic.created");
341        }
342        else
343          return super.addChild(name);
344      }
345
346  public String fhirType() {
347    return "Basic";
348
349  }
350
351      public Basic copy() {
352        Basic dst = new Basic();
353        copyValues(dst);
354        if (identifier != null) {
355          dst.identifier = new ArrayList<Identifier>();
356          for (Identifier i : identifier)
357            dst.identifier.add(i.copy());
358        };
359        dst.code = code == null ? null : code.copy();
360        dst.subject = subject == null ? null : subject.copy();
361        dst.author = author == null ? null : author.copy();
362        dst.created = created == null ? null : created.copy();
363        return dst;
364      }
365
366      protected Basic typedCopy() {
367        return copy();
368      }
369
370      @Override
371      public boolean equalsDeep(Base other) {
372        if (!super.equalsDeep(other))
373          return false;
374        if (!(other instanceof Basic))
375          return false;
376        Basic o = (Basic) other;
377        return compareDeep(identifier, o.identifier, true) && compareDeep(code, o.code, true) && compareDeep(subject, o.subject, true)
378           && compareDeep(author, o.author, true) && compareDeep(created, o.created, true);
379      }
380
381      @Override
382      public boolean equalsShallow(Base other) {
383        if (!super.equalsShallow(other))
384          return false;
385        if (!(other instanceof Basic))
386          return false;
387        Basic o = (Basic) other;
388        return compareValues(created, o.created, true);
389      }
390
391      public boolean isEmpty() {
392        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (code == null || code.isEmpty())
393           && (subject == null || subject.isEmpty()) && (author == null || author.isEmpty()) && (created == null || created.isEmpty())
394          ;
395      }
396
397  @Override
398  public ResourceType getResourceType() {
399    return ResourceType.Basic;
400   }
401
402  @SearchParamDefinition(name="identifier", path="Basic.identifier", description="Business identifier", type="token" )
403  public static final String SP_IDENTIFIER = "identifier";
404  @SearchParamDefinition(name="code", path="Basic.code", description="Kind of Resource", type="token" )
405  public static final String SP_CODE = "code";
406  @SearchParamDefinition(name="subject", path="Basic.subject", description="Identifies the focus of this resource", type="reference" )
407  public static final String SP_SUBJECT = "subject";
408  @SearchParamDefinition(name="created", path="Basic.created", description="When created", type="date" )
409  public static final String SP_CREATED = "created";
410  @SearchParamDefinition(name="patient", path="Basic.subject", description="Identifies the focus of this resource", type="reference" )
411  public static final String SP_PATIENT = "patient";
412  @SearchParamDefinition(name="author", path="Basic.author", description="Who created", type="reference" )
413  public static final String SP_AUTHOR = "author";
414
415}
416