001package org.hl7.fhir.dstu2016may.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
033import java.util.ArrayList;
034import java.util.Date;
035import java.util.List;
036
037import org.hl7.fhir.exceptions.FHIRException;
038import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
039import org.hl7.fhir.utilities.Utilities;
040
041import ca.uhn.fhir.model.api.annotation.Block;
042import ca.uhn.fhir.model.api.annotation.Child;
043import ca.uhn.fhir.model.api.annotation.Description;
044import ca.uhn.fhir.model.api.annotation.ResourceDef;
045import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
046/**
047 * A record of a medication that is being consumed by a patient.   A MedicationStatement may indicate that the patient may be taking the medication now, or has taken the medication in the past or will be taking the medication in the future.  The source of this information can be the patient, significant other (such as a family member or spouse), or a clinician.  A common scenario where this information is captured is during the history taking process during a patient visit or stay.   The medication information may come from e.g. the patient's memory, from a prescription bottle,  or from a list of medications the patient, clinician or other party maintains 
048
049The primary difference between a medication statement and a medication administration is that the medication administration has complete administration information and is based on actual administration information from the person who administered the medication.  A medication statement is often, if not always, less specific.  There is no required date/time when the medication was administered, in fact we only know that a source has reported the patient is taking this medication, where details such as time, quantity, or rate or even medication product may be incomplete or missing or less precise.  As stated earlier, the medication statement information may come from the patient's memory, from a prescription bottle or from a list of medications the patient, clinician or other party maintains.  Medication administration is more formal and is not missing detailed information.
050 */
051@ResourceDef(name="MedicationStatement", profile="http://hl7.org/fhir/Profile/MedicationStatement")
052public class MedicationStatement extends DomainResource {
053
054    public enum MedicationStatementStatus {
055        /**
056         * The medication is still being taken.
057         */
058        ACTIVE, 
059        /**
060         * The medication is no longer being taken.
061         */
062        COMPLETED, 
063        /**
064         * The statement was entered in error.
065         */
066        ENTEREDINERROR, 
067        /**
068         * The medication may be taken at some time in the future.
069         */
070        INTENDED, 
071        /**
072         * added to help the parsers
073         */
074        NULL;
075        public static MedicationStatementStatus fromCode(String codeString) throws FHIRException {
076            if (codeString == null || "".equals(codeString))
077                return null;
078        if ("active".equals(codeString))
079          return ACTIVE;
080        if ("completed".equals(codeString))
081          return COMPLETED;
082        if ("entered-in-error".equals(codeString))
083          return ENTEREDINERROR;
084        if ("intended".equals(codeString))
085          return INTENDED;
086        throw new FHIRException("Unknown MedicationStatementStatus code '"+codeString+"'");
087        }
088        public String toCode() {
089          switch (this) {
090            case ACTIVE: return "active";
091            case COMPLETED: return "completed";
092            case ENTEREDINERROR: return "entered-in-error";
093            case INTENDED: return "intended";
094            default: return "?";
095          }
096        }
097        public String getSystem() {
098          switch (this) {
099            case ACTIVE: return "http://hl7.org/fhir/medication-statement-status";
100            case COMPLETED: return "http://hl7.org/fhir/medication-statement-status";
101            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-statement-status";
102            case INTENDED: return "http://hl7.org/fhir/medication-statement-status";
103            default: return "?";
104          }
105        }
106        public String getDefinition() {
107          switch (this) {
108            case ACTIVE: return "The medication is still being taken.";
109            case COMPLETED: return "The medication is no longer being taken.";
110            case ENTEREDINERROR: return "The statement was entered in error.";
111            case INTENDED: return "The medication may be taken at some time in the future.";
112            default: return "?";
113          }
114        }
115        public String getDisplay() {
116          switch (this) {
117            case ACTIVE: return "Active";
118            case COMPLETED: return "Completed";
119            case ENTEREDINERROR: return "Entered in Error";
120            case INTENDED: return "Intended";
121            default: return "?";
122          }
123        }
124    }
125
126  public static class MedicationStatementStatusEnumFactory implements EnumFactory<MedicationStatementStatus> {
127    public MedicationStatementStatus fromCode(String codeString) throws IllegalArgumentException {
128      if (codeString == null || "".equals(codeString))
129            if (codeString == null || "".equals(codeString))
130                return null;
131        if ("active".equals(codeString))
132          return MedicationStatementStatus.ACTIVE;
133        if ("completed".equals(codeString))
134          return MedicationStatementStatus.COMPLETED;
135        if ("entered-in-error".equals(codeString))
136          return MedicationStatementStatus.ENTEREDINERROR;
137        if ("intended".equals(codeString))
138          return MedicationStatementStatus.INTENDED;
139        throw new IllegalArgumentException("Unknown MedicationStatementStatus code '"+codeString+"'");
140        }
141        public Enumeration<MedicationStatementStatus> fromType(Base code) throws FHIRException {
142          if (code == null || code.isEmpty())
143            return null;
144          String codeString = ((PrimitiveType) code).asStringValue();
145          if (codeString == null || "".equals(codeString))
146            return null;
147        if ("active".equals(codeString))
148          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.ACTIVE);
149        if ("completed".equals(codeString))
150          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.COMPLETED);
151        if ("entered-in-error".equals(codeString))
152          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.ENTEREDINERROR);
153        if ("intended".equals(codeString))
154          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.INTENDED);
155        throw new FHIRException("Unknown MedicationStatementStatus code '"+codeString+"'");
156        }
157    public String toCode(MedicationStatementStatus code) {
158      if (code == MedicationStatementStatus.ACTIVE)
159        return "active";
160      if (code == MedicationStatementStatus.COMPLETED)
161        return "completed";
162      if (code == MedicationStatementStatus.ENTEREDINERROR)
163        return "entered-in-error";
164      if (code == MedicationStatementStatus.INTENDED)
165        return "intended";
166      return "?";
167      }
168    public String toSystem(MedicationStatementStatus code) {
169      return code.getSystem();
170      }
171    }
172
173    @Block()
174    public static class MedicationStatementDosageComponent extends BackboneElement implements IBaseBackboneElement {
175        /**
176         * Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.
177         */
178        @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
179        @Description(shortDefinition="Free text dosage instructions as reported by the information source", formalDefinition="Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans." )
180        protected StringType text;
181
182        /**
183         * The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".
184         */
185        @Child(name = "timing", type = {Timing.class}, order=2, min=0, max=1, modifier=false, summary=true)
186        @Description(shortDefinition="When/how often was medication taken", formalDefinition="The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  \"Every  8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\";  \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\"." )
187        protected Timing timing;
188
189        /**
190         * Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
191
192Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.
193         */
194        @Child(name = "asNeeded", type = {BooleanType.class, CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=true)
195        @Description(shortDefinition="Take \"as needed\" (for x)", formalDefinition="Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  \n\nSpecifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule." )
196        protected Type asNeeded;
197
198        /**
199         * A coded specification of or a reference to the anatomic site where the medication first enters the body.
200         */
201        @Child(name = "site", type = {CodeableConcept.class, BodySite.class}, order=4, min=0, max=1, modifier=false, summary=true)
202        @Description(shortDefinition="Where (on body) medication is/was administered", formalDefinition="A coded specification of or a reference to the anatomic site where the medication first enters the body." )
203        protected Type site;
204
205        /**
206         * A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.
207         */
208        @Child(name = "route", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=true)
209        @Description(shortDefinition="How the medication entered the body", formalDefinition="A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject." )
210        protected CodeableConcept route;
211
212        /**
213         * A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.
214         */
215        @Child(name = "method", type = {CodeableConcept.class}, order=6, min=0, max=1, modifier=false, summary=true)
216        @Description(shortDefinition="Technique used to administer medication", formalDefinition="A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV." )
217        protected CodeableConcept method;
218
219        /**
220         * The amount of therapeutic or other substance given at one administration event.
221         */
222        @Child(name = "quantity", type = {SimpleQuantity.class, Range.class}, order=7, min=0, max=1, modifier=false, summary=true)
223        @Description(shortDefinition="Amount administered in one dose", formalDefinition="The amount of therapeutic or other substance given at one administration event." )
224        protected Type quantity;
225
226        /**
227         * Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.
228         */
229        @Child(name = "rate", type = {Ratio.class, Range.class}, order=8, min=0, max=1, modifier=false, summary=true)
230        @Description(shortDefinition="Dose quantity per unit of time", formalDefinition="Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours." )
231        protected Type rate;
232
233        /**
234         * The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.
235         */
236        @Child(name = "maxDosePerPeriod", type = {Ratio.class}, order=9, min=0, max=1, modifier=false, summary=true)
237        @Description(shortDefinition="Maximum dose that was consumed per unit of time", formalDefinition="The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours." )
238        protected Ratio maxDosePerPeriod;
239
240        private static final long serialVersionUID = 246880733L;
241
242    /**
243     * Constructor
244     */
245      public MedicationStatementDosageComponent() {
246        super();
247      }
248
249        /**
250         * @return {@link #text} (Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
251         */
252        public StringType getTextElement() { 
253          if (this.text == null)
254            if (Configuration.errorOnAutoCreate())
255              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.text");
256            else if (Configuration.doAutoCreate())
257              this.text = new StringType(); // bb
258          return this.text;
259        }
260
261        public boolean hasTextElement() { 
262          return this.text != null && !this.text.isEmpty();
263        }
264
265        public boolean hasText() { 
266          return this.text != null && !this.text.isEmpty();
267        }
268
269        /**
270         * @param value {@link #text} (Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
271         */
272        public MedicationStatementDosageComponent setTextElement(StringType value) { 
273          this.text = value;
274          return this;
275        }
276
277        /**
278         * @return Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.
279         */
280        public String getText() { 
281          return this.text == null ? null : this.text.getValue();
282        }
283
284        /**
285         * @param value Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.
286         */
287        public MedicationStatementDosageComponent setText(String value) { 
288          if (Utilities.noString(value))
289            this.text = null;
290          else {
291            if (this.text == null)
292              this.text = new StringType();
293            this.text.setValue(value);
294          }
295          return this;
296        }
297
298        /**
299         * @return {@link #timing} (The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
300         */
301        public Timing getTiming() { 
302          if (this.timing == null)
303            if (Configuration.errorOnAutoCreate())
304              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.timing");
305            else if (Configuration.doAutoCreate())
306              this.timing = new Timing(); // cc
307          return this.timing;
308        }
309
310        public boolean hasTiming() { 
311          return this.timing != null && !this.timing.isEmpty();
312        }
313
314        /**
315         * @param value {@link #timing} (The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
316         */
317        public MedicationStatementDosageComponent setTiming(Timing value) { 
318          this.timing = value;
319          return this;
320        }
321
322        /**
323         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
324
325Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
326         */
327        public Type getAsNeeded() { 
328          return this.asNeeded;
329        }
330
331        /**
332         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
333
334Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
335         */
336        public BooleanType getAsNeededBooleanType() throws FHIRException { 
337          if (!(this.asNeeded instanceof BooleanType))
338            throw new FHIRException("Type mismatch: the type BooleanType was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
339          return (BooleanType) this.asNeeded;
340        }
341
342        public boolean hasAsNeededBooleanType() { 
343          return this.asNeeded instanceof BooleanType;
344        }
345
346        /**
347         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
348
349Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
350         */
351        public CodeableConcept getAsNeededCodeableConcept() throws FHIRException { 
352          if (!(this.asNeeded instanceof CodeableConcept))
353            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
354          return (CodeableConcept) this.asNeeded;
355        }
356
357        public boolean hasAsNeededCodeableConcept() { 
358          return this.asNeeded instanceof CodeableConcept;
359        }
360
361        public boolean hasAsNeeded() { 
362          return this.asNeeded != null && !this.asNeeded.isEmpty();
363        }
364
365        /**
366         * @param value {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
367
368Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
369         */
370        public MedicationStatementDosageComponent setAsNeeded(Type value) { 
371          this.asNeeded = value;
372          return this;
373        }
374
375        /**
376         * @return {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
377         */
378        public Type getSite() { 
379          return this.site;
380        }
381
382        /**
383         * @return {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
384         */
385        public CodeableConcept getSiteCodeableConcept() throws FHIRException { 
386          if (!(this.site instanceof CodeableConcept))
387            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.site.getClass().getName()+" was encountered");
388          return (CodeableConcept) this.site;
389        }
390
391        public boolean hasSiteCodeableConcept() { 
392          return this.site instanceof CodeableConcept;
393        }
394
395        /**
396         * @return {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
397         */
398        public Reference getSiteReference() throws FHIRException { 
399          if (!(this.site instanceof Reference))
400            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.site.getClass().getName()+" was encountered");
401          return (Reference) this.site;
402        }
403
404        public boolean hasSiteReference() { 
405          return this.site instanceof Reference;
406        }
407
408        public boolean hasSite() { 
409          return this.site != null && !this.site.isEmpty();
410        }
411
412        /**
413         * @param value {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
414         */
415        public MedicationStatementDosageComponent setSite(Type value) { 
416          this.site = value;
417          return this;
418        }
419
420        /**
421         * @return {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.)
422         */
423        public CodeableConcept getRoute() { 
424          if (this.route == null)
425            if (Configuration.errorOnAutoCreate())
426              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.route");
427            else if (Configuration.doAutoCreate())
428              this.route = new CodeableConcept(); // cc
429          return this.route;
430        }
431
432        public boolean hasRoute() { 
433          return this.route != null && !this.route.isEmpty();
434        }
435
436        /**
437         * @param value {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.)
438         */
439        public MedicationStatementDosageComponent setRoute(CodeableConcept value) { 
440          this.route = value;
441          return this;
442        }
443
444        /**
445         * @return {@link #method} (A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.)
446         */
447        public CodeableConcept getMethod() { 
448          if (this.method == null)
449            if (Configuration.errorOnAutoCreate())
450              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.method");
451            else if (Configuration.doAutoCreate())
452              this.method = new CodeableConcept(); // cc
453          return this.method;
454        }
455
456        public boolean hasMethod() { 
457          return this.method != null && !this.method.isEmpty();
458        }
459
460        /**
461         * @param value {@link #method} (A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.)
462         */
463        public MedicationStatementDosageComponent setMethod(CodeableConcept value) { 
464          this.method = value;
465          return this;
466        }
467
468        /**
469         * @return {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
470         */
471        public Type getQuantity() { 
472          return this.quantity;
473        }
474
475        /**
476         * @return {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
477         */
478        public SimpleQuantity getQuantitySimpleQuantity() throws FHIRException { 
479          if (!(this.quantity instanceof SimpleQuantity))
480            throw new FHIRException("Type mismatch: the type SimpleQuantity was expected, but "+this.quantity.getClass().getName()+" was encountered");
481          return (SimpleQuantity) this.quantity;
482        }
483
484        public boolean hasQuantitySimpleQuantity() { 
485          return this.quantity instanceof SimpleQuantity;
486        }
487
488        /**
489         * @return {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
490         */
491        public Range getQuantityRange() throws FHIRException { 
492          if (!(this.quantity instanceof Range))
493            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.quantity.getClass().getName()+" was encountered");
494          return (Range) this.quantity;
495        }
496
497        public boolean hasQuantityRange() { 
498          return this.quantity instanceof Range;
499        }
500
501        public boolean hasQuantity() { 
502          return this.quantity != null && !this.quantity.isEmpty();
503        }
504
505        /**
506         * @param value {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
507         */
508        public MedicationStatementDosageComponent setQuantity(Type value) { 
509          this.quantity = value;
510          return this;
511        }
512
513        /**
514         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
515         */
516        public Type getRate() { 
517          return this.rate;
518        }
519
520        /**
521         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
522         */
523        public Ratio getRateRatio() throws FHIRException { 
524          if (!(this.rate instanceof Ratio))
525            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
526          return (Ratio) this.rate;
527        }
528
529        public boolean hasRateRatio() { 
530          return this.rate instanceof Ratio;
531        }
532
533        /**
534         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
535         */
536        public Range getRateRange() throws FHIRException { 
537          if (!(this.rate instanceof Range))
538            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
539          return (Range) this.rate;
540        }
541
542        public boolean hasRateRange() { 
543          return this.rate instanceof Range;
544        }
545
546        public boolean hasRate() { 
547          return this.rate != null && !this.rate.isEmpty();
548        }
549
550        /**
551         * @param value {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
552         */
553        public MedicationStatementDosageComponent setRate(Type value) { 
554          this.rate = value;
555          return this;
556        }
557
558        /**
559         * @return {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.)
560         */
561        public Ratio getMaxDosePerPeriod() { 
562          if (this.maxDosePerPeriod == null)
563            if (Configuration.errorOnAutoCreate())
564              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.maxDosePerPeriod");
565            else if (Configuration.doAutoCreate())
566              this.maxDosePerPeriod = new Ratio(); // cc
567          return this.maxDosePerPeriod;
568        }
569
570        public boolean hasMaxDosePerPeriod() { 
571          return this.maxDosePerPeriod != null && !this.maxDosePerPeriod.isEmpty();
572        }
573
574        /**
575         * @param value {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.)
576         */
577        public MedicationStatementDosageComponent setMaxDosePerPeriod(Ratio value) { 
578          this.maxDosePerPeriod = value;
579          return this;
580        }
581
582        protected void listChildren(List<Property> childrenList) {
583          super.listChildren(childrenList);
584          childrenList.add(new Property("text", "string", "Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.", 0, java.lang.Integer.MAX_VALUE, text));
585          childrenList.add(new Property("timing", "Timing", "The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  \"Every  8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\";  \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\".", 0, java.lang.Integer.MAX_VALUE, timing));
586          childrenList.add(new Property("asNeeded[x]", "boolean|CodeableConcept", "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  \n\nSpecifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.", 0, java.lang.Integer.MAX_VALUE, asNeeded));
587          childrenList.add(new Property("site[x]", "CodeableConcept|Reference(BodySite)", "A coded specification of or a reference to the anatomic site where the medication first enters the body.", 0, java.lang.Integer.MAX_VALUE, site));
588          childrenList.add(new Property("route", "CodeableConcept", "A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.", 0, java.lang.Integer.MAX_VALUE, route));
589          childrenList.add(new Property("method", "CodeableConcept", "A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.", 0, java.lang.Integer.MAX_VALUE, method));
590          childrenList.add(new Property("quantity[x]", "SimpleQuantity|Range", "The amount of therapeutic or other substance given at one administration event.", 0, java.lang.Integer.MAX_VALUE, quantity));
591          childrenList.add(new Property("rate[x]", "Ratio|Range", "Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.", 0, java.lang.Integer.MAX_VALUE, rate));
592          childrenList.add(new Property("maxDosePerPeriod", "Ratio", "The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod));
593        }
594
595      @Override
596      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
597        switch (hash) {
598        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
599        case -873664438: /*timing*/ return this.timing == null ? new Base[0] : new Base[] {this.timing}; // Timing
600        case -1432923513: /*asNeeded*/ return this.asNeeded == null ? new Base[0] : new Base[] {this.asNeeded}; // Type
601        case 3530567: /*site*/ return this.site == null ? new Base[0] : new Base[] {this.site}; // Type
602        case 108704329: /*route*/ return this.route == null ? new Base[0] : new Base[] {this.route}; // CodeableConcept
603        case -1077554975: /*method*/ return this.method == null ? new Base[0] : new Base[] {this.method}; // CodeableConcept
604        case -1285004149: /*quantity*/ return this.quantity == null ? new Base[0] : new Base[] {this.quantity}; // Type
605        case 3493088: /*rate*/ return this.rate == null ? new Base[0] : new Base[] {this.rate}; // Type
606        case 1506263709: /*maxDosePerPeriod*/ return this.maxDosePerPeriod == null ? new Base[0] : new Base[] {this.maxDosePerPeriod}; // Ratio
607        default: return super.getProperty(hash, name, checkValid);
608        }
609
610      }
611
612      @Override
613      public void setProperty(int hash, String name, Base value) throws FHIRException {
614        switch (hash) {
615        case 3556653: // text
616          this.text = castToString(value); // StringType
617          break;
618        case -873664438: // timing
619          this.timing = castToTiming(value); // Timing
620          break;
621        case -1432923513: // asNeeded
622          this.asNeeded = (Type) value; // Type
623          break;
624        case 3530567: // site
625          this.site = (Type) value; // Type
626          break;
627        case 108704329: // route
628          this.route = castToCodeableConcept(value); // CodeableConcept
629          break;
630        case -1077554975: // method
631          this.method = castToCodeableConcept(value); // CodeableConcept
632          break;
633        case -1285004149: // quantity
634          this.quantity = (Type) value; // Type
635          break;
636        case 3493088: // rate
637          this.rate = (Type) value; // Type
638          break;
639        case 1506263709: // maxDosePerPeriod
640          this.maxDosePerPeriod = castToRatio(value); // Ratio
641          break;
642        default: super.setProperty(hash, name, value);
643        }
644
645      }
646
647      @Override
648      public void setProperty(String name, Base value) throws FHIRException {
649        if (name.equals("text"))
650          this.text = castToString(value); // StringType
651        else if (name.equals("timing"))
652          this.timing = castToTiming(value); // Timing
653        else if (name.equals("asNeeded[x]"))
654          this.asNeeded = (Type) value; // Type
655        else if (name.equals("site[x]"))
656          this.site = (Type) value; // Type
657        else if (name.equals("route"))
658          this.route = castToCodeableConcept(value); // CodeableConcept
659        else if (name.equals("method"))
660          this.method = castToCodeableConcept(value); // CodeableConcept
661        else if (name.equals("quantity[x]"))
662          this.quantity = (Type) value; // Type
663        else if (name.equals("rate[x]"))
664          this.rate = (Type) value; // Type
665        else if (name.equals("maxDosePerPeriod"))
666          this.maxDosePerPeriod = castToRatio(value); // Ratio
667        else
668          super.setProperty(name, value);
669      }
670
671      @Override
672      public Base makeProperty(int hash, String name) throws FHIRException {
673        switch (hash) {
674        case 3556653: throw new FHIRException("Cannot make property text as it is not a complex type"); // StringType
675        case -873664438:  return getTiming(); // Timing
676        case -544329575:  return getAsNeeded(); // Type
677        case 2099997657:  return getSite(); // Type
678        case 108704329:  return getRoute(); // CodeableConcept
679        case -1077554975:  return getMethod(); // CodeableConcept
680        case -515002347:  return getQuantity(); // Type
681        case 983460768:  return getRate(); // Type
682        case 1506263709:  return getMaxDosePerPeriod(); // Ratio
683        default: return super.makeProperty(hash, name);
684        }
685
686      }
687
688      @Override
689      public Base addChild(String name) throws FHIRException {
690        if (name.equals("text")) {
691          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.text");
692        }
693        else if (name.equals("timing")) {
694          this.timing = new Timing();
695          return this.timing;
696        }
697        else if (name.equals("asNeededBoolean")) {
698          this.asNeeded = new BooleanType();
699          return this.asNeeded;
700        }
701        else if (name.equals("asNeededCodeableConcept")) {
702          this.asNeeded = new CodeableConcept();
703          return this.asNeeded;
704        }
705        else if (name.equals("siteCodeableConcept")) {
706          this.site = new CodeableConcept();
707          return this.site;
708        }
709        else if (name.equals("siteReference")) {
710          this.site = new Reference();
711          return this.site;
712        }
713        else if (name.equals("route")) {
714          this.route = new CodeableConcept();
715          return this.route;
716        }
717        else if (name.equals("method")) {
718          this.method = new CodeableConcept();
719          return this.method;
720        }
721        else if (name.equals("quantitySimpleQuantity")) {
722          this.quantity = new SimpleQuantity();
723          return this.quantity;
724        }
725        else if (name.equals("quantityRange")) {
726          this.quantity = new Range();
727          return this.quantity;
728        }
729        else if (name.equals("rateRatio")) {
730          this.rate = new Ratio();
731          return this.rate;
732        }
733        else if (name.equals("rateRange")) {
734          this.rate = new Range();
735          return this.rate;
736        }
737        else if (name.equals("maxDosePerPeriod")) {
738          this.maxDosePerPeriod = new Ratio();
739          return this.maxDosePerPeriod;
740        }
741        else
742          return super.addChild(name);
743      }
744
745      public MedicationStatementDosageComponent copy() {
746        MedicationStatementDosageComponent dst = new MedicationStatementDosageComponent();
747        copyValues(dst);
748        dst.text = text == null ? null : text.copy();
749        dst.timing = timing == null ? null : timing.copy();
750        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
751        dst.site = site == null ? null : site.copy();
752        dst.route = route == null ? null : route.copy();
753        dst.method = method == null ? null : method.copy();
754        dst.quantity = quantity == null ? null : quantity.copy();
755        dst.rate = rate == null ? null : rate.copy();
756        dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
757        return dst;
758      }
759
760      @Override
761      public boolean equalsDeep(Base other) {
762        if (!super.equalsDeep(other))
763          return false;
764        if (!(other instanceof MedicationStatementDosageComponent))
765          return false;
766        MedicationStatementDosageComponent o = (MedicationStatementDosageComponent) other;
767        return compareDeep(text, o.text, true) && compareDeep(timing, o.timing, true) && compareDeep(asNeeded, o.asNeeded, true)
768           && compareDeep(site, o.site, true) && compareDeep(route, o.route, true) && compareDeep(method, o.method, true)
769           && compareDeep(quantity, o.quantity, true) && compareDeep(rate, o.rate, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true)
770          ;
771      }
772
773      @Override
774      public boolean equalsShallow(Base other) {
775        if (!super.equalsShallow(other))
776          return false;
777        if (!(other instanceof MedicationStatementDosageComponent))
778          return false;
779        MedicationStatementDosageComponent o = (MedicationStatementDosageComponent) other;
780        return compareValues(text, o.text, true);
781      }
782
783      public boolean isEmpty() {
784        return super.isEmpty() && (text == null || text.isEmpty()) && (timing == null || timing.isEmpty())
785           && (asNeeded == null || asNeeded.isEmpty()) && (site == null || site.isEmpty()) && (route == null || route.isEmpty())
786           && (method == null || method.isEmpty()) && (quantity == null || quantity.isEmpty()) && (rate == null || rate.isEmpty())
787           && (maxDosePerPeriod == null || maxDosePerPeriod.isEmpty());
788      }
789
790  public String fhirType() {
791    return "MedicationStatement.dosage";
792
793  }
794
795  }
796
797    /**
798     * External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.
799     */
800    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
801    @Description(shortDefinition="External identifier", formalDefinition="External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated." )
802    protected List<Identifier> identifier;
803
804    /**
805     * A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.
806     */
807    @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=true, summary=true)
808    @Description(shortDefinition="active | completed | entered-in-error | intended", formalDefinition="A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed." )
809    protected Enumeration<MedicationStatementStatus> status;
810
811    /**
812     * Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.
813     */
814    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=2, min=1, max=1, modifier=false, summary=true)
815    @Description(shortDefinition="What medication was taken", formalDefinition="Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications." )
816    protected Type medication;
817
818    /**
819     * The person or animal who is/was taking the medication.
820     */
821    @Child(name = "patient", type = {Patient.class}, order=3, min=1, max=1, modifier=false, summary=true)
822    @Description(shortDefinition="Who is/was taking  the medication", formalDefinition="The person or animal who is/was taking the medication." )
823    protected Reference patient;
824
825    /**
826     * The actual object that is the target of the reference (The person or animal who is/was taking the medication.)
827     */
828    protected Patient patientTarget;
829
830    /**
831     * The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).
832     */
833    @Child(name = "effective", type = {DateTimeType.class, Period.class}, order=4, min=0, max=1, modifier=false, summary=true)
834    @Description(shortDefinition="Over what period was medication consumed?", formalDefinition="The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true)." )
835    protected Type effective;
836
837    /**
838     * The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.
839     */
840    @Child(name = "informationSource", type = {Patient.class, Practitioner.class, RelatedPerson.class}, order=5, min=0, max=1, modifier=false, summary=true)
841    @Description(shortDefinition="Person who provided the information about the taking of this medication", formalDefinition="The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder." )
842    protected Reference informationSource;
843
844    /**
845     * The actual object that is the target of the reference (The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.)
846     */
847    protected Resource informationSourceTarget;
848
849    /**
850     * Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement.
851     */
852    @Child(name = "supportingInformation", type = {}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
853    @Description(shortDefinition="Additional supporting information", formalDefinition="Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement." )
854    protected List<Reference> supportingInformation;
855    /**
856     * The actual objects that are the target of the reference (Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement.)
857     */
858    protected List<Resource> supportingInformationTarget;
859
860
861    /**
862     * The date when the medication statement was asserted by the information source.
863     */
864    @Child(name = "dateAsserted", type = {DateTimeType.class}, order=7, min=0, max=1, modifier=false, summary=true)
865    @Description(shortDefinition="When the statement was asserted?", formalDefinition="The date when the medication statement was asserted by the information source." )
866    protected DateTimeType dateAsserted;
867
868    /**
869     * Set this to true if the record is saying that the medication was NOT taken.
870     */
871    @Child(name = "wasNotTaken", type = {BooleanType.class}, order=8, min=0, max=1, modifier=true, summary=true)
872    @Description(shortDefinition="True if medication is/was not being taken", formalDefinition="Set this to true if the record is saying that the medication was NOT taken." )
873    protected BooleanType wasNotTaken;
874
875    /**
876     * A code indicating why the medication was not taken.
877     */
878    @Child(name = "reasonNotTaken", type = {CodeableConcept.class}, order=9, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
879    @Description(shortDefinition="True if asserting medication was not given", formalDefinition="A code indicating why the medication was not taken." )
880    protected List<CodeableConcept> reasonNotTaken;
881
882    /**
883     * A reason for why the medication is being/was taken.
884     */
885    @Child(name = "reasonForUse", type = {CodeableConcept.class, Condition.class}, order=10, min=0, max=1, modifier=false, summary=true)
886    @Description(shortDefinition="", formalDefinition="A reason for why the medication is being/was taken." )
887    protected Type reasonForUse;
888
889    /**
890     * Provides extra information about the medication statement that is not conveyed by the other attributes.
891     */
892    @Child(name = "note", type = {Annotation.class}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
893    @Description(shortDefinition="Further information about the statement", formalDefinition="Provides extra information about the medication statement that is not conveyed by the other attributes." )
894    protected List<Annotation> note;
895
896    /**
897     * Indicates how the medication is/was used by the patient.
898     */
899    @Child(name = "dosage", type = {}, order=12, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
900    @Description(shortDefinition="Details of how medication was taken", formalDefinition="Indicates how the medication is/was used by the patient." )
901    protected List<MedicationStatementDosageComponent> dosage;
902
903    private static final long serialVersionUID = -425948910L;
904
905  /**
906   * Constructor
907   */
908    public MedicationStatement() {
909      super();
910    }
911
912  /**
913   * Constructor
914   */
915    public MedicationStatement(Enumeration<MedicationStatementStatus> status, Type medication, Reference patient) {
916      super();
917      this.status = status;
918      this.medication = medication;
919      this.patient = patient;
920    }
921
922    /**
923     * @return {@link #identifier} (External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.)
924     */
925    public List<Identifier> getIdentifier() { 
926      if (this.identifier == null)
927        this.identifier = new ArrayList<Identifier>();
928      return this.identifier;
929    }
930
931    public boolean hasIdentifier() { 
932      if (this.identifier == null)
933        return false;
934      for (Identifier item : this.identifier)
935        if (!item.isEmpty())
936          return true;
937      return false;
938    }
939
940    /**
941     * @return {@link #identifier} (External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.)
942     */
943    // syntactic sugar
944    public Identifier addIdentifier() { //3
945      Identifier t = new Identifier();
946      if (this.identifier == null)
947        this.identifier = new ArrayList<Identifier>();
948      this.identifier.add(t);
949      return t;
950    }
951
952    // syntactic sugar
953    public MedicationStatement addIdentifier(Identifier t) { //3
954      if (t == null)
955        return this;
956      if (this.identifier == null)
957        this.identifier = new ArrayList<Identifier>();
958      this.identifier.add(t);
959      return this;
960    }
961
962    /**
963     * @return {@link #status} (A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
964     */
965    public Enumeration<MedicationStatementStatus> getStatusElement() { 
966      if (this.status == null)
967        if (Configuration.errorOnAutoCreate())
968          throw new Error("Attempt to auto-create MedicationStatement.status");
969        else if (Configuration.doAutoCreate())
970          this.status = new Enumeration<MedicationStatementStatus>(new MedicationStatementStatusEnumFactory()); // bb
971      return this.status;
972    }
973
974    public boolean hasStatusElement() { 
975      return this.status != null && !this.status.isEmpty();
976    }
977
978    public boolean hasStatus() { 
979      return this.status != null && !this.status.isEmpty();
980    }
981
982    /**
983     * @param value {@link #status} (A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
984     */
985    public MedicationStatement setStatusElement(Enumeration<MedicationStatementStatus> value) { 
986      this.status = value;
987      return this;
988    }
989
990    /**
991     * @return A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.
992     */
993    public MedicationStatementStatus getStatus() { 
994      return this.status == null ? null : this.status.getValue();
995    }
996
997    /**
998     * @param value A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.
999     */
1000    public MedicationStatement setStatus(MedicationStatementStatus value) { 
1001        if (this.status == null)
1002          this.status = new Enumeration<MedicationStatementStatus>(new MedicationStatementStatusEnumFactory());
1003        this.status.setValue(value);
1004      return this;
1005    }
1006
1007    /**
1008     * @return {@link #medication} (Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1009     */
1010    public Type getMedication() { 
1011      return this.medication;
1012    }
1013
1014    /**
1015     * @return {@link #medication} (Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1016     */
1017    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1018      if (!(this.medication instanceof CodeableConcept))
1019        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1020      return (CodeableConcept) this.medication;
1021    }
1022
1023    public boolean hasMedicationCodeableConcept() { 
1024      return this.medication instanceof CodeableConcept;
1025    }
1026
1027    /**
1028     * @return {@link #medication} (Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1029     */
1030    public Reference getMedicationReference() throws FHIRException { 
1031      if (!(this.medication instanceof Reference))
1032        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
1033      return (Reference) this.medication;
1034    }
1035
1036    public boolean hasMedicationReference() { 
1037      return this.medication instanceof Reference;
1038    }
1039
1040    public boolean hasMedication() { 
1041      return this.medication != null && !this.medication.isEmpty();
1042    }
1043
1044    /**
1045     * @param value {@link #medication} (Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1046     */
1047    public MedicationStatement setMedication(Type value) { 
1048      this.medication = value;
1049      return this;
1050    }
1051
1052    /**
1053     * @return {@link #patient} (The person or animal who is/was taking the medication.)
1054     */
1055    public Reference getPatient() { 
1056      if (this.patient == null)
1057        if (Configuration.errorOnAutoCreate())
1058          throw new Error("Attempt to auto-create MedicationStatement.patient");
1059        else if (Configuration.doAutoCreate())
1060          this.patient = new Reference(); // cc
1061      return this.patient;
1062    }
1063
1064    public boolean hasPatient() { 
1065      return this.patient != null && !this.patient.isEmpty();
1066    }
1067
1068    /**
1069     * @param value {@link #patient} (The person or animal who is/was taking the medication.)
1070     */
1071    public MedicationStatement setPatient(Reference value) { 
1072      this.patient = value;
1073      return this;
1074    }
1075
1076    /**
1077     * @return {@link #patient} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The person or animal who is/was taking the medication.)
1078     */
1079    public Patient getPatientTarget() { 
1080      if (this.patientTarget == null)
1081        if (Configuration.errorOnAutoCreate())
1082          throw new Error("Attempt to auto-create MedicationStatement.patient");
1083        else if (Configuration.doAutoCreate())
1084          this.patientTarget = new Patient(); // aa
1085      return this.patientTarget;
1086    }
1087
1088    /**
1089     * @param value {@link #patient} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The person or animal who is/was taking the medication.)
1090     */
1091    public MedicationStatement setPatientTarget(Patient value) { 
1092      this.patientTarget = value;
1093      return this;
1094    }
1095
1096    /**
1097     * @return {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1098     */
1099    public Type getEffective() { 
1100      return this.effective;
1101    }
1102
1103    /**
1104     * @return {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1105     */
1106    public DateTimeType getEffectiveDateTimeType() throws FHIRException { 
1107      if (!(this.effective instanceof DateTimeType))
1108        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.effective.getClass().getName()+" was encountered");
1109      return (DateTimeType) this.effective;
1110    }
1111
1112    public boolean hasEffectiveDateTimeType() { 
1113      return this.effective instanceof DateTimeType;
1114    }
1115
1116    /**
1117     * @return {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1118     */
1119    public Period getEffectivePeriod() throws FHIRException { 
1120      if (!(this.effective instanceof Period))
1121        throw new FHIRException("Type mismatch: the type Period was expected, but "+this.effective.getClass().getName()+" was encountered");
1122      return (Period) this.effective;
1123    }
1124
1125    public boolean hasEffectivePeriod() { 
1126      return this.effective instanceof Period;
1127    }
1128
1129    public boolean hasEffective() { 
1130      return this.effective != null && !this.effective.isEmpty();
1131    }
1132
1133    /**
1134     * @param value {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1135     */
1136    public MedicationStatement setEffective(Type value) { 
1137      this.effective = value;
1138      return this;
1139    }
1140
1141    /**
1142     * @return {@link #informationSource} (The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.)
1143     */
1144    public Reference getInformationSource() { 
1145      if (this.informationSource == null)
1146        if (Configuration.errorOnAutoCreate())
1147          throw new Error("Attempt to auto-create MedicationStatement.informationSource");
1148        else if (Configuration.doAutoCreate())
1149          this.informationSource = new Reference(); // cc
1150      return this.informationSource;
1151    }
1152
1153    public boolean hasInformationSource() { 
1154      return this.informationSource != null && !this.informationSource.isEmpty();
1155    }
1156
1157    /**
1158     * @param value {@link #informationSource} (The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.)
1159     */
1160    public MedicationStatement setInformationSource(Reference value) { 
1161      this.informationSource = value;
1162      return this;
1163    }
1164
1165    /**
1166     * @return {@link #informationSource} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.)
1167     */
1168    public Resource getInformationSourceTarget() { 
1169      return this.informationSourceTarget;
1170    }
1171
1172    /**
1173     * @param value {@link #informationSource} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.)
1174     */
1175    public MedicationStatement setInformationSourceTarget(Resource value) { 
1176      this.informationSourceTarget = value;
1177      return this;
1178    }
1179
1180    /**
1181     * @return {@link #supportingInformation} (Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement.)
1182     */
1183    public List<Reference> getSupportingInformation() { 
1184      if (this.supportingInformation == null)
1185        this.supportingInformation = new ArrayList<Reference>();
1186      return this.supportingInformation;
1187    }
1188
1189    public boolean hasSupportingInformation() { 
1190      if (this.supportingInformation == null)
1191        return false;
1192      for (Reference item : this.supportingInformation)
1193        if (!item.isEmpty())
1194          return true;
1195      return false;
1196    }
1197
1198    /**
1199     * @return {@link #supportingInformation} (Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement.)
1200     */
1201    // syntactic sugar
1202    public Reference addSupportingInformation() { //3
1203      Reference t = new Reference();
1204      if (this.supportingInformation == null)
1205        this.supportingInformation = new ArrayList<Reference>();
1206      this.supportingInformation.add(t);
1207      return t;
1208    }
1209
1210    // syntactic sugar
1211    public MedicationStatement addSupportingInformation(Reference t) { //3
1212      if (t == null)
1213        return this;
1214      if (this.supportingInformation == null)
1215        this.supportingInformation = new ArrayList<Reference>();
1216      this.supportingInformation.add(t);
1217      return this;
1218    }
1219
1220    /**
1221     * @return {@link #supportingInformation} (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. Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement.)
1222     */
1223    public List<Resource> getSupportingInformationTarget() { 
1224      if (this.supportingInformationTarget == null)
1225        this.supportingInformationTarget = new ArrayList<Resource>();
1226      return this.supportingInformationTarget;
1227    }
1228
1229    /**
1230     * @return {@link #dateAsserted} (The date when the medication statement was asserted by the information source.). This is the underlying object with id, value and extensions. The accessor "getDateAsserted" gives direct access to the value
1231     */
1232    public DateTimeType getDateAssertedElement() { 
1233      if (this.dateAsserted == null)
1234        if (Configuration.errorOnAutoCreate())
1235          throw new Error("Attempt to auto-create MedicationStatement.dateAsserted");
1236        else if (Configuration.doAutoCreate())
1237          this.dateAsserted = new DateTimeType(); // bb
1238      return this.dateAsserted;
1239    }
1240
1241    public boolean hasDateAssertedElement() { 
1242      return this.dateAsserted != null && !this.dateAsserted.isEmpty();
1243    }
1244
1245    public boolean hasDateAsserted() { 
1246      return this.dateAsserted != null && !this.dateAsserted.isEmpty();
1247    }
1248
1249    /**
1250     * @param value {@link #dateAsserted} (The date when the medication statement was asserted by the information source.). This is the underlying object with id, value and extensions. The accessor "getDateAsserted" gives direct access to the value
1251     */
1252    public MedicationStatement setDateAssertedElement(DateTimeType value) { 
1253      this.dateAsserted = value;
1254      return this;
1255    }
1256
1257    /**
1258     * @return The date when the medication statement was asserted by the information source.
1259     */
1260    public Date getDateAsserted() { 
1261      return this.dateAsserted == null ? null : this.dateAsserted.getValue();
1262    }
1263
1264    /**
1265     * @param value The date when the medication statement was asserted by the information source.
1266     */
1267    public MedicationStatement setDateAsserted(Date value) { 
1268      if (value == null)
1269        this.dateAsserted = null;
1270      else {
1271        if (this.dateAsserted == null)
1272          this.dateAsserted = new DateTimeType();
1273        this.dateAsserted.setValue(value);
1274      }
1275      return this;
1276    }
1277
1278    /**
1279     * @return {@link #wasNotTaken} (Set this to true if the record is saying that the medication was NOT taken.). This is the underlying object with id, value and extensions. The accessor "getWasNotTaken" gives direct access to the value
1280     */
1281    public BooleanType getWasNotTakenElement() { 
1282      if (this.wasNotTaken == null)
1283        if (Configuration.errorOnAutoCreate())
1284          throw new Error("Attempt to auto-create MedicationStatement.wasNotTaken");
1285        else if (Configuration.doAutoCreate())
1286          this.wasNotTaken = new BooleanType(); // bb
1287      return this.wasNotTaken;
1288    }
1289
1290    public boolean hasWasNotTakenElement() { 
1291      return this.wasNotTaken != null && !this.wasNotTaken.isEmpty();
1292    }
1293
1294    public boolean hasWasNotTaken() { 
1295      return this.wasNotTaken != null && !this.wasNotTaken.isEmpty();
1296    }
1297
1298    /**
1299     * @param value {@link #wasNotTaken} (Set this to true if the record is saying that the medication was NOT taken.). This is the underlying object with id, value and extensions. The accessor "getWasNotTaken" gives direct access to the value
1300     */
1301    public MedicationStatement setWasNotTakenElement(BooleanType value) { 
1302      this.wasNotTaken = value;
1303      return this;
1304    }
1305
1306    /**
1307     * @return Set this to true if the record is saying that the medication was NOT taken.
1308     */
1309    public boolean getWasNotTaken() { 
1310      return this.wasNotTaken == null || this.wasNotTaken.isEmpty() ? false : this.wasNotTaken.getValue();
1311    }
1312
1313    /**
1314     * @param value Set this to true if the record is saying that the medication was NOT taken.
1315     */
1316    public MedicationStatement setWasNotTaken(boolean value) { 
1317        if (this.wasNotTaken == null)
1318          this.wasNotTaken = new BooleanType();
1319        this.wasNotTaken.setValue(value);
1320      return this;
1321    }
1322
1323    /**
1324     * @return {@link #reasonNotTaken} (A code indicating why the medication was not taken.)
1325     */
1326    public List<CodeableConcept> getReasonNotTaken() { 
1327      if (this.reasonNotTaken == null)
1328        this.reasonNotTaken = new ArrayList<CodeableConcept>();
1329      return this.reasonNotTaken;
1330    }
1331
1332    public boolean hasReasonNotTaken() { 
1333      if (this.reasonNotTaken == null)
1334        return false;
1335      for (CodeableConcept item : this.reasonNotTaken)
1336        if (!item.isEmpty())
1337          return true;
1338      return false;
1339    }
1340
1341    /**
1342     * @return {@link #reasonNotTaken} (A code indicating why the medication was not taken.)
1343     */
1344    // syntactic sugar
1345    public CodeableConcept addReasonNotTaken() { //3
1346      CodeableConcept t = new CodeableConcept();
1347      if (this.reasonNotTaken == null)
1348        this.reasonNotTaken = new ArrayList<CodeableConcept>();
1349      this.reasonNotTaken.add(t);
1350      return t;
1351    }
1352
1353    // syntactic sugar
1354    public MedicationStatement addReasonNotTaken(CodeableConcept t) { //3
1355      if (t == null)
1356        return this;
1357      if (this.reasonNotTaken == null)
1358        this.reasonNotTaken = new ArrayList<CodeableConcept>();
1359      this.reasonNotTaken.add(t);
1360      return this;
1361    }
1362
1363    /**
1364     * @return {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1365     */
1366    public Type getReasonForUse() { 
1367      return this.reasonForUse;
1368    }
1369
1370    /**
1371     * @return {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1372     */
1373    public CodeableConcept getReasonForUseCodeableConcept() throws FHIRException { 
1374      if (!(this.reasonForUse instanceof CodeableConcept))
1375        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.reasonForUse.getClass().getName()+" was encountered");
1376      return (CodeableConcept) this.reasonForUse;
1377    }
1378
1379    public boolean hasReasonForUseCodeableConcept() { 
1380      return this.reasonForUse instanceof CodeableConcept;
1381    }
1382
1383    /**
1384     * @return {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1385     */
1386    public Reference getReasonForUseReference() throws FHIRException { 
1387      if (!(this.reasonForUse instanceof Reference))
1388        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.reasonForUse.getClass().getName()+" was encountered");
1389      return (Reference) this.reasonForUse;
1390    }
1391
1392    public boolean hasReasonForUseReference() { 
1393      return this.reasonForUse instanceof Reference;
1394    }
1395
1396    public boolean hasReasonForUse() { 
1397      return this.reasonForUse != null && !this.reasonForUse.isEmpty();
1398    }
1399
1400    /**
1401     * @param value {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1402     */
1403    public MedicationStatement setReasonForUse(Type value) { 
1404      this.reasonForUse = value;
1405      return this;
1406    }
1407
1408    /**
1409     * @return {@link #note} (Provides extra information about the medication statement that is not conveyed by the other attributes.)
1410     */
1411    public List<Annotation> getNote() { 
1412      if (this.note == null)
1413        this.note = new ArrayList<Annotation>();
1414      return this.note;
1415    }
1416
1417    public boolean hasNote() { 
1418      if (this.note == null)
1419        return false;
1420      for (Annotation item : this.note)
1421        if (!item.isEmpty())
1422          return true;
1423      return false;
1424    }
1425
1426    /**
1427     * @return {@link #note} (Provides extra information about the medication statement that is not conveyed by the other attributes.)
1428     */
1429    // syntactic sugar
1430    public Annotation addNote() { //3
1431      Annotation t = new Annotation();
1432      if (this.note == null)
1433        this.note = new ArrayList<Annotation>();
1434      this.note.add(t);
1435      return t;
1436    }
1437
1438    // syntactic sugar
1439    public MedicationStatement addNote(Annotation t) { //3
1440      if (t == null)
1441        return this;
1442      if (this.note == null)
1443        this.note = new ArrayList<Annotation>();
1444      this.note.add(t);
1445      return this;
1446    }
1447
1448    /**
1449     * @return {@link #dosage} (Indicates how the medication is/was used by the patient.)
1450     */
1451    public List<MedicationStatementDosageComponent> getDosage() { 
1452      if (this.dosage == null)
1453        this.dosage = new ArrayList<MedicationStatementDosageComponent>();
1454      return this.dosage;
1455    }
1456
1457    public boolean hasDosage() { 
1458      if (this.dosage == null)
1459        return false;
1460      for (MedicationStatementDosageComponent item : this.dosage)
1461        if (!item.isEmpty())
1462          return true;
1463      return false;
1464    }
1465
1466    /**
1467     * @return {@link #dosage} (Indicates how the medication is/was used by the patient.)
1468     */
1469    // syntactic sugar
1470    public MedicationStatementDosageComponent addDosage() { //3
1471      MedicationStatementDosageComponent t = new MedicationStatementDosageComponent();
1472      if (this.dosage == null)
1473        this.dosage = new ArrayList<MedicationStatementDosageComponent>();
1474      this.dosage.add(t);
1475      return t;
1476    }
1477
1478    // syntactic sugar
1479    public MedicationStatement addDosage(MedicationStatementDosageComponent t) { //3
1480      if (t == null)
1481        return this;
1482      if (this.dosage == null)
1483        this.dosage = new ArrayList<MedicationStatementDosageComponent>();
1484      this.dosage.add(t);
1485      return this;
1486    }
1487
1488      protected void listChildren(List<Property> childrenList) {
1489        super.listChildren(childrenList);
1490        childrenList.add(new Property("identifier", "Identifier", "External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.", 0, java.lang.Integer.MAX_VALUE, identifier));
1491        childrenList.add(new Property("status", "code", "A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.", 0, java.lang.Integer.MAX_VALUE, status));
1492        childrenList.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.", 0, java.lang.Integer.MAX_VALUE, medication));
1493        childrenList.add(new Property("patient", "Reference(Patient)", "The person or animal who is/was taking the medication.", 0, java.lang.Integer.MAX_VALUE, patient));
1494        childrenList.add(new Property("effective[x]", "dateTime|Period", "The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).", 0, java.lang.Integer.MAX_VALUE, effective));
1495        childrenList.add(new Property("informationSource", "Reference(Patient|Practitioner|RelatedPerson)", "The person who provided the information about the taking of this medication.  Note:  A MedicationStatement may be derived from supportingInformation e.g claims or medicationOrder.", 0, java.lang.Integer.MAX_VALUE, informationSource));
1496        childrenList.add(new Property("supportingInformation", "Reference(Any)", "Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports or is used to derive the MedicationStatement.", 0, java.lang.Integer.MAX_VALUE, supportingInformation));
1497        childrenList.add(new Property("dateAsserted", "dateTime", "The date when the medication statement was asserted by the information source.", 0, java.lang.Integer.MAX_VALUE, dateAsserted));
1498        childrenList.add(new Property("wasNotTaken", "boolean", "Set this to true if the record is saying that the medication was NOT taken.", 0, java.lang.Integer.MAX_VALUE, wasNotTaken));
1499        childrenList.add(new Property("reasonNotTaken", "CodeableConcept", "A code indicating why the medication was not taken.", 0, java.lang.Integer.MAX_VALUE, reasonNotTaken));
1500        childrenList.add(new Property("reasonForUse[x]", "CodeableConcept|Reference(Condition)", "A reason for why the medication is being/was taken.", 0, java.lang.Integer.MAX_VALUE, reasonForUse));
1501        childrenList.add(new Property("note", "Annotation", "Provides extra information about the medication statement that is not conveyed by the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
1502        childrenList.add(new Property("dosage", "", "Indicates how the medication is/was used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosage));
1503      }
1504
1505      @Override
1506      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1507        switch (hash) {
1508        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
1509        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<MedicationStatementStatus>
1510        case 1998965455: /*medication*/ return this.medication == null ? new Base[0] : new Base[] {this.medication}; // Type
1511        case -791418107: /*patient*/ return this.patient == null ? new Base[0] : new Base[] {this.patient}; // Reference
1512        case -1468651097: /*effective*/ return this.effective == null ? new Base[0] : new Base[] {this.effective}; // Type
1513        case -2123220889: /*informationSource*/ return this.informationSource == null ? new Base[0] : new Base[] {this.informationSource}; // Reference
1514        case -1248768647: /*supportingInformation*/ return this.supportingInformation == null ? new Base[0] : this.supportingInformation.toArray(new Base[this.supportingInformation.size()]); // Reference
1515        case -1980855245: /*dateAsserted*/ return this.dateAsserted == null ? new Base[0] : new Base[] {this.dateAsserted}; // DateTimeType
1516        case -1039154243: /*wasNotTaken*/ return this.wasNotTaken == null ? new Base[0] : new Base[] {this.wasNotTaken}; // BooleanType
1517        case 2112880664: /*reasonNotTaken*/ return this.reasonNotTaken == null ? new Base[0] : this.reasonNotTaken.toArray(new Base[this.reasonNotTaken.size()]); // CodeableConcept
1518        case -1724097694: /*reasonForUse*/ return this.reasonForUse == null ? new Base[0] : new Base[] {this.reasonForUse}; // Type
1519        case 3387378: /*note*/ return this.note == null ? new Base[0] : this.note.toArray(new Base[this.note.size()]); // Annotation
1520        case -1326018889: /*dosage*/ return this.dosage == null ? new Base[0] : this.dosage.toArray(new Base[this.dosage.size()]); // MedicationStatementDosageComponent
1521        default: return super.getProperty(hash, name, checkValid);
1522        }
1523
1524      }
1525
1526      @Override
1527      public void setProperty(int hash, String name, Base value) throws FHIRException {
1528        switch (hash) {
1529        case -1618432855: // identifier
1530          this.getIdentifier().add(castToIdentifier(value)); // Identifier
1531          break;
1532        case -892481550: // status
1533          this.status = new MedicationStatementStatusEnumFactory().fromType(value); // Enumeration<MedicationStatementStatus>
1534          break;
1535        case 1998965455: // medication
1536          this.medication = (Type) value; // Type
1537          break;
1538        case -791418107: // patient
1539          this.patient = castToReference(value); // Reference
1540          break;
1541        case -1468651097: // effective
1542          this.effective = (Type) value; // Type
1543          break;
1544        case -2123220889: // informationSource
1545          this.informationSource = castToReference(value); // Reference
1546          break;
1547        case -1248768647: // supportingInformation
1548          this.getSupportingInformation().add(castToReference(value)); // Reference
1549          break;
1550        case -1980855245: // dateAsserted
1551          this.dateAsserted = castToDateTime(value); // DateTimeType
1552          break;
1553        case -1039154243: // wasNotTaken
1554          this.wasNotTaken = castToBoolean(value); // BooleanType
1555          break;
1556        case 2112880664: // reasonNotTaken
1557          this.getReasonNotTaken().add(castToCodeableConcept(value)); // CodeableConcept
1558          break;
1559        case -1724097694: // reasonForUse
1560          this.reasonForUse = (Type) value; // Type
1561          break;
1562        case 3387378: // note
1563          this.getNote().add(castToAnnotation(value)); // Annotation
1564          break;
1565        case -1326018889: // dosage
1566          this.getDosage().add((MedicationStatementDosageComponent) value); // MedicationStatementDosageComponent
1567          break;
1568        default: super.setProperty(hash, name, value);
1569        }
1570
1571      }
1572
1573      @Override
1574      public void setProperty(String name, Base value) throws FHIRException {
1575        if (name.equals("identifier"))
1576          this.getIdentifier().add(castToIdentifier(value));
1577        else if (name.equals("status"))
1578          this.status = new MedicationStatementStatusEnumFactory().fromType(value); // Enumeration<MedicationStatementStatus>
1579        else if (name.equals("medication[x]"))
1580          this.medication = (Type) value; // Type
1581        else if (name.equals("patient"))
1582          this.patient = castToReference(value); // Reference
1583        else if (name.equals("effective[x]"))
1584          this.effective = (Type) value; // Type
1585        else if (name.equals("informationSource"))
1586          this.informationSource = castToReference(value); // Reference
1587        else if (name.equals("supportingInformation"))
1588          this.getSupportingInformation().add(castToReference(value));
1589        else if (name.equals("dateAsserted"))
1590          this.dateAsserted = castToDateTime(value); // DateTimeType
1591        else if (name.equals("wasNotTaken"))
1592          this.wasNotTaken = castToBoolean(value); // BooleanType
1593        else if (name.equals("reasonNotTaken"))
1594          this.getReasonNotTaken().add(castToCodeableConcept(value));
1595        else if (name.equals("reasonForUse[x]"))
1596          this.reasonForUse = (Type) value; // Type
1597        else if (name.equals("note"))
1598          this.getNote().add(castToAnnotation(value));
1599        else if (name.equals("dosage"))
1600          this.getDosage().add((MedicationStatementDosageComponent) value);
1601        else
1602          super.setProperty(name, value);
1603      }
1604
1605      @Override
1606      public Base makeProperty(int hash, String name) throws FHIRException {
1607        switch (hash) {
1608        case -1618432855:  return addIdentifier(); // Identifier
1609        case -892481550: throw new FHIRException("Cannot make property status as it is not a complex type"); // Enumeration<MedicationStatementStatus>
1610        case 1458402129:  return getMedication(); // Type
1611        case -791418107:  return getPatient(); // Reference
1612        case 247104889:  return getEffective(); // Type
1613        case -2123220889:  return getInformationSource(); // Reference
1614        case -1248768647:  return addSupportingInformation(); // Reference
1615        case -1980855245: throw new FHIRException("Cannot make property dateAsserted as it is not a complex type"); // DateTimeType
1616        case -1039154243: throw new FHIRException("Cannot make property wasNotTaken as it is not a complex type"); // BooleanType
1617        case 2112880664:  return addReasonNotTaken(); // CodeableConcept
1618        case 919582174:  return getReasonForUse(); // Type
1619        case 3387378:  return addNote(); // Annotation
1620        case -1326018889:  return addDosage(); // MedicationStatementDosageComponent
1621        default: return super.makeProperty(hash, name);
1622        }
1623
1624      }
1625
1626      @Override
1627      public Base addChild(String name) throws FHIRException {
1628        if (name.equals("identifier")) {
1629          return addIdentifier();
1630        }
1631        else if (name.equals("status")) {
1632          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.status");
1633        }
1634        else if (name.equals("medicationCodeableConcept")) {
1635          this.medication = new CodeableConcept();
1636          return this.medication;
1637        }
1638        else if (name.equals("medicationReference")) {
1639          this.medication = new Reference();
1640          return this.medication;
1641        }
1642        else if (name.equals("patient")) {
1643          this.patient = new Reference();
1644          return this.patient;
1645        }
1646        else if (name.equals("effectiveDateTime")) {
1647          this.effective = new DateTimeType();
1648          return this.effective;
1649        }
1650        else if (name.equals("effectivePeriod")) {
1651          this.effective = new Period();
1652          return this.effective;
1653        }
1654        else if (name.equals("informationSource")) {
1655          this.informationSource = new Reference();
1656          return this.informationSource;
1657        }
1658        else if (name.equals("supportingInformation")) {
1659          return addSupportingInformation();
1660        }
1661        else if (name.equals("dateAsserted")) {
1662          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.dateAsserted");
1663        }
1664        else if (name.equals("wasNotTaken")) {
1665          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.wasNotTaken");
1666        }
1667        else if (name.equals("reasonNotTaken")) {
1668          return addReasonNotTaken();
1669        }
1670        else if (name.equals("reasonForUseCodeableConcept")) {
1671          this.reasonForUse = new CodeableConcept();
1672          return this.reasonForUse;
1673        }
1674        else if (name.equals("reasonForUseReference")) {
1675          this.reasonForUse = new Reference();
1676          return this.reasonForUse;
1677        }
1678        else if (name.equals("note")) {
1679          return addNote();
1680        }
1681        else if (name.equals("dosage")) {
1682          return addDosage();
1683        }
1684        else
1685          return super.addChild(name);
1686      }
1687
1688  public String fhirType() {
1689    return "MedicationStatement";
1690
1691  }
1692
1693      public MedicationStatement copy() {
1694        MedicationStatement dst = new MedicationStatement();
1695        copyValues(dst);
1696        if (identifier != null) {
1697          dst.identifier = new ArrayList<Identifier>();
1698          for (Identifier i : identifier)
1699            dst.identifier.add(i.copy());
1700        };
1701        dst.status = status == null ? null : status.copy();
1702        dst.medication = medication == null ? null : medication.copy();
1703        dst.patient = patient == null ? null : patient.copy();
1704        dst.effective = effective == null ? null : effective.copy();
1705        dst.informationSource = informationSource == null ? null : informationSource.copy();
1706        if (supportingInformation != null) {
1707          dst.supportingInformation = new ArrayList<Reference>();
1708          for (Reference i : supportingInformation)
1709            dst.supportingInformation.add(i.copy());
1710        };
1711        dst.dateAsserted = dateAsserted == null ? null : dateAsserted.copy();
1712        dst.wasNotTaken = wasNotTaken == null ? null : wasNotTaken.copy();
1713        if (reasonNotTaken != null) {
1714          dst.reasonNotTaken = new ArrayList<CodeableConcept>();
1715          for (CodeableConcept i : reasonNotTaken)
1716            dst.reasonNotTaken.add(i.copy());
1717        };
1718        dst.reasonForUse = reasonForUse == null ? null : reasonForUse.copy();
1719        if (note != null) {
1720          dst.note = new ArrayList<Annotation>();
1721          for (Annotation i : note)
1722            dst.note.add(i.copy());
1723        };
1724        if (dosage != null) {
1725          dst.dosage = new ArrayList<MedicationStatementDosageComponent>();
1726          for (MedicationStatementDosageComponent i : dosage)
1727            dst.dosage.add(i.copy());
1728        };
1729        return dst;
1730      }
1731
1732      protected MedicationStatement typedCopy() {
1733        return copy();
1734      }
1735
1736      @Override
1737      public boolean equalsDeep(Base other) {
1738        if (!super.equalsDeep(other))
1739          return false;
1740        if (!(other instanceof MedicationStatement))
1741          return false;
1742        MedicationStatement o = (MedicationStatement) other;
1743        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(medication, o.medication, true)
1744           && compareDeep(patient, o.patient, true) && compareDeep(effective, o.effective, true) && compareDeep(informationSource, o.informationSource, true)
1745           && compareDeep(supportingInformation, o.supportingInformation, true) && compareDeep(dateAsserted, o.dateAsserted, true)
1746           && compareDeep(wasNotTaken, o.wasNotTaken, true) && compareDeep(reasonNotTaken, o.reasonNotTaken, true)
1747           && compareDeep(reasonForUse, o.reasonForUse, true) && compareDeep(note, o.note, true) && compareDeep(dosage, o.dosage, true)
1748          ;
1749      }
1750
1751      @Override
1752      public boolean equalsShallow(Base other) {
1753        if (!super.equalsShallow(other))
1754          return false;
1755        if (!(other instanceof MedicationStatement))
1756          return false;
1757        MedicationStatement o = (MedicationStatement) other;
1758        return compareValues(status, o.status, true) && compareValues(dateAsserted, o.dateAsserted, true) && compareValues(wasNotTaken, o.wasNotTaken, true)
1759          ;
1760      }
1761
1762      public boolean isEmpty() {
1763        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
1764           && (medication == null || medication.isEmpty()) && (patient == null || patient.isEmpty())
1765           && (effective == null || effective.isEmpty()) && (informationSource == null || informationSource.isEmpty())
1766           && (supportingInformation == null || supportingInformation.isEmpty()) && (dateAsserted == null || dateAsserted.isEmpty())
1767           && (wasNotTaken == null || wasNotTaken.isEmpty()) && (reasonNotTaken == null || reasonNotTaken.isEmpty())
1768           && (reasonForUse == null || reasonForUse.isEmpty()) && (note == null || note.isEmpty()) && (dosage == null || dosage.isEmpty())
1769          ;
1770      }
1771
1772  @Override
1773  public ResourceType getResourceType() {
1774    return ResourceType.MedicationStatement;
1775   }
1776
1777 /**
1778   * Search parameter: <b>medication</b>
1779   * <p>
1780   * Description: <b>Return administrations of this medication reference</b><br>
1781   * Type: <b>reference</b><br>
1782   * Path: <b>MedicationStatement.medicationReference</b><br>
1783   * </p>
1784   */
1785  @SearchParamDefinition(name="medication", path="MedicationStatement.medication.as(Reference)", description="Return administrations of this medication reference", type="reference" )
1786  public static final String SP_MEDICATION = "medication";
1787 /**
1788   * <b>Fluent Client</b> search parameter constant for <b>medication</b>
1789   * <p>
1790   * Description: <b>Return administrations of this medication reference</b><br>
1791   * Type: <b>reference</b><br>
1792   * Path: <b>MedicationStatement.medicationReference</b><br>
1793   * </p>
1794   */
1795  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam MEDICATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_MEDICATION);
1796
1797/**
1798   * Constant for fluent queries to be used to add include statements. Specifies
1799   * the path value of "<b>MedicationStatement:medication</b>".
1800   */
1801  public static final ca.uhn.fhir.model.api.Include INCLUDE_MEDICATION = new ca.uhn.fhir.model.api.Include("MedicationStatement:medication").toLocked();
1802
1803 /**
1804   * Search parameter: <b>patient</b>
1805   * <p>
1806   * Description: <b>The identity of a patient to list statements  for</b><br>
1807   * Type: <b>reference</b><br>
1808   * Path: <b>MedicationStatement.patient</b><br>
1809   * </p>
1810   */
1811  @SearchParamDefinition(name="patient", path="MedicationStatement.patient", description="The identity of a patient to list statements  for", type="reference" )
1812  public static final String SP_PATIENT = "patient";
1813 /**
1814   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
1815   * <p>
1816   * Description: <b>The identity of a patient to list statements  for</b><br>
1817   * Type: <b>reference</b><br>
1818   * Path: <b>MedicationStatement.patient</b><br>
1819   * </p>
1820   */
1821  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
1822
1823/**
1824   * Constant for fluent queries to be used to add include statements. Specifies
1825   * the path value of "<b>MedicationStatement:patient</b>".
1826   */
1827  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("MedicationStatement:patient").toLocked();
1828
1829 /**
1830   * Search parameter: <b>source</b>
1831   * <p>
1832   * Description: <b>Who the information in the statement came from</b><br>
1833   * Type: <b>reference</b><br>
1834   * Path: <b>MedicationStatement.informationSource</b><br>
1835   * </p>
1836   */
1837  @SearchParamDefinition(name="source", path="MedicationStatement.informationSource", description="Who the information in the statement came from", type="reference" )
1838  public static final String SP_SOURCE = "source";
1839 /**
1840   * <b>Fluent Client</b> search parameter constant for <b>source</b>
1841   * <p>
1842   * Description: <b>Who the information in the statement came from</b><br>
1843   * Type: <b>reference</b><br>
1844   * Path: <b>MedicationStatement.informationSource</b><br>
1845   * </p>
1846   */
1847  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SOURCE = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SOURCE);
1848
1849/**
1850   * Constant for fluent queries to be used to add include statements. Specifies
1851   * the path value of "<b>MedicationStatement:source</b>".
1852   */
1853  public static final ca.uhn.fhir.model.api.Include INCLUDE_SOURCE = new ca.uhn.fhir.model.api.Include("MedicationStatement:source").toLocked();
1854
1855 /**
1856   * Search parameter: <b>status</b>
1857   * <p>
1858   * Description: <b>Return statements that match the given status</b><br>
1859   * Type: <b>token</b><br>
1860   * Path: <b>MedicationStatement.status</b><br>
1861   * </p>
1862   */
1863  @SearchParamDefinition(name="status", path="MedicationStatement.status", description="Return statements that match the given status", type="token" )
1864  public static final String SP_STATUS = "status";
1865 /**
1866   * <b>Fluent Client</b> search parameter constant for <b>status</b>
1867   * <p>
1868   * Description: <b>Return statements that match the given status</b><br>
1869   * Type: <b>token</b><br>
1870   * Path: <b>MedicationStatement.status</b><br>
1871   * </p>
1872   */
1873  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_STATUS);
1874
1875 /**
1876   * Search parameter: <b>code</b>
1877   * <p>
1878   * Description: <b>Return administrations of this medication code</b><br>
1879   * Type: <b>token</b><br>
1880   * Path: <b>MedicationStatement.medicationCodeableConcept</b><br>
1881   * </p>
1882   */
1883  @SearchParamDefinition(name="code", path="MedicationStatement.medication.as(CodeableConcept)", description="Return administrations of this medication code", type="token" )
1884  public static final String SP_CODE = "code";
1885 /**
1886   * <b>Fluent Client</b> search parameter constant for <b>code</b>
1887   * <p>
1888   * Description: <b>Return administrations of this medication code</b><br>
1889   * Type: <b>token</b><br>
1890   * Path: <b>MedicationStatement.medicationCodeableConcept</b><br>
1891   * </p>
1892   */
1893  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CODE);
1894
1895 /**
1896   * Search parameter: <b>identifier</b>
1897   * <p>
1898   * Description: <b>Return statements with this external identifier</b><br>
1899   * Type: <b>token</b><br>
1900   * Path: <b>MedicationStatement.identifier</b><br>
1901   * </p>
1902   */
1903  @SearchParamDefinition(name="identifier", path="MedicationStatement.identifier", description="Return statements with this external identifier", type="token" )
1904  public static final String SP_IDENTIFIER = "identifier";
1905 /**
1906   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1907   * <p>
1908   * Description: <b>Return statements with this external identifier</b><br>
1909   * Type: <b>token</b><br>
1910   * Path: <b>MedicationStatement.identifier</b><br>
1911   * </p>
1912   */
1913  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
1914
1915 /**
1916   * Search parameter: <b>effective</b>
1917   * <p>
1918   * Description: <b>Date when patient was taking (or not taking) the medication</b><br>
1919   * Type: <b>date</b><br>
1920   * Path: <b>MedicationStatement.effective[x]</b><br>
1921   * </p>
1922   */
1923  @SearchParamDefinition(name="effective", path="MedicationStatement.effective", description="Date when patient was taking (or not taking) the medication", type="date" )
1924  public static final String SP_EFFECTIVE = "effective";
1925 /**
1926   * <b>Fluent Client</b> search parameter constant for <b>effective</b>
1927   * <p>
1928   * Description: <b>Date when patient was taking (or not taking) the medication</b><br>
1929   * Type: <b>date</b><br>
1930   * Path: <b>MedicationStatement.effective[x]</b><br>
1931   * </p>
1932   */
1933  public static final ca.uhn.fhir.rest.gclient.DateClientParam EFFECTIVE = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_EFFECTIVE);
1934
1935
1936}
1937