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