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