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