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