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.ArrayList;
034import java.util.List;
035
036import org.hl7.fhir.exceptions.FHIRException;
037import org.hl7.fhir.utilities.Utilities;
038
039import ca.uhn.fhir.model.api.annotation.*;
040/**
041 * 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.
042 */
043@ResourceDef(name="BodySite", profile="http://hl7.org/fhir/Profile/BodySite")
044public class BodySite extends DomainResource {
045
046    /**
047     * The person to which the body site belongs.
048     */
049    @Child(name = "patient", type = {Patient.class}, order=0, min=1, max=1, modifier=false, summary=true)
050    @Description(shortDefinition="Patient", formalDefinition="The person to which the body site belongs." )
051    protected Reference patient;
052
053    /**
054     * The actual object that is the target of the reference (The person to which the body site belongs.)
055     */
056    protected Patient patientTarget;
057
058    /**
059     * Identifier for this instance of the anatomical location.
060     */
061    @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
062    @Description(shortDefinition="Bodysite identifier", formalDefinition="Identifier for this instance of the anatomical location." )
063    protected List<Identifier> identifier;
064
065    /**
066     * Named anatomical location - ideally coded where possible.
067     */
068    @Child(name = "code", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=true)
069    @Description(shortDefinition="Named anatomical location", formalDefinition="Named anatomical location - ideally coded where possible." )
070    protected CodeableConcept code;
071
072    /**
073     * Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.
074     */
075    @Child(name = "modifier", type = {CodeableConcept.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
076    @Description(shortDefinition="Modification to location code", formalDefinition="Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane." )
077    protected List<CodeableConcept> modifier;
078
079    /**
080     * Description of anatomical location.
081     */
082    @Child(name = "description", type = {StringType.class}, order=4, min=0, max=1, modifier=false, summary=true)
083    @Description(shortDefinition="The Description of anatomical location", formalDefinition="Description of anatomical location." )
084    protected StringType description;
085
086    /**
087     * Image or images used to identify a location.
088     */
089    @Child(name = "image", type = {Attachment.class}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
090    @Description(shortDefinition="Attached images", formalDefinition="Image or images used to identify a location." )
091    protected List<Attachment> image;
092
093    private static final long serialVersionUID = 1568109920L;
094
095  /*
096   * Constructor
097   */
098    public BodySite() {
099      super();
100    }
101
102  /*
103   * Constructor
104   */
105    public BodySite(Reference patient) {
106      super();
107      this.patient = patient;
108    }
109
110    /**
111     * @return {@link #patient} (The person to which the body site belongs.)
112     */
113    public Reference getPatient() { 
114      if (this.patient == null)
115        if (Configuration.errorOnAutoCreate())
116          throw new Error("Attempt to auto-create BodySite.patient");
117        else if (Configuration.doAutoCreate())
118          this.patient = new Reference(); // cc
119      return this.patient;
120    }
121
122    public boolean hasPatient() { 
123      return this.patient != null && !this.patient.isEmpty();
124    }
125
126    /**
127     * @param value {@link #patient} (The person to which the body site belongs.)
128     */
129    public BodySite setPatient(Reference value) { 
130      this.patient = value;
131      return this;
132    }
133
134    /**
135     * @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.)
136     */
137    public Patient getPatientTarget() { 
138      if (this.patientTarget == null)
139        if (Configuration.errorOnAutoCreate())
140          throw new Error("Attempt to auto-create BodySite.patient");
141        else if (Configuration.doAutoCreate())
142          this.patientTarget = new Patient(); // aa
143      return this.patientTarget;
144    }
145
146    /**
147     * @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.)
148     */
149    public BodySite setPatientTarget(Patient value) { 
150      this.patientTarget = value;
151      return this;
152    }
153
154    /**
155     * @return {@link #identifier} (Identifier for this instance of the anatomical location.)
156     */
157    public List<Identifier> getIdentifier() { 
158      if (this.identifier == null)
159        this.identifier = new ArrayList<Identifier>();
160      return this.identifier;
161    }
162
163    public boolean hasIdentifier() { 
164      if (this.identifier == null)
165        return false;
166      for (Identifier item : this.identifier)
167        if (!item.isEmpty())
168          return true;
169      return false;
170    }
171
172    /**
173     * @return {@link #identifier} (Identifier for this instance of the anatomical location.)
174     */
175    // syntactic sugar
176    public Identifier addIdentifier() { //3
177      Identifier t = new Identifier();
178      if (this.identifier == null)
179        this.identifier = new ArrayList<Identifier>();
180      this.identifier.add(t);
181      return t;
182    }
183
184    // syntactic sugar
185    public BodySite addIdentifier(Identifier t) { //3
186      if (t == null)
187        return this;
188      if (this.identifier == null)
189        this.identifier = new ArrayList<Identifier>();
190      this.identifier.add(t);
191      return this;
192    }
193
194    /**
195     * @return {@link #code} (Named anatomical location - ideally coded where possible.)
196     */
197    public CodeableConcept getCode() { 
198      if (this.code == null)
199        if (Configuration.errorOnAutoCreate())
200          throw new Error("Attempt to auto-create BodySite.code");
201        else if (Configuration.doAutoCreate())
202          this.code = new CodeableConcept(); // cc
203      return this.code;
204    }
205
206    public boolean hasCode() { 
207      return this.code != null && !this.code.isEmpty();
208    }
209
210    /**
211     * @param value {@link #code} (Named anatomical location - ideally coded where possible.)
212     */
213    public BodySite setCode(CodeableConcept value) { 
214      this.code = value;
215      return this;
216    }
217
218    /**
219     * @return {@link #modifier} (Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.)
220     */
221    public List<CodeableConcept> getModifier() { 
222      if (this.modifier == null)
223        this.modifier = new ArrayList<CodeableConcept>();
224      return this.modifier;
225    }
226
227    public boolean hasModifier() { 
228      if (this.modifier == null)
229        return false;
230      for (CodeableConcept item : this.modifier)
231        if (!item.isEmpty())
232          return true;
233      return false;
234    }
235
236    /**
237     * @return {@link #modifier} (Modifier to refine the anatomical location.  These include modifiers for laterality, relative location, directionality, number, and plane.)
238     */
239    // syntactic sugar
240    public CodeableConcept addModifier() { //3
241      CodeableConcept t = new CodeableConcept();
242      if (this.modifier == null)
243        this.modifier = new ArrayList<CodeableConcept>();
244      this.modifier.add(t);
245      return t;
246    }
247
248    // syntactic sugar
249    public BodySite addModifier(CodeableConcept t) { //3
250      if (t == null)
251        return this;
252      if (this.modifier == null)
253        this.modifier = new ArrayList<CodeableConcept>();
254      this.modifier.add(t);
255      return this;
256    }
257
258    /**
259     * @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
260     */
261    public StringType getDescriptionElement() { 
262      if (this.description == null)
263        if (Configuration.errorOnAutoCreate())
264          throw new Error("Attempt to auto-create BodySite.description");
265        else if (Configuration.doAutoCreate())
266          this.description = new StringType(); // bb
267      return this.description;
268    }
269
270    public boolean hasDescriptionElement() { 
271      return this.description != null && !this.description.isEmpty();
272    }
273
274    public boolean hasDescription() { 
275      return this.description != null && !this.description.isEmpty();
276    }
277
278    /**
279     * @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
280     */
281    public BodySite setDescriptionElement(StringType value) { 
282      this.description = value;
283      return this;
284    }
285
286    /**
287     * @return Description of anatomical location.
288     */
289    public String getDescription() { 
290      return this.description == null ? null : this.description.getValue();
291    }
292
293    /**
294     * @param value Description of anatomical location.
295     */
296    public BodySite setDescription(String value) { 
297      if (Utilities.noString(value))
298        this.description = null;
299      else {
300        if (this.description == null)
301          this.description = new StringType();
302        this.description.setValue(value);
303      }
304      return this;
305    }
306
307    /**
308     * @return {@link #image} (Image or images used to identify a location.)
309     */
310    public List<Attachment> getImage() { 
311      if (this.image == null)
312        this.image = new ArrayList<Attachment>();
313      return this.image;
314    }
315
316    public boolean hasImage() { 
317      if (this.image == null)
318        return false;
319      for (Attachment item : this.image)
320        if (!item.isEmpty())
321          return true;
322      return false;
323    }
324
325    /**
326     * @return {@link #image} (Image or images used to identify a location.)
327     */
328    // syntactic sugar
329    public Attachment addImage() { //3
330      Attachment t = new Attachment();
331      if (this.image == null)
332        this.image = new ArrayList<Attachment>();
333      this.image.add(t);
334      return t;
335    }
336
337    // syntactic sugar
338    public BodySite addImage(Attachment t) { //3
339      if (t == null)
340        return this;
341      if (this.image == null)
342        this.image = new ArrayList<Attachment>();
343      this.image.add(t);
344      return this;
345    }
346
347      protected void listChildren(List<Property> childrenList) {
348        super.listChildren(childrenList);
349        childrenList.add(new Property("patient", "Reference(Patient)", "The person to which the body site belongs.", 0, java.lang.Integer.MAX_VALUE, patient));
350        childrenList.add(new Property("identifier", "Identifier", "Identifier for this instance of the anatomical location.", 0, java.lang.Integer.MAX_VALUE, identifier));
351        childrenList.add(new Property("code", "CodeableConcept", "Named anatomical location - ideally coded where possible.", 0, java.lang.Integer.MAX_VALUE, code));
352        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));
353        childrenList.add(new Property("description", "string", "Description of anatomical location.", 0, java.lang.Integer.MAX_VALUE, description));
354        childrenList.add(new Property("image", "Attachment", "Image or images used to identify a location.", 0, java.lang.Integer.MAX_VALUE, image));
355      }
356
357      @Override
358      public void setProperty(String name, Base value) throws FHIRException {
359        if (name.equals("patient"))
360          this.patient = castToReference(value); // Reference
361        else if (name.equals("identifier"))
362          this.getIdentifier().add(castToIdentifier(value));
363        else if (name.equals("code"))
364          this.code = castToCodeableConcept(value); // CodeableConcept
365        else if (name.equals("modifier"))
366          this.getModifier().add(castToCodeableConcept(value));
367        else if (name.equals("description"))
368          this.description = castToString(value); // StringType
369        else if (name.equals("image"))
370          this.getImage().add(castToAttachment(value));
371        else
372          super.setProperty(name, value);
373      }
374
375      @Override
376      public Base addChild(String name) throws FHIRException {
377        if (name.equals("patient")) {
378          this.patient = new Reference();
379          return this.patient;
380        }
381        else if (name.equals("identifier")) {
382          return addIdentifier();
383        }
384        else if (name.equals("code")) {
385          this.code = new CodeableConcept();
386          return this.code;
387        }
388        else if (name.equals("modifier")) {
389          return addModifier();
390        }
391        else if (name.equals("description")) {
392          throw new FHIRException("Cannot call addChild on a primitive type BodySite.description");
393        }
394        else if (name.equals("image")) {
395          return addImage();
396        }
397        else
398          return super.addChild(name);
399      }
400
401  public String fhirType() {
402    return "BodySite";
403
404  }
405
406      public BodySite copy() {
407        BodySite dst = new BodySite();
408        copyValues(dst);
409        dst.patient = patient == null ? null : patient.copy();
410        if (identifier != null) {
411          dst.identifier = new ArrayList<Identifier>();
412          for (Identifier i : identifier)
413            dst.identifier.add(i.copy());
414        };
415        dst.code = code == null ? null : code.copy();
416        if (modifier != null) {
417          dst.modifier = new ArrayList<CodeableConcept>();
418          for (CodeableConcept i : modifier)
419            dst.modifier.add(i.copy());
420        };
421        dst.description = description == null ? null : description.copy();
422        if (image != null) {
423          dst.image = new ArrayList<Attachment>();
424          for (Attachment i : image)
425            dst.image.add(i.copy());
426        };
427        return dst;
428      }
429
430      protected BodySite typedCopy() {
431        return copy();
432      }
433
434      @Override
435      public boolean equalsDeep(Base other) {
436        if (!super.equalsDeep(other))
437          return false;
438        if (!(other instanceof BodySite))
439          return false;
440        BodySite o = (BodySite) other;
441        return compareDeep(patient, o.patient, true) && compareDeep(identifier, o.identifier, true) && compareDeep(code, o.code, true)
442           && compareDeep(modifier, o.modifier, true) && compareDeep(description, o.description, true) && compareDeep(image, o.image, true)
443          ;
444      }
445
446      @Override
447      public boolean equalsShallow(Base other) {
448        if (!super.equalsShallow(other))
449          return false;
450        if (!(other instanceof BodySite))
451          return false;
452        BodySite o = (BodySite) other;
453        return compareValues(description, o.description, true);
454      }
455
456      public boolean isEmpty() {
457        return super.isEmpty() && (patient == null || patient.isEmpty()) && (identifier == null || identifier.isEmpty())
458           && (code == null || code.isEmpty()) && (modifier == null || modifier.isEmpty()) && (description == null || description.isEmpty())
459           && (image == null || image.isEmpty());
460      }
461
462  @Override
463  public ResourceType getResourceType() {
464    return ResourceType.BodySite;
465   }
466
467  @SearchParamDefinition(name="identifier", path="BodySite.identifier", description="Identifier for this instance of the anatomical location", type="token" )
468  public static final String SP_IDENTIFIER = "identifier";
469  @SearchParamDefinition(name="code", path="BodySite.code", description="Named anatomical location", type="token" )
470  public static final String SP_CODE = "code";
471  @SearchParamDefinition(name="patient", path="BodySite.patient", description="Patient to whom bodysite belongs", type="reference" )
472  public static final String SP_PATIENT = "patient";
473
474}
475