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