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