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