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.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.ResourceDef;
044import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
045import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
046import org.hl7.fhir.exceptions.FHIRException;
047import org.hl7.fhir.utilities.Utilities;
048/**
049 * A record of a medication that is being consumed by a patient.   A MedicationStatement may indicate that the patient may be taking the medication now, or has taken the medication in the past or will be taking the medication in the future.  The source of this information can be the patient, significant other (such as a family member or spouse), or a clinician.  A common scenario where this information is captured is during the history taking process during a patient visit or stay.   The medication information may come from e.g. the patient's memory, from a prescription bottle,  or from a list of medications the patient, clinician or other party maintains 
050
051The primary difference between a medication statement and a medication administration is that the medication administration has complete administration information and is based on actual administration information from the person who administered the medication.  A medication statement is often, if not always, less specific.  There is no required date/time when the medication was administered, in fact we only know that a source has reported the patient is taking this medication, where details such as time, quantity, or rate or even medication product may be incomplete or missing or less precise.  As stated earlier, the medication statement information may come from the patient's memory, from a prescription bottle or from a list of medications the patient, clinician or other party maintains.  Medication administration is more formal and is not missing detailed information.
052 */
053@ResourceDef(name="MedicationStatement", profile="http://hl7.org/fhir/Profile/MedicationStatement")
054public class MedicationStatement extends DomainResource {
055
056    public enum MedicationStatementStatus {
057        /**
058         * The medication is still being taken.
059         */
060        ACTIVE, 
061        /**
062         * The medication is no longer being taken.
063         */
064        COMPLETED, 
065        /**
066         * The statement was entered in error.
067         */
068        ENTEREDINERROR, 
069        /**
070         * The medication may be taken at some time in the future.
071         */
072        INTENDED, 
073        /**
074         * added to help the parsers
075         */
076        NULL;
077        public static MedicationStatementStatus fromCode(String codeString) throws FHIRException {
078            if (codeString == null || "".equals(codeString))
079                return null;
080        if ("active".equals(codeString))
081          return ACTIVE;
082        if ("completed".equals(codeString))
083          return COMPLETED;
084        if ("entered-in-error".equals(codeString))
085          return ENTEREDINERROR;
086        if ("intended".equals(codeString))
087          return INTENDED;
088        throw new FHIRException("Unknown MedicationStatementStatus code '"+codeString+"'");
089        }
090        public String toCode() {
091          switch (this) {
092            case ACTIVE: return "active";
093            case COMPLETED: return "completed";
094            case ENTEREDINERROR: return "entered-in-error";
095            case INTENDED: return "intended";
096            default: return "?";
097          }
098        }
099        public String getSystem() {
100          switch (this) {
101            case ACTIVE: return "http://hl7.org/fhir/medication-statement-status";
102            case COMPLETED: return "http://hl7.org/fhir/medication-statement-status";
103            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-statement-status";
104            case INTENDED: return "http://hl7.org/fhir/medication-statement-status";
105            default: return "?";
106          }
107        }
108        public String getDefinition() {
109          switch (this) {
110            case ACTIVE: return "The medication is still being taken.";
111            case COMPLETED: return "The medication is no longer being taken.";
112            case ENTEREDINERROR: return "The statement was entered in error.";
113            case INTENDED: return "The medication may be taken at some time in the future.";
114            default: return "?";
115          }
116        }
117        public String getDisplay() {
118          switch (this) {
119            case ACTIVE: return "Active";
120            case COMPLETED: return "Completed";
121            case ENTEREDINERROR: return "Entered in Error";
122            case INTENDED: return "Intended";
123            default: return "?";
124          }
125        }
126    }
127
128  public static class MedicationStatementStatusEnumFactory implements EnumFactory<MedicationStatementStatus> {
129    public MedicationStatementStatus fromCode(String codeString) throws IllegalArgumentException {
130      if (codeString == null || "".equals(codeString))
131            if (codeString == null || "".equals(codeString))
132                return null;
133        if ("active".equals(codeString))
134          return MedicationStatementStatus.ACTIVE;
135        if ("completed".equals(codeString))
136          return MedicationStatementStatus.COMPLETED;
137        if ("entered-in-error".equals(codeString))
138          return MedicationStatementStatus.ENTEREDINERROR;
139        if ("intended".equals(codeString))
140          return MedicationStatementStatus.INTENDED;
141        throw new IllegalArgumentException("Unknown MedicationStatementStatus code '"+codeString+"'");
142        }
143        public Enumeration<MedicationStatementStatus> fromType(Base code) throws FHIRException {
144          if (code == null || code.isEmpty())
145            return null;
146          String codeString = ((PrimitiveType) code).asStringValue();
147          if (codeString == null || "".equals(codeString))
148            return null;
149        if ("active".equals(codeString))
150          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.ACTIVE);
151        if ("completed".equals(codeString))
152          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.COMPLETED);
153        if ("entered-in-error".equals(codeString))
154          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.ENTEREDINERROR);
155        if ("intended".equals(codeString))
156          return new Enumeration<MedicationStatementStatus>(this, MedicationStatementStatus.INTENDED);
157        throw new FHIRException("Unknown MedicationStatementStatus code '"+codeString+"'");
158        }
159    public String toCode(MedicationStatementStatus code) {
160      if (code == MedicationStatementStatus.ACTIVE)
161        return "active";
162      if (code == MedicationStatementStatus.COMPLETED)
163        return "completed";
164      if (code == MedicationStatementStatus.ENTEREDINERROR)
165        return "entered-in-error";
166      if (code == MedicationStatementStatus.INTENDED)
167        return "intended";
168      return "?";
169      }
170    }
171
172    @Block()
173    public static class MedicationStatementDosageComponent extends BackboneElement implements IBaseBackboneElement {
174        /**
175         * Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.
176         */
177        @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
178        @Description(shortDefinition="Reported dosage information", formalDefinition="Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans." )
179        protected StringType text;
180
181        /**
182         * The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".
183         */
184        @Child(name = "timing", type = {Timing.class}, order=2, min=0, max=1, modifier=false, summary=true)
185        @Description(shortDefinition="When/how often was medication taken", formalDefinition="The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  \"Every  8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\";  \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\"." )
186        protected Timing timing;
187
188        /**
189         * Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
190
191Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.
192         */
193        @Child(name = "asNeeded", type = {BooleanType.class, CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=true)
194        @Description(shortDefinition="Take \"as needed\" (for x)", formalDefinition="Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  \n\nSpecifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule." )
195        protected Type asNeeded;
196
197        /**
198         * A coded specification of or a reference to the anatomic site where the medication first enters the body.
199         */
200        @Child(name = "site", type = {CodeableConcept.class, BodySite.class}, order=4, min=0, max=1, modifier=false, summary=true)
201        @Description(shortDefinition="Where (on body) medication is/was administered", formalDefinition="A coded specification of or a reference to the anatomic site where the medication first enters the body." )
202        protected Type site;
203
204        /**
205         * A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.
206         */
207        @Child(name = "route", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=true)
208        @Description(shortDefinition="How the medication entered the body", formalDefinition="A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject." )
209        protected CodeableConcept route;
210
211        /**
212         * 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         */
214        @Child(name = "method", type = {CodeableConcept.class}, order=6, min=0, max=1, modifier=false, summary=true)
215        @Description(shortDefinition="Technique used to administer medication", 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." )
216        protected CodeableConcept method;
217
218        /**
219         * The amount of therapeutic or other substance given at one administration event.
220         */
221        @Child(name = "quantity", type = {SimpleQuantity.class, Range.class}, order=7, min=0, max=1, modifier=false, summary=true)
222        @Description(shortDefinition="Amount administered in one dose", formalDefinition="The amount of therapeutic or other substance given at one administration event." )
223        protected Type quantity;
224
225        /**
226         * 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         */
228        @Child(name = "rate", type = {Ratio.class, Range.class}, order=8, min=0, max=1, modifier=false, summary=true)
229        @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." )
230        protected Type rate;
231
232        /**
233         * The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.
234         */
235        @Child(name = "maxDosePerPeriod", type = {Ratio.class}, order=9, min=0, max=1, modifier=false, summary=true)
236        @Description(shortDefinition="Maximum dose that was consumed per unit of time", formalDefinition="The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours." )
237        protected Ratio maxDosePerPeriod;
238
239        private static final long serialVersionUID = 246880733L;
240
241    /*
242     * Constructor
243     */
244      public MedicationStatementDosageComponent() {
245        super();
246      }
247
248        /**
249         * @return {@link #text} (Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
250         */
251        public StringType getTextElement() { 
252          if (this.text == null)
253            if (Configuration.errorOnAutoCreate())
254              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.text");
255            else if (Configuration.doAutoCreate())
256              this.text = new StringType(); // bb
257          return this.text;
258        }
259
260        public boolean hasTextElement() { 
261          return this.text != null && !this.text.isEmpty();
262        }
263
264        public boolean hasText() { 
265          return this.text != null && !this.text.isEmpty();
266        }
267
268        /**
269         * @param value {@link #text} (Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
270         */
271        public MedicationStatementDosageComponent setTextElement(StringType value) { 
272          this.text = value;
273          return this;
274        }
275
276        /**
277         * @return Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.
278         */
279        public String getText() { 
280          return this.text == null ? null : this.text.getValue();
281        }
282
283        /**
284         * @param value Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.
285         */
286        public MedicationStatementDosageComponent setText(String value) { 
287          if (Utilities.noString(value))
288            this.text = null;
289          else {
290            if (this.text == null)
291              this.text = new StringType();
292            this.text.setValue(value);
293          }
294          return this;
295        }
296
297        /**
298         * @return {@link #timing} (The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
299         */
300        public Timing getTiming() { 
301          if (this.timing == null)
302            if (Configuration.errorOnAutoCreate())
303              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.timing");
304            else if (Configuration.doAutoCreate())
305              this.timing = new Timing(); // cc
306          return this.timing;
307        }
308
309        public boolean hasTiming() { 
310          return this.timing != null && !this.timing.isEmpty();
311        }
312
313        /**
314         * @param value {@link #timing} (The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
315         */
316        public MedicationStatementDosageComponent setTiming(Timing value) { 
317          this.timing = value;
318          return this;
319        }
320
321        /**
322         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
323
324Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
325         */
326        public Type getAsNeeded() { 
327          return this.asNeeded;
328        }
329
330        /**
331         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
332
333Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
334         */
335        public BooleanType getAsNeededBooleanType() throws FHIRException { 
336          if (!(this.asNeeded instanceof BooleanType))
337            throw new FHIRException("Type mismatch: the type BooleanType was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
338          return (BooleanType) this.asNeeded;
339        }
340
341        public boolean hasAsNeededBooleanType() { 
342          return this.asNeeded instanceof BooleanType;
343        }
344
345        /**
346         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
347
348Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
349         */
350        public CodeableConcept getAsNeededCodeableConcept() throws FHIRException { 
351          if (!(this.asNeeded instanceof CodeableConcept))
352            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
353          return (CodeableConcept) this.asNeeded;
354        }
355
356        public boolean hasAsNeededCodeableConcept() { 
357          return this.asNeeded instanceof CodeableConcept;
358        }
359
360        public boolean hasAsNeeded() { 
361          return this.asNeeded != null && !this.asNeeded.isEmpty();
362        }
363
364        /**
365         * @param value {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
366
367Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
368         */
369        public MedicationStatementDosageComponent setAsNeeded(Type value) { 
370          this.asNeeded = value;
371          return this;
372        }
373
374        /**
375         * @return {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
376         */
377        public Type getSite() { 
378          return this.site;
379        }
380
381        /**
382         * @return {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
383         */
384        public CodeableConcept getSiteCodeableConcept() throws FHIRException { 
385          if (!(this.site instanceof CodeableConcept))
386            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.site.getClass().getName()+" was encountered");
387          return (CodeableConcept) this.site;
388        }
389
390        public boolean hasSiteCodeableConcept() { 
391          return this.site instanceof CodeableConcept;
392        }
393
394        /**
395         * @return {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
396         */
397        public Reference getSiteReference() throws FHIRException { 
398          if (!(this.site instanceof Reference))
399            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.site.getClass().getName()+" was encountered");
400          return (Reference) this.site;
401        }
402
403        public boolean hasSiteReference() { 
404          return this.site instanceof Reference;
405        }
406
407        public boolean hasSite() { 
408          return this.site != null && !this.site.isEmpty();
409        }
410
411        /**
412         * @param value {@link #site} (A coded specification of or a reference to the anatomic site where the medication first enters the body.)
413         */
414        public MedicationStatementDosageComponent setSite(Type value) { 
415          this.site = value;
416          return this;
417        }
418
419        /**
420         * @return {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.)
421         */
422        public CodeableConcept getRoute() { 
423          if (this.route == null)
424            if (Configuration.errorOnAutoCreate())
425              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.route");
426            else if (Configuration.doAutoCreate())
427              this.route = new CodeableConcept(); // cc
428          return this.route;
429        }
430
431        public boolean hasRoute() { 
432          return this.route != null && !this.route.isEmpty();
433        }
434
435        /**
436         * @param value {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.)
437         */
438        public MedicationStatementDosageComponent setRoute(CodeableConcept value) { 
439          this.route = value;
440          return this;
441        }
442
443        /**
444         * @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.)
445         */
446        public CodeableConcept getMethod() { 
447          if (this.method == null)
448            if (Configuration.errorOnAutoCreate())
449              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.method");
450            else if (Configuration.doAutoCreate())
451              this.method = new CodeableConcept(); // cc
452          return this.method;
453        }
454
455        public boolean hasMethod() { 
456          return this.method != null && !this.method.isEmpty();
457        }
458
459        /**
460         * @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.)
461         */
462        public MedicationStatementDosageComponent setMethod(CodeableConcept value) { 
463          this.method = value;
464          return this;
465        }
466
467        /**
468         * @return {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
469         */
470        public Type getQuantity() { 
471          return this.quantity;
472        }
473
474        /**
475         * @return {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
476         */
477        public SimpleQuantity getQuantitySimpleQuantity() throws FHIRException { 
478          if (!(this.quantity instanceof SimpleQuantity))
479            throw new FHIRException("Type mismatch: the type SimpleQuantity was expected, but "+this.quantity.getClass().getName()+" was encountered");
480          return (SimpleQuantity) this.quantity;
481        }
482
483        public boolean hasQuantitySimpleQuantity() { 
484          return this.quantity instanceof SimpleQuantity;
485        }
486
487        /**
488         * @return {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
489         */
490        public Range getQuantityRange() throws FHIRException { 
491          if (!(this.quantity instanceof Range))
492            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.quantity.getClass().getName()+" was encountered");
493          return (Range) this.quantity;
494        }
495
496        public boolean hasQuantityRange() { 
497          return this.quantity instanceof Range;
498        }
499
500        public boolean hasQuantity() { 
501          return this.quantity != null && !this.quantity.isEmpty();
502        }
503
504        /**
505         * @param value {@link #quantity} (The amount of therapeutic or other substance given at one administration event.)
506         */
507        public MedicationStatementDosageComponent setQuantity(Type value) { 
508          this.quantity = value;
509          return this;
510        }
511
512        /**
513         * @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.)
514         */
515        public Type getRate() { 
516          return this.rate;
517        }
518
519        /**
520         * @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.)
521         */
522        public Ratio getRateRatio() throws FHIRException { 
523          if (!(this.rate instanceof Ratio))
524            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
525          return (Ratio) this.rate;
526        }
527
528        public boolean hasRateRatio() { 
529          return this.rate instanceof Ratio;
530        }
531
532        /**
533         * @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.)
534         */
535        public Range getRateRange() throws FHIRException { 
536          if (!(this.rate instanceof Range))
537            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
538          return (Range) this.rate;
539        }
540
541        public boolean hasRateRange() { 
542          return this.rate instanceof Range;
543        }
544
545        public boolean hasRate() { 
546          return this.rate != null && !this.rate.isEmpty();
547        }
548
549        /**
550         * @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.)
551         */
552        public MedicationStatementDosageComponent setRate(Type value) { 
553          this.rate = value;
554          return this;
555        }
556
557        /**
558         * @return {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.)
559         */
560        public Ratio getMaxDosePerPeriod() { 
561          if (this.maxDosePerPeriod == null)
562            if (Configuration.errorOnAutoCreate())
563              throw new Error("Attempt to auto-create MedicationStatementDosageComponent.maxDosePerPeriod");
564            else if (Configuration.doAutoCreate())
565              this.maxDosePerPeriod = new Ratio(); // cc
566          return this.maxDosePerPeriod;
567        }
568
569        public boolean hasMaxDosePerPeriod() { 
570          return this.maxDosePerPeriod != null && !this.maxDosePerPeriod.isEmpty();
571        }
572
573        /**
574         * @param value {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.)
575         */
576        public MedicationStatementDosageComponent setMaxDosePerPeriod(Ratio value) { 
577          this.maxDosePerPeriod = value;
578          return this;
579        }
580
581        protected void listChildren(List<Property> childrenList) {
582          super.listChildren(childrenList);
583          childrenList.add(new Property("text", "string", "Free text dosage information as reported about a patient's medication use. When coded dosage information is present, the free text may still be present for display to humans.", 0, java.lang.Integer.MAX_VALUE, text));
584          childrenList.add(new Property("timing", "Timing", "The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions, for example.  \"Every  8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\";  \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\".", 0, java.lang.Integer.MAX_VALUE, timing));
585          childrenList.add(new Property("asNeeded[x]", "boolean|CodeableConcept", "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  \n\nSpecifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.", 0, java.lang.Integer.MAX_VALUE, asNeeded));
586          childrenList.add(new Property("site[x]", "CodeableConcept|Reference(BodySite)", "A coded specification of or a reference to the anatomic site where the medication first enters the body.", 0, java.lang.Integer.MAX_VALUE, site));
587          childrenList.add(new Property("route", "CodeableConcept", "A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.", 0, java.lang.Integer.MAX_VALUE, route));
588          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));
589          childrenList.add(new Property("quantity[x]", "SimpleQuantity|Range", "The amount of therapeutic or other substance given at one administration event.", 0, java.lang.Integer.MAX_VALUE, quantity));
590          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));
591          childrenList.add(new Property("maxDosePerPeriod", "Ratio", "The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time.  For example, 1000mg in 24 hours.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod));
592        }
593
594      @Override
595      public void setProperty(String name, Base value) throws FHIRException {
596        if (name.equals("text"))
597          this.text = castToString(value); // StringType
598        else if (name.equals("timing"))
599          this.timing = castToTiming(value); // Timing
600        else if (name.equals("asNeeded[x]"))
601          this.asNeeded = (Type) value; // Type
602        else if (name.equals("site[x]"))
603          this.site = (Type) value; // Type
604        else if (name.equals("route"))
605          this.route = castToCodeableConcept(value); // CodeableConcept
606        else if (name.equals("method"))
607          this.method = castToCodeableConcept(value); // CodeableConcept
608        else if (name.equals("quantity[x]"))
609          this.quantity = (Type) value; // Type
610        else if (name.equals("rate[x]"))
611          this.rate = (Type) value; // Type
612        else if (name.equals("maxDosePerPeriod"))
613          this.maxDosePerPeriod = castToRatio(value); // Ratio
614        else
615          super.setProperty(name, value);
616      }
617
618      @Override
619      public Base addChild(String name) throws FHIRException {
620        if (name.equals("text")) {
621          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.text");
622        }
623        else if (name.equals("timing")) {
624          this.timing = new Timing();
625          return this.timing;
626        }
627        else if (name.equals("asNeededBoolean")) {
628          this.asNeeded = new BooleanType();
629          return this.asNeeded;
630        }
631        else if (name.equals("asNeededCodeableConcept")) {
632          this.asNeeded = new CodeableConcept();
633          return this.asNeeded;
634        }
635        else if (name.equals("siteCodeableConcept")) {
636          this.site = new CodeableConcept();
637          return this.site;
638        }
639        else if (name.equals("siteReference")) {
640          this.site = new Reference();
641          return this.site;
642        }
643        else if (name.equals("route")) {
644          this.route = new CodeableConcept();
645          return this.route;
646        }
647        else if (name.equals("method")) {
648          this.method = new CodeableConcept();
649          return this.method;
650        }
651        else if (name.equals("quantitySimpleQuantity")) {
652          this.quantity = new SimpleQuantity();
653          return this.quantity;
654        }
655        else if (name.equals("quantityRange")) {
656          this.quantity = new Range();
657          return this.quantity;
658        }
659        else if (name.equals("rateRatio")) {
660          this.rate = new Ratio();
661          return this.rate;
662        }
663        else if (name.equals("rateRange")) {
664          this.rate = new Range();
665          return this.rate;
666        }
667        else if (name.equals("maxDosePerPeriod")) {
668          this.maxDosePerPeriod = new Ratio();
669          return this.maxDosePerPeriod;
670        }
671        else
672          return super.addChild(name);
673      }
674
675      public MedicationStatementDosageComponent copy() {
676        MedicationStatementDosageComponent dst = new MedicationStatementDosageComponent();
677        copyValues(dst);
678        dst.text = text == null ? null : text.copy();
679        dst.timing = timing == null ? null : timing.copy();
680        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
681        dst.site = site == null ? null : site.copy();
682        dst.route = route == null ? null : route.copy();
683        dst.method = method == null ? null : method.copy();
684        dst.quantity = quantity == null ? null : quantity.copy();
685        dst.rate = rate == null ? null : rate.copy();
686        dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
687        return dst;
688      }
689
690      @Override
691      public boolean equalsDeep(Base other) {
692        if (!super.equalsDeep(other))
693          return false;
694        if (!(other instanceof MedicationStatementDosageComponent))
695          return false;
696        MedicationStatementDosageComponent o = (MedicationStatementDosageComponent) other;
697        return compareDeep(text, o.text, true) && compareDeep(timing, o.timing, true) && compareDeep(asNeeded, o.asNeeded, true)
698           && compareDeep(site, o.site, true) && compareDeep(route, o.route, true) && compareDeep(method, o.method, true)
699           && compareDeep(quantity, o.quantity, true) && compareDeep(rate, o.rate, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true)
700          ;
701      }
702
703      @Override
704      public boolean equalsShallow(Base other) {
705        if (!super.equalsShallow(other))
706          return false;
707        if (!(other instanceof MedicationStatementDosageComponent))
708          return false;
709        MedicationStatementDosageComponent o = (MedicationStatementDosageComponent) other;
710        return compareValues(text, o.text, true);
711      }
712
713      public boolean isEmpty() {
714        return super.isEmpty() && (text == null || text.isEmpty()) && (timing == null || timing.isEmpty())
715           && (asNeeded == null || asNeeded.isEmpty()) && (site == null || site.isEmpty()) && (route == null || route.isEmpty())
716           && (method == null || method.isEmpty()) && (quantity == null || quantity.isEmpty()) && (rate == null || rate.isEmpty())
717           && (maxDosePerPeriod == null || maxDosePerPeriod.isEmpty());
718      }
719
720  public String fhirType() {
721    return "MedicationStatement.dosage";
722
723  }
724
725  }
726
727    /**
728     * 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.
729     */
730    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
731    @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." )
732    protected List<Identifier> identifier;
733
734    /**
735     * The person or animal who is/was taking the medication.
736     */
737    @Child(name = "patient", type = {Patient.class}, order=1, min=1, max=1, modifier=false, summary=true)
738    @Description(shortDefinition="Who is/was taking  the medication", formalDefinition="The person or animal who is/was taking the medication." )
739    protected Reference patient;
740
741    /**
742     * The actual object that is the target of the reference (The person or animal who is/was taking the medication.)
743     */
744    protected Patient patientTarget;
745
746    /**
747     * The person who provided the information about the taking of this medication.
748     */
749    @Child(name = "informationSource", type = {Patient.class, Practitioner.class, RelatedPerson.class}, order=2, min=0, max=1, modifier=false, summary=true)
750    @Description(shortDefinition="", formalDefinition="The person who provided the information about the taking of this medication." )
751    protected Reference informationSource;
752
753    /**
754     * The actual object that is the target of the reference (The person who provided the information about the taking of this medication.)
755     */
756    protected Resource informationSourceTarget;
757
758    /**
759     * The date when the medication statement was asserted by the information source.
760     */
761    @Child(name = "dateAsserted", type = {DateTimeType.class}, order=3, min=0, max=1, modifier=false, summary=true)
762    @Description(shortDefinition="When the statement was asserted?", formalDefinition="The date when the medication statement was asserted by the information source." )
763    protected DateTimeType dateAsserted;
764
765    /**
766     * A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.
767     */
768    @Child(name = "status", type = {CodeType.class}, order=4, min=1, max=1, modifier=true, summary=true)
769    @Description(shortDefinition="active | completed | entered-in-error | intended", formalDefinition="A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed." )
770    protected Enumeration<MedicationStatementStatus> status;
771
772    /**
773     * Set this to true if the record is saying that the medication was NOT taken.
774     */
775    @Child(name = "wasNotTaken", type = {BooleanType.class}, order=5, min=0, max=1, modifier=true, summary=true)
776    @Description(shortDefinition="True if medication is/was not being taken", formalDefinition="Set this to true if the record is saying that the medication was NOT taken." )
777    protected BooleanType wasNotTaken;
778
779    /**
780     * A code indicating why the medication was not taken.
781     */
782    @Child(name = "reasonNotTaken", type = {CodeableConcept.class}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
783    @Description(shortDefinition="True if asserting medication was not given", formalDefinition="A code indicating why the medication was not taken." )
784    protected List<CodeableConcept> reasonNotTaken;
785
786    /**
787     * A reason for why the medication is being/was taken.
788     */
789    @Child(name = "reasonForUse", type = {CodeableConcept.class, Condition.class}, order=7, min=0, max=1, modifier=false, summary=true)
790    @Description(shortDefinition="", formalDefinition="A reason for why the medication is being/was taken." )
791    protected Type reasonForUse;
792
793    /**
794     * The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).
795     */
796    @Child(name = "effective", type = {DateTimeType.class, Period.class}, order=8, min=0, max=1, modifier=false, summary=true)
797    @Description(shortDefinition="Over what period was medication consumed?", formalDefinition="The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true)." )
798    protected Type effective;
799
800    /**
801     * Provides extra information about the medication statement that is not conveyed by the other attributes.
802     */
803    @Child(name = "note", type = {StringType.class}, order=9, min=0, max=1, modifier=false, summary=true)
804    @Description(shortDefinition="Further information about the statement", formalDefinition="Provides extra information about the medication statement that is not conveyed by the other attributes." )
805    protected StringType note;
806
807    /**
808     * Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement.
809     */
810    @Child(name = "supportingInformation", type = {}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
811    @Description(shortDefinition="Additional supporting information", formalDefinition="Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement." )
812    protected List<Reference> supportingInformation;
813    /**
814     * The actual objects that are the target of the reference (Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement.)
815     */
816    protected List<Resource> supportingInformationTarget;
817
818
819    /**
820     * Identifies the medication being 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.
821     */
822    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=11, min=1, max=1, modifier=false, summary=true)
823    @Description(shortDefinition="What medication was taken", formalDefinition="Identifies the medication being 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." )
824    protected Type medication;
825
826    /**
827     * Indicates how the medication is/was used by the patient.
828     */
829    @Child(name = "dosage", type = {}, order=12, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
830    @Description(shortDefinition="Details of how medication was taken", formalDefinition="Indicates how the medication is/was used by the patient." )
831    protected List<MedicationStatementDosageComponent> dosage;
832
833    private static final long serialVersionUID = 55795672L;
834
835  /*
836   * Constructor
837   */
838    public MedicationStatement() {
839      super();
840    }
841
842  /*
843   * Constructor
844   */
845    public MedicationStatement(Reference patient, Enumeration<MedicationStatementStatus> status, Type medication) {
846      super();
847      this.patient = patient;
848      this.status = status;
849      this.medication = medication;
850    }
851
852    /**
853     * @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.)
854     */
855    public List<Identifier> getIdentifier() { 
856      if (this.identifier == null)
857        this.identifier = new ArrayList<Identifier>();
858      return this.identifier;
859    }
860
861    public boolean hasIdentifier() { 
862      if (this.identifier == null)
863        return false;
864      for (Identifier item : this.identifier)
865        if (!item.isEmpty())
866          return true;
867      return false;
868    }
869
870    /**
871     * @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.)
872     */
873    // syntactic sugar
874    public Identifier addIdentifier() { //3
875      Identifier t = new Identifier();
876      if (this.identifier == null)
877        this.identifier = new ArrayList<Identifier>();
878      this.identifier.add(t);
879      return t;
880    }
881
882    // syntactic sugar
883    public MedicationStatement addIdentifier(Identifier t) { //3
884      if (t == null)
885        return this;
886      if (this.identifier == null)
887        this.identifier = new ArrayList<Identifier>();
888      this.identifier.add(t);
889      return this;
890    }
891
892    /**
893     * @return {@link #patient} (The person or animal who is/was taking the medication.)
894     */
895    public Reference getPatient() { 
896      if (this.patient == null)
897        if (Configuration.errorOnAutoCreate())
898          throw new Error("Attempt to auto-create MedicationStatement.patient");
899        else if (Configuration.doAutoCreate())
900          this.patient = new Reference(); // cc
901      return this.patient;
902    }
903
904    public boolean hasPatient() { 
905      return this.patient != null && !this.patient.isEmpty();
906    }
907
908    /**
909     * @param value {@link #patient} (The person or animal who is/was taking the medication.)
910     */
911    public MedicationStatement setPatient(Reference value) { 
912      this.patient = value;
913      return this;
914    }
915
916    /**
917     * @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 who is/was taking the medication.)
918     */
919    public Patient getPatientTarget() { 
920      if (this.patientTarget == null)
921        if (Configuration.errorOnAutoCreate())
922          throw new Error("Attempt to auto-create MedicationStatement.patient");
923        else if (Configuration.doAutoCreate())
924          this.patientTarget = new Patient(); // aa
925      return this.patientTarget;
926    }
927
928    /**
929     * @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 who is/was taking the medication.)
930     */
931    public MedicationStatement setPatientTarget(Patient value) { 
932      this.patientTarget = value;
933      return this;
934    }
935
936    /**
937     * @return {@link #informationSource} (The person who provided the information about the taking of this medication.)
938     */
939    public Reference getInformationSource() { 
940      if (this.informationSource == null)
941        if (Configuration.errorOnAutoCreate())
942          throw new Error("Attempt to auto-create MedicationStatement.informationSource");
943        else if (Configuration.doAutoCreate())
944          this.informationSource = new Reference(); // cc
945      return this.informationSource;
946    }
947
948    public boolean hasInformationSource() { 
949      return this.informationSource != null && !this.informationSource.isEmpty();
950    }
951
952    /**
953     * @param value {@link #informationSource} (The person who provided the information about the taking of this medication.)
954     */
955    public MedicationStatement setInformationSource(Reference value) { 
956      this.informationSource = value;
957      return this;
958    }
959
960    /**
961     * @return {@link #informationSource} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The person who provided the information about the taking of this medication.)
962     */
963    public Resource getInformationSourceTarget() { 
964      return this.informationSourceTarget;
965    }
966
967    /**
968     * @param value {@link #informationSource} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The person who provided the information about the taking of this medication.)
969     */
970    public MedicationStatement setInformationSourceTarget(Resource value) { 
971      this.informationSourceTarget = value;
972      return this;
973    }
974
975    /**
976     * @return {@link #dateAsserted} (The date when the medication statement was asserted by the information source.). This is the underlying object with id, value and extensions. The accessor "getDateAsserted" gives direct access to the value
977     */
978    public DateTimeType getDateAssertedElement() { 
979      if (this.dateAsserted == null)
980        if (Configuration.errorOnAutoCreate())
981          throw new Error("Attempt to auto-create MedicationStatement.dateAsserted");
982        else if (Configuration.doAutoCreate())
983          this.dateAsserted = new DateTimeType(); // bb
984      return this.dateAsserted;
985    }
986
987    public boolean hasDateAssertedElement() { 
988      return this.dateAsserted != null && !this.dateAsserted.isEmpty();
989    }
990
991    public boolean hasDateAsserted() { 
992      return this.dateAsserted != null && !this.dateAsserted.isEmpty();
993    }
994
995    /**
996     * @param value {@link #dateAsserted} (The date when the medication statement was asserted by the information source.). This is the underlying object with id, value and extensions. The accessor "getDateAsserted" gives direct access to the value
997     */
998    public MedicationStatement setDateAssertedElement(DateTimeType value) { 
999      this.dateAsserted = value;
1000      return this;
1001    }
1002
1003    /**
1004     * @return The date when the medication statement was asserted by the information source.
1005     */
1006    public Date getDateAsserted() { 
1007      return this.dateAsserted == null ? null : this.dateAsserted.getValue();
1008    }
1009
1010    /**
1011     * @param value The date when the medication statement was asserted by the information source.
1012     */
1013    public MedicationStatement setDateAsserted(Date value) { 
1014      if (value == null)
1015        this.dateAsserted = null;
1016      else {
1017        if (this.dateAsserted == null)
1018          this.dateAsserted = new DateTimeType();
1019        this.dateAsserted.setValue(value);
1020      }
1021      return this;
1022    }
1023
1024    /**
1025     * @return {@link #status} (A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1026     */
1027    public Enumeration<MedicationStatementStatus> getStatusElement() { 
1028      if (this.status == null)
1029        if (Configuration.errorOnAutoCreate())
1030          throw new Error("Attempt to auto-create MedicationStatement.status");
1031        else if (Configuration.doAutoCreate())
1032          this.status = new Enumeration<MedicationStatementStatus>(new MedicationStatementStatusEnumFactory()); // bb
1033      return this.status;
1034    }
1035
1036    public boolean hasStatusElement() { 
1037      return this.status != null && !this.status.isEmpty();
1038    }
1039
1040    public boolean hasStatus() { 
1041      return this.status != null && !this.status.isEmpty();
1042    }
1043
1044    /**
1045     * @param value {@link #status} (A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1046     */
1047    public MedicationStatement setStatusElement(Enumeration<MedicationStatementStatus> value) { 
1048      this.status = value;
1049      return this;
1050    }
1051
1052    /**
1053     * @return A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.
1054     */
1055    public MedicationStatementStatus getStatus() { 
1056      return this.status == null ? null : this.status.getValue();
1057    }
1058
1059    /**
1060     * @param value A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.
1061     */
1062    public MedicationStatement setStatus(MedicationStatementStatus value) { 
1063        if (this.status == null)
1064          this.status = new Enumeration<MedicationStatementStatus>(new MedicationStatementStatusEnumFactory());
1065        this.status.setValue(value);
1066      return this;
1067    }
1068
1069    /**
1070     * @return {@link #wasNotTaken} (Set this to true if the record is saying that the medication was NOT taken.). This is the underlying object with id, value and extensions. The accessor "getWasNotTaken" gives direct access to the value
1071     */
1072    public BooleanType getWasNotTakenElement() { 
1073      if (this.wasNotTaken == null)
1074        if (Configuration.errorOnAutoCreate())
1075          throw new Error("Attempt to auto-create MedicationStatement.wasNotTaken");
1076        else if (Configuration.doAutoCreate())
1077          this.wasNotTaken = new BooleanType(); // bb
1078      return this.wasNotTaken;
1079    }
1080
1081    public boolean hasWasNotTakenElement() { 
1082      return this.wasNotTaken != null && !this.wasNotTaken.isEmpty();
1083    }
1084
1085    public boolean hasWasNotTaken() { 
1086      return this.wasNotTaken != null && !this.wasNotTaken.isEmpty();
1087    }
1088
1089    /**
1090     * @param value {@link #wasNotTaken} (Set this to true if the record is saying that the medication was NOT taken.). This is the underlying object with id, value and extensions. The accessor "getWasNotTaken" gives direct access to the value
1091     */
1092    public MedicationStatement setWasNotTakenElement(BooleanType value) { 
1093      this.wasNotTaken = value;
1094      return this;
1095    }
1096
1097    /**
1098     * @return Set this to true if the record is saying that the medication was NOT taken.
1099     */
1100    public boolean getWasNotTaken() { 
1101      return this.wasNotTaken == null || this.wasNotTaken.isEmpty() ? false : this.wasNotTaken.getValue();
1102    }
1103
1104    /**
1105     * @param value Set this to true if the record is saying that the medication was NOT taken.
1106     */
1107    public MedicationStatement setWasNotTaken(boolean value) { 
1108        if (this.wasNotTaken == null)
1109          this.wasNotTaken = new BooleanType();
1110        this.wasNotTaken.setValue(value);
1111      return this;
1112    }
1113
1114    /**
1115     * @return {@link #reasonNotTaken} (A code indicating why the medication was not taken.)
1116     */
1117    public List<CodeableConcept> getReasonNotTaken() { 
1118      if (this.reasonNotTaken == null)
1119        this.reasonNotTaken = new ArrayList<CodeableConcept>();
1120      return this.reasonNotTaken;
1121    }
1122
1123    public boolean hasReasonNotTaken() { 
1124      if (this.reasonNotTaken == null)
1125        return false;
1126      for (CodeableConcept item : this.reasonNotTaken)
1127        if (!item.isEmpty())
1128          return true;
1129      return false;
1130    }
1131
1132    /**
1133     * @return {@link #reasonNotTaken} (A code indicating why the medication was not taken.)
1134     */
1135    // syntactic sugar
1136    public CodeableConcept addReasonNotTaken() { //3
1137      CodeableConcept t = new CodeableConcept();
1138      if (this.reasonNotTaken == null)
1139        this.reasonNotTaken = new ArrayList<CodeableConcept>();
1140      this.reasonNotTaken.add(t);
1141      return t;
1142    }
1143
1144    // syntactic sugar
1145    public MedicationStatement addReasonNotTaken(CodeableConcept t) { //3
1146      if (t == null)
1147        return this;
1148      if (this.reasonNotTaken == null)
1149        this.reasonNotTaken = new ArrayList<CodeableConcept>();
1150      this.reasonNotTaken.add(t);
1151      return this;
1152    }
1153
1154    /**
1155     * @return {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1156     */
1157    public Type getReasonForUse() { 
1158      return this.reasonForUse;
1159    }
1160
1161    /**
1162     * @return {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1163     */
1164    public CodeableConcept getReasonForUseCodeableConcept() throws FHIRException { 
1165      if (!(this.reasonForUse instanceof CodeableConcept))
1166        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.reasonForUse.getClass().getName()+" was encountered");
1167      return (CodeableConcept) this.reasonForUse;
1168    }
1169
1170    public boolean hasReasonForUseCodeableConcept() { 
1171      return this.reasonForUse instanceof CodeableConcept;
1172    }
1173
1174    /**
1175     * @return {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1176     */
1177    public Reference getReasonForUseReference() throws FHIRException { 
1178      if (!(this.reasonForUse instanceof Reference))
1179        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.reasonForUse.getClass().getName()+" was encountered");
1180      return (Reference) this.reasonForUse;
1181    }
1182
1183    public boolean hasReasonForUseReference() { 
1184      return this.reasonForUse instanceof Reference;
1185    }
1186
1187    public boolean hasReasonForUse() { 
1188      return this.reasonForUse != null && !this.reasonForUse.isEmpty();
1189    }
1190
1191    /**
1192     * @param value {@link #reasonForUse} (A reason for why the medication is being/was taken.)
1193     */
1194    public MedicationStatement setReasonForUse(Type value) { 
1195      this.reasonForUse = value;
1196      return this;
1197    }
1198
1199    /**
1200     * @return {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1201     */
1202    public Type getEffective() { 
1203      return this.effective;
1204    }
1205
1206    /**
1207     * @return {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1208     */
1209    public DateTimeType getEffectiveDateTimeType() throws FHIRException { 
1210      if (!(this.effective instanceof DateTimeType))
1211        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.effective.getClass().getName()+" was encountered");
1212      return (DateTimeType) this.effective;
1213    }
1214
1215    public boolean hasEffectiveDateTimeType() { 
1216      return this.effective instanceof DateTimeType;
1217    }
1218
1219    /**
1220     * @return {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1221     */
1222    public Period getEffectivePeriod() throws FHIRException { 
1223      if (!(this.effective instanceof Period))
1224        throw new FHIRException("Type mismatch: the type Period was expected, but "+this.effective.getClass().getName()+" was encountered");
1225      return (Period) this.effective;
1226    }
1227
1228    public boolean hasEffectivePeriod() { 
1229      return this.effective instanceof Period;
1230    }
1231
1232    public boolean hasEffective() { 
1233      return this.effective != null && !this.effective.isEmpty();
1234    }
1235
1236    /**
1237     * @param value {@link #effective} (The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).)
1238     */
1239    public MedicationStatement setEffective(Type value) { 
1240      this.effective = value;
1241      return this;
1242    }
1243
1244    /**
1245     * @return {@link #note} (Provides extra information about the medication statement 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
1246     */
1247    public StringType getNoteElement() { 
1248      if (this.note == null)
1249        if (Configuration.errorOnAutoCreate())
1250          throw new Error("Attempt to auto-create MedicationStatement.note");
1251        else if (Configuration.doAutoCreate())
1252          this.note = new StringType(); // bb
1253      return this.note;
1254    }
1255
1256    public boolean hasNoteElement() { 
1257      return this.note != null && !this.note.isEmpty();
1258    }
1259
1260    public boolean hasNote() { 
1261      return this.note != null && !this.note.isEmpty();
1262    }
1263
1264    /**
1265     * @param value {@link #note} (Provides extra information about the medication statement 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
1266     */
1267    public MedicationStatement setNoteElement(StringType value) { 
1268      this.note = value;
1269      return this;
1270    }
1271
1272    /**
1273     * @return Provides extra information about the medication statement that is not conveyed by the other attributes.
1274     */
1275    public String getNote() { 
1276      return this.note == null ? null : this.note.getValue();
1277    }
1278
1279    /**
1280     * @param value Provides extra information about the medication statement that is not conveyed by the other attributes.
1281     */
1282    public MedicationStatement setNote(String value) { 
1283      if (Utilities.noString(value))
1284        this.note = null;
1285      else {
1286        if (this.note == null)
1287          this.note = new StringType();
1288        this.note.setValue(value);
1289      }
1290      return this;
1291    }
1292
1293    /**
1294     * @return {@link #supportingInformation} (Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement.)
1295     */
1296    public List<Reference> getSupportingInformation() { 
1297      if (this.supportingInformation == null)
1298        this.supportingInformation = new ArrayList<Reference>();
1299      return this.supportingInformation;
1300    }
1301
1302    public boolean hasSupportingInformation() { 
1303      if (this.supportingInformation == null)
1304        return false;
1305      for (Reference item : this.supportingInformation)
1306        if (!item.isEmpty())
1307          return true;
1308      return false;
1309    }
1310
1311    /**
1312     * @return {@link #supportingInformation} (Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement.)
1313     */
1314    // syntactic sugar
1315    public Reference addSupportingInformation() { //3
1316      Reference t = new Reference();
1317      if (this.supportingInformation == null)
1318        this.supportingInformation = new ArrayList<Reference>();
1319      this.supportingInformation.add(t);
1320      return t;
1321    }
1322
1323    // syntactic sugar
1324    public MedicationStatement addSupportingInformation(Reference t) { //3
1325      if (t == null)
1326        return this;
1327      if (this.supportingInformation == null)
1328        this.supportingInformation = new ArrayList<Reference>();
1329      this.supportingInformation.add(t);
1330      return this;
1331    }
1332
1333    /**
1334     * @return {@link #supportingInformation} (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. Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement.)
1335     */
1336    public List<Resource> getSupportingInformationTarget() { 
1337      if (this.supportingInformationTarget == null)
1338        this.supportingInformationTarget = new ArrayList<Resource>();
1339      return this.supportingInformationTarget;
1340    }
1341
1342    /**
1343     * @return {@link #medication} (Identifies the medication being 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.)
1344     */
1345    public Type getMedication() { 
1346      return this.medication;
1347    }
1348
1349    /**
1350     * @return {@link #medication} (Identifies the medication being 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.)
1351     */
1352    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1353      if (!(this.medication instanceof CodeableConcept))
1354        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1355      return (CodeableConcept) this.medication;
1356    }
1357
1358    public boolean hasMedicationCodeableConcept() { 
1359      return this.medication instanceof CodeableConcept;
1360    }
1361
1362    /**
1363     * @return {@link #medication} (Identifies the medication being 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.)
1364     */
1365    public Reference getMedicationReference() throws FHIRException { 
1366      if (!(this.medication instanceof Reference))
1367        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
1368      return (Reference) this.medication;
1369    }
1370
1371    public boolean hasMedicationReference() { 
1372      return this.medication instanceof Reference;
1373    }
1374
1375    public boolean hasMedication() { 
1376      return this.medication != null && !this.medication.isEmpty();
1377    }
1378
1379    /**
1380     * @param value {@link #medication} (Identifies the medication being 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.)
1381     */
1382    public MedicationStatement setMedication(Type value) { 
1383      this.medication = value;
1384      return this;
1385    }
1386
1387    /**
1388     * @return {@link #dosage} (Indicates how the medication is/was used by the patient.)
1389     */
1390    public List<MedicationStatementDosageComponent> getDosage() { 
1391      if (this.dosage == null)
1392        this.dosage = new ArrayList<MedicationStatementDosageComponent>();
1393      return this.dosage;
1394    }
1395
1396    public boolean hasDosage() { 
1397      if (this.dosage == null)
1398        return false;
1399      for (MedicationStatementDosageComponent item : this.dosage)
1400        if (!item.isEmpty())
1401          return true;
1402      return false;
1403    }
1404
1405    /**
1406     * @return {@link #dosage} (Indicates how the medication is/was used by the patient.)
1407     */
1408    // syntactic sugar
1409    public MedicationStatementDosageComponent addDosage() { //3
1410      MedicationStatementDosageComponent t = new MedicationStatementDosageComponent();
1411      if (this.dosage == null)
1412        this.dosage = new ArrayList<MedicationStatementDosageComponent>();
1413      this.dosage.add(t);
1414      return t;
1415    }
1416
1417    // syntactic sugar
1418    public MedicationStatement addDosage(MedicationStatementDosageComponent t) { //3
1419      if (t == null)
1420        return this;
1421      if (this.dosage == null)
1422        this.dosage = new ArrayList<MedicationStatementDosageComponent>();
1423      this.dosage.add(t);
1424      return this;
1425    }
1426
1427      protected void listChildren(List<Property> childrenList) {
1428        super.listChildren(childrenList);
1429        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));
1430        childrenList.add(new Property("patient", "Reference(Patient)", "The person or animal who is/was taking the medication.", 0, java.lang.Integer.MAX_VALUE, patient));
1431        childrenList.add(new Property("informationSource", "Reference(Patient|Practitioner|RelatedPerson)", "The person who provided the information about the taking of this medication.", 0, java.lang.Integer.MAX_VALUE, informationSource));
1432        childrenList.add(new Property("dateAsserted", "dateTime", "The date when the medication statement was asserted by the information source.", 0, java.lang.Integer.MAX_VALUE, dateAsserted));
1433        childrenList.add(new Property("status", "code", "A code representing the patient or other source's judgment about the state of the medication used that this statement is about.  Generally this will be active or completed.", 0, java.lang.Integer.MAX_VALUE, status));
1434        childrenList.add(new Property("wasNotTaken", "boolean", "Set this to true if the record is saying that the medication was NOT taken.", 0, java.lang.Integer.MAX_VALUE, wasNotTaken));
1435        childrenList.add(new Property("reasonNotTaken", "CodeableConcept", "A code indicating why the medication was not taken.", 0, java.lang.Integer.MAX_VALUE, reasonNotTaken));
1436        childrenList.add(new Property("reasonForUse[x]", "CodeableConcept|Reference(Condition)", "A reason for why the medication is being/was taken.", 0, java.lang.Integer.MAX_VALUE, reasonForUse));
1437        childrenList.add(new Property("effective[x]", "dateTime|Period", "The interval of time during which it is being asserted that the patient was taking the medication (or was not taking, when the wasNotGiven element is true).", 0, java.lang.Integer.MAX_VALUE, effective));
1438        childrenList.add(new Property("note", "string", "Provides extra information about the medication statement that is not conveyed by the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
1439        childrenList.add(new Property("supportingInformation", "Reference(Any)", "Allows linking the MedicationStatement to the underlying MedicationOrder, or to other information that supports the MedicationStatement.", 0, java.lang.Integer.MAX_VALUE, supportingInformation));
1440        childrenList.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being 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));
1441        childrenList.add(new Property("dosage", "", "Indicates how the medication is/was used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosage));
1442      }
1443
1444      @Override
1445      public void setProperty(String name, Base value) throws FHIRException {
1446        if (name.equals("identifier"))
1447          this.getIdentifier().add(castToIdentifier(value));
1448        else if (name.equals("patient"))
1449          this.patient = castToReference(value); // Reference
1450        else if (name.equals("informationSource"))
1451          this.informationSource = castToReference(value); // Reference
1452        else if (name.equals("dateAsserted"))
1453          this.dateAsserted = castToDateTime(value); // DateTimeType
1454        else if (name.equals("status"))
1455          this.status = new MedicationStatementStatusEnumFactory().fromType(value); // Enumeration<MedicationStatementStatus>
1456        else if (name.equals("wasNotTaken"))
1457          this.wasNotTaken = castToBoolean(value); // BooleanType
1458        else if (name.equals("reasonNotTaken"))
1459          this.getReasonNotTaken().add(castToCodeableConcept(value));
1460        else if (name.equals("reasonForUse[x]"))
1461          this.reasonForUse = (Type) value; // Type
1462        else if (name.equals("effective[x]"))
1463          this.effective = (Type) value; // Type
1464        else if (name.equals("note"))
1465          this.note = castToString(value); // StringType
1466        else if (name.equals("supportingInformation"))
1467          this.getSupportingInformation().add(castToReference(value));
1468        else if (name.equals("medication[x]"))
1469          this.medication = (Type) value; // Type
1470        else if (name.equals("dosage"))
1471          this.getDosage().add((MedicationStatementDosageComponent) value);
1472        else
1473          super.setProperty(name, value);
1474      }
1475
1476      @Override
1477      public Base addChild(String name) throws FHIRException {
1478        if (name.equals("identifier")) {
1479          return addIdentifier();
1480        }
1481        else if (name.equals("patient")) {
1482          this.patient = new Reference();
1483          return this.patient;
1484        }
1485        else if (name.equals("informationSource")) {
1486          this.informationSource = new Reference();
1487          return this.informationSource;
1488        }
1489        else if (name.equals("dateAsserted")) {
1490          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.dateAsserted");
1491        }
1492        else if (name.equals("status")) {
1493          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.status");
1494        }
1495        else if (name.equals("wasNotTaken")) {
1496          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.wasNotTaken");
1497        }
1498        else if (name.equals("reasonNotTaken")) {
1499          return addReasonNotTaken();
1500        }
1501        else if (name.equals("reasonForUseCodeableConcept")) {
1502          this.reasonForUse = new CodeableConcept();
1503          return this.reasonForUse;
1504        }
1505        else if (name.equals("reasonForUseReference")) {
1506          this.reasonForUse = new Reference();
1507          return this.reasonForUse;
1508        }
1509        else if (name.equals("effectiveDateTime")) {
1510          this.effective = new DateTimeType();
1511          return this.effective;
1512        }
1513        else if (name.equals("effectivePeriod")) {
1514          this.effective = new Period();
1515          return this.effective;
1516        }
1517        else if (name.equals("note")) {
1518          throw new FHIRException("Cannot call addChild on a primitive type MedicationStatement.note");
1519        }
1520        else if (name.equals("supportingInformation")) {
1521          return addSupportingInformation();
1522        }
1523        else if (name.equals("medicationCodeableConcept")) {
1524          this.medication = new CodeableConcept();
1525          return this.medication;
1526        }
1527        else if (name.equals("medicationReference")) {
1528          this.medication = new Reference();
1529          return this.medication;
1530        }
1531        else if (name.equals("dosage")) {
1532          return addDosage();
1533        }
1534        else
1535          return super.addChild(name);
1536      }
1537
1538  public String fhirType() {
1539    return "MedicationStatement";
1540
1541  }
1542
1543      public MedicationStatement copy() {
1544        MedicationStatement dst = new MedicationStatement();
1545        copyValues(dst);
1546        if (identifier != null) {
1547          dst.identifier = new ArrayList<Identifier>();
1548          for (Identifier i : identifier)
1549            dst.identifier.add(i.copy());
1550        };
1551        dst.patient = patient == null ? null : patient.copy();
1552        dst.informationSource = informationSource == null ? null : informationSource.copy();
1553        dst.dateAsserted = dateAsserted == null ? null : dateAsserted.copy();
1554        dst.status = status == null ? null : status.copy();
1555        dst.wasNotTaken = wasNotTaken == null ? null : wasNotTaken.copy();
1556        if (reasonNotTaken != null) {
1557          dst.reasonNotTaken = new ArrayList<CodeableConcept>();
1558          for (CodeableConcept i : reasonNotTaken)
1559            dst.reasonNotTaken.add(i.copy());
1560        };
1561        dst.reasonForUse = reasonForUse == null ? null : reasonForUse.copy();
1562        dst.effective = effective == null ? null : effective.copy();
1563        dst.note = note == null ? null : note.copy();
1564        if (supportingInformation != null) {
1565          dst.supportingInformation = new ArrayList<Reference>();
1566          for (Reference i : supportingInformation)
1567            dst.supportingInformation.add(i.copy());
1568        };
1569        dst.medication = medication == null ? null : medication.copy();
1570        if (dosage != null) {
1571          dst.dosage = new ArrayList<MedicationStatementDosageComponent>();
1572          for (MedicationStatementDosageComponent i : dosage)
1573            dst.dosage.add(i.copy());
1574        };
1575        return dst;
1576      }
1577
1578      protected MedicationStatement typedCopy() {
1579        return copy();
1580      }
1581
1582      @Override
1583      public boolean equalsDeep(Base other) {
1584        if (!super.equalsDeep(other))
1585          return false;
1586        if (!(other instanceof MedicationStatement))
1587          return false;
1588        MedicationStatement o = (MedicationStatement) other;
1589        return compareDeep(identifier, o.identifier, true) && compareDeep(patient, o.patient, true) && compareDeep(informationSource, o.informationSource, true)
1590           && compareDeep(dateAsserted, o.dateAsserted, true) && compareDeep(status, o.status, true) && compareDeep(wasNotTaken, o.wasNotTaken, true)
1591           && compareDeep(reasonNotTaken, o.reasonNotTaken, true) && compareDeep(reasonForUse, o.reasonForUse, true)
1592           && compareDeep(effective, o.effective, true) && compareDeep(note, o.note, true) && compareDeep(supportingInformation, o.supportingInformation, true)
1593           && compareDeep(medication, o.medication, true) && compareDeep(dosage, o.dosage, true);
1594      }
1595
1596      @Override
1597      public boolean equalsShallow(Base other) {
1598        if (!super.equalsShallow(other))
1599          return false;
1600        if (!(other instanceof MedicationStatement))
1601          return false;
1602        MedicationStatement o = (MedicationStatement) other;
1603        return compareValues(dateAsserted, o.dateAsserted, true) && compareValues(status, o.status, true) && compareValues(wasNotTaken, o.wasNotTaken, true)
1604           && compareValues(note, o.note, true);
1605      }
1606
1607      public boolean isEmpty() {
1608        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (patient == null || patient.isEmpty())
1609           && (informationSource == null || informationSource.isEmpty()) && (dateAsserted == null || dateAsserted.isEmpty())
1610           && (status == null || status.isEmpty()) && (wasNotTaken == null || wasNotTaken.isEmpty())
1611           && (reasonNotTaken == null || reasonNotTaken.isEmpty()) && (reasonForUse == null || reasonForUse.isEmpty())
1612           && (effective == null || effective.isEmpty()) && (note == null || note.isEmpty()) && (supportingInformation == null || supportingInformation.isEmpty())
1613           && (medication == null || medication.isEmpty()) && (dosage == null || dosage.isEmpty());
1614      }
1615
1616  @Override
1617  public ResourceType getResourceType() {
1618    return ResourceType.MedicationStatement;
1619   }
1620
1621  @SearchParamDefinition(name="identifier", path="MedicationStatement.identifier", description="Return statements with this external identifier", type="token" )
1622  public static final String SP_IDENTIFIER = "identifier";
1623  @SearchParamDefinition(name="code", path="MedicationStatement.medicationCodeableConcept", description="Return administrations of this medication code", type="token" )
1624  public static final String SP_CODE = "code";
1625  @SearchParamDefinition(name="patient", path="MedicationStatement.patient", description="The identity of a patient to list statements  for", type="reference" )
1626  public static final String SP_PATIENT = "patient";
1627  @SearchParamDefinition(name="medication", path="MedicationStatement.medicationReference", description="Return administrations of this medication reference", type="reference" )
1628  public static final String SP_MEDICATION = "medication";
1629  @SearchParamDefinition(name="source", path="MedicationStatement.informationSource", description="Who the information in the statement came from", type="reference" )
1630  public static final String SP_SOURCE = "source";
1631  @SearchParamDefinition(name="effectivedate", path="MedicationStatement.effective[x]", description="Date when patient was taking (or not taking) the medication", type="date" )
1632  public static final String SP_EFFECTIVEDATE = "effectivedate";
1633  @SearchParamDefinition(name="status", path="MedicationStatement.status", description="Return statements that match the given status", type="token" )
1634  public static final String SP_STATUS = "status";
1635
1636}