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 Fri, Jul 15, 2022 11:20+1000 for FHIR v5.0.0-snapshot2
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).
431     */
432    @Child(name = "asNeeded", type = {BooleanType.class}, order=5, min=0, max=1, modifier=false, summary=true)
433    @Description(shortDefinition="Take \"as needed\"", formalDefinition="Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option)." )
434    protected BooleanType asNeeded;
435
436    /**
437     * Indicates whether the Medication is only taken based on a precondition for taking the Medication (CodeableConcept).
438     */
439    @Child(name = "asNeededFor", type = {CodeableConcept.class}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
440    @Description(shortDefinition="Take \"as needed\" (for x)", formalDefinition="Indicates whether the Medication is only taken based on a precondition for taking the Medication (CodeableConcept)." )
441    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-as-needed-reason")
442    protected List<CodeableConcept> asNeededFor;
443
444    /**
445     * Body site to administer to.
446     */
447    @Child(name = "site", type = {CodeableConcept.class}, order=7, min=0, max=1, modifier=false, summary=true)
448    @Description(shortDefinition="Body site to administer to", formalDefinition="Body site to administer to." )
449    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/approach-site-codes")
450    protected CodeableConcept site;
451
452    /**
453     * How drug should enter body.
454     */
455    @Child(name = "route", type = {CodeableConcept.class}, order=8, min=0, max=1, modifier=false, summary=true)
456    @Description(shortDefinition="How drug should enter body", formalDefinition="How drug should enter body." )
457    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/route-codes")
458    protected CodeableConcept route;
459
460    /**
461     * Technique for administering medication.
462     */
463    @Child(name = "method", type = {CodeableConcept.class}, order=9, min=0, max=1, modifier=false, summary=true)
464    @Description(shortDefinition="Technique for administering medication", formalDefinition="Technique for administering medication." )
465    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/administration-method-codes")
466    protected CodeableConcept method;
467
468    /**
469     * Depending on the resource,this is the amount of medication administered, to  be administered or typical amount to be administered.
470     */
471    @Child(name = "doseAndRate", type = {}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
472    @Description(shortDefinition="Amount of medication administered, to be administered or typical amount to be administered", formalDefinition="Depending on the resource,this is the amount of medication administered, to  be administered or typical amount to be administered." )
473    protected List<DosageDoseAndRateComponent> doseAndRate;
474
475    /**
476     * Upper limit on medication per unit of time.
477     */
478    @Child(name = "maxDosePerPeriod", type = {Ratio.class}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
479    @Description(shortDefinition="Upper limit on medication per unit of time", formalDefinition="Upper limit on medication per unit of time." )
480    protected List<Ratio> maxDosePerPeriod;
481
482    /**
483     * Upper limit on medication per administration.
484     */
485    @Child(name = "maxDosePerAdministration", type = {Quantity.class}, order=12, min=0, max=1, modifier=false, summary=true)
486    @Description(shortDefinition="Upper limit on medication per administration", formalDefinition="Upper limit on medication per administration." )
487    protected Quantity maxDosePerAdministration;
488
489    /**
490     * Upper limit on medication per lifetime of the patient.
491     */
492    @Child(name = "maxDosePerLifetime", type = {Quantity.class}, order=13, min=0, max=1, modifier=false, summary=true)
493    @Description(shortDefinition="Upper limit on medication per lifetime of the patient", formalDefinition="Upper limit on medication per lifetime of the patient." )
494    protected Quantity maxDosePerLifetime;
495
496    private static final long serialVersionUID = 386091152L;
497
498  /**
499   * Constructor
500   */
501    public Dosage() {
502      super();
503    }
504
505    /**
506     * @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
507     */
508    public IntegerType getSequenceElement() { 
509      if (this.sequence == null)
510        if (Configuration.errorOnAutoCreate())
511          throw new Error("Attempt to auto-create Dosage.sequence");
512        else if (Configuration.doAutoCreate())
513          this.sequence = new IntegerType(); // bb
514      return this.sequence;
515    }
516
517    public boolean hasSequenceElement() { 
518      return this.sequence != null && !this.sequence.isEmpty();
519    }
520
521    public boolean hasSequence() { 
522      return this.sequence != null && !this.sequence.isEmpty();
523    }
524
525    /**
526     * @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
527     */
528    public Dosage setSequenceElement(IntegerType value) { 
529      this.sequence = value;
530      return this;
531    }
532
533    /**
534     * @return Indicates the order in which the dosage instructions should be applied or interpreted.
535     */
536    public int getSequence() { 
537      return this.sequence == null || this.sequence.isEmpty() ? 0 : this.sequence.getValue();
538    }
539
540    /**
541     * @param value Indicates the order in which the dosage instructions should be applied or interpreted.
542     */
543    public Dosage setSequence(int value) { 
544        if (this.sequence == null)
545          this.sequence = new IntegerType();
546        this.sequence.setValue(value);
547      return this;
548    }
549
550    /**
551     * @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
552     */
553    public StringType getTextElement() { 
554      if (this.text == null)
555        if (Configuration.errorOnAutoCreate())
556          throw new Error("Attempt to auto-create Dosage.text");
557        else if (Configuration.doAutoCreate())
558          this.text = new StringType(); // bb
559      return this.text;
560    }
561
562    public boolean hasTextElement() { 
563      return this.text != null && !this.text.isEmpty();
564    }
565
566    public boolean hasText() { 
567      return this.text != null && !this.text.isEmpty();
568    }
569
570    /**
571     * @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
572     */
573    public Dosage setTextElement(StringType value) { 
574      this.text = value;
575      return this;
576    }
577
578    /**
579     * @return Free text dosage instructions e.g. SIG.
580     */
581    public String getText() { 
582      return this.text == null ? null : this.text.getValue();
583    }
584
585    /**
586     * @param value Free text dosage instructions e.g. SIG.
587     */
588    public Dosage setText(String value) { 
589      if (Utilities.noString(value))
590        this.text = null;
591      else {
592        if (this.text == null)
593          this.text = new StringType();
594        this.text.setValue(value);
595      }
596      return this;
597    }
598
599    /**
600     * @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").)
601     */
602    public List<CodeableConcept> getAdditionalInstruction() { 
603      if (this.additionalInstruction == null)
604        this.additionalInstruction = new ArrayList<CodeableConcept>();
605      return this.additionalInstruction;
606    }
607
608    /**
609     * @return Returns a reference to <code>this</code> for easy method chaining
610     */
611    public Dosage setAdditionalInstruction(List<CodeableConcept> theAdditionalInstruction) { 
612      this.additionalInstruction = theAdditionalInstruction;
613      return this;
614    }
615
616    public boolean hasAdditionalInstruction() { 
617      if (this.additionalInstruction == null)
618        return false;
619      for (CodeableConcept item : this.additionalInstruction)
620        if (!item.isEmpty())
621          return true;
622      return false;
623    }
624
625    public CodeableConcept addAdditionalInstruction() { //3
626      CodeableConcept t = new CodeableConcept();
627      if (this.additionalInstruction == null)
628        this.additionalInstruction = new ArrayList<CodeableConcept>();
629      this.additionalInstruction.add(t);
630      return t;
631    }
632
633    public Dosage addAdditionalInstruction(CodeableConcept t) { //3
634      if (t == null)
635        return this;
636      if (this.additionalInstruction == null)
637        this.additionalInstruction = new ArrayList<CodeableConcept>();
638      this.additionalInstruction.add(t);
639      return this;
640    }
641
642    /**
643     * @return The first repetition of repeating field {@link #additionalInstruction}, creating it if it does not already exist {3}
644     */
645    public CodeableConcept getAdditionalInstructionFirstRep() { 
646      if (getAdditionalInstruction().isEmpty()) {
647        addAdditionalInstruction();
648      }
649      return getAdditionalInstruction().get(0);
650    }
651
652    /**
653     * @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
654     */
655    public StringType getPatientInstructionElement() { 
656      if (this.patientInstruction == null)
657        if (Configuration.errorOnAutoCreate())
658          throw new Error("Attempt to auto-create Dosage.patientInstruction");
659        else if (Configuration.doAutoCreate())
660          this.patientInstruction = new StringType(); // bb
661      return this.patientInstruction;
662    }
663
664    public boolean hasPatientInstructionElement() { 
665      return this.patientInstruction != null && !this.patientInstruction.isEmpty();
666    }
667
668    public boolean hasPatientInstruction() { 
669      return this.patientInstruction != null && !this.patientInstruction.isEmpty();
670    }
671
672    /**
673     * @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
674     */
675    public Dosage setPatientInstructionElement(StringType value) { 
676      this.patientInstruction = value;
677      return this;
678    }
679
680    /**
681     * @return Instructions in terms that are understood by the patient or consumer.
682     */
683    public String getPatientInstruction() { 
684      return this.patientInstruction == null ? null : this.patientInstruction.getValue();
685    }
686
687    /**
688     * @param value Instructions in terms that are understood by the patient or consumer.
689     */
690    public Dosage setPatientInstruction(String value) { 
691      if (Utilities.noString(value))
692        this.patientInstruction = null;
693      else {
694        if (this.patientInstruction == null)
695          this.patientInstruction = new StringType();
696        this.patientInstruction.setValue(value);
697      }
698      return this;
699    }
700
701    /**
702     * @return {@link #timing} (When medication should be administered.)
703     */
704    public Timing getTiming() { 
705      if (this.timing == null)
706        if (Configuration.errorOnAutoCreate())
707          throw new Error("Attempt to auto-create Dosage.timing");
708        else if (Configuration.doAutoCreate())
709          this.timing = new Timing(); // cc
710      return this.timing;
711    }
712
713    public boolean hasTiming() { 
714      return this.timing != null && !this.timing.isEmpty();
715    }
716
717    /**
718     * @param value {@link #timing} (When medication should be administered.)
719     */
720    public Dosage setTiming(Timing value) { 
721      this.timing = value;
722      return this;
723    }
724
725    /**
726     * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).). This is the underlying object with id, value and extensions. The accessor "getAsNeeded" gives direct access to the value
727     */
728    public BooleanType getAsNeededElement() { 
729      if (this.asNeeded == null)
730        if (Configuration.errorOnAutoCreate())
731          throw new Error("Attempt to auto-create Dosage.asNeeded");
732        else if (Configuration.doAutoCreate())
733          this.asNeeded = new BooleanType(); // bb
734      return this.asNeeded;
735    }
736
737    public boolean hasAsNeededElement() { 
738      return this.asNeeded != null && !this.asNeeded.isEmpty();
739    }
740
741    public boolean hasAsNeeded() { 
742      return this.asNeeded != null && !this.asNeeded.isEmpty();
743    }
744
745    /**
746     * @param value {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).). This is the underlying object with id, value and extensions. The accessor "getAsNeeded" gives direct access to the value
747     */
748    public Dosage setAsNeededElement(BooleanType value) { 
749      this.asNeeded = value;
750      return this;
751    }
752
753    /**
754     * @return Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).
755     */
756    public boolean getAsNeeded() { 
757      return this.asNeeded == null || this.asNeeded.isEmpty() ? false : this.asNeeded.getValue();
758    }
759
760    /**
761     * @param value Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).
762     */
763    public Dosage setAsNeeded(boolean value) { 
764        if (this.asNeeded == null)
765          this.asNeeded = new BooleanType();
766        this.asNeeded.setValue(value);
767      return this;
768    }
769
770    /**
771     * @return {@link #asNeededFor} (Indicates whether the Medication is only taken based on a precondition for taking the Medication (CodeableConcept).)
772     */
773    public List<CodeableConcept> getAsNeededFor() { 
774      if (this.asNeededFor == null)
775        this.asNeededFor = new ArrayList<CodeableConcept>();
776      return this.asNeededFor;
777    }
778
779    /**
780     * @return Returns a reference to <code>this</code> for easy method chaining
781     */
782    public Dosage setAsNeededFor(List<CodeableConcept> theAsNeededFor) { 
783      this.asNeededFor = theAsNeededFor;
784      return this;
785    }
786
787    public boolean hasAsNeededFor() { 
788      if (this.asNeededFor == null)
789        return false;
790      for (CodeableConcept item : this.asNeededFor)
791        if (!item.isEmpty())
792          return true;
793      return false;
794    }
795
796    public CodeableConcept addAsNeededFor() { //3
797      CodeableConcept t = new CodeableConcept();
798      if (this.asNeededFor == null)
799        this.asNeededFor = new ArrayList<CodeableConcept>();
800      this.asNeededFor.add(t);
801      return t;
802    }
803
804    public Dosage addAsNeededFor(CodeableConcept t) { //3
805      if (t == null)
806        return this;
807      if (this.asNeededFor == null)
808        this.asNeededFor = new ArrayList<CodeableConcept>();
809      this.asNeededFor.add(t);
810      return this;
811    }
812
813    /**
814     * @return The first repetition of repeating field {@link #asNeededFor}, creating it if it does not already exist {3}
815     */
816    public CodeableConcept getAsNeededForFirstRep() { 
817      if (getAsNeededFor().isEmpty()) {
818        addAsNeededFor();
819      }
820      return getAsNeededFor().get(0);
821    }
822
823    /**
824     * @return {@link #site} (Body site to administer to.)
825     */
826    public CodeableConcept getSite() { 
827      if (this.site == null)
828        if (Configuration.errorOnAutoCreate())
829          throw new Error("Attempt to auto-create Dosage.site");
830        else if (Configuration.doAutoCreate())
831          this.site = new CodeableConcept(); // cc
832      return this.site;
833    }
834
835    public boolean hasSite() { 
836      return this.site != null && !this.site.isEmpty();
837    }
838
839    /**
840     * @param value {@link #site} (Body site to administer to.)
841     */
842    public Dosage setSite(CodeableConcept value) { 
843      this.site = value;
844      return this;
845    }
846
847    /**
848     * @return {@link #route} (How drug should enter body.)
849     */
850    public CodeableConcept getRoute() { 
851      if (this.route == null)
852        if (Configuration.errorOnAutoCreate())
853          throw new Error("Attempt to auto-create Dosage.route");
854        else if (Configuration.doAutoCreate())
855          this.route = new CodeableConcept(); // cc
856      return this.route;
857    }
858
859    public boolean hasRoute() { 
860      return this.route != null && !this.route.isEmpty();
861    }
862
863    /**
864     * @param value {@link #route} (How drug should enter body.)
865     */
866    public Dosage setRoute(CodeableConcept value) { 
867      this.route = value;
868      return this;
869    }
870
871    /**
872     * @return {@link #method} (Technique for administering medication.)
873     */
874    public CodeableConcept getMethod() { 
875      if (this.method == null)
876        if (Configuration.errorOnAutoCreate())
877          throw new Error("Attempt to auto-create Dosage.method");
878        else if (Configuration.doAutoCreate())
879          this.method = new CodeableConcept(); // cc
880      return this.method;
881    }
882
883    public boolean hasMethod() { 
884      return this.method != null && !this.method.isEmpty();
885    }
886
887    /**
888     * @param value {@link #method} (Technique for administering medication.)
889     */
890    public Dosage setMethod(CodeableConcept value) { 
891      this.method = value;
892      return this;
893    }
894
895    /**
896     * @return {@link #doseAndRate} (Depending on the resource,this is the amount of medication administered, to  be administered or typical amount to be administered.)
897     */
898    public List<DosageDoseAndRateComponent> getDoseAndRate() { 
899      if (this.doseAndRate == null)
900        this.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
901      return this.doseAndRate;
902    }
903
904    /**
905     * @return Returns a reference to <code>this</code> for easy method chaining
906     */
907    public Dosage setDoseAndRate(List<DosageDoseAndRateComponent> theDoseAndRate) { 
908      this.doseAndRate = theDoseAndRate;
909      return this;
910    }
911
912    public boolean hasDoseAndRate() { 
913      if (this.doseAndRate == null)
914        return false;
915      for (DosageDoseAndRateComponent item : this.doseAndRate)
916        if (!item.isEmpty())
917          return true;
918      return false;
919    }
920
921    public DosageDoseAndRateComponent addDoseAndRate() { //3
922      DosageDoseAndRateComponent t = new DosageDoseAndRateComponent();
923      if (this.doseAndRate == null)
924        this.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
925      this.doseAndRate.add(t);
926      return t;
927    }
928
929    public Dosage addDoseAndRate(DosageDoseAndRateComponent t) { //3
930      if (t == null)
931        return this;
932      if (this.doseAndRate == null)
933        this.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
934      this.doseAndRate.add(t);
935      return this;
936    }
937
938    /**
939     * @return The first repetition of repeating field {@link #doseAndRate}, creating it if it does not already exist {3}
940     */
941    public DosageDoseAndRateComponent getDoseAndRateFirstRep() { 
942      if (getDoseAndRate().isEmpty()) {
943        addDoseAndRate();
944      }
945      return getDoseAndRate().get(0);
946    }
947
948    /**
949     * @return {@link #maxDosePerPeriod} (Upper limit on medication per unit of time.)
950     */
951    public List<Ratio> getMaxDosePerPeriod() { 
952      if (this.maxDosePerPeriod == null)
953        this.maxDosePerPeriod = new ArrayList<Ratio>();
954      return this.maxDosePerPeriod;
955    }
956
957    /**
958     * @return Returns a reference to <code>this</code> for easy method chaining
959     */
960    public Dosage setMaxDosePerPeriod(List<Ratio> theMaxDosePerPeriod) { 
961      this.maxDosePerPeriod = theMaxDosePerPeriod;
962      return this;
963    }
964
965    public boolean hasMaxDosePerPeriod() { 
966      if (this.maxDosePerPeriod == null)
967        return false;
968      for (Ratio item : this.maxDosePerPeriod)
969        if (!item.isEmpty())
970          return true;
971      return false;
972    }
973
974    public Ratio addMaxDosePerPeriod() { //3
975      Ratio t = new Ratio();
976      if (this.maxDosePerPeriod == null)
977        this.maxDosePerPeriod = new ArrayList<Ratio>();
978      this.maxDosePerPeriod.add(t);
979      return t;
980    }
981
982    public Dosage addMaxDosePerPeriod(Ratio t) { //3
983      if (t == null)
984        return this;
985      if (this.maxDosePerPeriod == null)
986        this.maxDosePerPeriod = new ArrayList<Ratio>();
987      this.maxDosePerPeriod.add(t);
988      return this;
989    }
990
991    /**
992     * @return The first repetition of repeating field {@link #maxDosePerPeriod}, creating it if it does not already exist {3}
993     */
994    public Ratio getMaxDosePerPeriodFirstRep() { 
995      if (getMaxDosePerPeriod().isEmpty()) {
996        addMaxDosePerPeriod();
997      }
998      return getMaxDosePerPeriod().get(0);
999    }
1000
1001    /**
1002     * @return {@link #maxDosePerAdministration} (Upper limit on medication per administration.)
1003     */
1004    public Quantity getMaxDosePerAdministration() { 
1005      if (this.maxDosePerAdministration == null)
1006        if (Configuration.errorOnAutoCreate())
1007          throw new Error("Attempt to auto-create Dosage.maxDosePerAdministration");
1008        else if (Configuration.doAutoCreate())
1009          this.maxDosePerAdministration = new Quantity(); // cc
1010      return this.maxDosePerAdministration;
1011    }
1012
1013    public boolean hasMaxDosePerAdministration() { 
1014      return this.maxDosePerAdministration != null && !this.maxDosePerAdministration.isEmpty();
1015    }
1016
1017    /**
1018     * @param value {@link #maxDosePerAdministration} (Upper limit on medication per administration.)
1019     */
1020    public Dosage setMaxDosePerAdministration(Quantity value) { 
1021      this.maxDosePerAdministration = value;
1022      return this;
1023    }
1024
1025    /**
1026     * @return {@link #maxDosePerLifetime} (Upper limit on medication per lifetime of the patient.)
1027     */
1028    public Quantity getMaxDosePerLifetime() { 
1029      if (this.maxDosePerLifetime == null)
1030        if (Configuration.errorOnAutoCreate())
1031          throw new Error("Attempt to auto-create Dosage.maxDosePerLifetime");
1032        else if (Configuration.doAutoCreate())
1033          this.maxDosePerLifetime = new Quantity(); // cc
1034      return this.maxDosePerLifetime;
1035    }
1036
1037    public boolean hasMaxDosePerLifetime() { 
1038      return this.maxDosePerLifetime != null && !this.maxDosePerLifetime.isEmpty();
1039    }
1040
1041    /**
1042     * @param value {@link #maxDosePerLifetime} (Upper limit on medication per lifetime of the patient.)
1043     */
1044    public Dosage setMaxDosePerLifetime(Quantity value) { 
1045      this.maxDosePerLifetime = value;
1046      return this;
1047    }
1048
1049      protected void listChildren(List<Property> children) {
1050        super.listChildren(children);
1051        children.add(new Property("sequence", "integer", "Indicates the order in which the dosage instructions should be applied or interpreted.", 0, 1, sequence));
1052        children.add(new Property("text", "string", "Free text dosage instructions e.g. SIG.", 0, 1, text));
1053        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));
1054        children.add(new Property("patientInstruction", "string", "Instructions in terms that are understood by the patient or consumer.", 0, 1, patientInstruction));
1055        children.add(new Property("timing", "Timing", "When medication should be administered.", 0, 1, timing));
1056        children.add(new Property("asNeeded", "boolean", "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).", 0, 1, asNeeded));
1057        children.add(new Property("asNeededFor", "CodeableConcept", "Indicates whether the Medication is only taken based on a precondition for taking the Medication (CodeableConcept).", 0, java.lang.Integer.MAX_VALUE, asNeededFor));
1058        children.add(new Property("site", "CodeableConcept", "Body site to administer to.", 0, 1, site));
1059        children.add(new Property("route", "CodeableConcept", "How drug should enter body.", 0, 1, route));
1060        children.add(new Property("method", "CodeableConcept", "Technique for administering medication.", 0, 1, method));
1061        children.add(new Property("doseAndRate", "", "Depending on the resource,this is the amount of medication administered, to  be administered or typical amount to be administered.", 0, java.lang.Integer.MAX_VALUE, doseAndRate));
1062        children.add(new Property("maxDosePerPeriod", "Ratio", "Upper limit on medication per unit of time.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod));
1063        children.add(new Property("maxDosePerAdministration", "Quantity", "Upper limit on medication per administration.", 0, 1, maxDosePerAdministration));
1064        children.add(new Property("maxDosePerLifetime", "Quantity", "Upper limit on medication per lifetime of the patient.", 0, 1, maxDosePerLifetime));
1065      }
1066
1067      @Override
1068      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1069        switch (_hash) {
1070        case 1349547969: /*sequence*/  return new Property("sequence", "integer", "Indicates the order in which the dosage instructions should be applied or interpreted.", 0, 1, sequence);
1071        case 3556653: /*text*/  return new Property("text", "string", "Free text dosage instructions e.g. SIG.", 0, 1, text);
1072        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);
1073        case 737543241: /*patientInstruction*/  return new Property("patientInstruction", "string", "Instructions in terms that are understood by the patient or consumer.", 0, 1, patientInstruction);
1074        case -873664438: /*timing*/  return new Property("timing", "Timing", "When medication should be administered.", 0, 1, timing);
1075        case -1432923513: /*asNeeded*/  return new Property("asNeeded", "boolean", "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).", 0, 1, asNeeded);
1076        case -544350014: /*asNeededFor*/  return new Property("asNeededFor", "CodeableConcept", "Indicates whether the Medication is only taken based on a precondition for taking the Medication (CodeableConcept).", 0, java.lang.Integer.MAX_VALUE, asNeededFor);
1077        case 3530567: /*site*/  return new Property("site", "CodeableConcept", "Body site to administer to.", 0, 1, site);
1078        case 108704329: /*route*/  return new Property("route", "CodeableConcept", "How drug should enter body.", 0, 1, route);
1079        case -1077554975: /*method*/  return new Property("method", "CodeableConcept", "Technique for administering medication.", 0, 1, method);
1080        case -611024774: /*doseAndRate*/  return new Property("doseAndRate", "", "Depending on the resource,this is the amount of medication administered, to  be administered or typical amount to be administered.", 0, java.lang.Integer.MAX_VALUE, doseAndRate);
1081        case 1506263709: /*maxDosePerPeriod*/  return new Property("maxDosePerPeriod", "Ratio", "Upper limit on medication per unit of time.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod);
1082        case 2004889914: /*maxDosePerAdministration*/  return new Property("maxDosePerAdministration", "Quantity", "Upper limit on medication per administration.", 0, 1, maxDosePerAdministration);
1083        case 642099621: /*maxDosePerLifetime*/  return new Property("maxDosePerLifetime", "Quantity", "Upper limit on medication per lifetime of the patient.", 0, 1, maxDosePerLifetime);
1084        default: return super.getNamedProperty(_hash, _name, _checkValid);
1085        }
1086
1087      }
1088
1089      @Override
1090      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1091        switch (hash) {
1092        case 1349547969: /*sequence*/ return this.sequence == null ? new Base[0] : new Base[] {this.sequence}; // IntegerType
1093        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
1094        case 1623641575: /*additionalInstruction*/ return this.additionalInstruction == null ? new Base[0] : this.additionalInstruction.toArray(new Base[this.additionalInstruction.size()]); // CodeableConcept
1095        case 737543241: /*patientInstruction*/ return this.patientInstruction == null ? new Base[0] : new Base[] {this.patientInstruction}; // StringType
1096        case -873664438: /*timing*/ return this.timing == null ? new Base[0] : new Base[] {this.timing}; // Timing
1097        case -1432923513: /*asNeeded*/ return this.asNeeded == null ? new Base[0] : new Base[] {this.asNeeded}; // BooleanType
1098        case -544350014: /*asNeededFor*/ return this.asNeededFor == null ? new Base[0] : this.asNeededFor.toArray(new Base[this.asNeededFor.size()]); // CodeableConcept
1099        case 3530567: /*site*/ return this.site == null ? new Base[0] : new Base[] {this.site}; // CodeableConcept
1100        case 108704329: /*route*/ return this.route == null ? new Base[0] : new Base[] {this.route}; // CodeableConcept
1101        case -1077554975: /*method*/ return this.method == null ? new Base[0] : new Base[] {this.method}; // CodeableConcept
1102        case -611024774: /*doseAndRate*/ return this.doseAndRate == null ? new Base[0] : this.doseAndRate.toArray(new Base[this.doseAndRate.size()]); // DosageDoseAndRateComponent
1103        case 1506263709: /*maxDosePerPeriod*/ return this.maxDosePerPeriod == null ? new Base[0] : this.maxDosePerPeriod.toArray(new Base[this.maxDosePerPeriod.size()]); // Ratio
1104        case 2004889914: /*maxDosePerAdministration*/ return this.maxDosePerAdministration == null ? new Base[0] : new Base[] {this.maxDosePerAdministration}; // Quantity
1105        case 642099621: /*maxDosePerLifetime*/ return this.maxDosePerLifetime == null ? new Base[0] : new Base[] {this.maxDosePerLifetime}; // Quantity
1106        default: return super.getProperty(hash, name, checkValid);
1107        }
1108
1109      }
1110
1111      @Override
1112      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1113        switch (hash) {
1114        case 1349547969: // sequence
1115          this.sequence = TypeConvertor.castToInteger(value); // IntegerType
1116          return value;
1117        case 3556653: // text
1118          this.text = TypeConvertor.castToString(value); // StringType
1119          return value;
1120        case 1623641575: // additionalInstruction
1121          this.getAdditionalInstruction().add(TypeConvertor.castToCodeableConcept(value)); // CodeableConcept
1122          return value;
1123        case 737543241: // patientInstruction
1124          this.patientInstruction = TypeConvertor.castToString(value); // StringType
1125          return value;
1126        case -873664438: // timing
1127          this.timing = TypeConvertor.castToTiming(value); // Timing
1128          return value;
1129        case -1432923513: // asNeeded
1130          this.asNeeded = TypeConvertor.castToBoolean(value); // BooleanType
1131          return value;
1132        case -544350014: // asNeededFor
1133          this.getAsNeededFor().add(TypeConvertor.castToCodeableConcept(value)); // CodeableConcept
1134          return value;
1135        case 3530567: // site
1136          this.site = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1137          return value;
1138        case 108704329: // route
1139          this.route = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1140          return value;
1141        case -1077554975: // method
1142          this.method = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1143          return value;
1144        case -611024774: // doseAndRate
1145          this.getDoseAndRate().add((DosageDoseAndRateComponent) value); // DosageDoseAndRateComponent
1146          return value;
1147        case 1506263709: // maxDosePerPeriod
1148          this.getMaxDosePerPeriod().add(TypeConvertor.castToRatio(value)); // Ratio
1149          return value;
1150        case 2004889914: // maxDosePerAdministration
1151          this.maxDosePerAdministration = TypeConvertor.castToQuantity(value); // Quantity
1152          return value;
1153        case 642099621: // maxDosePerLifetime
1154          this.maxDosePerLifetime = TypeConvertor.castToQuantity(value); // Quantity
1155          return value;
1156        default: return super.setProperty(hash, name, value);
1157        }
1158
1159      }
1160
1161      @Override
1162      public Base setProperty(String name, Base value) throws FHIRException {
1163        if (name.equals("sequence")) {
1164          this.sequence = TypeConvertor.castToInteger(value); // IntegerType
1165        } else if (name.equals("text")) {
1166          this.text = TypeConvertor.castToString(value); // StringType
1167        } else if (name.equals("additionalInstruction")) {
1168          this.getAdditionalInstruction().add(TypeConvertor.castToCodeableConcept(value));
1169        } else if (name.equals("patientInstruction")) {
1170          this.patientInstruction = TypeConvertor.castToString(value); // StringType
1171        } else if (name.equals("timing")) {
1172          this.timing = TypeConvertor.castToTiming(value); // Timing
1173        } else if (name.equals("asNeeded")) {
1174          this.asNeeded = TypeConvertor.castToBoolean(value); // BooleanType
1175        } else if (name.equals("asNeededFor")) {
1176          this.getAsNeededFor().add(TypeConvertor.castToCodeableConcept(value));
1177        } else if (name.equals("site")) {
1178          this.site = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1179        } else if (name.equals("route")) {
1180          this.route = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1181        } else if (name.equals("method")) {
1182          this.method = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1183        } else if (name.equals("doseAndRate")) {
1184          this.getDoseAndRate().add((DosageDoseAndRateComponent) value);
1185        } else if (name.equals("maxDosePerPeriod")) {
1186          this.getMaxDosePerPeriod().add(TypeConvertor.castToRatio(value));
1187        } else if (name.equals("maxDosePerAdministration")) {
1188          this.maxDosePerAdministration = TypeConvertor.castToQuantity(value); // Quantity
1189        } else if (name.equals("maxDosePerLifetime")) {
1190          this.maxDosePerLifetime = TypeConvertor.castToQuantity(value); // Quantity
1191        } else
1192          return super.setProperty(name, value);
1193        return value;
1194      }
1195
1196      @Override
1197      public Base makeProperty(int hash, String name) throws FHIRException {
1198        switch (hash) {
1199        case 1349547969:  return getSequenceElement();
1200        case 3556653:  return getTextElement();
1201        case 1623641575:  return addAdditionalInstruction(); 
1202        case 737543241:  return getPatientInstructionElement();
1203        case -873664438:  return getTiming();
1204        case -1432923513:  return getAsNeededElement();
1205        case -544350014:  return addAsNeededFor(); 
1206        case 3530567:  return getSite();
1207        case 108704329:  return getRoute();
1208        case -1077554975:  return getMethod();
1209        case -611024774:  return addDoseAndRate(); 
1210        case 1506263709:  return addMaxDosePerPeriod(); 
1211        case 2004889914:  return getMaxDosePerAdministration();
1212        case 642099621:  return getMaxDosePerLifetime();
1213        default: return super.makeProperty(hash, name);
1214        }
1215
1216      }
1217
1218      @Override
1219      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1220        switch (hash) {
1221        case 1349547969: /*sequence*/ return new String[] {"integer"};
1222        case 3556653: /*text*/ return new String[] {"string"};
1223        case 1623641575: /*additionalInstruction*/ return new String[] {"CodeableConcept"};
1224        case 737543241: /*patientInstruction*/ return new String[] {"string"};
1225        case -873664438: /*timing*/ return new String[] {"Timing"};
1226        case -1432923513: /*asNeeded*/ return new String[] {"boolean"};
1227        case -544350014: /*asNeededFor*/ return new String[] {"CodeableConcept"};
1228        case 3530567: /*site*/ return new String[] {"CodeableConcept"};
1229        case 108704329: /*route*/ return new String[] {"CodeableConcept"};
1230        case -1077554975: /*method*/ return new String[] {"CodeableConcept"};
1231        case -611024774: /*doseAndRate*/ return new String[] {};
1232        case 1506263709: /*maxDosePerPeriod*/ return new String[] {"Ratio"};
1233        case 2004889914: /*maxDosePerAdministration*/ return new String[] {"Quantity"};
1234        case 642099621: /*maxDosePerLifetime*/ return new String[] {"Quantity"};
1235        default: return super.getTypesForProperty(hash, name);
1236        }
1237
1238      }
1239
1240      @Override
1241      public Base addChild(String name) throws FHIRException {
1242        if (name.equals("sequence")) {
1243          throw new FHIRException("Cannot call addChild on a primitive type Dosage.sequence");
1244        }
1245        else if (name.equals("text")) {
1246          throw new FHIRException("Cannot call addChild on a primitive type Dosage.text");
1247        }
1248        else if (name.equals("additionalInstruction")) {
1249          return addAdditionalInstruction();
1250        }
1251        else if (name.equals("patientInstruction")) {
1252          throw new FHIRException("Cannot call addChild on a primitive type Dosage.patientInstruction");
1253        }
1254        else if (name.equals("timing")) {
1255          this.timing = new Timing();
1256          return this.timing;
1257        }
1258        else if (name.equals("asNeeded")) {
1259          throw new FHIRException("Cannot call addChild on a primitive type Dosage.asNeeded");
1260        }
1261        else if (name.equals("asNeededFor")) {
1262          return addAsNeededFor();
1263        }
1264        else if (name.equals("site")) {
1265          this.site = new CodeableConcept();
1266          return this.site;
1267        }
1268        else if (name.equals("route")) {
1269          this.route = new CodeableConcept();
1270          return this.route;
1271        }
1272        else if (name.equals("method")) {
1273          this.method = new CodeableConcept();
1274          return this.method;
1275        }
1276        else if (name.equals("doseAndRate")) {
1277          return addDoseAndRate();
1278        }
1279        else if (name.equals("maxDosePerPeriod")) {
1280          return addMaxDosePerPeriod();
1281        }
1282        else if (name.equals("maxDosePerAdministration")) {
1283          this.maxDosePerAdministration = new Quantity();
1284          return this.maxDosePerAdministration;
1285        }
1286        else if (name.equals("maxDosePerLifetime")) {
1287          this.maxDosePerLifetime = new Quantity();
1288          return this.maxDosePerLifetime;
1289        }
1290        else
1291          return super.addChild(name);
1292      }
1293
1294  public String fhirType() {
1295    return "Dosage";
1296
1297  }
1298
1299      public Dosage copy() {
1300        Dosage dst = new Dosage();
1301        copyValues(dst);
1302        return dst;
1303      }
1304
1305      public void copyValues(Dosage dst) {
1306        super.copyValues(dst);
1307        dst.sequence = sequence == null ? null : sequence.copy();
1308        dst.text = text == null ? null : text.copy();
1309        if (additionalInstruction != null) {
1310          dst.additionalInstruction = new ArrayList<CodeableConcept>();
1311          for (CodeableConcept i : additionalInstruction)
1312            dst.additionalInstruction.add(i.copy());
1313        };
1314        dst.patientInstruction = patientInstruction == null ? null : patientInstruction.copy();
1315        dst.timing = timing == null ? null : timing.copy();
1316        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
1317        if (asNeededFor != null) {
1318          dst.asNeededFor = new ArrayList<CodeableConcept>();
1319          for (CodeableConcept i : asNeededFor)
1320            dst.asNeededFor.add(i.copy());
1321        };
1322        dst.site = site == null ? null : site.copy();
1323        dst.route = route == null ? null : route.copy();
1324        dst.method = method == null ? null : method.copy();
1325        if (doseAndRate != null) {
1326          dst.doseAndRate = new ArrayList<DosageDoseAndRateComponent>();
1327          for (DosageDoseAndRateComponent i : doseAndRate)
1328            dst.doseAndRate.add(i.copy());
1329        };
1330        if (maxDosePerPeriod != null) {
1331          dst.maxDosePerPeriod = new ArrayList<Ratio>();
1332          for (Ratio i : maxDosePerPeriod)
1333            dst.maxDosePerPeriod.add(i.copy());
1334        };
1335        dst.maxDosePerAdministration = maxDosePerAdministration == null ? null : maxDosePerAdministration.copy();
1336        dst.maxDosePerLifetime = maxDosePerLifetime == null ? null : maxDosePerLifetime.copy();
1337      }
1338
1339      protected Dosage typedCopy() {
1340        return copy();
1341      }
1342
1343      @Override
1344      public boolean equalsDeep(Base other_) {
1345        if (!super.equalsDeep(other_))
1346          return false;
1347        if (!(other_ instanceof Dosage))
1348          return false;
1349        Dosage o = (Dosage) other_;
1350        return compareDeep(sequence, o.sequence, true) && compareDeep(text, o.text, true) && compareDeep(additionalInstruction, o.additionalInstruction, true)
1351           && compareDeep(patientInstruction, o.patientInstruction, true) && compareDeep(timing, o.timing, true)
1352           && compareDeep(asNeeded, o.asNeeded, true) && compareDeep(asNeededFor, o.asNeededFor, true) && compareDeep(site, o.site, true)
1353           && compareDeep(route, o.route, true) && compareDeep(method, o.method, true) && compareDeep(doseAndRate, o.doseAndRate, true)
1354           && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true) && compareDeep(maxDosePerAdministration, o.maxDosePerAdministration, true)
1355           && compareDeep(maxDosePerLifetime, o.maxDosePerLifetime, true);
1356      }
1357
1358      @Override
1359      public boolean equalsShallow(Base other_) {
1360        if (!super.equalsShallow(other_))
1361          return false;
1362        if (!(other_ instanceof Dosage))
1363          return false;
1364        Dosage o = (Dosage) other_;
1365        return compareValues(sequence, o.sequence, true) && compareValues(text, o.text, true) && compareValues(patientInstruction, o.patientInstruction, true)
1366           && compareValues(asNeeded, o.asNeeded, true);
1367      }
1368
1369      public boolean isEmpty() {
1370        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(sequence, text, additionalInstruction
1371          , patientInstruction, timing, asNeeded, asNeededFor, site, route, method, doseAndRate
1372          , maxDosePerPeriod, maxDosePerAdministration, maxDosePerLifetime);
1373      }
1374
1375
1376}
1377