001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.ResourceDef;
044import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
045import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
046import org.hl7.fhir.exceptions.FHIRException;
047import org.hl7.fhir.utilities.Utilities;
048/**
049 * An order for both supply of the medication and the instructions for administration of the medication to a patient. The resource is called "MedicationOrder" rather than "MedicationPrescription" to generalize the use across inpatient and outpatient settings as well as for care plans, etc.
050 */
051@ResourceDef(name="MedicationOrder", profile="http://hl7.org/fhir/Profile/MedicationOrder")
052public class MedicationOrder extends DomainResource {
053
054    public enum MedicationOrderStatus {
055        /**
056         * The prescription is 'actionable', but not all actions that are implied by it have occurred yet.
057         */
058        ACTIVE, 
059        /**
060         * Actions implied by the prescription are to be temporarily halted, but are expected to continue later.  May also be called "suspended".
061         */
062        ONHOLD, 
063        /**
064         * All actions that are implied by the prescription have occurred.
065         */
066        COMPLETED, 
067        /**
068         * The prescription was entered in error.
069         */
070        ENTEREDINERROR, 
071        /**
072         * Actions implied by the prescription are to be permanently halted, before all of them occurred.
073         */
074        STOPPED, 
075        /**
076         * The prescription is not yet 'actionable', i.e. it is a work in progress, requires sign-off or verification, and needs to be run through decision support process.
077         */
078        DRAFT, 
079        /**
080         * added to help the parsers
081         */
082        NULL;
083        public static MedicationOrderStatus fromCode(String codeString) throws FHIRException {
084            if (codeString == null || "".equals(codeString))
085                return null;
086        if ("active".equals(codeString))
087          return ACTIVE;
088        if ("on-hold".equals(codeString))
089          return ONHOLD;
090        if ("completed".equals(codeString))
091          return COMPLETED;
092        if ("entered-in-error".equals(codeString))
093          return ENTEREDINERROR;
094        if ("stopped".equals(codeString))
095          return STOPPED;
096        if ("draft".equals(codeString))
097          return DRAFT;
098        throw new FHIRException("Unknown MedicationOrderStatus code '"+codeString+"'");
099        }
100        public String toCode() {
101          switch (this) {
102            case ACTIVE: return "active";
103            case ONHOLD: return "on-hold";
104            case COMPLETED: return "completed";
105            case ENTEREDINERROR: return "entered-in-error";
106            case STOPPED: return "stopped";
107            case DRAFT: return "draft";
108            case NULL: return null;
109            default: return "?";
110          }
111        }
112        public String getSystem() {
113          switch (this) {
114            case ACTIVE: return "http://hl7.org/fhir/medication-order-status";
115            case ONHOLD: return "http://hl7.org/fhir/medication-order-status";
116            case COMPLETED: return "http://hl7.org/fhir/medication-order-status";
117            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-order-status";
118            case STOPPED: return "http://hl7.org/fhir/medication-order-status";
119            case DRAFT: return "http://hl7.org/fhir/medication-order-status";
120            case NULL: return null;
121            default: return "?";
122          }
123        }
124        public String getDefinition() {
125          switch (this) {
126            case ACTIVE: return "The prescription is 'actionable', but not all actions that are implied by it have occurred yet.";
127            case ONHOLD: return "Actions implied by the prescription are to be temporarily halted, but are expected to continue later.  May also be called \"suspended\".";
128            case COMPLETED: return "All actions that are implied by the prescription have occurred.";
129            case ENTEREDINERROR: return "The prescription was entered in error.";
130            case STOPPED: return "Actions implied by the prescription are to be permanently halted, before all of them occurred.";
131            case DRAFT: return "The prescription is not yet 'actionable', i.e. it is a work in progress, requires sign-off or verification, and needs to be run through decision support process.";
132            case NULL: return null;
133            default: return "?";
134          }
135        }
136        public String getDisplay() {
137          switch (this) {
138            case ACTIVE: return "Active";
139            case ONHOLD: return "On Hold";
140            case COMPLETED: return "Completed";
141            case ENTEREDINERROR: return "Entered In Error";
142            case STOPPED: return "Stopped";
143            case DRAFT: return "Draft";
144            case NULL: return null;
145            default: return "?";
146          }
147        }
148    }
149
150  public static class MedicationOrderStatusEnumFactory implements EnumFactory<MedicationOrderStatus> {
151    public MedicationOrderStatus fromCode(String codeString) throws IllegalArgumentException {
152      if (codeString == null || "".equals(codeString))
153            if (codeString == null || "".equals(codeString))
154                return null;
155        if ("active".equals(codeString))
156          return MedicationOrderStatus.ACTIVE;
157        if ("on-hold".equals(codeString))
158          return MedicationOrderStatus.ONHOLD;
159        if ("completed".equals(codeString))
160          return MedicationOrderStatus.COMPLETED;
161        if ("entered-in-error".equals(codeString))
162          return MedicationOrderStatus.ENTEREDINERROR;
163        if ("stopped".equals(codeString))
164          return MedicationOrderStatus.STOPPED;
165        if ("draft".equals(codeString))
166          return MedicationOrderStatus.DRAFT;
167        throw new IllegalArgumentException("Unknown MedicationOrderStatus code '"+codeString+"'");
168        }
169        public Enumeration<MedicationOrderStatus> fromType(Base code) throws FHIRException {
170          if (code == null || code.isEmpty())
171            return null;
172          String codeString = ((PrimitiveType) code).asStringValue();
173          if (codeString == null || "".equals(codeString))
174            return null;
175        if ("active".equals(codeString))
176          return new Enumeration<MedicationOrderStatus>(this, MedicationOrderStatus.ACTIVE);
177        if ("on-hold".equals(codeString))
178          return new Enumeration<MedicationOrderStatus>(this, MedicationOrderStatus.ONHOLD);
179        if ("completed".equals(codeString))
180          return new Enumeration<MedicationOrderStatus>(this, MedicationOrderStatus.COMPLETED);
181        if ("entered-in-error".equals(codeString))
182          return new Enumeration<MedicationOrderStatus>(this, MedicationOrderStatus.ENTEREDINERROR);
183        if ("stopped".equals(codeString))
184          return new Enumeration<MedicationOrderStatus>(this, MedicationOrderStatus.STOPPED);
185        if ("draft".equals(codeString))
186          return new Enumeration<MedicationOrderStatus>(this, MedicationOrderStatus.DRAFT);
187        throw new FHIRException("Unknown MedicationOrderStatus code '"+codeString+"'");
188        }
189    public String toCode(MedicationOrderStatus code) {
190      if (code == MedicationOrderStatus.ACTIVE)
191        return "active";
192      if (code == MedicationOrderStatus.ONHOLD)
193        return "on-hold";
194      if (code == MedicationOrderStatus.COMPLETED)
195        return "completed";
196      if (code == MedicationOrderStatus.ENTEREDINERROR)
197        return "entered-in-error";
198      if (code == MedicationOrderStatus.STOPPED)
199        return "stopped";
200      if (code == MedicationOrderStatus.DRAFT)
201        return "draft";
202      return "?";
203      }
204    }
205
206    @Block()
207    public static class MedicationOrderDosageInstructionComponent extends BackboneElement implements IBaseBackboneElement {
208        /**
209         * Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing.
210         */
211        @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
212        @Description(shortDefinition="Dosage instructions expressed as text", formalDefinition="Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing." )
213        protected StringType text;
214
215        /**
216         * Additional instructions such as "Swallow with plenty of water" which may or may not be coded.
217         */
218        @Child(name = "additionalInstructions", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=true)
219        @Description(shortDefinition="Supplemental instructions - e.g. \"with meals\"", formalDefinition="Additional instructions such as \"Swallow with plenty of water\" which may or may not be coded." )
220        protected CodeableConcept additionalInstructions;
221
222        /**
223         * The timing schedule for giving the medication to the patient. The Schedule data type allows many different expressions. For example: "Every 8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:"; "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".
224         */
225        @Child(name = "timing", type = {Timing.class}, order=3, min=0, max=1, modifier=false, summary=true)
226        @Description(shortDefinition="When medication should be administered", formalDefinition="The timing schedule for giving the medication to the patient. The Schedule data type allows many different expressions. For example: \"Every 8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\"; \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\"." )
227        protected Timing timing;
228
229        /**
230         * 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).
231         */
232        @Child(name = "asNeeded", type = {BooleanType.class, CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
233        @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)." )
234        protected Type asNeeded;
235
236        /**
237         * A coded specification of the anatomic site where the medication first enters the body.
238         */
239        @Child(name = "site", type = {CodeableConcept.class, BodySite.class}, order=5, min=0, max=1, modifier=false, summary=true)
240        @Description(shortDefinition="Body site to administer to", formalDefinition="A coded specification of the anatomic site where the medication first enters the body." )
241        protected Type site;
242
243        /**
244         * A code specifying the route or physiological path of administration of a therapeutic agent into or onto a patient's body.
245         */
246        @Child(name = "route", type = {CodeableConcept.class}, order=6, min=0, max=1, modifier=false, summary=true)
247        @Description(shortDefinition="How drug should enter body", formalDefinition="A code specifying the route or physiological path of administration of a therapeutic agent into or onto a patient's body." )
248        protected CodeableConcept route;
249
250        /**
251         * A coded value indicating the method by which the medication is introduced into or onto the body. Most commonly used for injections.  For examples, Slow Push; Deep IV.
252         */
253        @Child(name = "method", type = {CodeableConcept.class}, order=7, min=0, max=1, modifier=false, summary=true)
254        @Description(shortDefinition="Technique for administering medication", formalDefinition="A coded value indicating the method by which the medication is introduced into or onto the body. Most commonly used for injections.  For examples, Slow Push; Deep IV." )
255        protected CodeableConcept method;
256
257        /**
258         * The amount of therapeutic or other substance given at one administration event.
259         */
260        @Child(name = "dose", type = {Range.class, SimpleQuantity.class}, order=8, min=0, max=1, modifier=false, summary=true)
261        @Description(shortDefinition="Amount of medication per dose", formalDefinition="The amount of therapeutic or other substance given at one administration event." )
262        protected Type dose;
263
264        /**
265         * Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.
266         */
267        @Child(name = "rate", type = {Ratio.class, Range.class}, order=9, min=0, max=1, modifier=false, summary=true)
268        @Description(shortDefinition="Amount of medication per unit of time", formalDefinition="Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours." )
269        protected Type rate;
270
271        /**
272         * The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.
273         */
274        @Child(name = "maxDosePerPeriod", type = {Ratio.class}, order=10, min=0, max=1, modifier=false, summary=true)
275        @Description(shortDefinition="Upper limit on medication per unit of time", formalDefinition="The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours." )
276        protected Ratio maxDosePerPeriod;
277
278        private static final long serialVersionUID = -1470136646L;
279
280    /*
281     * Constructor
282     */
283      public MedicationOrderDosageInstructionComponent() {
284        super();
285      }
286
287        /**
288         * @return {@link #text} (Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
289         */
290        public StringType getTextElement() { 
291          if (this.text == null)
292            if (Configuration.errorOnAutoCreate())
293              throw new Error("Attempt to auto-create MedicationOrderDosageInstructionComponent.text");
294            else if (Configuration.doAutoCreate())
295              this.text = new StringType(); // bb
296          return this.text;
297        }
298
299        public boolean hasTextElement() { 
300          return this.text != null && !this.text.isEmpty();
301        }
302
303        public boolean hasText() { 
304          return this.text != null && !this.text.isEmpty();
305        }
306
307        /**
308         * @param value {@link #text} (Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
309         */
310        public MedicationOrderDosageInstructionComponent setTextElement(StringType value) { 
311          this.text = value;
312          return this;
313        }
314
315        /**
316         * @return Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing.
317         */
318        public String getText() { 
319          return this.text == null ? null : this.text.getValue();
320        }
321
322        /**
323         * @param value Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing.
324         */
325        public MedicationOrderDosageInstructionComponent setText(String value) { 
326          if (Utilities.noString(value))
327            this.text = null;
328          else {
329            if (this.text == null)
330              this.text = new StringType();
331            this.text.setValue(value);
332          }
333          return this;
334        }
335
336        /**
337         * @return {@link #additionalInstructions} (Additional instructions such as "Swallow with plenty of water" which may or may not be coded.)
338         */
339        public CodeableConcept getAdditionalInstructions() { 
340          if (this.additionalInstructions == null)
341            if (Configuration.errorOnAutoCreate())
342              throw new Error("Attempt to auto-create MedicationOrderDosageInstructionComponent.additionalInstructions");
343            else if (Configuration.doAutoCreate())
344              this.additionalInstructions = new CodeableConcept(); // cc
345          return this.additionalInstructions;
346        }
347
348        public boolean hasAdditionalInstructions() { 
349          return this.additionalInstructions != null && !this.additionalInstructions.isEmpty();
350        }
351
352        /**
353         * @param value {@link #additionalInstructions} (Additional instructions such as "Swallow with plenty of water" which may or may not be coded.)
354         */
355        public MedicationOrderDosageInstructionComponent setAdditionalInstructions(CodeableConcept value) { 
356          this.additionalInstructions = value;
357          return this;
358        }
359
360        /**
361         * @return {@link #timing} (The timing schedule for giving the medication to the patient. The Schedule data type allows many different expressions. For example: "Every 8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:"; "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
362         */
363        public Timing getTiming() { 
364          if (this.timing == null)
365            if (Configuration.errorOnAutoCreate())
366              throw new Error("Attempt to auto-create MedicationOrderDosageInstructionComponent.timing");
367            else if (Configuration.doAutoCreate())
368              this.timing = new Timing(); // cc
369          return this.timing;
370        }
371
372        public boolean hasTiming() { 
373          return this.timing != null && !this.timing.isEmpty();
374        }
375
376        /**
377         * @param value {@link #timing} (The timing schedule for giving the medication to the patient. The Schedule data type allows many different expressions. For example: "Every 8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:"; "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
378         */
379        public MedicationOrderDosageInstructionComponent setTiming(Timing value) { 
380          this.timing = value;
381          return this;
382        }
383
384        /**
385         * @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).)
386         */
387        public Type getAsNeeded() { 
388          return this.asNeeded;
389        }
390
391        /**
392         * @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).)
393         */
394        public BooleanType getAsNeededBooleanType() throws FHIRException { 
395          if (!(this.asNeeded instanceof BooleanType))
396            throw new FHIRException("Type mismatch: the type BooleanType was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
397          return (BooleanType) this.asNeeded;
398        }
399
400        public boolean hasAsNeededBooleanType() { 
401          return this.asNeeded instanceof BooleanType;
402        }
403
404        /**
405         * @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).)
406         */
407        public CodeableConcept getAsNeededCodeableConcept() throws FHIRException { 
408          if (!(this.asNeeded instanceof CodeableConcept))
409            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
410          return (CodeableConcept) this.asNeeded;
411        }
412
413        public boolean hasAsNeededCodeableConcept() { 
414          return this.asNeeded instanceof CodeableConcept;
415        }
416
417        public boolean hasAsNeeded() { 
418          return this.asNeeded != null && !this.asNeeded.isEmpty();
419        }
420
421        /**
422         * @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).)
423         */
424        public MedicationOrderDosageInstructionComponent setAsNeeded(Type value) { 
425          this.asNeeded = value;
426          return this;
427        }
428
429        /**
430         * @return {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
431         */
432        public Type getSite() { 
433          return this.site;
434        }
435
436        /**
437         * @return {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
438         */
439        public CodeableConcept getSiteCodeableConcept() throws FHIRException { 
440          if (!(this.site instanceof CodeableConcept))
441            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.site.getClass().getName()+" was encountered");
442          return (CodeableConcept) this.site;
443        }
444
445        public boolean hasSiteCodeableConcept() { 
446          return this.site instanceof CodeableConcept;
447        }
448
449        /**
450         * @return {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
451         */
452        public Reference getSiteReference() throws FHIRException { 
453          if (!(this.site instanceof Reference))
454            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.site.getClass().getName()+" was encountered");
455          return (Reference) this.site;
456        }
457
458        public boolean hasSiteReference() { 
459          return this.site instanceof Reference;
460        }
461
462        public boolean hasSite() { 
463          return this.site != null && !this.site.isEmpty();
464        }
465
466        /**
467         * @param value {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
468         */
469        public MedicationOrderDosageInstructionComponent setSite(Type value) { 
470          this.site = value;
471          return this;
472        }
473
474        /**
475         * @return {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a patient's body.)
476         */
477        public CodeableConcept getRoute() { 
478          if (this.route == null)
479            if (Configuration.errorOnAutoCreate())
480              throw new Error("Attempt to auto-create MedicationOrderDosageInstructionComponent.route");
481            else if (Configuration.doAutoCreate())
482              this.route = new CodeableConcept(); // cc
483          return this.route;
484        }
485
486        public boolean hasRoute() { 
487          return this.route != null && !this.route.isEmpty();
488        }
489
490        /**
491         * @param value {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a patient's body.)
492         */
493        public MedicationOrderDosageInstructionComponent setRoute(CodeableConcept value) { 
494          this.route = value;
495          return this;
496        }
497
498        /**
499         * @return {@link #method} (A coded value indicating the method by which the medication is introduced into or onto the body. Most commonly used for injections.  For examples, Slow Push; Deep IV.)
500         */
501        public CodeableConcept getMethod() { 
502          if (this.method == null)
503            if (Configuration.errorOnAutoCreate())
504              throw new Error("Attempt to auto-create MedicationOrderDosageInstructionComponent.method");
505            else if (Configuration.doAutoCreate())
506              this.method = new CodeableConcept(); // cc
507          return this.method;
508        }
509
510        public boolean hasMethod() { 
511          return this.method != null && !this.method.isEmpty();
512        }
513
514        /**
515         * @param value {@link #method} (A coded value indicating the method by which the medication is introduced into or onto the body. Most commonly used for injections.  For examples, Slow Push; Deep IV.)
516         */
517        public MedicationOrderDosageInstructionComponent setMethod(CodeableConcept value) { 
518          this.method = value;
519          return this;
520        }
521
522        /**
523         * @return {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
524         */
525        public Type getDose() { 
526          return this.dose;
527        }
528
529        /**
530         * @return {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
531         */
532        public Range getDoseRange() throws FHIRException { 
533          if (!(this.dose instanceof Range))
534            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.dose.getClass().getName()+" was encountered");
535          return (Range) this.dose;
536        }
537
538        public boolean hasDoseRange() { 
539          return this.dose instanceof Range;
540        }
541
542        /**
543         * @return {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
544         */
545        public SimpleQuantity getDoseSimpleQuantity() throws FHIRException { 
546          if (!(this.dose instanceof SimpleQuantity))
547            throw new FHIRException("Type mismatch: the type SimpleQuantity was expected, but "+this.dose.getClass().getName()+" was encountered");
548          return (SimpleQuantity) this.dose;
549        }
550
551        public boolean hasDoseSimpleQuantity() { 
552          return this.dose instanceof SimpleQuantity;
553        }
554
555        public boolean hasDose() { 
556          return this.dose != null && !this.dose.isEmpty();
557        }
558
559        /**
560         * @param value {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
561         */
562        public MedicationOrderDosageInstructionComponent setDose(Type value) { 
563          this.dose = value;
564          return this;
565        }
566
567        /**
568         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
569         */
570        public Type getRate() { 
571          return this.rate;
572        }
573
574        /**
575         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
576         */
577        public Ratio getRateRatio() throws FHIRException { 
578          if (!(this.rate instanceof Ratio))
579            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
580          return (Ratio) this.rate;
581        }
582
583        public boolean hasRateRatio() { 
584          return this.rate instanceof Ratio;
585        }
586
587        /**
588         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
589         */
590        public Range getRateRange() throws FHIRException { 
591          if (!(this.rate instanceof Range))
592            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
593          return (Range) this.rate;
594        }
595
596        public boolean hasRateRange() { 
597          return this.rate instanceof Range;
598        }
599
600        public boolean hasRate() { 
601          return this.rate != null && !this.rate.isEmpty();
602        }
603
604        /**
605         * @param value {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
606         */
607        public MedicationOrderDosageInstructionComponent setRate(Type value) { 
608          this.rate = value;
609          return this;
610        }
611
612        /**
613         * @return {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.)
614         */
615        public Ratio getMaxDosePerPeriod() { 
616          if (this.maxDosePerPeriod == null)
617            if (Configuration.errorOnAutoCreate())
618              throw new Error("Attempt to auto-create MedicationOrderDosageInstructionComponent.maxDosePerPeriod");
619            else if (Configuration.doAutoCreate())
620              this.maxDosePerPeriod = new Ratio(); // cc
621          return this.maxDosePerPeriod;
622        }
623
624        public boolean hasMaxDosePerPeriod() { 
625          return this.maxDosePerPeriod != null && !this.maxDosePerPeriod.isEmpty();
626        }
627
628        /**
629         * @param value {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.)
630         */
631        public MedicationOrderDosageInstructionComponent setMaxDosePerPeriod(Ratio value) { 
632          this.maxDosePerPeriod = value;
633          return this;
634        }
635
636        protected void listChildren(List<Property> childrenList) {
637          super.listChildren(childrenList);
638          childrenList.add(new Property("text", "string", "Free text dosage instructions can be used for cases where the instructions are too complex to code.  The content of this attribute does not include the name or description of the medication. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication. It is expected that the text instructions will always be populated.  If the dosage.timing attribute is also populated, then the dosage.text should reflect the same information as the timing.", 0, java.lang.Integer.MAX_VALUE, text));
639          childrenList.add(new Property("additionalInstructions", "CodeableConcept", "Additional instructions such as \"Swallow with plenty of water\" which may or may not be coded.", 0, java.lang.Integer.MAX_VALUE, additionalInstructions));
640          childrenList.add(new Property("timing", "Timing", "The timing schedule for giving the medication to the patient. The Schedule data type allows many different expressions. For example: \"Every 8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\"; \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\".", 0, java.lang.Integer.MAX_VALUE, timing));
641          childrenList.add(new Property("asNeeded[x]", "boolean|CodeableConcept", "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).", 0, java.lang.Integer.MAX_VALUE, asNeeded));
642          childrenList.add(new Property("site[x]", "CodeableConcept|Reference(BodySite)", "A coded specification of the anatomic site where the medication first enters the body.", 0, java.lang.Integer.MAX_VALUE, site));
643          childrenList.add(new Property("route", "CodeableConcept", "A code specifying the route or physiological path of administration of a therapeutic agent into or onto a patient's body.", 0, java.lang.Integer.MAX_VALUE, route));
644          childrenList.add(new Property("method", "CodeableConcept", "A coded value indicating the method by which the medication is introduced into or onto the body. Most commonly used for injections.  For examples, Slow Push; Deep IV.", 0, java.lang.Integer.MAX_VALUE, method));
645          childrenList.add(new Property("dose[x]", "Range|SimpleQuantity", "The amount of therapeutic or other substance given at one administration event.", 0, java.lang.Integer.MAX_VALUE, dose));
646          childrenList.add(new Property("rate[x]", "Ratio|Range", "Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.", 0, java.lang.Integer.MAX_VALUE, rate));
647          childrenList.add(new Property("maxDosePerPeriod", "Ratio", "The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod));
648        }
649
650      @Override
651      public void setProperty(String name, Base value) throws FHIRException {
652        if (name.equals("text"))
653          this.text = castToString(value); // StringType
654        else if (name.equals("additionalInstructions"))
655          this.additionalInstructions = castToCodeableConcept(value); // CodeableConcept
656        else if (name.equals("timing"))
657          this.timing = castToTiming(value); // Timing
658        else if (name.equals("asNeeded[x]"))
659          this.asNeeded = (Type) value; // Type
660        else if (name.equals("site[x]"))
661          this.site = (Type) value; // Type
662        else if (name.equals("route"))
663          this.route = castToCodeableConcept(value); // CodeableConcept
664        else if (name.equals("method"))
665          this.method = castToCodeableConcept(value); // CodeableConcept
666        else if (name.equals("dose[x]"))
667          this.dose = (Type) value; // Type
668        else if (name.equals("rate[x]"))
669          this.rate = (Type) value; // Type
670        else if (name.equals("maxDosePerPeriod"))
671          this.maxDosePerPeriod = castToRatio(value); // Ratio
672        else
673          super.setProperty(name, value);
674      }
675
676      @Override
677      public Base addChild(String name) throws FHIRException {
678        if (name.equals("text")) {
679          throw new FHIRException("Cannot call addChild on a primitive type MedicationOrder.text");
680        }
681        else if (name.equals("additionalInstructions")) {
682          this.additionalInstructions = new CodeableConcept();
683          return this.additionalInstructions;
684        }
685        else if (name.equals("timing")) {
686          this.timing = new Timing();
687          return this.timing;
688        }
689        else if (name.equals("asNeededBoolean")) {
690          this.asNeeded = new BooleanType();
691          return this.asNeeded;
692        }
693        else if (name.equals("asNeededCodeableConcept")) {
694          this.asNeeded = new CodeableConcept();
695          return this.asNeeded;
696        }
697        else if (name.equals("siteCodeableConcept")) {
698          this.site = new CodeableConcept();
699          return this.site;
700        }
701        else if (name.equals("siteReference")) {
702          this.site = new Reference();
703          return this.site;
704        }
705        else if (name.equals("route")) {
706          this.route = new CodeableConcept();
707          return this.route;
708        }
709        else if (name.equals("method")) {
710          this.method = new CodeableConcept();
711          return this.method;
712        }
713        else if (name.equals("doseRange")) {
714          this.dose = new Range();
715          return this.dose;
716        }
717        else if (name.equals("doseSimpleQuantity")) {
718          this.dose = new SimpleQuantity();
719          return this.dose;
720        }
721        else if (name.equals("rateRatio")) {
722          this.rate = new Ratio();
723          return this.rate;
724        }
725        else if (name.equals("rateRange")) {
726          this.rate = new Range();
727          return this.rate;
728        }
729        else if (name.equals("maxDosePerPeriod")) {
730          this.maxDosePerPeriod = new Ratio();
731          return this.maxDosePerPeriod;
732        }
733        else
734          return super.addChild(name);
735      }
736
737      public MedicationOrderDosageInstructionComponent copy() {
738        MedicationOrderDosageInstructionComponent dst = new MedicationOrderDosageInstructionComponent();
739        copyValues(dst);
740        dst.text = text == null ? null : text.copy();
741        dst.additionalInstructions = additionalInstructions == null ? null : additionalInstructions.copy();
742        dst.timing = timing == null ? null : timing.copy();
743        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
744        dst.site = site == null ? null : site.copy();
745        dst.route = route == null ? null : route.copy();
746        dst.method = method == null ? null : method.copy();
747        dst.dose = dose == null ? null : dose.copy();
748        dst.rate = rate == null ? null : rate.copy();
749        dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
750        return dst;
751      }
752
753      @Override
754      public boolean equalsDeep(Base other) {
755        if (!super.equalsDeep(other))
756          return false;
757        if (!(other instanceof MedicationOrderDosageInstructionComponent))
758          return false;
759        MedicationOrderDosageInstructionComponent o = (MedicationOrderDosageInstructionComponent) other;
760        return compareDeep(text, o.text, true) && compareDeep(additionalInstructions, o.additionalInstructions, true)
761           && compareDeep(timing, o.timing, true) && compareDeep(asNeeded, o.asNeeded, true) && compareDeep(site, o.site, true)
762           && compareDeep(route, o.route, true) && compareDeep(method, o.method, true) && compareDeep(dose, o.dose, true)
763           && compareDeep(rate, o.rate, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true);
764      }
765
766      @Override
767      public boolean equalsShallow(Base other) {
768        if (!super.equalsShallow(other))
769          return false;
770        if (!(other instanceof MedicationOrderDosageInstructionComponent))
771          return false;
772        MedicationOrderDosageInstructionComponent o = (MedicationOrderDosageInstructionComponent) other;
773        return compareValues(text, o.text, true);
774      }
775
776      public boolean isEmpty() {
777        return super.isEmpty() && (text == null || text.isEmpty()) && (additionalInstructions == null || additionalInstructions.isEmpty())
778           && (timing == null || timing.isEmpty()) && (asNeeded == null || asNeeded.isEmpty()) && (site == null || site.isEmpty())
779           && (route == null || route.isEmpty()) && (method == null || method.isEmpty()) && (dose == null || dose.isEmpty())
780           && (rate == null || rate.isEmpty()) && (maxDosePerPeriod == null || maxDosePerPeriod.isEmpty())
781          ;
782      }
783
784  public String fhirType() {
785    return "MedicationOrder.dosageInstruction";
786
787  }
788
789  }
790
791    @Block()
792    public static class MedicationOrderDispenseRequestComponent extends BackboneElement implements IBaseBackboneElement {
793        /**
794         * Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.
795         */
796        @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=1, min=0, max=1, modifier=false, summary=true)
797        @Description(shortDefinition="Product to be supplied", formalDefinition="Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications." )
798        protected Type medication;
799
800        /**
801         * This indicates the validity period of a prescription (stale dating the Prescription).
802         */
803        @Child(name = "validityPeriod", type = {Period.class}, order=2, min=0, max=1, modifier=false, summary=true)
804        @Description(shortDefinition="Time period supply is authorized for", formalDefinition="This indicates the validity period of a prescription (stale dating the Prescription)." )
805        protected Period validityPeriod;
806
807        /**
808         * An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  "3 repeats", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets.
809         */
810        @Child(name = "numberOfRepeatsAllowed", type = {PositiveIntType.class}, order=3, min=0, max=1, modifier=false, summary=true)
811        @Description(shortDefinition="Number of refills authorized", formalDefinition="An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  \"3 repeats\", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets." )
812        protected PositiveIntType numberOfRepeatsAllowed;
813
814        /**
815         * The amount that is to be dispensed for one fill.
816         */
817        @Child(name = "quantity", type = {SimpleQuantity.class}, order=4, min=0, max=1, modifier=false, summary=true)
818        @Description(shortDefinition="Amount of medication to supply per dispense", formalDefinition="The amount that is to be dispensed for one fill." )
819        protected SimpleQuantity quantity;
820
821        /**
822         * Identifies the period time over which the supplied product is expected to be used, or the length of time the dispense is expected to last.
823         */
824        @Child(name = "expectedSupplyDuration", type = {Duration.class}, order=5, min=0, max=1, modifier=false, summary=true)
825        @Description(shortDefinition="Number of days supply per dispense", formalDefinition="Identifies the period time over which the supplied product is expected to be used, or the length of time the dispense is expected to last." )
826        protected Duration expectedSupplyDuration;
827
828        private static final long serialVersionUID = -1690502728L;
829
830    /*
831     * Constructor
832     */
833      public MedicationOrderDispenseRequestComponent() {
834        super();
835      }
836
837        /**
838         * @return {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
839         */
840        public Type getMedication() { 
841          return this.medication;
842        }
843
844        /**
845         * @return {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
846         */
847        public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
848          if (!(this.medication instanceof CodeableConcept))
849            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
850          return (CodeableConcept) this.medication;
851        }
852
853        public boolean hasMedicationCodeableConcept() { 
854          return this.medication instanceof CodeableConcept;
855        }
856
857        /**
858         * @return {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
859         */
860        public Reference getMedicationReference() throws FHIRException { 
861          if (!(this.medication instanceof Reference))
862            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
863          return (Reference) this.medication;
864        }
865
866        public boolean hasMedicationReference() { 
867          return this.medication instanceof Reference;
868        }
869
870        public boolean hasMedication() { 
871          return this.medication != null && !this.medication.isEmpty();
872        }
873
874        /**
875         * @param value {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
876         */
877        public MedicationOrderDispenseRequestComponent setMedication(Type value) { 
878          this.medication = value;
879          return this;
880        }
881
882        /**
883         * @return {@link #validityPeriod} (This indicates the validity period of a prescription (stale dating the Prescription).)
884         */
885        public Period getValidityPeriod() { 
886          if (this.validityPeriod == null)
887            if (Configuration.errorOnAutoCreate())
888              throw new Error("Attempt to auto-create MedicationOrderDispenseRequestComponent.validityPeriod");
889            else if (Configuration.doAutoCreate())
890              this.validityPeriod = new Period(); // cc
891          return this.validityPeriod;
892        }
893
894        public boolean hasValidityPeriod() { 
895          return this.validityPeriod != null && !this.validityPeriod.isEmpty();
896        }
897
898        /**
899         * @param value {@link #validityPeriod} (This indicates the validity period of a prescription (stale dating the Prescription).)
900         */
901        public MedicationOrderDispenseRequestComponent setValidityPeriod(Period value) { 
902          this.validityPeriod = value;
903          return this;
904        }
905
906        /**
907         * @return {@link #numberOfRepeatsAllowed} (An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  "3 repeats", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets.). This is the underlying object with id, value and extensions. The accessor "getNumberOfRepeatsAllowed" gives direct access to the value
908         */
909        public PositiveIntType getNumberOfRepeatsAllowedElement() { 
910          if (this.numberOfRepeatsAllowed == null)
911            if (Configuration.errorOnAutoCreate())
912              throw new Error("Attempt to auto-create MedicationOrderDispenseRequestComponent.numberOfRepeatsAllowed");
913            else if (Configuration.doAutoCreate())
914              this.numberOfRepeatsAllowed = new PositiveIntType(); // bb
915          return this.numberOfRepeatsAllowed;
916        }
917
918        public boolean hasNumberOfRepeatsAllowedElement() { 
919          return this.numberOfRepeatsAllowed != null && !this.numberOfRepeatsAllowed.isEmpty();
920        }
921
922        public boolean hasNumberOfRepeatsAllowed() { 
923          return this.numberOfRepeatsAllowed != null && !this.numberOfRepeatsAllowed.isEmpty();
924        }
925
926        /**
927         * @param value {@link #numberOfRepeatsAllowed} (An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  "3 repeats", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets.). This is the underlying object with id, value and extensions. The accessor "getNumberOfRepeatsAllowed" gives direct access to the value
928         */
929        public MedicationOrderDispenseRequestComponent setNumberOfRepeatsAllowedElement(PositiveIntType value) { 
930          this.numberOfRepeatsAllowed = value;
931          return this;
932        }
933
934        /**
935         * @return An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  "3 repeats", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets.
936         */
937        public int getNumberOfRepeatsAllowed() { 
938          return this.numberOfRepeatsAllowed == null || this.numberOfRepeatsAllowed.isEmpty() ? 0 : this.numberOfRepeatsAllowed.getValue();
939        }
940
941        /**
942         * @param value An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  "3 repeats", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets.
943         */
944        public MedicationOrderDispenseRequestComponent setNumberOfRepeatsAllowed(int value) { 
945            if (this.numberOfRepeatsAllowed == null)
946              this.numberOfRepeatsAllowed = new PositiveIntType();
947            this.numberOfRepeatsAllowed.setValue(value);
948          return this;
949        }
950
951        /**
952         * @return {@link #quantity} (The amount that is to be dispensed for one fill.)
953         */
954        public SimpleQuantity getQuantity() { 
955          if (this.quantity == null)
956            if (Configuration.errorOnAutoCreate())
957              throw new Error("Attempt to auto-create MedicationOrderDispenseRequestComponent.quantity");
958            else if (Configuration.doAutoCreate())
959              this.quantity = new SimpleQuantity(); // cc
960          return this.quantity;
961        }
962
963        public boolean hasQuantity() { 
964          return this.quantity != null && !this.quantity.isEmpty();
965        }
966
967        /**
968         * @param value {@link #quantity} (The amount that is to be dispensed for one fill.)
969         */
970        public MedicationOrderDispenseRequestComponent setQuantity(SimpleQuantity value) { 
971          this.quantity = value;
972          return this;
973        }
974
975        /**
976         * @return {@link #expectedSupplyDuration} (Identifies the period time over which the supplied product is expected to be used, or the length of time the dispense is expected to last.)
977         */
978        public Duration getExpectedSupplyDuration() { 
979          if (this.expectedSupplyDuration == null)
980            if (Configuration.errorOnAutoCreate())
981              throw new Error("Attempt to auto-create MedicationOrderDispenseRequestComponent.expectedSupplyDuration");
982            else if (Configuration.doAutoCreate())
983              this.expectedSupplyDuration = new Duration(); // cc
984          return this.expectedSupplyDuration;
985        }
986
987        public boolean hasExpectedSupplyDuration() { 
988          return this.expectedSupplyDuration != null && !this.expectedSupplyDuration.isEmpty();
989        }
990
991        /**
992         * @param value {@link #expectedSupplyDuration} (Identifies the period time over which the supplied product is expected to be used, or the length of time the dispense is expected to last.)
993         */
994        public MedicationOrderDispenseRequestComponent setExpectedSupplyDuration(Duration value) { 
995          this.expectedSupplyDuration = value;
996          return this;
997        }
998
999        protected void listChildren(List<Property> childrenList) {
1000          super.listChildren(childrenList);
1001          childrenList.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.", 0, java.lang.Integer.MAX_VALUE, medication));
1002          childrenList.add(new Property("validityPeriod", "Period", "This indicates the validity period of a prescription (stale dating the Prescription).", 0, java.lang.Integer.MAX_VALUE, validityPeriod));
1003          childrenList.add(new Property("numberOfRepeatsAllowed", "positiveInt", "An integer indicating the number of additional times (aka refills or repeats) the patient can receive the prescribed medication.   Usage Notes: This integer does NOT include the original order dispense.   This means that if an order indicates dispense 30 tablets plus  \"3 repeats\", then the order can be dispensed a total of 4 times and the patient can receive a total of 120 tablets.", 0, java.lang.Integer.MAX_VALUE, numberOfRepeatsAllowed));
1004          childrenList.add(new Property("quantity", "SimpleQuantity", "The amount that is to be dispensed for one fill.", 0, java.lang.Integer.MAX_VALUE, quantity));
1005          childrenList.add(new Property("expectedSupplyDuration", "Duration", "Identifies the period time over which the supplied product is expected to be used, or the length of time the dispense is expected to last.", 0, java.lang.Integer.MAX_VALUE, expectedSupplyDuration));
1006        }
1007
1008      @Override
1009      public void setProperty(String name, Base value) throws FHIRException {
1010        if (name.equals("medication[x]"))
1011          this.medication = (Type) value; // Type
1012        else if (name.equals("validityPeriod"))
1013          this.validityPeriod = castToPeriod(value); // Period
1014        else if (name.equals("numberOfRepeatsAllowed"))
1015          this.numberOfRepeatsAllowed = castToPositiveInt(value); // PositiveIntType
1016        else if (name.equals("quantity"))
1017          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
1018        else if (name.equals("expectedSupplyDuration"))
1019          this.expectedSupplyDuration = castToDuration(value); // Duration
1020        else
1021          super.setProperty(name, value);
1022      }
1023
1024      @Override
1025      public Base addChild(String name) throws FHIRException {
1026        if (name.equals("medicationCodeableConcept")) {
1027          this.medication = new CodeableConcept();
1028          return this.medication;
1029        }
1030        else if (name.equals("medicationReference")) {
1031          this.medication = new Reference();
1032          return this.medication;
1033        }
1034        else if (name.equals("validityPeriod")) {
1035          this.validityPeriod = new Period();
1036          return this.validityPeriod;
1037        }
1038        else if (name.equals("numberOfRepeatsAllowed")) {
1039          throw new FHIRException("Cannot call addChild on a primitive type MedicationOrder.numberOfRepeatsAllowed");
1040        }
1041        else if (name.equals("quantity")) {
1042          this.quantity = new SimpleQuantity();
1043          return this.quantity;
1044        }
1045        else if (name.equals("expectedSupplyDuration")) {
1046          this.expectedSupplyDuration = new Duration();
1047          return this.expectedSupplyDuration;
1048        }
1049        else
1050          return super.addChild(name);
1051      }
1052
1053      public MedicationOrderDispenseRequestComponent copy() {
1054        MedicationOrderDispenseRequestComponent dst = new MedicationOrderDispenseRequestComponent();
1055        copyValues(dst);
1056        dst.medication = medication == null ? null : medication.copy();
1057        dst.validityPeriod = validityPeriod == null ? null : validityPeriod.copy();
1058        dst.numberOfRepeatsAllowed = numberOfRepeatsAllowed == null ? null : numberOfRepeatsAllowed.copy();
1059        dst.quantity = quantity == null ? null : quantity.copy();
1060        dst.expectedSupplyDuration = expectedSupplyDuration == null ? null : expectedSupplyDuration.copy();
1061        return dst;
1062      }
1063
1064      @Override
1065      public boolean equalsDeep(Base other) {
1066        if (!super.equalsDeep(other))
1067          return false;
1068        if (!(other instanceof MedicationOrderDispenseRequestComponent))
1069          return false;
1070        MedicationOrderDispenseRequestComponent o = (MedicationOrderDispenseRequestComponent) other;
1071        return compareDeep(medication, o.medication, true) && compareDeep(validityPeriod, o.validityPeriod, true)
1072           && compareDeep(numberOfRepeatsAllowed, o.numberOfRepeatsAllowed, true) && compareDeep(quantity, o.quantity, true)
1073           && compareDeep(expectedSupplyDuration, o.expectedSupplyDuration, true);
1074      }
1075
1076      @Override
1077      public boolean equalsShallow(Base other) {
1078        if (!super.equalsShallow(other))
1079          return false;
1080        if (!(other instanceof MedicationOrderDispenseRequestComponent))
1081          return false;
1082        MedicationOrderDispenseRequestComponent o = (MedicationOrderDispenseRequestComponent) other;
1083        return compareValues(numberOfRepeatsAllowed, o.numberOfRepeatsAllowed, true);
1084      }
1085
1086      public boolean isEmpty() {
1087        return super.isEmpty() && (medication == null || medication.isEmpty()) && (validityPeriod == null || validityPeriod.isEmpty())
1088           && (numberOfRepeatsAllowed == null || numberOfRepeatsAllowed.isEmpty()) && (quantity == null || quantity.isEmpty())
1089           && (expectedSupplyDuration == null || expectedSupplyDuration.isEmpty());
1090      }
1091
1092  public String fhirType() {
1093    return "MedicationOrder.dispenseRequest";
1094
1095  }
1096
1097  }
1098
1099    @Block()
1100    public static class MedicationOrderSubstitutionComponent extends BackboneElement implements IBaseBackboneElement {
1101        /**
1102         * A code signifying whether a different drug should be dispensed from what was prescribed.
1103         */
1104        @Child(name = "type", type = {CodeableConcept.class}, order=1, min=1, max=1, modifier=false, summary=true)
1105        @Description(shortDefinition="generic | formulary +", formalDefinition="A code signifying whether a different drug should be dispensed from what was prescribed." )
1106        protected CodeableConcept type;
1107
1108        /**
1109         * Indicates the reason for the substitution, or why substitution must or must not be performed.
1110         */
1111        @Child(name = "reason", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=true)
1112        @Description(shortDefinition="Why should (not) substitution be made", formalDefinition="Indicates the reason for the substitution, or why substitution must or must not be performed." )
1113        protected CodeableConcept reason;
1114
1115        private static final long serialVersionUID = 1693602518L;
1116
1117    /*
1118     * Constructor
1119     */
1120      public MedicationOrderSubstitutionComponent() {
1121        super();
1122      }
1123
1124    /*
1125     * Constructor
1126     */
1127      public MedicationOrderSubstitutionComponent(CodeableConcept type) {
1128        super();
1129        this.type = type;
1130      }
1131
1132        /**
1133         * @return {@link #type} (A code signifying whether a different drug should be dispensed from what was prescribed.)
1134         */
1135        public CodeableConcept getType() { 
1136          if (this.type == null)
1137            if (Configuration.errorOnAutoCreate())
1138              throw new Error("Attempt to auto-create MedicationOrderSubstitutionComponent.type");
1139            else if (Configuration.doAutoCreate())
1140              this.type = new CodeableConcept(); // cc
1141          return this.type;
1142        }
1143
1144        public boolean hasType() { 
1145          return this.type != null && !this.type.isEmpty();
1146        }
1147
1148        /**
1149         * @param value {@link #type} (A code signifying whether a different drug should be dispensed from what was prescribed.)
1150         */
1151        public MedicationOrderSubstitutionComponent setType(CodeableConcept value) { 
1152          this.type = value;
1153          return this;
1154        }
1155
1156        /**
1157         * @return {@link #reason} (Indicates the reason for the substitution, or why substitution must or must not be performed.)
1158         */
1159        public CodeableConcept getReason() { 
1160          if (this.reason == null)
1161            if (Configuration.errorOnAutoCreate())
1162              throw new Error("Attempt to auto-create MedicationOrderSubstitutionComponent.reason");
1163            else if (Configuration.doAutoCreate())
1164              this.reason = new CodeableConcept(); // cc
1165          return this.reason;
1166        }
1167
1168        public boolean hasReason() { 
1169          return this.reason != null && !this.reason.isEmpty();
1170        }
1171
1172        /**
1173         * @param value {@link #reason} (Indicates the reason for the substitution, or why substitution must or must not be performed.)
1174         */
1175        public MedicationOrderSubstitutionComponent setReason(CodeableConcept value) { 
1176          this.reason = value;
1177          return this;
1178        }
1179
1180        protected void listChildren(List<Property> childrenList) {
1181          super.listChildren(childrenList);
1182          childrenList.add(new Property("type", "CodeableConcept", "A code signifying whether a different drug should be dispensed from what was prescribed.", 0, java.lang.Integer.MAX_VALUE, type));
1183          childrenList.add(new Property("reason", "CodeableConcept", "Indicates the reason for the substitution, or why substitution must or must not be performed.", 0, java.lang.Integer.MAX_VALUE, reason));
1184        }
1185
1186      @Override
1187      public void setProperty(String name, Base value) throws FHIRException {
1188        if (name.equals("type"))
1189          this.type = castToCodeableConcept(value); // CodeableConcept
1190        else if (name.equals("reason"))
1191          this.reason = castToCodeableConcept(value); // CodeableConcept
1192        else
1193          super.setProperty(name, value);
1194      }
1195
1196      @Override
1197      public Base addChild(String name) throws FHIRException {
1198        if (name.equals("type")) {
1199          this.type = new CodeableConcept();
1200          return this.type;
1201        }
1202        else if (name.equals("reason")) {
1203          this.reason = new CodeableConcept();
1204          return this.reason;
1205        }
1206        else
1207          return super.addChild(name);
1208      }
1209
1210      public MedicationOrderSubstitutionComponent copy() {
1211        MedicationOrderSubstitutionComponent dst = new MedicationOrderSubstitutionComponent();
1212        copyValues(dst);
1213        dst.type = type == null ? null : type.copy();
1214        dst.reason = reason == null ? null : reason.copy();
1215        return dst;
1216      }
1217
1218      @Override
1219      public boolean equalsDeep(Base other) {
1220        if (!super.equalsDeep(other))
1221          return false;
1222        if (!(other instanceof MedicationOrderSubstitutionComponent))
1223          return false;
1224        MedicationOrderSubstitutionComponent o = (MedicationOrderSubstitutionComponent) other;
1225        return compareDeep(type, o.type, true) && compareDeep(reason, o.reason, true);
1226      }
1227
1228      @Override
1229      public boolean equalsShallow(Base other) {
1230        if (!super.equalsShallow(other))
1231          return false;
1232        if (!(other instanceof MedicationOrderSubstitutionComponent))
1233          return false;
1234        MedicationOrderSubstitutionComponent o = (MedicationOrderSubstitutionComponent) other;
1235        return true;
1236      }
1237
1238      public boolean isEmpty() {
1239        return super.isEmpty() && (type == null || type.isEmpty()) && (reason == null || reason.isEmpty())
1240          ;
1241      }
1242
1243  public String fhirType() {
1244    return "MedicationOrder.substitution";
1245
1246  }
1247
1248  }
1249
1250    /**
1251     * External identifier - one that would be used by another non-FHIR system - for example a re-imbursement system might issue its own id for each prescription that is created.  This is particularly important where FHIR only provides part of an entire workflow process where records have to be tracked through an entire system.
1252     */
1253    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1254    @Description(shortDefinition="External identifier", formalDefinition="External identifier - one that would be used by another non-FHIR system - for example a re-imbursement system might issue its own id for each prescription that is created.  This is particularly important where FHIR only provides part of an entire workflow process where records have to be tracked through an entire system." )
1255    protected List<Identifier> identifier;
1256
1257    /**
1258     * The date (and perhaps time) when the prescription was written.
1259     */
1260    @Child(name = "dateWritten", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
1261    @Description(shortDefinition="When prescription was authorized", formalDefinition="The date (and perhaps time) when the prescription was written." )
1262    protected DateTimeType dateWritten;
1263
1264    /**
1265     * A code specifying the state of the order.  Generally this will be active or completed state.
1266     */
1267    @Child(name = "status", type = {CodeType.class}, order=2, min=0, max=1, modifier=true, summary=true)
1268    @Description(shortDefinition="active | on-hold | completed | entered-in-error | stopped | draft", formalDefinition="A code specifying the state of the order.  Generally this will be active or completed state." )
1269    protected Enumeration<MedicationOrderStatus> status;
1270
1271    /**
1272     * The date (and perhaps time) when the prescription was stopped.
1273     */
1274    @Child(name = "dateEnded", type = {DateTimeType.class}, order=3, min=0, max=1, modifier=false, summary=true)
1275    @Description(shortDefinition="When prescription was stopped", formalDefinition="The date (and perhaps time) when the prescription was stopped." )
1276    protected DateTimeType dateEnded;
1277
1278    /**
1279     * The reason why the prescription was stopped, if it was.
1280     */
1281    @Child(name = "reasonEnded", type = {CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
1282    @Description(shortDefinition="Why prescription was stopped", formalDefinition="The reason why the prescription was stopped, if it was." )
1283    protected CodeableConcept reasonEnded;
1284
1285    /**
1286     * A link to a resource representing the person to whom the medication will be given.
1287     */
1288    @Child(name = "patient", type = {Patient.class}, order=5, min=0, max=1, modifier=false, summary=true)
1289    @Description(shortDefinition="Who prescription is for", formalDefinition="A link to a resource representing the person to whom the medication will be given." )
1290    protected Reference patient;
1291
1292    /**
1293     * The actual object that is the target of the reference (A link to a resource representing the person to whom the medication will be given.)
1294     */
1295    protected Patient patientTarget;
1296
1297    /**
1298     * The healthcare professional responsible for authorizing the prescription.
1299     */
1300    @Child(name = "prescriber", type = {Practitioner.class}, order=6, min=0, max=1, modifier=false, summary=true)
1301    @Description(shortDefinition="Who ordered the medication(s)", formalDefinition="The healthcare professional responsible for authorizing the prescription." )
1302    protected Reference prescriber;
1303
1304    /**
1305     * The actual object that is the target of the reference (The healthcare professional responsible for authorizing the prescription.)
1306     */
1307    protected Practitioner prescriberTarget;
1308
1309    /**
1310     * A link to a resource that identifies the particular occurrence of contact between patient and health care provider.
1311     */
1312    @Child(name = "encounter", type = {Encounter.class}, order=7, min=0, max=1, modifier=false, summary=true)
1313    @Description(shortDefinition="Created during encounter/admission/stay", formalDefinition="A link to a resource that identifies the particular occurrence of contact between patient and health care provider." )
1314    protected Reference encounter;
1315
1316    /**
1317     * The actual object that is the target of the reference (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1318     */
1319    protected Encounter encounterTarget;
1320
1321    /**
1322     * Can be the reason or the indication for writing the prescription.
1323     */
1324    @Child(name = "reason", type = {CodeableConcept.class, Condition.class}, order=8, min=0, max=1, modifier=false, summary=true)
1325    @Description(shortDefinition="Reason or indication for writing the prescription", formalDefinition="Can be the reason or the indication for writing the prescription." )
1326    protected Type reason;
1327
1328    /**
1329     * Extra information about the prescription that could not be conveyed by the other attributes.
1330     */
1331    @Child(name = "note", type = {StringType.class}, order=9, min=0, max=1, modifier=false, summary=true)
1332    @Description(shortDefinition="Information about the prescription", formalDefinition="Extra information about the prescription that could not be conveyed by the other attributes." )
1333    protected StringType note;
1334
1335    /**
1336     * Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.
1337     */
1338    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=10, min=1, max=1, modifier=false, summary=true)
1339    @Description(shortDefinition="Medication to be taken", formalDefinition="Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications." )
1340    protected Type medication;
1341
1342    /**
1343     * Indicates how the medication is to be used by the patient.
1344     */
1345    @Child(name = "dosageInstruction", type = {}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1346    @Description(shortDefinition="How medication should be taken", formalDefinition="Indicates how the medication is to be used by the patient." )
1347    protected List<MedicationOrderDosageInstructionComponent> dosageInstruction;
1348
1349    /**
1350     * Indicates the specific details for the dispense or medication supply part of a medication order (also known as a Medication Prescription).  Note that this information is NOT always sent with the order.  There may be in some settings (e.g. hospitals) institutional or system support for completing the dispense details in the pharmacy department.
1351     */
1352    @Child(name = "dispenseRequest", type = {}, order=12, min=0, max=1, modifier=false, summary=true)
1353    @Description(shortDefinition="Medication supply authorization", formalDefinition="Indicates the specific details for the dispense or medication supply part of a medication order (also known as a Medication Prescription).  Note that this information is NOT always sent with the order.  There may be in some settings (e.g. hospitals) institutional or system support for completing the dispense details in the pharmacy department." )
1354    protected MedicationOrderDispenseRequestComponent dispenseRequest;
1355
1356    /**
1357     * Indicates whether or not substitution can or should be part of the dispense. In some cases substitution must happen, in other cases substitution must not happen, and in others it does not matter. This block explains the prescriber's intent. If nothing is specified substitution may be done.
1358     */
1359    @Child(name = "substitution", type = {}, order=13, min=0, max=1, modifier=false, summary=true)
1360    @Description(shortDefinition="Any restrictions on medication substitution", formalDefinition="Indicates whether or not substitution can or should be part of the dispense. In some cases substitution must happen, in other cases substitution must not happen, and in others it does not matter. This block explains the prescriber's intent. If nothing is specified substitution may be done." )
1361    protected MedicationOrderSubstitutionComponent substitution;
1362
1363    /**
1364     * A link to a resource representing an earlier order or prescription that this order supersedes.
1365     */
1366    @Child(name = "priorPrescription", type = {MedicationOrder.class}, order=14, min=0, max=1, modifier=false, summary=true)
1367    @Description(shortDefinition="An order/prescription that this supersedes", formalDefinition="A link to a resource representing an earlier order or prescription that this order supersedes." )
1368    protected Reference priorPrescription;
1369
1370    /**
1371     * The actual object that is the target of the reference (A link to a resource representing an earlier order or prescription that this order supersedes.)
1372     */
1373    protected MedicationOrder priorPrescriptionTarget;
1374
1375    private static final long serialVersionUID = 619326051L;
1376
1377  /*
1378   * Constructor
1379   */
1380    public MedicationOrder() {
1381      super();
1382    }
1383
1384  /*
1385   * Constructor
1386   */
1387    public MedicationOrder(Type medication) {
1388      super();
1389      this.medication = medication;
1390    }
1391
1392    /**
1393     * @return {@link #identifier} (External identifier - one that would be used by another non-FHIR system - for example a re-imbursement system might issue its own id for each prescription that is created.  This is particularly important where FHIR only provides part of an entire workflow process where records have to be tracked through an entire system.)
1394     */
1395    public List<Identifier> getIdentifier() { 
1396      if (this.identifier == null)
1397        this.identifier = new ArrayList<Identifier>();
1398      return this.identifier;
1399    }
1400
1401    public boolean hasIdentifier() { 
1402      if (this.identifier == null)
1403        return false;
1404      for (Identifier item : this.identifier)
1405        if (!item.isEmpty())
1406          return true;
1407      return false;
1408    }
1409
1410    /**
1411     * @return {@link #identifier} (External identifier - one that would be used by another non-FHIR system - for example a re-imbursement system might issue its own id for each prescription that is created.  This is particularly important where FHIR only provides part of an entire workflow process where records have to be tracked through an entire system.)
1412     */
1413    // syntactic sugar
1414    public Identifier addIdentifier() { //3
1415      Identifier t = new Identifier();
1416      if (this.identifier == null)
1417        this.identifier = new ArrayList<Identifier>();
1418      this.identifier.add(t);
1419      return t;
1420    }
1421
1422    // syntactic sugar
1423    public MedicationOrder addIdentifier(Identifier t) { //3
1424      if (t == null)
1425        return this;
1426      if (this.identifier == null)
1427        this.identifier = new ArrayList<Identifier>();
1428      this.identifier.add(t);
1429      return this;
1430    }
1431
1432    /**
1433     * @return {@link #dateWritten} (The date (and perhaps time) when the prescription was written.). This is the underlying object with id, value and extensions. The accessor "getDateWritten" gives direct access to the value
1434     */
1435    public DateTimeType getDateWrittenElement() { 
1436      if (this.dateWritten == null)
1437        if (Configuration.errorOnAutoCreate())
1438          throw new Error("Attempt to auto-create MedicationOrder.dateWritten");
1439        else if (Configuration.doAutoCreate())
1440          this.dateWritten = new DateTimeType(); // bb
1441      return this.dateWritten;
1442    }
1443
1444    public boolean hasDateWrittenElement() { 
1445      return this.dateWritten != null && !this.dateWritten.isEmpty();
1446    }
1447
1448    public boolean hasDateWritten() { 
1449      return this.dateWritten != null && !this.dateWritten.isEmpty();
1450    }
1451
1452    /**
1453     * @param value {@link #dateWritten} (The date (and perhaps time) when the prescription was written.). This is the underlying object with id, value and extensions. The accessor "getDateWritten" gives direct access to the value
1454     */
1455    public MedicationOrder setDateWrittenElement(DateTimeType value) { 
1456      this.dateWritten = value;
1457      return this;
1458    }
1459
1460    /**
1461     * @return The date (and perhaps time) when the prescription was written.
1462     */
1463    public Date getDateWritten() { 
1464      return this.dateWritten == null ? null : this.dateWritten.getValue();
1465    }
1466
1467    /**
1468     * @param value The date (and perhaps time) when the prescription was written.
1469     */
1470    public MedicationOrder setDateWritten(Date value) { 
1471      if (value == null)
1472        this.dateWritten = null;
1473      else {
1474        if (this.dateWritten == null)
1475          this.dateWritten = new DateTimeType();
1476        this.dateWritten.setValue(value);
1477      }
1478      return this;
1479    }
1480
1481    /**
1482     * @return {@link #status} (A code specifying the state of the order.  Generally this will be active or completed state.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1483     */
1484    public Enumeration<MedicationOrderStatus> getStatusElement() { 
1485      if (this.status == null)
1486        if (Configuration.errorOnAutoCreate())
1487          throw new Error("Attempt to auto-create MedicationOrder.status");
1488        else if (Configuration.doAutoCreate())
1489          this.status = new Enumeration<MedicationOrderStatus>(new MedicationOrderStatusEnumFactory()); // bb
1490      return this.status;
1491    }
1492
1493    public boolean hasStatusElement() { 
1494      return this.status != null && !this.status.isEmpty();
1495    }
1496
1497    public boolean hasStatus() { 
1498      return this.status != null && !this.status.isEmpty();
1499    }
1500
1501    /**
1502     * @param value {@link #status} (A code specifying the state of the order.  Generally this will be active or completed state.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1503     */
1504    public MedicationOrder setStatusElement(Enumeration<MedicationOrderStatus> value) { 
1505      this.status = value;
1506      return this;
1507    }
1508
1509    /**
1510     * @return A code specifying the state of the order.  Generally this will be active or completed state.
1511     */
1512    public MedicationOrderStatus getStatus() { 
1513      return this.status == null ? null : this.status.getValue();
1514    }
1515
1516    /**
1517     * @param value A code specifying the state of the order.  Generally this will be active or completed state.
1518     */
1519    public MedicationOrder setStatus(MedicationOrderStatus value) { 
1520      if (value == null)
1521        this.status = null;
1522      else {
1523        if (this.status == null)
1524          this.status = new Enumeration<MedicationOrderStatus>(new MedicationOrderStatusEnumFactory());
1525        this.status.setValue(value);
1526      }
1527      return this;
1528    }
1529
1530    /**
1531     * @return {@link #dateEnded} (The date (and perhaps time) when the prescription was stopped.). This is the underlying object with id, value and extensions. The accessor "getDateEnded" gives direct access to the value
1532     */
1533    public DateTimeType getDateEndedElement() { 
1534      if (this.dateEnded == null)
1535        if (Configuration.errorOnAutoCreate())
1536          throw new Error("Attempt to auto-create MedicationOrder.dateEnded");
1537        else if (Configuration.doAutoCreate())
1538          this.dateEnded = new DateTimeType(); // bb
1539      return this.dateEnded;
1540    }
1541
1542    public boolean hasDateEndedElement() { 
1543      return this.dateEnded != null && !this.dateEnded.isEmpty();
1544    }
1545
1546    public boolean hasDateEnded() { 
1547      return this.dateEnded != null && !this.dateEnded.isEmpty();
1548    }
1549
1550    /**
1551     * @param value {@link #dateEnded} (The date (and perhaps time) when the prescription was stopped.). This is the underlying object with id, value and extensions. The accessor "getDateEnded" gives direct access to the value
1552     */
1553    public MedicationOrder setDateEndedElement(DateTimeType value) { 
1554      this.dateEnded = value;
1555      return this;
1556    }
1557
1558    /**
1559     * @return The date (and perhaps time) when the prescription was stopped.
1560     */
1561    public Date getDateEnded() { 
1562      return this.dateEnded == null ? null : this.dateEnded.getValue();
1563    }
1564
1565    /**
1566     * @param value The date (and perhaps time) when the prescription was stopped.
1567     */
1568    public MedicationOrder setDateEnded(Date value) { 
1569      if (value == null)
1570        this.dateEnded = null;
1571      else {
1572        if (this.dateEnded == null)
1573          this.dateEnded = new DateTimeType();
1574        this.dateEnded.setValue(value);
1575      }
1576      return this;
1577    }
1578
1579    /**
1580     * @return {@link #reasonEnded} (The reason why the prescription was stopped, if it was.)
1581     */
1582    public CodeableConcept getReasonEnded() { 
1583      if (this.reasonEnded == null)
1584        if (Configuration.errorOnAutoCreate())
1585          throw new Error("Attempt to auto-create MedicationOrder.reasonEnded");
1586        else if (Configuration.doAutoCreate())
1587          this.reasonEnded = new CodeableConcept(); // cc
1588      return this.reasonEnded;
1589    }
1590
1591    public boolean hasReasonEnded() { 
1592      return this.reasonEnded != null && !this.reasonEnded.isEmpty();
1593    }
1594
1595    /**
1596     * @param value {@link #reasonEnded} (The reason why the prescription was stopped, if it was.)
1597     */
1598    public MedicationOrder setReasonEnded(CodeableConcept value) { 
1599      this.reasonEnded = value;
1600      return this;
1601    }
1602
1603    /**
1604     * @return {@link #patient} (A link to a resource representing the person to whom the medication will be given.)
1605     */
1606    public Reference getPatient() { 
1607      if (this.patient == null)
1608        if (Configuration.errorOnAutoCreate())
1609          throw new Error("Attempt to auto-create MedicationOrder.patient");
1610        else if (Configuration.doAutoCreate())
1611          this.patient = new Reference(); // cc
1612      return this.patient;
1613    }
1614
1615    public boolean hasPatient() { 
1616      return this.patient != null && !this.patient.isEmpty();
1617    }
1618
1619    /**
1620     * @param value {@link #patient} (A link to a resource representing the person to whom the medication will be given.)
1621     */
1622    public MedicationOrder setPatient(Reference value) { 
1623      this.patient = value;
1624      return this;
1625    }
1626
1627    /**
1628     * @return {@link #patient} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (A link to a resource representing the person to whom the medication will be given.)
1629     */
1630    public Patient getPatientTarget() { 
1631      if (this.patientTarget == null)
1632        if (Configuration.errorOnAutoCreate())
1633          throw new Error("Attempt to auto-create MedicationOrder.patient");
1634        else if (Configuration.doAutoCreate())
1635          this.patientTarget = new Patient(); // aa
1636      return this.patientTarget;
1637    }
1638
1639    /**
1640     * @param value {@link #patient} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (A link to a resource representing the person to whom the medication will be given.)
1641     */
1642    public MedicationOrder setPatientTarget(Patient value) { 
1643      this.patientTarget = value;
1644      return this;
1645    }
1646
1647    /**
1648     * @return {@link #prescriber} (The healthcare professional responsible for authorizing the prescription.)
1649     */
1650    public Reference getPrescriber() { 
1651      if (this.prescriber == null)
1652        if (Configuration.errorOnAutoCreate())
1653          throw new Error("Attempt to auto-create MedicationOrder.prescriber");
1654        else if (Configuration.doAutoCreate())
1655          this.prescriber = new Reference(); // cc
1656      return this.prescriber;
1657    }
1658
1659    public boolean hasPrescriber() { 
1660      return this.prescriber != null && !this.prescriber.isEmpty();
1661    }
1662
1663    /**
1664     * @param value {@link #prescriber} (The healthcare professional responsible for authorizing the prescription.)
1665     */
1666    public MedicationOrder setPrescriber(Reference value) { 
1667      this.prescriber = value;
1668      return this;
1669    }
1670
1671    /**
1672     * @return {@link #prescriber} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The healthcare professional responsible for authorizing the prescription.)
1673     */
1674    public Practitioner getPrescriberTarget() { 
1675      if (this.prescriberTarget == null)
1676        if (Configuration.errorOnAutoCreate())
1677          throw new Error("Attempt to auto-create MedicationOrder.prescriber");
1678        else if (Configuration.doAutoCreate())
1679          this.prescriberTarget = new Practitioner(); // aa
1680      return this.prescriberTarget;
1681    }
1682
1683    /**
1684     * @param value {@link #prescriber} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The healthcare professional responsible for authorizing the prescription.)
1685     */
1686    public MedicationOrder setPrescriberTarget(Practitioner value) { 
1687      this.prescriberTarget = value;
1688      return this;
1689    }
1690
1691    /**
1692     * @return {@link #encounter} (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1693     */
1694    public Reference getEncounter() { 
1695      if (this.encounter == null)
1696        if (Configuration.errorOnAutoCreate())
1697          throw new Error("Attempt to auto-create MedicationOrder.encounter");
1698        else if (Configuration.doAutoCreate())
1699          this.encounter = new Reference(); // cc
1700      return this.encounter;
1701    }
1702
1703    public boolean hasEncounter() { 
1704      return this.encounter != null && !this.encounter.isEmpty();
1705    }
1706
1707    /**
1708     * @param value {@link #encounter} (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1709     */
1710    public MedicationOrder setEncounter(Reference value) { 
1711      this.encounter = value;
1712      return this;
1713    }
1714
1715    /**
1716     * @return {@link #encounter} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1717     */
1718    public Encounter getEncounterTarget() { 
1719      if (this.encounterTarget == null)
1720        if (Configuration.errorOnAutoCreate())
1721          throw new Error("Attempt to auto-create MedicationOrder.encounter");
1722        else if (Configuration.doAutoCreate())
1723          this.encounterTarget = new Encounter(); // aa
1724      return this.encounterTarget;
1725    }
1726
1727    /**
1728     * @param value {@link #encounter} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1729     */
1730    public MedicationOrder setEncounterTarget(Encounter value) { 
1731      this.encounterTarget = value;
1732      return this;
1733    }
1734
1735    /**
1736     * @return {@link #reason} (Can be the reason or the indication for writing the prescription.)
1737     */
1738    public Type getReason() { 
1739      return this.reason;
1740    }
1741
1742    /**
1743     * @return {@link #reason} (Can be the reason or the indication for writing the prescription.)
1744     */
1745    public CodeableConcept getReasonCodeableConcept() throws FHIRException { 
1746      if (!(this.reason instanceof CodeableConcept))
1747        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.reason.getClass().getName()+" was encountered");
1748      return (CodeableConcept) this.reason;
1749    }
1750
1751    public boolean hasReasonCodeableConcept() { 
1752      return this.reason instanceof CodeableConcept;
1753    }
1754
1755    /**
1756     * @return {@link #reason} (Can be the reason or the indication for writing the prescription.)
1757     */
1758    public Reference getReasonReference() throws FHIRException { 
1759      if (!(this.reason instanceof Reference))
1760        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.reason.getClass().getName()+" was encountered");
1761      return (Reference) this.reason;
1762    }
1763
1764    public boolean hasReasonReference() { 
1765      return this.reason instanceof Reference;
1766    }
1767
1768    public boolean hasReason() { 
1769      return this.reason != null && !this.reason.isEmpty();
1770    }
1771
1772    /**
1773     * @param value {@link #reason} (Can be the reason or the indication for writing the prescription.)
1774     */
1775    public MedicationOrder setReason(Type value) { 
1776      this.reason = value;
1777      return this;
1778    }
1779
1780    /**
1781     * @return {@link #note} (Extra information about the prescription that could not be conveyed by the other attributes.). This is the underlying object with id, value and extensions. The accessor "getNote" gives direct access to the value
1782     */
1783    public StringType getNoteElement() { 
1784      if (this.note == null)
1785        if (Configuration.errorOnAutoCreate())
1786          throw new Error("Attempt to auto-create MedicationOrder.note");
1787        else if (Configuration.doAutoCreate())
1788          this.note = new StringType(); // bb
1789      return this.note;
1790    }
1791
1792    public boolean hasNoteElement() { 
1793      return this.note != null && !this.note.isEmpty();
1794    }
1795
1796    public boolean hasNote() { 
1797      return this.note != null && !this.note.isEmpty();
1798    }
1799
1800    /**
1801     * @param value {@link #note} (Extra information about the prescription that could not be conveyed by the other attributes.). This is the underlying object with id, value and extensions. The accessor "getNote" gives direct access to the value
1802     */
1803    public MedicationOrder setNoteElement(StringType value) { 
1804      this.note = value;
1805      return this;
1806    }
1807
1808    /**
1809     * @return Extra information about the prescription that could not be conveyed by the other attributes.
1810     */
1811    public String getNote() { 
1812      return this.note == null ? null : this.note.getValue();
1813    }
1814
1815    /**
1816     * @param value Extra information about the prescription that could not be conveyed by the other attributes.
1817     */
1818    public MedicationOrder setNote(String value) { 
1819      if (Utilities.noString(value))
1820        this.note = null;
1821      else {
1822        if (this.note == null)
1823          this.note = new StringType();
1824        this.note.setValue(value);
1825      }
1826      return this;
1827    }
1828
1829    /**
1830     * @return {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
1831     */
1832    public Type getMedication() { 
1833      return this.medication;
1834    }
1835
1836    /**
1837     * @return {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
1838     */
1839    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1840      if (!(this.medication instanceof CodeableConcept))
1841        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1842      return (CodeableConcept) this.medication;
1843    }
1844
1845    public boolean hasMedicationCodeableConcept() { 
1846      return this.medication instanceof CodeableConcept;
1847    }
1848
1849    /**
1850     * @return {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
1851     */
1852    public Reference getMedicationReference() throws FHIRException { 
1853      if (!(this.medication instanceof Reference))
1854        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
1855      return (Reference) this.medication;
1856    }
1857
1858    public boolean hasMedicationReference() { 
1859      return this.medication instanceof Reference;
1860    }
1861
1862    public boolean hasMedication() { 
1863      return this.medication != null && !this.medication.isEmpty();
1864    }
1865
1866    /**
1867     * @param value {@link #medication} (Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.)
1868     */
1869    public MedicationOrder setMedication(Type value) { 
1870      this.medication = value;
1871      return this;
1872    }
1873
1874    /**
1875     * @return {@link #dosageInstruction} (Indicates how the medication is to be used by the patient.)
1876     */
1877    public List<MedicationOrderDosageInstructionComponent> getDosageInstruction() { 
1878      if (this.dosageInstruction == null)
1879        this.dosageInstruction = new ArrayList<MedicationOrderDosageInstructionComponent>();
1880      return this.dosageInstruction;
1881    }
1882
1883    public boolean hasDosageInstruction() { 
1884      if (this.dosageInstruction == null)
1885        return false;
1886      for (MedicationOrderDosageInstructionComponent item : this.dosageInstruction)
1887        if (!item.isEmpty())
1888          return true;
1889      return false;
1890    }
1891
1892    /**
1893     * @return {@link #dosageInstruction} (Indicates how the medication is to be used by the patient.)
1894     */
1895    // syntactic sugar
1896    public MedicationOrderDosageInstructionComponent addDosageInstruction() { //3
1897      MedicationOrderDosageInstructionComponent t = new MedicationOrderDosageInstructionComponent();
1898      if (this.dosageInstruction == null)
1899        this.dosageInstruction = new ArrayList<MedicationOrderDosageInstructionComponent>();
1900      this.dosageInstruction.add(t);
1901      return t;
1902    }
1903
1904    // syntactic sugar
1905    public MedicationOrder addDosageInstruction(MedicationOrderDosageInstructionComponent t) { //3
1906      if (t == null)
1907        return this;
1908      if (this.dosageInstruction == null)
1909        this.dosageInstruction = new ArrayList<MedicationOrderDosageInstructionComponent>();
1910      this.dosageInstruction.add(t);
1911      return this;
1912    }
1913
1914    /**
1915     * @return {@link #dispenseRequest} (Indicates the specific details for the dispense or medication supply part of a medication order (also known as a Medication Prescription).  Note that this information is NOT always sent with the order.  There may be in some settings (e.g. hospitals) institutional or system support for completing the dispense details in the pharmacy department.)
1916     */
1917    public MedicationOrderDispenseRequestComponent getDispenseRequest() { 
1918      if (this.dispenseRequest == null)
1919        if (Configuration.errorOnAutoCreate())
1920          throw new Error("Attempt to auto-create MedicationOrder.dispenseRequest");
1921        else if (Configuration.doAutoCreate())
1922          this.dispenseRequest = new MedicationOrderDispenseRequestComponent(); // cc
1923      return this.dispenseRequest;
1924    }
1925
1926    public boolean hasDispenseRequest() { 
1927      return this.dispenseRequest != null && !this.dispenseRequest.isEmpty();
1928    }
1929
1930    /**
1931     * @param value {@link #dispenseRequest} (Indicates the specific details for the dispense or medication supply part of a medication order (also known as a Medication Prescription).  Note that this information is NOT always sent with the order.  There may be in some settings (e.g. hospitals) institutional or system support for completing the dispense details in the pharmacy department.)
1932     */
1933    public MedicationOrder setDispenseRequest(MedicationOrderDispenseRequestComponent value) { 
1934      this.dispenseRequest = value;
1935      return this;
1936    }
1937
1938    /**
1939     * @return {@link #substitution} (Indicates whether or not substitution can or should be part of the dispense. In some cases substitution must happen, in other cases substitution must not happen, and in others it does not matter. This block explains the prescriber's intent. If nothing is specified substitution may be done.)
1940     */
1941    public MedicationOrderSubstitutionComponent getSubstitution() { 
1942      if (this.substitution == null)
1943        if (Configuration.errorOnAutoCreate())
1944          throw new Error("Attempt to auto-create MedicationOrder.substitution");
1945        else if (Configuration.doAutoCreate())
1946          this.substitution = new MedicationOrderSubstitutionComponent(); // cc
1947      return this.substitution;
1948    }
1949
1950    public boolean hasSubstitution() { 
1951      return this.substitution != null && !this.substitution.isEmpty();
1952    }
1953
1954    /**
1955     * @param value {@link #substitution} (Indicates whether or not substitution can or should be part of the dispense. In some cases substitution must happen, in other cases substitution must not happen, and in others it does not matter. This block explains the prescriber's intent. If nothing is specified substitution may be done.)
1956     */
1957    public MedicationOrder setSubstitution(MedicationOrderSubstitutionComponent value) { 
1958      this.substitution = value;
1959      return this;
1960    }
1961
1962    /**
1963     * @return {@link #priorPrescription} (A link to a resource representing an earlier order or prescription that this order supersedes.)
1964     */
1965    public Reference getPriorPrescription() { 
1966      if (this.priorPrescription == null)
1967        if (Configuration.errorOnAutoCreate())
1968          throw new Error("Attempt to auto-create MedicationOrder.priorPrescription");
1969        else if (Configuration.doAutoCreate())
1970          this.priorPrescription = new Reference(); // cc
1971      return this.priorPrescription;
1972    }
1973
1974    public boolean hasPriorPrescription() { 
1975      return this.priorPrescription != null && !this.priorPrescription.isEmpty();
1976    }
1977
1978    /**
1979     * @param value {@link #priorPrescription} (A link to a resource representing an earlier order or prescription that this order supersedes.)
1980     */
1981    public MedicationOrder setPriorPrescription(Reference value) { 
1982      this.priorPrescription = value;
1983      return this;
1984    }
1985
1986    /**
1987     * @return {@link #priorPrescription} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (A link to a resource representing an earlier order or prescription that this order supersedes.)
1988     */
1989    public MedicationOrder getPriorPrescriptionTarget() { 
1990      if (this.priorPrescriptionTarget == null)
1991        if (Configuration.errorOnAutoCreate())
1992          throw new Error("Attempt to auto-create MedicationOrder.priorPrescription");
1993        else if (Configuration.doAutoCreate())
1994          this.priorPrescriptionTarget = new MedicationOrder(); // aa
1995      return this.priorPrescriptionTarget;
1996    }
1997
1998    /**
1999     * @param value {@link #priorPrescription} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (A link to a resource representing an earlier order or prescription that this order supersedes.)
2000     */
2001    public MedicationOrder setPriorPrescriptionTarget(MedicationOrder value) { 
2002      this.priorPrescriptionTarget = value;
2003      return this;
2004    }
2005
2006      protected void listChildren(List<Property> childrenList) {
2007        super.listChildren(childrenList);
2008        childrenList.add(new Property("identifier", "Identifier", "External identifier - one that would be used by another non-FHIR system - for example a re-imbursement system might issue its own id for each prescription that is created.  This is particularly important where FHIR only provides part of an entire workflow process where records have to be tracked through an entire system.", 0, java.lang.Integer.MAX_VALUE, identifier));
2009        childrenList.add(new Property("dateWritten", "dateTime", "The date (and perhaps time) when the prescription was written.", 0, java.lang.Integer.MAX_VALUE, dateWritten));
2010        childrenList.add(new Property("status", "code", "A code specifying the state of the order.  Generally this will be active or completed state.", 0, java.lang.Integer.MAX_VALUE, status));
2011        childrenList.add(new Property("dateEnded", "dateTime", "The date (and perhaps time) when the prescription was stopped.", 0, java.lang.Integer.MAX_VALUE, dateEnded));
2012        childrenList.add(new Property("reasonEnded", "CodeableConcept", "The reason why the prescription was stopped, if it was.", 0, java.lang.Integer.MAX_VALUE, reasonEnded));
2013        childrenList.add(new Property("patient", "Reference(Patient)", "A link to a resource representing the person to whom the medication will be given.", 0, java.lang.Integer.MAX_VALUE, patient));
2014        childrenList.add(new Property("prescriber", "Reference(Practitioner)", "The healthcare professional responsible for authorizing the prescription.", 0, java.lang.Integer.MAX_VALUE, prescriber));
2015        childrenList.add(new Property("encounter", "Reference(Encounter)", "A link to a resource that identifies the particular occurrence of contact between patient and health care provider.", 0, java.lang.Integer.MAX_VALUE, encounter));
2016        childrenList.add(new Property("reason[x]", "CodeableConcept|Reference(Condition)", "Can be the reason or the indication for writing the prescription.", 0, java.lang.Integer.MAX_VALUE, reason));
2017        childrenList.add(new Property("note", "string", "Extra information about the prescription that could not be conveyed by the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
2018        childrenList.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being administered. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.", 0, java.lang.Integer.MAX_VALUE, medication));
2019        childrenList.add(new Property("dosageInstruction", "", "Indicates how the medication is to be used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosageInstruction));
2020        childrenList.add(new Property("dispenseRequest", "", "Indicates the specific details for the dispense or medication supply part of a medication order (also known as a Medication Prescription).  Note that this information is NOT always sent with the order.  There may be in some settings (e.g. hospitals) institutional or system support for completing the dispense details in the pharmacy department.", 0, java.lang.Integer.MAX_VALUE, dispenseRequest));
2021        childrenList.add(new Property("substitution", "", "Indicates whether or not substitution can or should be part of the dispense. In some cases substitution must happen, in other cases substitution must not happen, and in others it does not matter. This block explains the prescriber's intent. If nothing is specified substitution may be done.", 0, java.lang.Integer.MAX_VALUE, substitution));
2022        childrenList.add(new Property("priorPrescription", "Reference(MedicationOrder)", "A link to a resource representing an earlier order or prescription that this order supersedes.", 0, java.lang.Integer.MAX_VALUE, priorPrescription));
2023      }
2024
2025      @Override
2026      public void setProperty(String name, Base value) throws FHIRException {
2027        if (name.equals("identifier"))
2028          this.getIdentifier().add(castToIdentifier(value));
2029        else if (name.equals("dateWritten"))
2030          this.dateWritten = castToDateTime(value); // DateTimeType
2031        else if (name.equals("status"))
2032          this.status = new MedicationOrderStatusEnumFactory().fromType(value); // Enumeration<MedicationOrderStatus>
2033        else if (name.equals("dateEnded"))
2034          this.dateEnded = castToDateTime(value); // DateTimeType
2035        else if (name.equals("reasonEnded"))
2036          this.reasonEnded = castToCodeableConcept(value); // CodeableConcept
2037        else if (name.equals("patient"))
2038          this.patient = castToReference(value); // Reference
2039        else if (name.equals("prescriber"))
2040          this.prescriber = castToReference(value); // Reference
2041        else if (name.equals("encounter"))
2042          this.encounter = castToReference(value); // Reference
2043        else if (name.equals("reason[x]"))
2044          this.reason = (Type) value; // Type
2045        else if (name.equals("note"))
2046          this.note = castToString(value); // StringType
2047        else if (name.equals("medication[x]"))
2048          this.medication = (Type) value; // Type
2049        else if (name.equals("dosageInstruction"))
2050          this.getDosageInstruction().add((MedicationOrderDosageInstructionComponent) value);
2051        else if (name.equals("dispenseRequest"))
2052          this.dispenseRequest = (MedicationOrderDispenseRequestComponent) value; // MedicationOrderDispenseRequestComponent
2053        else if (name.equals("substitution"))
2054          this.substitution = (MedicationOrderSubstitutionComponent) value; // MedicationOrderSubstitutionComponent
2055        else if (name.equals("priorPrescription"))
2056          this.priorPrescription = castToReference(value); // Reference
2057        else
2058          super.setProperty(name, value);
2059      }
2060
2061      @Override
2062      public Base addChild(String name) throws FHIRException {
2063        if (name.equals("identifier")) {
2064          return addIdentifier();
2065        }
2066        else if (name.equals("dateWritten")) {
2067          throw new FHIRException("Cannot call addChild on a primitive type MedicationOrder.dateWritten");
2068        }
2069        else if (name.equals("status")) {
2070          throw new FHIRException("Cannot call addChild on a primitive type MedicationOrder.status");
2071        }
2072        else if (name.equals("dateEnded")) {
2073          throw new FHIRException("Cannot call addChild on a primitive type MedicationOrder.dateEnded");
2074        }
2075        else if (name.equals("reasonEnded")) {
2076          this.reasonEnded = new CodeableConcept();
2077          return this.reasonEnded;
2078        }
2079        else if (name.equals("patient")) {
2080          this.patient = new Reference();
2081          return this.patient;
2082        }
2083        else if (name.equals("prescriber")) {
2084          this.prescriber = new Reference();
2085          return this.prescriber;
2086        }
2087        else if (name.equals("encounter")) {
2088          this.encounter = new Reference();
2089          return this.encounter;
2090        }
2091        else if (name.equals("reasonCodeableConcept")) {
2092          this.reason = new CodeableConcept();
2093          return this.reason;
2094        }
2095        else if (name.equals("reasonReference")) {
2096          this.reason = new Reference();
2097          return this.reason;
2098        }
2099        else if (name.equals("note")) {
2100          throw new FHIRException("Cannot call addChild on a primitive type MedicationOrder.note");
2101        }
2102        else if (name.equals("medicationCodeableConcept")) {
2103          this.medication = new CodeableConcept();
2104          return this.medication;
2105        }
2106        else if (name.equals("medicationReference")) {
2107          this.medication = new Reference();
2108          return this.medication;
2109        }
2110        else if (name.equals("dosageInstruction")) {
2111          return addDosageInstruction();
2112        }
2113        else if (name.equals("dispenseRequest")) {
2114          this.dispenseRequest = new MedicationOrderDispenseRequestComponent();
2115          return this.dispenseRequest;
2116        }
2117        else if (name.equals("substitution")) {
2118          this.substitution = new MedicationOrderSubstitutionComponent();
2119          return this.substitution;
2120        }
2121        else if (name.equals("priorPrescription")) {
2122          this.priorPrescription = new Reference();
2123          return this.priorPrescription;
2124        }
2125        else
2126          return super.addChild(name);
2127      }
2128
2129  public String fhirType() {
2130    return "MedicationOrder";
2131
2132  }
2133
2134      public MedicationOrder copy() {
2135        MedicationOrder dst = new MedicationOrder();
2136        copyValues(dst);
2137        if (identifier != null) {
2138          dst.identifier = new ArrayList<Identifier>();
2139          for (Identifier i : identifier)
2140            dst.identifier.add(i.copy());
2141        };
2142        dst.dateWritten = dateWritten == null ? null : dateWritten.copy();
2143        dst.status = status == null ? null : status.copy();
2144        dst.dateEnded = dateEnded == null ? null : dateEnded.copy();
2145        dst.reasonEnded = reasonEnded == null ? null : reasonEnded.copy();
2146        dst.patient = patient == null ? null : patient.copy();
2147        dst.prescriber = prescriber == null ? null : prescriber.copy();
2148        dst.encounter = encounter == null ? null : encounter.copy();
2149        dst.reason = reason == null ? null : reason.copy();
2150        dst.note = note == null ? null : note.copy();
2151        dst.medication = medication == null ? null : medication.copy();
2152        if (dosageInstruction != null) {
2153          dst.dosageInstruction = new ArrayList<MedicationOrderDosageInstructionComponent>();
2154          for (MedicationOrderDosageInstructionComponent i : dosageInstruction)
2155            dst.dosageInstruction.add(i.copy());
2156        };
2157        dst.dispenseRequest = dispenseRequest == null ? null : dispenseRequest.copy();
2158        dst.substitution = substitution == null ? null : substitution.copy();
2159        dst.priorPrescription = priorPrescription == null ? null : priorPrescription.copy();
2160        return dst;
2161      }
2162
2163      protected MedicationOrder typedCopy() {
2164        return copy();
2165      }
2166
2167      @Override
2168      public boolean equalsDeep(Base other) {
2169        if (!super.equalsDeep(other))
2170          return false;
2171        if (!(other instanceof MedicationOrder))
2172          return false;
2173        MedicationOrder o = (MedicationOrder) other;
2174        return compareDeep(identifier, o.identifier, true) && compareDeep(dateWritten, o.dateWritten, true)
2175           && compareDeep(status, o.status, true) && compareDeep(dateEnded, o.dateEnded, true) && compareDeep(reasonEnded, o.reasonEnded, true)
2176           && compareDeep(patient, o.patient, true) && compareDeep(prescriber, o.prescriber, true) && compareDeep(encounter, o.encounter, true)
2177           && compareDeep(reason, o.reason, true) && compareDeep(note, o.note, true) && compareDeep(medication, o.medication, true)
2178           && compareDeep(dosageInstruction, o.dosageInstruction, true) && compareDeep(dispenseRequest, o.dispenseRequest, true)
2179           && compareDeep(substitution, o.substitution, true) && compareDeep(priorPrescription, o.priorPrescription, true)
2180          ;
2181      }
2182
2183      @Override
2184      public boolean equalsShallow(Base other) {
2185        if (!super.equalsShallow(other))
2186          return false;
2187        if (!(other instanceof MedicationOrder))
2188          return false;
2189        MedicationOrder o = (MedicationOrder) other;
2190        return compareValues(dateWritten, o.dateWritten, true) && compareValues(status, o.status, true) && compareValues(dateEnded, o.dateEnded, true)
2191           && compareValues(note, o.note, true);
2192      }
2193
2194      public boolean isEmpty() {
2195        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (dateWritten == null || dateWritten.isEmpty())
2196           && (status == null || status.isEmpty()) && (dateEnded == null || dateEnded.isEmpty()) && (reasonEnded == null || reasonEnded.isEmpty())
2197           && (patient == null || patient.isEmpty()) && (prescriber == null || prescriber.isEmpty())
2198           && (encounter == null || encounter.isEmpty()) && (reason == null || reason.isEmpty()) && (note == null || note.isEmpty())
2199           && (medication == null || medication.isEmpty()) && (dosageInstruction == null || dosageInstruction.isEmpty())
2200           && (dispenseRequest == null || dispenseRequest.isEmpty()) && (substitution == null || substitution.isEmpty())
2201           && (priorPrescription == null || priorPrescription.isEmpty());
2202      }
2203
2204  @Override
2205  public ResourceType getResourceType() {
2206    return ResourceType.MedicationOrder;
2207   }
2208
2209  @SearchParamDefinition(name="prescriber", path="MedicationOrder.prescriber", description="Who ordered the medication(s)", type="reference" )
2210  public static final String SP_PRESCRIBER = "prescriber";
2211  @SearchParamDefinition(name="identifier", path="MedicationOrder.identifier", description="Return prescriptions with this external identifier", type="token" )
2212  public static final String SP_IDENTIFIER = "identifier";
2213  @SearchParamDefinition(name="code", path="MedicationOrder.medicationCodeableConcept", description="Return administrations of this medication code", type="token" )
2214  public static final String SP_CODE = "code";
2215  @SearchParamDefinition(name="patient", path="MedicationOrder.patient", description="The identity of a patient to list orders  for", type="reference" )
2216  public static final String SP_PATIENT = "patient";
2217  @SearchParamDefinition(name="datewritten", path="MedicationOrder.dateWritten", description="Return prescriptions written on this date", type="date" )
2218  public static final String SP_DATEWRITTEN = "datewritten";
2219  @SearchParamDefinition(name="medication", path="MedicationOrder.medicationReference", description="Return administrations of this medication reference", type="reference" )
2220  public static final String SP_MEDICATION = "medication";
2221  @SearchParamDefinition(name="encounter", path="MedicationOrder.encounter", description="Return prescriptions with this encounter identifier", type="reference" )
2222  public static final String SP_ENCOUNTER = "encounter";
2223  @SearchParamDefinition(name="status", path="MedicationOrder.status", description="Status of the prescription", type="token" )
2224  public static final String SP_STATUS = "status";
2225
2226}