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