001package org.hl7.fhir.dstu3.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * Indicates how the medication is/was taken or should be taken by the patient.
046 */
047@DatatypeDef(name="Dosage")
048public class Dosage extends Type implements ICompositeType {
049
050    /**
051     * Indicates the order in which the dosage instructions should be applied or interpreted.
052     */
053    @Child(name = "sequence", type = {IntegerType.class}, order=0, min=0, max=1, modifier=false, summary=true)
054    @Description(shortDefinition="The order of the dosage instructions", formalDefinition="Indicates the order in which the dosage instructions should be applied or interpreted." )
055    protected IntegerType sequence;
056
057    /**
058     * Free text dosage instructions e.g. SIG.
059     */
060    @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
061    @Description(shortDefinition="Free text dosage instructions e.g. SIG", formalDefinition="Free text dosage instructions e.g. SIG." )
062    protected StringType text;
063
064    /**
065     * Supplemental instruction - e.g. "with meals".
066     */
067    @Child(name = "additionalInstruction", type = {CodeableConcept.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
068    @Description(shortDefinition="Supplemental instruction - e.g. \"with meals\"", formalDefinition="Supplemental instruction - e.g. \"with meals\"." )
069    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/additional-instruction-codes")
070    protected List<CodeableConcept> additionalInstruction;
071
072    /**
073     * Instructions in terms that are understood by the patient or consumer.
074     */
075    @Child(name = "patientInstruction", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
076    @Description(shortDefinition="Patient or consumer oriented instructions", formalDefinition="Instructions in terms that are understood by the patient or consumer." )
077    protected StringType patientInstruction;
078
079    /**
080     * When medication should be administered.
081     */
082    @Child(name = "timing", type = {Timing.class}, order=4, min=0, max=1, modifier=false, summary=true)
083    @Description(shortDefinition="When medication should be administered", formalDefinition="When medication should be administered." )
084    protected Timing timing;
085
086    /**
087     * 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).
088     */
089    @Child(name = "asNeeded", type = {BooleanType.class, CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=true)
090    @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)." )
091    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-as-needed-reason")
092    protected Type asNeeded;
093
094    /**
095     * Body site to administer to.
096     */
097    @Child(name = "site", type = {CodeableConcept.class}, order=6, min=0, max=1, modifier=false, summary=true)
098    @Description(shortDefinition="Body site to administer to", formalDefinition="Body site to administer to." )
099    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/approach-site-codes")
100    protected CodeableConcept site;
101
102    /**
103     * How drug should enter body.
104     */
105    @Child(name = "route", type = {CodeableConcept.class}, order=7, min=0, max=1, modifier=false, summary=true)
106    @Description(shortDefinition="How drug should enter body", formalDefinition="How drug should enter body." )
107    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/route-codes")
108    protected CodeableConcept route;
109
110    /**
111     * Technique for administering medication.
112     */
113    @Child(name = "method", type = {CodeableConcept.class}, order=8, min=0, max=1, modifier=false, summary=true)
114    @Description(shortDefinition="Technique for administering medication", formalDefinition="Technique for administering medication." )
115    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/administration-method-codes")
116    protected CodeableConcept method;
117
118    /**
119     * Amount of medication per dose.
120     */
121    @Child(name = "dose", type = {Range.class, SimpleQuantity.class}, order=9, min=0, max=1, modifier=false, summary=true)
122    @Description(shortDefinition="Amount of medication per dose", formalDefinition="Amount of medication per dose." )
123    protected Type dose;
124
125    /**
126     * Upper limit on medication per unit of time.
127     */
128    @Child(name = "maxDosePerPeriod", type = {Ratio.class}, order=10, min=0, max=1, modifier=false, summary=true)
129    @Description(shortDefinition="Upper limit on medication per unit of time", formalDefinition="Upper limit on medication per unit of time." )
130    protected Ratio maxDosePerPeriod;
131
132    /**
133     * Upper limit on medication per administration.
134     */
135    @Child(name = "maxDosePerAdministration", type = {SimpleQuantity.class}, order=11, min=0, max=1, modifier=false, summary=true)
136    @Description(shortDefinition="Upper limit on medication per administration", formalDefinition="Upper limit on medication per administration." )
137    protected SimpleQuantity maxDosePerAdministration;
138
139    /**
140     * Upper limit on medication per lifetime of the patient.
141     */
142    @Child(name = "maxDosePerLifetime", type = {SimpleQuantity.class}, order=12, min=0, max=1, modifier=false, summary=true)
143    @Description(shortDefinition="Upper limit on medication per lifetime of the patient", formalDefinition="Upper limit on medication per lifetime of the patient." )
144    protected SimpleQuantity maxDosePerLifetime;
145
146    /**
147     * Amount of medication per unit of time.
148     */
149    @Child(name = "rate", type = {Ratio.class, Range.class, SimpleQuantity.class}, order=13, min=0, max=1, modifier=false, summary=true)
150    @Description(shortDefinition="Amount of medication per unit of time", formalDefinition="Amount of medication per unit of time." )
151    protected Type rate;
152
153    private static final long serialVersionUID = 70626458L;
154
155  /**
156   * Constructor
157   */
158    public Dosage() {
159      super();
160    }
161
162    /**
163     * @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
164     */
165    public IntegerType getSequenceElement() { 
166      if (this.sequence == null)
167        if (Configuration.errorOnAutoCreate())
168          throw new Error("Attempt to auto-create Dosage.sequence");
169        else if (Configuration.doAutoCreate())
170          this.sequence = new IntegerType(); // bb
171      return this.sequence;
172    }
173
174    public boolean hasSequenceElement() { 
175      return this.sequence != null && !this.sequence.isEmpty();
176    }
177
178    public boolean hasSequence() { 
179      return this.sequence != null && !this.sequence.isEmpty();
180    }
181
182    /**
183     * @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
184     */
185    public Dosage setSequenceElement(IntegerType value) { 
186      this.sequence = value;
187      return this;
188    }
189
190    /**
191     * @return Indicates the order in which the dosage instructions should be applied or interpreted.
192     */
193    public int getSequence() { 
194      return this.sequence == null || this.sequence.isEmpty() ? 0 : this.sequence.getValue();
195    }
196
197    /**
198     * @param value Indicates the order in which the dosage instructions should be applied or interpreted.
199     */
200    public Dosage setSequence(int value) { 
201        if (this.sequence == null)
202          this.sequence = new IntegerType();
203        this.sequence.setValue(value);
204      return this;
205    }
206
207    /**
208     * @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
209     */
210    public StringType getTextElement() { 
211      if (this.text == null)
212        if (Configuration.errorOnAutoCreate())
213          throw new Error("Attempt to auto-create Dosage.text");
214        else if (Configuration.doAutoCreate())
215          this.text = new StringType(); // bb
216      return this.text;
217    }
218
219    public boolean hasTextElement() { 
220      return this.text != null && !this.text.isEmpty();
221    }
222
223    public boolean hasText() { 
224      return this.text != null && !this.text.isEmpty();
225    }
226
227    /**
228     * @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
229     */
230    public Dosage setTextElement(StringType value) { 
231      this.text = value;
232      return this;
233    }
234
235    /**
236     * @return Free text dosage instructions e.g. SIG.
237     */
238    public String getText() { 
239      return this.text == null ? null : this.text.getValue();
240    }
241
242    /**
243     * @param value Free text dosage instructions e.g. SIG.
244     */
245    public Dosage setText(String value) { 
246      if (Utilities.noString(value))
247        this.text = null;
248      else {
249        if (this.text == null)
250          this.text = new StringType();
251        this.text.setValue(value);
252      }
253      return this;
254    }
255
256    /**
257     * @return {@link #additionalInstruction} (Supplemental instruction - e.g. "with meals".)
258     */
259    public List<CodeableConcept> getAdditionalInstruction() { 
260      if (this.additionalInstruction == null)
261        this.additionalInstruction = new ArrayList<CodeableConcept>();
262      return this.additionalInstruction;
263    }
264
265    /**
266     * @return Returns a reference to <code>this</code> for easy method chaining
267     */
268    public Dosage setAdditionalInstruction(List<CodeableConcept> theAdditionalInstruction) { 
269      this.additionalInstruction = theAdditionalInstruction;
270      return this;
271    }
272
273    public boolean hasAdditionalInstruction() { 
274      if (this.additionalInstruction == null)
275        return false;
276      for (CodeableConcept item : this.additionalInstruction)
277        if (!item.isEmpty())
278          return true;
279      return false;
280    }
281
282    public CodeableConcept addAdditionalInstruction() { //3
283      CodeableConcept t = new CodeableConcept();
284      if (this.additionalInstruction == null)
285        this.additionalInstruction = new ArrayList<CodeableConcept>();
286      this.additionalInstruction.add(t);
287      return t;
288    }
289
290    public Dosage addAdditionalInstruction(CodeableConcept t) { //3
291      if (t == null)
292        return this;
293      if (this.additionalInstruction == null)
294        this.additionalInstruction = new ArrayList<CodeableConcept>();
295      this.additionalInstruction.add(t);
296      return this;
297    }
298
299    /**
300     * @return The first repetition of repeating field {@link #additionalInstruction}, creating it if it does not already exist
301     */
302    public CodeableConcept getAdditionalInstructionFirstRep() { 
303      if (getAdditionalInstruction().isEmpty()) {
304        addAdditionalInstruction();
305      }
306      return getAdditionalInstruction().get(0);
307    }
308
309    /**
310     * @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
311     */
312    public StringType getPatientInstructionElement() { 
313      if (this.patientInstruction == null)
314        if (Configuration.errorOnAutoCreate())
315          throw new Error("Attempt to auto-create Dosage.patientInstruction");
316        else if (Configuration.doAutoCreate())
317          this.patientInstruction = new StringType(); // bb
318      return this.patientInstruction;
319    }
320
321    public boolean hasPatientInstructionElement() { 
322      return this.patientInstruction != null && !this.patientInstruction.isEmpty();
323    }
324
325    public boolean hasPatientInstruction() { 
326      return this.patientInstruction != null && !this.patientInstruction.isEmpty();
327    }
328
329    /**
330     * @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
331     */
332    public Dosage setPatientInstructionElement(StringType value) { 
333      this.patientInstruction = value;
334      return this;
335    }
336
337    /**
338     * @return Instructions in terms that are understood by the patient or consumer.
339     */
340    public String getPatientInstruction() { 
341      return this.patientInstruction == null ? null : this.patientInstruction.getValue();
342    }
343
344    /**
345     * @param value Instructions in terms that are understood by the patient or consumer.
346     */
347    public Dosage setPatientInstruction(String value) { 
348      if (Utilities.noString(value))
349        this.patientInstruction = null;
350      else {
351        if (this.patientInstruction == null)
352          this.patientInstruction = new StringType();
353        this.patientInstruction.setValue(value);
354      }
355      return this;
356    }
357
358    /**
359     * @return {@link #timing} (When medication should be administered.)
360     */
361    public Timing getTiming() { 
362      if (this.timing == null)
363        if (Configuration.errorOnAutoCreate())
364          throw new Error("Attempt to auto-create Dosage.timing");
365        else if (Configuration.doAutoCreate())
366          this.timing = new Timing(); // cc
367      return this.timing;
368    }
369
370    public boolean hasTiming() { 
371      return this.timing != null && !this.timing.isEmpty();
372    }
373
374    /**
375     * @param value {@link #timing} (When medication should be administered.)
376     */
377    public Dosage setTiming(Timing value) { 
378      this.timing = value;
379      return this;
380    }
381
382    /**
383     * @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).)
384     */
385    public Type getAsNeeded() { 
386      return this.asNeeded;
387    }
388
389    /**
390     * @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).)
391     */
392    public BooleanType getAsNeededBooleanType() throws FHIRException { 
393      if (!(this.asNeeded instanceof BooleanType))
394        throw new FHIRException("Type mismatch: the type BooleanType was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
395      return (BooleanType) this.asNeeded;
396    }
397
398    public boolean hasAsNeededBooleanType() { 
399      return this.asNeeded instanceof BooleanType;
400    }
401
402    /**
403     * @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).)
404     */
405    public CodeableConcept getAsNeededCodeableConcept() throws FHIRException { 
406      if (!(this.asNeeded instanceof CodeableConcept))
407        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
408      return (CodeableConcept) this.asNeeded;
409    }
410
411    public boolean hasAsNeededCodeableConcept() { 
412      return this.asNeeded instanceof CodeableConcept;
413    }
414
415    public boolean hasAsNeeded() { 
416      return this.asNeeded != null && !this.asNeeded.isEmpty();
417    }
418
419    /**
420     * @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).)
421     */
422    public Dosage setAsNeeded(Type value) { 
423      this.asNeeded = value;
424      return this;
425    }
426
427    /**
428     * @return {@link #site} (Body site to administer to.)
429     */
430    public CodeableConcept getSite() { 
431      if (this.site == null)
432        if (Configuration.errorOnAutoCreate())
433          throw new Error("Attempt to auto-create Dosage.site");
434        else if (Configuration.doAutoCreate())
435          this.site = new CodeableConcept(); // cc
436      return this.site;
437    }
438
439    public boolean hasSite() { 
440      return this.site != null && !this.site.isEmpty();
441    }
442
443    /**
444     * @param value {@link #site} (Body site to administer to.)
445     */
446    public Dosage setSite(CodeableConcept value) { 
447      this.site = value;
448      return this;
449    }
450
451    /**
452     * @return {@link #route} (How drug should enter body.)
453     */
454    public CodeableConcept getRoute() { 
455      if (this.route == null)
456        if (Configuration.errorOnAutoCreate())
457          throw new Error("Attempt to auto-create Dosage.route");
458        else if (Configuration.doAutoCreate())
459          this.route = new CodeableConcept(); // cc
460      return this.route;
461    }
462
463    public boolean hasRoute() { 
464      return this.route != null && !this.route.isEmpty();
465    }
466
467    /**
468     * @param value {@link #route} (How drug should enter body.)
469     */
470    public Dosage setRoute(CodeableConcept value) { 
471      this.route = value;
472      return this;
473    }
474
475    /**
476     * @return {@link #method} (Technique for administering medication.)
477     */
478    public CodeableConcept getMethod() { 
479      if (this.method == null)
480        if (Configuration.errorOnAutoCreate())
481          throw new Error("Attempt to auto-create Dosage.method");
482        else if (Configuration.doAutoCreate())
483          this.method = new CodeableConcept(); // cc
484      return this.method;
485    }
486
487    public boolean hasMethod() { 
488      return this.method != null && !this.method.isEmpty();
489    }
490
491    /**
492     * @param value {@link #method} (Technique for administering medication.)
493     */
494    public Dosage setMethod(CodeableConcept value) { 
495      this.method = value;
496      return this;
497    }
498
499    /**
500     * @return {@link #dose} (Amount of medication per dose.)
501     */
502    public Type getDose() { 
503      return this.dose;
504    }
505
506    /**
507     * @return {@link #dose} (Amount of medication per dose.)
508     */
509    public Range getDoseRange() throws FHIRException { 
510      if (!(this.dose instanceof Range))
511        throw new FHIRException("Type mismatch: the type Range was expected, but "+this.dose.getClass().getName()+" was encountered");
512      return (Range) this.dose;
513    }
514
515    public boolean hasDoseRange() { 
516      return this.dose instanceof Range;
517    }
518
519    /**
520     * @return {@link #dose} (Amount of medication per dose.)
521     */
522    public SimpleQuantity getDoseSimpleQuantity() throws FHIRException { 
523      if (!(this.dose instanceof SimpleQuantity))
524        throw new FHIRException("Type mismatch: the type SimpleQuantity was expected, but "+this.dose.getClass().getName()+" was encountered");
525      return (SimpleQuantity) this.dose;
526    }
527
528    public boolean hasDoseSimpleQuantity() { 
529      return this.dose instanceof SimpleQuantity;
530    }
531
532    public boolean hasDose() { 
533      return this.dose != null && !this.dose.isEmpty();
534    }
535
536    /**
537     * @param value {@link #dose} (Amount of medication per dose.)
538     */
539    public Dosage setDose(Type value) { 
540      this.dose = value;
541      return this;
542    }
543
544    /**
545     * @return {@link #maxDosePerPeriod} (Upper limit on medication per unit of time.)
546     */
547    public Ratio getMaxDosePerPeriod() { 
548      if (this.maxDosePerPeriod == null)
549        if (Configuration.errorOnAutoCreate())
550          throw new Error("Attempt to auto-create Dosage.maxDosePerPeriod");
551        else if (Configuration.doAutoCreate())
552          this.maxDosePerPeriod = new Ratio(); // cc
553      return this.maxDosePerPeriod;
554    }
555
556    public boolean hasMaxDosePerPeriod() { 
557      return this.maxDosePerPeriod != null && !this.maxDosePerPeriod.isEmpty();
558    }
559
560    /**
561     * @param value {@link #maxDosePerPeriod} (Upper limit on medication per unit of time.)
562     */
563    public Dosage setMaxDosePerPeriod(Ratio value) { 
564      this.maxDosePerPeriod = value;
565      return this;
566    }
567
568    /**
569     * @return {@link #maxDosePerAdministration} (Upper limit on medication per administration.)
570     */
571    public SimpleQuantity getMaxDosePerAdministration() { 
572      if (this.maxDosePerAdministration == null)
573        if (Configuration.errorOnAutoCreate())
574          throw new Error("Attempt to auto-create Dosage.maxDosePerAdministration");
575        else if (Configuration.doAutoCreate())
576          this.maxDosePerAdministration = new SimpleQuantity(); // cc
577      return this.maxDosePerAdministration;
578    }
579
580    public boolean hasMaxDosePerAdministration() { 
581      return this.maxDosePerAdministration != null && !this.maxDosePerAdministration.isEmpty();
582    }
583
584    /**
585     * @param value {@link #maxDosePerAdministration} (Upper limit on medication per administration.)
586     */
587    public Dosage setMaxDosePerAdministration(SimpleQuantity value) { 
588      this.maxDosePerAdministration = value;
589      return this;
590    }
591
592    /**
593     * @return {@link #maxDosePerLifetime} (Upper limit on medication per lifetime of the patient.)
594     */
595    public SimpleQuantity getMaxDosePerLifetime() { 
596      if (this.maxDosePerLifetime == null)
597        if (Configuration.errorOnAutoCreate())
598          throw new Error("Attempt to auto-create Dosage.maxDosePerLifetime");
599        else if (Configuration.doAutoCreate())
600          this.maxDosePerLifetime = new SimpleQuantity(); // cc
601      return this.maxDosePerLifetime;
602    }
603
604    public boolean hasMaxDosePerLifetime() { 
605      return this.maxDosePerLifetime != null && !this.maxDosePerLifetime.isEmpty();
606    }
607
608    /**
609     * @param value {@link #maxDosePerLifetime} (Upper limit on medication per lifetime of the patient.)
610     */
611    public Dosage setMaxDosePerLifetime(SimpleQuantity value) { 
612      this.maxDosePerLifetime = value;
613      return this;
614    }
615
616    /**
617     * @return {@link #rate} (Amount of medication per unit of time.)
618     */
619    public Type getRate() { 
620      return this.rate;
621    }
622
623    /**
624     * @return {@link #rate} (Amount of medication per unit of time.)
625     */
626    public Ratio getRateRatio() throws FHIRException { 
627      if (!(this.rate instanceof Ratio))
628        throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
629      return (Ratio) this.rate;
630    }
631
632    public boolean hasRateRatio() { 
633      return this.rate instanceof Ratio;
634    }
635
636    /**
637     * @return {@link #rate} (Amount of medication per unit of time.)
638     */
639    public Range getRateRange() throws FHIRException { 
640      if (!(this.rate instanceof Range))
641        throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
642      return (Range) this.rate;
643    }
644
645    public boolean hasRateRange() { 
646      return this.rate instanceof Range;
647    }
648
649    /**
650     * @return {@link #rate} (Amount of medication per unit of time.)
651     */
652    public SimpleQuantity getRateSimpleQuantity() throws FHIRException { 
653      if (!(this.rate instanceof SimpleQuantity))
654        throw new FHIRException("Type mismatch: the type SimpleQuantity was expected, but "+this.rate.getClass().getName()+" was encountered");
655      return (SimpleQuantity) this.rate;
656    }
657
658    public boolean hasRateSimpleQuantity() { 
659      return this.rate instanceof SimpleQuantity;
660    }
661
662    public boolean hasRate() { 
663      return this.rate != null && !this.rate.isEmpty();
664    }
665
666    /**
667     * @param value {@link #rate} (Amount of medication per unit of time.)
668     */
669    public Dosage setRate(Type value) { 
670      this.rate = value;
671      return this;
672    }
673
674      protected void listChildren(List<Property> childrenList) {
675        super.listChildren(childrenList);
676        childrenList.add(new Property("sequence", "integer", "Indicates the order in which the dosage instructions should be applied or interpreted.", 0, java.lang.Integer.MAX_VALUE, sequence));
677        childrenList.add(new Property("text", "string", "Free text dosage instructions e.g. SIG.", 0, java.lang.Integer.MAX_VALUE, text));
678        childrenList.add(new Property("additionalInstruction", "CodeableConcept", "Supplemental instruction - e.g. \"with meals\".", 0, java.lang.Integer.MAX_VALUE, additionalInstruction));
679        childrenList.add(new Property("patientInstruction", "string", "Instructions in terms that are understood by the patient or consumer.", 0, java.lang.Integer.MAX_VALUE, patientInstruction));
680        childrenList.add(new Property("timing", "Timing", "When medication should be administered.", 0, java.lang.Integer.MAX_VALUE, timing));
681        childrenList.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, java.lang.Integer.MAX_VALUE, asNeeded));
682        childrenList.add(new Property("site", "CodeableConcept", "Body site to administer to.", 0, java.lang.Integer.MAX_VALUE, site));
683        childrenList.add(new Property("route", "CodeableConcept", "How drug should enter body.", 0, java.lang.Integer.MAX_VALUE, route));
684        childrenList.add(new Property("method", "CodeableConcept", "Technique for administering medication.", 0, java.lang.Integer.MAX_VALUE, method));
685        childrenList.add(new Property("dose[x]", "Range|SimpleQuantity", "Amount of medication per dose.", 0, java.lang.Integer.MAX_VALUE, dose));
686        childrenList.add(new Property("maxDosePerPeriod", "Ratio", "Upper limit on medication per unit of time.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod));
687        childrenList.add(new Property("maxDosePerAdministration", "SimpleQuantity", "Upper limit on medication per administration.", 0, java.lang.Integer.MAX_VALUE, maxDosePerAdministration));
688        childrenList.add(new Property("maxDosePerLifetime", "SimpleQuantity", "Upper limit on medication per lifetime of the patient.", 0, java.lang.Integer.MAX_VALUE, maxDosePerLifetime));
689        childrenList.add(new Property("rate[x]", "Ratio|Range|SimpleQuantity", "Amount of medication per unit of time.", 0, java.lang.Integer.MAX_VALUE, rate));
690      }
691
692      @Override
693      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
694        switch (hash) {
695        case 1349547969: /*sequence*/ return this.sequence == null ? new Base[0] : new Base[] {this.sequence}; // IntegerType
696        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
697        case 1623641575: /*additionalInstruction*/ return this.additionalInstruction == null ? new Base[0] : this.additionalInstruction.toArray(new Base[this.additionalInstruction.size()]); // CodeableConcept
698        case 737543241: /*patientInstruction*/ return this.patientInstruction == null ? new Base[0] : new Base[] {this.patientInstruction}; // StringType
699        case -873664438: /*timing*/ return this.timing == null ? new Base[0] : new Base[] {this.timing}; // Timing
700        case -1432923513: /*asNeeded*/ return this.asNeeded == null ? new Base[0] : new Base[] {this.asNeeded}; // Type
701        case 3530567: /*site*/ return this.site == null ? new Base[0] : new Base[] {this.site}; // CodeableConcept
702        case 108704329: /*route*/ return this.route == null ? new Base[0] : new Base[] {this.route}; // CodeableConcept
703        case -1077554975: /*method*/ return this.method == null ? new Base[0] : new Base[] {this.method}; // CodeableConcept
704        case 3089437: /*dose*/ return this.dose == null ? new Base[0] : new Base[] {this.dose}; // Type
705        case 1506263709: /*maxDosePerPeriod*/ return this.maxDosePerPeriod == null ? new Base[0] : new Base[] {this.maxDosePerPeriod}; // Ratio
706        case 2004889914: /*maxDosePerAdministration*/ return this.maxDosePerAdministration == null ? new Base[0] : new Base[] {this.maxDosePerAdministration}; // SimpleQuantity
707        case 642099621: /*maxDosePerLifetime*/ return this.maxDosePerLifetime == null ? new Base[0] : new Base[] {this.maxDosePerLifetime}; // SimpleQuantity
708        case 3493088: /*rate*/ return this.rate == null ? new Base[0] : new Base[] {this.rate}; // Type
709        default: return super.getProperty(hash, name, checkValid);
710        }
711
712      }
713
714      @Override
715      public Base setProperty(int hash, String name, Base value) throws FHIRException {
716        switch (hash) {
717        case 1349547969: // sequence
718          this.sequence = castToInteger(value); // IntegerType
719          return value;
720        case 3556653: // text
721          this.text = castToString(value); // StringType
722          return value;
723        case 1623641575: // additionalInstruction
724          this.getAdditionalInstruction().add(castToCodeableConcept(value)); // CodeableConcept
725          return value;
726        case 737543241: // patientInstruction
727          this.patientInstruction = castToString(value); // StringType
728          return value;
729        case -873664438: // timing
730          this.timing = castToTiming(value); // Timing
731          return value;
732        case -1432923513: // asNeeded
733          this.asNeeded = castToType(value); // Type
734          return value;
735        case 3530567: // site
736          this.site = castToCodeableConcept(value); // CodeableConcept
737          return value;
738        case 108704329: // route
739          this.route = castToCodeableConcept(value); // CodeableConcept
740          return value;
741        case -1077554975: // method
742          this.method = castToCodeableConcept(value); // CodeableConcept
743          return value;
744        case 3089437: // dose
745          this.dose = castToType(value); // Type
746          return value;
747        case 1506263709: // maxDosePerPeriod
748          this.maxDosePerPeriod = castToRatio(value); // Ratio
749          return value;
750        case 2004889914: // maxDosePerAdministration
751          this.maxDosePerAdministration = castToSimpleQuantity(value); // SimpleQuantity
752          return value;
753        case 642099621: // maxDosePerLifetime
754          this.maxDosePerLifetime = castToSimpleQuantity(value); // SimpleQuantity
755          return value;
756        case 3493088: // rate
757          this.rate = castToType(value); // Type
758          return value;
759        default: return super.setProperty(hash, name, value);
760        }
761
762      }
763
764      @Override
765      public Base setProperty(String name, Base value) throws FHIRException {
766        if (name.equals("sequence")) {
767          this.sequence = castToInteger(value); // IntegerType
768        } else if (name.equals("text")) {
769          this.text = castToString(value); // StringType
770        } else if (name.equals("additionalInstruction")) {
771          this.getAdditionalInstruction().add(castToCodeableConcept(value));
772        } else if (name.equals("patientInstruction")) {
773          this.patientInstruction = castToString(value); // StringType
774        } else if (name.equals("timing")) {
775          this.timing = castToTiming(value); // Timing
776        } else if (name.equals("asNeeded[x]")) {
777          this.asNeeded = castToType(value); // Type
778        } else if (name.equals("site")) {
779          this.site = castToCodeableConcept(value); // CodeableConcept
780        } else if (name.equals("route")) {
781          this.route = castToCodeableConcept(value); // CodeableConcept
782        } else if (name.equals("method")) {
783          this.method = castToCodeableConcept(value); // CodeableConcept
784        } else if (name.equals("dose[x]")) {
785          this.dose = castToType(value); // Type
786        } else if (name.equals("maxDosePerPeriod")) {
787          this.maxDosePerPeriod = castToRatio(value); // Ratio
788        } else if (name.equals("maxDosePerAdministration")) {
789          this.maxDosePerAdministration = castToSimpleQuantity(value); // SimpleQuantity
790        } else if (name.equals("maxDosePerLifetime")) {
791          this.maxDosePerLifetime = castToSimpleQuantity(value); // SimpleQuantity
792        } else if (name.equals("rate[x]")) {
793          this.rate = castToType(value); // Type
794        } else
795          return super.setProperty(name, value);
796        return value;
797      }
798
799      @Override
800      public Base makeProperty(int hash, String name) throws FHIRException {
801        switch (hash) {
802        case 1349547969:  return getSequenceElement();
803        case 3556653:  return getTextElement();
804        case 1623641575:  return addAdditionalInstruction(); 
805        case 737543241:  return getPatientInstructionElement();
806        case -873664438:  return getTiming(); 
807        case -544329575:  return getAsNeeded(); 
808        case -1432923513:  return getAsNeeded(); 
809        case 3530567:  return getSite(); 
810        case 108704329:  return getRoute(); 
811        case -1077554975:  return getMethod(); 
812        case 1843195715:  return getDose(); 
813        case 3089437:  return getDose(); 
814        case 1506263709:  return getMaxDosePerPeriod(); 
815        case 2004889914:  return getMaxDosePerAdministration(); 
816        case 642099621:  return getMaxDosePerLifetime(); 
817        case 983460768:  return getRate(); 
818        case 3493088:  return getRate(); 
819        default: return super.makeProperty(hash, name);
820        }
821
822      }
823
824      @Override
825      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
826        switch (hash) {
827        case 1349547969: /*sequence*/ return new String[] {"integer"};
828        case 3556653: /*text*/ return new String[] {"string"};
829        case 1623641575: /*additionalInstruction*/ return new String[] {"CodeableConcept"};
830        case 737543241: /*patientInstruction*/ return new String[] {"string"};
831        case -873664438: /*timing*/ return new String[] {"Timing"};
832        case -1432923513: /*asNeeded*/ return new String[] {"boolean", "CodeableConcept"};
833        case 3530567: /*site*/ return new String[] {"CodeableConcept"};
834        case 108704329: /*route*/ return new String[] {"CodeableConcept"};
835        case -1077554975: /*method*/ return new String[] {"CodeableConcept"};
836        case 3089437: /*dose*/ return new String[] {"Range", "SimpleQuantity"};
837        case 1506263709: /*maxDosePerPeriod*/ return new String[] {"Ratio"};
838        case 2004889914: /*maxDosePerAdministration*/ return new String[] {"SimpleQuantity"};
839        case 642099621: /*maxDosePerLifetime*/ return new String[] {"SimpleQuantity"};
840        case 3493088: /*rate*/ return new String[] {"Ratio", "Range", "SimpleQuantity"};
841        default: return super.getTypesForProperty(hash, name);
842        }
843
844      }
845
846      @Override
847      public Base addChild(String name) throws FHIRException {
848        if (name.equals("sequence")) {
849          throw new FHIRException("Cannot call addChild on a primitive type Dosage.sequence");
850        }
851        else if (name.equals("text")) {
852          throw new FHIRException("Cannot call addChild on a primitive type Dosage.text");
853        }
854        else if (name.equals("additionalInstruction")) {
855          return addAdditionalInstruction();
856        }
857        else if (name.equals("patientInstruction")) {
858          throw new FHIRException("Cannot call addChild on a primitive type Dosage.patientInstruction");
859        }
860        else if (name.equals("timing")) {
861          this.timing = new Timing();
862          return this.timing;
863        }
864        else if (name.equals("asNeededBoolean")) {
865          this.asNeeded = new BooleanType();
866          return this.asNeeded;
867        }
868        else if (name.equals("asNeededCodeableConcept")) {
869          this.asNeeded = new CodeableConcept();
870          return this.asNeeded;
871        }
872        else if (name.equals("site")) {
873          this.site = new CodeableConcept();
874          return this.site;
875        }
876        else if (name.equals("route")) {
877          this.route = new CodeableConcept();
878          return this.route;
879        }
880        else if (name.equals("method")) {
881          this.method = new CodeableConcept();
882          return this.method;
883        }
884        else if (name.equals("doseRange")) {
885          this.dose = new Range();
886          return this.dose;
887        }
888        else if (name.equals("doseSimpleQuantity")) {
889          this.dose = new SimpleQuantity();
890          return this.dose;
891        }
892        else if (name.equals("maxDosePerPeriod")) {
893          this.maxDosePerPeriod = new Ratio();
894          return this.maxDosePerPeriod;
895        }
896        else if (name.equals("maxDosePerAdministration")) {
897          this.maxDosePerAdministration = new SimpleQuantity();
898          return this.maxDosePerAdministration;
899        }
900        else if (name.equals("maxDosePerLifetime")) {
901          this.maxDosePerLifetime = new SimpleQuantity();
902          return this.maxDosePerLifetime;
903        }
904        else if (name.equals("rateRatio")) {
905          this.rate = new Ratio();
906          return this.rate;
907        }
908        else if (name.equals("rateRange")) {
909          this.rate = new Range();
910          return this.rate;
911        }
912        else if (name.equals("rateSimpleQuantity")) {
913          this.rate = new SimpleQuantity();
914          return this.rate;
915        }
916        else
917          return super.addChild(name);
918      }
919
920  public String fhirType() {
921    return "Dosage";
922
923  }
924
925      public Dosage copy() {
926        Dosage dst = new Dosage();
927        copyValues(dst);
928        dst.sequence = sequence == null ? null : sequence.copy();
929        dst.text = text == null ? null : text.copy();
930        if (additionalInstruction != null) {
931          dst.additionalInstruction = new ArrayList<CodeableConcept>();
932          for (CodeableConcept i : additionalInstruction)
933            dst.additionalInstruction.add(i.copy());
934        };
935        dst.patientInstruction = patientInstruction == null ? null : patientInstruction.copy();
936        dst.timing = timing == null ? null : timing.copy();
937        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
938        dst.site = site == null ? null : site.copy();
939        dst.route = route == null ? null : route.copy();
940        dst.method = method == null ? null : method.copy();
941        dst.dose = dose == null ? null : dose.copy();
942        dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
943        dst.maxDosePerAdministration = maxDosePerAdministration == null ? null : maxDosePerAdministration.copy();
944        dst.maxDosePerLifetime = maxDosePerLifetime == null ? null : maxDosePerLifetime.copy();
945        dst.rate = rate == null ? null : rate.copy();
946        return dst;
947      }
948
949      protected Dosage typedCopy() {
950        return copy();
951      }
952
953      @Override
954      public boolean equalsDeep(Base other) {
955        if (!super.equalsDeep(other))
956          return false;
957        if (!(other instanceof Dosage))
958          return false;
959        Dosage o = (Dosage) other;
960        return compareDeep(sequence, o.sequence, true) && compareDeep(text, o.text, true) && compareDeep(additionalInstruction, o.additionalInstruction, true)
961           && compareDeep(patientInstruction, o.patientInstruction, true) && compareDeep(timing, o.timing, true)
962           && compareDeep(asNeeded, o.asNeeded, true) && compareDeep(site, o.site, true) && compareDeep(route, o.route, true)
963           && compareDeep(method, o.method, true) && compareDeep(dose, o.dose, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true)
964           && compareDeep(maxDosePerAdministration, o.maxDosePerAdministration, true) && compareDeep(maxDosePerLifetime, o.maxDosePerLifetime, true)
965           && compareDeep(rate, o.rate, true);
966      }
967
968      @Override
969      public boolean equalsShallow(Base other) {
970        if (!super.equalsShallow(other))
971          return false;
972        if (!(other instanceof Dosage))
973          return false;
974        Dosage o = (Dosage) other;
975        return compareValues(sequence, o.sequence, true) && compareValues(text, o.text, true) && compareValues(patientInstruction, o.patientInstruction, true)
976          ;
977      }
978
979      public boolean isEmpty() {
980        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(sequence, text, additionalInstruction
981          , patientInstruction, timing, asNeeded, site, route, method, dose, maxDosePerPeriod
982          , maxDosePerAdministration, maxDosePerLifetime, rate);
983      }
984
985
986}
987