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