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