001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.List;
038
039import ca.uhn.fhir.model.api.annotation.Child;
040import ca.uhn.fhir.model.api.annotation.Description;
041import ca.uhn.fhir.model.api.annotation.ResourceDef;
042import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
043import org.hl7.fhir.exceptions.FHIRException;
044import org.hl7.fhir.utilities.Utilities;
045/**
046 * Record details about the anatomical location of a specimen or body part.  This resource may be used when a coded concept does not provide the necessary detail needed for the use case.
047 */
048@ResourceDef(name="BodySite", profile="http://hl7.org/fhir/Profile/BodySite")
049public class BodySite extends DomainResource {
050
051    /**
052     * The person to which the body site belongs.
053     */
054    @Child(name = "patient", type = {Patient.class}, order=0, min=1, max=1, modifier=false, summary=true)
055    @Description(shortDefinition="Patient", formalDefinition="The person to which the body site belongs." )
056    protected Reference patient;
057
058    /**
059     * The actual object that is the target of the reference (The person to which the body site belongs.)
060     */
061    protected Patient patientTarget;
062
063    /**
064     * Identifier for this instance of the anatomical location.
065     */
066    @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
067    @Description(shortDefinition="Bodysite identifier", formalDefinition="Identifier for this instance of the anatomical location." )
068    protected List<Identifier> identifier;
069
070    /**
071     * Named anatomical location - ideally coded where possible.
072     */
073    @Child(name = "code", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=true)
074    @Description(shortDefinition="Named anatomical location", formalDefinition="Named anatomical location - ideally coded where possible." )
075    protected CodeableConcept code;
076
077    /**
078     * Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.
079     */
080    @Child(name = "modifier", type = {CodeableConcept.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
081    @Description(shortDefinition="Modification to location code", formalDefinition="Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane." )
082    protected List<CodeableConcept> modifier;
083
084    /**
085     * Description of anatomical location.
086     */
087    @Child(name = "description", type = {StringType.class}, order=4, min=0, max=1, modifier=false, summary=true)
088    @Description(shortDefinition="The Description of anatomical location", formalDefinition="Description of anatomical location." )
089    protected StringType description;
090
091    /**
092     * Image or images used to identify a location.
093     */
094    @Child(name = "image", type = {Attachment.class}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
095    @Description(shortDefinition="Attached images", formalDefinition="Image or images used to identify a location." )
096    protected List<Attachment> image;
097
098    private static final long serialVersionUID = 1568109920L;
099
100  /*
101   * Constructor
102   */
103    public BodySite() {
104      super();
105    }
106
107  /*
108   * Constructor
109   */
110    public BodySite(Reference patient) {
111      super();
112      this.patient = patient;
113    }
114
115    /**
116     * @return {@link #patient} (The person to which the body site belongs.)
117     */
118    public Reference getPatient() { 
119      if (this.patient == null)
120        if (Configuration.errorOnAutoCreate())
121          throw new Error("Attempt to auto-create BodySite.patient");
122        else if (Configuration.doAutoCreate())
123          this.patient = new Reference(); // cc
124      return this.patient;
125    }
126
127    public boolean hasPatient() { 
128      return this.patient != null && !this.patient.isEmpty();
129    }
130
131    /**
132     * @param value {@link #patient} (The person to which the body site belongs.)
133     */
134    public BodySite setPatient(Reference value) { 
135      this.patient = value;
136      return this;
137    }
138
139    /**
140     * @return {@link #patient} 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. (The person to which the body site belongs.)
141     */
142    public Patient getPatientTarget() { 
143      if (this.patientTarget == null)
144        if (Configuration.errorOnAutoCreate())
145          throw new Error("Attempt to auto-create BodySite.patient");
146        else if (Configuration.doAutoCreate())
147          this.patientTarget = new Patient(); // aa
148      return this.patientTarget;
149    }
150
151    /**
152     * @param value {@link #patient} 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. (The person to which the body site belongs.)
153     */
154    public BodySite setPatientTarget(Patient value) { 
155      this.patientTarget = value;
156      return this;
157    }
158
159    /**
160     * @return {@link #identifier} (Identifier for this instance of the anatomical location.)
161     */
162    public List<Identifier> getIdentifier() { 
163      if (this.identifier == null)
164        this.identifier = new ArrayList<Identifier>();
165      return this.identifier;
166    }
167
168    public boolean hasIdentifier() { 
169      if (this.identifier == null)
170        return false;
171      for (Identifier item : this.identifier)
172        if (!item.isEmpty())
173          return true;
174      return false;
175    }
176
177    /**
178     * @return {@link #identifier} (Identifier for this instance of the anatomical location.)
179     */
180    // syntactic sugar
181    public Identifier addIdentifier() { //3
182      Identifier t = new Identifier();
183      if (this.identifier == null)
184        this.identifier = new ArrayList<Identifier>();
185      this.identifier.add(t);
186      return t;
187    }
188
189    // syntactic sugar
190    public BodySite addIdentifier(Identifier t) { //3
191      if (t == null)
192        return this;
193      if (this.identifier == null)
194        this.identifier = new ArrayList<Identifier>();
195      this.identifier.add(t);
196      return this;
197    }
198
199    /**
200     * @return {@link #code} (Named anatomical location - ideally coded where possible.)
201     */
202    public CodeableConcept getCode() { 
203      if (this.code == null)
204        if (Configuration.errorOnAutoCreate())
205          throw new Error("Attempt to auto-create BodySite.code");
206        else if (Configuration.doAutoCreate())
207          this.code = new CodeableConcept(); // cc
208      return this.code;
209    }
210
211    public boolean hasCode() { 
212      return this.code != null && !this.code.isEmpty();
213    }
214
215    /**
216     * @param value {@link #code} (Named anatomical location - ideally coded where possible.)
217     */
218    public BodySite setCode(CodeableConcept value) { 
219      this.code = value;
220      return this;
221    }
222
223    /**
224     * @return {@link #modifier} (Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.)
225     */
226    public List<CodeableConcept> getModifier() { 
227      if (this.modifier == null)
228        this.modifier = new ArrayList<CodeableConcept>();
229      return this.modifier;
230    }
231
232    public boolean hasModifier() { 
233      if (this.modifier == null)
234        return false;
235      for (CodeableConcept item : this.modifier)
236        if (!item.isEmpty())
237          return true;
238      return false;
239    }
240
241    /**
242     * @return {@link #modifier} (Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.)
243     */
244    // syntactic sugar
245    public CodeableConcept addModifier() { //3
246      CodeableConcept t = new CodeableConcept();
247      if (this.modifier == null)
248        this.modifier = new ArrayList<CodeableConcept>();
249      this.modifier.add(t);
250      return t;
251    }
252
253    // syntactic sugar
254    public BodySite addModifier(CodeableConcept t) { //3
255      if (t == null)
256        return this;
257      if (this.modifier == null)
258        this.modifier = new ArrayList<CodeableConcept>();
259      this.modifier.add(t);
260      return this;
261    }
262
263    /**
264     * @return {@link #description} (Description of anatomical location.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value
265     */
266    public StringType getDescriptionElement() { 
267      if (this.description == null)
268        if (Configuration.errorOnAutoCreate())
269          throw new Error("Attempt to auto-create BodySite.description");
270        else if (Configuration.doAutoCreate())
271          this.description = new StringType(); // bb
272      return this.description;
273    }
274
275    public boolean hasDescriptionElement() { 
276      return this.description != null && !this.description.isEmpty();
277    }
278
279    public boolean hasDescription() { 
280      return this.description != null && !this.description.isEmpty();
281    }
282
283    /**
284     * @param value {@link #description} (Description of anatomical location.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value
285     */
286    public BodySite setDescriptionElement(StringType value) { 
287      this.description = value;
288      return this;
289    }
290
291    /**
292     * @return Description of anatomical location.
293     */
294    public String getDescription() { 
295      return this.description == null ? null : this.description.getValue();
296    }
297
298    /**
299     * @param value Description of anatomical location.
300     */
301    public BodySite setDescription(String value) { 
302      if (Utilities.noString(value))
303        this.description = null;
304      else {
305        if (this.description == null)
306          this.description = new StringType();
307        this.description.setValue(value);
308      }
309      return this;
310    }
311
312    /**
313     * @return {@link #image} (Image or images used to identify a location.)
314     */
315    public List<Attachment> getImage() { 
316      if (this.image == null)
317        this.image = new ArrayList<Attachment>();
318      return this.image;
319    }
320
321    public boolean hasImage() { 
322      if (this.image == null)
323        return false;
324      for (Attachment item : this.image)
325        if (!item.isEmpty())
326          return true;
327      return false;
328    }
329
330    /**
331     * @return {@link #image} (Image or images used to identify a location.)
332     */
333    // syntactic sugar
334    public Attachment addImage() { //3
335      Attachment t = new Attachment();
336      if (this.image == null)
337        this.image = new ArrayList<Attachment>();
338      this.image.add(t);
339      return t;
340    }
341
342    // syntactic sugar
343    public BodySite addImage(Attachment t) { //3
344      if (t == null)
345        return this;
346      if (this.image == null)
347        this.image = new ArrayList<Attachment>();
348      this.image.add(t);
349      return this;
350    }
351
352      protected void listChildren(List<Property> childrenList) {
353        super.listChildren(childrenList);
354        childrenList.add(new Property("patient", "Reference(Patient)", "The person to which the body site belongs.", 0, java.lang.Integer.MAX_VALUE, patient));
355        childrenList.add(new Property("identifier", "Identifier", "Identifier for this instance of the anatomical location.", 0, java.lang.Integer.MAX_VALUE, identifier));
356        childrenList.add(new Property("code", "CodeableConcept", "Named anatomical location - ideally coded where possible.", 0, java.lang.Integer.MAX_VALUE, code));
357        childrenList.add(new Property("modifier", "CodeableConcept", "Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.", 0, java.lang.Integer.MAX_VALUE, modifier));
358        childrenList.add(new Property("description", "string", "Description of anatomical location.", 0, java.lang.Integer.MAX_VALUE, description));
359        childrenList.add(new Property("image", "Attachment", "Image or images used to identify a location.", 0, java.lang.Integer.MAX_VALUE, image));
360      }
361
362      @Override
363      public void setProperty(String name, Base value) throws FHIRException {
364        if (name.equals("patient"))
365          this.patient = castToReference(value); // Reference
366        else if (name.equals("identifier"))
367          this.getIdentifier().add(castToIdentifier(value));
368        else if (name.equals("code"))
369          this.code = castToCodeableConcept(value); // CodeableConcept
370        else if (name.equals("modifier"))
371          this.getModifier().add(castToCodeableConcept(value));
372        else if (name.equals("description"))
373          this.description = castToString(value); // StringType
374        else if (name.equals("image"))
375          this.getImage().add(castToAttachment(value));
376        else
377          super.setProperty(name, value);
378      }
379
380      @Override
381      public Base addChild(String name) throws FHIRException {
382        if (name.equals("patient")) {
383          this.patient = new Reference();
384          return this.patient;
385        }
386        else if (name.equals("identifier")) {
387          return addIdentifier();
388        }
389        else if (name.equals("code")) {
390          this.code = new CodeableConcept();
391          return this.code;
392        }
393        else if (name.equals("modifier")) {
394          return addModifier();
395        }
396        else if (name.equals("description")) {
397          throw new FHIRException("Cannot call addChild on a primitive type BodySite.description");
398        }
399        else if (name.equals("image")) {
400          return addImage();
401        }
402        else
403          return super.addChild(name);
404      }
405
406  public String fhirType() {
407    return "BodySite";
408
409  }
410
411      public BodySite copy() {
412        BodySite dst = new BodySite();
413        copyValues(dst);
414        dst.patient = patient == null ? null : patient.copy();
415        if (identifier != null) {
416          dst.identifier = new ArrayList<Identifier>();
417          for (Identifier i : identifier)
418            dst.identifier.add(i.copy());
419        };
420        dst.code = code == null ? null : code.copy();
421        if (modifier != null) {
422          dst.modifier = new ArrayList<CodeableConcept>();
423          for (CodeableConcept i : modifier)
424            dst.modifier.add(i.copy());
425        };
426        dst.description = description == null ? null : description.copy();
427        if (image != null) {
428          dst.image = new ArrayList<Attachment>();
429          for (Attachment i : image)
430            dst.image.add(i.copy());
431        };
432        return dst;
433      }
434
435      protected BodySite typedCopy() {
436        return copy();
437      }
438
439      @Override
440      public boolean equalsDeep(Base other) {
441        if (!super.equalsDeep(other))
442          return false;
443        if (!(other instanceof BodySite))
444          return false;
445        BodySite o = (BodySite) other;
446        return compareDeep(patient, o.patient, true) && compareDeep(identifier, o.identifier, true) && compareDeep(code, o.code, true)
447           && compareDeep(modifier, o.modifier, true) && compareDeep(description, o.description, true) && compareDeep(image, o.image, true)
448          ;
449      }
450
451      @Override
452      public boolean equalsShallow(Base other) {
453        if (!super.equalsShallow(other))
454          return false;
455        if (!(other instanceof BodySite))
456          return false;
457        BodySite o = (BodySite) other;
458        return compareValues(description, o.description, true);
459      }
460
461      public boolean isEmpty() {
462        return super.isEmpty() && (patient == null || patient.isEmpty()) && (identifier == null || identifier.isEmpty())
463           && (code == null || code.isEmpty()) && (modifier == null || modifier.isEmpty()) && (description == null || description.isEmpty())
464           && (image == null || image.isEmpty());
465      }
466
467  @Override
468  public ResourceType getResourceType() {
469    return ResourceType.BodySite;
470   }
471
472  @SearchParamDefinition(name="identifier", path="BodySite.identifier", description="Identifier for this instance of the anatomical location", type="token" )
473  public static final String SP_IDENTIFIER = "identifier";
474  @SearchParamDefinition(name="code", path="BodySite.code", description="Named anatomical location", type="token" )
475  public static final String SP_CODE = "code";
476  @SearchParamDefinition(name="patient", path="BodySite.patient", description="Patient to whom bodysite belongs", type="reference" )
477  public static final String SP_PATIENT = "patient";
478
479}