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