001package org.hl7.fhir.r5.model;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Tue, Dec 28, 2021 07:16+1100 for FHIR v5.0.0-snapshot1
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.utilities.Utilities;
038import org.hl7.fhir.r5.model.Enumerations.*;
039import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.instance.model.api.ICompositeType;
042import ca.uhn.fhir.model.api.annotation.Child;
043import ca.uhn.fhir.model.api.annotation.ChildOrder;
044import ca.uhn.fhir.model.api.annotation.DatatypeDef;
045import ca.uhn.fhir.model.api.annotation.Description;
046import ca.uhn.fhir.model.api.annotation.Block;
047
048/**
049 * Base StructureDefinition for Dosage Type: Indicates how the medication is/was taken or should be taken by the patient.
050 */
051@DatatypeDef(name="Dosage")
052public class Dosage extends BackboneType implements ICompositeType {
053
054    @Block()
055    public static class DosageDoseAndRateComponent extends Element implements IBaseDatatypeElement {
056        /**
057         * The kind of dose or rate specified, for example, ordered or calculated.
058         */
059        @Child(name = "type", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=true)
060        @Description(shortDefinition="The kind of dose or rate specified", formalDefinition="The kind of dose or rate specified, for example, ordered or calculated." )
061        @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/dose-rate-type")
062        protected CodeableConcept type;
063
064        /**
065         * Amount of medication per dose.
066         */
067        @Child(name = "dose", type = {Range.class, Quantity.class}, order=2, min=0, max=1, modifier=false, summary=true)
068        @Description(shortDefinition="Amount of medication per dose", formalDefinition="Amount of medication per dose." )
069        protected DataType dose;
070
071        /**
072         * Amount of medication per unit of time.
073         */
074        @Child(name = "rate", type = {Ratio.class, Range.class, Quantity.class}, order=3, min=0, max=1, modifier=false, summary=true)
075        @Description(shortDefinition="Amount of medication per unit of time", formalDefinition="Amount of medication per unit of time." )
076        protected DataType rate;
077
078        private static final long serialVersionUID = 230646604L;
079
080    /**
081     * Constructor
082     */
083      public DosageDoseAndRateComponent() {
084        super();
085      }
086
087        /**
088         * @return {@link #type} (The kind of dose or rate specified, for example, ordered or calculated.)
089         */
090        public CodeableConcept getType() { 
091          if (this.type == null)
092            if (Configuration.errorOnAutoCreate())
093              throw new Error("Attempt to auto-create DosageDoseAndRateComponent.type");
094            else if (Configuration.doAutoCreate())
095              this.type = new CodeableConcept(); // cc
096          return this.type;
097        }
098
099        public boolean hasType() { 
100          return this.type != null && !this.type.isEmpty();
101        }
102
103        /**
104         * @param value {@link #type} (The kind of dose or rate specified, for example, ordered or calculated.)
105         */
106        public DosageDoseAndRateComponent setType(CodeableConcept value) { 
107          this.type = value;
108          return this;
109        }
110
111        /**
112         * @return {@link #dose} (Amount of medication per dose.)
113         */
114        public DataType getDose() { 
115          return this.dose;
116        }
117
118        /**
119         * @return {@link #dose} (Amount of medication per dose.)
120         */
121        public Range getDoseRange() throws FHIRException { 
122          if (this.dose == null)
123            this.dose = new Range();
124          if (!(this.dose instanceof Range))
125            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.dose.getClass().getName()+" was encountered");
126          return (Range) this.dose;
127        }
128
129        public boolean hasDoseRange() { 
130          return this != null && this.dose instanceof Range;
131        }
132
133        /**
134         * @return {@link #dose} (Amount of medication per dose.)
135         */
136        public Quantity getDoseQuantity() throws FHIRException { 
137          if (this.dose == null)
138            this.dose = new Quantity();
139          if (!(this.dose instanceof Quantity))
140            throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.dose.getClass().getName()+" was encountered");
141          return (Quantity) this.dose;
142        }
143
144        public boolean hasDoseQuantity() { 
145          return this != null && this.dose instanceof Quantity;
146        }
147
148        public boolean hasDose() { 
149          return this.dose != null && !this.dose.isEmpty();
150        }
151
152        /**
153         * @param value {@link #dose} (Amount of medication per dose.)
154         */
155        public DosageDoseAndRateComponent setDose(DataType value) { 
156          if (value != null && !(value instanceof Range || value instanceof Quantity))
157            throw new Error("Not the right type for Dosage.doseAndRate.dose[x]: "+value.fhirType());
158          this.dose = value;
159          return this;
160        }
161
162        /**
163         * @return {@link #rate} (Amount of medication per unit of time.)
164         */
165        public DataType getRate() { 
166          return this.rate;
167        }
168
169        /**
170         * @return {@link #rate} (Amount of medication per unit of time.)
171         */
172        public Ratio getRateRatio() throws FHIRException { 
173          if (this.rate == null)
174            this.rate = new Ratio();
175          if (!(this.rate instanceof Ratio))
176            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
177          return (Ratio) this.rate;
178        }
179
180        public boolean hasRateRatio() { 
181          return this != null && this.rate instanceof Ratio;
182        }
183
184        /**
185         * @return {@link #rate} (Amount of medication per unit of time.)
186         */
187        public Range getRateRange() throws FHIRException { 
188          if (this.rate == null)
189            this.rate = new Range();
190          if (!(this.rate instanceof Range))
191            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
192          return (Range) this.rate;
193        }
194
195        public boolean hasRateRange() { 
196          return this != null && this.rate instanceof Range;
197        }
198
199        /**
200         * @return {@link #rate} (Amount of medication per unit of time.)
201         */
202        public Quantity getRateQuantity() throws FHIRException { 
203          if (this.rate == null)
204            this.rate = new Quantity();
205          if (!(this.rate instanceof Quantity))
206            throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.rate.getClass().getName()+" was encountered");
207          return (Quantity) this.rate;
208        }
209
210        public boolean hasRateQuantity() { 
211          return this != null && this.rate instanceof Quantity;
212        }
213
214        public boolean hasRate() { 
215          return this.rate != null && !this.rate.isEmpty();
216        }
217
218        /**
219         * @param value {@link #rate} (Amount of medication per unit of time.)
220         */
221        public DosageDoseAndRateComponent setRate(DataType value) { 
222          if (value != null && !(value instanceof Ratio || value instanceof Range || value instanceof Quantity))
223            throw new Error("Not the right type for Dosage.doseAndRate.rate[x]: "+value.fhirType());
224          this.rate = value;
225          return this;
226        }
227
228        protected void listChildren(List<Property> children) {
229          super.listChildren(children);
230          children.add(new Property("type", "CodeableConcept", "The kind of dose or rate specified, for example, ordered or calculated.", 0, 1, type));
231          children.add(new Property("dose[x]", "Range|Quantity", "Amount of medication per dose.", 0, 1, dose));
232          children.add(new Property("rate[x]", "Ratio|Range|Quantity", "Amount of medication per unit of time.", 0, 1, rate));
233        }
234
235        @Override
236        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
237          switch (_hash) {
238          case 3575610: /*type*/  return new Property("type", "CodeableConcept", "The kind of dose or rate specified, for example, ordered or calculated.", 0, 1, type);
239          case 1843195715: /*dose[x]*/  return new Property("dose[x]", "Range|Quantity", "Amount of medication per dose.", 0, 1, dose);
240          case 3089437: /*dose*/  return new Property("dose[x]", "Range|Quantity", "Amount of medication per dose.", 0, 1, dose);
241          case 1775578912: /*doseRange*/  return new Property("dose[x]", "Range", "Amount of medication per dose.", 0, 1, dose);
242          case -2083618872: /*doseQuantity*/  return new Property("dose[x]", "Quantity", "Amount of medication per dose.", 0, 1, dose);
243          case 983460768: /*rate[x]*/  return new Property("rate[x]", "Ratio|Range|Quantity", "Amount of medication per unit of time.", 0, 1, rate);
244          case 3493088: /*rate*/  return new Property("rate[x]", "Ratio|Range|Quantity", "Amount of medication per unit of time.", 0, 1, rate);
245          case 204021515: /*rateRatio*/  return new Property("rate[x]", "Ratio", "Amount of medication per unit of time.", 0, 1, rate);
246          case 204015677: /*rateRange*/  return new Property("rate[x]", "Range", "Amount of medication per unit of time.", 0, 1, rate);
247          case -1085459061: /*rateQuantity*/  return new Property("rate[x]", "Quantity", "Amount of medication per unit of time.", 0, 1, rate);
248          default: return super.getNamedProperty(_hash, _name, _checkValid);
249          }
250
251        }
252
253      @Override
254      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
255        switch (hash) {
256        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // CodeableConcept
257        case 3089437: /*dose*/ return this.dose == null ? new Base[0] : new Base[] {this.dose}; // DataType
258        case 3493088: /*rate*/ return this.rate == null ? new Base[0] : new Base[] {this.rate}; // DataType
259        default: return super.getProperty(hash, name, checkValid);
260        }
261
262      }
263
264      @Override
265      public Base setProperty(int hash, String name, Base value) throws FHIRException {
266        switch (hash) {
267        case 3575610: // type
268          this.type = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
269          return value;
270        case 3089437: // dose
271          this.dose = TypeConvertor.castToType(value); // DataType
272          return value;
273        case 3493088: // rate
274          this.rate = TypeConvertor.castToType(value); // DataType
275          return value;
276        default: return super.setProperty(hash, name, value);
277        }
278
279      }
280
281      @Override
282      public Base setProperty(String name, Base value) throws FHIRException {
283        if (name.equals("type")) {
284          this.type = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
285        } else if (name.equals("dose[x]")) {
286          this.dose = TypeConvertor.castToType(value); // DataType
287        } else if (name.equals("rate[x]")) {
288          this.rate = TypeConvertor.castToType(value); // DataType
289        } else
290          return super.setProperty(name, value);
291        return value;
292      }
293
294      @Override
295      public Base makeProperty(int hash, String name) throws FHIRException {
296        switch (hash) {
297        case 3575610:  return getType();
298        case 1843195715:  return getDose();
299        case 3089437:  return getDose();
300        case 983460768:  return getRate();
301        case 3493088:  return getRate();
302        default: return super.makeProperty(hash, name);
303        }
304
305      }
306
307      @Override
308      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
309        switch (hash) {
310        case 3575610: /*type*/ return new String[] {"CodeableConcept"};
311        case 3089437: /*dose*/ return new String[] {"Range", "Quantity"};
312        case 3493088: /*rate*/ return new String[] {"Ratio", "Range", "Quantity"};
313        default: return super.getTypesForProperty(hash, name);
314        }
315
316      }
317
318      @Override
319      public Base addChild(String name) throws FHIRException {
320        if (name.equals("type")) {
321          this.type = new CodeableConcept();
322          return this.type;
323        }
324        else if (name.equals("doseRange")) {
325          this.dose = new Range();
326          return this.dose;
327        }
328        else if (name.equals("doseQuantity")) {
329          this.dose = new Quantity();
330          return this.dose;
331        }
332        else if (name.equals("rateRatio")) {
333          this.rate = new Ratio();
334          return this.rate;
335        }
336        else if (name.equals("rateRange")) {
337          this.rate = new Range();
338          return this.rate;
339        }
340        else if (name.equals("rateQuantity")) {
341          this.rate = new Quantity();
342          return this.rate;
343        }
344        else
345          return super.addChild(name);
346      }
347
348      public DosageDoseAndRateComponent copy() {
349        DosageDoseAndRateComponent dst = new DosageDoseAndRateComponent();
350        copyValues(dst);
351        return dst;
352      }
353
354      public void copyValues(DosageDoseAndRateComponent dst) {
355        super.copyValues(dst);
356        dst.type = type == null ? null : type.copy();
357        dst.dose = dose == null ? null : dose.copy();
358        dst.rate = rate == null ? null : rate.copy();
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 DataType 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 = {Quantity.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 Quantity maxDosePerAdministration;
481
482    /**
483     * Upper limit on medication per lifetime of the patient.
484     */
485    @Child(name = "maxDosePerLifetime", type = {Quantity.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 Quantity maxDosePerLifetime;
488
489    private static final long serialVersionUID = 1743553833L;
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 {3}
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 DataType 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        this.asNeeded = new BooleanType();
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        this.asNeeded = new CodeableConcept();
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(DataType 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 {3}
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 Quantity 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 Quantity(); // 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(Quantity 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 Quantity 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 Quantity(); // 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(Quantity 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", "Quantity", "Upper limit on medication per administration.", 0, 1, maxDosePerAdministration));
980        children.add(new Property("maxDosePerLifetime", "Quantity", "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", "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]", "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", "Quantity", "Upper limit on medication per administration.", 0, 1, maxDosePerAdministration);
1001        case 642099621: /*maxDosePerLifetime*/  return new Property("maxDosePerLifetime", "Quantity", "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}; // DataType
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}; // Quantity
1022        case 642099621: /*maxDosePerLifetime*/ return this.maxDosePerLifetime == null ? new Base[0] : new Base[] {this.maxDosePerLifetime}; // Quantity
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 = TypeConvertor.castToInteger(value); // IntegerType
1033          return value;
1034        case 3556653: // text
1035          this.text = TypeConvertor.castToString(value); // StringType
1036          return value;
1037        case 1623641575: // additionalInstruction
1038          this.getAdditionalInstruction().add(TypeConvertor.castToCodeableConcept(value)); // CodeableConcept
1039          return value;
1040        case 737543241: // patientInstruction
1041          this.patientInstruction = TypeConvertor.castToString(value); // StringType
1042          return value;
1043        case -873664438: // timing
1044          this.timing = TypeConvertor.castToTiming(value); // Timing
1045          return value;
1046        case -1432923513: // asNeeded
1047          this.asNeeded = TypeConvertor.castToType(value); // DataType
1048          return value;
1049        case 3530567: // site
1050          this.site = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1051          return value;
1052        case 108704329: // route
1053          this.route = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1054          return value;
1055        case -1077554975: // method
1056          this.method = TypeConvertor.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 = TypeConvertor.castToRatio(value); // Ratio
1063          return value;
1064        case 2004889914: // maxDosePerAdministration
1065          this.maxDosePerAdministration = TypeConvertor.castToQuantity(value); // Quantity
1066          return value;
1067        case 642099621: // maxDosePerLifetime
1068          this.maxDosePerLifetime = TypeConvertor.castToQuantity(value); // Quantity
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 = TypeConvertor.castToInteger(value); // IntegerType
1079        } else if (name.equals("text")) {
1080          this.text = TypeConvertor.castToString(value); // StringType
1081        } else if (name.equals("additionalInstruction")) {
1082          this.getAdditionalInstruction().add(TypeConvertor.castToCodeableConcept(value));
1083        } else if (name.equals("patientInstruction")) {
1084          this.patientInstruction = TypeConvertor.castToString(value); // StringType
1085        } else if (name.equals("timing")) {
1086          this.timing = TypeConvertor.castToTiming(value); // Timing
1087        } else if (name.equals("asNeeded[x]")) {
1088          this.asNeeded = TypeConvertor.castToType(value); // DataType
1089        } else if (name.equals("site")) {
1090          this.site = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1091        } else if (name.equals("route")) {
1092          this.route = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1093        } else if (name.equals("method")) {
1094          this.method = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1095        } else if (name.equals("doseAndRate")) {
1096          this.getDoseAndRate().add((DosageDoseAndRateComponent) value);
1097        } else if (name.equals("maxDosePerPeriod")) {
1098          this.maxDosePerPeriod = TypeConvertor.castToRatio(value); // Ratio
1099        } else if (name.equals("maxDosePerAdministration")) {
1100          this.maxDosePerAdministration = TypeConvertor.castToQuantity(value); // Quantity
1101        } else if (name.equals("maxDosePerLifetime")) {
1102          this.maxDosePerLifetime = TypeConvertor.castToQuantity(value); // Quantity
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[] {"Quantity"};
1145        case 642099621: /*maxDosePerLifetime*/ return new String[] {"Quantity"};
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 Quantity();
1198          return this.maxDosePerAdministration;
1199        }
1200        else if (name.equals("maxDosePerLifetime")) {
1201          this.maxDosePerLifetime = new Quantity();
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        return dst;
1217      }
1218
1219      public void copyValues(Dosage dst) {
1220        super.copyValues(dst);
1221        dst.sequence = sequence == null ? null : sequence.copy();
1222        dst.text = text == null ? null : text.copy();
1223        if (additionalInstruction != null) {
1224          dst.additionalInstruction = new ArrayList<CodeableConcept>();
1225          for (CodeableConcept i : additionalInstruction)
1226            dst.additionalInstruction.add(i.copy());
1227        };
1228        dst.patientInstruction = patientInstruction == null ? null : patientInstruction.copy();
1229        dst.timing = timing == null ? null : timing.copy();
1230        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
1231        dst.site = site == null ? null : site.copy();
1232        dst.route = route == null ? null : route.copy();
1233        dst.method = method == null ? null : method.copy();
1234        if (doseAndRate != null) {
1235          dst.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
1236          for (DosageDoseAndRateComponent i : doseAndRate)
1237            dst.doseAndRate.add(i.copy());
1238        };
1239        dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
1240        dst.maxDosePerAdministration = maxDosePerAdministration == null ? null : maxDosePerAdministration.copy();
1241        dst.maxDosePerLifetime = maxDosePerLifetime == null ? null : maxDosePerLifetime.copy();
1242      }
1243
1244      protected Dosage typedCopy() {
1245        return copy();
1246      }
1247
1248      @Override
1249      public boolean equalsDeep(Base other_) {
1250        if (!super.equalsDeep(other_))
1251          return false;
1252        if (!(other_ instanceof Dosage))
1253          return false;
1254        Dosage o = (Dosage) other_;
1255        return compareDeep(sequence, o.sequence, true) && compareDeep(text, o.text, true) && compareDeep(additionalInstruction, o.additionalInstruction, true)
1256           && compareDeep(patientInstruction, o.patientInstruction, true) && compareDeep(timing, o.timing, true)
1257           && compareDeep(asNeeded, o.asNeeded, true) && compareDeep(site, o.site, true) && compareDeep(route, o.route, true)
1258           && compareDeep(method, o.method, true) && compareDeep(doseAndRate, o.doseAndRate, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true)
1259           && compareDeep(maxDosePerAdministration, o.maxDosePerAdministration, true) && compareDeep(maxDosePerLifetime, o.maxDosePerLifetime, true)
1260          ;
1261      }
1262
1263      @Override
1264      public boolean equalsShallow(Base other_) {
1265        if (!super.equalsShallow(other_))
1266          return false;
1267        if (!(other_ instanceof Dosage))
1268          return false;
1269        Dosage o = (Dosage) other_;
1270        return compareValues(sequence, o.sequence, true) && compareValues(text, o.text, true) && compareValues(patientInstruction, o.patientInstruction, true)
1271          ;
1272      }
1273
1274      public boolean isEmpty() {
1275        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(sequence, text, additionalInstruction
1276          , patientInstruction, timing, asNeeded, site, route, method, doseAndRate, maxDosePerPeriod
1277          , maxDosePerAdministration, maxDosePerLifetime);
1278      }
1279
1280
1281}
1282