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.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.ResourceDef;
044import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
045import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
046import org.hl7.fhir.exceptions.FHIRException;
047import org.hl7.fhir.utilities.Utilities;
048/**
049 * Measurements and simple assertions made about a patient, device or other subject.
050 */
051@ResourceDef(name="Observation", profile="http://hl7.org/fhir/Profile/Observation")
052public class Observation extends DomainResource {
053
054    public enum ObservationStatus {
055        /**
056         * The existence of the observation is registered, but there is no result yet available.
057         */
058        REGISTERED, 
059        /**
060         * This is an initial or interim observation: data may be incomplete or unverified.
061         */
062        PRELIMINARY, 
063        /**
064         * The observation is complete and verified by an authorized person.
065         */
066        FINAL, 
067        /**
068         * The observation has been modified subsequent to being Final, and is complete and verified by an authorized person.
069         */
070        AMENDED, 
071        /**
072         * The observation is unavailable because the measurement was not started or not completed (also sometimes called "aborted").
073         */
074        CANCELLED, 
075        /**
076         * The observation has been withdrawn following previous final release.
077         */
078        ENTEREDINERROR, 
079        /**
080         * The observation status is unknown.  Note that "unknown" is a value of last resort and every attempt should be made to provide a meaningful value other than "unknown".
081         */
082        UNKNOWN, 
083        /**
084         * added to help the parsers
085         */
086        NULL;
087        public static ObservationStatus fromCode(String codeString) throws FHIRException {
088            if (codeString == null || "".equals(codeString))
089                return null;
090        if ("registered".equals(codeString))
091          return REGISTERED;
092        if ("preliminary".equals(codeString))
093          return PRELIMINARY;
094        if ("final".equals(codeString))
095          return FINAL;
096        if ("amended".equals(codeString))
097          return AMENDED;
098        if ("cancelled".equals(codeString))
099          return CANCELLED;
100        if ("entered-in-error".equals(codeString))
101          return ENTEREDINERROR;
102        if ("unknown".equals(codeString))
103          return UNKNOWN;
104        throw new FHIRException("Unknown ObservationStatus code '"+codeString+"'");
105        }
106        public String toCode() {
107          switch (this) {
108            case REGISTERED: return "registered";
109            case PRELIMINARY: return "preliminary";
110            case FINAL: return "final";
111            case AMENDED: return "amended";
112            case CANCELLED: return "cancelled";
113            case ENTEREDINERROR: return "entered-in-error";
114            case UNKNOWN: return "unknown";
115            default: return "?";
116          }
117        }
118        public String getSystem() {
119          switch (this) {
120            case REGISTERED: return "http://hl7.org/fhir/observation-status";
121            case PRELIMINARY: return "http://hl7.org/fhir/observation-status";
122            case FINAL: return "http://hl7.org/fhir/observation-status";
123            case AMENDED: return "http://hl7.org/fhir/observation-status";
124            case CANCELLED: return "http://hl7.org/fhir/observation-status";
125            case ENTEREDINERROR: return "http://hl7.org/fhir/observation-status";
126            case UNKNOWN: return "http://hl7.org/fhir/observation-status";
127            default: return "?";
128          }
129        }
130        public String getDefinition() {
131          switch (this) {
132            case REGISTERED: return "The existence of the observation is registered, but there is no result yet available.";
133            case PRELIMINARY: return "This is an initial or interim observation: data may be incomplete or unverified.";
134            case FINAL: return "The observation is complete and verified by an authorized person.";
135            case AMENDED: return "The observation has been modified subsequent to being Final, and is complete and verified by an authorized person.";
136            case CANCELLED: return "The observation is unavailable because the measurement was not started or not completed (also sometimes called \"aborted\").";
137            case ENTEREDINERROR: return "The observation has been withdrawn following previous final release.";
138            case UNKNOWN: return "The observation status is unknown.  Note that \"unknown\" is a value of last resort and every attempt should be made to provide a meaningful value other than \"unknown\".";
139            default: return "?";
140          }
141        }
142        public String getDisplay() {
143          switch (this) {
144            case REGISTERED: return "Registered";
145            case PRELIMINARY: return "Preliminary";
146            case FINAL: return "Final";
147            case AMENDED: return "Amended";
148            case CANCELLED: return "cancelled";
149            case ENTEREDINERROR: return "Entered in Error";
150            case UNKNOWN: return "Unknown Status";
151            default: return "?";
152          }
153        }
154    }
155
156  public static class ObservationStatusEnumFactory implements EnumFactory<ObservationStatus> {
157    public ObservationStatus fromCode(String codeString) throws IllegalArgumentException {
158      if (codeString == null || "".equals(codeString))
159            if (codeString == null || "".equals(codeString))
160                return null;
161        if ("registered".equals(codeString))
162          return ObservationStatus.REGISTERED;
163        if ("preliminary".equals(codeString))
164          return ObservationStatus.PRELIMINARY;
165        if ("final".equals(codeString))
166          return ObservationStatus.FINAL;
167        if ("amended".equals(codeString))
168          return ObservationStatus.AMENDED;
169        if ("cancelled".equals(codeString))
170          return ObservationStatus.CANCELLED;
171        if ("entered-in-error".equals(codeString))
172          return ObservationStatus.ENTEREDINERROR;
173        if ("unknown".equals(codeString))
174          return ObservationStatus.UNKNOWN;
175        throw new IllegalArgumentException("Unknown ObservationStatus code '"+codeString+"'");
176        }
177        public Enumeration<ObservationStatus> fromType(Base code) throws FHIRException {
178          if (code == null || code.isEmpty())
179            return null;
180          String codeString = ((PrimitiveType) code).asStringValue();
181          if (codeString == null || "".equals(codeString))
182            return null;
183        if ("registered".equals(codeString))
184          return new Enumeration<ObservationStatus>(this, ObservationStatus.REGISTERED);
185        if ("preliminary".equals(codeString))
186          return new Enumeration<ObservationStatus>(this, ObservationStatus.PRELIMINARY);
187        if ("final".equals(codeString))
188          return new Enumeration<ObservationStatus>(this, ObservationStatus.FINAL);
189        if ("amended".equals(codeString))
190          return new Enumeration<ObservationStatus>(this, ObservationStatus.AMENDED);
191        if ("cancelled".equals(codeString))
192          return new Enumeration<ObservationStatus>(this, ObservationStatus.CANCELLED);
193        if ("entered-in-error".equals(codeString))
194          return new Enumeration<ObservationStatus>(this, ObservationStatus.ENTEREDINERROR);
195        if ("unknown".equals(codeString))
196          return new Enumeration<ObservationStatus>(this, ObservationStatus.UNKNOWN);
197        throw new FHIRException("Unknown ObservationStatus code '"+codeString+"'");
198        }
199    public String toCode(ObservationStatus code) {
200      if (code == ObservationStatus.REGISTERED)
201        return "registered";
202      if (code == ObservationStatus.PRELIMINARY)
203        return "preliminary";
204      if (code == ObservationStatus.FINAL)
205        return "final";
206      if (code == ObservationStatus.AMENDED)
207        return "amended";
208      if (code == ObservationStatus.CANCELLED)
209        return "cancelled";
210      if (code == ObservationStatus.ENTEREDINERROR)
211        return "entered-in-error";
212      if (code == ObservationStatus.UNKNOWN)
213        return "unknown";
214      return "?";
215      }
216    }
217
218    public enum ObservationRelationshipType {
219        /**
220         * This observation is a group observation (e.g. a battery, a panel of tests, a set of vital sign measurements) that includes the target as a member of the group.
221         */
222        HASMEMBER, 
223        /**
224         * The target resource (Observation or QuestionnaireResponse) is part of the information from which this observation value is derived. (e.g. calculated anion gap, Apgar score)  NOTE:  "derived-from" is only logical choice when referencing QuestionnaireResponse.
225         */
226        DERIVEDFROM, 
227        /**
228         * This observation follows the target observation (e.g. timed tests such as Glucose Tolerance Test).
229         */
230        SEQUELTO, 
231        /**
232         * This observation replaces a previous observation (i.e. a revised value). The target observation is now obsolete.
233         */
234        REPLACES, 
235        /**
236         * The value of the target observation qualifies (refines) the semantics of the source observation (e.g. a lipemia measure target from a plasma measure).
237         */
238        QUALIFIEDBY, 
239        /**
240         * The value of the target observation interferes (degrades quality, or prevents valid observation) with the semantics of the source observation (e.g. a hemolysis measure target from a plasma potassium measure which has no value).
241         */
242        INTERFEREDBY, 
243        /**
244         * added to help the parsers
245         */
246        NULL;
247        public static ObservationRelationshipType fromCode(String codeString) throws FHIRException {
248            if (codeString == null || "".equals(codeString))
249                return null;
250        if ("has-member".equals(codeString))
251          return HASMEMBER;
252        if ("derived-from".equals(codeString))
253          return DERIVEDFROM;
254        if ("sequel-to".equals(codeString))
255          return SEQUELTO;
256        if ("replaces".equals(codeString))
257          return REPLACES;
258        if ("qualified-by".equals(codeString))
259          return QUALIFIEDBY;
260        if ("interfered-by".equals(codeString))
261          return INTERFEREDBY;
262        throw new FHIRException("Unknown ObservationRelationshipType code '"+codeString+"'");
263        }
264        public String toCode() {
265          switch (this) {
266            case HASMEMBER: return "has-member";
267            case DERIVEDFROM: return "derived-from";
268            case SEQUELTO: return "sequel-to";
269            case REPLACES: return "replaces";
270            case QUALIFIEDBY: return "qualified-by";
271            case INTERFEREDBY: return "interfered-by";
272            default: return "?";
273          }
274        }
275        public String getSystem() {
276          switch (this) {
277            case HASMEMBER: return "http://hl7.org/fhir/observation-relationshiptypes";
278            case DERIVEDFROM: return "http://hl7.org/fhir/observation-relationshiptypes";
279            case SEQUELTO: return "http://hl7.org/fhir/observation-relationshiptypes";
280            case REPLACES: return "http://hl7.org/fhir/observation-relationshiptypes";
281            case QUALIFIEDBY: return "http://hl7.org/fhir/observation-relationshiptypes";
282            case INTERFEREDBY: return "http://hl7.org/fhir/observation-relationshiptypes";
283            default: return "?";
284          }
285        }
286        public String getDefinition() {
287          switch (this) {
288            case HASMEMBER: return "This observation is a group observation (e.g. a battery, a panel of tests, a set of vital sign measurements) that includes the target as a member of the group.";
289            case DERIVEDFROM: return "The target resource (Observation or QuestionnaireResponse) is part of the information from which this observation value is derived. (e.g. calculated anion gap, Apgar score)  NOTE:  \"derived-from\" is only logical choice when referencing QuestionnaireResponse.";
290            case SEQUELTO: return "This observation follows the target observation (e.g. timed tests such as Glucose Tolerance Test).";
291            case REPLACES: return "This observation replaces a previous observation (i.e. a revised value). The target observation is now obsolete.";
292            case QUALIFIEDBY: return "The value of the target observation qualifies (refines) the semantics of the source observation (e.g. a lipemia measure target from a plasma measure).";
293            case INTERFEREDBY: return "The value of the target observation interferes (degrades quality, or prevents valid observation) with the semantics of the source observation (e.g. a hemolysis measure target from a plasma potassium measure which has no value).";
294            default: return "?";
295          }
296        }
297        public String getDisplay() {
298          switch (this) {
299            case HASMEMBER: return "Has Member";
300            case DERIVEDFROM: return "Derived From";
301            case SEQUELTO: return "Sequel To";
302            case REPLACES: return "Replaces";
303            case QUALIFIEDBY: return "Qualified By";
304            case INTERFEREDBY: return "Interfered By";
305            default: return "?";
306          }
307        }
308    }
309
310  public static class ObservationRelationshipTypeEnumFactory implements EnumFactory<ObservationRelationshipType> {
311    public ObservationRelationshipType fromCode(String codeString) throws IllegalArgumentException {
312      if (codeString == null || "".equals(codeString))
313            if (codeString == null || "".equals(codeString))
314                return null;
315        if ("has-member".equals(codeString))
316          return ObservationRelationshipType.HASMEMBER;
317        if ("derived-from".equals(codeString))
318          return ObservationRelationshipType.DERIVEDFROM;
319        if ("sequel-to".equals(codeString))
320          return ObservationRelationshipType.SEQUELTO;
321        if ("replaces".equals(codeString))
322          return ObservationRelationshipType.REPLACES;
323        if ("qualified-by".equals(codeString))
324          return ObservationRelationshipType.QUALIFIEDBY;
325        if ("interfered-by".equals(codeString))
326          return ObservationRelationshipType.INTERFEREDBY;
327        throw new IllegalArgumentException("Unknown ObservationRelationshipType code '"+codeString+"'");
328        }
329        public Enumeration<ObservationRelationshipType> fromType(Base code) throws FHIRException {
330          if (code == null || code.isEmpty())
331            return null;
332          String codeString = ((PrimitiveType) code).asStringValue();
333          if (codeString == null || "".equals(codeString))
334            return null;
335        if ("has-member".equals(codeString))
336          return new Enumeration<ObservationRelationshipType>(this, ObservationRelationshipType.HASMEMBER);
337        if ("derived-from".equals(codeString))
338          return new Enumeration<ObservationRelationshipType>(this, ObservationRelationshipType.DERIVEDFROM);
339        if ("sequel-to".equals(codeString))
340          return new Enumeration<ObservationRelationshipType>(this, ObservationRelationshipType.SEQUELTO);
341        if ("replaces".equals(codeString))
342          return new Enumeration<ObservationRelationshipType>(this, ObservationRelationshipType.REPLACES);
343        if ("qualified-by".equals(codeString))
344          return new Enumeration<ObservationRelationshipType>(this, ObservationRelationshipType.QUALIFIEDBY);
345        if ("interfered-by".equals(codeString))
346          return new Enumeration<ObservationRelationshipType>(this, ObservationRelationshipType.INTERFEREDBY);
347        throw new FHIRException("Unknown ObservationRelationshipType code '"+codeString+"'");
348        }
349    public String toCode(ObservationRelationshipType code) {
350      if (code == ObservationRelationshipType.HASMEMBER)
351        return "has-member";
352      if (code == ObservationRelationshipType.DERIVEDFROM)
353        return "derived-from";
354      if (code == ObservationRelationshipType.SEQUELTO)
355        return "sequel-to";
356      if (code == ObservationRelationshipType.REPLACES)
357        return "replaces";
358      if (code == ObservationRelationshipType.QUALIFIEDBY)
359        return "qualified-by";
360      if (code == ObservationRelationshipType.INTERFEREDBY)
361        return "interfered-by";
362      return "?";
363      }
364    }
365
366    @Block()
367    public static class ObservationReferenceRangeComponent extends BackboneElement implements IBaseBackboneElement {
368        /**
369         * The value of the low bound of the reference range.  The low bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the low bound is omitted,  it is assumed to be meaningless (e.g. reference range is <=2.3).
370         */
371        @Child(name = "low", type = {SimpleQuantity.class}, order=1, min=0, max=1, modifier=false, summary=false)
372        @Description(shortDefinition="Low Range, if relevant", formalDefinition="The value of the low bound of the reference range.  The low bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the low bound is omitted,  it is assumed to be meaningless (e.g. reference range is <=2.3)." )
373        protected SimpleQuantity low;
374
375        /**
376         * The value of the high bound of the reference range.  The high bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the high bound is omitted,  it is assumed to be meaningless (e.g. reference range is >= 2.3).
377         */
378        @Child(name = "high", type = {SimpleQuantity.class}, order=2, min=0, max=1, modifier=false, summary=false)
379        @Description(shortDefinition="High Range, if relevant", formalDefinition="The value of the high bound of the reference range.  The high bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the high bound is omitted,  it is assumed to be meaningless (e.g. reference range is >= 2.3)." )
380        protected SimpleQuantity high;
381
382        /**
383         * Code for the meaning of the reference range.
384         */
385        @Child(name = "meaning", type = {CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=false)
386        @Description(shortDefinition="Indicates the meaning/use of this range of this range", formalDefinition="Code for the meaning of the reference range." )
387        protected CodeableConcept meaning;
388
389        /**
390         * The age at which this reference range is applicable. This is a neonatal age (e.g. number of weeks at term) if the meaning says so.
391         */
392        @Child(name = "age", type = {Range.class}, order=4, min=0, max=1, modifier=false, summary=false)
393        @Description(shortDefinition="Applicable age range, if relevant", formalDefinition="The age at which this reference range is applicable. This is a neonatal age (e.g. number of weeks at term) if the meaning says so." )
394        protected Range age;
395
396        /**
397         * Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of "Negative" or a list or table of 'normals'.
398         */
399        @Child(name = "text", type = {StringType.class}, order=5, min=0, max=1, modifier=false, summary=false)
400        @Description(shortDefinition="Text based reference range in an observation", formalDefinition="Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of \"Negative\" or a list or table of 'normals'." )
401        protected StringType text;
402
403        private static final long serialVersionUID = -238694788L;
404
405    /*
406     * Constructor
407     */
408      public ObservationReferenceRangeComponent() {
409        super();
410      }
411
412        /**
413         * @return {@link #low} (The value of the low bound of the reference range.  The low bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the low bound is omitted,  it is assumed to be meaningless (e.g. reference range is <=2.3).)
414         */
415        public SimpleQuantity getLow() { 
416          if (this.low == null)
417            if (Configuration.errorOnAutoCreate())
418              throw new Error("Attempt to auto-create ObservationReferenceRangeComponent.low");
419            else if (Configuration.doAutoCreate())
420              this.low = new SimpleQuantity(); // cc
421          return this.low;
422        }
423
424        public boolean hasLow() { 
425          return this.low != null && !this.low.isEmpty();
426        }
427
428        /**
429         * @param value {@link #low} (The value of the low bound of the reference range.  The low bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the low bound is omitted,  it is assumed to be meaningless (e.g. reference range is <=2.3).)
430         */
431        public ObservationReferenceRangeComponent setLow(SimpleQuantity value) { 
432          this.low = value;
433          return this;
434        }
435
436        /**
437         * @return {@link #high} (The value of the high bound of the reference range.  The high bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the high bound is omitted,  it is assumed to be meaningless (e.g. reference range is >= 2.3).)
438         */
439        public SimpleQuantity getHigh() { 
440          if (this.high == null)
441            if (Configuration.errorOnAutoCreate())
442              throw new Error("Attempt to auto-create ObservationReferenceRangeComponent.high");
443            else if (Configuration.doAutoCreate())
444              this.high = new SimpleQuantity(); // cc
445          return this.high;
446        }
447
448        public boolean hasHigh() { 
449          return this.high != null && !this.high.isEmpty();
450        }
451
452        /**
453         * @param value {@link #high} (The value of the high bound of the reference range.  The high bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the high bound is omitted,  it is assumed to be meaningless (e.g. reference range is >= 2.3).)
454         */
455        public ObservationReferenceRangeComponent setHigh(SimpleQuantity value) { 
456          this.high = value;
457          return this;
458        }
459
460        /**
461         * @return {@link #meaning} (Code for the meaning of the reference range.)
462         */
463        public CodeableConcept getMeaning() { 
464          if (this.meaning == null)
465            if (Configuration.errorOnAutoCreate())
466              throw new Error("Attempt to auto-create ObservationReferenceRangeComponent.meaning");
467            else if (Configuration.doAutoCreate())
468              this.meaning = new CodeableConcept(); // cc
469          return this.meaning;
470        }
471
472        public boolean hasMeaning() { 
473          return this.meaning != null && !this.meaning.isEmpty();
474        }
475
476        /**
477         * @param value {@link #meaning} (Code for the meaning of the reference range.)
478         */
479        public ObservationReferenceRangeComponent setMeaning(CodeableConcept value) { 
480          this.meaning = value;
481          return this;
482        }
483
484        /**
485         * @return {@link #age} (The age at which this reference range is applicable. This is a neonatal age (e.g. number of weeks at term) if the meaning says so.)
486         */
487        public Range getAge() { 
488          if (this.age == null)
489            if (Configuration.errorOnAutoCreate())
490              throw new Error("Attempt to auto-create ObservationReferenceRangeComponent.age");
491            else if (Configuration.doAutoCreate())
492              this.age = new Range(); // cc
493          return this.age;
494        }
495
496        public boolean hasAge() { 
497          return this.age != null && !this.age.isEmpty();
498        }
499
500        /**
501         * @param value {@link #age} (The age at which this reference range is applicable. This is a neonatal age (e.g. number of weeks at term) if the meaning says so.)
502         */
503        public ObservationReferenceRangeComponent setAge(Range value) { 
504          this.age = value;
505          return this;
506        }
507
508        /**
509         * @return {@link #text} (Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of "Negative" or a list or table of 'normals'.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
510         */
511        public StringType getTextElement() { 
512          if (this.text == null)
513            if (Configuration.errorOnAutoCreate())
514              throw new Error("Attempt to auto-create ObservationReferenceRangeComponent.text");
515            else if (Configuration.doAutoCreate())
516              this.text = new StringType(); // bb
517          return this.text;
518        }
519
520        public boolean hasTextElement() { 
521          return this.text != null && !this.text.isEmpty();
522        }
523
524        public boolean hasText() { 
525          return this.text != null && !this.text.isEmpty();
526        }
527
528        /**
529         * @param value {@link #text} (Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of "Negative" or a list or table of 'normals'.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
530         */
531        public ObservationReferenceRangeComponent setTextElement(StringType value) { 
532          this.text = value;
533          return this;
534        }
535
536        /**
537         * @return Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of "Negative" or a list or table of 'normals'.
538         */
539        public String getText() { 
540          return this.text == null ? null : this.text.getValue();
541        }
542
543        /**
544         * @param value Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of "Negative" or a list or table of 'normals'.
545         */
546        public ObservationReferenceRangeComponent setText(String value) { 
547          if (Utilities.noString(value))
548            this.text = null;
549          else {
550            if (this.text == null)
551              this.text = new StringType();
552            this.text.setValue(value);
553          }
554          return this;
555        }
556
557        protected void listChildren(List<Property> childrenList) {
558          super.listChildren(childrenList);
559          childrenList.add(new Property("low", "SimpleQuantity", "The value of the low bound of the reference range.  The low bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the low bound is omitted,  it is assumed to be meaningless (e.g. reference range is <=2.3).", 0, java.lang.Integer.MAX_VALUE, low));
560          childrenList.add(new Property("high", "SimpleQuantity", "The value of the high bound of the reference range.  The high bound of the reference range endpoint is inclusive of the value (e.g.  reference range is >=5 - <=9).   If the high bound is omitted,  it is assumed to be meaningless (e.g. reference range is >= 2.3).", 0, java.lang.Integer.MAX_VALUE, high));
561          childrenList.add(new Property("meaning", "CodeableConcept", "Code for the meaning of the reference range.", 0, java.lang.Integer.MAX_VALUE, meaning));
562          childrenList.add(new Property("age", "Range", "The age at which this reference range is applicable. This is a neonatal age (e.g. number of weeks at term) if the meaning says so.", 0, java.lang.Integer.MAX_VALUE, age));
563          childrenList.add(new Property("text", "string", "Text based reference range in an observation which may be used when a quantitative range is not appropriate for an observation.  An example would be a reference value of \"Negative\" or a list or table of 'normals'.", 0, java.lang.Integer.MAX_VALUE, text));
564        }
565
566      @Override
567      public void setProperty(String name, Base value) throws FHIRException {
568        if (name.equals("low"))
569          this.low = castToSimpleQuantity(value); // SimpleQuantity
570        else if (name.equals("high"))
571          this.high = castToSimpleQuantity(value); // SimpleQuantity
572        else if (name.equals("meaning"))
573          this.meaning = castToCodeableConcept(value); // CodeableConcept
574        else if (name.equals("age"))
575          this.age = castToRange(value); // Range
576        else if (name.equals("text"))
577          this.text = castToString(value); // StringType
578        else
579          super.setProperty(name, value);
580      }
581
582      @Override
583      public Base addChild(String name) throws FHIRException {
584        if (name.equals("low")) {
585          this.low = new SimpleQuantity();
586          return this.low;
587        }
588        else if (name.equals("high")) {
589          this.high = new SimpleQuantity();
590          return this.high;
591        }
592        else if (name.equals("meaning")) {
593          this.meaning = new CodeableConcept();
594          return this.meaning;
595        }
596        else if (name.equals("age")) {
597          this.age = new Range();
598          return this.age;
599        }
600        else if (name.equals("text")) {
601          throw new FHIRException("Cannot call addChild on a primitive type Observation.text");
602        }
603        else
604          return super.addChild(name);
605      }
606
607      public ObservationReferenceRangeComponent copy() {
608        ObservationReferenceRangeComponent dst = new ObservationReferenceRangeComponent();
609        copyValues(dst);
610        dst.low = low == null ? null : low.copy();
611        dst.high = high == null ? null : high.copy();
612        dst.meaning = meaning == null ? null : meaning.copy();
613        dst.age = age == null ? null : age.copy();
614        dst.text = text == null ? null : text.copy();
615        return dst;
616      }
617
618      @Override
619      public boolean equalsDeep(Base other) {
620        if (!super.equalsDeep(other))
621          return false;
622        if (!(other instanceof ObservationReferenceRangeComponent))
623          return false;
624        ObservationReferenceRangeComponent o = (ObservationReferenceRangeComponent) other;
625        return compareDeep(low, o.low, true) && compareDeep(high, o.high, true) && compareDeep(meaning, o.meaning, true)
626           && compareDeep(age, o.age, true) && compareDeep(text, o.text, true);
627      }
628
629      @Override
630      public boolean equalsShallow(Base other) {
631        if (!super.equalsShallow(other))
632          return false;
633        if (!(other instanceof ObservationReferenceRangeComponent))
634          return false;
635        ObservationReferenceRangeComponent o = (ObservationReferenceRangeComponent) other;
636        return compareValues(text, o.text, true);
637      }
638
639      public boolean isEmpty() {
640        return super.isEmpty() && (low == null || low.isEmpty()) && (high == null || high.isEmpty())
641           && (meaning == null || meaning.isEmpty()) && (age == null || age.isEmpty()) && (text == null || text.isEmpty())
642          ;
643      }
644
645  public String fhirType() {
646    return "Observation.referenceRange";
647
648  }
649
650  }
651
652    @Block()
653    public static class ObservationRelatedComponent extends BackboneElement implements IBaseBackboneElement {
654        /**
655         * A code specifying the kind of relationship that exists with the target resource.
656         */
657        @Child(name = "type", type = {CodeType.class}, order=1, min=0, max=1, modifier=false, summary=false)
658        @Description(shortDefinition="has-member | derived-from | sequel-to | replaces | qualified-by | interfered-by", formalDefinition="A code specifying the kind of relationship that exists with the target resource." )
659        protected Enumeration<ObservationRelationshipType> type;
660
661        /**
662         * A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.
663         */
664        @Child(name = "target", type = {Observation.class, QuestionnaireResponse.class}, order=2, min=1, max=1, modifier=false, summary=false)
665        @Description(shortDefinition="Resource that is related to this one", formalDefinition="A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation." )
666        protected Reference target;
667
668        /**
669         * The actual object that is the target of the reference (A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.)
670         */
671        protected Resource targetTarget;
672
673        private static final long serialVersionUID = 1541802577L;
674
675    /*
676     * Constructor
677     */
678      public ObservationRelatedComponent() {
679        super();
680      }
681
682    /*
683     * Constructor
684     */
685      public ObservationRelatedComponent(Reference target) {
686        super();
687        this.target = target;
688      }
689
690        /**
691         * @return {@link #type} (A code specifying the kind of relationship that exists with the target resource.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
692         */
693        public Enumeration<ObservationRelationshipType> getTypeElement() { 
694          if (this.type == null)
695            if (Configuration.errorOnAutoCreate())
696              throw new Error("Attempt to auto-create ObservationRelatedComponent.type");
697            else if (Configuration.doAutoCreate())
698              this.type = new Enumeration<ObservationRelationshipType>(new ObservationRelationshipTypeEnumFactory()); // bb
699          return this.type;
700        }
701
702        public boolean hasTypeElement() { 
703          return this.type != null && !this.type.isEmpty();
704        }
705
706        public boolean hasType() { 
707          return this.type != null && !this.type.isEmpty();
708        }
709
710        /**
711         * @param value {@link #type} (A code specifying the kind of relationship that exists with the target resource.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
712         */
713        public ObservationRelatedComponent setTypeElement(Enumeration<ObservationRelationshipType> value) { 
714          this.type = value;
715          return this;
716        }
717
718        /**
719         * @return A code specifying the kind of relationship that exists with the target resource.
720         */
721        public ObservationRelationshipType getType() { 
722          return this.type == null ? null : this.type.getValue();
723        }
724
725        /**
726         * @param value A code specifying the kind of relationship that exists with the target resource.
727         */
728        public ObservationRelatedComponent setType(ObservationRelationshipType value) { 
729          if (value == null)
730            this.type = null;
731          else {
732            if (this.type == null)
733              this.type = new Enumeration<ObservationRelationshipType>(new ObservationRelationshipTypeEnumFactory());
734            this.type.setValue(value);
735          }
736          return this;
737        }
738
739        /**
740         * @return {@link #target} (A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.)
741         */
742        public Reference getTarget() { 
743          if (this.target == null)
744            if (Configuration.errorOnAutoCreate())
745              throw new Error("Attempt to auto-create ObservationRelatedComponent.target");
746            else if (Configuration.doAutoCreate())
747              this.target = new Reference(); // cc
748          return this.target;
749        }
750
751        public boolean hasTarget() { 
752          return this.target != null && !this.target.isEmpty();
753        }
754
755        /**
756         * @param value {@link #target} (A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.)
757         */
758        public ObservationRelatedComponent setTarget(Reference value) { 
759          this.target = value;
760          return this;
761        }
762
763        /**
764         * @return {@link #target} 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. (A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.)
765         */
766        public Resource getTargetTarget() { 
767          return this.targetTarget;
768        }
769
770        /**
771         * @param value {@link #target} 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. (A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.)
772         */
773        public ObservationRelatedComponent setTargetTarget(Resource value) { 
774          this.targetTarget = value;
775          return this;
776        }
777
778        protected void listChildren(List<Property> childrenList) {
779          super.listChildren(childrenList);
780          childrenList.add(new Property("type", "code", "A code specifying the kind of relationship that exists with the target resource.", 0, java.lang.Integer.MAX_VALUE, type));
781          childrenList.add(new Property("target", "Reference(Observation|QuestionnaireResponse)", "A reference to the observation or [[[QuestionnaireResponse]]] resource that is related to this observation.", 0, java.lang.Integer.MAX_VALUE, target));
782        }
783
784      @Override
785      public void setProperty(String name, Base value) throws FHIRException {
786        if (name.equals("type"))
787          this.type = new ObservationRelationshipTypeEnumFactory().fromType(value); // Enumeration<ObservationRelationshipType>
788        else if (name.equals("target"))
789          this.target = castToReference(value); // Reference
790        else
791          super.setProperty(name, value);
792      }
793
794      @Override
795      public Base addChild(String name) throws FHIRException {
796        if (name.equals("type")) {
797          throw new FHIRException("Cannot call addChild on a primitive type Observation.type");
798        }
799        else if (name.equals("target")) {
800          this.target = new Reference();
801          return this.target;
802        }
803        else
804          return super.addChild(name);
805      }
806
807      public ObservationRelatedComponent copy() {
808        ObservationRelatedComponent dst = new ObservationRelatedComponent();
809        copyValues(dst);
810        dst.type = type == null ? null : type.copy();
811        dst.target = target == null ? null : target.copy();
812        return dst;
813      }
814
815      @Override
816      public boolean equalsDeep(Base other) {
817        if (!super.equalsDeep(other))
818          return false;
819        if (!(other instanceof ObservationRelatedComponent))
820          return false;
821        ObservationRelatedComponent o = (ObservationRelatedComponent) other;
822        return compareDeep(type, o.type, true) && compareDeep(target, o.target, true);
823      }
824
825      @Override
826      public boolean equalsShallow(Base other) {
827        if (!super.equalsShallow(other))
828          return false;
829        if (!(other instanceof ObservationRelatedComponent))
830          return false;
831        ObservationRelatedComponent o = (ObservationRelatedComponent) other;
832        return compareValues(type, o.type, true);
833      }
834
835      public boolean isEmpty() {
836        return super.isEmpty() && (type == null || type.isEmpty()) && (target == null || target.isEmpty())
837          ;
838      }
839
840  public String fhirType() {
841    return "Observation.related";
842
843  }
844
845  }
846
847    @Block()
848    public static class ObservationComponentComponent extends BackboneElement implements IBaseBackboneElement {
849        /**
850         * Describes what was observed. Sometimes this is called the observation "code".
851         */
852        @Child(name = "code", type = {CodeableConcept.class}, order=1, min=1, max=1, modifier=false, summary=true)
853        @Description(shortDefinition="Type of component observation (code / type)", formalDefinition="Describes what was observed. Sometimes this is called the observation \"code\"." )
854        protected CodeableConcept code;
855
856        /**
857         * The information determined as a result of making the observation, if the information has a simple value.
858         */
859        @Child(name = "value", type = {Quantity.class, CodeableConcept.class, StringType.class, Range.class, Ratio.class, SampledData.class, Attachment.class, TimeType.class, DateTimeType.class, Period.class}, order=2, min=0, max=1, modifier=false, summary=true)
860        @Description(shortDefinition="Actual component result", formalDefinition="The information determined as a result of making the observation, if the information has a simple value." )
861        protected Type value;
862
863        /**
864         * Provides a reason why the expected value in the element Observation.value[x] is missing.
865         */
866        @Child(name = "dataAbsentReason", type = {CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=false)
867        @Description(shortDefinition="Why the component result is missing", formalDefinition="Provides a reason why the expected value in the element Observation.value[x] is missing." )
868        protected CodeableConcept dataAbsentReason;
869
870        /**
871         * Guidance on how to interpret the value by comparison to a normal or recommended range.
872         */
873        @Child(name = "referenceRange", type = {ObservationReferenceRangeComponent.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
874        @Description(shortDefinition="Provides guide for interpretation of component result", formalDefinition="Guidance on how to interpret the value by comparison to a normal or recommended range." )
875        protected List<ObservationReferenceRangeComponent> referenceRange;
876
877        private static final long serialVersionUID = 946602904L;
878
879    /*
880     * Constructor
881     */
882      public ObservationComponentComponent() {
883        super();
884      }
885
886    /*
887     * Constructor
888     */
889      public ObservationComponentComponent(CodeableConcept code) {
890        super();
891        this.code = code;
892      }
893
894        /**
895         * @return {@link #code} (Describes what was observed. Sometimes this is called the observation "code".)
896         */
897        public CodeableConcept getCode() { 
898          if (this.code == null)
899            if (Configuration.errorOnAutoCreate())
900              throw new Error("Attempt to auto-create ObservationComponentComponent.code");
901            else if (Configuration.doAutoCreate())
902              this.code = new CodeableConcept(); // cc
903          return this.code;
904        }
905
906        public boolean hasCode() { 
907          return this.code != null && !this.code.isEmpty();
908        }
909
910        /**
911         * @param value {@link #code} (Describes what was observed. Sometimes this is called the observation "code".)
912         */
913        public ObservationComponentComponent setCode(CodeableConcept value) { 
914          this.code = value;
915          return this;
916        }
917
918        /**
919         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
920         */
921        public Type getValue() { 
922          return this.value;
923        }
924
925        /**
926         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
927         */
928        public Quantity getValueQuantity() throws FHIRException { 
929          if (!(this.value instanceof Quantity))
930            throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered");
931          return (Quantity) this.value;
932        }
933
934        public boolean hasValueQuantity() { 
935          return this.value instanceof Quantity;
936        }
937
938        /**
939         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
940         */
941        public CodeableConcept getValueCodeableConcept() throws FHIRException { 
942          if (!(this.value instanceof CodeableConcept))
943            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.value.getClass().getName()+" was encountered");
944          return (CodeableConcept) this.value;
945        }
946
947        public boolean hasValueCodeableConcept() { 
948          return this.value instanceof CodeableConcept;
949        }
950
951        /**
952         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
953         */
954        public StringType getValueStringType() throws FHIRException { 
955          if (!(this.value instanceof StringType))
956            throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.value.getClass().getName()+" was encountered");
957          return (StringType) this.value;
958        }
959
960        public boolean hasValueStringType() { 
961          return this.value instanceof StringType;
962        }
963
964        /**
965         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
966         */
967        public Range getValueRange() throws FHIRException { 
968          if (!(this.value instanceof Range))
969            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.value.getClass().getName()+" was encountered");
970          return (Range) this.value;
971        }
972
973        public boolean hasValueRange() { 
974          return this.value instanceof Range;
975        }
976
977        /**
978         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
979         */
980        public Ratio getValueRatio() throws FHIRException { 
981          if (!(this.value instanceof Ratio))
982            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.value.getClass().getName()+" was encountered");
983          return (Ratio) this.value;
984        }
985
986        public boolean hasValueRatio() { 
987          return this.value instanceof Ratio;
988        }
989
990        /**
991         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
992         */
993        public SampledData getValueSampledData() throws FHIRException { 
994          if (!(this.value instanceof SampledData))
995            throw new FHIRException("Type mismatch: the type SampledData was expected, but "+this.value.getClass().getName()+" was encountered");
996          return (SampledData) this.value;
997        }
998
999        public boolean hasValueSampledData() { 
1000          return this.value instanceof SampledData;
1001        }
1002
1003        /**
1004         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1005         */
1006        public Attachment getValueAttachment() throws FHIRException { 
1007          if (!(this.value instanceof Attachment))
1008            throw new FHIRException("Type mismatch: the type Attachment was expected, but "+this.value.getClass().getName()+" was encountered");
1009          return (Attachment) this.value;
1010        }
1011
1012        public boolean hasValueAttachment() { 
1013          return this.value instanceof Attachment;
1014        }
1015
1016        /**
1017         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1018         */
1019        public TimeType getValueTimeType() throws FHIRException { 
1020          if (!(this.value instanceof TimeType))
1021            throw new FHIRException("Type mismatch: the type TimeType was expected, but "+this.value.getClass().getName()+" was encountered");
1022          return (TimeType) this.value;
1023        }
1024
1025        public boolean hasValueTimeType() { 
1026          return this.value instanceof TimeType;
1027        }
1028
1029        /**
1030         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1031         */
1032        public DateTimeType getValueDateTimeType() throws FHIRException { 
1033          if (!(this.value instanceof DateTimeType))
1034            throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.value.getClass().getName()+" was encountered");
1035          return (DateTimeType) this.value;
1036        }
1037
1038        public boolean hasValueDateTimeType() { 
1039          return this.value instanceof DateTimeType;
1040        }
1041
1042        /**
1043         * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1044         */
1045        public Period getValuePeriod() throws FHIRException { 
1046          if (!(this.value instanceof Period))
1047            throw new FHIRException("Type mismatch: the type Period was expected, but "+this.value.getClass().getName()+" was encountered");
1048          return (Period) this.value;
1049        }
1050
1051        public boolean hasValuePeriod() { 
1052          return this.value instanceof Period;
1053        }
1054
1055        public boolean hasValue() { 
1056          return this.value != null && !this.value.isEmpty();
1057        }
1058
1059        /**
1060         * @param value {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1061         */
1062        public ObservationComponentComponent setValue(Type value) { 
1063          this.value = value;
1064          return this;
1065        }
1066
1067        /**
1068         * @return {@link #dataAbsentReason} (Provides a reason why the expected value in the element Observation.value[x] is missing.)
1069         */
1070        public CodeableConcept getDataAbsentReason() { 
1071          if (this.dataAbsentReason == null)
1072            if (Configuration.errorOnAutoCreate())
1073              throw new Error("Attempt to auto-create ObservationComponentComponent.dataAbsentReason");
1074            else if (Configuration.doAutoCreate())
1075              this.dataAbsentReason = new CodeableConcept(); // cc
1076          return this.dataAbsentReason;
1077        }
1078
1079        public boolean hasDataAbsentReason() { 
1080          return this.dataAbsentReason != null && !this.dataAbsentReason.isEmpty();
1081        }
1082
1083        /**
1084         * @param value {@link #dataAbsentReason} (Provides a reason why the expected value in the element Observation.value[x] is missing.)
1085         */
1086        public ObservationComponentComponent setDataAbsentReason(CodeableConcept value) { 
1087          this.dataAbsentReason = value;
1088          return this;
1089        }
1090
1091        /**
1092         * @return {@link #referenceRange} (Guidance on how to interpret the value by comparison to a normal or recommended range.)
1093         */
1094        public List<ObservationReferenceRangeComponent> getReferenceRange() { 
1095          if (this.referenceRange == null)
1096            this.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
1097          return this.referenceRange;
1098        }
1099
1100        public boolean hasReferenceRange() { 
1101          if (this.referenceRange == null)
1102            return false;
1103          for (ObservationReferenceRangeComponent item : this.referenceRange)
1104            if (!item.isEmpty())
1105              return true;
1106          return false;
1107        }
1108
1109        /**
1110         * @return {@link #referenceRange} (Guidance on how to interpret the value by comparison to a normal or recommended range.)
1111         */
1112    // syntactic sugar
1113        public ObservationReferenceRangeComponent addReferenceRange() { //3
1114          ObservationReferenceRangeComponent t = new ObservationReferenceRangeComponent();
1115          if (this.referenceRange == null)
1116            this.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
1117          this.referenceRange.add(t);
1118          return t;
1119        }
1120
1121    // syntactic sugar
1122        public ObservationComponentComponent addReferenceRange(ObservationReferenceRangeComponent t) { //3
1123          if (t == null)
1124            return this;
1125          if (this.referenceRange == null)
1126            this.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
1127          this.referenceRange.add(t);
1128          return this;
1129        }
1130
1131        protected void listChildren(List<Property> childrenList) {
1132          super.listChildren(childrenList);
1133          childrenList.add(new Property("code", "CodeableConcept", "Describes what was observed. Sometimes this is called the observation \"code\".", 0, java.lang.Integer.MAX_VALUE, code));
1134          childrenList.add(new Property("value[x]", "Quantity|CodeableConcept|string|Range|Ratio|SampledData|Attachment|time|dateTime|Period", "The information determined as a result of making the observation, if the information has a simple value.", 0, java.lang.Integer.MAX_VALUE, value));
1135          childrenList.add(new Property("dataAbsentReason", "CodeableConcept", "Provides a reason why the expected value in the element Observation.value[x] is missing.", 0, java.lang.Integer.MAX_VALUE, dataAbsentReason));
1136          childrenList.add(new Property("referenceRange", "@Observation.referenceRange", "Guidance on how to interpret the value by comparison to a normal or recommended range.", 0, java.lang.Integer.MAX_VALUE, referenceRange));
1137        }
1138
1139      @Override
1140      public void setProperty(String name, Base value) throws FHIRException {
1141        if (name.equals("code"))
1142          this.code = castToCodeableConcept(value); // CodeableConcept
1143        else if (name.equals("value[x]"))
1144          this.value = (Type) value; // Type
1145        else if (name.equals("dataAbsentReason"))
1146          this.dataAbsentReason = castToCodeableConcept(value); // CodeableConcept
1147        else if (name.equals("referenceRange"))
1148          this.getReferenceRange().add((ObservationReferenceRangeComponent) value);
1149        else
1150          super.setProperty(name, value);
1151      }
1152
1153      @Override
1154      public Base addChild(String name) throws FHIRException {
1155        if (name.equals("code")) {
1156          this.code = new CodeableConcept();
1157          return this.code;
1158        }
1159        else if (name.equals("valueQuantity")) {
1160          this.value = new Quantity();
1161          return this.value;
1162        }
1163        else if (name.equals("valueCodeableConcept")) {
1164          this.value = new CodeableConcept();
1165          return this.value;
1166        }
1167        else if (name.equals("valueString")) {
1168          this.value = new StringType();
1169          return this.value;
1170        }
1171        else if (name.equals("valueRange")) {
1172          this.value = new Range();
1173          return this.value;
1174        }
1175        else if (name.equals("valueRatio")) {
1176          this.value = new Ratio();
1177          return this.value;
1178        }
1179        else if (name.equals("valueSampledData")) {
1180          this.value = new SampledData();
1181          return this.value;
1182        }
1183        else if (name.equals("valueAttachment")) {
1184          this.value = new Attachment();
1185          return this.value;
1186        }
1187        else if (name.equals("valueTime")) {
1188          this.value = new TimeType();
1189          return this.value;
1190        }
1191        else if (name.equals("valueDateTime")) {
1192          this.value = new DateTimeType();
1193          return this.value;
1194        }
1195        else if (name.equals("valuePeriod")) {
1196          this.value = new Period();
1197          return this.value;
1198        }
1199        else if (name.equals("dataAbsentReason")) {
1200          this.dataAbsentReason = new CodeableConcept();
1201          return this.dataAbsentReason;
1202        }
1203        else if (name.equals("referenceRange")) {
1204          return addReferenceRange();
1205        }
1206        else
1207          return super.addChild(name);
1208      }
1209
1210      public ObservationComponentComponent copy() {
1211        ObservationComponentComponent dst = new ObservationComponentComponent();
1212        copyValues(dst);
1213        dst.code = code == null ? null : code.copy();
1214        dst.value = value == null ? null : value.copy();
1215        dst.dataAbsentReason = dataAbsentReason == null ? null : dataAbsentReason.copy();
1216        if (referenceRange != null) {
1217          dst.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
1218          for (ObservationReferenceRangeComponent i : referenceRange)
1219            dst.referenceRange.add(i.copy());
1220        };
1221        return dst;
1222      }
1223
1224      @Override
1225      public boolean equalsDeep(Base other) {
1226        if (!super.equalsDeep(other))
1227          return false;
1228        if (!(other instanceof ObservationComponentComponent))
1229          return false;
1230        ObservationComponentComponent o = (ObservationComponentComponent) other;
1231        return compareDeep(code, o.code, true) && compareDeep(value, o.value, true) && compareDeep(dataAbsentReason, o.dataAbsentReason, true)
1232           && compareDeep(referenceRange, o.referenceRange, true);
1233      }
1234
1235      @Override
1236      public boolean equalsShallow(Base other) {
1237        if (!super.equalsShallow(other))
1238          return false;
1239        if (!(other instanceof ObservationComponentComponent))
1240          return false;
1241        ObservationComponentComponent o = (ObservationComponentComponent) other;
1242        return true;
1243      }
1244
1245      public boolean isEmpty() {
1246        return super.isEmpty() && (code == null || code.isEmpty()) && (value == null || value.isEmpty())
1247           && (dataAbsentReason == null || dataAbsentReason.isEmpty()) && (referenceRange == null || referenceRange.isEmpty())
1248          ;
1249      }
1250
1251  public String fhirType() {
1252    return "Observation.component";
1253
1254  }
1255
1256  }
1257
1258    /**
1259     * A unique identifier for the simple observation instance.
1260     */
1261    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1262    @Description(shortDefinition="Unique Id for this particular observation", formalDefinition="A unique identifier for the simple observation instance." )
1263    protected List<Identifier> identifier;
1264
1265    /**
1266     * The status of the result value.
1267     */
1268    @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=true, summary=true)
1269    @Description(shortDefinition="registered | preliminary | final | amended +", formalDefinition="The status of the result value." )
1270    protected Enumeration<ObservationStatus> status;
1271
1272    /**
1273     * A code that classifies the general type of observation being made.  This is used  for searching, sorting and display purposes.
1274     */
1275    @Child(name = "category", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=false)
1276    @Description(shortDefinition="Classification of  type of observation", formalDefinition="A code that classifies the general type of observation being made.  This is used  for searching, sorting and display purposes." )
1277    protected CodeableConcept category;
1278
1279    /**
1280     * Describes what was observed. Sometimes this is called the observation "name".
1281     */
1282    @Child(name = "code", type = {CodeableConcept.class}, order=3, min=1, max=1, modifier=false, summary=true)
1283    @Description(shortDefinition="Type of observation (code / type)", formalDefinition="Describes what was observed. Sometimes this is called the observation \"name\"." )
1284    protected CodeableConcept code;
1285
1286    /**
1287     * The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.
1288     */
1289    @Child(name = "subject", type = {Patient.class, Group.class, Device.class, Location.class}, order=4, min=0, max=1, modifier=false, summary=true)
1290    @Description(shortDefinition="Who and/or what this is about", formalDefinition="The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject." )
1291    protected Reference subject;
1292
1293    /**
1294     * The actual object that is the target of the reference (The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.)
1295     */
1296    protected Resource subjectTarget;
1297
1298    /**
1299     * The healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.
1300     */
1301    @Child(name = "encounter", type = {Encounter.class}, order=5, min=0, max=1, modifier=false, summary=false)
1302    @Description(shortDefinition="Healthcare event during which this observation is made", formalDefinition="The healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made." )
1303    protected Reference encounter;
1304
1305    /**
1306     * The actual object that is the target of the reference (The healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.)
1307     */
1308    protected Encounter encounterTarget;
1309
1310    /**
1311     * The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the "physiologically relevant time". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself.
1312     */
1313    @Child(name = "effective", type = {DateTimeType.class, Period.class}, order=6, min=0, max=1, modifier=false, summary=true)
1314    @Description(shortDefinition="Clinically relevant time/time-period for observation", formalDefinition="The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the \"physiologically relevant time\". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself." )
1315    protected Type effective;
1316
1317    /**
1318     * The date and time this observation was made available to providers, typically after the results have been reviewed and verified.
1319     */
1320    @Child(name = "issued", type = {InstantType.class}, order=7, min=0, max=1, modifier=false, summary=true)
1321    @Description(shortDefinition="Date/Time this was made available", formalDefinition="The date and time this observation was made available to providers, typically after the results have been reviewed and verified." )
1322    protected InstantType issued;
1323
1324    /**
1325     * Who was responsible for asserting the observed value as "true".
1326     */
1327    @Child(name = "performer", type = {Practitioner.class, Organization.class, Patient.class, RelatedPerson.class}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1328    @Description(shortDefinition="Who is responsible for the observation", formalDefinition="Who was responsible for asserting the observed value as \"true\"." )
1329    protected List<Reference> performer;
1330    /**
1331     * The actual objects that are the target of the reference (Who was responsible for asserting the observed value as "true".)
1332     */
1333    protected List<Resource> performerTarget;
1334
1335
1336    /**
1337     * The information determined as a result of making the observation, if the information has a simple value.
1338     */
1339    @Child(name = "value", type = {Quantity.class, CodeableConcept.class, StringType.class, Range.class, Ratio.class, SampledData.class, Attachment.class, TimeType.class, DateTimeType.class, Period.class}, order=9, min=0, max=1, modifier=false, summary=true)
1340    @Description(shortDefinition="Actual result", formalDefinition="The information determined as a result of making the observation, if the information has a simple value." )
1341    protected Type value;
1342
1343    /**
1344     * Provides a reason why the expected value in the element Observation.value[x] is missing.
1345     */
1346    @Child(name = "dataAbsentReason", type = {CodeableConcept.class}, order=10, min=0, max=1, modifier=false, summary=false)
1347    @Description(shortDefinition="Why the result is missing", formalDefinition="Provides a reason why the expected value in the element Observation.value[x] is missing." )
1348    protected CodeableConcept dataAbsentReason;
1349
1350    /**
1351     * The assessment made based on the result of the observation.  Intended as a simple compact code often placed adjacent to the result value in reports and flow sheets to signal the meaning/normalcy status of the result. Otherwise known as abnormal flag.
1352     */
1353    @Child(name = "interpretation", type = {CodeableConcept.class}, order=11, min=0, max=1, modifier=false, summary=false)
1354    @Description(shortDefinition="High, low, normal, etc.", formalDefinition="The assessment made based on the result of the observation.  Intended as a simple compact code often placed adjacent to the result value in reports and flow sheets to signal the meaning/normalcy status of the result. Otherwise known as abnormal flag." )
1355    protected CodeableConcept interpretation;
1356
1357    /**
1358     * May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result.
1359     */
1360    @Child(name = "comments", type = {StringType.class}, order=12, min=0, max=1, modifier=false, summary=false)
1361    @Description(shortDefinition="Comments about result", formalDefinition="May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result." )
1362    protected StringType comments;
1363
1364    /**
1365     * Indicates the site on the subject's body where the observation was made (i.e. the target site).
1366     */
1367    @Child(name = "bodySite", type = {CodeableConcept.class}, order=13, min=0, max=1, modifier=false, summary=false)
1368    @Description(shortDefinition="Observed body part", formalDefinition="Indicates the site on the subject's body where the observation was made (i.e. the target site)." )
1369    protected CodeableConcept bodySite;
1370
1371    /**
1372     * Indicates the mechanism used to perform the observation.
1373     */
1374    @Child(name = "method", type = {CodeableConcept.class}, order=14, min=0, max=1, modifier=false, summary=false)
1375    @Description(shortDefinition="How it was done", formalDefinition="Indicates the mechanism used to perform the observation." )
1376    protected CodeableConcept method;
1377
1378    /**
1379     * The specimen that was used when this observation was made.
1380     */
1381    @Child(name = "specimen", type = {Specimen.class}, order=15, min=0, max=1, modifier=false, summary=false)
1382    @Description(shortDefinition="Specimen used for this observation", formalDefinition="The specimen that was used when this observation was made." )
1383    protected Reference specimen;
1384
1385    /**
1386     * The actual object that is the target of the reference (The specimen that was used when this observation was made.)
1387     */
1388    protected Specimen specimenTarget;
1389
1390    /**
1391     * The device used to generate the observation data.
1392     */
1393    @Child(name = "device", type = {Device.class, DeviceMetric.class}, order=16, min=0, max=1, modifier=false, summary=false)
1394    @Description(shortDefinition="(Measurement) Device", formalDefinition="The device used to generate the observation data." )
1395    protected Reference device;
1396
1397    /**
1398     * The actual object that is the target of the reference (The device used to generate the observation data.)
1399     */
1400    protected Resource deviceTarget;
1401
1402    /**
1403     * Guidance on how to interpret the value by comparison to a normal or recommended range.
1404     */
1405    @Child(name = "referenceRange", type = {}, order=17, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1406    @Description(shortDefinition="Provides guide for interpretation", formalDefinition="Guidance on how to interpret the value by comparison to a normal or recommended range." )
1407    protected List<ObservationReferenceRangeComponent> referenceRange;
1408
1409    /**
1410     * A  reference to another resource (usually another Observation but could  also be a QuestionnaireAnswer) whose relationship is defined by the relationship type code.
1411     */
1412    @Child(name = "related", type = {}, order=18, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1413    @Description(shortDefinition="Resource related to this observation", formalDefinition="A  reference to another resource (usually another Observation but could  also be a QuestionnaireAnswer) whose relationship is defined by the relationship type code." )
1414    protected List<ObservationRelatedComponent> related;
1415
1416    /**
1417     * Some observations have multiple component observations.  These component observations are expressed as separate code value pairs that share the same attributes.  Examples include systolic and diastolic component observations for blood pressure measurement and multiple component observations for genetics observations.
1418     */
1419    @Child(name = "component", type = {}, order=19, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1420    @Description(shortDefinition="Component results", formalDefinition="Some observations have multiple component observations.  These component observations are expressed as separate code value pairs that share the same attributes.  Examples include systolic and diastolic component observations for blood pressure measurement and multiple component observations for genetics observations." )
1421    protected List<ObservationComponentComponent> component;
1422
1423    private static final long serialVersionUID = -931593572L;
1424
1425  /*
1426   * Constructor
1427   */
1428    public Observation() {
1429      super();
1430    }
1431
1432  /*
1433   * Constructor
1434   */
1435    public Observation(Enumeration<ObservationStatus> status, CodeableConcept code) {
1436      super();
1437      this.status = status;
1438      this.code = code;
1439    }
1440
1441    /**
1442     * @return {@link #identifier} (A unique identifier for the simple observation instance.)
1443     */
1444    public List<Identifier> getIdentifier() { 
1445      if (this.identifier == null)
1446        this.identifier = new ArrayList<Identifier>();
1447      return this.identifier;
1448    }
1449
1450    public boolean hasIdentifier() { 
1451      if (this.identifier == null)
1452        return false;
1453      for (Identifier item : this.identifier)
1454        if (!item.isEmpty())
1455          return true;
1456      return false;
1457    }
1458
1459    /**
1460     * @return {@link #identifier} (A unique identifier for the simple observation instance.)
1461     */
1462    // syntactic sugar
1463    public Identifier addIdentifier() { //3
1464      Identifier t = new Identifier();
1465      if (this.identifier == null)
1466        this.identifier = new ArrayList<Identifier>();
1467      this.identifier.add(t);
1468      return t;
1469    }
1470
1471    // syntactic sugar
1472    public Observation addIdentifier(Identifier t) { //3
1473      if (t == null)
1474        return this;
1475      if (this.identifier == null)
1476        this.identifier = new ArrayList<Identifier>();
1477      this.identifier.add(t);
1478      return this;
1479    }
1480
1481    /**
1482     * @return {@link #status} (The status of the result value.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1483     */
1484    public Enumeration<ObservationStatus> getStatusElement() { 
1485      if (this.status == null)
1486        if (Configuration.errorOnAutoCreate())
1487          throw new Error("Attempt to auto-create Observation.status");
1488        else if (Configuration.doAutoCreate())
1489          this.status = new Enumeration<ObservationStatus>(new ObservationStatusEnumFactory()); // bb
1490      return this.status;
1491    }
1492
1493    public boolean hasStatusElement() { 
1494      return this.status != null && !this.status.isEmpty();
1495    }
1496
1497    public boolean hasStatus() { 
1498      return this.status != null && !this.status.isEmpty();
1499    }
1500
1501    /**
1502     * @param value {@link #status} (The status of the result value.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1503     */
1504    public Observation setStatusElement(Enumeration<ObservationStatus> value) { 
1505      this.status = value;
1506      return this;
1507    }
1508
1509    /**
1510     * @return The status of the result value.
1511     */
1512    public ObservationStatus getStatus() { 
1513      return this.status == null ? null : this.status.getValue();
1514    }
1515
1516    /**
1517     * @param value The status of the result value.
1518     */
1519    public Observation setStatus(ObservationStatus value) { 
1520        if (this.status == null)
1521          this.status = new Enumeration<ObservationStatus>(new ObservationStatusEnumFactory());
1522        this.status.setValue(value);
1523      return this;
1524    }
1525
1526    /**
1527     * @return {@link #category} (A code that classifies the general type of observation being made.  This is used  for searching, sorting and display purposes.)
1528     */
1529    public CodeableConcept getCategory() { 
1530      if (this.category == null)
1531        if (Configuration.errorOnAutoCreate())
1532          throw new Error("Attempt to auto-create Observation.category");
1533        else if (Configuration.doAutoCreate())
1534          this.category = new CodeableConcept(); // cc
1535      return this.category;
1536    }
1537
1538    public boolean hasCategory() { 
1539      return this.category != null && !this.category.isEmpty();
1540    }
1541
1542    /**
1543     * @param value {@link #category} (A code that classifies the general type of observation being made.  This is used  for searching, sorting and display purposes.)
1544     */
1545    public Observation setCategory(CodeableConcept value) { 
1546      this.category = value;
1547      return this;
1548    }
1549
1550    /**
1551     * @return {@link #code} (Describes what was observed. Sometimes this is called the observation "name".)
1552     */
1553    public CodeableConcept getCode() { 
1554      if (this.code == null)
1555        if (Configuration.errorOnAutoCreate())
1556          throw new Error("Attempt to auto-create Observation.code");
1557        else if (Configuration.doAutoCreate())
1558          this.code = new CodeableConcept(); // cc
1559      return this.code;
1560    }
1561
1562    public boolean hasCode() { 
1563      return this.code != null && !this.code.isEmpty();
1564    }
1565
1566    /**
1567     * @param value {@link #code} (Describes what was observed. Sometimes this is called the observation "name".)
1568     */
1569    public Observation setCode(CodeableConcept value) { 
1570      this.code = value;
1571      return this;
1572    }
1573
1574    /**
1575     * @return {@link #subject} (The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.)
1576     */
1577    public Reference getSubject() { 
1578      if (this.subject == null)
1579        if (Configuration.errorOnAutoCreate())
1580          throw new Error("Attempt to auto-create Observation.subject");
1581        else if (Configuration.doAutoCreate())
1582          this.subject = new Reference(); // cc
1583      return this.subject;
1584    }
1585
1586    public boolean hasSubject() { 
1587      return this.subject != null && !this.subject.isEmpty();
1588    }
1589
1590    /**
1591     * @param value {@link #subject} (The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.)
1592     */
1593    public Observation setSubject(Reference value) { 
1594      this.subject = value;
1595      return this;
1596    }
1597
1598    /**
1599     * @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. (The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.)
1600     */
1601    public Resource getSubjectTarget() { 
1602      return this.subjectTarget;
1603    }
1604
1605    /**
1606     * @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. (The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.)
1607     */
1608    public Observation setSubjectTarget(Resource value) { 
1609      this.subjectTarget = value;
1610      return this;
1611    }
1612
1613    /**
1614     * @return {@link #encounter} (The healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.)
1615     */
1616    public Reference getEncounter() { 
1617      if (this.encounter == null)
1618        if (Configuration.errorOnAutoCreate())
1619          throw new Error("Attempt to auto-create Observation.encounter");
1620        else if (Configuration.doAutoCreate())
1621          this.encounter = new Reference(); // cc
1622      return this.encounter;
1623    }
1624
1625    public boolean hasEncounter() { 
1626      return this.encounter != null && !this.encounter.isEmpty();
1627    }
1628
1629    /**
1630     * @param value {@link #encounter} (The healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.)
1631     */
1632    public Observation setEncounter(Reference value) { 
1633      this.encounter = value;
1634      return this;
1635    }
1636
1637    /**
1638     * @return {@link #encounter} 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 healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.)
1639     */
1640    public Encounter getEncounterTarget() { 
1641      if (this.encounterTarget == null)
1642        if (Configuration.errorOnAutoCreate())
1643          throw new Error("Attempt to auto-create Observation.encounter");
1644        else if (Configuration.doAutoCreate())
1645          this.encounterTarget = new Encounter(); // aa
1646      return this.encounterTarget;
1647    }
1648
1649    /**
1650     * @param value {@link #encounter} 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 healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.)
1651     */
1652    public Observation setEncounterTarget(Encounter value) { 
1653      this.encounterTarget = value;
1654      return this;
1655    }
1656
1657    /**
1658     * @return {@link #effective} (The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the "physiologically relevant time". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself.)
1659     */
1660    public Type getEffective() { 
1661      return this.effective;
1662    }
1663
1664    /**
1665     * @return {@link #effective} (The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the "physiologically relevant time". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself.)
1666     */
1667    public DateTimeType getEffectiveDateTimeType() throws FHIRException { 
1668      if (!(this.effective instanceof DateTimeType))
1669        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.effective.getClass().getName()+" was encountered");
1670      return (DateTimeType) this.effective;
1671    }
1672
1673    public boolean hasEffectiveDateTimeType() { 
1674      return this.effective instanceof DateTimeType;
1675    }
1676
1677    /**
1678     * @return {@link #effective} (The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the "physiologically relevant time". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself.)
1679     */
1680    public Period getEffectivePeriod() throws FHIRException { 
1681      if (!(this.effective instanceof Period))
1682        throw new FHIRException("Type mismatch: the type Period was expected, but "+this.effective.getClass().getName()+" was encountered");
1683      return (Period) this.effective;
1684    }
1685
1686    public boolean hasEffectivePeriod() { 
1687      return this.effective instanceof Period;
1688    }
1689
1690    public boolean hasEffective() { 
1691      return this.effective != null && !this.effective.isEmpty();
1692    }
1693
1694    /**
1695     * @param value {@link #effective} (The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the "physiologically relevant time". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself.)
1696     */
1697    public Observation setEffective(Type value) { 
1698      this.effective = value;
1699      return this;
1700    }
1701
1702    /**
1703     * @return {@link #issued} (The date and time this observation was made available to providers, typically after the results have been reviewed and verified.). This is the underlying object with id, value and extensions. The accessor "getIssued" gives direct access to the value
1704     */
1705    public InstantType getIssuedElement() { 
1706      if (this.issued == null)
1707        if (Configuration.errorOnAutoCreate())
1708          throw new Error("Attempt to auto-create Observation.issued");
1709        else if (Configuration.doAutoCreate())
1710          this.issued = new InstantType(); // bb
1711      return this.issued;
1712    }
1713
1714    public boolean hasIssuedElement() { 
1715      return this.issued != null && !this.issued.isEmpty();
1716    }
1717
1718    public boolean hasIssued() { 
1719      return this.issued != null && !this.issued.isEmpty();
1720    }
1721
1722    /**
1723     * @param value {@link #issued} (The date and time this observation was made available to providers, typically after the results have been reviewed and verified.). This is the underlying object with id, value and extensions. The accessor "getIssued" gives direct access to the value
1724     */
1725    public Observation setIssuedElement(InstantType value) { 
1726      this.issued = value;
1727      return this;
1728    }
1729
1730    /**
1731     * @return The date and time this observation was made available to providers, typically after the results have been reviewed and verified.
1732     */
1733    public Date getIssued() { 
1734      return this.issued == null ? null : this.issued.getValue();
1735    }
1736
1737    /**
1738     * @param value The date and time this observation was made available to providers, typically after the results have been reviewed and verified.
1739     */
1740    public Observation setIssued(Date value) { 
1741      if (value == null)
1742        this.issued = null;
1743      else {
1744        if (this.issued == null)
1745          this.issued = new InstantType();
1746        this.issued.setValue(value);
1747      }
1748      return this;
1749    }
1750
1751    /**
1752     * @return {@link #performer} (Who was responsible for asserting the observed value as "true".)
1753     */
1754    public List<Reference> getPerformer() { 
1755      if (this.performer == null)
1756        this.performer = new ArrayList<Reference>();
1757      return this.performer;
1758    }
1759
1760    public boolean hasPerformer() { 
1761      if (this.performer == null)
1762        return false;
1763      for (Reference item : this.performer)
1764        if (!item.isEmpty())
1765          return true;
1766      return false;
1767    }
1768
1769    /**
1770     * @return {@link #performer} (Who was responsible for asserting the observed value as "true".)
1771     */
1772    // syntactic sugar
1773    public Reference addPerformer() { //3
1774      Reference t = new Reference();
1775      if (this.performer == null)
1776        this.performer = new ArrayList<Reference>();
1777      this.performer.add(t);
1778      return t;
1779    }
1780
1781    // syntactic sugar
1782    public Observation addPerformer(Reference t) { //3
1783      if (t == null)
1784        return this;
1785      if (this.performer == null)
1786        this.performer = new ArrayList<Reference>();
1787      this.performer.add(t);
1788      return this;
1789    }
1790
1791    /**
1792     * @return {@link #performer} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. Who was responsible for asserting the observed value as "true".)
1793     */
1794    public List<Resource> getPerformerTarget() { 
1795      if (this.performerTarget == null)
1796        this.performerTarget = new ArrayList<Resource>();
1797      return this.performerTarget;
1798    }
1799
1800    /**
1801     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1802     */
1803    public Type getValue() { 
1804      return this.value;
1805    }
1806
1807    /**
1808     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1809     */
1810    public Quantity getValueQuantity() throws FHIRException { 
1811      if (!(this.value instanceof Quantity))
1812        throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered");
1813      return (Quantity) this.value;
1814    }
1815
1816    public boolean hasValueQuantity() { 
1817      return this.value instanceof Quantity;
1818    }
1819
1820    /**
1821     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1822     */
1823    public CodeableConcept getValueCodeableConcept() throws FHIRException { 
1824      if (!(this.value instanceof CodeableConcept))
1825        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.value.getClass().getName()+" was encountered");
1826      return (CodeableConcept) this.value;
1827    }
1828
1829    public boolean hasValueCodeableConcept() { 
1830      return this.value instanceof CodeableConcept;
1831    }
1832
1833    /**
1834     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1835     */
1836    public StringType getValueStringType() throws FHIRException { 
1837      if (!(this.value instanceof StringType))
1838        throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.value.getClass().getName()+" was encountered");
1839      return (StringType) this.value;
1840    }
1841
1842    public boolean hasValueStringType() { 
1843      return this.value instanceof StringType;
1844    }
1845
1846    /**
1847     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1848     */
1849    public Range getValueRange() throws FHIRException { 
1850      if (!(this.value instanceof Range))
1851        throw new FHIRException("Type mismatch: the type Range was expected, but "+this.value.getClass().getName()+" was encountered");
1852      return (Range) this.value;
1853    }
1854
1855    public boolean hasValueRange() { 
1856      return this.value instanceof Range;
1857    }
1858
1859    /**
1860     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1861     */
1862    public Ratio getValueRatio() throws FHIRException { 
1863      if (!(this.value instanceof Ratio))
1864        throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.value.getClass().getName()+" was encountered");
1865      return (Ratio) this.value;
1866    }
1867
1868    public boolean hasValueRatio() { 
1869      return this.value instanceof Ratio;
1870    }
1871
1872    /**
1873     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1874     */
1875    public SampledData getValueSampledData() throws FHIRException { 
1876      if (!(this.value instanceof SampledData))
1877        throw new FHIRException("Type mismatch: the type SampledData was expected, but "+this.value.getClass().getName()+" was encountered");
1878      return (SampledData) this.value;
1879    }
1880
1881    public boolean hasValueSampledData() { 
1882      return this.value instanceof SampledData;
1883    }
1884
1885    /**
1886     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1887     */
1888    public Attachment getValueAttachment() throws FHIRException { 
1889      if (!(this.value instanceof Attachment))
1890        throw new FHIRException("Type mismatch: the type Attachment was expected, but "+this.value.getClass().getName()+" was encountered");
1891      return (Attachment) this.value;
1892    }
1893
1894    public boolean hasValueAttachment() { 
1895      return this.value instanceof Attachment;
1896    }
1897
1898    /**
1899     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1900     */
1901    public TimeType getValueTimeType() throws FHIRException { 
1902      if (!(this.value instanceof TimeType))
1903        throw new FHIRException("Type mismatch: the type TimeType was expected, but "+this.value.getClass().getName()+" was encountered");
1904      return (TimeType) this.value;
1905    }
1906
1907    public boolean hasValueTimeType() { 
1908      return this.value instanceof TimeType;
1909    }
1910
1911    /**
1912     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1913     */
1914    public DateTimeType getValueDateTimeType() throws FHIRException { 
1915      if (!(this.value instanceof DateTimeType))
1916        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.value.getClass().getName()+" was encountered");
1917      return (DateTimeType) this.value;
1918    }
1919
1920    public boolean hasValueDateTimeType() { 
1921      return this.value instanceof DateTimeType;
1922    }
1923
1924    /**
1925     * @return {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1926     */
1927    public Period getValuePeriod() throws FHIRException { 
1928      if (!(this.value instanceof Period))
1929        throw new FHIRException("Type mismatch: the type Period was expected, but "+this.value.getClass().getName()+" was encountered");
1930      return (Period) this.value;
1931    }
1932
1933    public boolean hasValuePeriod() { 
1934      return this.value instanceof Period;
1935    }
1936
1937    public boolean hasValue() { 
1938      return this.value != null && !this.value.isEmpty();
1939    }
1940
1941    /**
1942     * @param value {@link #value} (The information determined as a result of making the observation, if the information has a simple value.)
1943     */
1944    public Observation setValue(Type value) { 
1945      this.value = value;
1946      return this;
1947    }
1948
1949    /**
1950     * @return {@link #dataAbsentReason} (Provides a reason why the expected value in the element Observation.value[x] is missing.)
1951     */
1952    public CodeableConcept getDataAbsentReason() { 
1953      if (this.dataAbsentReason == null)
1954        if (Configuration.errorOnAutoCreate())
1955          throw new Error("Attempt to auto-create Observation.dataAbsentReason");
1956        else if (Configuration.doAutoCreate())
1957          this.dataAbsentReason = new CodeableConcept(); // cc
1958      return this.dataAbsentReason;
1959    }
1960
1961    public boolean hasDataAbsentReason() { 
1962      return this.dataAbsentReason != null && !this.dataAbsentReason.isEmpty();
1963    }
1964
1965    /**
1966     * @param value {@link #dataAbsentReason} (Provides a reason why the expected value in the element Observation.value[x] is missing.)
1967     */
1968    public Observation setDataAbsentReason(CodeableConcept value) { 
1969      this.dataAbsentReason = value;
1970      return this;
1971    }
1972
1973    /**
1974     * @return {@link #interpretation} (The assessment made based on the result of the observation.  Intended as a simple compact code often placed adjacent to the result value in reports and flow sheets to signal the meaning/normalcy status of the result. Otherwise known as abnormal flag.)
1975     */
1976    public CodeableConcept getInterpretation() { 
1977      if (this.interpretation == null)
1978        if (Configuration.errorOnAutoCreate())
1979          throw new Error("Attempt to auto-create Observation.interpretation");
1980        else if (Configuration.doAutoCreate())
1981          this.interpretation = new CodeableConcept(); // cc
1982      return this.interpretation;
1983    }
1984
1985    public boolean hasInterpretation() { 
1986      return this.interpretation != null && !this.interpretation.isEmpty();
1987    }
1988
1989    /**
1990     * @param value {@link #interpretation} (The assessment made based on the result of the observation.  Intended as a simple compact code often placed adjacent to the result value in reports and flow sheets to signal the meaning/normalcy status of the result. Otherwise known as abnormal flag.)
1991     */
1992    public Observation setInterpretation(CodeableConcept value) { 
1993      this.interpretation = value;
1994      return this;
1995    }
1996
1997    /**
1998     * @return {@link #comments} (May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result.). This is the underlying object with id, value and extensions. The accessor "getComments" gives direct access to the value
1999     */
2000    public StringType getCommentsElement() { 
2001      if (this.comments == null)
2002        if (Configuration.errorOnAutoCreate())
2003          throw new Error("Attempt to auto-create Observation.comments");
2004        else if (Configuration.doAutoCreate())
2005          this.comments = new StringType(); // bb
2006      return this.comments;
2007    }
2008
2009    public boolean hasCommentsElement() { 
2010      return this.comments != null && !this.comments.isEmpty();
2011    }
2012
2013    public boolean hasComments() { 
2014      return this.comments != null && !this.comments.isEmpty();
2015    }
2016
2017    /**
2018     * @param value {@link #comments} (May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result.). This is the underlying object with id, value and extensions. The accessor "getComments" gives direct access to the value
2019     */
2020    public Observation setCommentsElement(StringType value) { 
2021      this.comments = value;
2022      return this;
2023    }
2024
2025    /**
2026     * @return May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result.
2027     */
2028    public String getComments() { 
2029      return this.comments == null ? null : this.comments.getValue();
2030    }
2031
2032    /**
2033     * @param value May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result.
2034     */
2035    public Observation setComments(String value) { 
2036      if (Utilities.noString(value))
2037        this.comments = null;
2038      else {
2039        if (this.comments == null)
2040          this.comments = new StringType();
2041        this.comments.setValue(value);
2042      }
2043      return this;
2044    }
2045
2046    /**
2047     * @return {@link #bodySite} (Indicates the site on the subject's body where the observation was made (i.e. the target site).)
2048     */
2049    public CodeableConcept getBodySite() { 
2050      if (this.bodySite == null)
2051        if (Configuration.errorOnAutoCreate())
2052          throw new Error("Attempt to auto-create Observation.bodySite");
2053        else if (Configuration.doAutoCreate())
2054          this.bodySite = new CodeableConcept(); // cc
2055      return this.bodySite;
2056    }
2057
2058    public boolean hasBodySite() { 
2059      return this.bodySite != null && !this.bodySite.isEmpty();
2060    }
2061
2062    /**
2063     * @param value {@link #bodySite} (Indicates the site on the subject's body where the observation was made (i.e. the target site).)
2064     */
2065    public Observation setBodySite(CodeableConcept value) { 
2066      this.bodySite = value;
2067      return this;
2068    }
2069
2070    /**
2071     * @return {@link #method} (Indicates the mechanism used to perform the observation.)
2072     */
2073    public CodeableConcept getMethod() { 
2074      if (this.method == null)
2075        if (Configuration.errorOnAutoCreate())
2076          throw new Error("Attempt to auto-create Observation.method");
2077        else if (Configuration.doAutoCreate())
2078          this.method = new CodeableConcept(); // cc
2079      return this.method;
2080    }
2081
2082    public boolean hasMethod() { 
2083      return this.method != null && !this.method.isEmpty();
2084    }
2085
2086    /**
2087     * @param value {@link #method} (Indicates the mechanism used to perform the observation.)
2088     */
2089    public Observation setMethod(CodeableConcept value) { 
2090      this.method = value;
2091      return this;
2092    }
2093
2094    /**
2095     * @return {@link #specimen} (The specimen that was used when this observation was made.)
2096     */
2097    public Reference getSpecimen() { 
2098      if (this.specimen == null)
2099        if (Configuration.errorOnAutoCreate())
2100          throw new Error("Attempt to auto-create Observation.specimen");
2101        else if (Configuration.doAutoCreate())
2102          this.specimen = new Reference(); // cc
2103      return this.specimen;
2104    }
2105
2106    public boolean hasSpecimen() { 
2107      return this.specimen != null && !this.specimen.isEmpty();
2108    }
2109
2110    /**
2111     * @param value {@link #specimen} (The specimen that was used when this observation was made.)
2112     */
2113    public Observation setSpecimen(Reference value) { 
2114      this.specimen = value;
2115      return this;
2116    }
2117
2118    /**
2119     * @return {@link #specimen} 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 specimen that was used when this observation was made.)
2120     */
2121    public Specimen getSpecimenTarget() { 
2122      if (this.specimenTarget == null)
2123        if (Configuration.errorOnAutoCreate())
2124          throw new Error("Attempt to auto-create Observation.specimen");
2125        else if (Configuration.doAutoCreate())
2126          this.specimenTarget = new Specimen(); // aa
2127      return this.specimenTarget;
2128    }
2129
2130    /**
2131     * @param value {@link #specimen} 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 specimen that was used when this observation was made.)
2132     */
2133    public Observation setSpecimenTarget(Specimen value) { 
2134      this.specimenTarget = value;
2135      return this;
2136    }
2137
2138    /**
2139     * @return {@link #device} (The device used to generate the observation data.)
2140     */
2141    public Reference getDevice() { 
2142      if (this.device == null)
2143        if (Configuration.errorOnAutoCreate())
2144          throw new Error("Attempt to auto-create Observation.device");
2145        else if (Configuration.doAutoCreate())
2146          this.device = new Reference(); // cc
2147      return this.device;
2148    }
2149
2150    public boolean hasDevice() { 
2151      return this.device != null && !this.device.isEmpty();
2152    }
2153
2154    /**
2155     * @param value {@link #device} (The device used to generate the observation data.)
2156     */
2157    public Observation setDevice(Reference value) { 
2158      this.device = value;
2159      return this;
2160    }
2161
2162    /**
2163     * @return {@link #device} 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 device used to generate the observation data.)
2164     */
2165    public Resource getDeviceTarget() { 
2166      return this.deviceTarget;
2167    }
2168
2169    /**
2170     * @param value {@link #device} 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 device used to generate the observation data.)
2171     */
2172    public Observation setDeviceTarget(Resource value) { 
2173      this.deviceTarget = value;
2174      return this;
2175    }
2176
2177    /**
2178     * @return {@link #referenceRange} (Guidance on how to interpret the value by comparison to a normal or recommended range.)
2179     */
2180    public List<ObservationReferenceRangeComponent> getReferenceRange() { 
2181      if (this.referenceRange == null)
2182        this.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
2183      return this.referenceRange;
2184    }
2185
2186    public boolean hasReferenceRange() { 
2187      if (this.referenceRange == null)
2188        return false;
2189      for (ObservationReferenceRangeComponent item : this.referenceRange)
2190        if (!item.isEmpty())
2191          return true;
2192      return false;
2193    }
2194
2195    /**
2196     * @return {@link #referenceRange} (Guidance on how to interpret the value by comparison to a normal or recommended range.)
2197     */
2198    // syntactic sugar
2199    public ObservationReferenceRangeComponent addReferenceRange() { //3
2200      ObservationReferenceRangeComponent t = new ObservationReferenceRangeComponent();
2201      if (this.referenceRange == null)
2202        this.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
2203      this.referenceRange.add(t);
2204      return t;
2205    }
2206
2207    // syntactic sugar
2208    public Observation addReferenceRange(ObservationReferenceRangeComponent t) { //3
2209      if (t == null)
2210        return this;
2211      if (this.referenceRange == null)
2212        this.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
2213      this.referenceRange.add(t);
2214      return this;
2215    }
2216
2217    /**
2218     * @return {@link #related} (A  reference to another resource (usually another Observation but could  also be a QuestionnaireAnswer) whose relationship is defined by the relationship type code.)
2219     */
2220    public List<ObservationRelatedComponent> getRelated() { 
2221      if (this.related == null)
2222        this.related = new ArrayList<ObservationRelatedComponent>();
2223      return this.related;
2224    }
2225
2226    public boolean hasRelated() { 
2227      if (this.related == null)
2228        return false;
2229      for (ObservationRelatedComponent item : this.related)
2230        if (!item.isEmpty())
2231          return true;
2232      return false;
2233    }
2234
2235    /**
2236     * @return {@link #related} (A  reference to another resource (usually another Observation but could  also be a QuestionnaireAnswer) whose relationship is defined by the relationship type code.)
2237     */
2238    // syntactic sugar
2239    public ObservationRelatedComponent addRelated() { //3
2240      ObservationRelatedComponent t = new ObservationRelatedComponent();
2241      if (this.related == null)
2242        this.related = new ArrayList<ObservationRelatedComponent>();
2243      this.related.add(t);
2244      return t;
2245    }
2246
2247    // syntactic sugar
2248    public Observation addRelated(ObservationRelatedComponent t) { //3
2249      if (t == null)
2250        return this;
2251      if (this.related == null)
2252        this.related = new ArrayList<ObservationRelatedComponent>();
2253      this.related.add(t);
2254      return this;
2255    }
2256
2257    /**
2258     * @return {@link #component} (Some observations have multiple component observations.  These component observations are expressed as separate code value pairs that share the same attributes.  Examples include systolic and diastolic component observations for blood pressure measurement and multiple component observations for genetics observations.)
2259     */
2260    public List<ObservationComponentComponent> getComponent() { 
2261      if (this.component == null)
2262        this.component = new ArrayList<ObservationComponentComponent>();
2263      return this.component;
2264    }
2265
2266    public boolean hasComponent() { 
2267      if (this.component == null)
2268        return false;
2269      for (ObservationComponentComponent item : this.component)
2270        if (!item.isEmpty())
2271          return true;
2272      return false;
2273    }
2274
2275    /**
2276     * @return {@link #component} (Some observations have multiple component observations.  These component observations are expressed as separate code value pairs that share the same attributes.  Examples include systolic and diastolic component observations for blood pressure measurement and multiple component observations for genetics observations.)
2277     */
2278    // syntactic sugar
2279    public ObservationComponentComponent addComponent() { //3
2280      ObservationComponentComponent t = new ObservationComponentComponent();
2281      if (this.component == null)
2282        this.component = new ArrayList<ObservationComponentComponent>();
2283      this.component.add(t);
2284      return t;
2285    }
2286
2287    // syntactic sugar
2288    public Observation addComponent(ObservationComponentComponent t) { //3
2289      if (t == null)
2290        return this;
2291      if (this.component == null)
2292        this.component = new ArrayList<ObservationComponentComponent>();
2293      this.component.add(t);
2294      return this;
2295    }
2296
2297      protected void listChildren(List<Property> childrenList) {
2298        super.listChildren(childrenList);
2299        childrenList.add(new Property("identifier", "Identifier", "A unique identifier for the simple observation instance.", 0, java.lang.Integer.MAX_VALUE, identifier));
2300        childrenList.add(new Property("status", "code", "The status of the result value.", 0, java.lang.Integer.MAX_VALUE, status));
2301        childrenList.add(new Property("category", "CodeableConcept", "A code that classifies the general type of observation being made.  This is used  for searching, sorting and display purposes.", 0, java.lang.Integer.MAX_VALUE, category));
2302        childrenList.add(new Property("code", "CodeableConcept", "Describes what was observed. Sometimes this is called the observation \"name\".", 0, java.lang.Integer.MAX_VALUE, code));
2303        childrenList.add(new Property("subject", "Reference(Patient|Group|Device|Location)", "The patient, or group of patients, location, or device whose characteristics (direct or indirect) are described by the observation and into whose record the observation is placed.  Comments: Indirect characteristics may be those of a specimen, fetus, donor,  other observer (for example a relative or EMT), or any observation made about the subject.", 0, java.lang.Integer.MAX_VALUE, subject));
2304        childrenList.add(new Property("encounter", "Reference(Encounter)", "The healthcare event  (e.g. a patient and healthcare provider interaction) during which this observation is made.", 0, java.lang.Integer.MAX_VALUE, encounter));
2305        childrenList.add(new Property("effective[x]", "dateTime|Period", "The time or time-period the observed value is asserted as being true. For biological subjects - e.g. human patients - this is usually called the \"physiologically relevant time\". This is usually either the time of the procedure or of specimen collection, but very often the source of the date/time is not known, only the date/time itself.", 0, java.lang.Integer.MAX_VALUE, effective));
2306        childrenList.add(new Property("issued", "instant", "The date and time this observation was made available to providers, typically after the results have been reviewed and verified.", 0, java.lang.Integer.MAX_VALUE, issued));
2307        childrenList.add(new Property("performer", "Reference(Practitioner|Organization|Patient|RelatedPerson)", "Who was responsible for asserting the observed value as \"true\".", 0, java.lang.Integer.MAX_VALUE, performer));
2308        childrenList.add(new Property("value[x]", "Quantity|CodeableConcept|string|Range|Ratio|SampledData|Attachment|time|dateTime|Period", "The information determined as a result of making the observation, if the information has a simple value.", 0, java.lang.Integer.MAX_VALUE, value));
2309        childrenList.add(new Property("dataAbsentReason", "CodeableConcept", "Provides a reason why the expected value in the element Observation.value[x] is missing.", 0, java.lang.Integer.MAX_VALUE, dataAbsentReason));
2310        childrenList.add(new Property("interpretation", "CodeableConcept", "The assessment made based on the result of the observation.  Intended as a simple compact code often placed adjacent to the result value in reports and flow sheets to signal the meaning/normalcy status of the result. Otherwise known as abnormal flag.", 0, java.lang.Integer.MAX_VALUE, interpretation));
2311        childrenList.add(new Property("comments", "string", "May include statements about significant, unexpected or unreliable values, or information about the source of the value where this may be relevant to the interpretation of the result.", 0, java.lang.Integer.MAX_VALUE, comments));
2312        childrenList.add(new Property("bodySite", "CodeableConcept", "Indicates the site on the subject's body where the observation was made (i.e. the target site).", 0, java.lang.Integer.MAX_VALUE, bodySite));
2313        childrenList.add(new Property("method", "CodeableConcept", "Indicates the mechanism used to perform the observation.", 0, java.lang.Integer.MAX_VALUE, method));
2314        childrenList.add(new Property("specimen", "Reference(Specimen)", "The specimen that was used when this observation was made.", 0, java.lang.Integer.MAX_VALUE, specimen));
2315        childrenList.add(new Property("device", "Reference(Device|DeviceMetric)", "The device used to generate the observation data.", 0, java.lang.Integer.MAX_VALUE, device));
2316        childrenList.add(new Property("referenceRange", "", "Guidance on how to interpret the value by comparison to a normal or recommended range.", 0, java.lang.Integer.MAX_VALUE, referenceRange));
2317        childrenList.add(new Property("related", "", "A  reference to another resource (usually another Observation but could  also be a QuestionnaireAnswer) whose relationship is defined by the relationship type code.", 0, java.lang.Integer.MAX_VALUE, related));
2318        childrenList.add(new Property("component", "", "Some observations have multiple component observations.  These component observations are expressed as separate code value pairs that share the same attributes.  Examples include systolic and diastolic component observations for blood pressure measurement and multiple component observations for genetics observations.", 0, java.lang.Integer.MAX_VALUE, component));
2319      }
2320
2321      @Override
2322      public void setProperty(String name, Base value) throws FHIRException {
2323        if (name.equals("identifier"))
2324          this.getIdentifier().add(castToIdentifier(value));
2325        else if (name.equals("status"))
2326          this.status = new ObservationStatusEnumFactory().fromType(value); // Enumeration<ObservationStatus>
2327        else if (name.equals("category"))
2328          this.category = castToCodeableConcept(value); // CodeableConcept
2329        else if (name.equals("code"))
2330          this.code = castToCodeableConcept(value); // CodeableConcept
2331        else if (name.equals("subject"))
2332          this.subject = castToReference(value); // Reference
2333        else if (name.equals("encounter"))
2334          this.encounter = castToReference(value); // Reference
2335        else if (name.equals("effective[x]"))
2336          this.effective = (Type) value; // Type
2337        else if (name.equals("issued"))
2338          this.issued = castToInstant(value); // InstantType
2339        else if (name.equals("performer"))
2340          this.getPerformer().add(castToReference(value));
2341        else if (name.equals("value[x]"))
2342          this.value = (Type) value; // Type
2343        else if (name.equals("dataAbsentReason"))
2344          this.dataAbsentReason = castToCodeableConcept(value); // CodeableConcept
2345        else if (name.equals("interpretation"))
2346          this.interpretation = castToCodeableConcept(value); // CodeableConcept
2347        else if (name.equals("comments"))
2348          this.comments = castToString(value); // StringType
2349        else if (name.equals("bodySite"))
2350          this.bodySite = castToCodeableConcept(value); // CodeableConcept
2351        else if (name.equals("method"))
2352          this.method = castToCodeableConcept(value); // CodeableConcept
2353        else if (name.equals("specimen"))
2354          this.specimen = castToReference(value); // Reference
2355        else if (name.equals("device"))
2356          this.device = castToReference(value); // Reference
2357        else if (name.equals("referenceRange"))
2358          this.getReferenceRange().add((ObservationReferenceRangeComponent) value);
2359        else if (name.equals("related"))
2360          this.getRelated().add((ObservationRelatedComponent) value);
2361        else if (name.equals("component"))
2362          this.getComponent().add((ObservationComponentComponent) value);
2363        else
2364          super.setProperty(name, value);
2365      }
2366
2367      @Override
2368      public Base addChild(String name) throws FHIRException {
2369        if (name.equals("identifier")) {
2370          return addIdentifier();
2371        }
2372        else if (name.equals("status")) {
2373          throw new FHIRException("Cannot call addChild on a primitive type Observation.status");
2374        }
2375        else if (name.equals("category")) {
2376          this.category = new CodeableConcept();
2377          return this.category;
2378        }
2379        else if (name.equals("code")) {
2380          this.code = new CodeableConcept();
2381          return this.code;
2382        }
2383        else if (name.equals("subject")) {
2384          this.subject = new Reference();
2385          return this.subject;
2386        }
2387        else if (name.equals("encounter")) {
2388          this.encounter = new Reference();
2389          return this.encounter;
2390        }
2391        else if (name.equals("effectiveDateTime")) {
2392          this.effective = new DateTimeType();
2393          return this.effective;
2394        }
2395        else if (name.equals("effectivePeriod")) {
2396          this.effective = new Period();
2397          return this.effective;
2398        }
2399        else if (name.equals("issued")) {
2400          throw new FHIRException("Cannot call addChild on a primitive type Observation.issued");
2401        }
2402        else if (name.equals("performer")) {
2403          return addPerformer();
2404        }
2405        else if (name.equals("valueQuantity")) {
2406          this.value = new Quantity();
2407          return this.value;
2408        }
2409        else if (name.equals("valueCodeableConcept")) {
2410          this.value = new CodeableConcept();
2411          return this.value;
2412        }
2413        else if (name.equals("valueString")) {
2414          this.value = new StringType();
2415          return this.value;
2416        }
2417        else if (name.equals("valueRange")) {
2418          this.value = new Range();
2419          return this.value;
2420        }
2421        else if (name.equals("valueRatio")) {
2422          this.value = new Ratio();
2423          return this.value;
2424        }
2425        else if (name.equals("valueSampledData")) {
2426          this.value = new SampledData();
2427          return this.value;
2428        }
2429        else if (name.equals("valueAttachment")) {
2430          this.value = new Attachment();
2431          return this.value;
2432        }
2433        else if (name.equals("valueTime")) {
2434          this.value = new TimeType();
2435          return this.value;
2436        }
2437        else if (name.equals("valueDateTime")) {
2438          this.value = new DateTimeType();
2439          return this.value;
2440        }
2441        else if (name.equals("valuePeriod")) {
2442          this.value = new Period();
2443          return this.value;
2444        }
2445        else if (name.equals("dataAbsentReason")) {
2446          this.dataAbsentReason = new CodeableConcept();
2447          return this.dataAbsentReason;
2448        }
2449        else if (name.equals("interpretation")) {
2450          this.interpretation = new CodeableConcept();
2451          return this.interpretation;
2452        }
2453        else if (name.equals("comments")) {
2454          throw new FHIRException("Cannot call addChild on a primitive type Observation.comments");
2455        }
2456        else if (name.equals("bodySite")) {
2457          this.bodySite = new CodeableConcept();
2458          return this.bodySite;
2459        }
2460        else if (name.equals("method")) {
2461          this.method = new CodeableConcept();
2462          return this.method;
2463        }
2464        else if (name.equals("specimen")) {
2465          this.specimen = new Reference();
2466          return this.specimen;
2467        }
2468        else if (name.equals("device")) {
2469          this.device = new Reference();
2470          return this.device;
2471        }
2472        else if (name.equals("referenceRange")) {
2473          return addReferenceRange();
2474        }
2475        else if (name.equals("related")) {
2476          return addRelated();
2477        }
2478        else if (name.equals("component")) {
2479          return addComponent();
2480        }
2481        else
2482          return super.addChild(name);
2483      }
2484
2485  public String fhirType() {
2486    return "Observation";
2487
2488  }
2489
2490      public Observation copy() {
2491        Observation dst = new Observation();
2492        copyValues(dst);
2493        if (identifier != null) {
2494          dst.identifier = new ArrayList<Identifier>();
2495          for (Identifier i : identifier)
2496            dst.identifier.add(i.copy());
2497        };
2498        dst.status = status == null ? null : status.copy();
2499        dst.category = category == null ? null : category.copy();
2500        dst.code = code == null ? null : code.copy();
2501        dst.subject = subject == null ? null : subject.copy();
2502        dst.encounter = encounter == null ? null : encounter.copy();
2503        dst.effective = effective == null ? null : effective.copy();
2504        dst.issued = issued == null ? null : issued.copy();
2505        if (performer != null) {
2506          dst.performer = new ArrayList<Reference>();
2507          for (Reference i : performer)
2508            dst.performer.add(i.copy());
2509        };
2510        dst.value = value == null ? null : value.copy();
2511        dst.dataAbsentReason = dataAbsentReason == null ? null : dataAbsentReason.copy();
2512        dst.interpretation = interpretation == null ? null : interpretation.copy();
2513        dst.comments = comments == null ? null : comments.copy();
2514        dst.bodySite = bodySite == null ? null : bodySite.copy();
2515        dst.method = method == null ? null : method.copy();
2516        dst.specimen = specimen == null ? null : specimen.copy();
2517        dst.device = device == null ? null : device.copy();
2518        if (referenceRange != null) {
2519          dst.referenceRange = new ArrayList<ObservationReferenceRangeComponent>();
2520          for (ObservationReferenceRangeComponent i : referenceRange)
2521            dst.referenceRange.add(i.copy());
2522        };
2523        if (related != null) {
2524          dst.related = new ArrayList<ObservationRelatedComponent>();
2525          for (ObservationRelatedComponent i : related)
2526            dst.related.add(i.copy());
2527        };
2528        if (component != null) {
2529          dst.component = new ArrayList<ObservationComponentComponent>();
2530          for (ObservationComponentComponent i : component)
2531            dst.component.add(i.copy());
2532        };
2533        return dst;
2534      }
2535
2536      protected Observation typedCopy() {
2537        return copy();
2538      }
2539
2540      @Override
2541      public boolean equalsDeep(Base other) {
2542        if (!super.equalsDeep(other))
2543          return false;
2544        if (!(other instanceof Observation))
2545          return false;
2546        Observation o = (Observation) other;
2547        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(category, o.category, true)
2548           && compareDeep(code, o.code, true) && compareDeep(subject, o.subject, true) && compareDeep(encounter, o.encounter, true)
2549           && compareDeep(effective, o.effective, true) && compareDeep(issued, o.issued, true) && compareDeep(performer, o.performer, true)
2550           && compareDeep(value, o.value, true) && compareDeep(dataAbsentReason, o.dataAbsentReason, true)
2551           && compareDeep(interpretation, o.interpretation, true) && compareDeep(comments, o.comments, true)
2552           && compareDeep(bodySite, o.bodySite, true) && compareDeep(method, o.method, true) && compareDeep(specimen, o.specimen, true)
2553           && compareDeep(device, o.device, true) && compareDeep(referenceRange, o.referenceRange, true) && compareDeep(related, o.related, true)
2554           && compareDeep(component, o.component, true);
2555      }
2556
2557      @Override
2558      public boolean equalsShallow(Base other) {
2559        if (!super.equalsShallow(other))
2560          return false;
2561        if (!(other instanceof Observation))
2562          return false;
2563        Observation o = (Observation) other;
2564        return compareValues(status, o.status, true) && compareValues(issued, o.issued, true) && compareValues(comments, o.comments, true)
2565          ;
2566      }
2567
2568      public boolean isEmpty() {
2569        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
2570           && (category == null || category.isEmpty()) && (code == null || code.isEmpty()) && (subject == null || subject.isEmpty())
2571           && (encounter == null || encounter.isEmpty()) && (effective == null || effective.isEmpty())
2572           && (issued == null || issued.isEmpty()) && (performer == null || performer.isEmpty()) && (value == null || value.isEmpty())
2573           && (dataAbsentReason == null || dataAbsentReason.isEmpty()) && (interpretation == null || interpretation.isEmpty())
2574           && (comments == null || comments.isEmpty()) && (bodySite == null || bodySite.isEmpty()) && (method == null || method.isEmpty())
2575           && (specimen == null || specimen.isEmpty()) && (device == null || device.isEmpty()) && (referenceRange == null || referenceRange.isEmpty())
2576           && (related == null || related.isEmpty()) && (component == null || component.isEmpty());
2577      }
2578
2579  @Override
2580  public ResourceType getResourceType() {
2581    return ResourceType.Observation;
2582   }
2583
2584  @SearchParamDefinition(name="date", path="Observation.effective[x]", description="Obtained date/time. If the obtained element is a period, a date that falls in the period", type="date" )
2585  public static final String SP_DATE = "date";
2586  @SearchParamDefinition(name="code", path="Observation.code", description="The code of the observation type", type="token" )
2587  public static final String SP_CODE = "code";
2588  @SearchParamDefinition(name="subject", path="Observation.subject", description="The subject that the observation is about", type="reference" )
2589  public static final String SP_SUBJECT = "subject";
2590  @SearchParamDefinition(name="component-data-absent-reason", path="Observation.component.dataAbsentReason", description="The reason why the expected value in the element Observation.component.value[x] is missing.", type="token" )
2591  public static final String SP_COMPONENTDATAABSENTREASON = "component-data-absent-reason";
2592  @SearchParamDefinition(name="value-concept", path="Observation.valueCodeableConcept", description="The value of the observation, if the value is a CodeableConcept", type="token" )
2593  public static final String SP_VALUECONCEPT = "value-concept";
2594  @SearchParamDefinition(name="value-date", path="Observation.valueDateTime | Observation.valuePeriod", description="The value of the observation, if the value is a date or period of time", type="date" )
2595  public static final String SP_VALUEDATE = "value-date";
2596  @SearchParamDefinition(name="related", path="null", description="Related Observations - search on related-type and related-target together", type="composite" )
2597  public static final String SP_RELATED = "related";
2598  @SearchParamDefinition(name="patient", path="Observation.subject", description="The subject that the observation is about (if patient)", type="reference" )
2599  public static final String SP_PATIENT = "patient";
2600  @SearchParamDefinition(name="specimen", path="Observation.specimen", description="Specimen used for this observation", type="reference" )
2601  public static final String SP_SPECIMEN = "specimen";
2602  @SearchParamDefinition(name="component-code", path="Observation.component.code", description="The component code of the observation type", type="token" )
2603  public static final String SP_COMPONENTCODE = "component-code";
2604  @SearchParamDefinition(name="value-string", path="Observation.valueString", description="The value of the observation, if the value is a string, and also searches in CodeableConcept.text", type="string" )
2605  public static final String SP_VALUESTRING = "value-string";
2606  @SearchParamDefinition(name="identifier", path="Observation.identifier", description="The unique id for a particular observation", type="token" )
2607  public static final String SP_IDENTIFIER = "identifier";
2608  @SearchParamDefinition(name="component-code-value-[x]", path="null", description="Both component code and one of the component value parameters", type="composite" )
2609  public static final String SP_COMPONENTCODEVALUEX = "component-code-value-[x]";
2610  @SearchParamDefinition(name="code-value-[x]", path="null", description="Both code and one of the value parameters", type="composite" )
2611  public static final String SP_CODEVALUEX = "code-value-[x]";
2612  @SearchParamDefinition(name="performer", path="Observation.performer", description="Who performed the observation", type="reference" )
2613  public static final String SP_PERFORMER = "performer";
2614  @SearchParamDefinition(name="value-quantity", path="Observation.valueQuantity", description="The value of the observation, if the value is a Quantity, or a SampledData (just search on the bounds of the values in sampled data)", type="quantity" )
2615  public static final String SP_VALUEQUANTITY = "value-quantity";
2616  @SearchParamDefinition(name="component-value-quantity", path="Observation.component.valueQuantity", description="The value of the component observation, if the value is a Quantity, or a SampledData (just search on the bounds of the values in sampled data)", type="quantity" )
2617  public static final String SP_COMPONENTVALUEQUANTITY = "component-value-quantity";
2618  @SearchParamDefinition(name="data-absent-reason", path="Observation.dataAbsentReason", description="The reason why the expected value in the element Observation.value[x] is missing.", type="token" )
2619  public static final String SP_DATAABSENTREASON = "data-absent-reason";
2620  @SearchParamDefinition(name="encounter", path="Observation.encounter", description="Healthcare event related to the observation", type="reference" )
2621  public static final String SP_ENCOUNTER = "encounter";
2622  @SearchParamDefinition(name="related-type", path="Observation.related.type", description="has-member | derived-from | sequel-to | replaces | qualified-by | interfered-by", type="token" )
2623  public static final String SP_RELATEDTYPE = "related-type";
2624  @SearchParamDefinition(name="related-target", path="Observation.related.target", description="Resource that is related to this one", type="reference" )
2625  public static final String SP_RELATEDTARGET = "related-target";
2626  @SearchParamDefinition(name="component-value-string", path="Observation.component.valueString", description="The value of the component observation, if the value is a string, and also searches in CodeableConcept.text", type="string" )
2627  public static final String SP_COMPONENTVALUESTRING = "component-value-string";
2628  @SearchParamDefinition(name="component-value-concept", path="Observation.component.valueCodeableConcept", description="The value of the component observation, if the value is a CodeableConcept", type="token" )
2629  public static final String SP_COMPONENTVALUECONCEPT = "component-value-concept";
2630  @SearchParamDefinition(name="category", path="Observation.category", description="The classification of the type of observation", type="token" )
2631  public static final String SP_CATEGORY = "category";
2632  @SearchParamDefinition(name="device", path="Observation.device", description="The Device that generated the observation data.", type="reference" )
2633  public static final String SP_DEVICE = "device";
2634  @SearchParamDefinition(name="status", path="Observation.status", description="The status of the observation", type="token" )
2635  public static final String SP_STATUS = "status";
2636
2637}