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