001package org.hl7.fhir.dstu3.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.x
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.exceptions.FHIRFormatError;
042import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
043
044import ca.uhn.fhir.model.api.annotation.Block;
045import ca.uhn.fhir.model.api.annotation.Child;
046import ca.uhn.fhir.model.api.annotation.Description;
047import ca.uhn.fhir.model.api.annotation.ResourceDef;
048import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
049/**
050 * An order or request for both supply of the medication and the instructions for administration of the medication to a patient. The resource is called "MedicationRequest" rather than "MedicationPrescription" or "MedicationOrder" to generalize the use across inpatient and outpatient settings, including care plans, etc., and to harmonize with workflow patterns.
051 */
052@ResourceDef(name="MedicationRequest", profile="http://hl7.org/fhir/Profile/MedicationRequest")
053public class MedicationRequest extends DomainResource {
054
055    public enum MedicationRequestStatus {
056        /**
057         * The prescription is 'actionable', but not all actions that are implied by it have occurred yet.
058         */
059        ACTIVE, 
060        /**
061         * Actions implied by the prescription are to be temporarily halted, but are expected to continue later.  May also be called "suspended".
062         */
063        ONHOLD, 
064        /**
065         * The prescription has been withdrawn.
066         */
067        CANCELLED, 
068        /**
069         * All actions that are implied by the prescription have occurred.
070         */
071        COMPLETED, 
072        /**
073         * The prescription was entered in error.
074         */
075        ENTEREDINERROR, 
076        /**
077         * Actions implied by the prescription are to be permanently halted, before all of them occurred.
078         */
079        STOPPED, 
080        /**
081         * 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.
082         */
083        DRAFT, 
084        /**
085         * The authoring system does not know which of the status values currently applies for this request
086         */
087        UNKNOWN, 
088        /**
089         * added to help the parsers with the generic types
090         */
091        NULL;
092        public static MedicationRequestStatus fromCode(String codeString) throws FHIRException {
093            if (codeString == null || "".equals(codeString))
094                return null;
095        if ("active".equals(codeString))
096          return ACTIVE;
097        if ("on-hold".equals(codeString))
098          return ONHOLD;
099        if ("cancelled".equals(codeString))
100          return CANCELLED;
101        if ("completed".equals(codeString))
102          return COMPLETED;
103        if ("entered-in-error".equals(codeString))
104          return ENTEREDINERROR;
105        if ("stopped".equals(codeString))
106          return STOPPED;
107        if ("draft".equals(codeString))
108          return DRAFT;
109        if ("unknown".equals(codeString))
110          return UNKNOWN;
111        if (Configuration.isAcceptInvalidEnums())
112          return null;
113        else
114          throw new FHIRException("Unknown MedicationRequestStatus code '"+codeString+"'");
115        }
116        public String toCode() {
117          switch (this) {
118            case ACTIVE: return "active";
119            case ONHOLD: return "on-hold";
120            case CANCELLED: return "cancelled";
121            case COMPLETED: return "completed";
122            case ENTEREDINERROR: return "entered-in-error";
123            case STOPPED: return "stopped";
124            case DRAFT: return "draft";
125            case UNKNOWN: return "unknown";
126            case NULL: return null;
127            default: return "?";
128          }
129        }
130        public String getSystem() {
131          switch (this) {
132            case ACTIVE: return "http://hl7.org/fhir/medication-request-status";
133            case ONHOLD: return "http://hl7.org/fhir/medication-request-status";
134            case CANCELLED: return "http://hl7.org/fhir/medication-request-status";
135            case COMPLETED: return "http://hl7.org/fhir/medication-request-status";
136            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-request-status";
137            case STOPPED: return "http://hl7.org/fhir/medication-request-status";
138            case DRAFT: return "http://hl7.org/fhir/medication-request-status";
139            case UNKNOWN: return "http://hl7.org/fhir/medication-request-status";
140            case NULL: return null;
141            default: return "?";
142          }
143        }
144        public String getDefinition() {
145          switch (this) {
146            case ACTIVE: return "The prescription is 'actionable', but not all actions that are implied by it have occurred yet.";
147            case ONHOLD: return "Actions implied by the prescription are to be temporarily halted, but are expected to continue later.  May also be called \"suspended\".";
148            case CANCELLED: return "The prescription has been withdrawn.";
149            case COMPLETED: return "All actions that are implied by the prescription have occurred.";
150            case ENTEREDINERROR: return "The prescription was entered in error.";
151            case STOPPED: return "Actions implied by the prescription are to be permanently halted, before all of them occurred.";
152            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.";
153            case UNKNOWN: return "The authoring system does not know which of the status values currently applies for this request";
154            case NULL: return null;
155            default: return "?";
156          }
157        }
158        public String getDisplay() {
159          switch (this) {
160            case ACTIVE: return "Active";
161            case ONHOLD: return "On Hold";
162            case CANCELLED: return "Cancelled";
163            case COMPLETED: return "Completed";
164            case ENTEREDINERROR: return "Entered In Error";
165            case STOPPED: return "Stopped";
166            case DRAFT: return "Draft";
167            case UNKNOWN: return "Unknown";
168            case NULL: return null;
169            default: return "?";
170          }
171        }
172    }
173
174  public static class MedicationRequestStatusEnumFactory implements EnumFactory<MedicationRequestStatus> {
175    public MedicationRequestStatus fromCode(String codeString) throws IllegalArgumentException {
176      if (codeString == null || "".equals(codeString))
177            if (codeString == null || "".equals(codeString))
178                return null;
179        if ("active".equals(codeString))
180          return MedicationRequestStatus.ACTIVE;
181        if ("on-hold".equals(codeString))
182          return MedicationRequestStatus.ONHOLD;
183        if ("cancelled".equals(codeString))
184          return MedicationRequestStatus.CANCELLED;
185        if ("completed".equals(codeString))
186          return MedicationRequestStatus.COMPLETED;
187        if ("entered-in-error".equals(codeString))
188          return MedicationRequestStatus.ENTEREDINERROR;
189        if ("stopped".equals(codeString))
190          return MedicationRequestStatus.STOPPED;
191        if ("draft".equals(codeString))
192          return MedicationRequestStatus.DRAFT;
193        if ("unknown".equals(codeString))
194          return MedicationRequestStatus.UNKNOWN;
195        throw new IllegalArgumentException("Unknown MedicationRequestStatus code '"+codeString+"'");
196        }
197        public Enumeration<MedicationRequestStatus> fromType(Base code) throws FHIRException {
198          if (code == null)
199            return null;
200          if (code.isEmpty())
201            return new Enumeration<MedicationRequestStatus>(this);
202          String codeString = ((PrimitiveType) code).asStringValue();
203          if (codeString == null || "".equals(codeString))
204            return null;
205        if ("active".equals(codeString))
206          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.ACTIVE);
207        if ("on-hold".equals(codeString))
208          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.ONHOLD);
209        if ("cancelled".equals(codeString))
210          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.CANCELLED);
211        if ("completed".equals(codeString))
212          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.COMPLETED);
213        if ("entered-in-error".equals(codeString))
214          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.ENTEREDINERROR);
215        if ("stopped".equals(codeString))
216          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.STOPPED);
217        if ("draft".equals(codeString))
218          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.DRAFT);
219        if ("unknown".equals(codeString))
220          return new Enumeration<MedicationRequestStatus>(this, MedicationRequestStatus.UNKNOWN);
221        throw new FHIRException("Unknown MedicationRequestStatus code '"+codeString+"'");
222        }
223    public String toCode(MedicationRequestStatus code) {
224      if (code == MedicationRequestStatus.ACTIVE)
225        return "active";
226      if (code == MedicationRequestStatus.ONHOLD)
227        return "on-hold";
228      if (code == MedicationRequestStatus.CANCELLED)
229        return "cancelled";
230      if (code == MedicationRequestStatus.COMPLETED)
231        return "completed";
232      if (code == MedicationRequestStatus.ENTEREDINERROR)
233        return "entered-in-error";
234      if (code == MedicationRequestStatus.STOPPED)
235        return "stopped";
236      if (code == MedicationRequestStatus.DRAFT)
237        return "draft";
238      if (code == MedicationRequestStatus.UNKNOWN)
239        return "unknown";
240      return "?";
241      }
242    public String toSystem(MedicationRequestStatus code) {
243      return code.getSystem();
244      }
245    }
246
247    public enum MedicationRequestIntent {
248        /**
249         * The request is a suggestion made by someone/something that doesn't have an intention to ensure it occurs and without providing an authorization to act
250         */
251        PROPOSAL, 
252        /**
253         * The request represents an intension to ensure something occurs without providing an authorization for others to act
254         */
255        PLAN, 
256        /**
257         * The request represents a request/demand and authorization for action
258         */
259        ORDER, 
260        /**
261         * The request represents an instance for the particular order, for example a medication administration record.
262         */
263        INSTANCEORDER, 
264        /**
265         * added to help the parsers with the generic types
266         */
267        NULL;
268        public static MedicationRequestIntent fromCode(String codeString) throws FHIRException {
269            if (codeString == null || "".equals(codeString))
270                return null;
271        if ("proposal".equals(codeString))
272          return PROPOSAL;
273        if ("plan".equals(codeString))
274          return PLAN;
275        if ("order".equals(codeString))
276          return ORDER;
277        if ("instance-order".equals(codeString))
278          return INSTANCEORDER;
279        if (Configuration.isAcceptInvalidEnums())
280          return null;
281        else
282          throw new FHIRException("Unknown MedicationRequestIntent code '"+codeString+"'");
283        }
284        public String toCode() {
285          switch (this) {
286            case PROPOSAL: return "proposal";
287            case PLAN: return "plan";
288            case ORDER: return "order";
289            case INSTANCEORDER: return "instance-order";
290            case NULL: return null;
291            default: return "?";
292          }
293        }
294        public String getSystem() {
295          switch (this) {
296            case PROPOSAL: return "http://hl7.org/fhir/medication-request-intent";
297            case PLAN: return "http://hl7.org/fhir/medication-request-intent";
298            case ORDER: return "http://hl7.org/fhir/medication-request-intent";
299            case INSTANCEORDER: return "http://hl7.org/fhir/medication-request-intent";
300            case NULL: return null;
301            default: return "?";
302          }
303        }
304        public String getDefinition() {
305          switch (this) {
306            case PROPOSAL: return "The request is a suggestion made by someone/something that doesn't have an intention to ensure it occurs and without providing an authorization to act";
307            case PLAN: return "The request represents an intension to ensure something occurs without providing an authorization for others to act";
308            case ORDER: return "The request represents a request/demand and authorization for action";
309            case INSTANCEORDER: return "The request represents an instance for the particular order, for example a medication administration record.";
310            case NULL: return null;
311            default: return "?";
312          }
313        }
314        public String getDisplay() {
315          switch (this) {
316            case PROPOSAL: return "Proposal";
317            case PLAN: return "Plan";
318            case ORDER: return "Order";
319            case INSTANCEORDER: return "Instance Order";
320            case NULL: return null;
321            default: return "?";
322          }
323        }
324    }
325
326  public static class MedicationRequestIntentEnumFactory implements EnumFactory<MedicationRequestIntent> {
327    public MedicationRequestIntent fromCode(String codeString) throws IllegalArgumentException {
328      if (codeString == null || "".equals(codeString))
329            if (codeString == null || "".equals(codeString))
330                return null;
331        if ("proposal".equals(codeString))
332          return MedicationRequestIntent.PROPOSAL;
333        if ("plan".equals(codeString))
334          return MedicationRequestIntent.PLAN;
335        if ("order".equals(codeString))
336          return MedicationRequestIntent.ORDER;
337        if ("instance-order".equals(codeString))
338          return MedicationRequestIntent.INSTANCEORDER;
339        throw new IllegalArgumentException("Unknown MedicationRequestIntent code '"+codeString+"'");
340        }
341        public Enumeration<MedicationRequestIntent> fromType(Base code) throws FHIRException {
342          if (code == null)
343            return null;
344          if (code.isEmpty())
345            return new Enumeration<MedicationRequestIntent>(this);
346          String codeString = ((PrimitiveType) code).asStringValue();
347          if (codeString == null || "".equals(codeString))
348            return null;
349        if ("proposal".equals(codeString))
350          return new Enumeration<MedicationRequestIntent>(this, MedicationRequestIntent.PROPOSAL);
351        if ("plan".equals(codeString))
352          return new Enumeration<MedicationRequestIntent>(this, MedicationRequestIntent.PLAN);
353        if ("order".equals(codeString))
354          return new Enumeration<MedicationRequestIntent>(this, MedicationRequestIntent.ORDER);
355        if ("instance-order".equals(codeString))
356          return new Enumeration<MedicationRequestIntent>(this, MedicationRequestIntent.INSTANCEORDER);
357        throw new FHIRException("Unknown MedicationRequestIntent code '"+codeString+"'");
358        }
359    public String toCode(MedicationRequestIntent code) {
360      if (code == MedicationRequestIntent.PROPOSAL)
361        return "proposal";
362      if (code == MedicationRequestIntent.PLAN)
363        return "plan";
364      if (code == MedicationRequestIntent.ORDER)
365        return "order";
366      if (code == MedicationRequestIntent.INSTANCEORDER)
367        return "instance-order";
368      return "?";
369      }
370    public String toSystem(MedicationRequestIntent code) {
371      return code.getSystem();
372      }
373    }
374
375    public enum MedicationRequestPriority {
376        /**
377         * The order has a normal priority .
378         */
379        ROUTINE, 
380        /**
381         * The order should be urgently.
382         */
383        URGENT, 
384        /**
385         * The order is time-critical.
386         */
387        STAT, 
388        /**
389         * The order should be acted on as soon as possible.
390         */
391        ASAP, 
392        /**
393         * added to help the parsers with the generic types
394         */
395        NULL;
396        public static MedicationRequestPriority fromCode(String codeString) throws FHIRException {
397            if (codeString == null || "".equals(codeString))
398                return null;
399        if ("routine".equals(codeString))
400          return ROUTINE;
401        if ("urgent".equals(codeString))
402          return URGENT;
403        if ("stat".equals(codeString))
404          return STAT;
405        if ("asap".equals(codeString))
406          return ASAP;
407        if (Configuration.isAcceptInvalidEnums())
408          return null;
409        else
410          throw new FHIRException("Unknown MedicationRequestPriority code '"+codeString+"'");
411        }
412        public String toCode() {
413          switch (this) {
414            case ROUTINE: return "routine";
415            case URGENT: return "urgent";
416            case STAT: return "stat";
417            case ASAP: return "asap";
418            case NULL: return null;
419            default: return "?";
420          }
421        }
422        public String getSystem() {
423          switch (this) {
424            case ROUTINE: return "http://hl7.org/fhir/medication-request-priority";
425            case URGENT: return "http://hl7.org/fhir/medication-request-priority";
426            case STAT: return "http://hl7.org/fhir/medication-request-priority";
427            case ASAP: return "http://hl7.org/fhir/medication-request-priority";
428            case NULL: return null;
429            default: return "?";
430          }
431        }
432        public String getDefinition() {
433          switch (this) {
434            case ROUTINE: return "The order has a normal priority .";
435            case URGENT: return "The order should be urgently.";
436            case STAT: return "The order is time-critical.";
437            case ASAP: return "The order should be acted on as soon as possible.";
438            case NULL: return null;
439            default: return "?";
440          }
441        }
442        public String getDisplay() {
443          switch (this) {
444            case ROUTINE: return "Routine";
445            case URGENT: return "Urgent";
446            case STAT: return "Stat";
447            case ASAP: return "ASAP";
448            case NULL: return null;
449            default: return "?";
450          }
451        }
452    }
453
454  public static class MedicationRequestPriorityEnumFactory implements EnumFactory<MedicationRequestPriority> {
455    public MedicationRequestPriority fromCode(String codeString) throws IllegalArgumentException {
456      if (codeString == null || "".equals(codeString))
457            if (codeString == null || "".equals(codeString))
458                return null;
459        if ("routine".equals(codeString))
460          return MedicationRequestPriority.ROUTINE;
461        if ("urgent".equals(codeString))
462          return MedicationRequestPriority.URGENT;
463        if ("stat".equals(codeString))
464          return MedicationRequestPriority.STAT;
465        if ("asap".equals(codeString))
466          return MedicationRequestPriority.ASAP;
467        throw new IllegalArgumentException("Unknown MedicationRequestPriority code '"+codeString+"'");
468        }
469        public Enumeration<MedicationRequestPriority> fromType(Base code) throws FHIRException {
470          if (code == null)
471            return null;
472          if (code.isEmpty())
473            return new Enumeration<MedicationRequestPriority>(this);
474          String codeString = ((PrimitiveType) code).asStringValue();
475          if (codeString == null || "".equals(codeString))
476            return null;
477        if ("routine".equals(codeString))
478          return new Enumeration<MedicationRequestPriority>(this, MedicationRequestPriority.ROUTINE);
479        if ("urgent".equals(codeString))
480          return new Enumeration<MedicationRequestPriority>(this, MedicationRequestPriority.URGENT);
481        if ("stat".equals(codeString))
482          return new Enumeration<MedicationRequestPriority>(this, MedicationRequestPriority.STAT);
483        if ("asap".equals(codeString))
484          return new Enumeration<MedicationRequestPriority>(this, MedicationRequestPriority.ASAP);
485        throw new FHIRException("Unknown MedicationRequestPriority code '"+codeString+"'");
486        }
487    public String toCode(MedicationRequestPriority code) {
488      if (code == MedicationRequestPriority.ROUTINE)
489        return "routine";
490      if (code == MedicationRequestPriority.URGENT)
491        return "urgent";
492      if (code == MedicationRequestPriority.STAT)
493        return "stat";
494      if (code == MedicationRequestPriority.ASAP)
495        return "asap";
496      return "?";
497      }
498    public String toSystem(MedicationRequestPriority code) {
499      return code.getSystem();
500      }
501    }
502
503    @Block()
504    public static class MedicationRequestRequesterComponent extends BackboneElement implements IBaseBackboneElement {
505        /**
506         * The healthcare professional responsible for authorizing the initial prescription.
507         */
508        @Child(name = "agent", type = {Practitioner.class, Organization.class, Patient.class, RelatedPerson.class, Device.class}, order=1, min=1, max=1, modifier=false, summary=true)
509        @Description(shortDefinition="Who ordered the initial medication(s)", formalDefinition="The healthcare professional responsible for authorizing the initial prescription." )
510        protected Reference agent;
511
512        /**
513         * The actual object that is the target of the reference (The healthcare professional responsible for authorizing the initial prescription.)
514         */
515        protected Resource agentTarget;
516
517        /**
518         * The organization the device or practitioner was acting on behalf of.
519         */
520        @Child(name = "onBehalfOf", type = {Organization.class}, order=2, min=0, max=1, modifier=false, summary=true)
521        @Description(shortDefinition="Organization agent is acting for", formalDefinition="The organization the device or practitioner was acting on behalf of." )
522        protected Reference onBehalfOf;
523
524        /**
525         * The actual object that is the target of the reference (The organization the device or practitioner was acting on behalf of.)
526         */
527        protected Organization onBehalfOfTarget;
528
529        private static final long serialVersionUID = -71453027L;
530
531    /**
532     * Constructor
533     */
534      public MedicationRequestRequesterComponent() {
535        super();
536      }
537
538    /**
539     * Constructor
540     */
541      public MedicationRequestRequesterComponent(Reference agent) {
542        super();
543        this.agent = agent;
544      }
545
546        /**
547         * @return {@link #agent} (The healthcare professional responsible for authorizing the initial prescription.)
548         */
549        public Reference getAgent() { 
550          if (this.agent == null)
551            if (Configuration.errorOnAutoCreate())
552              throw new Error("Attempt to auto-create MedicationRequestRequesterComponent.agent");
553            else if (Configuration.doAutoCreate())
554              this.agent = new Reference(); // cc
555          return this.agent;
556        }
557
558        public boolean hasAgent() { 
559          return this.agent != null && !this.agent.isEmpty();
560        }
561
562        /**
563         * @param value {@link #agent} (The healthcare professional responsible for authorizing the initial prescription.)
564         */
565        public MedicationRequestRequesterComponent setAgent(Reference value)  { 
566          this.agent = value;
567          return this;
568        }
569
570        /**
571         * @return {@link #agent} 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 initial prescription.)
572         */
573        public Resource getAgentTarget() { 
574          return this.agentTarget;
575        }
576
577        /**
578         * @param value {@link #agent} 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 initial prescription.)
579         */
580        public MedicationRequestRequesterComponent setAgentTarget(Resource value) { 
581          this.agentTarget = value;
582          return this;
583        }
584
585        /**
586         * @return {@link #onBehalfOf} (The organization the device or practitioner was acting on behalf of.)
587         */
588        public Reference getOnBehalfOf() { 
589          if (this.onBehalfOf == null)
590            if (Configuration.errorOnAutoCreate())
591              throw new Error("Attempt to auto-create MedicationRequestRequesterComponent.onBehalfOf");
592            else if (Configuration.doAutoCreate())
593              this.onBehalfOf = new Reference(); // cc
594          return this.onBehalfOf;
595        }
596
597        public boolean hasOnBehalfOf() { 
598          return this.onBehalfOf != null && !this.onBehalfOf.isEmpty();
599        }
600
601        /**
602         * @param value {@link #onBehalfOf} (The organization the device or practitioner was acting on behalf of.)
603         */
604        public MedicationRequestRequesterComponent setOnBehalfOf(Reference value)  { 
605          this.onBehalfOf = value;
606          return this;
607        }
608
609        /**
610         * @return {@link #onBehalfOf} 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 organization the device or practitioner was acting on behalf of.)
611         */
612        public Organization getOnBehalfOfTarget() { 
613          if (this.onBehalfOfTarget == null)
614            if (Configuration.errorOnAutoCreate())
615              throw new Error("Attempt to auto-create MedicationRequestRequesterComponent.onBehalfOf");
616            else if (Configuration.doAutoCreate())
617              this.onBehalfOfTarget = new Organization(); // aa
618          return this.onBehalfOfTarget;
619        }
620
621        /**
622         * @param value {@link #onBehalfOf} 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 organization the device or practitioner was acting on behalf of.)
623         */
624        public MedicationRequestRequesterComponent setOnBehalfOfTarget(Organization value) { 
625          this.onBehalfOfTarget = value;
626          return this;
627        }
628
629        protected void listChildren(List<Property> children) {
630          super.listChildren(children);
631          children.add(new Property("agent", "Reference(Practitioner|Organization|Patient|RelatedPerson|Device)", "The healthcare professional responsible for authorizing the initial prescription.", 0, 1, agent));
632          children.add(new Property("onBehalfOf", "Reference(Organization)", "The organization the device or practitioner was acting on behalf of.", 0, 1, onBehalfOf));
633        }
634
635        @Override
636        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
637          switch (_hash) {
638          case 92750597: /*agent*/  return new Property("agent", "Reference(Practitioner|Organization|Patient|RelatedPerson|Device)", "The healthcare professional responsible for authorizing the initial prescription.", 0, 1, agent);
639          case -14402964: /*onBehalfOf*/  return new Property("onBehalfOf", "Reference(Organization)", "The organization the device or practitioner was acting on behalf of.", 0, 1, onBehalfOf);
640          default: return super.getNamedProperty(_hash, _name, _checkValid);
641          }
642
643        }
644
645      @Override
646      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
647        switch (hash) {
648        case 92750597: /*agent*/ return this.agent == null ? new Base[0] : new Base[] {this.agent}; // Reference
649        case -14402964: /*onBehalfOf*/ return this.onBehalfOf == null ? new Base[0] : new Base[] {this.onBehalfOf}; // Reference
650        default: return super.getProperty(hash, name, checkValid);
651        }
652
653      }
654
655      @Override
656      public Base setProperty(int hash, String name, Base value) throws FHIRException {
657        switch (hash) {
658        case 92750597: // agent
659          this.agent = castToReference(value); // Reference
660          return value;
661        case -14402964: // onBehalfOf
662          this.onBehalfOf = castToReference(value); // Reference
663          return value;
664        default: return super.setProperty(hash, name, value);
665        }
666
667      }
668
669      @Override
670      public Base setProperty(String name, Base value) throws FHIRException {
671        if (name.equals("agent")) {
672          this.agent = castToReference(value); // Reference
673        } else if (name.equals("onBehalfOf")) {
674          this.onBehalfOf = castToReference(value); // Reference
675        } else
676          return super.setProperty(name, value);
677        return value;
678      }
679
680      @Override
681      public Base makeProperty(int hash, String name) throws FHIRException {
682        switch (hash) {
683        case 92750597:  return getAgent(); 
684        case -14402964:  return getOnBehalfOf(); 
685        default: return super.makeProperty(hash, name);
686        }
687
688      }
689
690      @Override
691      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
692        switch (hash) {
693        case 92750597: /*agent*/ return new String[] {"Reference"};
694        case -14402964: /*onBehalfOf*/ return new String[] {"Reference"};
695        default: return super.getTypesForProperty(hash, name);
696        }
697
698      }
699
700      @Override
701      public Base addChild(String name) throws FHIRException {
702        if (name.equals("agent")) {
703          this.agent = new Reference();
704          return this.agent;
705        }
706        else if (name.equals("onBehalfOf")) {
707          this.onBehalfOf = new Reference();
708          return this.onBehalfOf;
709        }
710        else
711          return super.addChild(name);
712      }
713
714      public MedicationRequestRequesterComponent copy() {
715        MedicationRequestRequesterComponent dst = new MedicationRequestRequesterComponent();
716        copyValues(dst);
717        dst.agent = agent == null ? null : agent.copy();
718        dst.onBehalfOf = onBehalfOf == null ? null : onBehalfOf.copy();
719        return dst;
720      }
721
722      @Override
723      public boolean equalsDeep(Base other_) {
724        if (!super.equalsDeep(other_))
725          return false;
726        if (!(other_ instanceof MedicationRequestRequesterComponent))
727          return false;
728        MedicationRequestRequesterComponent o = (MedicationRequestRequesterComponent) other_;
729        return compareDeep(agent, o.agent, true) && compareDeep(onBehalfOf, o.onBehalfOf, true);
730      }
731
732      @Override
733      public boolean equalsShallow(Base other_) {
734        if (!super.equalsShallow(other_))
735          return false;
736        if (!(other_ instanceof MedicationRequestRequesterComponent))
737          return false;
738        MedicationRequestRequesterComponent o = (MedicationRequestRequesterComponent) other_;
739        return true;
740      }
741
742      public boolean isEmpty() {
743        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(agent, onBehalfOf);
744      }
745
746  public String fhirType() {
747    return "MedicationRequest.requester";
748
749  }
750
751  }
752
753    @Block()
754    public static class MedicationRequestDispenseRequestComponent extends BackboneElement implements IBaseBackboneElement {
755        /**
756         * This indicates the validity period of a prescription (stale dating the Prescription).
757         */
758        @Child(name = "validityPeriod", type = {Period.class}, order=1, min=0, max=1, modifier=false, summary=false)
759        @Description(shortDefinition="Time period supply is authorized for", formalDefinition="This indicates the validity period of a prescription (stale dating the Prescription)." )
760        protected Period validityPeriod;
761
762        /**
763         * An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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.
764         */
765        @Child(name = "numberOfRepeatsAllowed", type = {PositiveIntType.class}, order=2, min=0, max=1, modifier=false, summary=false)
766        @Description(shortDefinition="Number of refills authorized", formalDefinition="An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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." )
767        protected PositiveIntType numberOfRepeatsAllowed;
768
769        /**
770         * The amount that is to be dispensed for one fill.
771         */
772        @Child(name = "quantity", type = {SimpleQuantity.class}, order=3, min=0, max=1, modifier=false, summary=false)
773        @Description(shortDefinition="Amount of medication to supply per dispense", formalDefinition="The amount that is to be dispensed for one fill." )
774        protected SimpleQuantity quantity;
775
776        /**
777         * 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.
778         */
779        @Child(name = "expectedSupplyDuration", type = {Duration.class}, order=4, min=0, max=1, modifier=false, summary=false)
780        @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." )
781        protected Duration expectedSupplyDuration;
782
783        /**
784         * Indicates the intended dispensing Organization specified by the prescriber.
785         */
786        @Child(name = "performer", type = {Organization.class}, order=5, min=0, max=1, modifier=false, summary=false)
787        @Description(shortDefinition="Intended dispenser", formalDefinition="Indicates the intended dispensing Organization specified by the prescriber." )
788        protected Reference performer;
789
790        /**
791         * The actual object that is the target of the reference (Indicates the intended dispensing Organization specified by the prescriber.)
792         */
793        protected Organization performerTarget;
794
795        private static final long serialVersionUID = 280197622L;
796
797    /**
798     * Constructor
799     */
800      public MedicationRequestDispenseRequestComponent() {
801        super();
802      }
803
804        /**
805         * @return {@link #validityPeriod} (This indicates the validity period of a prescription (stale dating the Prescription).)
806         */
807        public Period getValidityPeriod() { 
808          if (this.validityPeriod == null)
809            if (Configuration.errorOnAutoCreate())
810              throw new Error("Attempt to auto-create MedicationRequestDispenseRequestComponent.validityPeriod");
811            else if (Configuration.doAutoCreate())
812              this.validityPeriod = new Period(); // cc
813          return this.validityPeriod;
814        }
815
816        public boolean hasValidityPeriod() { 
817          return this.validityPeriod != null && !this.validityPeriod.isEmpty();
818        }
819
820        /**
821         * @param value {@link #validityPeriod} (This indicates the validity period of a prescription (stale dating the Prescription).)
822         */
823        public MedicationRequestDispenseRequestComponent setValidityPeriod(Period value)  { 
824          this.validityPeriod = value;
825          return this;
826        }
827
828        /**
829         * @return {@link #numberOfRepeatsAllowed} (An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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
830         */
831        public PositiveIntType getNumberOfRepeatsAllowedElement() { 
832          if (this.numberOfRepeatsAllowed == null)
833            if (Configuration.errorOnAutoCreate())
834              throw new Error("Attempt to auto-create MedicationRequestDispenseRequestComponent.numberOfRepeatsAllowed");
835            else if (Configuration.doAutoCreate())
836              this.numberOfRepeatsAllowed = new PositiveIntType(); // bb
837          return this.numberOfRepeatsAllowed;
838        }
839
840        public boolean hasNumberOfRepeatsAllowedElement() { 
841          return this.numberOfRepeatsAllowed != null && !this.numberOfRepeatsAllowed.isEmpty();
842        }
843
844        public boolean hasNumberOfRepeatsAllowed() { 
845          return this.numberOfRepeatsAllowed != null && !this.numberOfRepeatsAllowed.isEmpty();
846        }
847
848        /**
849         * @param value {@link #numberOfRepeatsAllowed} (An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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
850         */
851        public MedicationRequestDispenseRequestComponent setNumberOfRepeatsAllowedElement(PositiveIntType value) { 
852          this.numberOfRepeatsAllowed = value;
853          return this;
854        }
855
856        /**
857         * @return An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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.
858         */
859        public int getNumberOfRepeatsAllowed() { 
860          return this.numberOfRepeatsAllowed == null || this.numberOfRepeatsAllowed.isEmpty() ? 0 : this.numberOfRepeatsAllowed.getValue();
861        }
862
863        /**
864         * @param value An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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.
865         */
866        public MedicationRequestDispenseRequestComponent setNumberOfRepeatsAllowed(int value) { 
867            if (this.numberOfRepeatsAllowed == null)
868              this.numberOfRepeatsAllowed = new PositiveIntType();
869            this.numberOfRepeatsAllowed.setValue(value);
870          return this;
871        }
872
873        /**
874         * @return {@link #quantity} (The amount that is to be dispensed for one fill.)
875         */
876        public SimpleQuantity getQuantity() { 
877          if (this.quantity == null)
878            if (Configuration.errorOnAutoCreate())
879              throw new Error("Attempt to auto-create MedicationRequestDispenseRequestComponent.quantity");
880            else if (Configuration.doAutoCreate())
881              this.quantity = new SimpleQuantity(); // cc
882          return this.quantity;
883        }
884
885        public boolean hasQuantity() { 
886          return this.quantity != null && !this.quantity.isEmpty();
887        }
888
889        /**
890         * @param value {@link #quantity} (The amount that is to be dispensed for one fill.)
891         */
892        public MedicationRequestDispenseRequestComponent setQuantity(SimpleQuantity value)  { 
893          this.quantity = value;
894          return this;
895        }
896
897        /**
898         * @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.)
899         */
900        public Duration getExpectedSupplyDuration() { 
901          if (this.expectedSupplyDuration == null)
902            if (Configuration.errorOnAutoCreate())
903              throw new Error("Attempt to auto-create MedicationRequestDispenseRequestComponent.expectedSupplyDuration");
904            else if (Configuration.doAutoCreate())
905              this.expectedSupplyDuration = new Duration(); // cc
906          return this.expectedSupplyDuration;
907        }
908
909        public boolean hasExpectedSupplyDuration() { 
910          return this.expectedSupplyDuration != null && !this.expectedSupplyDuration.isEmpty();
911        }
912
913        /**
914         * @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.)
915         */
916        public MedicationRequestDispenseRequestComponent setExpectedSupplyDuration(Duration value)  { 
917          this.expectedSupplyDuration = value;
918          return this;
919        }
920
921        /**
922         * @return {@link #performer} (Indicates the intended dispensing Organization specified by the prescriber.)
923         */
924        public Reference getPerformer() { 
925          if (this.performer == null)
926            if (Configuration.errorOnAutoCreate())
927              throw new Error("Attempt to auto-create MedicationRequestDispenseRequestComponent.performer");
928            else if (Configuration.doAutoCreate())
929              this.performer = new Reference(); // cc
930          return this.performer;
931        }
932
933        public boolean hasPerformer() { 
934          return this.performer != null && !this.performer.isEmpty();
935        }
936
937        /**
938         * @param value {@link #performer} (Indicates the intended dispensing Organization specified by the prescriber.)
939         */
940        public MedicationRequestDispenseRequestComponent setPerformer(Reference value)  { 
941          this.performer = value;
942          return this;
943        }
944
945        /**
946         * @return {@link #performer} 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. (Indicates the intended dispensing Organization specified by the prescriber.)
947         */
948        public Organization getPerformerTarget() { 
949          if (this.performerTarget == null)
950            if (Configuration.errorOnAutoCreate())
951              throw new Error("Attempt to auto-create MedicationRequestDispenseRequestComponent.performer");
952            else if (Configuration.doAutoCreate())
953              this.performerTarget = new Organization(); // aa
954          return this.performerTarget;
955        }
956
957        /**
958         * @param value {@link #performer} 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. (Indicates the intended dispensing Organization specified by the prescriber.)
959         */
960        public MedicationRequestDispenseRequestComponent setPerformerTarget(Organization value) { 
961          this.performerTarget = value;
962          return this;
963        }
964
965        protected void listChildren(List<Property> children) {
966          super.listChildren(children);
967          children.add(new Property("validityPeriod", "Period", "This indicates the validity period of a prescription (stale dating the Prescription).", 0, 1, validityPeriod));
968          children.add(new Property("numberOfRepeatsAllowed", "positiveInt", "An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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, 1, numberOfRepeatsAllowed));
969          children.add(new Property("quantity", "SimpleQuantity", "The amount that is to be dispensed for one fill.", 0, 1, quantity));
970          children.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, 1, expectedSupplyDuration));
971          children.add(new Property("performer", "Reference(Organization)", "Indicates the intended dispensing Organization specified by the prescriber.", 0, 1, performer));
972        }
973
974        @Override
975        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
976          switch (_hash) {
977          case -1434195053: /*validityPeriod*/  return new Property("validityPeriod", "Period", "This indicates the validity period of a prescription (stale dating the Prescription).", 0, 1, validityPeriod);
978          case -239736976: /*numberOfRepeatsAllowed*/  return new Property("numberOfRepeatsAllowed", "positiveInt", "An integer indicating the number of times, in addition to the original dispense, (aka refills or repeats) that 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, 1, numberOfRepeatsAllowed);
979          case -1285004149: /*quantity*/  return new Property("quantity", "SimpleQuantity", "The amount that is to be dispensed for one fill.", 0, 1, quantity);
980          case -1910182789: /*expectedSupplyDuration*/  return 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, 1, expectedSupplyDuration);
981          case 481140686: /*performer*/  return new Property("performer", "Reference(Organization)", "Indicates the intended dispensing Organization specified by the prescriber.", 0, 1, performer);
982          default: return super.getNamedProperty(_hash, _name, _checkValid);
983          }
984
985        }
986
987      @Override
988      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
989        switch (hash) {
990        case -1434195053: /*validityPeriod*/ return this.validityPeriod == null ? new Base[0] : new Base[] {this.validityPeriod}; // Period
991        case -239736976: /*numberOfRepeatsAllowed*/ return this.numberOfRepeatsAllowed == null ? new Base[0] : new Base[] {this.numberOfRepeatsAllowed}; // PositiveIntType
992        case -1285004149: /*quantity*/ return this.quantity == null ? new Base[0] : new Base[] {this.quantity}; // SimpleQuantity
993        case -1910182789: /*expectedSupplyDuration*/ return this.expectedSupplyDuration == null ? new Base[0] : new Base[] {this.expectedSupplyDuration}; // Duration
994        case 481140686: /*performer*/ return this.performer == null ? new Base[0] : new Base[] {this.performer}; // Reference
995        default: return super.getProperty(hash, name, checkValid);
996        }
997
998      }
999
1000      @Override
1001      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1002        switch (hash) {
1003        case -1434195053: // validityPeriod
1004          this.validityPeriod = castToPeriod(value); // Period
1005          return value;
1006        case -239736976: // numberOfRepeatsAllowed
1007          this.numberOfRepeatsAllowed = castToPositiveInt(value); // PositiveIntType
1008          return value;
1009        case -1285004149: // quantity
1010          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
1011          return value;
1012        case -1910182789: // expectedSupplyDuration
1013          this.expectedSupplyDuration = castToDuration(value); // Duration
1014          return value;
1015        case 481140686: // performer
1016          this.performer = castToReference(value); // Reference
1017          return value;
1018        default: return super.setProperty(hash, name, value);
1019        }
1020
1021      }
1022
1023      @Override
1024      public Base setProperty(String name, Base value) throws FHIRException {
1025        if (name.equals("validityPeriod")) {
1026          this.validityPeriod = castToPeriod(value); // Period
1027        } else if (name.equals("numberOfRepeatsAllowed")) {
1028          this.numberOfRepeatsAllowed = castToPositiveInt(value); // PositiveIntType
1029        } else if (name.equals("quantity")) {
1030          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
1031        } else if (name.equals("expectedSupplyDuration")) {
1032          this.expectedSupplyDuration = castToDuration(value); // Duration
1033        } else if (name.equals("performer")) {
1034          this.performer = castToReference(value); // Reference
1035        } else
1036          return super.setProperty(name, value);
1037        return value;
1038      }
1039
1040      @Override
1041      public Base makeProperty(int hash, String name) throws FHIRException {
1042        switch (hash) {
1043        case -1434195053:  return getValidityPeriod(); 
1044        case -239736976:  return getNumberOfRepeatsAllowedElement();
1045        case -1285004149:  return getQuantity(); 
1046        case -1910182789:  return getExpectedSupplyDuration(); 
1047        case 481140686:  return getPerformer(); 
1048        default: return super.makeProperty(hash, name);
1049        }
1050
1051      }
1052
1053      @Override
1054      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1055        switch (hash) {
1056        case -1434195053: /*validityPeriod*/ return new String[] {"Period"};
1057        case -239736976: /*numberOfRepeatsAllowed*/ return new String[] {"positiveInt"};
1058        case -1285004149: /*quantity*/ return new String[] {"SimpleQuantity"};
1059        case -1910182789: /*expectedSupplyDuration*/ return new String[] {"Duration"};
1060        case 481140686: /*performer*/ return new String[] {"Reference"};
1061        default: return super.getTypesForProperty(hash, name);
1062        }
1063
1064      }
1065
1066      @Override
1067      public Base addChild(String name) throws FHIRException {
1068        if (name.equals("validityPeriod")) {
1069          this.validityPeriod = new Period();
1070          return this.validityPeriod;
1071        }
1072        else if (name.equals("numberOfRepeatsAllowed")) {
1073          throw new FHIRException("Cannot call addChild on a primitive type MedicationRequest.numberOfRepeatsAllowed");
1074        }
1075        else if (name.equals("quantity")) {
1076          this.quantity = new SimpleQuantity();
1077          return this.quantity;
1078        }
1079        else if (name.equals("expectedSupplyDuration")) {
1080          this.expectedSupplyDuration = new Duration();
1081          return this.expectedSupplyDuration;
1082        }
1083        else if (name.equals("performer")) {
1084          this.performer = new Reference();
1085          return this.performer;
1086        }
1087        else
1088          return super.addChild(name);
1089      }
1090
1091      public MedicationRequestDispenseRequestComponent copy() {
1092        MedicationRequestDispenseRequestComponent dst = new MedicationRequestDispenseRequestComponent();
1093        copyValues(dst);
1094        dst.validityPeriod = validityPeriod == null ? null : validityPeriod.copy();
1095        dst.numberOfRepeatsAllowed = numberOfRepeatsAllowed == null ? null : numberOfRepeatsAllowed.copy();
1096        dst.quantity = quantity == null ? null : quantity.copy();
1097        dst.expectedSupplyDuration = expectedSupplyDuration == null ? null : expectedSupplyDuration.copy();
1098        dst.performer = performer == null ? null : performer.copy();
1099        return dst;
1100      }
1101
1102      @Override
1103      public boolean equalsDeep(Base other_) {
1104        if (!super.equalsDeep(other_))
1105          return false;
1106        if (!(other_ instanceof MedicationRequestDispenseRequestComponent))
1107          return false;
1108        MedicationRequestDispenseRequestComponent o = (MedicationRequestDispenseRequestComponent) other_;
1109        return compareDeep(validityPeriod, o.validityPeriod, true) && compareDeep(numberOfRepeatsAllowed, o.numberOfRepeatsAllowed, true)
1110           && compareDeep(quantity, o.quantity, true) && compareDeep(expectedSupplyDuration, o.expectedSupplyDuration, true)
1111           && compareDeep(performer, o.performer, true);
1112      }
1113
1114      @Override
1115      public boolean equalsShallow(Base other_) {
1116        if (!super.equalsShallow(other_))
1117          return false;
1118        if (!(other_ instanceof MedicationRequestDispenseRequestComponent))
1119          return false;
1120        MedicationRequestDispenseRequestComponent o = (MedicationRequestDispenseRequestComponent) other_;
1121        return compareValues(numberOfRepeatsAllowed, o.numberOfRepeatsAllowed, true);
1122      }
1123
1124      public boolean isEmpty() {
1125        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(validityPeriod, numberOfRepeatsAllowed
1126          , quantity, expectedSupplyDuration, performer);
1127      }
1128
1129  public String fhirType() {
1130    return "MedicationRequest.dispenseRequest";
1131
1132  }
1133
1134  }
1135
1136    @Block()
1137    public static class MedicationRequestSubstitutionComponent extends BackboneElement implements IBaseBackboneElement {
1138        /**
1139         * True if the prescriber allows a different drug to be dispensed from what was prescribed.
1140         */
1141        @Child(name = "allowed", type = {BooleanType.class}, order=1, min=1, max=1, modifier=true, summary=false)
1142        @Description(shortDefinition="Whether substitution is allowed or not", formalDefinition="True if the prescriber allows a different drug to be dispensed from what was prescribed." )
1143        protected BooleanType allowed;
1144
1145        /**
1146         * Indicates the reason for the substitution, or why substitution must or must not be performed.
1147         */
1148        @Child(name = "reason", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=false)
1149        @Description(shortDefinition="Why should (not) substitution be made", formalDefinition="Indicates the reason for the substitution, or why substitution must or must not be performed." )
1150        @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/v3-SubstanceAdminSubstitutionReason")
1151        protected CodeableConcept reason;
1152
1153        private static final long serialVersionUID = -141547037L;
1154
1155    /**
1156     * Constructor
1157     */
1158      public MedicationRequestSubstitutionComponent() {
1159        super();
1160      }
1161
1162    /**
1163     * Constructor
1164     */
1165      public MedicationRequestSubstitutionComponent(BooleanType allowed) {
1166        super();
1167        this.allowed = allowed;
1168      }
1169
1170        /**
1171         * @return {@link #allowed} (True if the prescriber allows a different drug to be dispensed from what was prescribed.). This is the underlying object with id, value and extensions. The accessor "getAllowed" gives direct access to the value
1172         */
1173        public BooleanType getAllowedElement() { 
1174          if (this.allowed == null)
1175            if (Configuration.errorOnAutoCreate())
1176              throw new Error("Attempt to auto-create MedicationRequestSubstitutionComponent.allowed");
1177            else if (Configuration.doAutoCreate())
1178              this.allowed = new BooleanType(); // bb
1179          return this.allowed;
1180        }
1181
1182        public boolean hasAllowedElement() { 
1183          return this.allowed != null && !this.allowed.isEmpty();
1184        }
1185
1186        public boolean hasAllowed() { 
1187          return this.allowed != null && !this.allowed.isEmpty();
1188        }
1189
1190        /**
1191         * @param value {@link #allowed} (True if the prescriber allows a different drug to be dispensed from what was prescribed.). This is the underlying object with id, value and extensions. The accessor "getAllowed" gives direct access to the value
1192         */
1193        public MedicationRequestSubstitutionComponent setAllowedElement(BooleanType value) { 
1194          this.allowed = value;
1195          return this;
1196        }
1197
1198        /**
1199         * @return True if the prescriber allows a different drug to be dispensed from what was prescribed.
1200         */
1201        public boolean getAllowed() { 
1202          return this.allowed == null || this.allowed.isEmpty() ? false : this.allowed.getValue();
1203        }
1204
1205        /**
1206         * @param value True if the prescriber allows a different drug to be dispensed from what was prescribed.
1207         */
1208        public MedicationRequestSubstitutionComponent setAllowed(boolean value) { 
1209            if (this.allowed == null)
1210              this.allowed = new BooleanType();
1211            this.allowed.setValue(value);
1212          return this;
1213        }
1214
1215        /**
1216         * @return {@link #reason} (Indicates the reason for the substitution, or why substitution must or must not be performed.)
1217         */
1218        public CodeableConcept getReason() { 
1219          if (this.reason == null)
1220            if (Configuration.errorOnAutoCreate())
1221              throw new Error("Attempt to auto-create MedicationRequestSubstitutionComponent.reason");
1222            else if (Configuration.doAutoCreate())
1223              this.reason = new CodeableConcept(); // cc
1224          return this.reason;
1225        }
1226
1227        public boolean hasReason() { 
1228          return this.reason != null && !this.reason.isEmpty();
1229        }
1230
1231        /**
1232         * @param value {@link #reason} (Indicates the reason for the substitution, or why substitution must or must not be performed.)
1233         */
1234        public MedicationRequestSubstitutionComponent setReason(CodeableConcept value)  { 
1235          this.reason = value;
1236          return this;
1237        }
1238
1239        protected void listChildren(List<Property> children) {
1240          super.listChildren(children);
1241          children.add(new Property("allowed", "boolean", "True if the prescriber allows a different drug to be dispensed from what was prescribed.", 0, 1, allowed));
1242          children.add(new Property("reason", "CodeableConcept", "Indicates the reason for the substitution, or why substitution must or must not be performed.", 0, 1, reason));
1243        }
1244
1245        @Override
1246        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1247          switch (_hash) {
1248          case -911343192: /*allowed*/  return new Property("allowed", "boolean", "True if the prescriber allows a different drug to be dispensed from what was prescribed.", 0, 1, allowed);
1249          case -934964668: /*reason*/  return new Property("reason", "CodeableConcept", "Indicates the reason for the substitution, or why substitution must or must not be performed.", 0, 1, reason);
1250          default: return super.getNamedProperty(_hash, _name, _checkValid);
1251          }
1252
1253        }
1254
1255      @Override
1256      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1257        switch (hash) {
1258        case -911343192: /*allowed*/ return this.allowed == null ? new Base[0] : new Base[] {this.allowed}; // BooleanType
1259        case -934964668: /*reason*/ return this.reason == null ? new Base[0] : new Base[] {this.reason}; // CodeableConcept
1260        default: return super.getProperty(hash, name, checkValid);
1261        }
1262
1263      }
1264
1265      @Override
1266      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1267        switch (hash) {
1268        case -911343192: // allowed
1269          this.allowed = castToBoolean(value); // BooleanType
1270          return value;
1271        case -934964668: // reason
1272          this.reason = castToCodeableConcept(value); // CodeableConcept
1273          return value;
1274        default: return super.setProperty(hash, name, value);
1275        }
1276
1277      }
1278
1279      @Override
1280      public Base setProperty(String name, Base value) throws FHIRException {
1281        if (name.equals("allowed")) {
1282          this.allowed = castToBoolean(value); // BooleanType
1283        } else if (name.equals("reason")) {
1284          this.reason = castToCodeableConcept(value); // CodeableConcept
1285        } else
1286          return super.setProperty(name, value);
1287        return value;
1288      }
1289
1290      @Override
1291      public Base makeProperty(int hash, String name) throws FHIRException {
1292        switch (hash) {
1293        case -911343192:  return getAllowedElement();
1294        case -934964668:  return getReason(); 
1295        default: return super.makeProperty(hash, name);
1296        }
1297
1298      }
1299
1300      @Override
1301      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1302        switch (hash) {
1303        case -911343192: /*allowed*/ return new String[] {"boolean"};
1304        case -934964668: /*reason*/ return new String[] {"CodeableConcept"};
1305        default: return super.getTypesForProperty(hash, name);
1306        }
1307
1308      }
1309
1310      @Override
1311      public Base addChild(String name) throws FHIRException {
1312        if (name.equals("allowed")) {
1313          throw new FHIRException("Cannot call addChild on a primitive type MedicationRequest.allowed");
1314        }
1315        else if (name.equals("reason")) {
1316          this.reason = new CodeableConcept();
1317          return this.reason;
1318        }
1319        else
1320          return super.addChild(name);
1321      }
1322
1323      public MedicationRequestSubstitutionComponent copy() {
1324        MedicationRequestSubstitutionComponent dst = new MedicationRequestSubstitutionComponent();
1325        copyValues(dst);
1326        dst.allowed = allowed == null ? null : allowed.copy();
1327        dst.reason = reason == null ? null : reason.copy();
1328        return dst;
1329      }
1330
1331      @Override
1332      public boolean equalsDeep(Base other_) {
1333        if (!super.equalsDeep(other_))
1334          return false;
1335        if (!(other_ instanceof MedicationRequestSubstitutionComponent))
1336          return false;
1337        MedicationRequestSubstitutionComponent o = (MedicationRequestSubstitutionComponent) other_;
1338        return compareDeep(allowed, o.allowed, true) && compareDeep(reason, o.reason, true);
1339      }
1340
1341      @Override
1342      public boolean equalsShallow(Base other_) {
1343        if (!super.equalsShallow(other_))
1344          return false;
1345        if (!(other_ instanceof MedicationRequestSubstitutionComponent))
1346          return false;
1347        MedicationRequestSubstitutionComponent o = (MedicationRequestSubstitutionComponent) other_;
1348        return compareValues(allowed, o.allowed, true);
1349      }
1350
1351      public boolean isEmpty() {
1352        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(allowed, reason);
1353      }
1354
1355  public String fhirType() {
1356    return "MedicationRequest.substitution";
1357
1358  }
1359
1360  }
1361
1362    /**
1363     * This records identifiers associated with this medication request that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. 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 must be tracked through an entire system.
1364     */
1365    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1366    @Description(shortDefinition="External ids for this request", formalDefinition="This records identifiers associated with this medication request that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. 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 must be tracked through an entire system." )
1367    protected List<Identifier> identifier;
1368
1369    /**
1370     * Protocol or definition followed by this request.
1371     */
1372    @Child(name = "definition", type = {ActivityDefinition.class, PlanDefinition.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1373    @Description(shortDefinition="Protocol or definition", formalDefinition="Protocol or definition followed by this request." )
1374    protected List<Reference> definition;
1375    /**
1376     * The actual objects that are the target of the reference (Protocol or definition followed by this request.)
1377     */
1378    protected List<Resource> definitionTarget;
1379
1380
1381    /**
1382     * A plan or request that is fulfilled in whole or in part by this medication request.
1383     */
1384    @Child(name = "basedOn", type = {CarePlan.class, MedicationRequest.class, ProcedureRequest.class, ReferralRequest.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1385    @Description(shortDefinition="What request fulfills", formalDefinition="A plan or request that is fulfilled in whole or in part by this medication request." )
1386    protected List<Reference> basedOn;
1387    /**
1388     * The actual objects that are the target of the reference (A plan or request that is fulfilled in whole or in part by this medication request.)
1389     */
1390    protected List<Resource> basedOnTarget;
1391
1392
1393    /**
1394     * A shared identifier common to all requests that were authorized more or less simultaneously by a single author, representing the identifier of the requisition or prescription.
1395     */
1396    @Child(name = "groupIdentifier", type = {Identifier.class}, order=3, min=0, max=1, modifier=false, summary=true)
1397    @Description(shortDefinition="Composite request this is part of", formalDefinition="A shared identifier common to all requests that were authorized more or less simultaneously by a single author, representing the identifier of the requisition or prescription." )
1398    protected Identifier groupIdentifier;
1399
1400    /**
1401     * A code specifying the current state of the order.  Generally this will be active or completed state.
1402     */
1403    @Child(name = "status", type = {CodeType.class}, order=4, min=0, max=1, modifier=true, summary=true)
1404    @Description(shortDefinition="active | on-hold | cancelled | completed | entered-in-error | stopped | draft | unknown", formalDefinition="A code specifying the current state of the order.  Generally this will be active or completed state." )
1405    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-request-status")
1406    protected Enumeration<MedicationRequestStatus> status;
1407
1408    /**
1409     * Whether the request is a proposal, plan, or an original order.
1410     */
1411    @Child(name = "intent", type = {CodeType.class}, order=5, min=1, max=1, modifier=true, summary=true)
1412    @Description(shortDefinition="proposal | plan | order | instance-order", formalDefinition="Whether the request is a proposal, plan, or an original order." )
1413    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-request-intent")
1414    protected Enumeration<MedicationRequestIntent> intent;
1415
1416    /**
1417     * Indicates the type of medication order and where the medication is expected to be consumed or administered.
1418     */
1419    @Child(name = "category", type = {CodeableConcept.class}, order=6, min=0, max=1, modifier=false, summary=false)
1420    @Description(shortDefinition="Type of medication usage", formalDefinition="Indicates the type of medication order and where the medication is expected to be consumed or administered." )
1421    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-request-category")
1422    protected CodeableConcept category;
1423
1424    /**
1425     * Indicates how quickly the Medication Request should be addressed with respect to other requests.
1426     */
1427    @Child(name = "priority", type = {CodeType.class}, order=7, min=0, max=1, modifier=false, summary=true)
1428    @Description(shortDefinition="routine | urgent | stat | asap", formalDefinition="Indicates how quickly the Medication Request should be addressed with respect to other requests." )
1429    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-request-priority")
1430    protected Enumeration<MedicationRequestPriority> priority;
1431
1432    /**
1433     * Identifies the medication being requested. 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.
1434     */
1435    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=8, min=1, max=1, modifier=false, summary=true)
1436    @Description(shortDefinition="Medication to be taken", formalDefinition="Identifies the medication being requested. 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." )
1437    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-codes")
1438    protected Type medication;
1439
1440    /**
1441     * A link to a resource representing the person or set of individuals to whom the medication will be given.
1442     */
1443    @Child(name = "subject", type = {Patient.class, Group.class}, order=9, min=1, max=1, modifier=false, summary=true)
1444    @Description(shortDefinition="Who or group medication request is for", formalDefinition="A link to a resource representing the person or set of individuals to whom the medication will be given." )
1445    protected Reference subject;
1446
1447    /**
1448     * The actual object that is the target of the reference (A link to a resource representing the person or set of individuals to whom the medication will be given.)
1449     */
1450    protected Resource subjectTarget;
1451
1452    /**
1453     * A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.
1454     */
1455    @Child(name = "context", type = {Encounter.class, EpisodeOfCare.class}, order=10, min=0, max=1, modifier=false, summary=false)
1456    @Description(shortDefinition="Created during encounter/admission/stay", formalDefinition="A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider." )
1457    protected Reference context;
1458
1459    /**
1460     * The actual object that is the target of the reference (A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.)
1461     */
1462    protected Resource contextTarget;
1463
1464    /**
1465     * Include additional information (for example, patient height and weight) that supports the ordering of the medication.
1466     */
1467    @Child(name = "supportingInformation", type = {Reference.class}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1468    @Description(shortDefinition="Information to support ordering of the medication", formalDefinition="Include additional information (for example, patient height and weight) that supports the ordering of the medication." )
1469    protected List<Reference> supportingInformation;
1470    /**
1471     * The actual objects that are the target of the reference (Include additional information (for example, patient height and weight) that supports the ordering of the medication.)
1472     */
1473    protected List<Resource> supportingInformationTarget;
1474
1475
1476    /**
1477     * The date (and perhaps time) when the prescription was initially written or authored on.
1478     */
1479    @Child(name = "authoredOn", type = {DateTimeType.class}, order=12, min=0, max=1, modifier=false, summary=true)
1480    @Description(shortDefinition="When request was initially authored", formalDefinition="The date (and perhaps time) when the prescription was initially written or authored on." )
1481    protected DateTimeType authoredOn;
1482
1483    /**
1484     * The individual, organization or device that initiated the request and has responsibility for its activation.
1485     */
1486    @Child(name = "requester", type = {}, order=13, min=0, max=1, modifier=false, summary=true)
1487    @Description(shortDefinition="Who/What requested the Request", formalDefinition="The individual, organization or device that initiated the request and has responsibility for its activation." )
1488    protected MedicationRequestRequesterComponent requester;
1489
1490    /**
1491     * The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.
1492     */
1493    @Child(name = "recorder", type = {Practitioner.class}, order=14, min=0, max=1, modifier=false, summary=false)
1494    @Description(shortDefinition="Person who entered the request", formalDefinition="The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order." )
1495    protected Reference recorder;
1496
1497    /**
1498     * The actual object that is the target of the reference (The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.)
1499     */
1500    protected Practitioner recorderTarget;
1501
1502    /**
1503     * The reason or the indication for ordering the medication.
1504     */
1505    @Child(name = "reasonCode", type = {CodeableConcept.class}, order=15, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1506    @Description(shortDefinition="Reason or indication for writing the prescription", formalDefinition="The reason or the indication for ordering the medication." )
1507    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/condition-code")
1508    protected List<CodeableConcept> reasonCode;
1509
1510    /**
1511     * Condition or observation that supports why the medication was ordered.
1512     */
1513    @Child(name = "reasonReference", type = {Condition.class, Observation.class}, order=16, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1514    @Description(shortDefinition="Condition or Observation that supports why the prescription is being written", formalDefinition="Condition or observation that supports why the medication was ordered." )
1515    protected List<Reference> reasonReference;
1516    /**
1517     * The actual objects that are the target of the reference (Condition or observation that supports why the medication was ordered.)
1518     */
1519    protected List<Resource> reasonReferenceTarget;
1520
1521
1522    /**
1523     * Extra information about the prescription that could not be conveyed by the other attributes.
1524     */
1525    @Child(name = "note", type = {Annotation.class}, order=17, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1526    @Description(shortDefinition="Information about the prescription", formalDefinition="Extra information about the prescription that could not be conveyed by the other attributes." )
1527    protected List<Annotation> note;
1528
1529    /**
1530     * Indicates how the medication is to be used by the patient.
1531     */
1532    @Child(name = "dosageInstruction", type = {Dosage.class}, order=18, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1533    @Description(shortDefinition="How the medication should be taken", formalDefinition="Indicates how the medication is to be used by the patient." )
1534    protected List<Dosage> dosageInstruction;
1535
1536    /**
1537     * Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order).  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.
1538     */
1539    @Child(name = "dispenseRequest", type = {}, order=19, min=0, max=1, modifier=false, summary=false)
1540    @Description(shortDefinition="Medication supply authorization", formalDefinition="Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order).  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." )
1541    protected MedicationRequestDispenseRequestComponent dispenseRequest;
1542
1543    /**
1544     * 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. This block explains the prescriber's intent. If nothing is specified substitution may be done.
1545     */
1546    @Child(name = "substitution", type = {}, order=20, min=0, max=1, modifier=false, summary=false)
1547    @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. This block explains the prescriber's intent. If nothing is specified substitution may be done." )
1548    protected MedicationRequestSubstitutionComponent substitution;
1549
1550    /**
1551     * A link to a resource representing an earlier order related order or prescription.
1552     */
1553    @Child(name = "priorPrescription", type = {MedicationRequest.class}, order=21, min=0, max=1, modifier=false, summary=false)
1554    @Description(shortDefinition="An order/prescription that is being replaced", formalDefinition="A link to a resource representing an earlier order related order or prescription." )
1555    protected Reference priorPrescription;
1556
1557    /**
1558     * The actual object that is the target of the reference (A link to a resource representing an earlier order related order or prescription.)
1559     */
1560    protected MedicationRequest priorPrescriptionTarget;
1561
1562    /**
1563     * Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.
1564     */
1565    @Child(name = "detectedIssue", type = {DetectedIssue.class}, order=22, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1566    @Description(shortDefinition="Clinical Issue with action", formalDefinition="Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc." )
1567    protected List<Reference> detectedIssue;
1568    /**
1569     * The actual objects that are the target of the reference (Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.)
1570     */
1571    protected List<DetectedIssue> detectedIssueTarget;
1572
1573
1574    /**
1575     * Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource.
1576     */
1577    @Child(name = "eventHistory", type = {Provenance.class}, order=23, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1578    @Description(shortDefinition="A list of events of interest in the lifecycle", formalDefinition="Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource." )
1579    protected List<Reference> eventHistory;
1580    /**
1581     * The actual objects that are the target of the reference (Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource.)
1582     */
1583    protected List<Provenance> eventHistoryTarget;
1584
1585
1586    private static final long serialVersionUID = 299392400L;
1587
1588  /**
1589   * Constructor
1590   */
1591    public MedicationRequest() {
1592      super();
1593    }
1594
1595  /**
1596   * Constructor
1597   */
1598    public MedicationRequest(Enumeration<MedicationRequestIntent> intent, Type medication, Reference subject) {
1599      super();
1600      this.intent = intent;
1601      this.medication = medication;
1602      this.subject = subject;
1603    }
1604
1605    /**
1606     * @return {@link #identifier} (This records identifiers associated with this medication request that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. 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 must be tracked through an entire system.)
1607     */
1608    public List<Identifier> getIdentifier() { 
1609      if (this.identifier == null)
1610        this.identifier = new ArrayList<Identifier>();
1611      return this.identifier;
1612    }
1613
1614    /**
1615     * @return Returns a reference to <code>this</code> for easy method chaining
1616     */
1617    public MedicationRequest setIdentifier(List<Identifier> theIdentifier) { 
1618      this.identifier = theIdentifier;
1619      return this;
1620    }
1621
1622    public boolean hasIdentifier() { 
1623      if (this.identifier == null)
1624        return false;
1625      for (Identifier item : this.identifier)
1626        if (!item.isEmpty())
1627          return true;
1628      return false;
1629    }
1630
1631    public Identifier addIdentifier() { //3
1632      Identifier t = new Identifier();
1633      if (this.identifier == null)
1634        this.identifier = new ArrayList<Identifier>();
1635      this.identifier.add(t);
1636      return t;
1637    }
1638
1639    public MedicationRequest addIdentifier(Identifier t) { //3
1640      if (t == null)
1641        return this;
1642      if (this.identifier == null)
1643        this.identifier = new ArrayList<Identifier>();
1644      this.identifier.add(t);
1645      return this;
1646    }
1647
1648    /**
1649     * @return The first repetition of repeating field {@link #identifier}, creating it if it does not already exist
1650     */
1651    public Identifier getIdentifierFirstRep() { 
1652      if (getIdentifier().isEmpty()) {
1653        addIdentifier();
1654      }
1655      return getIdentifier().get(0);
1656    }
1657
1658    /**
1659     * @return {@link #definition} (Protocol or definition followed by this request.)
1660     */
1661    public List<Reference> getDefinition() { 
1662      if (this.definition == null)
1663        this.definition = new ArrayList<Reference>();
1664      return this.definition;
1665    }
1666
1667    /**
1668     * @return Returns a reference to <code>this</code> for easy method chaining
1669     */
1670    public MedicationRequest setDefinition(List<Reference> theDefinition) { 
1671      this.definition = theDefinition;
1672      return this;
1673    }
1674
1675    public boolean hasDefinition() { 
1676      if (this.definition == null)
1677        return false;
1678      for (Reference item : this.definition)
1679        if (!item.isEmpty())
1680          return true;
1681      return false;
1682    }
1683
1684    public Reference addDefinition() { //3
1685      Reference t = new Reference();
1686      if (this.definition == null)
1687        this.definition = new ArrayList<Reference>();
1688      this.definition.add(t);
1689      return t;
1690    }
1691
1692    public MedicationRequest addDefinition(Reference t) { //3
1693      if (t == null)
1694        return this;
1695      if (this.definition == null)
1696        this.definition = new ArrayList<Reference>();
1697      this.definition.add(t);
1698      return this;
1699    }
1700
1701    /**
1702     * @return The first repetition of repeating field {@link #definition}, creating it if it does not already exist
1703     */
1704    public Reference getDefinitionFirstRep() { 
1705      if (getDefinition().isEmpty()) {
1706        addDefinition();
1707      }
1708      return getDefinition().get(0);
1709    }
1710
1711    /**
1712     * @deprecated Use Reference#setResource(IBaseResource) instead
1713     */
1714    @Deprecated
1715    public List<Resource> getDefinitionTarget() { 
1716      if (this.definitionTarget == null)
1717        this.definitionTarget = new ArrayList<Resource>();
1718      return this.definitionTarget;
1719    }
1720
1721    /**
1722     * @return {@link #basedOn} (A plan or request that is fulfilled in whole or in part by this medication request.)
1723     */
1724    public List<Reference> getBasedOn() { 
1725      if (this.basedOn == null)
1726        this.basedOn = new ArrayList<Reference>();
1727      return this.basedOn;
1728    }
1729
1730    /**
1731     * @return Returns a reference to <code>this</code> for easy method chaining
1732     */
1733    public MedicationRequest setBasedOn(List<Reference> theBasedOn) { 
1734      this.basedOn = theBasedOn;
1735      return this;
1736    }
1737
1738    public boolean hasBasedOn() { 
1739      if (this.basedOn == null)
1740        return false;
1741      for (Reference item : this.basedOn)
1742        if (!item.isEmpty())
1743          return true;
1744      return false;
1745    }
1746
1747    public Reference addBasedOn() { //3
1748      Reference t = new Reference();
1749      if (this.basedOn == null)
1750        this.basedOn = new ArrayList<Reference>();
1751      this.basedOn.add(t);
1752      return t;
1753    }
1754
1755    public MedicationRequest addBasedOn(Reference t) { //3
1756      if (t == null)
1757        return this;
1758      if (this.basedOn == null)
1759        this.basedOn = new ArrayList<Reference>();
1760      this.basedOn.add(t);
1761      return this;
1762    }
1763
1764    /**
1765     * @return The first repetition of repeating field {@link #basedOn}, creating it if it does not already exist
1766     */
1767    public Reference getBasedOnFirstRep() { 
1768      if (getBasedOn().isEmpty()) {
1769        addBasedOn();
1770      }
1771      return getBasedOn().get(0);
1772    }
1773
1774    /**
1775     * @deprecated Use Reference#setResource(IBaseResource) instead
1776     */
1777    @Deprecated
1778    public List<Resource> getBasedOnTarget() { 
1779      if (this.basedOnTarget == null)
1780        this.basedOnTarget = new ArrayList<Resource>();
1781      return this.basedOnTarget;
1782    }
1783
1784    /**
1785     * @return {@link #groupIdentifier} (A shared identifier common to all requests that were authorized more or less simultaneously by a single author, representing the identifier of the requisition or prescription.)
1786     */
1787    public Identifier getGroupIdentifier() { 
1788      if (this.groupIdentifier == null)
1789        if (Configuration.errorOnAutoCreate())
1790          throw new Error("Attempt to auto-create MedicationRequest.groupIdentifier");
1791        else if (Configuration.doAutoCreate())
1792          this.groupIdentifier = new Identifier(); // cc
1793      return this.groupIdentifier;
1794    }
1795
1796    public boolean hasGroupIdentifier() { 
1797      return this.groupIdentifier != null && !this.groupIdentifier.isEmpty();
1798    }
1799
1800    /**
1801     * @param value {@link #groupIdentifier} (A shared identifier common to all requests that were authorized more or less simultaneously by a single author, representing the identifier of the requisition or prescription.)
1802     */
1803    public MedicationRequest setGroupIdentifier(Identifier value)  { 
1804      this.groupIdentifier = value;
1805      return this;
1806    }
1807
1808    /**
1809     * @return {@link #status} (A code specifying the current 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
1810     */
1811    public Enumeration<MedicationRequestStatus> getStatusElement() { 
1812      if (this.status == null)
1813        if (Configuration.errorOnAutoCreate())
1814          throw new Error("Attempt to auto-create MedicationRequest.status");
1815        else if (Configuration.doAutoCreate())
1816          this.status = new Enumeration<MedicationRequestStatus>(new MedicationRequestStatusEnumFactory()); // bb
1817      return this.status;
1818    }
1819
1820    public boolean hasStatusElement() { 
1821      return this.status != null && !this.status.isEmpty();
1822    }
1823
1824    public boolean hasStatus() { 
1825      return this.status != null && !this.status.isEmpty();
1826    }
1827
1828    /**
1829     * @param value {@link #status} (A code specifying the current 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
1830     */
1831    public MedicationRequest setStatusElement(Enumeration<MedicationRequestStatus> value) { 
1832      this.status = value;
1833      return this;
1834    }
1835
1836    /**
1837     * @return A code specifying the current state of the order.  Generally this will be active or completed state.
1838     */
1839    public MedicationRequestStatus getStatus() { 
1840      return this.status == null ? null : this.status.getValue();
1841    }
1842
1843    /**
1844     * @param value A code specifying the current state of the order.  Generally this will be active or completed state.
1845     */
1846    public MedicationRequest setStatus(MedicationRequestStatus value) { 
1847      if (value == null)
1848        this.status = null;
1849      else {
1850        if (this.status == null)
1851          this.status = new Enumeration<MedicationRequestStatus>(new MedicationRequestStatusEnumFactory());
1852        this.status.setValue(value);
1853      }
1854      return this;
1855    }
1856
1857    /**
1858     * @return {@link #intent} (Whether the request is a proposal, plan, or an original order.). This is the underlying object with id, value and extensions. The accessor "getIntent" gives direct access to the value
1859     */
1860    public Enumeration<MedicationRequestIntent> getIntentElement() { 
1861      if (this.intent == null)
1862        if (Configuration.errorOnAutoCreate())
1863          throw new Error("Attempt to auto-create MedicationRequest.intent");
1864        else if (Configuration.doAutoCreate())
1865          this.intent = new Enumeration<MedicationRequestIntent>(new MedicationRequestIntentEnumFactory()); // bb
1866      return this.intent;
1867    }
1868
1869    public boolean hasIntentElement() { 
1870      return this.intent != null && !this.intent.isEmpty();
1871    }
1872
1873    public boolean hasIntent() { 
1874      return this.intent != null && !this.intent.isEmpty();
1875    }
1876
1877    /**
1878     * @param value {@link #intent} (Whether the request is a proposal, plan, or an original order.). This is the underlying object with id, value and extensions. The accessor "getIntent" gives direct access to the value
1879     */
1880    public MedicationRequest setIntentElement(Enumeration<MedicationRequestIntent> value) { 
1881      this.intent = value;
1882      return this;
1883    }
1884
1885    /**
1886     * @return Whether the request is a proposal, plan, or an original order.
1887     */
1888    public MedicationRequestIntent getIntent() { 
1889      return this.intent == null ? null : this.intent.getValue();
1890    }
1891
1892    /**
1893     * @param value Whether the request is a proposal, plan, or an original order.
1894     */
1895    public MedicationRequest setIntent(MedicationRequestIntent value) { 
1896        if (this.intent == null)
1897          this.intent = new Enumeration<MedicationRequestIntent>(new MedicationRequestIntentEnumFactory());
1898        this.intent.setValue(value);
1899      return this;
1900    }
1901
1902    /**
1903     * @return {@link #category} (Indicates the type of medication order and where the medication is expected to be consumed or administered.)
1904     */
1905    public CodeableConcept getCategory() { 
1906      if (this.category == null)
1907        if (Configuration.errorOnAutoCreate())
1908          throw new Error("Attempt to auto-create MedicationRequest.category");
1909        else if (Configuration.doAutoCreate())
1910          this.category = new CodeableConcept(); // cc
1911      return this.category;
1912    }
1913
1914    public boolean hasCategory() { 
1915      return this.category != null && !this.category.isEmpty();
1916    }
1917
1918    /**
1919     * @param value {@link #category} (Indicates the type of medication order and where the medication is expected to be consumed or administered.)
1920     */
1921    public MedicationRequest setCategory(CodeableConcept value)  { 
1922      this.category = value;
1923      return this;
1924    }
1925
1926    /**
1927     * @return {@link #priority} (Indicates how quickly the Medication Request should be addressed with respect to other requests.). This is the underlying object with id, value and extensions. The accessor "getPriority" gives direct access to the value
1928     */
1929    public Enumeration<MedicationRequestPriority> getPriorityElement() { 
1930      if (this.priority == null)
1931        if (Configuration.errorOnAutoCreate())
1932          throw new Error("Attempt to auto-create MedicationRequest.priority");
1933        else if (Configuration.doAutoCreate())
1934          this.priority = new Enumeration<MedicationRequestPriority>(new MedicationRequestPriorityEnumFactory()); // bb
1935      return this.priority;
1936    }
1937
1938    public boolean hasPriorityElement() { 
1939      return this.priority != null && !this.priority.isEmpty();
1940    }
1941
1942    public boolean hasPriority() { 
1943      return this.priority != null && !this.priority.isEmpty();
1944    }
1945
1946    /**
1947     * @param value {@link #priority} (Indicates how quickly the Medication Request should be addressed with respect to other requests.). This is the underlying object with id, value and extensions. The accessor "getPriority" gives direct access to the value
1948     */
1949    public MedicationRequest setPriorityElement(Enumeration<MedicationRequestPriority> value) { 
1950      this.priority = value;
1951      return this;
1952    }
1953
1954    /**
1955     * @return Indicates how quickly the Medication Request should be addressed with respect to other requests.
1956     */
1957    public MedicationRequestPriority getPriority() { 
1958      return this.priority == null ? null : this.priority.getValue();
1959    }
1960
1961    /**
1962     * @param value Indicates how quickly the Medication Request should be addressed with respect to other requests.
1963     */
1964    public MedicationRequest setPriority(MedicationRequestPriority value) { 
1965      if (value == null)
1966        this.priority = null;
1967      else {
1968        if (this.priority == null)
1969          this.priority = new Enumeration<MedicationRequestPriority>(new MedicationRequestPriorityEnumFactory());
1970        this.priority.setValue(value);
1971      }
1972      return this;
1973    }
1974
1975    /**
1976     * @return {@link #medication} (Identifies the medication being requested. 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.)
1977     */
1978    public Type getMedication() { 
1979      return this.medication;
1980    }
1981
1982    /**
1983     * @return {@link #medication} (Identifies the medication being requested. 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.)
1984     */
1985    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1986      if (this.medication == null)
1987        return null;
1988      if (!(this.medication instanceof CodeableConcept))
1989        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1990      return (CodeableConcept) this.medication;
1991    }
1992
1993    public boolean hasMedicationCodeableConcept() { 
1994      return this != null && this.medication instanceof CodeableConcept;
1995    }
1996
1997    /**
1998     * @return {@link #medication} (Identifies the medication being requested. 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.)
1999     */
2000    public Reference getMedicationReference() throws FHIRException { 
2001      if (this.medication == null)
2002        return null;
2003      if (!(this.medication instanceof Reference))
2004        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
2005      return (Reference) this.medication;
2006    }
2007
2008    public boolean hasMedicationReference() { 
2009      return this != null && this.medication instanceof Reference;
2010    }
2011
2012    public boolean hasMedication() { 
2013      return this.medication != null && !this.medication.isEmpty();
2014    }
2015
2016    /**
2017     * @param value {@link #medication} (Identifies the medication being requested. 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.)
2018     */
2019    public MedicationRequest setMedication(Type value) throws FHIRFormatError { 
2020      if (value != null && !(value instanceof CodeableConcept || value instanceof Reference))
2021        throw new FHIRFormatError("Not the right type for MedicationRequest.medication[x]: "+value.fhirType());
2022      this.medication = value;
2023      return this;
2024    }
2025
2026    /**
2027     * @return {@link #subject} (A link to a resource representing the person or set of individuals to whom the medication will be given.)
2028     */
2029    public Reference getSubject() { 
2030      if (this.subject == null)
2031        if (Configuration.errorOnAutoCreate())
2032          throw new Error("Attempt to auto-create MedicationRequest.subject");
2033        else if (Configuration.doAutoCreate())
2034          this.subject = new Reference(); // cc
2035      return this.subject;
2036    }
2037
2038    public boolean hasSubject() { 
2039      return this.subject != null && !this.subject.isEmpty();
2040    }
2041
2042    /**
2043     * @param value {@link #subject} (A link to a resource representing the person or set of individuals to whom the medication will be given.)
2044     */
2045    public MedicationRequest setSubject(Reference value)  { 
2046      this.subject = value;
2047      return this;
2048    }
2049
2050    /**
2051     * @return {@link #subject} 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 or set of individuals to whom the medication will be given.)
2052     */
2053    public Resource getSubjectTarget() { 
2054      return this.subjectTarget;
2055    }
2056
2057    /**
2058     * @param value {@link #subject} 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 or set of individuals to whom the medication will be given.)
2059     */
2060    public MedicationRequest setSubjectTarget(Resource value) { 
2061      this.subjectTarget = value;
2062      return this;
2063    }
2064
2065    /**
2066     * @return {@link #context} (A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.)
2067     */
2068    public Reference getContext() { 
2069      if (this.context == null)
2070        if (Configuration.errorOnAutoCreate())
2071          throw new Error("Attempt to auto-create MedicationRequest.context");
2072        else if (Configuration.doAutoCreate())
2073          this.context = new Reference(); // cc
2074      return this.context;
2075    }
2076
2077    public boolean hasContext() { 
2078      return this.context != null && !this.context.isEmpty();
2079    }
2080
2081    /**
2082     * @param value {@link #context} (A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.)
2083     */
2084    public MedicationRequest setContext(Reference value)  { 
2085      this.context = value;
2086      return this;
2087    }
2088
2089    /**
2090     * @return {@link #context} 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 an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.)
2091     */
2092    public Resource getContextTarget() { 
2093      return this.contextTarget;
2094    }
2095
2096    /**
2097     * @param value {@link #context} 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 an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.)
2098     */
2099    public MedicationRequest setContextTarget(Resource value) { 
2100      this.contextTarget = value;
2101      return this;
2102    }
2103
2104    /**
2105     * @return {@link #supportingInformation} (Include additional information (for example, patient height and weight) that supports the ordering of the medication.)
2106     */
2107    public List<Reference> getSupportingInformation() { 
2108      if (this.supportingInformation == null)
2109        this.supportingInformation = new ArrayList<Reference>();
2110      return this.supportingInformation;
2111    }
2112
2113    /**
2114     * @return Returns a reference to <code>this</code> for easy method chaining
2115     */
2116    public MedicationRequest setSupportingInformation(List<Reference> theSupportingInformation) { 
2117      this.supportingInformation = theSupportingInformation;
2118      return this;
2119    }
2120
2121    public boolean hasSupportingInformation() { 
2122      if (this.supportingInformation == null)
2123        return false;
2124      for (Reference item : this.supportingInformation)
2125        if (!item.isEmpty())
2126          return true;
2127      return false;
2128    }
2129
2130    public Reference addSupportingInformation() { //3
2131      Reference t = new Reference();
2132      if (this.supportingInformation == null)
2133        this.supportingInformation = new ArrayList<Reference>();
2134      this.supportingInformation.add(t);
2135      return t;
2136    }
2137
2138    public MedicationRequest addSupportingInformation(Reference t) { //3
2139      if (t == null)
2140        return this;
2141      if (this.supportingInformation == null)
2142        this.supportingInformation = new ArrayList<Reference>();
2143      this.supportingInformation.add(t);
2144      return this;
2145    }
2146
2147    /**
2148     * @return The first repetition of repeating field {@link #supportingInformation}, creating it if it does not already exist
2149     */
2150    public Reference getSupportingInformationFirstRep() { 
2151      if (getSupportingInformation().isEmpty()) {
2152        addSupportingInformation();
2153      }
2154      return getSupportingInformation().get(0);
2155    }
2156
2157    /**
2158     * @deprecated Use Reference#setResource(IBaseResource) instead
2159     */
2160    @Deprecated
2161    public List<Resource> getSupportingInformationTarget() { 
2162      if (this.supportingInformationTarget == null)
2163        this.supportingInformationTarget = new ArrayList<Resource>();
2164      return this.supportingInformationTarget;
2165    }
2166
2167    /**
2168     * @return {@link #authoredOn} (The date (and perhaps time) when the prescription was initially written or authored on.). This is the underlying object with id, value and extensions. The accessor "getAuthoredOn" gives direct access to the value
2169     */
2170    public DateTimeType getAuthoredOnElement() { 
2171      if (this.authoredOn == null)
2172        if (Configuration.errorOnAutoCreate())
2173          throw new Error("Attempt to auto-create MedicationRequest.authoredOn");
2174        else if (Configuration.doAutoCreate())
2175          this.authoredOn = new DateTimeType(); // bb
2176      return this.authoredOn;
2177    }
2178
2179    public boolean hasAuthoredOnElement() { 
2180      return this.authoredOn != null && !this.authoredOn.isEmpty();
2181    }
2182
2183    public boolean hasAuthoredOn() { 
2184      return this.authoredOn != null && !this.authoredOn.isEmpty();
2185    }
2186
2187    /**
2188     * @param value {@link #authoredOn} (The date (and perhaps time) when the prescription was initially written or authored on.). This is the underlying object with id, value and extensions. The accessor "getAuthoredOn" gives direct access to the value
2189     */
2190    public MedicationRequest setAuthoredOnElement(DateTimeType value) { 
2191      this.authoredOn = value;
2192      return this;
2193    }
2194
2195    /**
2196     * @return The date (and perhaps time) when the prescription was initially written or authored on.
2197     */
2198    public Date getAuthoredOn() { 
2199      return this.authoredOn == null ? null : this.authoredOn.getValue();
2200    }
2201
2202    /**
2203     * @param value The date (and perhaps time) when the prescription was initially written or authored on.
2204     */
2205    public MedicationRequest setAuthoredOn(Date value) { 
2206      if (value == null)
2207        this.authoredOn = null;
2208      else {
2209        if (this.authoredOn == null)
2210          this.authoredOn = new DateTimeType();
2211        this.authoredOn.setValue(value);
2212      }
2213      return this;
2214    }
2215
2216    /**
2217     * @return {@link #requester} (The individual, organization or device that initiated the request and has responsibility for its activation.)
2218     */
2219    public MedicationRequestRequesterComponent getRequester() { 
2220      if (this.requester == null)
2221        if (Configuration.errorOnAutoCreate())
2222          throw new Error("Attempt to auto-create MedicationRequest.requester");
2223        else if (Configuration.doAutoCreate())
2224          this.requester = new MedicationRequestRequesterComponent(); // cc
2225      return this.requester;
2226    }
2227
2228    public boolean hasRequester() { 
2229      return this.requester != null && !this.requester.isEmpty();
2230    }
2231
2232    /**
2233     * @param value {@link #requester} (The individual, organization or device that initiated the request and has responsibility for its activation.)
2234     */
2235    public MedicationRequest setRequester(MedicationRequestRequesterComponent value)  { 
2236      this.requester = value;
2237      return this;
2238    }
2239
2240    /**
2241     * @return {@link #recorder} (The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.)
2242     */
2243    public Reference getRecorder() { 
2244      if (this.recorder == null)
2245        if (Configuration.errorOnAutoCreate())
2246          throw new Error("Attempt to auto-create MedicationRequest.recorder");
2247        else if (Configuration.doAutoCreate())
2248          this.recorder = new Reference(); // cc
2249      return this.recorder;
2250    }
2251
2252    public boolean hasRecorder() { 
2253      return this.recorder != null && !this.recorder.isEmpty();
2254    }
2255
2256    /**
2257     * @param value {@link #recorder} (The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.)
2258     */
2259    public MedicationRequest setRecorder(Reference value)  { 
2260      this.recorder = value;
2261      return this;
2262    }
2263
2264    /**
2265     * @return {@link #recorder} 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 person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.)
2266     */
2267    public Practitioner getRecorderTarget() { 
2268      if (this.recorderTarget == null)
2269        if (Configuration.errorOnAutoCreate())
2270          throw new Error("Attempt to auto-create MedicationRequest.recorder");
2271        else if (Configuration.doAutoCreate())
2272          this.recorderTarget = new Practitioner(); // aa
2273      return this.recorderTarget;
2274    }
2275
2276    /**
2277     * @param value {@link #recorder} 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 person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.)
2278     */
2279    public MedicationRequest setRecorderTarget(Practitioner value) { 
2280      this.recorderTarget = value;
2281      return this;
2282    }
2283
2284    /**
2285     * @return {@link #reasonCode} (The reason or the indication for ordering the medication.)
2286     */
2287    public List<CodeableConcept> getReasonCode() { 
2288      if (this.reasonCode == null)
2289        this.reasonCode = new ArrayList<CodeableConcept>();
2290      return this.reasonCode;
2291    }
2292
2293    /**
2294     * @return Returns a reference to <code>this</code> for easy method chaining
2295     */
2296    public MedicationRequest setReasonCode(List<CodeableConcept> theReasonCode) { 
2297      this.reasonCode = theReasonCode;
2298      return this;
2299    }
2300
2301    public boolean hasReasonCode() { 
2302      if (this.reasonCode == null)
2303        return false;
2304      for (CodeableConcept item : this.reasonCode)
2305        if (!item.isEmpty())
2306          return true;
2307      return false;
2308    }
2309
2310    public CodeableConcept addReasonCode() { //3
2311      CodeableConcept t = new CodeableConcept();
2312      if (this.reasonCode == null)
2313        this.reasonCode = new ArrayList<CodeableConcept>();
2314      this.reasonCode.add(t);
2315      return t;
2316    }
2317
2318    public MedicationRequest addReasonCode(CodeableConcept t) { //3
2319      if (t == null)
2320        return this;
2321      if (this.reasonCode == null)
2322        this.reasonCode = new ArrayList<CodeableConcept>();
2323      this.reasonCode.add(t);
2324      return this;
2325    }
2326
2327    /**
2328     * @return The first repetition of repeating field {@link #reasonCode}, creating it if it does not already exist
2329     */
2330    public CodeableConcept getReasonCodeFirstRep() { 
2331      if (getReasonCode().isEmpty()) {
2332        addReasonCode();
2333      }
2334      return getReasonCode().get(0);
2335    }
2336
2337    /**
2338     * @return {@link #reasonReference} (Condition or observation that supports why the medication was ordered.)
2339     */
2340    public List<Reference> getReasonReference() { 
2341      if (this.reasonReference == null)
2342        this.reasonReference = new ArrayList<Reference>();
2343      return this.reasonReference;
2344    }
2345
2346    /**
2347     * @return Returns a reference to <code>this</code> for easy method chaining
2348     */
2349    public MedicationRequest setReasonReference(List<Reference> theReasonReference) { 
2350      this.reasonReference = theReasonReference;
2351      return this;
2352    }
2353
2354    public boolean hasReasonReference() { 
2355      if (this.reasonReference == null)
2356        return false;
2357      for (Reference item : this.reasonReference)
2358        if (!item.isEmpty())
2359          return true;
2360      return false;
2361    }
2362
2363    public Reference addReasonReference() { //3
2364      Reference t = new Reference();
2365      if (this.reasonReference == null)
2366        this.reasonReference = new ArrayList<Reference>();
2367      this.reasonReference.add(t);
2368      return t;
2369    }
2370
2371    public MedicationRequest addReasonReference(Reference t) { //3
2372      if (t == null)
2373        return this;
2374      if (this.reasonReference == null)
2375        this.reasonReference = new ArrayList<Reference>();
2376      this.reasonReference.add(t);
2377      return this;
2378    }
2379
2380    /**
2381     * @return The first repetition of repeating field {@link #reasonReference}, creating it if it does not already exist
2382     */
2383    public Reference getReasonReferenceFirstRep() { 
2384      if (getReasonReference().isEmpty()) {
2385        addReasonReference();
2386      }
2387      return getReasonReference().get(0);
2388    }
2389
2390    /**
2391     * @deprecated Use Reference#setResource(IBaseResource) instead
2392     */
2393    @Deprecated
2394    public List<Resource> getReasonReferenceTarget() { 
2395      if (this.reasonReferenceTarget == null)
2396        this.reasonReferenceTarget = new ArrayList<Resource>();
2397      return this.reasonReferenceTarget;
2398    }
2399
2400    /**
2401     * @return {@link #note} (Extra information about the prescription that could not be conveyed by the other attributes.)
2402     */
2403    public List<Annotation> getNote() { 
2404      if (this.note == null)
2405        this.note = new ArrayList<Annotation>();
2406      return this.note;
2407    }
2408
2409    /**
2410     * @return Returns a reference to <code>this</code> for easy method chaining
2411     */
2412    public MedicationRequest setNote(List<Annotation> theNote) { 
2413      this.note = theNote;
2414      return this;
2415    }
2416
2417    public boolean hasNote() { 
2418      if (this.note == null)
2419        return false;
2420      for (Annotation item : this.note)
2421        if (!item.isEmpty())
2422          return true;
2423      return false;
2424    }
2425
2426    public Annotation addNote() { //3
2427      Annotation t = new Annotation();
2428      if (this.note == null)
2429        this.note = new ArrayList<Annotation>();
2430      this.note.add(t);
2431      return t;
2432    }
2433
2434    public MedicationRequest addNote(Annotation t) { //3
2435      if (t == null)
2436        return this;
2437      if (this.note == null)
2438        this.note = new ArrayList<Annotation>();
2439      this.note.add(t);
2440      return this;
2441    }
2442
2443    /**
2444     * @return The first repetition of repeating field {@link #note}, creating it if it does not already exist
2445     */
2446    public Annotation getNoteFirstRep() { 
2447      if (getNote().isEmpty()) {
2448        addNote();
2449      }
2450      return getNote().get(0);
2451    }
2452
2453    /**
2454     * @return {@link #dosageInstruction} (Indicates how the medication is to be used by the patient.)
2455     */
2456    public List<Dosage> getDosageInstruction() { 
2457      if (this.dosageInstruction == null)
2458        this.dosageInstruction = new ArrayList<Dosage>();
2459      return this.dosageInstruction;
2460    }
2461
2462    /**
2463     * @return Returns a reference to <code>this</code> for easy method chaining
2464     */
2465    public MedicationRequest setDosageInstruction(List<Dosage> theDosageInstruction) { 
2466      this.dosageInstruction = theDosageInstruction;
2467      return this;
2468    }
2469
2470    public boolean hasDosageInstruction() { 
2471      if (this.dosageInstruction == null)
2472        return false;
2473      for (Dosage item : this.dosageInstruction)
2474        if (!item.isEmpty())
2475          return true;
2476      return false;
2477    }
2478
2479    public Dosage addDosageInstruction() { //3
2480      Dosage t = new Dosage();
2481      if (this.dosageInstruction == null)
2482        this.dosageInstruction = new ArrayList<Dosage>();
2483      this.dosageInstruction.add(t);
2484      return t;
2485    }
2486
2487    public MedicationRequest addDosageInstruction(Dosage t) { //3
2488      if (t == null)
2489        return this;
2490      if (this.dosageInstruction == null)
2491        this.dosageInstruction = new ArrayList<Dosage>();
2492      this.dosageInstruction.add(t);
2493      return this;
2494    }
2495
2496    /**
2497     * @return The first repetition of repeating field {@link #dosageInstruction}, creating it if it does not already exist
2498     */
2499    public Dosage getDosageInstructionFirstRep() { 
2500      if (getDosageInstruction().isEmpty()) {
2501        addDosageInstruction();
2502      }
2503      return getDosageInstruction().get(0);
2504    }
2505
2506    /**
2507     * @return {@link #dispenseRequest} (Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order).  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.)
2508     */
2509    public MedicationRequestDispenseRequestComponent getDispenseRequest() { 
2510      if (this.dispenseRequest == null)
2511        if (Configuration.errorOnAutoCreate())
2512          throw new Error("Attempt to auto-create MedicationRequest.dispenseRequest");
2513        else if (Configuration.doAutoCreate())
2514          this.dispenseRequest = new MedicationRequestDispenseRequestComponent(); // cc
2515      return this.dispenseRequest;
2516    }
2517
2518    public boolean hasDispenseRequest() { 
2519      return this.dispenseRequest != null && !this.dispenseRequest.isEmpty();
2520    }
2521
2522    /**
2523     * @param value {@link #dispenseRequest} (Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order).  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.)
2524     */
2525    public MedicationRequest setDispenseRequest(MedicationRequestDispenseRequestComponent value)  { 
2526      this.dispenseRequest = value;
2527      return this;
2528    }
2529
2530    /**
2531     * @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. This block explains the prescriber's intent. If nothing is specified substitution may be done.)
2532     */
2533    public MedicationRequestSubstitutionComponent getSubstitution() { 
2534      if (this.substitution == null)
2535        if (Configuration.errorOnAutoCreate())
2536          throw new Error("Attempt to auto-create MedicationRequest.substitution");
2537        else if (Configuration.doAutoCreate())
2538          this.substitution = new MedicationRequestSubstitutionComponent(); // cc
2539      return this.substitution;
2540    }
2541
2542    public boolean hasSubstitution() { 
2543      return this.substitution != null && !this.substitution.isEmpty();
2544    }
2545
2546    /**
2547     * @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. This block explains the prescriber's intent. If nothing is specified substitution may be done.)
2548     */
2549    public MedicationRequest setSubstitution(MedicationRequestSubstitutionComponent value)  { 
2550      this.substitution = value;
2551      return this;
2552    }
2553
2554    /**
2555     * @return {@link #priorPrescription} (A link to a resource representing an earlier order related order or prescription.)
2556     */
2557    public Reference getPriorPrescription() { 
2558      if (this.priorPrescription == null)
2559        if (Configuration.errorOnAutoCreate())
2560          throw new Error("Attempt to auto-create MedicationRequest.priorPrescription");
2561        else if (Configuration.doAutoCreate())
2562          this.priorPrescription = new Reference(); // cc
2563      return this.priorPrescription;
2564    }
2565
2566    public boolean hasPriorPrescription() { 
2567      return this.priorPrescription != null && !this.priorPrescription.isEmpty();
2568    }
2569
2570    /**
2571     * @param value {@link #priorPrescription} (A link to a resource representing an earlier order related order or prescription.)
2572     */
2573    public MedicationRequest setPriorPrescription(Reference value)  { 
2574      this.priorPrescription = value;
2575      return this;
2576    }
2577
2578    /**
2579     * @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 related order or prescription.)
2580     */
2581    public MedicationRequest getPriorPrescriptionTarget() { 
2582      if (this.priorPrescriptionTarget == null)
2583        if (Configuration.errorOnAutoCreate())
2584          throw new Error("Attempt to auto-create MedicationRequest.priorPrescription");
2585        else if (Configuration.doAutoCreate())
2586          this.priorPrescriptionTarget = new MedicationRequest(); // aa
2587      return this.priorPrescriptionTarget;
2588    }
2589
2590    /**
2591     * @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 related order or prescription.)
2592     */
2593    public MedicationRequest setPriorPrescriptionTarget(MedicationRequest value) { 
2594      this.priorPrescriptionTarget = value;
2595      return this;
2596    }
2597
2598    /**
2599     * @return {@link #detectedIssue} (Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.)
2600     */
2601    public List<Reference> getDetectedIssue() { 
2602      if (this.detectedIssue == null)
2603        this.detectedIssue = new ArrayList<Reference>();
2604      return this.detectedIssue;
2605    }
2606
2607    /**
2608     * @return Returns a reference to <code>this</code> for easy method chaining
2609     */
2610    public MedicationRequest setDetectedIssue(List<Reference> theDetectedIssue) { 
2611      this.detectedIssue = theDetectedIssue;
2612      return this;
2613    }
2614
2615    public boolean hasDetectedIssue() { 
2616      if (this.detectedIssue == null)
2617        return false;
2618      for (Reference item : this.detectedIssue)
2619        if (!item.isEmpty())
2620          return true;
2621      return false;
2622    }
2623
2624    public Reference addDetectedIssue() { //3
2625      Reference t = new Reference();
2626      if (this.detectedIssue == null)
2627        this.detectedIssue = new ArrayList<Reference>();
2628      this.detectedIssue.add(t);
2629      return t;
2630    }
2631
2632    public MedicationRequest addDetectedIssue(Reference t) { //3
2633      if (t == null)
2634        return this;
2635      if (this.detectedIssue == null)
2636        this.detectedIssue = new ArrayList<Reference>();
2637      this.detectedIssue.add(t);
2638      return this;
2639    }
2640
2641    /**
2642     * @return The first repetition of repeating field {@link #detectedIssue}, creating it if it does not already exist
2643     */
2644    public Reference getDetectedIssueFirstRep() { 
2645      if (getDetectedIssue().isEmpty()) {
2646        addDetectedIssue();
2647      }
2648      return getDetectedIssue().get(0);
2649    }
2650
2651    /**
2652     * @deprecated Use Reference#setResource(IBaseResource) instead
2653     */
2654    @Deprecated
2655    public List<DetectedIssue> getDetectedIssueTarget() { 
2656      if (this.detectedIssueTarget == null)
2657        this.detectedIssueTarget = new ArrayList<DetectedIssue>();
2658      return this.detectedIssueTarget;
2659    }
2660
2661    /**
2662     * @deprecated Use Reference#setResource(IBaseResource) instead
2663     */
2664    @Deprecated
2665    public DetectedIssue addDetectedIssueTarget() { 
2666      DetectedIssue r = new DetectedIssue();
2667      if (this.detectedIssueTarget == null)
2668        this.detectedIssueTarget = new ArrayList<DetectedIssue>();
2669      this.detectedIssueTarget.add(r);
2670      return r;
2671    }
2672
2673    /**
2674     * @return {@link #eventHistory} (Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource.)
2675     */
2676    public List<Reference> getEventHistory() { 
2677      if (this.eventHistory == null)
2678        this.eventHistory = new ArrayList<Reference>();
2679      return this.eventHistory;
2680    }
2681
2682    /**
2683     * @return Returns a reference to <code>this</code> for easy method chaining
2684     */
2685    public MedicationRequest setEventHistory(List<Reference> theEventHistory) { 
2686      this.eventHistory = theEventHistory;
2687      return this;
2688    }
2689
2690    public boolean hasEventHistory() { 
2691      if (this.eventHistory == null)
2692        return false;
2693      for (Reference item : this.eventHistory)
2694        if (!item.isEmpty())
2695          return true;
2696      return false;
2697    }
2698
2699    public Reference addEventHistory() { //3
2700      Reference t = new Reference();
2701      if (this.eventHistory == null)
2702        this.eventHistory = new ArrayList<Reference>();
2703      this.eventHistory.add(t);
2704      return t;
2705    }
2706
2707    public MedicationRequest addEventHistory(Reference t) { //3
2708      if (t == null)
2709        return this;
2710      if (this.eventHistory == null)
2711        this.eventHistory = new ArrayList<Reference>();
2712      this.eventHistory.add(t);
2713      return this;
2714    }
2715
2716    /**
2717     * @return The first repetition of repeating field {@link #eventHistory}, creating it if it does not already exist
2718     */
2719    public Reference getEventHistoryFirstRep() { 
2720      if (getEventHistory().isEmpty()) {
2721        addEventHistory();
2722      }
2723      return getEventHistory().get(0);
2724    }
2725
2726    /**
2727     * @deprecated Use Reference#setResource(IBaseResource) instead
2728     */
2729    @Deprecated
2730    public List<Provenance> getEventHistoryTarget() { 
2731      if (this.eventHistoryTarget == null)
2732        this.eventHistoryTarget = new ArrayList<Provenance>();
2733      return this.eventHistoryTarget;
2734    }
2735
2736    /**
2737     * @deprecated Use Reference#setResource(IBaseResource) instead
2738     */
2739    @Deprecated
2740    public Provenance addEventHistoryTarget() { 
2741      Provenance r = new Provenance();
2742      if (this.eventHistoryTarget == null)
2743        this.eventHistoryTarget = new ArrayList<Provenance>();
2744      this.eventHistoryTarget.add(r);
2745      return r;
2746    }
2747
2748      protected void listChildren(List<Property> children) {
2749        super.listChildren(children);
2750        children.add(new Property("identifier", "Identifier", "This records identifiers associated with this medication request that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. 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 must be tracked through an entire system.", 0, java.lang.Integer.MAX_VALUE, identifier));
2751        children.add(new Property("definition", "Reference(ActivityDefinition|PlanDefinition)", "Protocol or definition followed by this request.", 0, java.lang.Integer.MAX_VALUE, definition));
2752        children.add(new Property("basedOn", "Reference(CarePlan|MedicationRequest|ProcedureRequest|ReferralRequest)", "A plan or request that is fulfilled in whole or in part by this medication request.", 0, java.lang.Integer.MAX_VALUE, basedOn));
2753        children.add(new Property("groupIdentifier", "Identifier", "A shared identifier common to all requests that were authorized more or less simultaneously by a single author, representing the identifier of the requisition or prescription.", 0, 1, groupIdentifier));
2754        children.add(new Property("status", "code", "A code specifying the current state of the order.  Generally this will be active or completed state.", 0, 1, status));
2755        children.add(new Property("intent", "code", "Whether the request is a proposal, plan, or an original order.", 0, 1, intent));
2756        children.add(new Property("category", "CodeableConcept", "Indicates the type of medication order and where the medication is expected to be consumed or administered.", 0, 1, category));
2757        children.add(new Property("priority", "code", "Indicates how quickly the Medication Request should be addressed with respect to other requests.", 0, 1, priority));
2758        children.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being requested. 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, 1, medication));
2759        children.add(new Property("subject", "Reference(Patient|Group)", "A link to a resource representing the person or set of individuals to whom the medication will be given.", 0, 1, subject));
2760        children.add(new Property("context", "Reference(Encounter|EpisodeOfCare)", "A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.", 0, 1, context));
2761        children.add(new Property("supportingInformation", "Reference(Any)", "Include additional information (for example, patient height and weight) that supports the ordering of the medication.", 0, java.lang.Integer.MAX_VALUE, supportingInformation));
2762        children.add(new Property("authoredOn", "dateTime", "The date (and perhaps time) when the prescription was initially written or authored on.", 0, 1, authoredOn));
2763        children.add(new Property("requester", "", "The individual, organization or device that initiated the request and has responsibility for its activation.", 0, 1, requester));
2764        children.add(new Property("recorder", "Reference(Practitioner)", "The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.", 0, 1, recorder));
2765        children.add(new Property("reasonCode", "CodeableConcept", "The reason or the indication for ordering the medication.", 0, java.lang.Integer.MAX_VALUE, reasonCode));
2766        children.add(new Property("reasonReference", "Reference(Condition|Observation)", "Condition or observation that supports why the medication was ordered.", 0, java.lang.Integer.MAX_VALUE, reasonReference));
2767        children.add(new Property("note", "Annotation", "Extra information about the prescription that could not be conveyed by the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
2768        children.add(new Property("dosageInstruction", "Dosage", "Indicates how the medication is to be used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosageInstruction));
2769        children.add(new Property("dispenseRequest", "", "Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order).  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, 1, dispenseRequest));
2770        children.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. This block explains the prescriber's intent. If nothing is specified substitution may be done.", 0, 1, substitution));
2771        children.add(new Property("priorPrescription", "Reference(MedicationRequest)", "A link to a resource representing an earlier order related order or prescription.", 0, 1, priorPrescription));
2772        children.add(new Property("detectedIssue", "Reference(DetectedIssue)", "Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.", 0, java.lang.Integer.MAX_VALUE, detectedIssue));
2773        children.add(new Property("eventHistory", "Reference(Provenance)", "Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource.", 0, java.lang.Integer.MAX_VALUE, eventHistory));
2774      }
2775
2776      @Override
2777      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
2778        switch (_hash) {
2779        case -1618432855: /*identifier*/  return new Property("identifier", "Identifier", "This records identifiers associated with this medication request that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. 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 must be tracked through an entire system.", 0, java.lang.Integer.MAX_VALUE, identifier);
2780        case -1014418093: /*definition*/  return new Property("definition", "Reference(ActivityDefinition|PlanDefinition)", "Protocol or definition followed by this request.", 0, java.lang.Integer.MAX_VALUE, definition);
2781        case -332612366: /*basedOn*/  return new Property("basedOn", "Reference(CarePlan|MedicationRequest|ProcedureRequest|ReferralRequest)", "A plan or request that is fulfilled in whole or in part by this medication request.", 0, java.lang.Integer.MAX_VALUE, basedOn);
2782        case -445338488: /*groupIdentifier*/  return new Property("groupIdentifier", "Identifier", "A shared identifier common to all requests that were authorized more or less simultaneously by a single author, representing the identifier of the requisition or prescription.", 0, 1, groupIdentifier);
2783        case -892481550: /*status*/  return new Property("status", "code", "A code specifying the current state of the order.  Generally this will be active or completed state.", 0, 1, status);
2784        case -1183762788: /*intent*/  return new Property("intent", "code", "Whether the request is a proposal, plan, or an original order.", 0, 1, intent);
2785        case 50511102: /*category*/  return new Property("category", "CodeableConcept", "Indicates the type of medication order and where the medication is expected to be consumed or administered.", 0, 1, category);
2786        case -1165461084: /*priority*/  return new Property("priority", "code", "Indicates how quickly the Medication Request should be addressed with respect to other requests.", 0, 1, priority);
2787        case 1458402129: /*medication[x]*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being requested. 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, 1, medication);
2788        case 1998965455: /*medication*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being requested. 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, 1, medication);
2789        case -209845038: /*medicationCodeableConcept*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being requested. 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, 1, medication);
2790        case 2104315196: /*medicationReference*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being requested. 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, 1, medication);
2791        case -1867885268: /*subject*/  return new Property("subject", "Reference(Patient|Group)", "A link to a resource representing the person or set of individuals to whom the medication will be given.", 0, 1, subject);
2792        case 951530927: /*context*/  return new Property("context", "Reference(Encounter|EpisodeOfCare)", "A link to an encounter, or episode of care, that identifies the particular occurrence or set occurrences of contact between patient and health care provider.", 0, 1, context);
2793        case -1248768647: /*supportingInformation*/  return new Property("supportingInformation", "Reference(Any)", "Include additional information (for example, patient height and weight) that supports the ordering of the medication.", 0, java.lang.Integer.MAX_VALUE, supportingInformation);
2794        case -1500852503: /*authoredOn*/  return new Property("authoredOn", "dateTime", "The date (and perhaps time) when the prescription was initially written or authored on.", 0, 1, authoredOn);
2795        case 693933948: /*requester*/  return new Property("requester", "", "The individual, organization or device that initiated the request and has responsibility for its activation.", 0, 1, requester);
2796        case -799233858: /*recorder*/  return new Property("recorder", "Reference(Practitioner)", "The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.", 0, 1, recorder);
2797        case 722137681: /*reasonCode*/  return new Property("reasonCode", "CodeableConcept", "The reason or the indication for ordering the medication.", 0, java.lang.Integer.MAX_VALUE, reasonCode);
2798        case -1146218137: /*reasonReference*/  return new Property("reasonReference", "Reference(Condition|Observation)", "Condition or observation that supports why the medication was ordered.", 0, java.lang.Integer.MAX_VALUE, reasonReference);
2799        case 3387378: /*note*/  return new Property("note", "Annotation", "Extra information about the prescription that could not be conveyed by the other attributes.", 0, java.lang.Integer.MAX_VALUE, note);
2800        case -1201373865: /*dosageInstruction*/  return new Property("dosageInstruction", "Dosage", "Indicates how the medication is to be used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosageInstruction);
2801        case 824620658: /*dispenseRequest*/  return new Property("dispenseRequest", "", "Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order).  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, 1, dispenseRequest);
2802        case 826147581: /*substitution*/  return 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. This block explains the prescriber's intent. If nothing is specified substitution may be done.", 0, 1, substitution);
2803        case -486355964: /*priorPrescription*/  return new Property("priorPrescription", "Reference(MedicationRequest)", "A link to a resource representing an earlier order related order or prescription.", 0, 1, priorPrescription);
2804        case 51602295: /*detectedIssue*/  return new Property("detectedIssue", "Reference(DetectedIssue)", "Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.", 0, java.lang.Integer.MAX_VALUE, detectedIssue);
2805        case 1835190426: /*eventHistory*/  return new Property("eventHistory", "Reference(Provenance)", "Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource.", 0, java.lang.Integer.MAX_VALUE, eventHistory);
2806        default: return super.getNamedProperty(_hash, _name, _checkValid);
2807        }
2808
2809      }
2810
2811      @Override
2812      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
2813        switch (hash) {
2814        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
2815        case -1014418093: /*definition*/ return this.definition == null ? new Base[0] : this.definition.toArray(new Base[this.definition.size()]); // Reference
2816        case -332612366: /*basedOn*/ return this.basedOn == null ? new Base[0] : this.basedOn.toArray(new Base[this.basedOn.size()]); // Reference
2817        case -445338488: /*groupIdentifier*/ return this.groupIdentifier == null ? new Base[0] : new Base[] {this.groupIdentifier}; // Identifier
2818        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<MedicationRequestStatus>
2819        case -1183762788: /*intent*/ return this.intent == null ? new Base[0] : new Base[] {this.intent}; // Enumeration<MedicationRequestIntent>
2820        case 50511102: /*category*/ return this.category == null ? new Base[0] : new Base[] {this.category}; // CodeableConcept
2821        case -1165461084: /*priority*/ return this.priority == null ? new Base[0] : new Base[] {this.priority}; // Enumeration<MedicationRequestPriority>
2822        case 1998965455: /*medication*/ return this.medication == null ? new Base[0] : new Base[] {this.medication}; // Type
2823        case -1867885268: /*subject*/ return this.subject == null ? new Base[0] : new Base[] {this.subject}; // Reference
2824        case 951530927: /*context*/ return this.context == null ? new Base[0] : new Base[] {this.context}; // Reference
2825        case -1248768647: /*supportingInformation*/ return this.supportingInformation == null ? new Base[0] : this.supportingInformation.toArray(new Base[this.supportingInformation.size()]); // Reference
2826        case -1500852503: /*authoredOn*/ return this.authoredOn == null ? new Base[0] : new Base[] {this.authoredOn}; // DateTimeType
2827        case 693933948: /*requester*/ return this.requester == null ? new Base[0] : new Base[] {this.requester}; // MedicationRequestRequesterComponent
2828        case -799233858: /*recorder*/ return this.recorder == null ? new Base[0] : new Base[] {this.recorder}; // Reference
2829        case 722137681: /*reasonCode*/ return this.reasonCode == null ? new Base[0] : this.reasonCode.toArray(new Base[this.reasonCode.size()]); // CodeableConcept
2830        case -1146218137: /*reasonReference*/ return this.reasonReference == null ? new Base[0] : this.reasonReference.toArray(new Base[this.reasonReference.size()]); // Reference
2831        case 3387378: /*note*/ return this.note == null ? new Base[0] : this.note.toArray(new Base[this.note.size()]); // Annotation
2832        case -1201373865: /*dosageInstruction*/ return this.dosageInstruction == null ? new Base[0] : this.dosageInstruction.toArray(new Base[this.dosageInstruction.size()]); // Dosage
2833        case 824620658: /*dispenseRequest*/ return this.dispenseRequest == null ? new Base[0] : new Base[] {this.dispenseRequest}; // MedicationRequestDispenseRequestComponent
2834        case 826147581: /*substitution*/ return this.substitution == null ? new Base[0] : new Base[] {this.substitution}; // MedicationRequestSubstitutionComponent
2835        case -486355964: /*priorPrescription*/ return this.priorPrescription == null ? new Base[0] : new Base[] {this.priorPrescription}; // Reference
2836        case 51602295: /*detectedIssue*/ return this.detectedIssue == null ? new Base[0] : this.detectedIssue.toArray(new Base[this.detectedIssue.size()]); // Reference
2837        case 1835190426: /*eventHistory*/ return this.eventHistory == null ? new Base[0] : this.eventHistory.toArray(new Base[this.eventHistory.size()]); // Reference
2838        default: return super.getProperty(hash, name, checkValid);
2839        }
2840
2841      }
2842
2843      @Override
2844      public Base setProperty(int hash, String name, Base value) throws FHIRException {
2845        switch (hash) {
2846        case -1618432855: // identifier
2847          this.getIdentifier().add(castToIdentifier(value)); // Identifier
2848          return value;
2849        case -1014418093: // definition
2850          this.getDefinition().add(castToReference(value)); // Reference
2851          return value;
2852        case -332612366: // basedOn
2853          this.getBasedOn().add(castToReference(value)); // Reference
2854          return value;
2855        case -445338488: // groupIdentifier
2856          this.groupIdentifier = castToIdentifier(value); // Identifier
2857          return value;
2858        case -892481550: // status
2859          value = new MedicationRequestStatusEnumFactory().fromType(castToCode(value));
2860          this.status = (Enumeration) value; // Enumeration<MedicationRequestStatus>
2861          return value;
2862        case -1183762788: // intent
2863          value = new MedicationRequestIntentEnumFactory().fromType(castToCode(value));
2864          this.intent = (Enumeration) value; // Enumeration<MedicationRequestIntent>
2865          return value;
2866        case 50511102: // category
2867          this.category = castToCodeableConcept(value); // CodeableConcept
2868          return value;
2869        case -1165461084: // priority
2870          value = new MedicationRequestPriorityEnumFactory().fromType(castToCode(value));
2871          this.priority = (Enumeration) value; // Enumeration<MedicationRequestPriority>
2872          return value;
2873        case 1998965455: // medication
2874          this.medication = castToType(value); // Type
2875          return value;
2876        case -1867885268: // subject
2877          this.subject = castToReference(value); // Reference
2878          return value;
2879        case 951530927: // context
2880          this.context = castToReference(value); // Reference
2881          return value;
2882        case -1248768647: // supportingInformation
2883          this.getSupportingInformation().add(castToReference(value)); // Reference
2884          return value;
2885        case -1500852503: // authoredOn
2886          this.authoredOn = castToDateTime(value); // DateTimeType
2887          return value;
2888        case 693933948: // requester
2889          this.requester = (MedicationRequestRequesterComponent) value; // MedicationRequestRequesterComponent
2890          return value;
2891        case -799233858: // recorder
2892          this.recorder = castToReference(value); // Reference
2893          return value;
2894        case 722137681: // reasonCode
2895          this.getReasonCode().add(castToCodeableConcept(value)); // CodeableConcept
2896          return value;
2897        case -1146218137: // reasonReference
2898          this.getReasonReference().add(castToReference(value)); // Reference
2899          return value;
2900        case 3387378: // note
2901          this.getNote().add(castToAnnotation(value)); // Annotation
2902          return value;
2903        case -1201373865: // dosageInstruction
2904          this.getDosageInstruction().add(castToDosage(value)); // Dosage
2905          return value;
2906        case 824620658: // dispenseRequest
2907          this.dispenseRequest = (MedicationRequestDispenseRequestComponent) value; // MedicationRequestDispenseRequestComponent
2908          return value;
2909        case 826147581: // substitution
2910          this.substitution = (MedicationRequestSubstitutionComponent) value; // MedicationRequestSubstitutionComponent
2911          return value;
2912        case -486355964: // priorPrescription
2913          this.priorPrescription = castToReference(value); // Reference
2914          return value;
2915        case 51602295: // detectedIssue
2916          this.getDetectedIssue().add(castToReference(value)); // Reference
2917          return value;
2918        case 1835190426: // eventHistory
2919          this.getEventHistory().add(castToReference(value)); // Reference
2920          return value;
2921        default: return super.setProperty(hash, name, value);
2922        }
2923
2924      }
2925
2926      @Override
2927      public Base setProperty(String name, Base value) throws FHIRException {
2928        if (name.equals("identifier")) {
2929          this.getIdentifier().add(castToIdentifier(value));
2930        } else if (name.equals("definition")) {
2931          this.getDefinition().add(castToReference(value));
2932        } else if (name.equals("basedOn")) {
2933          this.getBasedOn().add(castToReference(value));
2934        } else if (name.equals("groupIdentifier")) {
2935          this.groupIdentifier = castToIdentifier(value); // Identifier
2936        } else if (name.equals("status")) {
2937          value = new MedicationRequestStatusEnumFactory().fromType(castToCode(value));
2938          this.status = (Enumeration) value; // Enumeration<MedicationRequestStatus>
2939        } else if (name.equals("intent")) {
2940          value = new MedicationRequestIntentEnumFactory().fromType(castToCode(value));
2941          this.intent = (Enumeration) value; // Enumeration<MedicationRequestIntent>
2942        } else if (name.equals("category")) {
2943          this.category = castToCodeableConcept(value); // CodeableConcept
2944        } else if (name.equals("priority")) {
2945          value = new MedicationRequestPriorityEnumFactory().fromType(castToCode(value));
2946          this.priority = (Enumeration) value; // Enumeration<MedicationRequestPriority>
2947        } else if (name.equals("medication[x]")) {
2948          this.medication = castToType(value); // Type
2949        } else if (name.equals("subject")) {
2950          this.subject = castToReference(value); // Reference
2951        } else if (name.equals("context")) {
2952          this.context = castToReference(value); // Reference
2953        } else if (name.equals("supportingInformation")) {
2954          this.getSupportingInformation().add(castToReference(value));
2955        } else if (name.equals("authoredOn")) {
2956          this.authoredOn = castToDateTime(value); // DateTimeType
2957        } else if (name.equals("requester")) {
2958          this.requester = (MedicationRequestRequesterComponent) value; // MedicationRequestRequesterComponent
2959        } else if (name.equals("recorder")) {
2960          this.recorder = castToReference(value); // Reference
2961        } else if (name.equals("reasonCode")) {
2962          this.getReasonCode().add(castToCodeableConcept(value));
2963        } else if (name.equals("reasonReference")) {
2964          this.getReasonReference().add(castToReference(value));
2965        } else if (name.equals("note")) {
2966          this.getNote().add(castToAnnotation(value));
2967        } else if (name.equals("dosageInstruction")) {
2968          this.getDosageInstruction().add(castToDosage(value));
2969        } else if (name.equals("dispenseRequest")) {
2970          this.dispenseRequest = (MedicationRequestDispenseRequestComponent) value; // MedicationRequestDispenseRequestComponent
2971        } else if (name.equals("substitution")) {
2972          this.substitution = (MedicationRequestSubstitutionComponent) value; // MedicationRequestSubstitutionComponent
2973        } else if (name.equals("priorPrescription")) {
2974          this.priorPrescription = castToReference(value); // Reference
2975        } else if (name.equals("detectedIssue")) {
2976          this.getDetectedIssue().add(castToReference(value));
2977        } else if (name.equals("eventHistory")) {
2978          this.getEventHistory().add(castToReference(value));
2979        } else
2980          return super.setProperty(name, value);
2981        return value;
2982      }
2983
2984      @Override
2985      public Base makeProperty(int hash, String name) throws FHIRException {
2986        switch (hash) {
2987        case -1618432855:  return addIdentifier(); 
2988        case -1014418093:  return addDefinition(); 
2989        case -332612366:  return addBasedOn(); 
2990        case -445338488:  return getGroupIdentifier(); 
2991        case -892481550:  return getStatusElement();
2992        case -1183762788:  return getIntentElement();
2993        case 50511102:  return getCategory(); 
2994        case -1165461084:  return getPriorityElement();
2995        case 1458402129:  return getMedication(); 
2996        case 1998965455:  return getMedication(); 
2997        case -1867885268:  return getSubject(); 
2998        case 951530927:  return getContext(); 
2999        case -1248768647:  return addSupportingInformation(); 
3000        case -1500852503:  return getAuthoredOnElement();
3001        case 693933948:  return getRequester(); 
3002        case -799233858:  return getRecorder(); 
3003        case 722137681:  return addReasonCode(); 
3004        case -1146218137:  return addReasonReference(); 
3005        case 3387378:  return addNote(); 
3006        case -1201373865:  return addDosageInstruction(); 
3007        case 824620658:  return getDispenseRequest(); 
3008        case 826147581:  return getSubstitution(); 
3009        case -486355964:  return getPriorPrescription(); 
3010        case 51602295:  return addDetectedIssue(); 
3011        case 1835190426:  return addEventHistory(); 
3012        default: return super.makeProperty(hash, name);
3013        }
3014
3015      }
3016
3017      @Override
3018      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
3019        switch (hash) {
3020        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
3021        case -1014418093: /*definition*/ return new String[] {"Reference"};
3022        case -332612366: /*basedOn*/ return new String[] {"Reference"};
3023        case -445338488: /*groupIdentifier*/ return new String[] {"Identifier"};
3024        case -892481550: /*status*/ return new String[] {"code"};
3025        case -1183762788: /*intent*/ return new String[] {"code"};
3026        case 50511102: /*category*/ return new String[] {"CodeableConcept"};
3027        case -1165461084: /*priority*/ return new String[] {"code"};
3028        case 1998965455: /*medication*/ return new String[] {"CodeableConcept", "Reference"};
3029        case -1867885268: /*subject*/ return new String[] {"Reference"};
3030        case 951530927: /*context*/ return new String[] {"Reference"};
3031        case -1248768647: /*supportingInformation*/ return new String[] {"Reference"};
3032        case -1500852503: /*authoredOn*/ return new String[] {"dateTime"};
3033        case 693933948: /*requester*/ return new String[] {};
3034        case -799233858: /*recorder*/ return new String[] {"Reference"};
3035        case 722137681: /*reasonCode*/ return new String[] {"CodeableConcept"};
3036        case -1146218137: /*reasonReference*/ return new String[] {"Reference"};
3037        case 3387378: /*note*/ return new String[] {"Annotation"};
3038        case -1201373865: /*dosageInstruction*/ return new String[] {"Dosage"};
3039        case 824620658: /*dispenseRequest*/ return new String[] {};
3040        case 826147581: /*substitution*/ return new String[] {};
3041        case -486355964: /*priorPrescription*/ return new String[] {"Reference"};
3042        case 51602295: /*detectedIssue*/ return new String[] {"Reference"};
3043        case 1835190426: /*eventHistory*/ return new String[] {"Reference"};
3044        default: return super.getTypesForProperty(hash, name);
3045        }
3046
3047      }
3048
3049      @Override
3050      public Base addChild(String name) throws FHIRException {
3051        if (name.equals("identifier")) {
3052          return addIdentifier();
3053        }
3054        else if (name.equals("definition")) {
3055          return addDefinition();
3056        }
3057        else if (name.equals("basedOn")) {
3058          return addBasedOn();
3059        }
3060        else if (name.equals("groupIdentifier")) {
3061          this.groupIdentifier = new Identifier();
3062          return this.groupIdentifier;
3063        }
3064        else if (name.equals("status")) {
3065          throw new FHIRException("Cannot call addChild on a primitive type MedicationRequest.status");
3066        }
3067        else if (name.equals("intent")) {
3068          throw new FHIRException("Cannot call addChild on a primitive type MedicationRequest.intent");
3069        }
3070        else if (name.equals("category")) {
3071          this.category = new CodeableConcept();
3072          return this.category;
3073        }
3074        else if (name.equals("priority")) {
3075          throw new FHIRException("Cannot call addChild on a primitive type MedicationRequest.priority");
3076        }
3077        else if (name.equals("medicationCodeableConcept")) {
3078          this.medication = new CodeableConcept();
3079          return this.medication;
3080        }
3081        else if (name.equals("medicationReference")) {
3082          this.medication = new Reference();
3083          return this.medication;
3084        }
3085        else if (name.equals("subject")) {
3086          this.subject = new Reference();
3087          return this.subject;
3088        }
3089        else if (name.equals("context")) {
3090          this.context = new Reference();
3091          return this.context;
3092        }
3093        else if (name.equals("supportingInformation")) {
3094          return addSupportingInformation();
3095        }
3096        else if (name.equals("authoredOn")) {
3097          throw new FHIRException("Cannot call addChild on a primitive type MedicationRequest.authoredOn");
3098        }
3099        else if (name.equals("requester")) {
3100          this.requester = new MedicationRequestRequesterComponent();
3101          return this.requester;
3102        }
3103        else if (name.equals("recorder")) {
3104          this.recorder = new Reference();
3105          return this.recorder;
3106        }
3107        else if (name.equals("reasonCode")) {
3108          return addReasonCode();
3109        }
3110        else if (name.equals("reasonReference")) {
3111          return addReasonReference();
3112        }
3113        else if (name.equals("note")) {
3114          return addNote();
3115        }
3116        else if (name.equals("dosageInstruction")) {
3117          return addDosageInstruction();
3118        }
3119        else if (name.equals("dispenseRequest")) {
3120          this.dispenseRequest = new MedicationRequestDispenseRequestComponent();
3121          return this.dispenseRequest;
3122        }
3123        else if (name.equals("substitution")) {
3124          this.substitution = new MedicationRequestSubstitutionComponent();
3125          return this.substitution;
3126        }
3127        else if (name.equals("priorPrescription")) {
3128          this.priorPrescription = new Reference();
3129          return this.priorPrescription;
3130        }
3131        else if (name.equals("detectedIssue")) {
3132          return addDetectedIssue();
3133        }
3134        else if (name.equals("eventHistory")) {
3135          return addEventHistory();
3136        }
3137        else
3138          return super.addChild(name);
3139      }
3140
3141  public String fhirType() {
3142    return "MedicationRequest";
3143
3144  }
3145
3146      public MedicationRequest copy() {
3147        MedicationRequest dst = new MedicationRequest();
3148        copyValues(dst);
3149        if (identifier != null) {
3150          dst.identifier = new ArrayList<Identifier>();
3151          for (Identifier i : identifier)
3152            dst.identifier.add(i.copy());
3153        };
3154        if (definition != null) {
3155          dst.definition = new ArrayList<Reference>();
3156          for (Reference i : definition)
3157            dst.definition.add(i.copy());
3158        };
3159        if (basedOn != null) {
3160          dst.basedOn = new ArrayList<Reference>();
3161          for (Reference i : basedOn)
3162            dst.basedOn.add(i.copy());
3163        };
3164        dst.groupIdentifier = groupIdentifier == null ? null : groupIdentifier.copy();
3165        dst.status = status == null ? null : status.copy();
3166        dst.intent = intent == null ? null : intent.copy();
3167        dst.category = category == null ? null : category.copy();
3168        dst.priority = priority == null ? null : priority.copy();
3169        dst.medication = medication == null ? null : medication.copy();
3170        dst.subject = subject == null ? null : subject.copy();
3171        dst.context = context == null ? null : context.copy();
3172        if (supportingInformation != null) {
3173          dst.supportingInformation = new ArrayList<Reference>();
3174          for (Reference i : supportingInformation)
3175            dst.supportingInformation.add(i.copy());
3176        };
3177        dst.authoredOn = authoredOn == null ? null : authoredOn.copy();
3178        dst.requester = requester == null ? null : requester.copy();
3179        dst.recorder = recorder == null ? null : recorder.copy();
3180        if (reasonCode != null) {
3181          dst.reasonCode = new ArrayList<CodeableConcept>();
3182          for (CodeableConcept i : reasonCode)
3183            dst.reasonCode.add(i.copy());
3184        };
3185        if (reasonReference != null) {
3186          dst.reasonReference = new ArrayList<Reference>();
3187          for (Reference i : reasonReference)
3188            dst.reasonReference.add(i.copy());
3189        };
3190        if (note != null) {
3191          dst.note = new ArrayList<Annotation>();
3192          for (Annotation i : note)
3193            dst.note.add(i.copy());
3194        };
3195        if (dosageInstruction != null) {
3196          dst.dosageInstruction = new ArrayList<Dosage>();
3197          for (Dosage i : dosageInstruction)
3198            dst.dosageInstruction.add(i.copy());
3199        };
3200        dst.dispenseRequest = dispenseRequest == null ? null : dispenseRequest.copy();
3201        dst.substitution = substitution == null ? null : substitution.copy();
3202        dst.priorPrescription = priorPrescription == null ? null : priorPrescription.copy();
3203        if (detectedIssue != null) {
3204          dst.detectedIssue = new ArrayList<Reference>();
3205          for (Reference i : detectedIssue)
3206            dst.detectedIssue.add(i.copy());
3207        };
3208        if (eventHistory != null) {
3209          dst.eventHistory = new ArrayList<Reference>();
3210          for (Reference i : eventHistory)
3211            dst.eventHistory.add(i.copy());
3212        };
3213        return dst;
3214      }
3215
3216      protected MedicationRequest typedCopy() {
3217        return copy();
3218      }
3219
3220      @Override
3221      public boolean equalsDeep(Base other_) {
3222        if (!super.equalsDeep(other_))
3223          return false;
3224        if (!(other_ instanceof MedicationRequest))
3225          return false;
3226        MedicationRequest o = (MedicationRequest) other_;
3227        return compareDeep(identifier, o.identifier, true) && compareDeep(definition, o.definition, true)
3228           && compareDeep(basedOn, o.basedOn, true) && compareDeep(groupIdentifier, o.groupIdentifier, true)
3229           && compareDeep(status, o.status, true) && compareDeep(intent, o.intent, true) && compareDeep(category, o.category, true)
3230           && compareDeep(priority, o.priority, true) && compareDeep(medication, o.medication, true) && compareDeep(subject, o.subject, true)
3231           && compareDeep(context, o.context, true) && compareDeep(supportingInformation, o.supportingInformation, true)
3232           && compareDeep(authoredOn, o.authoredOn, true) && compareDeep(requester, o.requester, true) && compareDeep(recorder, o.recorder, true)
3233           && compareDeep(reasonCode, o.reasonCode, true) && compareDeep(reasonReference, o.reasonReference, true)
3234           && compareDeep(note, o.note, true) && compareDeep(dosageInstruction, o.dosageInstruction, true)
3235           && compareDeep(dispenseRequest, o.dispenseRequest, true) && compareDeep(substitution, o.substitution, true)
3236           && compareDeep(priorPrescription, o.priorPrescription, true) && compareDeep(detectedIssue, o.detectedIssue, true)
3237           && compareDeep(eventHistory, o.eventHistory, true);
3238      }
3239
3240      @Override
3241      public boolean equalsShallow(Base other_) {
3242        if (!super.equalsShallow(other_))
3243          return false;
3244        if (!(other_ instanceof MedicationRequest))
3245          return false;
3246        MedicationRequest o = (MedicationRequest) other_;
3247        return compareValues(status, o.status, true) && compareValues(intent, o.intent, true) && compareValues(priority, o.priority, true)
3248           && compareValues(authoredOn, o.authoredOn, true);
3249      }
3250
3251      public boolean isEmpty() {
3252        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, definition, basedOn
3253          , groupIdentifier, status, intent, category, priority, medication, subject, context
3254          , supportingInformation, authoredOn, requester, recorder, reasonCode, reasonReference
3255          , note, dosageInstruction, dispenseRequest, substitution, priorPrescription, detectedIssue
3256          , eventHistory);
3257      }
3258
3259  @Override
3260  public ResourceType getResourceType() {
3261    return ResourceType.MedicationRequest;
3262   }
3263
3264 /**
3265   * Search parameter: <b>requester</b>
3266   * <p>
3267   * Description: <b>Returns prescriptions prescribed by this prescriber</b><br>
3268   * Type: <b>reference</b><br>
3269   * Path: <b>MedicationRequest.requester.agent</b><br>
3270   * </p>
3271   */
3272  @SearchParamDefinition(name="requester", path="MedicationRequest.requester.agent", description="Returns prescriptions prescribed by this prescriber", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Practitioner") }, target={Device.class, Organization.class, Patient.class, Practitioner.class, RelatedPerson.class } )
3273  public static final String SP_REQUESTER = "requester";
3274 /**
3275   * <b>Fluent Client</b> search parameter constant for <b>requester</b>
3276   * <p>
3277   * Description: <b>Returns prescriptions prescribed by this prescriber</b><br>
3278   * Type: <b>reference</b><br>
3279   * Path: <b>MedicationRequest.requester.agent</b><br>
3280   * </p>
3281   */
3282  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam REQUESTER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_REQUESTER);
3283
3284/**
3285   * Constant for fluent queries to be used to add include statements. Specifies
3286   * the path value of "<b>MedicationRequest:requester</b>".
3287   */
3288  public static final ca.uhn.fhir.model.api.Include INCLUDE_REQUESTER = new ca.uhn.fhir.model.api.Include("MedicationRequest:requester").toLocked();
3289
3290 /**
3291   * Search parameter: <b>date</b>
3292   * <p>
3293   * Description: <b>Returns medication request to be administered on a specific date</b><br>
3294   * Type: <b>date</b><br>
3295   * Path: <b>MedicationRequest.dosageInstruction.timing.event</b><br>
3296   * </p>
3297   */
3298  @SearchParamDefinition(name="date", path="MedicationRequest.dosageInstruction.timing.event", description="Returns medication request to be administered on a specific date", type="date" )
3299  public static final String SP_DATE = "date";
3300 /**
3301   * <b>Fluent Client</b> search parameter constant for <b>date</b>
3302   * <p>
3303   * Description: <b>Returns medication request to be administered on a specific date</b><br>
3304   * Type: <b>date</b><br>
3305   * Path: <b>MedicationRequest.dosageInstruction.timing.event</b><br>
3306   * </p>
3307   */
3308  public static final ca.uhn.fhir.rest.gclient.DateClientParam DATE = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_DATE);
3309
3310 /**
3311   * Search parameter: <b>identifier</b>
3312   * <p>
3313   * Description: <b>Return prescriptions with this external identifier</b><br>
3314   * Type: <b>token</b><br>
3315   * Path: <b>MedicationRequest.identifier</b><br>
3316   * </p>
3317   */
3318  @SearchParamDefinition(name="identifier", path="MedicationRequest.identifier", description="Return prescriptions with this external identifier", type="token" )
3319  public static final String SP_IDENTIFIER = "identifier";
3320 /**
3321   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
3322   * <p>
3323   * Description: <b>Return prescriptions with this external identifier</b><br>
3324   * Type: <b>token</b><br>
3325   * Path: <b>MedicationRequest.identifier</b><br>
3326   * </p>
3327   */
3328  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
3329
3330 /**
3331   * Search parameter: <b>intended-dispenser</b>
3332   * <p>
3333   * Description: <b>Returns prescriptions intended to be dispensed by this Organization</b><br>
3334   * Type: <b>reference</b><br>
3335   * Path: <b>MedicationRequest.dispenseRequest.performer</b><br>
3336   * </p>
3337   */
3338  @SearchParamDefinition(name="intended-dispenser", path="MedicationRequest.dispenseRequest.performer", description="Returns prescriptions intended to be dispensed by this Organization", type="reference", target={Organization.class } )
3339  public static final String SP_INTENDED_DISPENSER = "intended-dispenser";
3340 /**
3341   * <b>Fluent Client</b> search parameter constant for <b>intended-dispenser</b>
3342   * <p>
3343   * Description: <b>Returns prescriptions intended to be dispensed by this Organization</b><br>
3344   * Type: <b>reference</b><br>
3345   * Path: <b>MedicationRequest.dispenseRequest.performer</b><br>
3346   * </p>
3347   */
3348  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam INTENDED_DISPENSER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_INTENDED_DISPENSER);
3349
3350/**
3351   * Constant for fluent queries to be used to add include statements. Specifies
3352   * the path value of "<b>MedicationRequest:intended-dispenser</b>".
3353   */
3354  public static final ca.uhn.fhir.model.api.Include INCLUDE_INTENDED_DISPENSER = new ca.uhn.fhir.model.api.Include("MedicationRequest:intended-dispenser").toLocked();
3355
3356 /**
3357   * Search parameter: <b>authoredon</b>
3358   * <p>
3359   * Description: <b>Return prescriptions written on this date</b><br>
3360   * Type: <b>date</b><br>
3361   * Path: <b>MedicationRequest.authoredOn</b><br>
3362   * </p>
3363   */
3364  @SearchParamDefinition(name="authoredon", path="MedicationRequest.authoredOn", description="Return prescriptions written on this date", type="date" )
3365  public static final String SP_AUTHOREDON = "authoredon";
3366 /**
3367   * <b>Fluent Client</b> search parameter constant for <b>authoredon</b>
3368   * <p>
3369   * Description: <b>Return prescriptions written on this date</b><br>
3370   * Type: <b>date</b><br>
3371   * Path: <b>MedicationRequest.authoredOn</b><br>
3372   * </p>
3373   */
3374  public static final ca.uhn.fhir.rest.gclient.DateClientParam AUTHOREDON = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_AUTHOREDON);
3375
3376 /**
3377   * Search parameter: <b>code</b>
3378   * <p>
3379   * Description: <b>Return prescriptions of this medication code</b><br>
3380   * Type: <b>token</b><br>
3381   * Path: <b>MedicationRequest.medicationCodeableConcept</b><br>
3382   * </p>
3383   */
3384  @SearchParamDefinition(name="code", path="MedicationRequest.medication.as(CodeableConcept)", description="Return prescriptions of this medication code", type="token" )
3385  public static final String SP_CODE = "code";
3386 /**
3387   * <b>Fluent Client</b> search parameter constant for <b>code</b>
3388   * <p>
3389   * Description: <b>Return prescriptions of this medication code</b><br>
3390   * Type: <b>token</b><br>
3391   * Path: <b>MedicationRequest.medicationCodeableConcept</b><br>
3392   * </p>
3393   */
3394  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CODE);
3395
3396 /**
3397   * Search parameter: <b>subject</b>
3398   * <p>
3399   * Description: <b>The identity of a patient to list orders  for</b><br>
3400   * Type: <b>reference</b><br>
3401   * Path: <b>MedicationRequest.subject</b><br>
3402   * </p>
3403   */
3404  @SearchParamDefinition(name="subject", path="MedicationRequest.subject", description="The identity of a patient to list orders  for", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Patient") }, target={Group.class, Patient.class } )
3405  public static final String SP_SUBJECT = "subject";
3406 /**
3407   * <b>Fluent Client</b> search parameter constant for <b>subject</b>
3408   * <p>
3409   * Description: <b>The identity of a patient to list orders  for</b><br>
3410   * Type: <b>reference</b><br>
3411   * Path: <b>MedicationRequest.subject</b><br>
3412   * </p>
3413   */
3414  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBJECT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SUBJECT);
3415
3416/**
3417   * Constant for fluent queries to be used to add include statements. Specifies
3418   * the path value of "<b>MedicationRequest:subject</b>".
3419   */
3420  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBJECT = new ca.uhn.fhir.model.api.Include("MedicationRequest:subject").toLocked();
3421
3422 /**
3423   * Search parameter: <b>medication</b>
3424   * <p>
3425   * Description: <b>Return prescriptions of this medication reference</b><br>
3426   * Type: <b>reference</b><br>
3427   * Path: <b>MedicationRequest.medicationReference</b><br>
3428   * </p>
3429   */
3430  @SearchParamDefinition(name="medication", path="MedicationRequest.medication.as(Reference)", description="Return prescriptions of this medication reference", type="reference", target={Medication.class } )
3431  public static final String SP_MEDICATION = "medication";
3432 /**
3433   * <b>Fluent Client</b> search parameter constant for <b>medication</b>
3434   * <p>
3435   * Description: <b>Return prescriptions of this medication reference</b><br>
3436   * Type: <b>reference</b><br>
3437   * Path: <b>MedicationRequest.medicationReference</b><br>
3438   * </p>
3439   */
3440  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam MEDICATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_MEDICATION);
3441
3442/**
3443   * Constant for fluent queries to be used to add include statements. Specifies
3444   * the path value of "<b>MedicationRequest:medication</b>".
3445   */
3446  public static final ca.uhn.fhir.model.api.Include INCLUDE_MEDICATION = new ca.uhn.fhir.model.api.Include("MedicationRequest:medication").toLocked();
3447
3448 /**
3449   * Search parameter: <b>priority</b>
3450   * <p>
3451   * Description: <b>Returns prescriptions with different priorities</b><br>
3452   * Type: <b>token</b><br>
3453   * Path: <b>MedicationRequest.priority</b><br>
3454   * </p>
3455   */
3456  @SearchParamDefinition(name="priority", path="MedicationRequest.priority", description="Returns prescriptions with different priorities", type="token" )
3457  public static final String SP_PRIORITY = "priority";
3458 /**
3459   * <b>Fluent Client</b> search parameter constant for <b>priority</b>
3460   * <p>
3461   * Description: <b>Returns prescriptions with different priorities</b><br>
3462   * Type: <b>token</b><br>
3463   * Path: <b>MedicationRequest.priority</b><br>
3464   * </p>
3465   */
3466  public static final ca.uhn.fhir.rest.gclient.TokenClientParam PRIORITY = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_PRIORITY);
3467
3468 /**
3469   * Search parameter: <b>intent</b>
3470   * <p>
3471   * Description: <b>Returns prescriptions with different intents</b><br>
3472   * Type: <b>token</b><br>
3473   * Path: <b>MedicationRequest.intent</b><br>
3474   * </p>
3475   */
3476  @SearchParamDefinition(name="intent", path="MedicationRequest.intent", description="Returns prescriptions with different intents", type="token" )
3477  public static final String SP_INTENT = "intent";
3478 /**
3479   * <b>Fluent Client</b> search parameter constant for <b>intent</b>
3480   * <p>
3481   * Description: <b>Returns prescriptions with different intents</b><br>
3482   * Type: <b>token</b><br>
3483   * Path: <b>MedicationRequest.intent</b><br>
3484   * </p>
3485   */
3486  public static final ca.uhn.fhir.rest.gclient.TokenClientParam INTENT = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_INTENT);
3487
3488 /**
3489   * Search parameter: <b>patient</b>
3490   * <p>
3491   * Description: <b>Returns prescriptions for a specific patient</b><br>
3492   * Type: <b>reference</b><br>
3493   * Path: <b>MedicationRequest.subject</b><br>
3494   * </p>
3495   */
3496  @SearchParamDefinition(name="patient", path="MedicationRequest.subject", description="Returns prescriptions for a specific patient", type="reference", target={Patient.class } )
3497  public static final String SP_PATIENT = "patient";
3498 /**
3499   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
3500   * <p>
3501   * Description: <b>Returns prescriptions for a specific patient</b><br>
3502   * Type: <b>reference</b><br>
3503   * Path: <b>MedicationRequest.subject</b><br>
3504   * </p>
3505   */
3506  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
3507
3508/**
3509   * Constant for fluent queries to be used to add include statements. Specifies
3510   * the path value of "<b>MedicationRequest:patient</b>".
3511   */
3512  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("MedicationRequest:patient").toLocked();
3513
3514 /**
3515   * Search parameter: <b>context</b>
3516   * <p>
3517   * Description: <b>Return prescriptions with this encounter or episode of care identifier</b><br>
3518   * Type: <b>reference</b><br>
3519   * Path: <b>MedicationRequest.context</b><br>
3520   * </p>
3521   */
3522  @SearchParamDefinition(name="context", path="MedicationRequest.context", description="Return prescriptions with this encounter or episode of care identifier", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Encounter") }, target={Encounter.class, EpisodeOfCare.class } )
3523  public static final String SP_CONTEXT = "context";
3524 /**
3525   * <b>Fluent Client</b> search parameter constant for <b>context</b>
3526   * <p>
3527   * Description: <b>Return prescriptions with this encounter or episode of care identifier</b><br>
3528   * Type: <b>reference</b><br>
3529   * Path: <b>MedicationRequest.context</b><br>
3530   * </p>
3531   */
3532  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CONTEXT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_CONTEXT);
3533
3534/**
3535   * Constant for fluent queries to be used to add include statements. Specifies
3536   * the path value of "<b>MedicationRequest:context</b>".
3537   */
3538  public static final ca.uhn.fhir.model.api.Include INCLUDE_CONTEXT = new ca.uhn.fhir.model.api.Include("MedicationRequest:context").toLocked();
3539
3540 /**
3541   * Search parameter: <b>category</b>
3542   * <p>
3543   * Description: <b>Returns prescriptions with different categories</b><br>
3544   * Type: <b>token</b><br>
3545   * Path: <b>MedicationRequest.category</b><br>
3546   * </p>
3547   */
3548  @SearchParamDefinition(name="category", path="MedicationRequest.category", description="Returns prescriptions with different categories", type="token" )
3549  public static final String SP_CATEGORY = "category";
3550 /**
3551   * <b>Fluent Client</b> search parameter constant for <b>category</b>
3552   * <p>
3553   * Description: <b>Returns prescriptions with different categories</b><br>
3554   * Type: <b>token</b><br>
3555   * Path: <b>MedicationRequest.category</b><br>
3556   * </p>
3557   */
3558  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CATEGORY = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CATEGORY);
3559
3560 /**
3561   * Search parameter: <b>status</b>
3562   * <p>
3563   * Description: <b>Status of the prescription</b><br>
3564   * Type: <b>token</b><br>
3565   * Path: <b>MedicationRequest.status</b><br>
3566   * </p>
3567   */
3568  @SearchParamDefinition(name="status", path="MedicationRequest.status", description="Status of the prescription", type="token" )
3569  public static final String SP_STATUS = "status";
3570 /**
3571   * <b>Fluent Client</b> search parameter constant for <b>status</b>
3572   * <p>
3573   * Description: <b>Status of the prescription</b><br>
3574   * Type: <b>token</b><br>
3575   * Path: <b>MedicationRequest.status</b><br>
3576   * </p>
3577   */
3578  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_STATUS);
3579
3580
3581}