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