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