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.List;
035
036import org.hl7.fhir.exceptions.FHIRException;
037import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
038import org.hl7.fhir.instance.model.api.ICompositeType;
039import org.hl7.fhir.utilities.Utilities;
040
041import ca.uhn.fhir.model.api.annotation.Block;
042import ca.uhn.fhir.model.api.annotation.Child;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Description;
045
046/**
047 * Indicates how the medication is/was taken or should be taken by the patient.
048 */
049@DatatypeDef(name = "Dosage")
050public class Dosage extends BackboneType implements ICompositeType {
051
052  @Block()
053  public static class DosageDoseAndRateComponent extends Element implements IBaseDatatypeElement {
054    /**
055     * The kind of dose or rate specified, for example, ordered or calculated.
056     */
057    @Child(name = "type", type = {
058        CodeableConcept.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
059    @Description(shortDefinition = "The kind of dose or rate specified", formalDefinition = "The kind of dose or rate specified, for example, ordered or calculated.")
060    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/dose-rate-type")
061    protected CodeableConcept type;
062
063    /**
064     * Amount of medication per dose.
065     */
066    @Child(name = "dose", type = { Range.class,
067        Quantity.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
068    @Description(shortDefinition = "Amount of medication per dose", formalDefinition = "Amount of medication per dose.")
069    protected Type dose;
070
071    /**
072     * Amount of medication per unit of time.
073     */
074    @Child(name = "rate", type = { Ratio.class, Range.class,
075        Quantity.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
076    @Description(shortDefinition = "Amount of medication per unit of time", formalDefinition = "Amount of medication per unit of time.")
077    protected Type rate;
078
079    private static final long serialVersionUID = -2133698888L;
080
081    /**
082     * Constructor
083     */
084    public DosageDoseAndRateComponent() {
085      super();
086    }
087
088    /**
089     * @return {@link #type} (The kind of dose or rate specified, for example,
090     *         ordered or calculated.)
091     */
092    public CodeableConcept getType() {
093      if (this.type == null)
094        if (Configuration.errorOnAutoCreate())
095          throw new Error("Attempt to auto-create DosageDoseAndRateComponent.type");
096        else if (Configuration.doAutoCreate())
097          this.type = new CodeableConcept(); // cc
098      return this.type;
099    }
100
101    public boolean hasType() {
102      return this.type != null && !this.type.isEmpty();
103    }
104
105    /**
106     * @param value {@link #type} (The kind of dose or rate specified, for example,
107     *              ordered or calculated.)
108     */
109    public DosageDoseAndRateComponent setType(CodeableConcept value) {
110      this.type = value;
111      return this;
112    }
113
114    /**
115     * @return {@link #dose} (Amount of medication per dose.)
116     */
117    public Type getDose() {
118      return this.dose;
119    }
120
121    /**
122     * @return {@link #dose} (Amount of medication per dose.)
123     */
124    public Range getDoseRange() throws FHIRException {
125      if (this.dose == null)
126        this.dose = new Range();
127      if (!(this.dose instanceof Range))
128        throw new FHIRException(
129            "Type mismatch: the type Range was expected, but " + this.dose.getClass().getName() + " was encountered");
130      return (Range) this.dose;
131    }
132
133    public boolean hasDoseRange() {
134      return this != null && this.dose instanceof Range;
135    }
136
137    /**
138     * @return {@link #dose} (Amount of medication per dose.)
139     */
140    public Quantity getDoseQuantity() throws FHIRException {
141      if (this.dose == null)
142        this.dose = new Quantity();
143      if (!(this.dose instanceof Quantity))
144        throw new FHIRException("Type mismatch: the type Quantity was expected, but " + this.dose.getClass().getName()
145            + " was encountered");
146      return (Quantity) this.dose;
147    }
148
149    public boolean hasDoseQuantity() {
150      return this != null && this.dose instanceof Quantity;
151    }
152
153    public boolean hasDose() {
154      return this.dose != null && !this.dose.isEmpty();
155    }
156
157    /**
158     * @param value {@link #dose} (Amount of medication per dose.)
159     */
160    public DosageDoseAndRateComponent setDose(Type value) {
161      if (value != null && !(value instanceof Range || value instanceof Quantity))
162        throw new Error("Not the right type for Dosage.doseAndRate.dose[x]: " + value.fhirType());
163      this.dose = value;
164      return this;
165    }
166
167    /**
168     * @return {@link #rate} (Amount of medication per unit of time.)
169     */
170    public Type getRate() {
171      return this.rate;
172    }
173
174    /**
175     * @return {@link #rate} (Amount of medication per unit of time.)
176     */
177    public Ratio getRateRatio() throws FHIRException {
178      if (this.rate == null)
179        this.rate = new Ratio();
180      if (!(this.rate instanceof Ratio))
181        throw new FHIRException(
182            "Type mismatch: the type Ratio was expected, but " + this.rate.getClass().getName() + " was encountered");
183      return (Ratio) this.rate;
184    }
185
186    public boolean hasRateRatio() {
187      return this != null && this.rate instanceof Ratio;
188    }
189
190    /**
191     * @return {@link #rate} (Amount of medication per unit of time.)
192     */
193    public Range getRateRange() throws FHIRException {
194      if (this.rate == null)
195        this.rate = new Range();
196      if (!(this.rate instanceof Range))
197        throw new FHIRException(
198            "Type mismatch: the type Range was expected, but " + this.rate.getClass().getName() + " was encountered");
199      return (Range) this.rate;
200    }
201
202    public boolean hasRateRange() {
203      return this != null && this.rate instanceof Range;
204    }
205
206    /**
207     * @return {@link #rate} (Amount of medication per unit of time.)
208     */
209    public Quantity getRateQuantity() throws FHIRException {
210      if (this.rate == null)
211        this.rate = new Quantity();
212      if (!(this.rate instanceof Quantity))
213        throw new FHIRException("Type mismatch: the type Quantity was expected, but " + this.rate.getClass().getName()
214            + " was encountered");
215      return (Quantity) this.rate;
216    }
217
218    public boolean hasRateQuantity() {
219      return this != null && this.rate instanceof Quantity;
220    }
221
222    public boolean hasRate() {
223      return this.rate != null && !this.rate.isEmpty();
224    }
225
226    /**
227     * @param value {@link #rate} (Amount of medication per unit of time.)
228     */
229    public DosageDoseAndRateComponent setRate(Type value) {
230      if (value != null && !(value instanceof Ratio || value instanceof Range || value instanceof Quantity))
231        throw new Error("Not the right type for Dosage.doseAndRate.rate[x]: " + value.fhirType());
232      this.rate = value;
233      return this;
234    }
235
236    protected void listChildren(List<Property> children) {
237      super.listChildren(children);
238      children.add(new Property("type", "CodeableConcept",
239          "The kind of dose or rate specified, for example, ordered or calculated.", 0, 1, type));
240      children.add(new Property("dose[x]", "Range|SimpleQuantity", "Amount of medication per dose.", 0, 1, dose));
241      children.add(
242          new Property("rate[x]", "Ratio|Range|SimpleQuantity", "Amount of medication per unit of time.", 0, 1, rate));
243    }
244
245    @Override
246    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
247      switch (_hash) {
248      case 3575610:
249        /* type */ return new Property("type", "CodeableConcept",
250            "The kind of dose or rate specified, for example, ordered or calculated.", 0, 1, type);
251      case 1843195715:
252        /* dose[x] */ return new Property("dose[x]", "Range|SimpleQuantity", "Amount of medication per dose.", 0, 1,
253            dose);
254      case 3089437:
255        /* dose */ return new Property("dose[x]", "Range|SimpleQuantity", "Amount of medication per dose.", 0, 1, dose);
256      case 1775578912:
257        /* doseRange */ return new Property("dose[x]", "Range|SimpleQuantity", "Amount of medication per dose.", 0, 1,
258            dose);
259      case -2083618872:
260        /* doseQuantity */ return new Property("dose[x]", "Range|SimpleQuantity", "Amount of medication per dose.", 0,
261            1, dose);
262      case 983460768:
263        /* rate[x] */ return new Property("rate[x]", "Ratio|Range|SimpleQuantity",
264            "Amount of medication per unit of time.", 0, 1, rate);
265      case 3493088:
266        /* rate */ return new Property("rate[x]", "Ratio|Range|SimpleQuantity",
267            "Amount of medication per unit of time.", 0, 1, rate);
268      case 204021515:
269        /* rateRatio */ return new Property("rate[x]", "Ratio|Range|SimpleQuantity",
270            "Amount of medication per unit of time.", 0, 1, rate);
271      case 204015677:
272        /* rateRange */ return new Property("rate[x]", "Ratio|Range|SimpleQuantity",
273            "Amount of medication per unit of time.", 0, 1, rate);
274      case -1085459061:
275        /* rateQuantity */ return new Property("rate[x]", "Ratio|Range|SimpleQuantity",
276            "Amount of medication per unit of time.", 0, 1, rate);
277      default:
278        return super.getNamedProperty(_hash, _name, _checkValid);
279      }
280
281    }
282
283    @Override
284    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
285      switch (hash) {
286      case 3575610:
287        /* type */ return this.type == null ? new Base[0] : new Base[] { this.type }; // CodeableConcept
288      case 3089437:
289        /* dose */ return this.dose == null ? new Base[0] : new Base[] { this.dose }; // Type
290      case 3493088:
291        /* rate */ return this.rate == null ? new Base[0] : new Base[] { this.rate }; // Type
292      default:
293        return super.getProperty(hash, name, checkValid);
294      }
295
296    }
297
298    @Override
299    public Base setProperty(int hash, String name, Base value) throws FHIRException {
300      switch (hash) {
301      case 3575610: // type
302        this.type = castToCodeableConcept(value); // CodeableConcept
303        return value;
304      case 3089437: // dose
305        this.dose = castToType(value); // Type
306        return value;
307      case 3493088: // rate
308        this.rate = castToType(value); // Type
309        return value;
310      default:
311        return super.setProperty(hash, name, value);
312      }
313
314    }
315
316    @Override
317    public Base setProperty(String name, Base value) throws FHIRException {
318      if (name.equals("type")) {
319        this.type = castToCodeableConcept(value); // CodeableConcept
320      } else if (name.equals("dose[x]")) {
321        this.dose = castToType(value); // Type
322      } else if (name.equals("rate[x]")) {
323        this.rate = castToType(value); // Type
324      } else
325        return super.setProperty(name, value);
326      return value;
327    }
328
329    @Override
330    public Base makeProperty(int hash, String name) throws FHIRException {
331      switch (hash) {
332      case 3575610:
333        return getType();
334      case 1843195715:
335        return getDose();
336      case 3089437:
337        return getDose();
338      case 983460768:
339        return getRate();
340      case 3493088:
341        return getRate();
342      default:
343        return super.makeProperty(hash, name);
344      }
345
346    }
347
348    @Override
349    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
350      switch (hash) {
351      case 3575610:
352        /* type */ return new String[] { "CodeableConcept" };
353      case 3089437:
354        /* dose */ return new String[] { "Range", "SimpleQuantity" };
355      case 3493088:
356        /* rate */ return new String[] { "Ratio", "Range", "SimpleQuantity" };
357      default:
358        return super.getTypesForProperty(hash, name);
359      }
360
361    }
362
363    @Override
364    public Base addChild(String name) throws FHIRException {
365      if (name.equals("type")) {
366        this.type = new CodeableConcept();
367        return this.type;
368      } else if (name.equals("doseRange")) {
369        this.dose = new Range();
370        return this.dose;
371      } else if (name.equals("doseQuantity")) {
372        this.dose = new Quantity();
373        return this.dose;
374      } else if (name.equals("rateRatio")) {
375        this.rate = new Ratio();
376        return this.rate;
377      } else if (name.equals("rateRange")) {
378        this.rate = new Range();
379        return this.rate;
380      } else if (name.equals("rateQuantity")) {
381        this.rate = new Quantity();
382        return this.rate;
383      } else
384        return super.addChild(name);
385    }
386
387    public DosageDoseAndRateComponent copy() {
388      DosageDoseAndRateComponent dst = new DosageDoseAndRateComponent();
389      copyValues(dst);
390      return dst;
391    }
392
393    public void copyValues(DosageDoseAndRateComponent dst) {
394      super.copyValues(dst);
395      dst.type = type == null ? null : type.copy();
396      dst.dose = dose == null ? null : dose.copy();
397      dst.rate = rate == null ? null : rate.copy();
398    }
399
400    @Override
401    public boolean equalsDeep(Base other_) {
402      if (!super.equalsDeep(other_))
403        return false;
404      if (!(other_ instanceof DosageDoseAndRateComponent))
405        return false;
406      DosageDoseAndRateComponent o = (DosageDoseAndRateComponent) other_;
407      return compareDeep(type, o.type, true) && compareDeep(dose, o.dose, true) && compareDeep(rate, o.rate, true);
408    }
409
410    @Override
411    public boolean equalsShallow(Base other_) {
412      if (!super.equalsShallow(other_))
413        return false;
414      if (!(other_ instanceof DosageDoseAndRateComponent))
415        return false;
416      DosageDoseAndRateComponent o = (DosageDoseAndRateComponent) other_;
417      return true;
418    }
419
420    public boolean isEmpty() {
421      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, dose, rate);
422    }
423
424    public String fhirType() {
425      return "Dosage.doseAndRate";
426
427    }
428
429  }
430
431  /**
432   * Indicates the order in which the dosage instructions should be applied or
433   * interpreted.
434   */
435  @Child(name = "sequence", type = { IntegerType.class }, order = 0, min = 0, max = 1, modifier = false, summary = true)
436  @Description(shortDefinition = "The order of the dosage instructions", formalDefinition = "Indicates the order in which the dosage instructions should be applied or interpreted.")
437  protected IntegerType sequence;
438
439  /**
440   * Free text dosage instructions e.g. SIG.
441   */
442  @Child(name = "text", type = { StringType.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
443  @Description(shortDefinition = "Free text dosage instructions e.g. SIG", formalDefinition = "Free text dosage instructions e.g. SIG.")
444  protected StringType text;
445
446  /**
447   * Supplemental instructions to the patient on how to take the medication (e.g.
448   * "with meals" or"take half to one hour before food") or warnings for the
449   * patient about the medication (e.g. "may cause drowsiness" or "avoid exposure
450   * of skin to direct sunlight or sunlamps").
451   */
452  @Child(name = "additionalInstruction", type = {
453      CodeableConcept.class }, order = 2, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
454  @Description(shortDefinition = "Supplemental instruction or warnings to the patient - e.g. \"with meals\", \"may cause drowsiness\"", formalDefinition = "Supplemental instructions to the patient on how to take the medication  (e.g. \"with meals\" or\"take half to one hour before food\") or warnings for the patient about the medication (e.g. \"may cause drowsiness\" or \"avoid exposure of skin to direct sunlight or sunlamps\").")
455  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/additional-instruction-codes")
456  protected List<CodeableConcept> additionalInstruction;
457
458  /**
459   * Instructions in terms that are understood by the patient or consumer.
460   */
461  @Child(name = "patientInstruction", type = {
462      StringType.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
463  @Description(shortDefinition = "Patient or consumer oriented instructions", formalDefinition = "Instructions in terms that are understood by the patient or consumer.")
464  protected StringType patientInstruction;
465
466  /**
467   * When medication should be administered.
468   */
469  @Child(name = "timing", type = { Timing.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
470  @Description(shortDefinition = "When medication should be administered", formalDefinition = "When medication should be administered.")
471  protected Timing timing;
472
473  /**
474   * Indicates whether the Medication is only taken when needed within a specific
475   * dosing schedule (Boolean option), or it indicates the precondition for taking
476   * the Medication (CodeableConcept).
477   */
478  @Child(name = "asNeeded", type = { BooleanType.class,
479      CodeableConcept.class }, order = 5, min = 0, max = 1, modifier = false, summary = true)
480  @Description(shortDefinition = "Take \"as needed\" (for x)", formalDefinition = "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).")
481  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/medication-as-needed-reason")
482  protected Type asNeeded;
483
484  /**
485   * Body site to administer to.
486   */
487  @Child(name = "site", type = { CodeableConcept.class }, order = 6, min = 0, max = 1, modifier = false, summary = true)
488  @Description(shortDefinition = "Body site to administer to", formalDefinition = "Body site to administer to.")
489  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/approach-site-codes")
490  protected CodeableConcept site;
491
492  /**
493   * How drug should enter body.
494   */
495  @Child(name = "route", type = {
496      CodeableConcept.class }, order = 7, min = 0, max = 1, modifier = false, summary = true)
497  @Description(shortDefinition = "How drug should enter body", formalDefinition = "How drug should enter body.")
498  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/route-codes")
499  protected CodeableConcept route;
500
501  /**
502   * Technique for administering medication.
503   */
504  @Child(name = "method", type = {
505      CodeableConcept.class }, order = 8, min = 0, max = 1, modifier = false, summary = true)
506  @Description(shortDefinition = "Technique for administering medication", formalDefinition = "Technique for administering medication.")
507  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/administration-method-codes")
508  protected CodeableConcept method;
509
510  /**
511   * The amount of medication administered.
512   */
513  @Child(name = "doseAndRate", type = {}, order = 9, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
514  @Description(shortDefinition = "Amount of medication administered", formalDefinition = "The amount of medication administered.")
515  protected List<DosageDoseAndRateComponent> doseAndRate;
516
517  /**
518   * Upper limit on medication per unit of time.
519   */
520  @Child(name = "maxDosePerPeriod", type = {
521      Ratio.class }, order = 10, min = 0, max = 1, modifier = false, summary = true)
522  @Description(shortDefinition = "Upper limit on medication per unit of time", formalDefinition = "Upper limit on medication per unit of time.")
523  protected Ratio maxDosePerPeriod;
524
525  /**
526   * Upper limit on medication per administration.
527   */
528  @Child(name = "maxDosePerAdministration", type = {
529      Quantity.class }, order = 11, min = 0, max = 1, modifier = false, summary = true)
530  @Description(shortDefinition = "Upper limit on medication per administration", formalDefinition = "Upper limit on medication per administration.")
531  protected Quantity maxDosePerAdministration;
532
533  /**
534   * Upper limit on medication per lifetime of the patient.
535   */
536  @Child(name = "maxDosePerLifetime", type = {
537      Quantity.class }, order = 12, min = 0, max = 1, modifier = false, summary = true)
538  @Description(shortDefinition = "Upper limit on medication per lifetime of the patient", formalDefinition = "Upper limit on medication per lifetime of the patient.")
539  protected Quantity maxDosePerLifetime;
540
541  private static final long serialVersionUID = -1095063329L;
542
543  /**
544   * Constructor
545   */
546  public Dosage() {
547    super();
548  }
549
550  /**
551   * @return {@link #sequence} (Indicates the order in which the dosage
552   *         instructions should be applied or interpreted.). This is the
553   *         underlying object with id, value and extensions. The accessor
554   *         "getSequence" gives direct access to the value
555   */
556  public IntegerType getSequenceElement() {
557    if (this.sequence == null)
558      if (Configuration.errorOnAutoCreate())
559        throw new Error("Attempt to auto-create Dosage.sequence");
560      else if (Configuration.doAutoCreate())
561        this.sequence = new IntegerType(); // bb
562    return this.sequence;
563  }
564
565  public boolean hasSequenceElement() {
566    return this.sequence != null && !this.sequence.isEmpty();
567  }
568
569  public boolean hasSequence() {
570    return this.sequence != null && !this.sequence.isEmpty();
571  }
572
573  /**
574   * @param value {@link #sequence} (Indicates the order in which the dosage
575   *              instructions should be applied or interpreted.). This is the
576   *              underlying object with id, value and extensions. The accessor
577   *              "getSequence" gives direct access to the value
578   */
579  public Dosage setSequenceElement(IntegerType value) {
580    this.sequence = value;
581    return this;
582  }
583
584  /**
585   * @return Indicates the order in which the dosage instructions should be
586   *         applied or interpreted.
587   */
588  public int getSequence() {
589    return this.sequence == null || this.sequence.isEmpty() ? 0 : this.sequence.getValue();
590  }
591
592  /**
593   * @param value Indicates the order in which the dosage instructions should be
594   *              applied or interpreted.
595   */
596  public Dosage setSequence(int value) {
597    if (this.sequence == null)
598      this.sequence = new IntegerType();
599    this.sequence.setValue(value);
600    return this;
601  }
602
603  /**
604   * @return {@link #text} (Free text dosage instructions e.g. SIG.). This is the
605   *         underlying object with id, value and extensions. The accessor
606   *         "getText" gives direct access to the value
607   */
608  public StringType getTextElement() {
609    if (this.text == null)
610      if (Configuration.errorOnAutoCreate())
611        throw new Error("Attempt to auto-create Dosage.text");
612      else if (Configuration.doAutoCreate())
613        this.text = new StringType(); // bb
614    return this.text;
615  }
616
617  public boolean hasTextElement() {
618    return this.text != null && !this.text.isEmpty();
619  }
620
621  public boolean hasText() {
622    return this.text != null && !this.text.isEmpty();
623  }
624
625  /**
626   * @param value {@link #text} (Free text dosage instructions e.g. SIG.). This is
627   *              the underlying object with id, value and extensions. The
628   *              accessor "getText" gives direct access to the value
629   */
630  public Dosage setTextElement(StringType value) {
631    this.text = value;
632    return this;
633  }
634
635  /**
636   * @return Free text dosage instructions e.g. SIG.
637   */
638  public String getText() {
639    return this.text == null ? null : this.text.getValue();
640  }
641
642  /**
643   * @param value Free text dosage instructions e.g. SIG.
644   */
645  public Dosage setText(String value) {
646    if (Utilities.noString(value))
647      this.text = null;
648    else {
649      if (this.text == null)
650        this.text = new StringType();
651      this.text.setValue(value);
652    }
653    return this;
654  }
655
656  /**
657   * @return {@link #additionalInstruction} (Supplemental instructions to the
658   *         patient on how to take the medication (e.g. "with meals" or"take half
659   *         to one hour before food") or warnings for the patient about the
660   *         medication (e.g. "may cause drowsiness" or "avoid exposure of skin to
661   *         direct sunlight or sunlamps").)
662   */
663  public List<CodeableConcept> getAdditionalInstruction() {
664    if (this.additionalInstruction == null)
665      this.additionalInstruction = new ArrayList<CodeableConcept>();
666    return this.additionalInstruction;
667  }
668
669  /**
670   * @return Returns a reference to <code>this</code> for easy method chaining
671   */
672  public Dosage setAdditionalInstruction(List<CodeableConcept> theAdditionalInstruction) {
673    this.additionalInstruction = theAdditionalInstruction;
674    return this;
675  }
676
677  public boolean hasAdditionalInstruction() {
678    if (this.additionalInstruction == null)
679      return false;
680    for (CodeableConcept item : this.additionalInstruction)
681      if (!item.isEmpty())
682        return true;
683    return false;
684  }
685
686  public CodeableConcept addAdditionalInstruction() { // 3
687    CodeableConcept t = new CodeableConcept();
688    if (this.additionalInstruction == null)
689      this.additionalInstruction = new ArrayList<CodeableConcept>();
690    this.additionalInstruction.add(t);
691    return t;
692  }
693
694  public Dosage addAdditionalInstruction(CodeableConcept t) { // 3
695    if (t == null)
696      return this;
697    if (this.additionalInstruction == null)
698      this.additionalInstruction = new ArrayList<CodeableConcept>();
699    this.additionalInstruction.add(t);
700    return this;
701  }
702
703  /**
704   * @return The first repetition of repeating field
705   *         {@link #additionalInstruction}, creating it if it does not already
706   *         exist
707   */
708  public CodeableConcept getAdditionalInstructionFirstRep() {
709    if (getAdditionalInstruction().isEmpty()) {
710      addAdditionalInstruction();
711    }
712    return getAdditionalInstruction().get(0);
713  }
714
715  /**
716   * @return {@link #patientInstruction} (Instructions in terms that are
717   *         understood by the patient or consumer.). This is the underlying
718   *         object with id, value and extensions. The accessor
719   *         "getPatientInstruction" gives direct access to the value
720   */
721  public StringType getPatientInstructionElement() {
722    if (this.patientInstruction == null)
723      if (Configuration.errorOnAutoCreate())
724        throw new Error("Attempt to auto-create Dosage.patientInstruction");
725      else if (Configuration.doAutoCreate())
726        this.patientInstruction = new StringType(); // bb
727    return this.patientInstruction;
728  }
729
730  public boolean hasPatientInstructionElement() {
731    return this.patientInstruction != null && !this.patientInstruction.isEmpty();
732  }
733
734  public boolean hasPatientInstruction() {
735    return this.patientInstruction != null && !this.patientInstruction.isEmpty();
736  }
737
738  /**
739   * @param value {@link #patientInstruction} (Instructions in terms that are
740   *              understood by the patient or consumer.). This is the underlying
741   *              object with id, value and extensions. The accessor
742   *              "getPatientInstruction" gives direct access to the value
743   */
744  public Dosage setPatientInstructionElement(StringType value) {
745    this.patientInstruction = value;
746    return this;
747  }
748
749  /**
750   * @return Instructions in terms that are understood by the patient or consumer.
751   */
752  public String getPatientInstruction() {
753    return this.patientInstruction == null ? null : this.patientInstruction.getValue();
754  }
755
756  /**
757   * @param value Instructions in terms that are understood by the patient or
758   *              consumer.
759   */
760  public Dosage setPatientInstruction(String value) {
761    if (Utilities.noString(value))
762      this.patientInstruction = null;
763    else {
764      if (this.patientInstruction == null)
765        this.patientInstruction = new StringType();
766      this.patientInstruction.setValue(value);
767    }
768    return this;
769  }
770
771  /**
772   * @return {@link #timing} (When medication should be administered.)
773   */
774  public Timing getTiming() {
775    if (this.timing == null)
776      if (Configuration.errorOnAutoCreate())
777        throw new Error("Attempt to auto-create Dosage.timing");
778      else if (Configuration.doAutoCreate())
779        this.timing = new Timing(); // cc
780    return this.timing;
781  }
782
783  public boolean hasTiming() {
784    return this.timing != null && !this.timing.isEmpty();
785  }
786
787  /**
788   * @param value {@link #timing} (When medication should be administered.)
789   */
790  public Dosage setTiming(Timing value) {
791    this.timing = value;
792    return this;
793  }
794
795  /**
796   * @return {@link #asNeeded} (Indicates whether the Medication is only taken
797   *         when needed within a specific dosing schedule (Boolean option), or it
798   *         indicates the precondition for taking the Medication
799   *         (CodeableConcept).)
800   */
801  public Type getAsNeeded() {
802    return this.asNeeded;
803  }
804
805  /**
806   * @return {@link #asNeeded} (Indicates whether the Medication is only taken
807   *         when needed within a specific dosing schedule (Boolean option), or it
808   *         indicates the precondition for taking the Medication
809   *         (CodeableConcept).)
810   */
811  public BooleanType getAsNeededBooleanType() throws FHIRException {
812    if (this.asNeeded == null)
813      this.asNeeded = new BooleanType();
814    if (!(this.asNeeded instanceof BooleanType))
815      throw new FHIRException("Type mismatch: the type BooleanType was expected, but "
816          + this.asNeeded.getClass().getName() + " was encountered");
817    return (BooleanType) this.asNeeded;
818  }
819
820  public boolean hasAsNeededBooleanType() {
821    return this != null && this.asNeeded instanceof BooleanType;
822  }
823
824  /**
825   * @return {@link #asNeeded} (Indicates whether the Medication is only taken
826   *         when needed within a specific dosing schedule (Boolean option), or it
827   *         indicates the precondition for taking the Medication
828   *         (CodeableConcept).)
829   */
830  public CodeableConcept getAsNeededCodeableConcept() throws FHIRException {
831    if (this.asNeeded == null)
832      this.asNeeded = new CodeableConcept();
833    if (!(this.asNeeded instanceof CodeableConcept))
834      throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "
835          + this.asNeeded.getClass().getName() + " was encountered");
836    return (CodeableConcept) this.asNeeded;
837  }
838
839  public boolean hasAsNeededCodeableConcept() {
840    return this != null && this.asNeeded instanceof CodeableConcept;
841  }
842
843  public boolean hasAsNeeded() {
844    return this.asNeeded != null && !this.asNeeded.isEmpty();
845  }
846
847  /**
848   * @param value {@link #asNeeded} (Indicates whether the Medication is only
849   *              taken when needed within a specific dosing schedule (Boolean
850   *              option), or it indicates the precondition for taking the
851   *              Medication (CodeableConcept).)
852   */
853  public Dosage setAsNeeded(Type value) {
854    if (value != null && !(value instanceof BooleanType || value instanceof CodeableConcept))
855      throw new Error("Not the right type for Dosage.asNeeded[x]: " + value.fhirType());
856    this.asNeeded = value;
857    return this;
858  }
859
860  /**
861   * @return {@link #site} (Body site to administer to.)
862   */
863  public CodeableConcept getSite() {
864    if (this.site == null)
865      if (Configuration.errorOnAutoCreate())
866        throw new Error("Attempt to auto-create Dosage.site");
867      else if (Configuration.doAutoCreate())
868        this.site = new CodeableConcept(); // cc
869    return this.site;
870  }
871
872  public boolean hasSite() {
873    return this.site != null && !this.site.isEmpty();
874  }
875
876  /**
877   * @param value {@link #site} (Body site to administer to.)
878   */
879  public Dosage setSite(CodeableConcept value) {
880    this.site = value;
881    return this;
882  }
883
884  /**
885   * @return {@link #route} (How drug should enter body.)
886   */
887  public CodeableConcept getRoute() {
888    if (this.route == null)
889      if (Configuration.errorOnAutoCreate())
890        throw new Error("Attempt to auto-create Dosage.route");
891      else if (Configuration.doAutoCreate())
892        this.route = new CodeableConcept(); // cc
893    return this.route;
894  }
895
896  public boolean hasRoute() {
897    return this.route != null && !this.route.isEmpty();
898  }
899
900  /**
901   * @param value {@link #route} (How drug should enter body.)
902   */
903  public Dosage setRoute(CodeableConcept value) {
904    this.route = value;
905    return this;
906  }
907
908  /**
909   * @return {@link #method} (Technique for administering medication.)
910   */
911  public CodeableConcept getMethod() {
912    if (this.method == null)
913      if (Configuration.errorOnAutoCreate())
914        throw new Error("Attempt to auto-create Dosage.method");
915      else if (Configuration.doAutoCreate())
916        this.method = new CodeableConcept(); // cc
917    return this.method;
918  }
919
920  public boolean hasMethod() {
921    return this.method != null && !this.method.isEmpty();
922  }
923
924  /**
925   * @param value {@link #method} (Technique for administering medication.)
926   */
927  public Dosage setMethod(CodeableConcept value) {
928    this.method = value;
929    return this;
930  }
931
932  /**
933   * @return {@link #doseAndRate} (The amount of medication administered.)
934   */
935  public List<DosageDoseAndRateComponent> getDoseAndRate() {
936    if (this.doseAndRate == null)
937      this.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
938    return this.doseAndRate;
939  }
940
941  /**
942   * @return Returns a reference to <code>this</code> for easy method chaining
943   */
944  public Dosage setDoseAndRate(List<DosageDoseAndRateComponent> theDoseAndRate) {
945    this.doseAndRate = theDoseAndRate;
946    return this;
947  }
948
949  public boolean hasDoseAndRate() {
950    if (this.doseAndRate == null)
951      return false;
952    for (DosageDoseAndRateComponent item : this.doseAndRate)
953      if (!item.isEmpty())
954        return true;
955    return false;
956  }
957
958  public DosageDoseAndRateComponent addDoseAndRate() { // 3
959    DosageDoseAndRateComponent t = new DosageDoseAndRateComponent();
960    if (this.doseAndRate == null)
961      this.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
962    this.doseAndRate.add(t);
963    return t;
964  }
965
966  public Dosage addDoseAndRate(DosageDoseAndRateComponent t) { // 3
967    if (t == null)
968      return this;
969    if (this.doseAndRate == null)
970      this.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
971    this.doseAndRate.add(t);
972    return this;
973  }
974
975  /**
976   * @return The first repetition of repeating field {@link #doseAndRate},
977   *         creating it if it does not already exist
978   */
979  public DosageDoseAndRateComponent getDoseAndRateFirstRep() {
980    if (getDoseAndRate().isEmpty()) {
981      addDoseAndRate();
982    }
983    return getDoseAndRate().get(0);
984  }
985
986  /**
987   * @return {@link #maxDosePerPeriod} (Upper limit on medication per unit of
988   *         time.)
989   */
990  public Ratio getMaxDosePerPeriod() {
991    if (this.maxDosePerPeriod == null)
992      if (Configuration.errorOnAutoCreate())
993        throw new Error("Attempt to auto-create Dosage.maxDosePerPeriod");
994      else if (Configuration.doAutoCreate())
995        this.maxDosePerPeriod = new Ratio(); // cc
996    return this.maxDosePerPeriod;
997  }
998
999  public boolean hasMaxDosePerPeriod() {
1000    return this.maxDosePerPeriod != null && !this.maxDosePerPeriod.isEmpty();
1001  }
1002
1003  /**
1004   * @param value {@link #maxDosePerPeriod} (Upper limit on medication per unit of
1005   *              time.)
1006   */
1007  public Dosage setMaxDosePerPeriod(Ratio value) {
1008    this.maxDosePerPeriod = value;
1009    return this;
1010  }
1011
1012  /**
1013   * @return {@link #maxDosePerAdministration} (Upper limit on medication per
1014   *         administration.)
1015   */
1016  public Quantity getMaxDosePerAdministration() {
1017    if (this.maxDosePerAdministration == null)
1018      if (Configuration.errorOnAutoCreate())
1019        throw new Error("Attempt to auto-create Dosage.maxDosePerAdministration");
1020      else if (Configuration.doAutoCreate())
1021        this.maxDosePerAdministration = new Quantity(); // cc
1022    return this.maxDosePerAdministration;
1023  }
1024
1025  public boolean hasMaxDosePerAdministration() {
1026    return this.maxDosePerAdministration != null && !this.maxDosePerAdministration.isEmpty();
1027  }
1028
1029  /**
1030   * @param value {@link #maxDosePerAdministration} (Upper limit on medication per
1031   *              administration.)
1032   */
1033  public Dosage setMaxDosePerAdministration(Quantity value) {
1034    this.maxDosePerAdministration = value;
1035    return this;
1036  }
1037
1038  /**
1039   * @return {@link #maxDosePerLifetime} (Upper limit on medication per lifetime
1040   *         of the patient.)
1041   */
1042  public Quantity getMaxDosePerLifetime() {
1043    if (this.maxDosePerLifetime == null)
1044      if (Configuration.errorOnAutoCreate())
1045        throw new Error("Attempt to auto-create Dosage.maxDosePerLifetime");
1046      else if (Configuration.doAutoCreate())
1047        this.maxDosePerLifetime = new Quantity(); // cc
1048    return this.maxDosePerLifetime;
1049  }
1050
1051  public boolean hasMaxDosePerLifetime() {
1052    return this.maxDosePerLifetime != null && !this.maxDosePerLifetime.isEmpty();
1053  }
1054
1055  /**
1056   * @param value {@link #maxDosePerLifetime} (Upper limit on medication per
1057   *              lifetime of the patient.)
1058   */
1059  public Dosage setMaxDosePerLifetime(Quantity value) {
1060    this.maxDosePerLifetime = value;
1061    return this;
1062  }
1063
1064  protected void listChildren(List<Property> children) {
1065    super.listChildren(children);
1066    children.add(new Property("sequence", "integer",
1067        "Indicates the order in which the dosage instructions should be applied or interpreted.", 0, 1, sequence));
1068    children.add(new Property("text", "string", "Free text dosage instructions e.g. SIG.", 0, 1, text));
1069    children.add(new Property("additionalInstruction", "CodeableConcept",
1070        "Supplemental instructions to the patient on how to take the medication  (e.g. \"with meals\" or\"take half to one hour before food\") or warnings for the patient about the medication (e.g. \"may cause drowsiness\" or \"avoid exposure of skin to direct sunlight or sunlamps\").",
1071        0, java.lang.Integer.MAX_VALUE, additionalInstruction));
1072    children.add(new Property("patientInstruction", "string",
1073        "Instructions in terms that are understood by the patient or consumer.", 0, 1, patientInstruction));
1074    children.add(new Property("timing", "Timing", "When medication should be administered.", 0, 1, timing));
1075    children.add(new Property("asNeeded[x]", "boolean|CodeableConcept",
1076        "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).",
1077        0, 1, asNeeded));
1078    children.add(new Property("site", "CodeableConcept", "Body site to administer to.", 0, 1, site));
1079    children.add(new Property("route", "CodeableConcept", "How drug should enter body.", 0, 1, route));
1080    children.add(new Property("method", "CodeableConcept", "Technique for administering medication.", 0, 1, method));
1081    children.add(new Property("doseAndRate", "", "The amount of medication administered.", 0,
1082        java.lang.Integer.MAX_VALUE, doseAndRate));
1083    children.add(new Property("maxDosePerPeriod", "Ratio", "Upper limit on medication per unit of time.", 0, 1,
1084        maxDosePerPeriod));
1085    children.add(new Property("maxDosePerAdministration", "SimpleQuantity",
1086        "Upper limit on medication per administration.", 0, 1, maxDosePerAdministration));
1087    children.add(new Property("maxDosePerLifetime", "SimpleQuantity",
1088        "Upper limit on medication per lifetime of the patient.", 0, 1, maxDosePerLifetime));
1089  }
1090
1091  @Override
1092  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1093    switch (_hash) {
1094    case 1349547969:
1095      /* sequence */ return new Property("sequence", "integer",
1096          "Indicates the order in which the dosage instructions should be applied or interpreted.", 0, 1, sequence);
1097    case 3556653:
1098      /* text */ return new Property("text", "string", "Free text dosage instructions e.g. SIG.", 0, 1, text);
1099    case 1623641575:
1100      /* additionalInstruction */ return new Property("additionalInstruction", "CodeableConcept",
1101          "Supplemental instructions to the patient on how to take the medication  (e.g. \"with meals\" or\"take half to one hour before food\") or warnings for the patient about the medication (e.g. \"may cause drowsiness\" or \"avoid exposure of skin to direct sunlight or sunlamps\").",
1102          0, java.lang.Integer.MAX_VALUE, additionalInstruction);
1103    case 737543241:
1104      /* patientInstruction */ return new Property("patientInstruction", "string",
1105          "Instructions in terms that are understood by the patient or consumer.", 0, 1, patientInstruction);
1106    case -873664438:
1107      /* timing */ return new Property("timing", "Timing", "When medication should be administered.", 0, 1, timing);
1108    case -544329575:
1109      /* asNeeded[x] */ return new Property("asNeeded[x]", "boolean|CodeableConcept",
1110          "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).",
1111          0, 1, asNeeded);
1112    case -1432923513:
1113      /* asNeeded */ return new Property("asNeeded[x]", "boolean|CodeableConcept",
1114          "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).",
1115          0, 1, asNeeded);
1116    case -591717471:
1117      /* asNeededBoolean */ return new Property("asNeeded[x]", "boolean|CodeableConcept",
1118          "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).",
1119          0, 1, asNeeded);
1120    case 1556420122:
1121      /* asNeededCodeableConcept */ return new Property("asNeeded[x]", "boolean|CodeableConcept",
1122          "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).",
1123          0, 1, asNeeded);
1124    case 3530567:
1125      /* site */ return new Property("site", "CodeableConcept", "Body site to administer to.", 0, 1, site);
1126    case 108704329:
1127      /* route */ return new Property("route", "CodeableConcept", "How drug should enter body.", 0, 1, route);
1128    case -1077554975:
1129      /* method */ return new Property("method", "CodeableConcept", "Technique for administering medication.", 0, 1,
1130          method);
1131    case -611024774:
1132      /* doseAndRate */ return new Property("doseAndRate", "", "The amount of medication administered.", 0,
1133          java.lang.Integer.MAX_VALUE, doseAndRate);
1134    case 1506263709:
1135      /* maxDosePerPeriod */ return new Property("maxDosePerPeriod", "Ratio",
1136          "Upper limit on medication per unit of time.", 0, 1, maxDosePerPeriod);
1137    case 2004889914:
1138      /* maxDosePerAdministration */ return new Property("maxDosePerAdministration", "SimpleQuantity",
1139          "Upper limit on medication per administration.", 0, 1, maxDosePerAdministration);
1140    case 642099621:
1141      /* maxDosePerLifetime */ return new Property("maxDosePerLifetime", "SimpleQuantity",
1142          "Upper limit on medication per lifetime of the patient.", 0, 1, maxDosePerLifetime);
1143    default:
1144      return super.getNamedProperty(_hash, _name, _checkValid);
1145    }
1146
1147  }
1148
1149  @Override
1150  public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1151    switch (hash) {
1152    case 1349547969:
1153      /* sequence */ return this.sequence == null ? new Base[0] : new Base[] { this.sequence }; // IntegerType
1154    case 3556653:
1155      /* text */ return this.text == null ? new Base[0] : new Base[] { this.text }; // StringType
1156    case 1623641575:
1157      /* additionalInstruction */ return this.additionalInstruction == null ? new Base[0]
1158          : this.additionalInstruction.toArray(new Base[this.additionalInstruction.size()]); // CodeableConcept
1159    case 737543241:
1160      /* patientInstruction */ return this.patientInstruction == null ? new Base[0]
1161          : new Base[] { this.patientInstruction }; // StringType
1162    case -873664438:
1163      /* timing */ return this.timing == null ? new Base[0] : new Base[] { this.timing }; // Timing
1164    case -1432923513:
1165      /* asNeeded */ return this.asNeeded == null ? new Base[0] : new Base[] { this.asNeeded }; // Type
1166    case 3530567:
1167      /* site */ return this.site == null ? new Base[0] : new Base[] { this.site }; // CodeableConcept
1168    case 108704329:
1169      /* route */ return this.route == null ? new Base[0] : new Base[] { this.route }; // CodeableConcept
1170    case -1077554975:
1171      /* method */ return this.method == null ? new Base[0] : new Base[] { this.method }; // CodeableConcept
1172    case -611024774:
1173      /* doseAndRate */ return this.doseAndRate == null ? new Base[0]
1174          : this.doseAndRate.toArray(new Base[this.doseAndRate.size()]); // DosageDoseAndRateComponent
1175    case 1506263709:
1176      /* maxDosePerPeriod */ return this.maxDosePerPeriod == null ? new Base[0] : new Base[] { this.maxDosePerPeriod }; // Ratio
1177    case 2004889914:
1178      /* maxDosePerAdministration */ return this.maxDosePerAdministration == null ? new Base[0]
1179          : new Base[] { this.maxDosePerAdministration }; // Quantity
1180    case 642099621:
1181      /* maxDosePerLifetime */ return this.maxDosePerLifetime == null ? new Base[0]
1182          : new Base[] { this.maxDosePerLifetime }; // Quantity
1183    default:
1184      return super.getProperty(hash, name, checkValid);
1185    }
1186
1187  }
1188
1189  @Override
1190  public Base setProperty(int hash, String name, Base value) throws FHIRException {
1191    switch (hash) {
1192    case 1349547969: // sequence
1193      this.sequence = castToInteger(value); // IntegerType
1194      return value;
1195    case 3556653: // text
1196      this.text = castToString(value); // StringType
1197      return value;
1198    case 1623641575: // additionalInstruction
1199      this.getAdditionalInstruction().add(castToCodeableConcept(value)); // CodeableConcept
1200      return value;
1201    case 737543241: // patientInstruction
1202      this.patientInstruction = castToString(value); // StringType
1203      return value;
1204    case -873664438: // timing
1205      this.timing = castToTiming(value); // Timing
1206      return value;
1207    case -1432923513: // asNeeded
1208      this.asNeeded = castToType(value); // Type
1209      return value;
1210    case 3530567: // site
1211      this.site = castToCodeableConcept(value); // CodeableConcept
1212      return value;
1213    case 108704329: // route
1214      this.route = castToCodeableConcept(value); // CodeableConcept
1215      return value;
1216    case -1077554975: // method
1217      this.method = castToCodeableConcept(value); // CodeableConcept
1218      return value;
1219    case -611024774: // doseAndRate
1220      this.getDoseAndRate().add((DosageDoseAndRateComponent) value); // DosageDoseAndRateComponent
1221      return value;
1222    case 1506263709: // maxDosePerPeriod
1223      this.maxDosePerPeriod = castToRatio(value); // Ratio
1224      return value;
1225    case 2004889914: // maxDosePerAdministration
1226      this.maxDosePerAdministration = castToQuantity(value); // Quantity
1227      return value;
1228    case 642099621: // maxDosePerLifetime
1229      this.maxDosePerLifetime = castToQuantity(value); // Quantity
1230      return value;
1231    default:
1232      return super.setProperty(hash, name, value);
1233    }
1234
1235  }
1236
1237  @Override
1238  public Base setProperty(String name, Base value) throws FHIRException {
1239    if (name.equals("sequence")) {
1240      this.sequence = castToInteger(value); // IntegerType
1241    } else if (name.equals("text")) {
1242      this.text = castToString(value); // StringType
1243    } else if (name.equals("additionalInstruction")) {
1244      this.getAdditionalInstruction().add(castToCodeableConcept(value));
1245    } else if (name.equals("patientInstruction")) {
1246      this.patientInstruction = castToString(value); // StringType
1247    } else if (name.equals("timing")) {
1248      this.timing = castToTiming(value); // Timing
1249    } else if (name.equals("asNeeded[x]")) {
1250      this.asNeeded = castToType(value); // Type
1251    } else if (name.equals("site")) {
1252      this.site = castToCodeableConcept(value); // CodeableConcept
1253    } else if (name.equals("route")) {
1254      this.route = castToCodeableConcept(value); // CodeableConcept
1255    } else if (name.equals("method")) {
1256      this.method = castToCodeableConcept(value); // CodeableConcept
1257    } else if (name.equals("doseAndRate")) {
1258      this.getDoseAndRate().add((DosageDoseAndRateComponent) value);
1259    } else if (name.equals("maxDosePerPeriod")) {
1260      this.maxDosePerPeriod = castToRatio(value); // Ratio
1261    } else if (name.equals("maxDosePerAdministration")) {
1262      this.maxDosePerAdministration = castToQuantity(value); // Quantity
1263    } else if (name.equals("maxDosePerLifetime")) {
1264      this.maxDosePerLifetime = castToQuantity(value); // Quantity
1265    } else
1266      return super.setProperty(name, value);
1267    return value;
1268  }
1269
1270  @Override
1271  public Base makeProperty(int hash, String name) throws FHIRException {
1272    switch (hash) {
1273    case 1349547969:
1274      return getSequenceElement();
1275    case 3556653:
1276      return getTextElement();
1277    case 1623641575:
1278      return addAdditionalInstruction();
1279    case 737543241:
1280      return getPatientInstructionElement();
1281    case -873664438:
1282      return getTiming();
1283    case -544329575:
1284      return getAsNeeded();
1285    case -1432923513:
1286      return getAsNeeded();
1287    case 3530567:
1288      return getSite();
1289    case 108704329:
1290      return getRoute();
1291    case -1077554975:
1292      return getMethod();
1293    case -611024774:
1294      return addDoseAndRate();
1295    case 1506263709:
1296      return getMaxDosePerPeriod();
1297    case 2004889914:
1298      return getMaxDosePerAdministration();
1299    case 642099621:
1300      return getMaxDosePerLifetime();
1301    default:
1302      return super.makeProperty(hash, name);
1303    }
1304
1305  }
1306
1307  @Override
1308  public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1309    switch (hash) {
1310    case 1349547969:
1311      /* sequence */ return new String[] { "integer" };
1312    case 3556653:
1313      /* text */ return new String[] { "string" };
1314    case 1623641575:
1315      /* additionalInstruction */ return new String[] { "CodeableConcept" };
1316    case 737543241:
1317      /* patientInstruction */ return new String[] { "string" };
1318    case -873664438:
1319      /* timing */ return new String[] { "Timing" };
1320    case -1432923513:
1321      /* asNeeded */ return new String[] { "boolean", "CodeableConcept" };
1322    case 3530567:
1323      /* site */ return new String[] { "CodeableConcept" };
1324    case 108704329:
1325      /* route */ return new String[] { "CodeableConcept" };
1326    case -1077554975:
1327      /* method */ return new String[] { "CodeableConcept" };
1328    case -611024774:
1329      /* doseAndRate */ return new String[] {};
1330    case 1506263709:
1331      /* maxDosePerPeriod */ return new String[] { "Ratio" };
1332    case 2004889914:
1333      /* maxDosePerAdministration */ return new String[] { "SimpleQuantity" };
1334    case 642099621:
1335      /* maxDosePerLifetime */ return new String[] { "SimpleQuantity" };
1336    default:
1337      return super.getTypesForProperty(hash, name);
1338    }
1339
1340  }
1341
1342  @Override
1343  public Base addChild(String name) throws FHIRException {
1344    if (name.equals("sequence")) {
1345      throw new FHIRException("Cannot call addChild on a singleton property Dosage.sequence");
1346    } else if (name.equals("text")) {
1347      throw new FHIRException("Cannot call addChild on a singleton property Dosage.text");
1348    } else if (name.equals("additionalInstruction")) {
1349      return addAdditionalInstruction();
1350    } else if (name.equals("patientInstruction")) {
1351      throw new FHIRException("Cannot call addChild on a singleton property Dosage.patientInstruction");
1352    } else if (name.equals("timing")) {
1353      this.timing = new Timing();
1354      return this.timing;
1355    } else if (name.equals("asNeededBoolean")) {
1356      this.asNeeded = new BooleanType();
1357      return this.asNeeded;
1358    } else if (name.equals("asNeededCodeableConcept")) {
1359      this.asNeeded = new CodeableConcept();
1360      return this.asNeeded;
1361    } else if (name.equals("site")) {
1362      this.site = new CodeableConcept();
1363      return this.site;
1364    } else if (name.equals("route")) {
1365      this.route = new CodeableConcept();
1366      return this.route;
1367    } else if (name.equals("method")) {
1368      this.method = new CodeableConcept();
1369      return this.method;
1370    } else if (name.equals("doseAndRate")) {
1371      return addDoseAndRate();
1372    } else if (name.equals("maxDosePerPeriod")) {
1373      this.maxDosePerPeriod = new Ratio();
1374      return this.maxDosePerPeriod;
1375    } else if (name.equals("maxDosePerAdministration")) {
1376      this.maxDosePerAdministration = new Quantity();
1377      return this.maxDosePerAdministration;
1378    } else if (name.equals("maxDosePerLifetime")) {
1379      this.maxDosePerLifetime = new Quantity();
1380      return this.maxDosePerLifetime;
1381    } else
1382      return super.addChild(name);
1383  }
1384
1385  public String fhirType() {
1386    return "Dosage";
1387
1388  }
1389
1390  public Dosage copy() {
1391    Dosage dst = new Dosage();
1392    copyValues(dst);
1393    return dst;
1394  }
1395
1396  public void copyValues(Dosage dst) {
1397    super.copyValues(dst);
1398    dst.sequence = sequence == null ? null : sequence.copy();
1399    dst.text = text == null ? null : text.copy();
1400    if (additionalInstruction != null) {
1401      dst.additionalInstruction = new ArrayList<CodeableConcept>();
1402      for (CodeableConcept i : additionalInstruction)
1403        dst.additionalInstruction.add(i.copy());
1404    }
1405    ;
1406    dst.patientInstruction = patientInstruction == null ? null : patientInstruction.copy();
1407    dst.timing = timing == null ? null : timing.copy();
1408    dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
1409    dst.site = site == null ? null : site.copy();
1410    dst.route = route == null ? null : route.copy();
1411    dst.method = method == null ? null : method.copy();
1412    if (doseAndRate != null) {
1413      dst.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
1414      for (DosageDoseAndRateComponent i : doseAndRate)
1415        dst.doseAndRate.add(i.copy());
1416    }
1417    ;
1418    dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
1419    dst.maxDosePerAdministration = maxDosePerAdministration == null ? null : maxDosePerAdministration.copy();
1420    dst.maxDosePerLifetime = maxDosePerLifetime == null ? null : maxDosePerLifetime.copy();
1421  }
1422
1423  protected Dosage typedCopy() {
1424    return copy();
1425  }
1426
1427  @Override
1428  public boolean equalsDeep(Base other_) {
1429    if (!super.equalsDeep(other_))
1430      return false;
1431    if (!(other_ instanceof Dosage))
1432      return false;
1433    Dosage o = (Dosage) other_;
1434    return compareDeep(sequence, o.sequence, true) && compareDeep(text, o.text, true)
1435        && compareDeep(additionalInstruction, o.additionalInstruction, true)
1436        && compareDeep(patientInstruction, o.patientInstruction, true) && compareDeep(timing, o.timing, true)
1437        && compareDeep(asNeeded, o.asNeeded, true) && compareDeep(site, o.site, true)
1438        && compareDeep(route, o.route, true) && compareDeep(method, o.method, true)
1439        && compareDeep(doseAndRate, o.doseAndRate, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true)
1440        && compareDeep(maxDosePerAdministration, o.maxDosePerAdministration, true)
1441        && compareDeep(maxDosePerLifetime, o.maxDosePerLifetime, true);
1442  }
1443
1444  @Override
1445  public boolean equalsShallow(Base other_) {
1446    if (!super.equalsShallow(other_))
1447      return false;
1448    if (!(other_ instanceof Dosage))
1449      return false;
1450    Dosage o = (Dosage) other_;
1451    return compareValues(sequence, o.sequence, true) && compareValues(text, o.text, true)
1452        && compareValues(patientInstruction, o.patientInstruction, true);
1453  }
1454
1455  public boolean isEmpty() {
1456    return super.isEmpty()
1457        && ca.uhn.fhir.util.ElementUtil.isEmpty(sequence, text, additionalInstruction, patientInstruction, timing,
1458            asNeeded, site, route, method, doseAndRate, maxDosePerPeriod, maxDosePerAdministration, maxDosePerLifetime);
1459  }
1460
1461}