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