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