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