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 * This resource is primarily used for the identification and definition of a medication. It covers the ingredients and the packaging for a medication.
050 */
051@ResourceDef(name="Medication", profile="http://hl7.org/fhir/Profile/Medication")
052public class Medication extends DomainResource {
053
054    @Block()
055    public static class MedicationProductComponent extends BackboneElement implements IBaseBackboneElement {
056        /**
057         * Describes the form of the item.  Powder; tablets; carton.
058         */
059        @Child(name = "form", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=false)
060        @Description(shortDefinition="powder | tablets | carton +", formalDefinition="Describes the form of the item.  Powder; tablets; carton." )
061        protected CodeableConcept form;
062
063        /**
064         * Identifies a particular constituent of interest in the product.
065         */
066        @Child(name = "ingredient", type = {}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
067        @Description(shortDefinition="Active or inactive ingredient", formalDefinition="Identifies a particular constituent of interest in the product." )
068        protected List<MedicationProductIngredientComponent> ingredient;
069
070        /**
071         * Information about a group of medication produced or packaged from one production run.
072         */
073        @Child(name = "batch", type = {}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
074        @Description(shortDefinition="", formalDefinition="Information about a group of medication produced or packaged from one production run." )
075        protected List<MedicationProductBatchComponent> batch;
076
077        private static final long serialVersionUID = 1132853671L;
078
079    /*
080     * Constructor
081     */
082      public MedicationProductComponent() {
083        super();
084      }
085
086        /**
087         * @return {@link #form} (Describes the form of the item.  Powder; tablets; carton.)
088         */
089        public CodeableConcept getForm() { 
090          if (this.form == null)
091            if (Configuration.errorOnAutoCreate())
092              throw new Error("Attempt to auto-create MedicationProductComponent.form");
093            else if (Configuration.doAutoCreate())
094              this.form = new CodeableConcept(); // cc
095          return this.form;
096        }
097
098        public boolean hasForm() { 
099          return this.form != null && !this.form.isEmpty();
100        }
101
102        /**
103         * @param value {@link #form} (Describes the form of the item.  Powder; tablets; carton.)
104         */
105        public MedicationProductComponent setForm(CodeableConcept value) { 
106          this.form = value;
107          return this;
108        }
109
110        /**
111         * @return {@link #ingredient} (Identifies a particular constituent of interest in the product.)
112         */
113        public List<MedicationProductIngredientComponent> getIngredient() { 
114          if (this.ingredient == null)
115            this.ingredient = new ArrayList<MedicationProductIngredientComponent>();
116          return this.ingredient;
117        }
118
119        public boolean hasIngredient() { 
120          if (this.ingredient == null)
121            return false;
122          for (MedicationProductIngredientComponent item : this.ingredient)
123            if (!item.isEmpty())
124              return true;
125          return false;
126        }
127
128        /**
129         * @return {@link #ingredient} (Identifies a particular constituent of interest in the product.)
130         */
131    // syntactic sugar
132        public MedicationProductIngredientComponent addIngredient() { //3
133          MedicationProductIngredientComponent t = new MedicationProductIngredientComponent();
134          if (this.ingredient == null)
135            this.ingredient = new ArrayList<MedicationProductIngredientComponent>();
136          this.ingredient.add(t);
137          return t;
138        }
139
140    // syntactic sugar
141        public MedicationProductComponent addIngredient(MedicationProductIngredientComponent t) { //3
142          if (t == null)
143            return this;
144          if (this.ingredient == null)
145            this.ingredient = new ArrayList<MedicationProductIngredientComponent>();
146          this.ingredient.add(t);
147          return this;
148        }
149
150        /**
151         * @return {@link #batch} (Information about a group of medication produced or packaged from one production run.)
152         */
153        public List<MedicationProductBatchComponent> getBatch() { 
154          if (this.batch == null)
155            this.batch = new ArrayList<MedicationProductBatchComponent>();
156          return this.batch;
157        }
158
159        public boolean hasBatch() { 
160          if (this.batch == null)
161            return false;
162          for (MedicationProductBatchComponent item : this.batch)
163            if (!item.isEmpty())
164              return true;
165          return false;
166        }
167
168        /**
169         * @return {@link #batch} (Information about a group of medication produced or packaged from one production run.)
170         */
171    // syntactic sugar
172        public MedicationProductBatchComponent addBatch() { //3
173          MedicationProductBatchComponent t = new MedicationProductBatchComponent();
174          if (this.batch == null)
175            this.batch = new ArrayList<MedicationProductBatchComponent>();
176          this.batch.add(t);
177          return t;
178        }
179
180    // syntactic sugar
181        public MedicationProductComponent addBatch(MedicationProductBatchComponent t) { //3
182          if (t == null)
183            return this;
184          if (this.batch == null)
185            this.batch = new ArrayList<MedicationProductBatchComponent>();
186          this.batch.add(t);
187          return this;
188        }
189
190        protected void listChildren(List<Property> childrenList) {
191          super.listChildren(childrenList);
192          childrenList.add(new Property("form", "CodeableConcept", "Describes the form of the item.  Powder; tablets; carton.", 0, java.lang.Integer.MAX_VALUE, form));
193          childrenList.add(new Property("ingredient", "", "Identifies a particular constituent of interest in the product.", 0, java.lang.Integer.MAX_VALUE, ingredient));
194          childrenList.add(new Property("batch", "", "Information about a group of medication produced or packaged from one production run.", 0, java.lang.Integer.MAX_VALUE, batch));
195        }
196
197      @Override
198      public void setProperty(String name, Base value) throws FHIRException {
199        if (name.equals("form"))
200          this.form = castToCodeableConcept(value); // CodeableConcept
201        else if (name.equals("ingredient"))
202          this.getIngredient().add((MedicationProductIngredientComponent) value);
203        else if (name.equals("batch"))
204          this.getBatch().add((MedicationProductBatchComponent) value);
205        else
206          super.setProperty(name, value);
207      }
208
209      @Override
210      public Base addChild(String name) throws FHIRException {
211        if (name.equals("form")) {
212          this.form = new CodeableConcept();
213          return this.form;
214        }
215        else if (name.equals("ingredient")) {
216          return addIngredient();
217        }
218        else if (name.equals("batch")) {
219          return addBatch();
220        }
221        else
222          return super.addChild(name);
223      }
224
225      public MedicationProductComponent copy() {
226        MedicationProductComponent dst = new MedicationProductComponent();
227        copyValues(dst);
228        dst.form = form == null ? null : form.copy();
229        if (ingredient != null) {
230          dst.ingredient = new ArrayList<MedicationProductIngredientComponent>();
231          for (MedicationProductIngredientComponent i : ingredient)
232            dst.ingredient.add(i.copy());
233        };
234        if (batch != null) {
235          dst.batch = new ArrayList<MedicationProductBatchComponent>();
236          for (MedicationProductBatchComponent i : batch)
237            dst.batch.add(i.copy());
238        };
239        return dst;
240      }
241
242      @Override
243      public boolean equalsDeep(Base other) {
244        if (!super.equalsDeep(other))
245          return false;
246        if (!(other instanceof MedicationProductComponent))
247          return false;
248        MedicationProductComponent o = (MedicationProductComponent) other;
249        return compareDeep(form, o.form, true) && compareDeep(ingredient, o.ingredient, true) && compareDeep(batch, o.batch, true)
250          ;
251      }
252
253      @Override
254      public boolean equalsShallow(Base other) {
255        if (!super.equalsShallow(other))
256          return false;
257        if (!(other instanceof MedicationProductComponent))
258          return false;
259        MedicationProductComponent o = (MedicationProductComponent) other;
260        return true;
261      }
262
263      public boolean isEmpty() {
264        return super.isEmpty() && (form == null || form.isEmpty()) && (ingredient == null || ingredient.isEmpty())
265           && (batch == null || batch.isEmpty());
266      }
267
268  public String fhirType() {
269    return "Medication.product";
270
271  }
272
273  }
274
275    @Block()
276    public static class MedicationProductIngredientComponent extends BackboneElement implements IBaseBackboneElement {
277        /**
278         * The actual ingredient - either a substance (simple ingredient) or another medication.
279         */
280        @Child(name = "item", type = {Substance.class, Medication.class}, order=1, min=1, max=1, modifier=false, summary=false)
281        @Description(shortDefinition="The product contained", formalDefinition="The actual ingredient - either a substance (simple ingredient) or another medication." )
282        protected Reference item;
283
284        /**
285         * The actual object that is the target of the reference (The actual ingredient - either a substance (simple ingredient) or another medication.)
286         */
287        protected Resource itemTarget;
288
289        /**
290         * Specifies how many (or how much) of the items there are in this Medication.  For example, 250 mg per tablet.
291         */
292        @Child(name = "amount", type = {Ratio.class}, order=2, min=0, max=1, modifier=false, summary=false)
293        @Description(shortDefinition="Quantity of ingredient present", formalDefinition="Specifies how many (or how much) of the items there are in this Medication.  For example, 250 mg per tablet." )
294        protected Ratio amount;
295
296        private static final long serialVersionUID = -1217232889L;
297
298    /*
299     * Constructor
300     */
301      public MedicationProductIngredientComponent() {
302        super();
303      }
304
305    /*
306     * Constructor
307     */
308      public MedicationProductIngredientComponent(Reference item) {
309        super();
310        this.item = item;
311      }
312
313        /**
314         * @return {@link #item} (The actual ingredient - either a substance (simple ingredient) or another medication.)
315         */
316        public Reference getItem() { 
317          if (this.item == null)
318            if (Configuration.errorOnAutoCreate())
319              throw new Error("Attempt to auto-create MedicationProductIngredientComponent.item");
320            else if (Configuration.doAutoCreate())
321              this.item = new Reference(); // cc
322          return this.item;
323        }
324
325        public boolean hasItem() { 
326          return this.item != null && !this.item.isEmpty();
327        }
328
329        /**
330         * @param value {@link #item} (The actual ingredient - either a substance (simple ingredient) or another medication.)
331         */
332        public MedicationProductIngredientComponent setItem(Reference value) { 
333          this.item = value;
334          return this;
335        }
336
337        /**
338         * @return {@link #item} 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 actual ingredient - either a substance (simple ingredient) or another medication.)
339         */
340        public Resource getItemTarget() { 
341          return this.itemTarget;
342        }
343
344        /**
345         * @param value {@link #item} 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 actual ingredient - either a substance (simple ingredient) or another medication.)
346         */
347        public MedicationProductIngredientComponent setItemTarget(Resource value) { 
348          this.itemTarget = value;
349          return this;
350        }
351
352        /**
353         * @return {@link #amount} (Specifies how many (or how much) of the items there are in this Medication.  For example, 250 mg per tablet.)
354         */
355        public Ratio getAmount() { 
356          if (this.amount == null)
357            if (Configuration.errorOnAutoCreate())
358              throw new Error("Attempt to auto-create MedicationProductIngredientComponent.amount");
359            else if (Configuration.doAutoCreate())
360              this.amount = new Ratio(); // cc
361          return this.amount;
362        }
363
364        public boolean hasAmount() { 
365          return this.amount != null && !this.amount.isEmpty();
366        }
367
368        /**
369         * @param value {@link #amount} (Specifies how many (or how much) of the items there are in this Medication.  For example, 250 mg per tablet.)
370         */
371        public MedicationProductIngredientComponent setAmount(Ratio value) { 
372          this.amount = value;
373          return this;
374        }
375
376        protected void listChildren(List<Property> childrenList) {
377          super.listChildren(childrenList);
378          childrenList.add(new Property("item", "Reference(Substance|Medication)", "The actual ingredient - either a substance (simple ingredient) or another medication.", 0, java.lang.Integer.MAX_VALUE, item));
379          childrenList.add(new Property("amount", "Ratio", "Specifies how many (or how much) of the items there are in this Medication.  For example, 250 mg per tablet.", 0, java.lang.Integer.MAX_VALUE, amount));
380        }
381
382      @Override
383      public void setProperty(String name, Base value) throws FHIRException {
384        if (name.equals("item"))
385          this.item = castToReference(value); // Reference
386        else if (name.equals("amount"))
387          this.amount = castToRatio(value); // Ratio
388        else
389          super.setProperty(name, value);
390      }
391
392      @Override
393      public Base addChild(String name) throws FHIRException {
394        if (name.equals("item")) {
395          this.item = new Reference();
396          return this.item;
397        }
398        else if (name.equals("amount")) {
399          this.amount = new Ratio();
400          return this.amount;
401        }
402        else
403          return super.addChild(name);
404      }
405
406      public MedicationProductIngredientComponent copy() {
407        MedicationProductIngredientComponent dst = new MedicationProductIngredientComponent();
408        copyValues(dst);
409        dst.item = item == null ? null : item.copy();
410        dst.amount = amount == null ? null : amount.copy();
411        return dst;
412      }
413
414      @Override
415      public boolean equalsDeep(Base other) {
416        if (!super.equalsDeep(other))
417          return false;
418        if (!(other instanceof MedicationProductIngredientComponent))
419          return false;
420        MedicationProductIngredientComponent o = (MedicationProductIngredientComponent) other;
421        return compareDeep(item, o.item, true) && compareDeep(amount, o.amount, true);
422      }
423
424      @Override
425      public boolean equalsShallow(Base other) {
426        if (!super.equalsShallow(other))
427          return false;
428        if (!(other instanceof MedicationProductIngredientComponent))
429          return false;
430        MedicationProductIngredientComponent o = (MedicationProductIngredientComponent) other;
431        return true;
432      }
433
434      public boolean isEmpty() {
435        return super.isEmpty() && (item == null || item.isEmpty()) && (amount == null || amount.isEmpty())
436          ;
437      }
438
439  public String fhirType() {
440    return "Medication.product.ingredient";
441
442  }
443
444  }
445
446    @Block()
447    public static class MedicationProductBatchComponent extends BackboneElement implements IBaseBackboneElement {
448        /**
449         * The assigned lot number of a batch of the specified product.
450         */
451        @Child(name = "lotNumber", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=false)
452        @Description(shortDefinition="", formalDefinition="The assigned lot number of a batch of the specified product." )
453        protected StringType lotNumber;
454
455        /**
456         * When this specific batch of product will expire.
457         */
458        @Child(name = "expirationDate", type = {DateTimeType.class}, order=2, min=0, max=1, modifier=false, summary=false)
459        @Description(shortDefinition="", formalDefinition="When this specific batch of product will expire." )
460        protected DateTimeType expirationDate;
461
462        private static final long serialVersionUID = 1982738755L;
463
464    /*
465     * Constructor
466     */
467      public MedicationProductBatchComponent() {
468        super();
469      }
470
471        /**
472         * @return {@link #lotNumber} (The assigned lot number of a batch of the specified product.). This is the underlying object with id, value and extensions. The accessor "getLotNumber" gives direct access to the value
473         */
474        public StringType getLotNumberElement() { 
475          if (this.lotNumber == null)
476            if (Configuration.errorOnAutoCreate())
477              throw new Error("Attempt to auto-create MedicationProductBatchComponent.lotNumber");
478            else if (Configuration.doAutoCreate())
479              this.lotNumber = new StringType(); // bb
480          return this.lotNumber;
481        }
482
483        public boolean hasLotNumberElement() { 
484          return this.lotNumber != null && !this.lotNumber.isEmpty();
485        }
486
487        public boolean hasLotNumber() { 
488          return this.lotNumber != null && !this.lotNumber.isEmpty();
489        }
490
491        /**
492         * @param value {@link #lotNumber} (The assigned lot number of a batch of the specified product.). This is the underlying object with id, value and extensions. The accessor "getLotNumber" gives direct access to the value
493         */
494        public MedicationProductBatchComponent setLotNumberElement(StringType value) { 
495          this.lotNumber = value;
496          return this;
497        }
498
499        /**
500         * @return The assigned lot number of a batch of the specified product.
501         */
502        public String getLotNumber() { 
503          return this.lotNumber == null ? null : this.lotNumber.getValue();
504        }
505
506        /**
507         * @param value The assigned lot number of a batch of the specified product.
508         */
509        public MedicationProductBatchComponent setLotNumber(String value) { 
510          if (Utilities.noString(value))
511            this.lotNumber = null;
512          else {
513            if (this.lotNumber == null)
514              this.lotNumber = new StringType();
515            this.lotNumber.setValue(value);
516          }
517          return this;
518        }
519
520        /**
521         * @return {@link #expirationDate} (When this specific batch of product will expire.). This is the underlying object with id, value and extensions. The accessor "getExpirationDate" gives direct access to the value
522         */
523        public DateTimeType getExpirationDateElement() { 
524          if (this.expirationDate == null)
525            if (Configuration.errorOnAutoCreate())
526              throw new Error("Attempt to auto-create MedicationProductBatchComponent.expirationDate");
527            else if (Configuration.doAutoCreate())
528              this.expirationDate = new DateTimeType(); // bb
529          return this.expirationDate;
530        }
531
532        public boolean hasExpirationDateElement() { 
533          return this.expirationDate != null && !this.expirationDate.isEmpty();
534        }
535
536        public boolean hasExpirationDate() { 
537          return this.expirationDate != null && !this.expirationDate.isEmpty();
538        }
539
540        /**
541         * @param value {@link #expirationDate} (When this specific batch of product will expire.). This is the underlying object with id, value and extensions. The accessor "getExpirationDate" gives direct access to the value
542         */
543        public MedicationProductBatchComponent setExpirationDateElement(DateTimeType value) { 
544          this.expirationDate = value;
545          return this;
546        }
547
548        /**
549         * @return When this specific batch of product will expire.
550         */
551        public Date getExpirationDate() { 
552          return this.expirationDate == null ? null : this.expirationDate.getValue();
553        }
554
555        /**
556         * @param value When this specific batch of product will expire.
557         */
558        public MedicationProductBatchComponent setExpirationDate(Date value) { 
559          if (value == null)
560            this.expirationDate = null;
561          else {
562            if (this.expirationDate == null)
563              this.expirationDate = new DateTimeType();
564            this.expirationDate.setValue(value);
565          }
566          return this;
567        }
568
569        protected void listChildren(List<Property> childrenList) {
570          super.listChildren(childrenList);
571          childrenList.add(new Property("lotNumber", "string", "The assigned lot number of a batch of the specified product.", 0, java.lang.Integer.MAX_VALUE, lotNumber));
572          childrenList.add(new Property("expirationDate", "dateTime", "When this specific batch of product will expire.", 0, java.lang.Integer.MAX_VALUE, expirationDate));
573        }
574
575      @Override
576      public void setProperty(String name, Base value) throws FHIRException {
577        if (name.equals("lotNumber"))
578          this.lotNumber = castToString(value); // StringType
579        else if (name.equals("expirationDate"))
580          this.expirationDate = castToDateTime(value); // DateTimeType
581        else
582          super.setProperty(name, value);
583      }
584
585      @Override
586      public Base addChild(String name) throws FHIRException {
587        if (name.equals("lotNumber")) {
588          throw new FHIRException("Cannot call addChild on a primitive type Medication.lotNumber");
589        }
590        else if (name.equals("expirationDate")) {
591          throw new FHIRException("Cannot call addChild on a primitive type Medication.expirationDate");
592        }
593        else
594          return super.addChild(name);
595      }
596
597      public MedicationProductBatchComponent copy() {
598        MedicationProductBatchComponent dst = new MedicationProductBatchComponent();
599        copyValues(dst);
600        dst.lotNumber = lotNumber == null ? null : lotNumber.copy();
601        dst.expirationDate = expirationDate == null ? null : expirationDate.copy();
602        return dst;
603      }
604
605      @Override
606      public boolean equalsDeep(Base other) {
607        if (!super.equalsDeep(other))
608          return false;
609        if (!(other instanceof MedicationProductBatchComponent))
610          return false;
611        MedicationProductBatchComponent o = (MedicationProductBatchComponent) other;
612        return compareDeep(lotNumber, o.lotNumber, true) && compareDeep(expirationDate, o.expirationDate, true)
613          ;
614      }
615
616      @Override
617      public boolean equalsShallow(Base other) {
618        if (!super.equalsShallow(other))
619          return false;
620        if (!(other instanceof MedicationProductBatchComponent))
621          return false;
622        MedicationProductBatchComponent o = (MedicationProductBatchComponent) other;
623        return compareValues(lotNumber, o.lotNumber, true) && compareValues(expirationDate, o.expirationDate, true)
624          ;
625      }
626
627      public boolean isEmpty() {
628        return super.isEmpty() && (lotNumber == null || lotNumber.isEmpty()) && (expirationDate == null || expirationDate.isEmpty())
629          ;
630      }
631
632  public String fhirType() {
633    return "Medication.product.batch";
634
635  }
636
637  }
638
639    @Block()
640    public static class MedicationPackageComponent extends BackboneElement implements IBaseBackboneElement {
641        /**
642         * The kind of container that this package comes as.
643         */
644        @Child(name = "container", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=false)
645        @Description(shortDefinition="E.g. box, vial, blister-pack", formalDefinition="The kind of container that this package comes as." )
646        protected CodeableConcept container;
647
648        /**
649         * A set of components that go to make up the described item.
650         */
651        @Child(name = "content", type = {}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
652        @Description(shortDefinition="What is  in the package", formalDefinition="A set of components that go to make up the described item." )
653        protected List<MedicationPackageContentComponent> content;
654
655        private static final long serialVersionUID = 503772472L;
656
657    /*
658     * Constructor
659     */
660      public MedicationPackageComponent() {
661        super();
662      }
663
664        /**
665         * @return {@link #container} (The kind of container that this package comes as.)
666         */
667        public CodeableConcept getContainer() { 
668          if (this.container == null)
669            if (Configuration.errorOnAutoCreate())
670              throw new Error("Attempt to auto-create MedicationPackageComponent.container");
671            else if (Configuration.doAutoCreate())
672              this.container = new CodeableConcept(); // cc
673          return this.container;
674        }
675
676        public boolean hasContainer() { 
677          return this.container != null && !this.container.isEmpty();
678        }
679
680        /**
681         * @param value {@link #container} (The kind of container that this package comes as.)
682         */
683        public MedicationPackageComponent setContainer(CodeableConcept value) { 
684          this.container = value;
685          return this;
686        }
687
688        /**
689         * @return {@link #content} (A set of components that go to make up the described item.)
690         */
691        public List<MedicationPackageContentComponent> getContent() { 
692          if (this.content == null)
693            this.content = new ArrayList<MedicationPackageContentComponent>();
694          return this.content;
695        }
696
697        public boolean hasContent() { 
698          if (this.content == null)
699            return false;
700          for (MedicationPackageContentComponent item : this.content)
701            if (!item.isEmpty())
702              return true;
703          return false;
704        }
705
706        /**
707         * @return {@link #content} (A set of components that go to make up the described item.)
708         */
709    // syntactic sugar
710        public MedicationPackageContentComponent addContent() { //3
711          MedicationPackageContentComponent t = new MedicationPackageContentComponent();
712          if (this.content == null)
713            this.content = new ArrayList<MedicationPackageContentComponent>();
714          this.content.add(t);
715          return t;
716        }
717
718    // syntactic sugar
719        public MedicationPackageComponent addContent(MedicationPackageContentComponent t) { //3
720          if (t == null)
721            return this;
722          if (this.content == null)
723            this.content = new ArrayList<MedicationPackageContentComponent>();
724          this.content.add(t);
725          return this;
726        }
727
728        protected void listChildren(List<Property> childrenList) {
729          super.listChildren(childrenList);
730          childrenList.add(new Property("container", "CodeableConcept", "The kind of container that this package comes as.", 0, java.lang.Integer.MAX_VALUE, container));
731          childrenList.add(new Property("content", "", "A set of components that go to make up the described item.", 0, java.lang.Integer.MAX_VALUE, content));
732        }
733
734      @Override
735      public void setProperty(String name, Base value) throws FHIRException {
736        if (name.equals("container"))
737          this.container = castToCodeableConcept(value); // CodeableConcept
738        else if (name.equals("content"))
739          this.getContent().add((MedicationPackageContentComponent) value);
740        else
741          super.setProperty(name, value);
742      }
743
744      @Override
745      public Base addChild(String name) throws FHIRException {
746        if (name.equals("container")) {
747          this.container = new CodeableConcept();
748          return this.container;
749        }
750        else if (name.equals("content")) {
751          return addContent();
752        }
753        else
754          return super.addChild(name);
755      }
756
757      public MedicationPackageComponent copy() {
758        MedicationPackageComponent dst = new MedicationPackageComponent();
759        copyValues(dst);
760        dst.container = container == null ? null : container.copy();
761        if (content != null) {
762          dst.content = new ArrayList<MedicationPackageContentComponent>();
763          for (MedicationPackageContentComponent i : content)
764            dst.content.add(i.copy());
765        };
766        return dst;
767      }
768
769      @Override
770      public boolean equalsDeep(Base other) {
771        if (!super.equalsDeep(other))
772          return false;
773        if (!(other instanceof MedicationPackageComponent))
774          return false;
775        MedicationPackageComponent o = (MedicationPackageComponent) other;
776        return compareDeep(container, o.container, true) && compareDeep(content, o.content, true);
777      }
778
779      @Override
780      public boolean equalsShallow(Base other) {
781        if (!super.equalsShallow(other))
782          return false;
783        if (!(other instanceof MedicationPackageComponent))
784          return false;
785        MedicationPackageComponent o = (MedicationPackageComponent) other;
786        return true;
787      }
788
789      public boolean isEmpty() {
790        return super.isEmpty() && (container == null || container.isEmpty()) && (content == null || content.isEmpty())
791          ;
792      }
793
794  public String fhirType() {
795    return "Medication.package";
796
797  }
798
799  }
800
801    @Block()
802    public static class MedicationPackageContentComponent extends BackboneElement implements IBaseBackboneElement {
803        /**
804         * Identifies one of the items in the package.
805         */
806        @Child(name = "item", type = {Medication.class}, order=1, min=1, max=1, modifier=false, summary=false)
807        @Description(shortDefinition="A product in the package", formalDefinition="Identifies one of the items in the package." )
808        protected Reference item;
809
810        /**
811         * The actual object that is the target of the reference (Identifies one of the items in the package.)
812         */
813        protected Medication itemTarget;
814
815        /**
816         * The amount of the product that is in the package.
817         */
818        @Child(name = "amount", type = {SimpleQuantity.class}, order=2, min=0, max=1, modifier=false, summary=false)
819        @Description(shortDefinition="Quantity present in the package", formalDefinition="The amount of the product that is in the package." )
820        protected SimpleQuantity amount;
821
822        private static final long serialVersionUID = -1150048030L;
823
824    /*
825     * Constructor
826     */
827      public MedicationPackageContentComponent() {
828        super();
829      }
830
831    /*
832     * Constructor
833     */
834      public MedicationPackageContentComponent(Reference item) {
835        super();
836        this.item = item;
837      }
838
839        /**
840         * @return {@link #item} (Identifies one of the items in the package.)
841         */
842        public Reference getItem() { 
843          if (this.item == null)
844            if (Configuration.errorOnAutoCreate())
845              throw new Error("Attempt to auto-create MedicationPackageContentComponent.item");
846            else if (Configuration.doAutoCreate())
847              this.item = new Reference(); // cc
848          return this.item;
849        }
850
851        public boolean hasItem() { 
852          return this.item != null && !this.item.isEmpty();
853        }
854
855        /**
856         * @param value {@link #item} (Identifies one of the items in the package.)
857         */
858        public MedicationPackageContentComponent setItem(Reference value) { 
859          this.item = value;
860          return this;
861        }
862
863        /**
864         * @return {@link #item} 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. (Identifies one of the items in the package.)
865         */
866        public Medication getItemTarget() { 
867          if (this.itemTarget == null)
868            if (Configuration.errorOnAutoCreate())
869              throw new Error("Attempt to auto-create MedicationPackageContentComponent.item");
870            else if (Configuration.doAutoCreate())
871              this.itemTarget = new Medication(); // aa
872          return this.itemTarget;
873        }
874
875        /**
876         * @param value {@link #item} 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. (Identifies one of the items in the package.)
877         */
878        public MedicationPackageContentComponent setItemTarget(Medication value) { 
879          this.itemTarget = value;
880          return this;
881        }
882
883        /**
884         * @return {@link #amount} (The amount of the product that is in the package.)
885         */
886        public SimpleQuantity getAmount() { 
887          if (this.amount == null)
888            if (Configuration.errorOnAutoCreate())
889              throw new Error("Attempt to auto-create MedicationPackageContentComponent.amount");
890            else if (Configuration.doAutoCreate())
891              this.amount = new SimpleQuantity(); // cc
892          return this.amount;
893        }
894
895        public boolean hasAmount() { 
896          return this.amount != null && !this.amount.isEmpty();
897        }
898
899        /**
900         * @param value {@link #amount} (The amount of the product that is in the package.)
901         */
902        public MedicationPackageContentComponent setAmount(SimpleQuantity value) { 
903          this.amount = value;
904          return this;
905        }
906
907        protected void listChildren(List<Property> childrenList) {
908          super.listChildren(childrenList);
909          childrenList.add(new Property("item", "Reference(Medication)", "Identifies one of the items in the package.", 0, java.lang.Integer.MAX_VALUE, item));
910          childrenList.add(new Property("amount", "SimpleQuantity", "The amount of the product that is in the package.", 0, java.lang.Integer.MAX_VALUE, amount));
911        }
912
913      @Override
914      public void setProperty(String name, Base value) throws FHIRException {
915        if (name.equals("item"))
916          this.item = castToReference(value); // Reference
917        else if (name.equals("amount"))
918          this.amount = castToSimpleQuantity(value); // SimpleQuantity
919        else
920          super.setProperty(name, value);
921      }
922
923      @Override
924      public Base addChild(String name) throws FHIRException {
925        if (name.equals("item")) {
926          this.item = new Reference();
927          return this.item;
928        }
929        else if (name.equals("amount")) {
930          this.amount = new SimpleQuantity();
931          return this.amount;
932        }
933        else
934          return super.addChild(name);
935      }
936
937      public MedicationPackageContentComponent copy() {
938        MedicationPackageContentComponent dst = new MedicationPackageContentComponent();
939        copyValues(dst);
940        dst.item = item == null ? null : item.copy();
941        dst.amount = amount == null ? null : amount.copy();
942        return dst;
943      }
944
945      @Override
946      public boolean equalsDeep(Base other) {
947        if (!super.equalsDeep(other))
948          return false;
949        if (!(other instanceof MedicationPackageContentComponent))
950          return false;
951        MedicationPackageContentComponent o = (MedicationPackageContentComponent) other;
952        return compareDeep(item, o.item, true) && compareDeep(amount, o.amount, true);
953      }
954
955      @Override
956      public boolean equalsShallow(Base other) {
957        if (!super.equalsShallow(other))
958          return false;
959        if (!(other instanceof MedicationPackageContentComponent))
960          return false;
961        MedicationPackageContentComponent o = (MedicationPackageContentComponent) other;
962        return true;
963      }
964
965      public boolean isEmpty() {
966        return super.isEmpty() && (item == null || item.isEmpty()) && (amount == null || amount.isEmpty())
967          ;
968      }
969
970  public String fhirType() {
971    return "Medication.package.content";
972
973  }
974
975  }
976
977    /**
978     * A code (or set of codes) that specify this medication, or a textual description if no code is available. Usage note: This could be a standard medication code such as a code from RxNorm, SNOMED CT, IDMP etc. It could also be a national or local formulary code, optionally with translations to other code systems.
979     */
980    @Child(name = "code", type = {CodeableConcept.class}, order=0, min=0, max=1, modifier=false, summary=true)
981    @Description(shortDefinition="Codes that identify this medication", formalDefinition="A code (or set of codes) that specify this medication, or a textual description if no code is available. Usage note: This could be a standard medication code such as a code from RxNorm, SNOMED CT, IDMP etc. It could also be a national or local formulary code, optionally with translations to other code systems." )
982    protected CodeableConcept code;
983
984    /**
985     * Set to true if the item is attributable to a specific manufacturer.
986     */
987    @Child(name = "isBrand", type = {BooleanType.class}, order=1, min=0, max=1, modifier=false, summary=true)
988    @Description(shortDefinition="True if a brand", formalDefinition="Set to true if the item is attributable to a specific manufacturer." )
989    protected BooleanType isBrand;
990
991    /**
992     * Describes the details of the manufacturer.
993     */
994    @Child(name = "manufacturer", type = {Organization.class}, order=2, min=0, max=1, modifier=false, summary=true)
995    @Description(shortDefinition="Manufacturer of the item", formalDefinition="Describes the details of the manufacturer." )
996    protected Reference manufacturer;
997
998    /**
999     * The actual object that is the target of the reference (Describes the details of the manufacturer.)
1000     */
1001    protected Organization manufacturerTarget;
1002
1003    /**
1004     * Information that only applies to products (not packages).
1005     */
1006    @Child(name = "product", type = {}, order=3, min=0, max=1, modifier=false, summary=false)
1007    @Description(shortDefinition="Administrable medication details", formalDefinition="Information that only applies to products (not packages)." )
1008    protected MedicationProductComponent product;
1009
1010    /**
1011     * Information that only applies to packages (not products).
1012     */
1013    @Child(name = "package", type = {}, order=4, min=0, max=1, modifier=false, summary=false)
1014    @Description(shortDefinition="Details about packaged medications", formalDefinition="Information that only applies to packages (not products)." )
1015    protected MedicationPackageComponent package_;
1016
1017    private static final long serialVersionUID = 859308699L;
1018
1019  /*
1020   * Constructor
1021   */
1022    public Medication() {
1023      super();
1024    }
1025
1026    /**
1027     * @return {@link #code} (A code (or set of codes) that specify this medication, or a textual description if no code is available. Usage note: This could be a standard medication code such as a code from RxNorm, SNOMED CT, IDMP etc. It could also be a national or local formulary code, optionally with translations to other code systems.)
1028     */
1029    public CodeableConcept getCode() { 
1030      if (this.code == null)
1031        if (Configuration.errorOnAutoCreate())
1032          throw new Error("Attempt to auto-create Medication.code");
1033        else if (Configuration.doAutoCreate())
1034          this.code = new CodeableConcept(); // cc
1035      return this.code;
1036    }
1037
1038    public boolean hasCode() { 
1039      return this.code != null && !this.code.isEmpty();
1040    }
1041
1042    /**
1043     * @param value {@link #code} (A code (or set of codes) that specify this medication, or a textual description if no code is available. Usage note: This could be a standard medication code such as a code from RxNorm, SNOMED CT, IDMP etc. It could also be a national or local formulary code, optionally with translations to other code systems.)
1044     */
1045    public Medication setCode(CodeableConcept value) { 
1046      this.code = value;
1047      return this;
1048    }
1049
1050    /**
1051     * @return {@link #isBrand} (Set to true if the item is attributable to a specific manufacturer.). This is the underlying object with id, value and extensions. The accessor "getIsBrand" gives direct access to the value
1052     */
1053    public BooleanType getIsBrandElement() { 
1054      if (this.isBrand == null)
1055        if (Configuration.errorOnAutoCreate())
1056          throw new Error("Attempt to auto-create Medication.isBrand");
1057        else if (Configuration.doAutoCreate())
1058          this.isBrand = new BooleanType(); // bb
1059      return this.isBrand;
1060    }
1061
1062    public boolean hasIsBrandElement() { 
1063      return this.isBrand != null && !this.isBrand.isEmpty();
1064    }
1065
1066    public boolean hasIsBrand() { 
1067      return this.isBrand != null && !this.isBrand.isEmpty();
1068    }
1069
1070    /**
1071     * @param value {@link #isBrand} (Set to true if the item is attributable to a specific manufacturer.). This is the underlying object with id, value and extensions. The accessor "getIsBrand" gives direct access to the value
1072     */
1073    public Medication setIsBrandElement(BooleanType value) { 
1074      this.isBrand = value;
1075      return this;
1076    }
1077
1078    /**
1079     * @return Set to true if the item is attributable to a specific manufacturer.
1080     */
1081    public boolean getIsBrand() { 
1082      return this.isBrand == null || this.isBrand.isEmpty() ? false : this.isBrand.getValue();
1083    }
1084
1085    /**
1086     * @param value Set to true if the item is attributable to a specific manufacturer.
1087     */
1088    public Medication setIsBrand(boolean value) { 
1089        if (this.isBrand == null)
1090          this.isBrand = new BooleanType();
1091        this.isBrand.setValue(value);
1092      return this;
1093    }
1094
1095    /**
1096     * @return {@link #manufacturer} (Describes the details of the manufacturer.)
1097     */
1098    public Reference getManufacturer() { 
1099      if (this.manufacturer == null)
1100        if (Configuration.errorOnAutoCreate())
1101          throw new Error("Attempt to auto-create Medication.manufacturer");
1102        else if (Configuration.doAutoCreate())
1103          this.manufacturer = new Reference(); // cc
1104      return this.manufacturer;
1105    }
1106
1107    public boolean hasManufacturer() { 
1108      return this.manufacturer != null && !this.manufacturer.isEmpty();
1109    }
1110
1111    /**
1112     * @param value {@link #manufacturer} (Describes the details of the manufacturer.)
1113     */
1114    public Medication setManufacturer(Reference value) { 
1115      this.manufacturer = value;
1116      return this;
1117    }
1118
1119    /**
1120     * @return {@link #manufacturer} 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. (Describes the details of the manufacturer.)
1121     */
1122    public Organization getManufacturerTarget() { 
1123      if (this.manufacturerTarget == null)
1124        if (Configuration.errorOnAutoCreate())
1125          throw new Error("Attempt to auto-create Medication.manufacturer");
1126        else if (Configuration.doAutoCreate())
1127          this.manufacturerTarget = new Organization(); // aa
1128      return this.manufacturerTarget;
1129    }
1130
1131    /**
1132     * @param value {@link #manufacturer} 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. (Describes the details of the manufacturer.)
1133     */
1134    public Medication setManufacturerTarget(Organization value) { 
1135      this.manufacturerTarget = value;
1136      return this;
1137    }
1138
1139    /**
1140     * @return {@link #product} (Information that only applies to products (not packages).)
1141     */
1142    public MedicationProductComponent getProduct() { 
1143      if (this.product == null)
1144        if (Configuration.errorOnAutoCreate())
1145          throw new Error("Attempt to auto-create Medication.product");
1146        else if (Configuration.doAutoCreate())
1147          this.product = new MedicationProductComponent(); // cc
1148      return this.product;
1149    }
1150
1151    public boolean hasProduct() { 
1152      return this.product != null && !this.product.isEmpty();
1153    }
1154
1155    /**
1156     * @param value {@link #product} (Information that only applies to products (not packages).)
1157     */
1158    public Medication setProduct(MedicationProductComponent value) { 
1159      this.product = value;
1160      return this;
1161    }
1162
1163    /**
1164     * @return {@link #package_} (Information that only applies to packages (not products).)
1165     */
1166    public MedicationPackageComponent getPackage() { 
1167      if (this.package_ == null)
1168        if (Configuration.errorOnAutoCreate())
1169          throw new Error("Attempt to auto-create Medication.package_");
1170        else if (Configuration.doAutoCreate())
1171          this.package_ = new MedicationPackageComponent(); // cc
1172      return this.package_;
1173    }
1174
1175    public boolean hasPackage() { 
1176      return this.package_ != null && !this.package_.isEmpty();
1177    }
1178
1179    /**
1180     * @param value {@link #package_} (Information that only applies to packages (not products).)
1181     */
1182    public Medication setPackage(MedicationPackageComponent value) { 
1183      this.package_ = value;
1184      return this;
1185    }
1186
1187      protected void listChildren(List<Property> childrenList) {
1188        super.listChildren(childrenList);
1189        childrenList.add(new Property("code", "CodeableConcept", "A code (or set of codes) that specify this medication, or a textual description if no code is available. Usage note: This could be a standard medication code such as a code from RxNorm, SNOMED CT, IDMP etc. It could also be a national or local formulary code, optionally with translations to other code systems.", 0, java.lang.Integer.MAX_VALUE, code));
1190        childrenList.add(new Property("isBrand", "boolean", "Set to true if the item is attributable to a specific manufacturer.", 0, java.lang.Integer.MAX_VALUE, isBrand));
1191        childrenList.add(new Property("manufacturer", "Reference(Organization)", "Describes the details of the manufacturer.", 0, java.lang.Integer.MAX_VALUE, manufacturer));
1192        childrenList.add(new Property("product", "", "Information that only applies to products (not packages).", 0, java.lang.Integer.MAX_VALUE, product));
1193        childrenList.add(new Property("package", "", "Information that only applies to packages (not products).", 0, java.lang.Integer.MAX_VALUE, package_));
1194      }
1195
1196      @Override
1197      public void setProperty(String name, Base value) throws FHIRException {
1198        if (name.equals("code"))
1199          this.code = castToCodeableConcept(value); // CodeableConcept
1200        else if (name.equals("isBrand"))
1201          this.isBrand = castToBoolean(value); // BooleanType
1202        else if (name.equals("manufacturer"))
1203          this.manufacturer = castToReference(value); // Reference
1204        else if (name.equals("product"))
1205          this.product = (MedicationProductComponent) value; // MedicationProductComponent
1206        else if (name.equals("package"))
1207          this.package_ = (MedicationPackageComponent) value; // MedicationPackageComponent
1208        else
1209          super.setProperty(name, value);
1210      }
1211
1212      @Override
1213      public Base addChild(String name) throws FHIRException {
1214        if (name.equals("code")) {
1215          this.code = new CodeableConcept();
1216          return this.code;
1217        }
1218        else if (name.equals("isBrand")) {
1219          throw new FHIRException("Cannot call addChild on a primitive type Medication.isBrand");
1220        }
1221        else if (name.equals("manufacturer")) {
1222          this.manufacturer = new Reference();
1223          return this.manufacturer;
1224        }
1225        else if (name.equals("product")) {
1226          this.product = new MedicationProductComponent();
1227          return this.product;
1228        }
1229        else if (name.equals("package")) {
1230          this.package_ = new MedicationPackageComponent();
1231          return this.package_;
1232        }
1233        else
1234          return super.addChild(name);
1235      }
1236
1237  public String fhirType() {
1238    return "Medication";
1239
1240  }
1241
1242      public Medication copy() {
1243        Medication dst = new Medication();
1244        copyValues(dst);
1245        dst.code = code == null ? null : code.copy();
1246        dst.isBrand = isBrand == null ? null : isBrand.copy();
1247        dst.manufacturer = manufacturer == null ? null : manufacturer.copy();
1248        dst.product = product == null ? null : product.copy();
1249        dst.package_ = package_ == null ? null : package_.copy();
1250        return dst;
1251      }
1252
1253      protected Medication typedCopy() {
1254        return copy();
1255      }
1256
1257      @Override
1258      public boolean equalsDeep(Base other) {
1259        if (!super.equalsDeep(other))
1260          return false;
1261        if (!(other instanceof Medication))
1262          return false;
1263        Medication o = (Medication) other;
1264        return compareDeep(code, o.code, true) && compareDeep(isBrand, o.isBrand, true) && compareDeep(manufacturer, o.manufacturer, true)
1265           && compareDeep(product, o.product, true) && compareDeep(package_, o.package_, true);
1266      }
1267
1268      @Override
1269      public boolean equalsShallow(Base other) {
1270        if (!super.equalsShallow(other))
1271          return false;
1272        if (!(other instanceof Medication))
1273          return false;
1274        Medication o = (Medication) other;
1275        return compareValues(isBrand, o.isBrand, true);
1276      }
1277
1278      public boolean isEmpty() {
1279        return super.isEmpty() && (code == null || code.isEmpty()) && (isBrand == null || isBrand.isEmpty())
1280           && (manufacturer == null || manufacturer.isEmpty()) && (product == null || product.isEmpty())
1281           && (package_ == null || package_.isEmpty());
1282      }
1283
1284  @Override
1285  public ResourceType getResourceType() {
1286    return ResourceType.Medication;
1287   }
1288
1289  @SearchParamDefinition(name="container", path="Medication.package.container", description="E.g. box, vial, blister-pack", type="token" )
1290  public static final String SP_CONTAINER = "container";
1291  @SearchParamDefinition(name="code", path="Medication.code", description="Codes that identify this medication", type="token" )
1292  public static final String SP_CODE = "code";
1293  @SearchParamDefinition(name="ingredient", path="Medication.product.ingredient.item", description="The product contained", type="reference" )
1294  public static final String SP_INGREDIENT = "ingredient";
1295  @SearchParamDefinition(name="form", path="Medication.product.form", description="powder | tablets | carton +", type="token" )
1296  public static final String SP_FORM = "form";
1297  @SearchParamDefinition(name="content", path="Medication.package.content.item", description="A product in the package", type="reference" )
1298  public static final String SP_CONTENT = "content";
1299  @SearchParamDefinition(name="manufacturer", path="Medication.manufacturer", description="Manufacturer of the item", type="reference" )
1300  public static final String SP_MANUFACTURER = "manufacturer";
1301
1302}