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