001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.List;
038
039import ca.uhn.fhir.model.api.annotation.Block;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.Description;
042import ca.uhn.fhir.model.api.annotation.ResourceDef;
043import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
044import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
045import org.hl7.fhir.exceptions.FHIRException;
046import org.hl7.fhir.utilities.Utilities;
047/**
048 * Describes the event of a patient consuming or otherwise being administered a medication.  This may be as simple as swallowing a tablet or it may be a long running infusion.  Related resources tie this event to the authorizing prescription, and the specific encounter between patient and health care practitioner.
049 */
050@ResourceDef(name="MedicationAdministration", profile="http://hl7.org/fhir/Profile/MedicationAdministration")
051public class MedicationAdministration extends DomainResource {
052
053    public enum MedicationAdministrationStatus {
054        /**
055         * The administration has started but has not yet completed.
056         */
057        INPROGRESS, 
058        /**
059         * Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called "suspended".
060         */
061        ONHOLD, 
062        /**
063         * All actions that are implied by the administration have occurred.
064         */
065        COMPLETED, 
066        /**
067         * The administration was entered in error and therefore nullified.
068         */
069        ENTEREDINERROR, 
070        /**
071         * Actions implied by the administration have been permanently halted, before all of them occurred.
072         */
073        STOPPED, 
074        /**
075         * added to help the parsers
076         */
077        NULL;
078        public static MedicationAdministrationStatus fromCode(String codeString) throws FHIRException {
079            if (codeString == null || "".equals(codeString))
080                return null;
081        if ("in-progress".equals(codeString))
082          return INPROGRESS;
083        if ("on-hold".equals(codeString))
084          return ONHOLD;
085        if ("completed".equals(codeString))
086          return COMPLETED;
087        if ("entered-in-error".equals(codeString))
088          return ENTEREDINERROR;
089        if ("stopped".equals(codeString))
090          return STOPPED;
091        throw new FHIRException("Unknown MedicationAdministrationStatus code '"+codeString+"'");
092        }
093        public String toCode() {
094          switch (this) {
095            case INPROGRESS: return "in-progress";
096            case ONHOLD: return "on-hold";
097            case COMPLETED: return "completed";
098            case ENTEREDINERROR: return "entered-in-error";
099            case STOPPED: return "stopped";
100            case NULL: return null;
101            default: return "?";
102          }
103        }
104        public String getSystem() {
105          switch (this) {
106            case INPROGRESS: return "http://hl7.org/fhir/medication-admin-status";
107            case ONHOLD: return "http://hl7.org/fhir/medication-admin-status";
108            case COMPLETED: return "http://hl7.org/fhir/medication-admin-status";
109            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-admin-status";
110            case STOPPED: return "http://hl7.org/fhir/medication-admin-status";
111            case NULL: return null;
112            default: return "?";
113          }
114        }
115        public String getDefinition() {
116          switch (this) {
117            case INPROGRESS: return "The administration has started but has not yet completed.";
118            case ONHOLD: return "Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called \"suspended\".";
119            case COMPLETED: return "All actions that are implied by the administration have occurred.";
120            case ENTEREDINERROR: return "The administration was entered in error and therefore nullified.";
121            case STOPPED: return "Actions implied by the administration have been permanently halted, before all of them occurred.";
122            case NULL: return null;
123            default: return "?";
124          }
125        }
126        public String getDisplay() {
127          switch (this) {
128            case INPROGRESS: return "In Progress";
129            case ONHOLD: return "On Hold";
130            case COMPLETED: return "Completed";
131            case ENTEREDINERROR: return "Entered in Error";
132            case STOPPED: return "Stopped";
133            case NULL: return null;
134            default: return "?";
135          }
136        }
137    }
138
139  public static class MedicationAdministrationStatusEnumFactory implements EnumFactory<MedicationAdministrationStatus> {
140    public MedicationAdministrationStatus fromCode(String codeString) throws IllegalArgumentException {
141      if (codeString == null || "".equals(codeString))
142            if (codeString == null || "".equals(codeString))
143                return null;
144        if ("in-progress".equals(codeString))
145          return MedicationAdministrationStatus.INPROGRESS;
146        if ("on-hold".equals(codeString))
147          return MedicationAdministrationStatus.ONHOLD;
148        if ("completed".equals(codeString))
149          return MedicationAdministrationStatus.COMPLETED;
150        if ("entered-in-error".equals(codeString))
151          return MedicationAdministrationStatus.ENTEREDINERROR;
152        if ("stopped".equals(codeString))
153          return MedicationAdministrationStatus.STOPPED;
154        throw new IllegalArgumentException("Unknown MedicationAdministrationStatus code '"+codeString+"'");
155        }
156        public Enumeration<MedicationAdministrationStatus> fromType(Base code) throws FHIRException {
157          if (code == null || code.isEmpty())
158            return null;
159          String codeString = ((PrimitiveType) code).asStringValue();
160          if (codeString == null || "".equals(codeString))
161            return null;
162        if ("in-progress".equals(codeString))
163          return new Enumeration<MedicationAdministrationStatus>(this, MedicationAdministrationStatus.INPROGRESS);
164        if ("on-hold".equals(codeString))
165          return new Enumeration<MedicationAdministrationStatus>(this, MedicationAdministrationStatus.ONHOLD);
166        if ("completed".equals(codeString))
167          return new Enumeration<MedicationAdministrationStatus>(this, MedicationAdministrationStatus.COMPLETED);
168        if ("entered-in-error".equals(codeString))
169          return new Enumeration<MedicationAdministrationStatus>(this, MedicationAdministrationStatus.ENTEREDINERROR);
170        if ("stopped".equals(codeString))
171          return new Enumeration<MedicationAdministrationStatus>(this, MedicationAdministrationStatus.STOPPED);
172        throw new FHIRException("Unknown MedicationAdministrationStatus code '"+codeString+"'");
173        }
174    public String toCode(MedicationAdministrationStatus code) {
175      if (code == MedicationAdministrationStatus.INPROGRESS)
176        return "in-progress";
177      if (code == MedicationAdministrationStatus.ONHOLD)
178        return "on-hold";
179      if (code == MedicationAdministrationStatus.COMPLETED)
180        return "completed";
181      if (code == MedicationAdministrationStatus.ENTEREDINERROR)
182        return "entered-in-error";
183      if (code == MedicationAdministrationStatus.STOPPED)
184        return "stopped";
185      return "?";
186      }
187    }
188
189    @Block()
190    public static class MedicationAdministrationDosageComponent extends BackboneElement implements IBaseBackboneElement {
191        /**
192         * Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.
193         */
194        @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
195        @Description(shortDefinition="Dosage Instructions", formalDefinition="Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication." )
196        protected StringType text;
197
198        /**
199         * A coded specification of the anatomic site where the medication first entered the body.  For example, "left arm".
200         */
201        @Child(name = "site", type = {CodeableConcept.class, BodySite.class}, order=2, min=0, max=1, modifier=false, summary=true)
202        @Description(shortDefinition="Body site administered to", formalDefinition="A coded specification of the anatomic site where the medication first entered the body.  For example, \"left arm\"." )
203        protected Type site;
204
205        /**
206         * A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.
207         */
208        @Child(name = "route", type = {CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=true)
209        @Description(shortDefinition="Path of substance into body", formalDefinition="A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc." )
210        protected CodeableConcept route;
211
212        /**
213         * A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.
214         */
215        @Child(name = "method", type = {CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
216        @Description(shortDefinition="How drug was administered", formalDefinition="A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV." )
217        protected CodeableConcept method;
218
219        /**
220         * The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.
221         */
222        @Child(name = "quantity", type = {SimpleQuantity.class}, order=5, min=0, max=1, modifier=false, summary=true)
223        @Description(shortDefinition="Amount administered in one dose", formalDefinition="The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection." )
224        protected SimpleQuantity quantity;
225
226        /**
227         * Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.
228         */
229        @Child(name = "rate", type = {Ratio.class, Range.class}, order=6, min=0, max=1, modifier=false, summary=true)
230        @Description(shortDefinition="Dose quantity per unit of time", formalDefinition="Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours." )
231        protected Type rate;
232
233        private static final long serialVersionUID = -1772198879L;
234
235    /*
236     * Constructor
237     */
238      public MedicationAdministrationDosageComponent() {
239        super();
240      }
241
242        /**
243         * @return {@link #text} (Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
244         */
245        public StringType getTextElement() { 
246          if (this.text == null)
247            if (Configuration.errorOnAutoCreate())
248              throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.text");
249            else if (Configuration.doAutoCreate())
250              this.text = new StringType(); // bb
251          return this.text;
252        }
253
254        public boolean hasTextElement() { 
255          return this.text != null && !this.text.isEmpty();
256        }
257
258        public boolean hasText() { 
259          return this.text != null && !this.text.isEmpty();
260        }
261
262        /**
263         * @param value {@link #text} (Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
264         */
265        public MedicationAdministrationDosageComponent setTextElement(StringType value) { 
266          this.text = value;
267          return this;
268        }
269
270        /**
271         * @return Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.
272         */
273        public String getText() { 
274          return this.text == null ? null : this.text.getValue();
275        }
276
277        /**
278         * @param value Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.
279         */
280        public MedicationAdministrationDosageComponent setText(String value) { 
281          if (Utilities.noString(value))
282            this.text = null;
283          else {
284            if (this.text == null)
285              this.text = new StringType();
286            this.text.setValue(value);
287          }
288          return this;
289        }
290
291        /**
292         * @return {@link #site} (A coded specification of the anatomic site where the medication first entered the body.  For example, "left arm".)
293         */
294        public Type getSite() { 
295          return this.site;
296        }
297
298        /**
299         * @return {@link #site} (A coded specification of the anatomic site where the medication first entered the body.  For example, "left arm".)
300         */
301        public CodeableConcept getSiteCodeableConcept() throws FHIRException { 
302          if (!(this.site instanceof CodeableConcept))
303            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.site.getClass().getName()+" was encountered");
304          return (CodeableConcept) this.site;
305        }
306
307        public boolean hasSiteCodeableConcept() { 
308          return this.site instanceof CodeableConcept;
309        }
310
311        /**
312         * @return {@link #site} (A coded specification of the anatomic site where the medication first entered the body.  For example, "left arm".)
313         */
314        public Reference getSiteReference() throws FHIRException { 
315          if (!(this.site instanceof Reference))
316            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.site.getClass().getName()+" was encountered");
317          return (Reference) this.site;
318        }
319
320        public boolean hasSiteReference() { 
321          return this.site instanceof Reference;
322        }
323
324        public boolean hasSite() { 
325          return this.site != null && !this.site.isEmpty();
326        }
327
328        /**
329         * @param value {@link #site} (A coded specification of the anatomic site where the medication first entered the body.  For example, "left arm".)
330         */
331        public MedicationAdministrationDosageComponent setSite(Type value) { 
332          this.site = value;
333          return this;
334        }
335
336        /**
337         * @return {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.)
338         */
339        public CodeableConcept getRoute() { 
340          if (this.route == null)
341            if (Configuration.errorOnAutoCreate())
342              throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.route");
343            else if (Configuration.doAutoCreate())
344              this.route = new CodeableConcept(); // cc
345          return this.route;
346        }
347
348        public boolean hasRoute() { 
349          return this.route != null && !this.route.isEmpty();
350        }
351
352        /**
353         * @param value {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.)
354         */
355        public MedicationAdministrationDosageComponent setRoute(CodeableConcept value) { 
356          this.route = value;
357          return this;
358        }
359
360        /**
361         * @return {@link #method} (A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.)
362         */
363        public CodeableConcept getMethod() { 
364          if (this.method == null)
365            if (Configuration.errorOnAutoCreate())
366              throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.method");
367            else if (Configuration.doAutoCreate())
368              this.method = new CodeableConcept(); // cc
369          return this.method;
370        }
371
372        public boolean hasMethod() { 
373          return this.method != null && !this.method.isEmpty();
374        }
375
376        /**
377         * @param value {@link #method} (A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.)
378         */
379        public MedicationAdministrationDosageComponent setMethod(CodeableConcept value) { 
380          this.method = value;
381          return this;
382        }
383
384        /**
385         * @return {@link #quantity} (The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.)
386         */
387        public SimpleQuantity getQuantity() { 
388          if (this.quantity == null)
389            if (Configuration.errorOnAutoCreate())
390              throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.quantity");
391            else if (Configuration.doAutoCreate())
392              this.quantity = new SimpleQuantity(); // cc
393          return this.quantity;
394        }
395
396        public boolean hasQuantity() { 
397          return this.quantity != null && !this.quantity.isEmpty();
398        }
399
400        /**
401         * @param value {@link #quantity} (The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.)
402         */
403        public MedicationAdministrationDosageComponent setQuantity(SimpleQuantity value) { 
404          this.quantity = value;
405          return this;
406        }
407
408        /**
409         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
410         */
411        public Type getRate() { 
412          return this.rate;
413        }
414
415        /**
416         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
417         */
418        public Ratio getRateRatio() throws FHIRException { 
419          if (!(this.rate instanceof Ratio))
420            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
421          return (Ratio) this.rate;
422        }
423
424        public boolean hasRateRatio() { 
425          return this.rate instanceof Ratio;
426        }
427
428        /**
429         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
430         */
431        public Range getRateRange() throws FHIRException { 
432          if (!(this.rate instanceof Range))
433            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
434          return (Range) this.rate;
435        }
436
437        public boolean hasRateRange() { 
438          return this.rate instanceof Range;
439        }
440
441        public boolean hasRate() { 
442          return this.rate != null && !this.rate.isEmpty();
443        }
444
445        /**
446         * @param value {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
447         */
448        public MedicationAdministrationDosageComponent setRate(Type value) { 
449          this.rate = value;
450          return this;
451        }
452
453        protected void listChildren(List<Property> childrenList) {
454          super.listChildren(childrenList);
455          childrenList.add(new Property("text", "string", "Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.", 0, java.lang.Integer.MAX_VALUE, text));
456          childrenList.add(new Property("site[x]", "CodeableConcept|Reference(BodySite)", "A coded specification of the anatomic site where the medication first entered the body.  For example, \"left arm\".", 0, java.lang.Integer.MAX_VALUE, site));
457          childrenList.add(new Property("route", "CodeableConcept", "A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.", 0, java.lang.Integer.MAX_VALUE, route));
458          childrenList.add(new Property("method", "CodeableConcept", "A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.", 0, java.lang.Integer.MAX_VALUE, method));
459          childrenList.add(new Property("quantity", "SimpleQuantity", "The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.", 0, java.lang.Integer.MAX_VALUE, quantity));
460          childrenList.add(new Property("rate[x]", "Ratio|Range", "Identifies the speed with which the medication was or will be introduced into the patient.  Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.  Currently we do not specify a default of '1' in the denominator, but this is being discussed.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.", 0, java.lang.Integer.MAX_VALUE, rate));
461        }
462
463      @Override
464      public void setProperty(String name, Base value) throws FHIRException {
465        if (name.equals("text"))
466          this.text = castToString(value); // StringType
467        else if (name.equals("site[x]"))
468          this.site = (Type) value; // Type
469        else if (name.equals("route"))
470          this.route = castToCodeableConcept(value); // CodeableConcept
471        else if (name.equals("method"))
472          this.method = castToCodeableConcept(value); // CodeableConcept
473        else if (name.equals("quantity"))
474          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
475        else if (name.equals("rate[x]"))
476          this.rate = (Type) value; // Type
477        else
478          super.setProperty(name, value);
479      }
480
481      @Override
482      public Base addChild(String name) throws FHIRException {
483        if (name.equals("text")) {
484          throw new FHIRException("Cannot call addChild on a primitive type MedicationAdministration.text");
485        }
486        else if (name.equals("siteCodeableConcept")) {
487          this.site = new CodeableConcept();
488          return this.site;
489        }
490        else if (name.equals("siteReference")) {
491          this.site = new Reference();
492          return this.site;
493        }
494        else if (name.equals("route")) {
495          this.route = new CodeableConcept();
496          return this.route;
497        }
498        else if (name.equals("method")) {
499          this.method = new CodeableConcept();
500          return this.method;
501        }
502        else if (name.equals("quantity")) {
503          this.quantity = new SimpleQuantity();
504          return this.quantity;
505        }
506        else if (name.equals("rateRatio")) {
507          this.rate = new Ratio();
508          return this.rate;
509        }
510        else if (name.equals("rateRange")) {
511          this.rate = new Range();
512          return this.rate;
513        }
514        else
515          return super.addChild(name);
516      }
517
518      public MedicationAdministrationDosageComponent copy() {
519        MedicationAdministrationDosageComponent dst = new MedicationAdministrationDosageComponent();
520        copyValues(dst);
521        dst.text = text == null ? null : text.copy();
522        dst.site = site == null ? null : site.copy();
523        dst.route = route == null ? null : route.copy();
524        dst.method = method == null ? null : method.copy();
525        dst.quantity = quantity == null ? null : quantity.copy();
526        dst.rate = rate == null ? null : rate.copy();
527        return dst;
528      }
529
530      @Override
531      public boolean equalsDeep(Base other) {
532        if (!super.equalsDeep(other))
533          return false;
534        if (!(other instanceof MedicationAdministrationDosageComponent))
535          return false;
536        MedicationAdministrationDosageComponent o = (MedicationAdministrationDosageComponent) other;
537        return compareDeep(text, o.text, true) && compareDeep(site, o.site, true) && compareDeep(route, o.route, true)
538           && compareDeep(method, o.method, true) && compareDeep(quantity, o.quantity, true) && compareDeep(rate, o.rate, true)
539          ;
540      }
541
542      @Override
543      public boolean equalsShallow(Base other) {
544        if (!super.equalsShallow(other))
545          return false;
546        if (!(other instanceof MedicationAdministrationDosageComponent))
547          return false;
548        MedicationAdministrationDosageComponent o = (MedicationAdministrationDosageComponent) other;
549        return compareValues(text, o.text, true);
550      }
551
552      public boolean isEmpty() {
553        return super.isEmpty() && (text == null || text.isEmpty()) && (site == null || site.isEmpty())
554           && (route == null || route.isEmpty()) && (method == null || method.isEmpty()) && (quantity == null || quantity.isEmpty())
555           && (rate == null || rate.isEmpty());
556      }
557
558  public String fhirType() {
559    return "MedicationAdministration.dosage";
560
561  }
562
563  }
564
565    /**
566     * External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.
567     */
568    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
569    @Description(shortDefinition="External identifier", formalDefinition="External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated." )
570    protected List<Identifier> identifier;
571
572    /**
573     * Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way.
574     */
575    @Child(name = "status", type = {CodeType.class}, order=1, min=1, max=1, modifier=true, summary=true)
576    @Description(shortDefinition="in-progress | on-hold | completed | entered-in-error | stopped", formalDefinition="Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way." )
577    protected Enumeration<MedicationAdministrationStatus> status;
578
579    /**
580     * The person or animal receiving the medication.
581     */
582    @Child(name = "patient", type = {Patient.class}, order=2, min=1, max=1, modifier=false, summary=true)
583    @Description(shortDefinition="Who received medication", formalDefinition="The person or animal receiving the medication." )
584    protected Reference patient;
585
586    /**
587     * The actual object that is the target of the reference (The person or animal receiving the medication.)
588     */
589    protected Patient patientTarget;
590
591    /**
592     * The individual who was responsible for giving the medication to the patient.
593     */
594    @Child(name = "practitioner", type = {Practitioner.class, Patient.class, RelatedPerson.class}, order=3, min=0, max=1, modifier=false, summary=true)
595    @Description(shortDefinition="Who administered substance", formalDefinition="The individual who was responsible for giving the medication to the patient." )
596    protected Reference practitioner;
597
598    /**
599     * The actual object that is the target of the reference (The individual who was responsible for giving the medication to the patient.)
600     */
601    protected Resource practitionerTarget;
602
603    /**
604     * The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.
605     */
606    @Child(name = "encounter", type = {Encounter.class}, order=4, min=0, max=1, modifier=false, summary=true)
607    @Description(shortDefinition="Encounter administered as part of", formalDefinition="The visit, admission or other contact between patient and health care provider the medication administration was performed as part of." )
608    protected Reference encounter;
609
610    /**
611     * The actual object that is the target of the reference (The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.)
612     */
613    protected Encounter encounterTarget;
614
615    /**
616     * The original request, instruction or authority to perform the administration.
617     */
618    @Child(name = "prescription", type = {MedicationOrder.class}, order=5, min=0, max=1, modifier=false, summary=true)
619    @Description(shortDefinition="Order administration performed against", formalDefinition="The original request, instruction or authority to perform the administration." )
620    protected Reference prescription;
621
622    /**
623     * The actual object that is the target of the reference (The original request, instruction or authority to perform the administration.)
624     */
625    protected MedicationOrder prescriptionTarget;
626
627    /**
628     * Set this to true if the record is saying that the medication was NOT administered.
629     */
630    @Child(name = "wasNotGiven", type = {BooleanType.class}, order=6, min=0, max=1, modifier=true, summary=true)
631    @Description(shortDefinition="True if medication not administered", formalDefinition="Set this to true if the record is saying that the medication was NOT administered." )
632    protected BooleanType wasNotGiven;
633
634    /**
635     * A code indicating why the administration was not performed.
636     */
637    @Child(name = "reasonNotGiven", type = {CodeableConcept.class}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
638    @Description(shortDefinition="Reason administration not performed", formalDefinition="A code indicating why the administration was not performed." )
639    protected List<CodeableConcept> reasonNotGiven;
640
641    /**
642     * A code indicating why the medication was given.
643     */
644    @Child(name = "reasonGiven", type = {CodeableConcept.class}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
645    @Description(shortDefinition="Reason administration performed", formalDefinition="A code indicating why the medication was given." )
646    protected List<CodeableConcept> reasonGiven;
647
648    /**
649     * A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.
650     */
651    @Child(name = "effectiveTime", type = {DateTimeType.class, Period.class}, order=9, min=1, max=1, modifier=false, summary=true)
652    @Description(shortDefinition="Start and end time of administration", formalDefinition="A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate." )
653    protected Type effectiveTime;
654
655    /**
656     * Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.
657     */
658    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=10, min=1, max=1, modifier=false, summary=true)
659    @Description(shortDefinition="What was administered", formalDefinition="Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications." )
660    protected Type medication;
661
662    /**
663     * The device used in administering the medication to the patient.  For example, a particular infusion pump.
664     */
665    @Child(name = "device", type = {Device.class}, order=11, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
666    @Description(shortDefinition="Device used to administer", formalDefinition="The device used in administering the medication to the patient.  For example, a particular infusion pump." )
667    protected List<Reference> device;
668    /**
669     * The actual objects that are the target of the reference (The device used in administering the medication to the patient.  For example, a particular infusion pump.)
670     */
671    protected List<Device> deviceTarget;
672
673
674    /**
675     * Extra information about the medication administration that is not conveyed by the other attributes.
676     */
677    @Child(name = "note", type = {StringType.class}, order=12, min=0, max=1, modifier=false, summary=true)
678    @Description(shortDefinition="Information about the administration", formalDefinition="Extra information about the medication administration that is not conveyed by the other attributes." )
679    protected StringType note;
680
681    /**
682     * Describes the medication dosage information details e.g. dose, rate, site, route, etc.
683     */
684    @Child(name = "dosage", type = {}, order=13, min=0, max=1, modifier=false, summary=true)
685    @Description(shortDefinition="Details of how medication was taken", formalDefinition="Describes the medication dosage information details e.g. dose, rate, site, route, etc." )
686    protected MedicationAdministrationDosageComponent dosage;
687
688    private static final long serialVersionUID = -669616345L;
689
690  /*
691   * Constructor
692   */
693    public MedicationAdministration() {
694      super();
695    }
696
697  /*
698   * Constructor
699   */
700    public MedicationAdministration(Enumeration<MedicationAdministrationStatus> status, Reference patient, Type effectiveTime, Type medication) {
701      super();
702      this.status = status;
703      this.patient = patient;
704      this.effectiveTime = effectiveTime;
705      this.medication = medication;
706    }
707
708    /**
709     * @return {@link #identifier} (External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.)
710     */
711    public List<Identifier> getIdentifier() { 
712      if (this.identifier == null)
713        this.identifier = new ArrayList<Identifier>();
714      return this.identifier;
715    }
716
717    public boolean hasIdentifier() { 
718      if (this.identifier == null)
719        return false;
720      for (Identifier item : this.identifier)
721        if (!item.isEmpty())
722          return true;
723      return false;
724    }
725
726    /**
727     * @return {@link #identifier} (External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.)
728     */
729    // syntactic sugar
730    public Identifier addIdentifier() { //3
731      Identifier t = new Identifier();
732      if (this.identifier == null)
733        this.identifier = new ArrayList<Identifier>();
734      this.identifier.add(t);
735      return t;
736    }
737
738    // syntactic sugar
739    public MedicationAdministration addIdentifier(Identifier t) { //3
740      if (t == null)
741        return this;
742      if (this.identifier == null)
743        this.identifier = new ArrayList<Identifier>();
744      this.identifier.add(t);
745      return this;
746    }
747
748    /**
749     * @return {@link #status} (Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
750     */
751    public Enumeration<MedicationAdministrationStatus> getStatusElement() { 
752      if (this.status == null)
753        if (Configuration.errorOnAutoCreate())
754          throw new Error("Attempt to auto-create MedicationAdministration.status");
755        else if (Configuration.doAutoCreate())
756          this.status = new Enumeration<MedicationAdministrationStatus>(new MedicationAdministrationStatusEnumFactory()); // bb
757      return this.status;
758    }
759
760    public boolean hasStatusElement() { 
761      return this.status != null && !this.status.isEmpty();
762    }
763
764    public boolean hasStatus() { 
765      return this.status != null && !this.status.isEmpty();
766    }
767
768    /**
769     * @param value {@link #status} (Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
770     */
771    public MedicationAdministration setStatusElement(Enumeration<MedicationAdministrationStatus> value) { 
772      this.status = value;
773      return this;
774    }
775
776    /**
777     * @return Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way.
778     */
779    public MedicationAdministrationStatus getStatus() { 
780      return this.status == null ? null : this.status.getValue();
781    }
782
783    /**
784     * @param value Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way.
785     */
786    public MedicationAdministration setStatus(MedicationAdministrationStatus value) { 
787        if (this.status == null)
788          this.status = new Enumeration<MedicationAdministrationStatus>(new MedicationAdministrationStatusEnumFactory());
789        this.status.setValue(value);
790      return this;
791    }
792
793    /**
794     * @return {@link #patient} (The person or animal receiving the medication.)
795     */
796    public Reference getPatient() { 
797      if (this.patient == null)
798        if (Configuration.errorOnAutoCreate())
799          throw new Error("Attempt to auto-create MedicationAdministration.patient");
800        else if (Configuration.doAutoCreate())
801          this.patient = new Reference(); // cc
802      return this.patient;
803    }
804
805    public boolean hasPatient() { 
806      return this.patient != null && !this.patient.isEmpty();
807    }
808
809    /**
810     * @param value {@link #patient} (The person or animal receiving the medication.)
811     */
812    public MedicationAdministration setPatient(Reference value) { 
813      this.patient = value;
814      return this;
815    }
816
817    /**
818     * @return {@link #patient} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The person or animal receiving the medication.)
819     */
820    public Patient getPatientTarget() { 
821      if (this.patientTarget == null)
822        if (Configuration.errorOnAutoCreate())
823          throw new Error("Attempt to auto-create MedicationAdministration.patient");
824        else if (Configuration.doAutoCreate())
825          this.patientTarget = new Patient(); // aa
826      return this.patientTarget;
827    }
828
829    /**
830     * @param value {@link #patient} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The person or animal receiving the medication.)
831     */
832    public MedicationAdministration setPatientTarget(Patient value) { 
833      this.patientTarget = value;
834      return this;
835    }
836
837    /**
838     * @return {@link #practitioner} (The individual who was responsible for giving the medication to the patient.)
839     */
840    public Reference getPractitioner() { 
841      if (this.practitioner == null)
842        if (Configuration.errorOnAutoCreate())
843          throw new Error("Attempt to auto-create MedicationAdministration.practitioner");
844        else if (Configuration.doAutoCreate())
845          this.practitioner = new Reference(); // cc
846      return this.practitioner;
847    }
848
849    public boolean hasPractitioner() { 
850      return this.practitioner != null && !this.practitioner.isEmpty();
851    }
852
853    /**
854     * @param value {@link #practitioner} (The individual who was responsible for giving the medication to the patient.)
855     */
856    public MedicationAdministration setPractitioner(Reference value) { 
857      this.practitioner = value;
858      return this;
859    }
860
861    /**
862     * @return {@link #practitioner} 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 individual who was responsible for giving the medication to the patient.)
863     */
864    public Resource getPractitionerTarget() { 
865      return this.practitionerTarget;
866    }
867
868    /**
869     * @param value {@link #practitioner} 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 individual who was responsible for giving the medication to the patient.)
870     */
871    public MedicationAdministration setPractitionerTarget(Resource value) { 
872      this.practitionerTarget = value;
873      return this;
874    }
875
876    /**
877     * @return {@link #encounter} (The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.)
878     */
879    public Reference getEncounter() { 
880      if (this.encounter == null)
881        if (Configuration.errorOnAutoCreate())
882          throw new Error("Attempt to auto-create MedicationAdministration.encounter");
883        else if (Configuration.doAutoCreate())
884          this.encounter = new Reference(); // cc
885      return this.encounter;
886    }
887
888    public boolean hasEncounter() { 
889      return this.encounter != null && !this.encounter.isEmpty();
890    }
891
892    /**
893     * @param value {@link #encounter} (The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.)
894     */
895    public MedicationAdministration setEncounter(Reference value) { 
896      this.encounter = value;
897      return this;
898    }
899
900    /**
901     * @return {@link #encounter} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.)
902     */
903    public Encounter getEncounterTarget() { 
904      if (this.encounterTarget == null)
905        if (Configuration.errorOnAutoCreate())
906          throw new Error("Attempt to auto-create MedicationAdministration.encounter");
907        else if (Configuration.doAutoCreate())
908          this.encounterTarget = new Encounter(); // aa
909      return this.encounterTarget;
910    }
911
912    /**
913     * @param value {@link #encounter} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.)
914     */
915    public MedicationAdministration setEncounterTarget(Encounter value) { 
916      this.encounterTarget = value;
917      return this;
918    }
919
920    /**
921     * @return {@link #prescription} (The original request, instruction or authority to perform the administration.)
922     */
923    public Reference getPrescription() { 
924      if (this.prescription == null)
925        if (Configuration.errorOnAutoCreate())
926          throw new Error("Attempt to auto-create MedicationAdministration.prescription");
927        else if (Configuration.doAutoCreate())
928          this.prescription = new Reference(); // cc
929      return this.prescription;
930    }
931
932    public boolean hasPrescription() { 
933      return this.prescription != null && !this.prescription.isEmpty();
934    }
935
936    /**
937     * @param value {@link #prescription} (The original request, instruction or authority to perform the administration.)
938     */
939    public MedicationAdministration setPrescription(Reference value) { 
940      this.prescription = value;
941      return this;
942    }
943
944    /**
945     * @return {@link #prescription} 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 original request, instruction or authority to perform the administration.)
946     */
947    public MedicationOrder getPrescriptionTarget() { 
948      if (this.prescriptionTarget == null)
949        if (Configuration.errorOnAutoCreate())
950          throw new Error("Attempt to auto-create MedicationAdministration.prescription");
951        else if (Configuration.doAutoCreate())
952          this.prescriptionTarget = new MedicationOrder(); // aa
953      return this.prescriptionTarget;
954    }
955
956    /**
957     * @param value {@link #prescription} 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 original request, instruction or authority to perform the administration.)
958     */
959    public MedicationAdministration setPrescriptionTarget(MedicationOrder value) { 
960      this.prescriptionTarget = value;
961      return this;
962    }
963
964    /**
965     * @return {@link #wasNotGiven} (Set this to true if the record is saying that the medication was NOT administered.). This is the underlying object with id, value and extensions. The accessor "getWasNotGiven" gives direct access to the value
966     */
967    public BooleanType getWasNotGivenElement() { 
968      if (this.wasNotGiven == null)
969        if (Configuration.errorOnAutoCreate())
970          throw new Error("Attempt to auto-create MedicationAdministration.wasNotGiven");
971        else if (Configuration.doAutoCreate())
972          this.wasNotGiven = new BooleanType(); // bb
973      return this.wasNotGiven;
974    }
975
976    public boolean hasWasNotGivenElement() { 
977      return this.wasNotGiven != null && !this.wasNotGiven.isEmpty();
978    }
979
980    public boolean hasWasNotGiven() { 
981      return this.wasNotGiven != null && !this.wasNotGiven.isEmpty();
982    }
983
984    /**
985     * @param value {@link #wasNotGiven} (Set this to true if the record is saying that the medication was NOT administered.). This is the underlying object with id, value and extensions. The accessor "getWasNotGiven" gives direct access to the value
986     */
987    public MedicationAdministration setWasNotGivenElement(BooleanType value) { 
988      this.wasNotGiven = value;
989      return this;
990    }
991
992    /**
993     * @return Set this to true if the record is saying that the medication was NOT administered.
994     */
995    public boolean getWasNotGiven() { 
996      return this.wasNotGiven == null || this.wasNotGiven.isEmpty() ? false : this.wasNotGiven.getValue();
997    }
998
999    /**
1000     * @param value Set this to true if the record is saying that the medication was NOT administered.
1001     */
1002    public MedicationAdministration setWasNotGiven(boolean value) { 
1003        if (this.wasNotGiven == null)
1004          this.wasNotGiven = new BooleanType();
1005        this.wasNotGiven.setValue(value);
1006      return this;
1007    }
1008
1009    /**
1010     * @return {@link #reasonNotGiven} (A code indicating why the administration was not performed.)
1011     */
1012    public List<CodeableConcept> getReasonNotGiven() { 
1013      if (this.reasonNotGiven == null)
1014        this.reasonNotGiven = new ArrayList<CodeableConcept>();
1015      return this.reasonNotGiven;
1016    }
1017
1018    public boolean hasReasonNotGiven() { 
1019      if (this.reasonNotGiven == null)
1020        return false;
1021      for (CodeableConcept item : this.reasonNotGiven)
1022        if (!item.isEmpty())
1023          return true;
1024      return false;
1025    }
1026
1027    /**
1028     * @return {@link #reasonNotGiven} (A code indicating why the administration was not performed.)
1029     */
1030    // syntactic sugar
1031    public CodeableConcept addReasonNotGiven() { //3
1032      CodeableConcept t = new CodeableConcept();
1033      if (this.reasonNotGiven == null)
1034        this.reasonNotGiven = new ArrayList<CodeableConcept>();
1035      this.reasonNotGiven.add(t);
1036      return t;
1037    }
1038
1039    // syntactic sugar
1040    public MedicationAdministration addReasonNotGiven(CodeableConcept t) { //3
1041      if (t == null)
1042        return this;
1043      if (this.reasonNotGiven == null)
1044        this.reasonNotGiven = new ArrayList<CodeableConcept>();
1045      this.reasonNotGiven.add(t);
1046      return this;
1047    }
1048
1049    /**
1050     * @return {@link #reasonGiven} (A code indicating why the medication was given.)
1051     */
1052    public List<CodeableConcept> getReasonGiven() { 
1053      if (this.reasonGiven == null)
1054        this.reasonGiven = new ArrayList<CodeableConcept>();
1055      return this.reasonGiven;
1056    }
1057
1058    public boolean hasReasonGiven() { 
1059      if (this.reasonGiven == null)
1060        return false;
1061      for (CodeableConcept item : this.reasonGiven)
1062        if (!item.isEmpty())
1063          return true;
1064      return false;
1065    }
1066
1067    /**
1068     * @return {@link #reasonGiven} (A code indicating why the medication was given.)
1069     */
1070    // syntactic sugar
1071    public CodeableConcept addReasonGiven() { //3
1072      CodeableConcept t = new CodeableConcept();
1073      if (this.reasonGiven == null)
1074        this.reasonGiven = new ArrayList<CodeableConcept>();
1075      this.reasonGiven.add(t);
1076      return t;
1077    }
1078
1079    // syntactic sugar
1080    public MedicationAdministration addReasonGiven(CodeableConcept t) { //3
1081      if (t == null)
1082        return this;
1083      if (this.reasonGiven == null)
1084        this.reasonGiven = new ArrayList<CodeableConcept>();
1085      this.reasonGiven.add(t);
1086      return this;
1087    }
1088
1089    /**
1090     * @return {@link #effectiveTime} (A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.)
1091     */
1092    public Type getEffectiveTime() { 
1093      return this.effectiveTime;
1094    }
1095
1096    /**
1097     * @return {@link #effectiveTime} (A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.)
1098     */
1099    public DateTimeType getEffectiveTimeDateTimeType() throws FHIRException { 
1100      if (!(this.effectiveTime instanceof DateTimeType))
1101        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.effectiveTime.getClass().getName()+" was encountered");
1102      return (DateTimeType) this.effectiveTime;
1103    }
1104
1105    public boolean hasEffectiveTimeDateTimeType() { 
1106      return this.effectiveTime instanceof DateTimeType;
1107    }
1108
1109    /**
1110     * @return {@link #effectiveTime} (A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.)
1111     */
1112    public Period getEffectiveTimePeriod() throws FHIRException { 
1113      if (!(this.effectiveTime instanceof Period))
1114        throw new FHIRException("Type mismatch: the type Period was expected, but "+this.effectiveTime.getClass().getName()+" was encountered");
1115      return (Period) this.effectiveTime;
1116    }
1117
1118    public boolean hasEffectiveTimePeriod() { 
1119      return this.effectiveTime instanceof Period;
1120    }
1121
1122    public boolean hasEffectiveTime() { 
1123      return this.effectiveTime != null && !this.effectiveTime.isEmpty();
1124    }
1125
1126    /**
1127     * @param value {@link #effectiveTime} (A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.)
1128     */
1129    public MedicationAdministration setEffectiveTime(Type value) { 
1130      this.effectiveTime = value;
1131      return this;
1132    }
1133
1134    /**
1135     * @return {@link #medication} (Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1136     */
1137    public Type getMedication() { 
1138      return this.medication;
1139    }
1140
1141    /**
1142     * @return {@link #medication} (Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1143     */
1144    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1145      if (!(this.medication instanceof CodeableConcept))
1146        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1147      return (CodeableConcept) this.medication;
1148    }
1149
1150    public boolean hasMedicationCodeableConcept() { 
1151      return this.medication instanceof CodeableConcept;
1152    }
1153
1154    /**
1155     * @return {@link #medication} (Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1156     */
1157    public Reference getMedicationReference() throws FHIRException { 
1158      if (!(this.medication instanceof Reference))
1159        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
1160      return (Reference) this.medication;
1161    }
1162
1163    public boolean hasMedicationReference() { 
1164      return this.medication instanceof Reference;
1165    }
1166
1167    public boolean hasMedication() { 
1168      return this.medication != null && !this.medication.isEmpty();
1169    }
1170
1171    /**
1172     * @param value {@link #medication} (Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.)
1173     */
1174    public MedicationAdministration setMedication(Type value) { 
1175      this.medication = value;
1176      return this;
1177    }
1178
1179    /**
1180     * @return {@link #device} (The device used in administering the medication to the patient.  For example, a particular infusion pump.)
1181     */
1182    public List<Reference> getDevice() { 
1183      if (this.device == null)
1184        this.device = new ArrayList<Reference>();
1185      return this.device;
1186    }
1187
1188    public boolean hasDevice() { 
1189      if (this.device == null)
1190        return false;
1191      for (Reference item : this.device)
1192        if (!item.isEmpty())
1193          return true;
1194      return false;
1195    }
1196
1197    /**
1198     * @return {@link #device} (The device used in administering the medication to the patient.  For example, a particular infusion pump.)
1199     */
1200    // syntactic sugar
1201    public Reference addDevice() { //3
1202      Reference t = new Reference();
1203      if (this.device == null)
1204        this.device = new ArrayList<Reference>();
1205      this.device.add(t);
1206      return t;
1207    }
1208
1209    // syntactic sugar
1210    public MedicationAdministration addDevice(Reference t) { //3
1211      if (t == null)
1212        return this;
1213      if (this.device == null)
1214        this.device = new ArrayList<Reference>();
1215      this.device.add(t);
1216      return this;
1217    }
1218
1219    /**
1220     * @return {@link #device} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. The device used in administering the medication to the patient.  For example, a particular infusion pump.)
1221     */
1222    public List<Device> getDeviceTarget() { 
1223      if (this.deviceTarget == null)
1224        this.deviceTarget = new ArrayList<Device>();
1225      return this.deviceTarget;
1226    }
1227
1228    // syntactic sugar
1229    /**
1230     * @return {@link #device} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. The device used in administering the medication to the patient.  For example, a particular infusion pump.)
1231     */
1232    public Device addDeviceTarget() { 
1233      Device r = new Device();
1234      if (this.deviceTarget == null)
1235        this.deviceTarget = new ArrayList<Device>();
1236      this.deviceTarget.add(r);
1237      return r;
1238    }
1239
1240    /**
1241     * @return {@link #note} (Extra information about the medication administration that is not conveyed by the other attributes.). This is the underlying object with id, value and extensions. The accessor "getNote" gives direct access to the value
1242     */
1243    public StringType getNoteElement() { 
1244      if (this.note == null)
1245        if (Configuration.errorOnAutoCreate())
1246          throw new Error("Attempt to auto-create MedicationAdministration.note");
1247        else if (Configuration.doAutoCreate())
1248          this.note = new StringType(); // bb
1249      return this.note;
1250    }
1251
1252    public boolean hasNoteElement() { 
1253      return this.note != null && !this.note.isEmpty();
1254    }
1255
1256    public boolean hasNote() { 
1257      return this.note != null && !this.note.isEmpty();
1258    }
1259
1260    /**
1261     * @param value {@link #note} (Extra information about the medication administration that is not conveyed by the other attributes.). This is the underlying object with id, value and extensions. The accessor "getNote" gives direct access to the value
1262     */
1263    public MedicationAdministration setNoteElement(StringType value) { 
1264      this.note = value;
1265      return this;
1266    }
1267
1268    /**
1269     * @return Extra information about the medication administration that is not conveyed by the other attributes.
1270     */
1271    public String getNote() { 
1272      return this.note == null ? null : this.note.getValue();
1273    }
1274
1275    /**
1276     * @param value Extra information about the medication administration that is not conveyed by the other attributes.
1277     */
1278    public MedicationAdministration setNote(String value) { 
1279      if (Utilities.noString(value))
1280        this.note = null;
1281      else {
1282        if (this.note == null)
1283          this.note = new StringType();
1284        this.note.setValue(value);
1285      }
1286      return this;
1287    }
1288
1289    /**
1290     * @return {@link #dosage} (Describes the medication dosage information details e.g. dose, rate, site, route, etc.)
1291     */
1292    public MedicationAdministrationDosageComponent getDosage() { 
1293      if (this.dosage == null)
1294        if (Configuration.errorOnAutoCreate())
1295          throw new Error("Attempt to auto-create MedicationAdministration.dosage");
1296        else if (Configuration.doAutoCreate())
1297          this.dosage = new MedicationAdministrationDosageComponent(); // cc
1298      return this.dosage;
1299    }
1300
1301    public boolean hasDosage() { 
1302      return this.dosage != null && !this.dosage.isEmpty();
1303    }
1304
1305    /**
1306     * @param value {@link #dosage} (Describes the medication dosage information details e.g. dose, rate, site, route, etc.)
1307     */
1308    public MedicationAdministration setDosage(MedicationAdministrationDosageComponent value) { 
1309      this.dosage = value;
1310      return this;
1311    }
1312
1313      protected void listChildren(List<Property> childrenList) {
1314        super.listChildren(childrenList);
1315        childrenList.add(new Property("identifier", "Identifier", "External identifier - FHIR will generate its own internal identifiers (probably URLs) which do not need to be explicitly managed by the resource.  The identifier here is one that would be used by another non-FHIR system - for example an automated medication pump would provide a record each time it operated; an administration while the patient was off the ward might be made with a different system and entered after the event.  Particularly important if these records have to be updated.", 0, java.lang.Integer.MAX_VALUE, identifier));
1316        childrenList.add(new Property("status", "code", "Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions it is possible for an administration to be started but not completed or it may be paused while some other process is under way.", 0, java.lang.Integer.MAX_VALUE, status));
1317        childrenList.add(new Property("patient", "Reference(Patient)", "The person or animal receiving the medication.", 0, java.lang.Integer.MAX_VALUE, patient));
1318        childrenList.add(new Property("practitioner", "Reference(Practitioner|Patient|RelatedPerson)", "The individual who was responsible for giving the medication to the patient.", 0, java.lang.Integer.MAX_VALUE, practitioner));
1319        childrenList.add(new Property("encounter", "Reference(Encounter)", "The visit, admission or other contact between patient and health care provider the medication administration was performed as part of.", 0, java.lang.Integer.MAX_VALUE, encounter));
1320        childrenList.add(new Property("prescription", "Reference(MedicationOrder)", "The original request, instruction or authority to perform the administration.", 0, java.lang.Integer.MAX_VALUE, prescription));
1321        childrenList.add(new Property("wasNotGiven", "boolean", "Set this to true if the record is saying that the medication was NOT administered.", 0, java.lang.Integer.MAX_VALUE, wasNotGiven));
1322        childrenList.add(new Property("reasonNotGiven", "CodeableConcept", "A code indicating why the administration was not performed.", 0, java.lang.Integer.MAX_VALUE, reasonNotGiven));
1323        childrenList.add(new Property("reasonGiven", "CodeableConcept", "A code indicating why the medication was given.", 0, java.lang.Integer.MAX_VALUE, reasonGiven));
1324        childrenList.add(new Property("effectiveTime[x]", "dateTime|Period", "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.", 0, java.lang.Integer.MAX_VALUE, effectiveTime));
1325        childrenList.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.", 0, java.lang.Integer.MAX_VALUE, medication));
1326        childrenList.add(new Property("device", "Reference(Device)", "The device used in administering the medication to the patient.  For example, a particular infusion pump.", 0, java.lang.Integer.MAX_VALUE, device));
1327        childrenList.add(new Property("note", "string", "Extra information about the medication administration that is not conveyed by the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
1328        childrenList.add(new Property("dosage", "", "Describes the medication dosage information details e.g. dose, rate, site, route, etc.", 0, java.lang.Integer.MAX_VALUE, dosage));
1329      }
1330
1331      @Override
1332      public void setProperty(String name, Base value) throws FHIRException {
1333        if (name.equals("identifier"))
1334          this.getIdentifier().add(castToIdentifier(value));
1335        else if (name.equals("status"))
1336          this.status = new MedicationAdministrationStatusEnumFactory().fromType(value); // Enumeration<MedicationAdministrationStatus>
1337        else if (name.equals("patient"))
1338          this.patient = castToReference(value); // Reference
1339        else if (name.equals("practitioner"))
1340          this.practitioner = castToReference(value); // Reference
1341        else if (name.equals("encounter"))
1342          this.encounter = castToReference(value); // Reference
1343        else if (name.equals("prescription"))
1344          this.prescription = castToReference(value); // Reference
1345        else if (name.equals("wasNotGiven"))
1346          this.wasNotGiven = castToBoolean(value); // BooleanType
1347        else if (name.equals("reasonNotGiven"))
1348          this.getReasonNotGiven().add(castToCodeableConcept(value));
1349        else if (name.equals("reasonGiven"))
1350          this.getReasonGiven().add(castToCodeableConcept(value));
1351        else if (name.equals("effectiveTime[x]"))
1352          this.effectiveTime = (Type) value; // Type
1353        else if (name.equals("medication[x]"))
1354          this.medication = (Type) value; // Type
1355        else if (name.equals("device"))
1356          this.getDevice().add(castToReference(value));
1357        else if (name.equals("note"))
1358          this.note = castToString(value); // StringType
1359        else if (name.equals("dosage"))
1360          this.dosage = (MedicationAdministrationDosageComponent) value; // MedicationAdministrationDosageComponent
1361        else
1362          super.setProperty(name, value);
1363      }
1364
1365      @Override
1366      public Base addChild(String name) throws FHIRException {
1367        if (name.equals("identifier")) {
1368          return addIdentifier();
1369        }
1370        else if (name.equals("status")) {
1371          throw new FHIRException("Cannot call addChild on a primitive type MedicationAdministration.status");
1372        }
1373        else if (name.equals("patient")) {
1374          this.patient = new Reference();
1375          return this.patient;
1376        }
1377        else if (name.equals("practitioner")) {
1378          this.practitioner = new Reference();
1379          return this.practitioner;
1380        }
1381        else if (name.equals("encounter")) {
1382          this.encounter = new Reference();
1383          return this.encounter;
1384        }
1385        else if (name.equals("prescription")) {
1386          this.prescription = new Reference();
1387          return this.prescription;
1388        }
1389        else if (name.equals("wasNotGiven")) {
1390          throw new FHIRException("Cannot call addChild on a primitive type MedicationAdministration.wasNotGiven");
1391        }
1392        else if (name.equals("reasonNotGiven")) {
1393          return addReasonNotGiven();
1394        }
1395        else if (name.equals("reasonGiven")) {
1396          return addReasonGiven();
1397        }
1398        else if (name.equals("effectiveTimeDateTime")) {
1399          this.effectiveTime = new DateTimeType();
1400          return this.effectiveTime;
1401        }
1402        else if (name.equals("effectiveTimePeriod")) {
1403          this.effectiveTime = new Period();
1404          return this.effectiveTime;
1405        }
1406        else if (name.equals("medicationCodeableConcept")) {
1407          this.medication = new CodeableConcept();
1408          return this.medication;
1409        }
1410        else if (name.equals("medicationReference")) {
1411          this.medication = new Reference();
1412          return this.medication;
1413        }
1414        else if (name.equals("device")) {
1415          return addDevice();
1416        }
1417        else if (name.equals("note")) {
1418          throw new FHIRException("Cannot call addChild on a primitive type MedicationAdministration.note");
1419        }
1420        else if (name.equals("dosage")) {
1421          this.dosage = new MedicationAdministrationDosageComponent();
1422          return this.dosage;
1423        }
1424        else
1425          return super.addChild(name);
1426      }
1427
1428  public String fhirType() {
1429    return "MedicationAdministration";
1430
1431  }
1432
1433      public MedicationAdministration copy() {
1434        MedicationAdministration dst = new MedicationAdministration();
1435        copyValues(dst);
1436        if (identifier != null) {
1437          dst.identifier = new ArrayList<Identifier>();
1438          for (Identifier i : identifier)
1439            dst.identifier.add(i.copy());
1440        };
1441        dst.status = status == null ? null : status.copy();
1442        dst.patient = patient == null ? null : patient.copy();
1443        dst.practitioner = practitioner == null ? null : practitioner.copy();
1444        dst.encounter = encounter == null ? null : encounter.copy();
1445        dst.prescription = prescription == null ? null : prescription.copy();
1446        dst.wasNotGiven = wasNotGiven == null ? null : wasNotGiven.copy();
1447        if (reasonNotGiven != null) {
1448          dst.reasonNotGiven = new ArrayList<CodeableConcept>();
1449          for (CodeableConcept i : reasonNotGiven)
1450            dst.reasonNotGiven.add(i.copy());
1451        };
1452        if (reasonGiven != null) {
1453          dst.reasonGiven = new ArrayList<CodeableConcept>();
1454          for (CodeableConcept i : reasonGiven)
1455            dst.reasonGiven.add(i.copy());
1456        };
1457        dst.effectiveTime = effectiveTime == null ? null : effectiveTime.copy();
1458        dst.medication = medication == null ? null : medication.copy();
1459        if (device != null) {
1460          dst.device = new ArrayList<Reference>();
1461          for (Reference i : device)
1462            dst.device.add(i.copy());
1463        };
1464        dst.note = note == null ? null : note.copy();
1465        dst.dosage = dosage == null ? null : dosage.copy();
1466        return dst;
1467      }
1468
1469      protected MedicationAdministration typedCopy() {
1470        return copy();
1471      }
1472
1473      @Override
1474      public boolean equalsDeep(Base other) {
1475        if (!super.equalsDeep(other))
1476          return false;
1477        if (!(other instanceof MedicationAdministration))
1478          return false;
1479        MedicationAdministration o = (MedicationAdministration) other;
1480        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(patient, o.patient, true)
1481           && compareDeep(practitioner, o.practitioner, true) && compareDeep(encounter, o.encounter, true)
1482           && compareDeep(prescription, o.prescription, true) && compareDeep(wasNotGiven, o.wasNotGiven, true)
1483           && compareDeep(reasonNotGiven, o.reasonNotGiven, true) && compareDeep(reasonGiven, o.reasonGiven, true)
1484           && compareDeep(effectiveTime, o.effectiveTime, true) && compareDeep(medication, o.medication, true)
1485           && compareDeep(device, o.device, true) && compareDeep(note, o.note, true) && compareDeep(dosage, o.dosage, true)
1486          ;
1487      }
1488
1489      @Override
1490      public boolean equalsShallow(Base other) {
1491        if (!super.equalsShallow(other))
1492          return false;
1493        if (!(other instanceof MedicationAdministration))
1494          return false;
1495        MedicationAdministration o = (MedicationAdministration) other;
1496        return compareValues(status, o.status, true) && compareValues(wasNotGiven, o.wasNotGiven, true) && compareValues(note, o.note, true)
1497          ;
1498      }
1499
1500      public boolean isEmpty() {
1501        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
1502           && (patient == null || patient.isEmpty()) && (practitioner == null || practitioner.isEmpty())
1503           && (encounter == null || encounter.isEmpty()) && (prescription == null || prescription.isEmpty())
1504           && (wasNotGiven == null || wasNotGiven.isEmpty()) && (reasonNotGiven == null || reasonNotGiven.isEmpty())
1505           && (reasonGiven == null || reasonGiven.isEmpty()) && (effectiveTime == null || effectiveTime.isEmpty())
1506           && (medication == null || medication.isEmpty()) && (device == null || device.isEmpty()) && (note == null || note.isEmpty())
1507           && (dosage == null || dosage.isEmpty());
1508      }
1509
1510  @Override
1511  public ResourceType getResourceType() {
1512    return ResourceType.MedicationAdministration;
1513   }
1514
1515  @SearchParamDefinition(name="identifier", path="MedicationAdministration.identifier", description="Return administrations with this external identifier", type="token" )
1516  public static final String SP_IDENTIFIER = "identifier";
1517  @SearchParamDefinition(name="code", path="MedicationAdministration.medicationCodeableConcept", description="Return administrations of this medication code", type="token" )
1518  public static final String SP_CODE = "code";
1519  @SearchParamDefinition(name="prescription", path="MedicationAdministration.prescription", description="The identity of a prescription to list administrations from", type="reference" )
1520  public static final String SP_PRESCRIPTION = "prescription";
1521  @SearchParamDefinition(name="effectivetime", path="MedicationAdministration.effectiveTime[x]", description="Date administration happened (or did not happen)", type="date" )
1522  public static final String SP_EFFECTIVETIME = "effectivetime";
1523  @SearchParamDefinition(name="practitioner", path="MedicationAdministration.practitioner", description="Who administered substance", type="reference" )
1524  public static final String SP_PRACTITIONER = "practitioner";
1525  @SearchParamDefinition(name="patient", path="MedicationAdministration.patient", description="The identity of a patient to list administrations  for", type="reference" )
1526  public static final String SP_PATIENT = "patient";
1527  @SearchParamDefinition(name="medication", path="MedicationAdministration.medicationReference", description="Return administrations of this medication resource", type="reference" )
1528  public static final String SP_MEDICATION = "medication";
1529  @SearchParamDefinition(name="encounter", path="MedicationAdministration.encounter", description="Return administrations that share this encounter", type="reference" )
1530  public static final String SP_ENCOUNTER = "encounter";
1531  @SearchParamDefinition(name="device", path="MedicationAdministration.device", description="Return administrations with this administration device identity", type="reference" )
1532  public static final String SP_DEVICE = "device";
1533  @SearchParamDefinition(name="notgiven", path="MedicationAdministration.wasNotGiven", description="Administrations that were not made", type="token" )
1534  public static final String SP_NOTGIVEN = "notgiven";
1535  @SearchParamDefinition(name="status", path="MedicationAdministration.status", description="MedicationAdministration event status (for example one of active/paused/completed/nullified)", type="token" )
1536  public static final String SP_STATUS = "status";
1537
1538}