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