001package org.hl7.fhir.dstu2.model;
002
003
004
005
006import java.math.BigDecimal;
007
008/*
009  Copyright (c) 2011+, HL7, Inc.
010  All rights reserved.
011  
012  Redistribution and use in source and binary forms, with or without modification, 
013  are permitted provided that the following conditions are met:
014  
015   * Redistributions of source code must retain the above copyright notice, this 
016     list of conditions and the following disclaimer.
017   * Redistributions in binary form must reproduce the above copyright notice, 
018     this list of conditions and the following disclaimer in the documentation 
019     and/or other materials provided with the distribution.
020   * Neither the name of HL7 nor the names of its contributors may be used to 
021     endorse or promote products derived from this software without specific 
022     prior written permission.
023  
024  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
025  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
026  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
027  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
028  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
029  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
030  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
031  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
032  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
033  POSSIBILITY OF SUCH DAMAGE.
034  
035*/
036
037// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
038import java.util.ArrayList;
039import java.util.Date;
040import java.util.List;
041
042import ca.uhn.fhir.model.api.annotation.Block;
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.Description;
045import ca.uhn.fhir.model.api.annotation.ResourceDef;
046import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
047import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
048import org.hl7.fhir.exceptions.FHIRException;
049import org.hl7.fhir.utilities.Utilities;
050/**
051 * An authorization for the supply of glasses and/or contact lenses to a patient.
052 */
053@ResourceDef(name="VisionPrescription", profile="http://hl7.org/fhir/Profile/VisionPrescription")
054public class VisionPrescription extends DomainResource {
055
056    public enum VisionEyes {
057        /**
058         * Right Eye
059         */
060        RIGHT, 
061        /**
062         * Left Eye
063         */
064        LEFT, 
065        /**
066         * added to help the parsers
067         */
068        NULL;
069        public static VisionEyes fromCode(String codeString) throws FHIRException {
070            if (codeString == null || "".equals(codeString))
071                return null;
072        if ("right".equals(codeString))
073          return RIGHT;
074        if ("left".equals(codeString))
075          return LEFT;
076        throw new FHIRException("Unknown VisionEyes code '"+codeString+"'");
077        }
078        public String toCode() {
079          switch (this) {
080            case RIGHT: return "right";
081            case LEFT: return "left";
082            case NULL: return null;
083            default: return "?";
084          }
085        }
086        public String getSystem() {
087          switch (this) {
088            case RIGHT: return "http://hl7.org/fhir/vision-eye-codes";
089            case LEFT: return "http://hl7.org/fhir/vision-eye-codes";
090            case NULL: return null;
091            default: return "?";
092          }
093        }
094        public String getDefinition() {
095          switch (this) {
096            case RIGHT: return "Right Eye";
097            case LEFT: return "Left Eye";
098            case NULL: return null;
099            default: return "?";
100          }
101        }
102        public String getDisplay() {
103          switch (this) {
104            case RIGHT: return "Right Eye";
105            case LEFT: return "Left Eye";
106            case NULL: return null;
107            default: return "?";
108          }
109        }
110    }
111
112  public static class VisionEyesEnumFactory implements EnumFactory<VisionEyes> {
113    public VisionEyes fromCode(String codeString) throws IllegalArgumentException {
114      if (codeString == null || "".equals(codeString))
115            if (codeString == null || "".equals(codeString))
116                return null;
117        if ("right".equals(codeString))
118          return VisionEyes.RIGHT;
119        if ("left".equals(codeString))
120          return VisionEyes.LEFT;
121        throw new IllegalArgumentException("Unknown VisionEyes code '"+codeString+"'");
122        }
123        public Enumeration<VisionEyes> fromType(Base code) throws FHIRException {
124          if (code == null || code.isEmpty())
125            return null;
126          String codeString = ((PrimitiveType) code).asStringValue();
127          if (codeString == null || "".equals(codeString))
128            return null;
129        if ("right".equals(codeString))
130          return new Enumeration<VisionEyes>(this, VisionEyes.RIGHT);
131        if ("left".equals(codeString))
132          return new Enumeration<VisionEyes>(this, VisionEyes.LEFT);
133        throw new FHIRException("Unknown VisionEyes code '"+codeString+"'");
134        }
135    public String toCode(VisionEyes code) {
136      if (code == VisionEyes.RIGHT)
137        return "right";
138      if (code == VisionEyes.LEFT)
139        return "left";
140      return "?";
141      }
142    }
143
144    public enum VisionBase {
145        /**
146         * top
147         */
148        UP, 
149        /**
150         * bottom
151         */
152        DOWN, 
153        /**
154         * inner edge
155         */
156        IN, 
157        /**
158         * outer edge
159         */
160        OUT, 
161        /**
162         * added to help the parsers
163         */
164        NULL;
165        public static VisionBase fromCode(String codeString) throws FHIRException {
166            if (codeString == null || "".equals(codeString))
167                return null;
168        if ("up".equals(codeString))
169          return UP;
170        if ("down".equals(codeString))
171          return DOWN;
172        if ("in".equals(codeString))
173          return IN;
174        if ("out".equals(codeString))
175          return OUT;
176        throw new FHIRException("Unknown VisionBase code '"+codeString+"'");
177        }
178        public String toCode() {
179          switch (this) {
180            case UP: return "up";
181            case DOWN: return "down";
182            case IN: return "in";
183            case OUT: return "out";
184            case NULL: return null;
185            default: return "?";
186          }
187        }
188        public String getSystem() {
189          switch (this) {
190            case UP: return "http://hl7.org/fhir/vision-base-codes";
191            case DOWN: return "http://hl7.org/fhir/vision-base-codes";
192            case IN: return "http://hl7.org/fhir/vision-base-codes";
193            case OUT: return "http://hl7.org/fhir/vision-base-codes";
194            case NULL: return null;
195            default: return "?";
196          }
197        }
198        public String getDefinition() {
199          switch (this) {
200            case UP: return "top";
201            case DOWN: return "bottom";
202            case IN: return "inner edge";
203            case OUT: return "outer edge";
204            case NULL: return null;
205            default: return "?";
206          }
207        }
208        public String getDisplay() {
209          switch (this) {
210            case UP: return "Up";
211            case DOWN: return "Down";
212            case IN: return "In";
213            case OUT: return "Out";
214            case NULL: return null;
215            default: return "?";
216          }
217        }
218    }
219
220  public static class VisionBaseEnumFactory implements EnumFactory<VisionBase> {
221    public VisionBase fromCode(String codeString) throws IllegalArgumentException {
222      if (codeString == null || "".equals(codeString))
223            if (codeString == null || "".equals(codeString))
224                return null;
225        if ("up".equals(codeString))
226          return VisionBase.UP;
227        if ("down".equals(codeString))
228          return VisionBase.DOWN;
229        if ("in".equals(codeString))
230          return VisionBase.IN;
231        if ("out".equals(codeString))
232          return VisionBase.OUT;
233        throw new IllegalArgumentException("Unknown VisionBase code '"+codeString+"'");
234        }
235        public Enumeration<VisionBase> fromType(Base code) throws FHIRException {
236          if (code == null || code.isEmpty())
237            return null;
238          String codeString = ((PrimitiveType) code).asStringValue();
239          if (codeString == null || "".equals(codeString))
240            return null;
241        if ("up".equals(codeString))
242          return new Enumeration<VisionBase>(this, VisionBase.UP);
243        if ("down".equals(codeString))
244          return new Enumeration<VisionBase>(this, VisionBase.DOWN);
245        if ("in".equals(codeString))
246          return new Enumeration<VisionBase>(this, VisionBase.IN);
247        if ("out".equals(codeString))
248          return new Enumeration<VisionBase>(this, VisionBase.OUT);
249        throw new FHIRException("Unknown VisionBase code '"+codeString+"'");
250        }
251    public String toCode(VisionBase code) {
252      if (code == VisionBase.UP)
253        return "up";
254      if (code == VisionBase.DOWN)
255        return "down";
256      if (code == VisionBase.IN)
257        return "in";
258      if (code == VisionBase.OUT)
259        return "out";
260      return "?";
261      }
262    }
263
264    @Block()
265    public static class VisionPrescriptionDispenseComponent extends BackboneElement implements IBaseBackboneElement {
266        /**
267         * Identifies the type of vision correction product which is required for the patient.
268         */
269        @Child(name = "product", type = {Coding.class}, order=1, min=1, max=1, modifier=false, summary=true)
270        @Description(shortDefinition="Product to be supplied", formalDefinition="Identifies the type of vision correction product which is required for the patient." )
271        protected Coding product;
272
273        /**
274         * The eye for which the lens applies.
275         */
276        @Child(name = "eye", type = {CodeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
277        @Description(shortDefinition="right | left", formalDefinition="The eye for which the lens applies." )
278        protected Enumeration<VisionEyes> eye;
279
280        /**
281         * Lens power measured in diopters (0.25 units).
282         */
283        @Child(name = "sphere", type = {DecimalType.class}, order=3, min=0, max=1, modifier=false, summary=true)
284        @Description(shortDefinition="Lens sphere", formalDefinition="Lens power measured in diopters (0.25 units)." )
285        protected DecimalType sphere;
286
287        /**
288         * Power adjustment for astigmatism measured in diopters (0.25 units).
289         */
290        @Child(name = "cylinder", type = {DecimalType.class}, order=4, min=0, max=1, modifier=false, summary=true)
291        @Description(shortDefinition="Lens cylinder", formalDefinition="Power adjustment for astigmatism measured in diopters (0.25 units)." )
292        protected DecimalType cylinder;
293
294        /**
295         * Adjustment for astigmatism measured in integer degrees.
296         */
297        @Child(name = "axis", type = {IntegerType.class}, order=5, min=0, max=1, modifier=false, summary=true)
298        @Description(shortDefinition="Lens axis", formalDefinition="Adjustment for astigmatism measured in integer degrees." )
299        protected IntegerType axis;
300
301        /**
302         * Amount of prism to compensate for eye alignment in fractional units.
303         */
304        @Child(name = "prism", type = {DecimalType.class}, order=6, min=0, max=1, modifier=false, summary=true)
305        @Description(shortDefinition="Lens prism", formalDefinition="Amount of prism to compensate for eye alignment in fractional units." )
306        protected DecimalType prism;
307
308        /**
309         * The relative base, or reference lens edge, for the prism.
310         */
311        @Child(name = "base", type = {CodeType.class}, order=7, min=0, max=1, modifier=false, summary=true)
312        @Description(shortDefinition="up | down | in | out", formalDefinition="The relative base, or reference lens edge, for the prism." )
313        protected Enumeration<VisionBase> base;
314
315        /**
316         * Power adjustment for multifocal lenses measured in diopters (0.25 units).
317         */
318        @Child(name = "add", type = {DecimalType.class}, order=8, min=0, max=1, modifier=false, summary=true)
319        @Description(shortDefinition="Lens add", formalDefinition="Power adjustment for multifocal lenses measured in diopters (0.25 units)." )
320        protected DecimalType add;
321
322        /**
323         * Contact lens power measured in diopters (0.25 units).
324         */
325        @Child(name = "power", type = {DecimalType.class}, order=9, min=0, max=1, modifier=false, summary=true)
326        @Description(shortDefinition="Contact lens power", formalDefinition="Contact lens power measured in diopters (0.25 units)." )
327        protected DecimalType power;
328
329        /**
330         * Back curvature measured in millimeters.
331         */
332        @Child(name = "backCurve", type = {DecimalType.class}, order=10, min=0, max=1, modifier=false, summary=true)
333        @Description(shortDefinition="Contact lens back curvature", formalDefinition="Back curvature measured in millimeters." )
334        protected DecimalType backCurve;
335
336        /**
337         * Contact lens diameter measured in millimeters.
338         */
339        @Child(name = "diameter", type = {DecimalType.class}, order=11, min=0, max=1, modifier=false, summary=true)
340        @Description(shortDefinition="Contact lens diameter", formalDefinition="Contact lens diameter measured in millimeters." )
341        protected DecimalType diameter;
342
343        /**
344         * The recommended maximum wear period for the lens.
345         */
346        @Child(name = "duration", type = {SimpleQuantity.class}, order=12, min=0, max=1, modifier=false, summary=true)
347        @Description(shortDefinition="Lens wear duration", formalDefinition="The recommended maximum wear period for the lens." )
348        protected SimpleQuantity duration;
349
350        /**
351         * Special color or pattern.
352         */
353        @Child(name = "color", type = {StringType.class}, order=13, min=0, max=1, modifier=false, summary=true)
354        @Description(shortDefinition="Lens add", formalDefinition="Special color or pattern." )
355        protected StringType color;
356
357        /**
358         * Brand recommendations or restrictions.
359         */
360        @Child(name = "brand", type = {StringType.class}, order=14, min=0, max=1, modifier=false, summary=true)
361        @Description(shortDefinition="Lens add", formalDefinition="Brand recommendations or restrictions." )
362        protected StringType brand;
363
364        /**
365         * Notes for special requirements such as coatings and lens materials.
366         */
367        @Child(name = "notes", type = {StringType.class}, order=15, min=0, max=1, modifier=false, summary=true)
368        @Description(shortDefinition="Notes for coatings", formalDefinition="Notes for special requirements such as coatings and lens materials." )
369        protected StringType notes;
370
371        private static final long serialVersionUID = -1586392610L;
372
373    /*
374     * Constructor
375     */
376      public VisionPrescriptionDispenseComponent() {
377        super();
378      }
379
380    /*
381     * Constructor
382     */
383      public VisionPrescriptionDispenseComponent(Coding product) {
384        super();
385        this.product = product;
386      }
387
388        /**
389         * @return {@link #product} (Identifies the type of vision correction product which is required for the patient.)
390         */
391        public Coding getProduct() { 
392          if (this.product == null)
393            if (Configuration.errorOnAutoCreate())
394              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.product");
395            else if (Configuration.doAutoCreate())
396              this.product = new Coding(); // cc
397          return this.product;
398        }
399
400        public boolean hasProduct() { 
401          return this.product != null && !this.product.isEmpty();
402        }
403
404        /**
405         * @param value {@link #product} (Identifies the type of vision correction product which is required for the patient.)
406         */
407        public VisionPrescriptionDispenseComponent setProduct(Coding value) { 
408          this.product = value;
409          return this;
410        }
411
412        /**
413         * @return {@link #eye} (The eye for which the lens applies.). This is the underlying object with id, value and extensions. The accessor "getEye" gives direct access to the value
414         */
415        public Enumeration<VisionEyes> getEyeElement() { 
416          if (this.eye == null)
417            if (Configuration.errorOnAutoCreate())
418              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.eye");
419            else if (Configuration.doAutoCreate())
420              this.eye = new Enumeration<VisionEyes>(new VisionEyesEnumFactory()); // bb
421          return this.eye;
422        }
423
424        public boolean hasEyeElement() { 
425          return this.eye != null && !this.eye.isEmpty();
426        }
427
428        public boolean hasEye() { 
429          return this.eye != null && !this.eye.isEmpty();
430        }
431
432        /**
433         * @param value {@link #eye} (The eye for which the lens applies.). This is the underlying object with id, value and extensions. The accessor "getEye" gives direct access to the value
434         */
435        public VisionPrescriptionDispenseComponent setEyeElement(Enumeration<VisionEyes> value) { 
436          this.eye = value;
437          return this;
438        }
439
440        /**
441         * @return The eye for which the lens applies.
442         */
443        public VisionEyes getEye() { 
444          return this.eye == null ? null : this.eye.getValue();
445        }
446
447        /**
448         * @param value The eye for which the lens applies.
449         */
450        public VisionPrescriptionDispenseComponent setEye(VisionEyes value) { 
451          if (value == null)
452            this.eye = null;
453          else {
454            if (this.eye == null)
455              this.eye = new Enumeration<VisionEyes>(new VisionEyesEnumFactory());
456            this.eye.setValue(value);
457          }
458          return this;
459        }
460
461        /**
462         * @return {@link #sphere} (Lens power measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getSphere" gives direct access to the value
463         */
464        public DecimalType getSphereElement() { 
465          if (this.sphere == null)
466            if (Configuration.errorOnAutoCreate())
467              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.sphere");
468            else if (Configuration.doAutoCreate())
469              this.sphere = new DecimalType(); // bb
470          return this.sphere;
471        }
472
473        public boolean hasSphereElement() { 
474          return this.sphere != null && !this.sphere.isEmpty();
475        }
476
477        public boolean hasSphere() { 
478          return this.sphere != null && !this.sphere.isEmpty();
479        }
480
481        /**
482         * @param value {@link #sphere} (Lens power measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getSphere" gives direct access to the value
483         */
484        public VisionPrescriptionDispenseComponent setSphereElement(DecimalType value) { 
485          this.sphere = value;
486          return this;
487        }
488
489        /**
490         * @return Lens power measured in diopters (0.25 units).
491         */
492        public BigDecimal getSphere() { 
493          return this.sphere == null ? null : this.sphere.getValue();
494        }
495
496        /**
497         * @param value Lens power measured in diopters (0.25 units).
498         */
499        public VisionPrescriptionDispenseComponent setSphere(BigDecimal value) { 
500          if (value == null)
501            this.sphere = null;
502          else {
503            if (this.sphere == null)
504              this.sphere = new DecimalType();
505            this.sphere.setValue(value);
506          }
507          return this;
508        }
509
510        /**
511         * @return {@link #cylinder} (Power adjustment for astigmatism measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getCylinder" gives direct access to the value
512         */
513        public DecimalType getCylinderElement() { 
514          if (this.cylinder == null)
515            if (Configuration.errorOnAutoCreate())
516              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.cylinder");
517            else if (Configuration.doAutoCreate())
518              this.cylinder = new DecimalType(); // bb
519          return this.cylinder;
520        }
521
522        public boolean hasCylinderElement() { 
523          return this.cylinder != null && !this.cylinder.isEmpty();
524        }
525
526        public boolean hasCylinder() { 
527          return this.cylinder != null && !this.cylinder.isEmpty();
528        }
529
530        /**
531         * @param value {@link #cylinder} (Power adjustment for astigmatism measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getCylinder" gives direct access to the value
532         */
533        public VisionPrescriptionDispenseComponent setCylinderElement(DecimalType value) { 
534          this.cylinder = value;
535          return this;
536        }
537
538        /**
539         * @return Power adjustment for astigmatism measured in diopters (0.25 units).
540         */
541        public BigDecimal getCylinder() { 
542          return this.cylinder == null ? null : this.cylinder.getValue();
543        }
544
545        /**
546         * @param value Power adjustment for astigmatism measured in diopters (0.25 units).
547         */
548        public VisionPrescriptionDispenseComponent setCylinder(BigDecimal value) { 
549          if (value == null)
550            this.cylinder = null;
551          else {
552            if (this.cylinder == null)
553              this.cylinder = new DecimalType();
554            this.cylinder.setValue(value);
555          }
556          return this;
557        }
558
559        /**
560         * @return {@link #axis} (Adjustment for astigmatism measured in integer degrees.). This is the underlying object with id, value and extensions. The accessor "getAxis" gives direct access to the value
561         */
562        public IntegerType getAxisElement() { 
563          if (this.axis == null)
564            if (Configuration.errorOnAutoCreate())
565              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.axis");
566            else if (Configuration.doAutoCreate())
567              this.axis = new IntegerType(); // bb
568          return this.axis;
569        }
570
571        public boolean hasAxisElement() { 
572          return this.axis != null && !this.axis.isEmpty();
573        }
574
575        public boolean hasAxis() { 
576          return this.axis != null && !this.axis.isEmpty();
577        }
578
579        /**
580         * @param value {@link #axis} (Adjustment for astigmatism measured in integer degrees.). This is the underlying object with id, value and extensions. The accessor "getAxis" gives direct access to the value
581         */
582        public VisionPrescriptionDispenseComponent setAxisElement(IntegerType value) { 
583          this.axis = value;
584          return this;
585        }
586
587        /**
588         * @return Adjustment for astigmatism measured in integer degrees.
589         */
590        public int getAxis() { 
591          return this.axis == null || this.axis.isEmpty() ? 0 : this.axis.getValue();
592        }
593
594        /**
595         * @param value Adjustment for astigmatism measured in integer degrees.
596         */
597        public VisionPrescriptionDispenseComponent setAxis(int value) { 
598            if (this.axis == null)
599              this.axis = new IntegerType();
600            this.axis.setValue(value);
601          return this;
602        }
603
604        /**
605         * @return {@link #prism} (Amount of prism to compensate for eye alignment in fractional units.). This is the underlying object with id, value and extensions. The accessor "getPrism" gives direct access to the value
606         */
607        public DecimalType getPrismElement() { 
608          if (this.prism == null)
609            if (Configuration.errorOnAutoCreate())
610              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.prism");
611            else if (Configuration.doAutoCreate())
612              this.prism = new DecimalType(); // bb
613          return this.prism;
614        }
615
616        public boolean hasPrismElement() { 
617          return this.prism != null && !this.prism.isEmpty();
618        }
619
620        public boolean hasPrism() { 
621          return this.prism != null && !this.prism.isEmpty();
622        }
623
624        /**
625         * @param value {@link #prism} (Amount of prism to compensate for eye alignment in fractional units.). This is the underlying object with id, value and extensions. The accessor "getPrism" gives direct access to the value
626         */
627        public VisionPrescriptionDispenseComponent setPrismElement(DecimalType value) { 
628          this.prism = value;
629          return this;
630        }
631
632        /**
633         * @return Amount of prism to compensate for eye alignment in fractional units.
634         */
635        public BigDecimal getPrism() { 
636          return this.prism == null ? null : this.prism.getValue();
637        }
638
639        /**
640         * @param value Amount of prism to compensate for eye alignment in fractional units.
641         */
642        public VisionPrescriptionDispenseComponent setPrism(BigDecimal value) { 
643          if (value == null)
644            this.prism = null;
645          else {
646            if (this.prism == null)
647              this.prism = new DecimalType();
648            this.prism.setValue(value);
649          }
650          return this;
651        }
652
653        /**
654         * @return {@link #base} (The relative base, or reference lens edge, for the prism.). This is the underlying object with id, value and extensions. The accessor "getBase" gives direct access to the value
655         */
656        public Enumeration<VisionBase> getBaseElement() { 
657          if (this.base == null)
658            if (Configuration.errorOnAutoCreate())
659              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.base");
660            else if (Configuration.doAutoCreate())
661              this.base = new Enumeration<VisionBase>(new VisionBaseEnumFactory()); // bb
662          return this.base;
663        }
664
665        public boolean hasBaseElement() { 
666          return this.base != null && !this.base.isEmpty();
667        }
668
669        public boolean hasBase() { 
670          return this.base != null && !this.base.isEmpty();
671        }
672
673        /**
674         * @param value {@link #base} (The relative base, or reference lens edge, for the prism.). This is the underlying object with id, value and extensions. The accessor "getBase" gives direct access to the value
675         */
676        public VisionPrescriptionDispenseComponent setBaseElement(Enumeration<VisionBase> value) { 
677          this.base = value;
678          return this;
679        }
680
681        /**
682         * @return The relative base, or reference lens edge, for the prism.
683         */
684        public VisionBase getBase() { 
685          return this.base == null ? null : this.base.getValue();
686        }
687
688        /**
689         * @param value The relative base, or reference lens edge, for the prism.
690         */
691        public VisionPrescriptionDispenseComponent setBase(VisionBase value) { 
692          if (value == null)
693            this.base = null;
694          else {
695            if (this.base == null)
696              this.base = new Enumeration<VisionBase>(new VisionBaseEnumFactory());
697            this.base.setValue(value);
698          }
699          return this;
700        }
701
702        /**
703         * @return {@link #add} (Power adjustment for multifocal lenses measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getAdd" gives direct access to the value
704         */
705        public DecimalType getAddElement() { 
706          if (this.add == null)
707            if (Configuration.errorOnAutoCreate())
708              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.add");
709            else if (Configuration.doAutoCreate())
710              this.add = new DecimalType(); // bb
711          return this.add;
712        }
713
714        public boolean hasAddElement() { 
715          return this.add != null && !this.add.isEmpty();
716        }
717
718        public boolean hasAdd() { 
719          return this.add != null && !this.add.isEmpty();
720        }
721
722        /**
723         * @param value {@link #add} (Power adjustment for multifocal lenses measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getAdd" gives direct access to the value
724         */
725        public VisionPrescriptionDispenseComponent setAddElement(DecimalType value) { 
726          this.add = value;
727          return this;
728        }
729
730        /**
731         * @return Power adjustment for multifocal lenses measured in diopters (0.25 units).
732         */
733        public BigDecimal getAdd() { 
734          return this.add == null ? null : this.add.getValue();
735        }
736
737        /**
738         * @param value Power adjustment for multifocal lenses measured in diopters (0.25 units).
739         */
740        public VisionPrescriptionDispenseComponent setAdd(BigDecimal value) { 
741          if (value == null)
742            this.add = null;
743          else {
744            if (this.add == null)
745              this.add = new DecimalType();
746            this.add.setValue(value);
747          }
748          return this;
749        }
750
751        /**
752         * @return {@link #power} (Contact lens power measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getPower" gives direct access to the value
753         */
754        public DecimalType getPowerElement() { 
755          if (this.power == null)
756            if (Configuration.errorOnAutoCreate())
757              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.power");
758            else if (Configuration.doAutoCreate())
759              this.power = new DecimalType(); // bb
760          return this.power;
761        }
762
763        public boolean hasPowerElement() { 
764          return this.power != null && !this.power.isEmpty();
765        }
766
767        public boolean hasPower() { 
768          return this.power != null && !this.power.isEmpty();
769        }
770
771        /**
772         * @param value {@link #power} (Contact lens power measured in diopters (0.25 units).). This is the underlying object with id, value and extensions. The accessor "getPower" gives direct access to the value
773         */
774        public VisionPrescriptionDispenseComponent setPowerElement(DecimalType value) { 
775          this.power = value;
776          return this;
777        }
778
779        /**
780         * @return Contact lens power measured in diopters (0.25 units).
781         */
782        public BigDecimal getPower() { 
783          return this.power == null ? null : this.power.getValue();
784        }
785
786        /**
787         * @param value Contact lens power measured in diopters (0.25 units).
788         */
789        public VisionPrescriptionDispenseComponent setPower(BigDecimal value) { 
790          if (value == null)
791            this.power = null;
792          else {
793            if (this.power == null)
794              this.power = new DecimalType();
795            this.power.setValue(value);
796          }
797          return this;
798        }
799
800        /**
801         * @return {@link #backCurve} (Back curvature measured in millimeters.). This is the underlying object with id, value and extensions. The accessor "getBackCurve" gives direct access to the value
802         */
803        public DecimalType getBackCurveElement() { 
804          if (this.backCurve == null)
805            if (Configuration.errorOnAutoCreate())
806              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.backCurve");
807            else if (Configuration.doAutoCreate())
808              this.backCurve = new DecimalType(); // bb
809          return this.backCurve;
810        }
811
812        public boolean hasBackCurveElement() { 
813          return this.backCurve != null && !this.backCurve.isEmpty();
814        }
815
816        public boolean hasBackCurve() { 
817          return this.backCurve != null && !this.backCurve.isEmpty();
818        }
819
820        /**
821         * @param value {@link #backCurve} (Back curvature measured in millimeters.). This is the underlying object with id, value and extensions. The accessor "getBackCurve" gives direct access to the value
822         */
823        public VisionPrescriptionDispenseComponent setBackCurveElement(DecimalType value) { 
824          this.backCurve = value;
825          return this;
826        }
827
828        /**
829         * @return Back curvature measured in millimeters.
830         */
831        public BigDecimal getBackCurve() { 
832          return this.backCurve == null ? null : this.backCurve.getValue();
833        }
834
835        /**
836         * @param value Back curvature measured in millimeters.
837         */
838        public VisionPrescriptionDispenseComponent setBackCurve(BigDecimal value) { 
839          if (value == null)
840            this.backCurve = null;
841          else {
842            if (this.backCurve == null)
843              this.backCurve = new DecimalType();
844            this.backCurve.setValue(value);
845          }
846          return this;
847        }
848
849        /**
850         * @return {@link #diameter} (Contact lens diameter measured in millimeters.). This is the underlying object with id, value and extensions. The accessor "getDiameter" gives direct access to the value
851         */
852        public DecimalType getDiameterElement() { 
853          if (this.diameter == null)
854            if (Configuration.errorOnAutoCreate())
855              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.diameter");
856            else if (Configuration.doAutoCreate())
857              this.diameter = new DecimalType(); // bb
858          return this.diameter;
859        }
860
861        public boolean hasDiameterElement() { 
862          return this.diameter != null && !this.diameter.isEmpty();
863        }
864
865        public boolean hasDiameter() { 
866          return this.diameter != null && !this.diameter.isEmpty();
867        }
868
869        /**
870         * @param value {@link #diameter} (Contact lens diameter measured in millimeters.). This is the underlying object with id, value and extensions. The accessor "getDiameter" gives direct access to the value
871         */
872        public VisionPrescriptionDispenseComponent setDiameterElement(DecimalType value) { 
873          this.diameter = value;
874          return this;
875        }
876
877        /**
878         * @return Contact lens diameter measured in millimeters.
879         */
880        public BigDecimal getDiameter() { 
881          return this.diameter == null ? null : this.diameter.getValue();
882        }
883
884        /**
885         * @param value Contact lens diameter measured in millimeters.
886         */
887        public VisionPrescriptionDispenseComponent setDiameter(BigDecimal value) { 
888          if (value == null)
889            this.diameter = null;
890          else {
891            if (this.diameter == null)
892              this.diameter = new DecimalType();
893            this.diameter.setValue(value);
894          }
895          return this;
896        }
897
898        /**
899         * @return {@link #duration} (The recommended maximum wear period for the lens.)
900         */
901        public SimpleQuantity getDuration() { 
902          if (this.duration == null)
903            if (Configuration.errorOnAutoCreate())
904              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.duration");
905            else if (Configuration.doAutoCreate())
906              this.duration = new SimpleQuantity(); // cc
907          return this.duration;
908        }
909
910        public boolean hasDuration() { 
911          return this.duration != null && !this.duration.isEmpty();
912        }
913
914        /**
915         * @param value {@link #duration} (The recommended maximum wear period for the lens.)
916         */
917        public VisionPrescriptionDispenseComponent setDuration(SimpleQuantity value) { 
918          this.duration = value;
919          return this;
920        }
921
922        /**
923         * @return {@link #color} (Special color or pattern.). This is the underlying object with id, value and extensions. The accessor "getColor" gives direct access to the value
924         */
925        public StringType getColorElement() { 
926          if (this.color == null)
927            if (Configuration.errorOnAutoCreate())
928              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.color");
929            else if (Configuration.doAutoCreate())
930              this.color = new StringType(); // bb
931          return this.color;
932        }
933
934        public boolean hasColorElement() { 
935          return this.color != null && !this.color.isEmpty();
936        }
937
938        public boolean hasColor() { 
939          return this.color != null && !this.color.isEmpty();
940        }
941
942        /**
943         * @param value {@link #color} (Special color or pattern.). This is the underlying object with id, value and extensions. The accessor "getColor" gives direct access to the value
944         */
945        public VisionPrescriptionDispenseComponent setColorElement(StringType value) { 
946          this.color = value;
947          return this;
948        }
949
950        /**
951         * @return Special color or pattern.
952         */
953        public String getColor() { 
954          return this.color == null ? null : this.color.getValue();
955        }
956
957        /**
958         * @param value Special color or pattern.
959         */
960        public VisionPrescriptionDispenseComponent setColor(String value) { 
961          if (Utilities.noString(value))
962            this.color = null;
963          else {
964            if (this.color == null)
965              this.color = new StringType();
966            this.color.setValue(value);
967          }
968          return this;
969        }
970
971        /**
972         * @return {@link #brand} (Brand recommendations or restrictions.). This is the underlying object with id, value and extensions. The accessor "getBrand" gives direct access to the value
973         */
974        public StringType getBrandElement() { 
975          if (this.brand == null)
976            if (Configuration.errorOnAutoCreate())
977              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.brand");
978            else if (Configuration.doAutoCreate())
979              this.brand = new StringType(); // bb
980          return this.brand;
981        }
982
983        public boolean hasBrandElement() { 
984          return this.brand != null && !this.brand.isEmpty();
985        }
986
987        public boolean hasBrand() { 
988          return this.brand != null && !this.brand.isEmpty();
989        }
990
991        /**
992         * @param value {@link #brand} (Brand recommendations or restrictions.). This is the underlying object with id, value and extensions. The accessor "getBrand" gives direct access to the value
993         */
994        public VisionPrescriptionDispenseComponent setBrandElement(StringType value) { 
995          this.brand = value;
996          return this;
997        }
998
999        /**
1000         * @return Brand recommendations or restrictions.
1001         */
1002        public String getBrand() { 
1003          return this.brand == null ? null : this.brand.getValue();
1004        }
1005
1006        /**
1007         * @param value Brand recommendations or restrictions.
1008         */
1009        public VisionPrescriptionDispenseComponent setBrand(String value) { 
1010          if (Utilities.noString(value))
1011            this.brand = null;
1012          else {
1013            if (this.brand == null)
1014              this.brand = new StringType();
1015            this.brand.setValue(value);
1016          }
1017          return this;
1018        }
1019
1020        /**
1021         * @return {@link #notes} (Notes for special requirements such as coatings and lens materials.). This is the underlying object with id, value and extensions. The accessor "getNotes" gives direct access to the value
1022         */
1023        public StringType getNotesElement() { 
1024          if (this.notes == null)
1025            if (Configuration.errorOnAutoCreate())
1026              throw new Error("Attempt to auto-create VisionPrescriptionDispenseComponent.notes");
1027            else if (Configuration.doAutoCreate())
1028              this.notes = new StringType(); // bb
1029          return this.notes;
1030        }
1031
1032        public boolean hasNotesElement() { 
1033          return this.notes != null && !this.notes.isEmpty();
1034        }
1035
1036        public boolean hasNotes() { 
1037          return this.notes != null && !this.notes.isEmpty();
1038        }
1039
1040        /**
1041         * @param value {@link #notes} (Notes for special requirements such as coatings and lens materials.). This is the underlying object with id, value and extensions. The accessor "getNotes" gives direct access to the value
1042         */
1043        public VisionPrescriptionDispenseComponent setNotesElement(StringType value) { 
1044          this.notes = value;
1045          return this;
1046        }
1047
1048        /**
1049         * @return Notes for special requirements such as coatings and lens materials.
1050         */
1051        public String getNotes() { 
1052          return this.notes == null ? null : this.notes.getValue();
1053        }
1054
1055        /**
1056         * @param value Notes for special requirements such as coatings and lens materials.
1057         */
1058        public VisionPrescriptionDispenseComponent setNotes(String value) { 
1059          if (Utilities.noString(value))
1060            this.notes = null;
1061          else {
1062            if (this.notes == null)
1063              this.notes = new StringType();
1064            this.notes.setValue(value);
1065          }
1066          return this;
1067        }
1068
1069        protected void listChildren(List<Property> childrenList) {
1070          super.listChildren(childrenList);
1071          childrenList.add(new Property("product", "Coding", "Identifies the type of vision correction product which is required for the patient.", 0, java.lang.Integer.MAX_VALUE, product));
1072          childrenList.add(new Property("eye", "code", "The eye for which the lens applies.", 0, java.lang.Integer.MAX_VALUE, eye));
1073          childrenList.add(new Property("sphere", "decimal", "Lens power measured in diopters (0.25 units).", 0, java.lang.Integer.MAX_VALUE, sphere));
1074          childrenList.add(new Property("cylinder", "decimal", "Power adjustment for astigmatism measured in diopters (0.25 units).", 0, java.lang.Integer.MAX_VALUE, cylinder));
1075          childrenList.add(new Property("axis", "integer", "Adjustment for astigmatism measured in integer degrees.", 0, java.lang.Integer.MAX_VALUE, axis));
1076          childrenList.add(new Property("prism", "decimal", "Amount of prism to compensate for eye alignment in fractional units.", 0, java.lang.Integer.MAX_VALUE, prism));
1077          childrenList.add(new Property("base", "code", "The relative base, or reference lens edge, for the prism.", 0, java.lang.Integer.MAX_VALUE, base));
1078          childrenList.add(new Property("add", "decimal", "Power adjustment for multifocal lenses measured in diopters (0.25 units).", 0, java.lang.Integer.MAX_VALUE, add));
1079          childrenList.add(new Property("power", "decimal", "Contact lens power measured in diopters (0.25 units).", 0, java.lang.Integer.MAX_VALUE, power));
1080          childrenList.add(new Property("backCurve", "decimal", "Back curvature measured in millimeters.", 0, java.lang.Integer.MAX_VALUE, backCurve));
1081          childrenList.add(new Property("diameter", "decimal", "Contact lens diameter measured in millimeters.", 0, java.lang.Integer.MAX_VALUE, diameter));
1082          childrenList.add(new Property("duration", "SimpleQuantity", "The recommended maximum wear period for the lens.", 0, java.lang.Integer.MAX_VALUE, duration));
1083          childrenList.add(new Property("color", "string", "Special color or pattern.", 0, java.lang.Integer.MAX_VALUE, color));
1084          childrenList.add(new Property("brand", "string", "Brand recommendations or restrictions.", 0, java.lang.Integer.MAX_VALUE, brand));
1085          childrenList.add(new Property("notes", "string", "Notes for special requirements such as coatings and lens materials.", 0, java.lang.Integer.MAX_VALUE, notes));
1086        }
1087
1088      @Override
1089      public void setProperty(String name, Base value) throws FHIRException {
1090        if (name.equals("product"))
1091          this.product = castToCoding(value); // Coding
1092        else if (name.equals("eye"))
1093          this.eye = new VisionEyesEnumFactory().fromType(value); // Enumeration<VisionEyes>
1094        else if (name.equals("sphere"))
1095          this.sphere = castToDecimal(value); // DecimalType
1096        else if (name.equals("cylinder"))
1097          this.cylinder = castToDecimal(value); // DecimalType
1098        else if (name.equals("axis"))
1099          this.axis = castToInteger(value); // IntegerType
1100        else if (name.equals("prism"))
1101          this.prism = castToDecimal(value); // DecimalType
1102        else if (name.equals("base"))
1103          this.base = new VisionBaseEnumFactory().fromType(value); // Enumeration<VisionBase>
1104        else if (name.equals("add"))
1105          this.add = castToDecimal(value); // DecimalType
1106        else if (name.equals("power"))
1107          this.power = castToDecimal(value); // DecimalType
1108        else if (name.equals("backCurve"))
1109          this.backCurve = castToDecimal(value); // DecimalType
1110        else if (name.equals("diameter"))
1111          this.diameter = castToDecimal(value); // DecimalType
1112        else if (name.equals("duration"))
1113          this.duration = castToSimpleQuantity(value); // SimpleQuantity
1114        else if (name.equals("color"))
1115          this.color = castToString(value); // StringType
1116        else if (name.equals("brand"))
1117          this.brand = castToString(value); // StringType
1118        else if (name.equals("notes"))
1119          this.notes = castToString(value); // StringType
1120        else
1121          super.setProperty(name, value);
1122      }
1123
1124      @Override
1125      public Base addChild(String name) throws FHIRException {
1126        if (name.equals("product")) {
1127          this.product = new Coding();
1128          return this.product;
1129        }
1130        else if (name.equals("eye")) {
1131          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.eye");
1132        }
1133        else if (name.equals("sphere")) {
1134          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.sphere");
1135        }
1136        else if (name.equals("cylinder")) {
1137          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.cylinder");
1138        }
1139        else if (name.equals("axis")) {
1140          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.axis");
1141        }
1142        else if (name.equals("prism")) {
1143          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.prism");
1144        }
1145        else if (name.equals("base")) {
1146          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.base");
1147        }
1148        else if (name.equals("add")) {
1149          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.add");
1150        }
1151        else if (name.equals("power")) {
1152          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.power");
1153        }
1154        else if (name.equals("backCurve")) {
1155          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.backCurve");
1156        }
1157        else if (name.equals("diameter")) {
1158          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.diameter");
1159        }
1160        else if (name.equals("duration")) {
1161          this.duration = new SimpleQuantity();
1162          return this.duration;
1163        }
1164        else if (name.equals("color")) {
1165          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.color");
1166        }
1167        else if (name.equals("brand")) {
1168          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.brand");
1169        }
1170        else if (name.equals("notes")) {
1171          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.notes");
1172        }
1173        else
1174          return super.addChild(name);
1175      }
1176
1177      public VisionPrescriptionDispenseComponent copy() {
1178        VisionPrescriptionDispenseComponent dst = new VisionPrescriptionDispenseComponent();
1179        copyValues(dst);
1180        dst.product = product == null ? null : product.copy();
1181        dst.eye = eye == null ? null : eye.copy();
1182        dst.sphere = sphere == null ? null : sphere.copy();
1183        dst.cylinder = cylinder == null ? null : cylinder.copy();
1184        dst.axis = axis == null ? null : axis.copy();
1185        dst.prism = prism == null ? null : prism.copy();
1186        dst.base = base == null ? null : base.copy();
1187        dst.add = add == null ? null : add.copy();
1188        dst.power = power == null ? null : power.copy();
1189        dst.backCurve = backCurve == null ? null : backCurve.copy();
1190        dst.diameter = diameter == null ? null : diameter.copy();
1191        dst.duration = duration == null ? null : duration.copy();
1192        dst.color = color == null ? null : color.copy();
1193        dst.brand = brand == null ? null : brand.copy();
1194        dst.notes = notes == null ? null : notes.copy();
1195        return dst;
1196      }
1197
1198      @Override
1199      public boolean equalsDeep(Base other) {
1200        if (!super.equalsDeep(other))
1201          return false;
1202        if (!(other instanceof VisionPrescriptionDispenseComponent))
1203          return false;
1204        VisionPrescriptionDispenseComponent o = (VisionPrescriptionDispenseComponent) other;
1205        return compareDeep(product, o.product, true) && compareDeep(eye, o.eye, true) && compareDeep(sphere, o.sphere, true)
1206           && compareDeep(cylinder, o.cylinder, true) && compareDeep(axis, o.axis, true) && compareDeep(prism, o.prism, true)
1207           && compareDeep(base, o.base, true) && compareDeep(add, o.add, true) && compareDeep(power, o.power, true)
1208           && compareDeep(backCurve, o.backCurve, true) && compareDeep(diameter, o.diameter, true) && compareDeep(duration, o.duration, true)
1209           && compareDeep(color, o.color, true) && compareDeep(brand, o.brand, true) && compareDeep(notes, o.notes, true)
1210          ;
1211      }
1212
1213      @Override
1214      public boolean equalsShallow(Base other) {
1215        if (!super.equalsShallow(other))
1216          return false;
1217        if (!(other instanceof VisionPrescriptionDispenseComponent))
1218          return false;
1219        VisionPrescriptionDispenseComponent o = (VisionPrescriptionDispenseComponent) other;
1220        return compareValues(eye, o.eye, true) && compareValues(sphere, o.sphere, true) && compareValues(cylinder, o.cylinder, true)
1221           && compareValues(axis, o.axis, true) && compareValues(prism, o.prism, true) && compareValues(base, o.base, true)
1222           && compareValues(add, o.add, true) && compareValues(power, o.power, true) && compareValues(backCurve, o.backCurve, true)
1223           && compareValues(diameter, o.diameter, true) && compareValues(color, o.color, true) && compareValues(brand, o.brand, true)
1224           && compareValues(notes, o.notes, true);
1225      }
1226
1227      public boolean isEmpty() {
1228        return super.isEmpty() && (product == null || product.isEmpty()) && (eye == null || eye.isEmpty())
1229           && (sphere == null || sphere.isEmpty()) && (cylinder == null || cylinder.isEmpty()) && (axis == null || axis.isEmpty())
1230           && (prism == null || prism.isEmpty()) && (base == null || base.isEmpty()) && (add == null || add.isEmpty())
1231           && (power == null || power.isEmpty()) && (backCurve == null || backCurve.isEmpty()) && (diameter == null || diameter.isEmpty())
1232           && (duration == null || duration.isEmpty()) && (color == null || color.isEmpty()) && (brand == null || brand.isEmpty())
1233           && (notes == null || notes.isEmpty());
1234      }
1235
1236  public String fhirType() {
1237    return "VisionPrescription.dispense";
1238
1239  }
1240
1241  }
1242
1243    /**
1244     * Business identifier which may be used by other parties to reference or identify the prescription.
1245     */
1246    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1247    @Description(shortDefinition="Business identifier", formalDefinition="Business identifier which may be used by other parties to reference or identify the prescription." )
1248    protected List<Identifier> identifier;
1249
1250    /**
1251     * The date (and perhaps time) when the prescription was written.
1252     */
1253    @Child(name = "dateWritten", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
1254    @Description(shortDefinition="When prescription was authorized", formalDefinition="The date (and perhaps time) when the prescription was written." )
1255    protected DateTimeType dateWritten;
1256
1257    /**
1258     * A link to a resource representing the person to whom the vision products will be supplied.
1259     */
1260    @Child(name = "patient", type = {Patient.class}, order=2, min=0, max=1, modifier=false, summary=true)
1261    @Description(shortDefinition="Who prescription is for", formalDefinition="A link to a resource representing the person to whom the vision products will be supplied." )
1262    protected Reference patient;
1263
1264    /**
1265     * The actual object that is the target of the reference (A link to a resource representing the person to whom the vision products will be supplied.)
1266     */
1267    protected Patient patientTarget;
1268
1269    /**
1270     * The healthcare professional responsible for authorizing the prescription.
1271     */
1272    @Child(name = "prescriber", type = {Practitioner.class}, order=3, min=0, max=1, modifier=false, summary=true)
1273    @Description(shortDefinition="Who authorizes the vision product", formalDefinition="The healthcare professional responsible for authorizing the prescription." )
1274    protected Reference prescriber;
1275
1276    /**
1277     * The actual object that is the target of the reference (The healthcare professional responsible for authorizing the prescription.)
1278     */
1279    protected Practitioner prescriberTarget;
1280
1281    /**
1282     * A link to a resource that identifies the particular occurrence of contact between patient and health care provider.
1283     */
1284    @Child(name = "encounter", type = {Encounter.class}, order=4, min=0, max=1, modifier=false, summary=true)
1285    @Description(shortDefinition="Created during encounter / admission / stay", formalDefinition="A link to a resource that identifies the particular occurrence of contact between patient and health care provider." )
1286    protected Reference encounter;
1287
1288    /**
1289     * The actual object that is the target of the reference (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1290     */
1291    protected Encounter encounterTarget;
1292
1293    /**
1294     * Can be the reason or the indication for writing the prescription.
1295     */
1296    @Child(name = "reason", type = {CodeableConcept.class, Condition.class}, order=5, min=0, max=1, modifier=false, summary=true)
1297    @Description(shortDefinition="Reason or indication for writing the prescription", formalDefinition="Can be the reason or the indication for writing the prescription." )
1298    protected Type reason;
1299
1300    /**
1301     * Deals with details of the dispense part of the supply specification.
1302     */
1303    @Child(name = "dispense", type = {}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1304    @Description(shortDefinition="Vision supply authorization", formalDefinition="Deals with details of the dispense part of the supply specification." )
1305    protected List<VisionPrescriptionDispenseComponent> dispense;
1306
1307    private static final long serialVersionUID = -1108276057L;
1308
1309  /*
1310   * Constructor
1311   */
1312    public VisionPrescription() {
1313      super();
1314    }
1315
1316    /**
1317     * @return {@link #identifier} (Business identifier which may be used by other parties to reference or identify the prescription.)
1318     */
1319    public List<Identifier> getIdentifier() { 
1320      if (this.identifier == null)
1321        this.identifier = new ArrayList<Identifier>();
1322      return this.identifier;
1323    }
1324
1325    public boolean hasIdentifier() { 
1326      if (this.identifier == null)
1327        return false;
1328      for (Identifier item : this.identifier)
1329        if (!item.isEmpty())
1330          return true;
1331      return false;
1332    }
1333
1334    /**
1335     * @return {@link #identifier} (Business identifier which may be used by other parties to reference or identify the prescription.)
1336     */
1337    // syntactic sugar
1338    public Identifier addIdentifier() { //3
1339      Identifier t = new Identifier();
1340      if (this.identifier == null)
1341        this.identifier = new ArrayList<Identifier>();
1342      this.identifier.add(t);
1343      return t;
1344    }
1345
1346    // syntactic sugar
1347    public VisionPrescription addIdentifier(Identifier t) { //3
1348      if (t == null)
1349        return this;
1350      if (this.identifier == null)
1351        this.identifier = new ArrayList<Identifier>();
1352      this.identifier.add(t);
1353      return this;
1354    }
1355
1356    /**
1357     * @return {@link #dateWritten} (The date (and perhaps time) when the prescription was written.). This is the underlying object with id, value and extensions. The accessor "getDateWritten" gives direct access to the value
1358     */
1359    public DateTimeType getDateWrittenElement() { 
1360      if (this.dateWritten == null)
1361        if (Configuration.errorOnAutoCreate())
1362          throw new Error("Attempt to auto-create VisionPrescription.dateWritten");
1363        else if (Configuration.doAutoCreate())
1364          this.dateWritten = new DateTimeType(); // bb
1365      return this.dateWritten;
1366    }
1367
1368    public boolean hasDateWrittenElement() { 
1369      return this.dateWritten != null && !this.dateWritten.isEmpty();
1370    }
1371
1372    public boolean hasDateWritten() { 
1373      return this.dateWritten != null && !this.dateWritten.isEmpty();
1374    }
1375
1376    /**
1377     * @param value {@link #dateWritten} (The date (and perhaps time) when the prescription was written.). This is the underlying object with id, value and extensions. The accessor "getDateWritten" gives direct access to the value
1378     */
1379    public VisionPrescription setDateWrittenElement(DateTimeType value) { 
1380      this.dateWritten = value;
1381      return this;
1382    }
1383
1384    /**
1385     * @return The date (and perhaps time) when the prescription was written.
1386     */
1387    public Date getDateWritten() { 
1388      return this.dateWritten == null ? null : this.dateWritten.getValue();
1389    }
1390
1391    /**
1392     * @param value The date (and perhaps time) when the prescription was written.
1393     */
1394    public VisionPrescription setDateWritten(Date value) { 
1395      if (value == null)
1396        this.dateWritten = null;
1397      else {
1398        if (this.dateWritten == null)
1399          this.dateWritten = new DateTimeType();
1400        this.dateWritten.setValue(value);
1401      }
1402      return this;
1403    }
1404
1405    /**
1406     * @return {@link #patient} (A link to a resource representing the person to whom the vision products will be supplied.)
1407     */
1408    public Reference getPatient() { 
1409      if (this.patient == null)
1410        if (Configuration.errorOnAutoCreate())
1411          throw new Error("Attempt to auto-create VisionPrescription.patient");
1412        else if (Configuration.doAutoCreate())
1413          this.patient = new Reference(); // cc
1414      return this.patient;
1415    }
1416
1417    public boolean hasPatient() { 
1418      return this.patient != null && !this.patient.isEmpty();
1419    }
1420
1421    /**
1422     * @param value {@link #patient} (A link to a resource representing the person to whom the vision products will be supplied.)
1423     */
1424    public VisionPrescription setPatient(Reference value) { 
1425      this.patient = value;
1426      return this;
1427    }
1428
1429    /**
1430     * @return {@link #patient} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (A link to a resource representing the person to whom the vision products will be supplied.)
1431     */
1432    public Patient getPatientTarget() { 
1433      if (this.patientTarget == null)
1434        if (Configuration.errorOnAutoCreate())
1435          throw new Error("Attempt to auto-create VisionPrescription.patient");
1436        else if (Configuration.doAutoCreate())
1437          this.patientTarget = new Patient(); // aa
1438      return this.patientTarget;
1439    }
1440
1441    /**
1442     * @param value {@link #patient} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (A link to a resource representing the person to whom the vision products will be supplied.)
1443     */
1444    public VisionPrescription setPatientTarget(Patient value) { 
1445      this.patientTarget = value;
1446      return this;
1447    }
1448
1449    /**
1450     * @return {@link #prescriber} (The healthcare professional responsible for authorizing the prescription.)
1451     */
1452    public Reference getPrescriber() { 
1453      if (this.prescriber == null)
1454        if (Configuration.errorOnAutoCreate())
1455          throw new Error("Attempt to auto-create VisionPrescription.prescriber");
1456        else if (Configuration.doAutoCreate())
1457          this.prescriber = new Reference(); // cc
1458      return this.prescriber;
1459    }
1460
1461    public boolean hasPrescriber() { 
1462      return this.prescriber != null && !this.prescriber.isEmpty();
1463    }
1464
1465    /**
1466     * @param value {@link #prescriber} (The healthcare professional responsible for authorizing the prescription.)
1467     */
1468    public VisionPrescription setPrescriber(Reference value) { 
1469      this.prescriber = value;
1470      return this;
1471    }
1472
1473    /**
1474     * @return {@link #prescriber} 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 healthcare professional responsible for authorizing the prescription.)
1475     */
1476    public Practitioner getPrescriberTarget() { 
1477      if (this.prescriberTarget == null)
1478        if (Configuration.errorOnAutoCreate())
1479          throw new Error("Attempt to auto-create VisionPrescription.prescriber");
1480        else if (Configuration.doAutoCreate())
1481          this.prescriberTarget = new Practitioner(); // aa
1482      return this.prescriberTarget;
1483    }
1484
1485    /**
1486     * @param value {@link #prescriber} 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 healthcare professional responsible for authorizing the prescription.)
1487     */
1488    public VisionPrescription setPrescriberTarget(Practitioner value) { 
1489      this.prescriberTarget = value;
1490      return this;
1491    }
1492
1493    /**
1494     * @return {@link #encounter} (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1495     */
1496    public Reference getEncounter() { 
1497      if (this.encounter == null)
1498        if (Configuration.errorOnAutoCreate())
1499          throw new Error("Attempt to auto-create VisionPrescription.encounter");
1500        else if (Configuration.doAutoCreate())
1501          this.encounter = new Reference(); // cc
1502      return this.encounter;
1503    }
1504
1505    public boolean hasEncounter() { 
1506      return this.encounter != null && !this.encounter.isEmpty();
1507    }
1508
1509    /**
1510     * @param value {@link #encounter} (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1511     */
1512    public VisionPrescription setEncounter(Reference value) { 
1513      this.encounter = value;
1514      return this;
1515    }
1516
1517    /**
1518     * @return {@link #encounter} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1519     */
1520    public Encounter getEncounterTarget() { 
1521      if (this.encounterTarget == null)
1522        if (Configuration.errorOnAutoCreate())
1523          throw new Error("Attempt to auto-create VisionPrescription.encounter");
1524        else if (Configuration.doAutoCreate())
1525          this.encounterTarget = new Encounter(); // aa
1526      return this.encounterTarget;
1527    }
1528
1529    /**
1530     * @param value {@link #encounter} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (A link to a resource that identifies the particular occurrence of contact between patient and health care provider.)
1531     */
1532    public VisionPrescription setEncounterTarget(Encounter value) { 
1533      this.encounterTarget = value;
1534      return this;
1535    }
1536
1537    /**
1538     * @return {@link #reason} (Can be the reason or the indication for writing the prescription.)
1539     */
1540    public Type getReason() { 
1541      return this.reason;
1542    }
1543
1544    /**
1545     * @return {@link #reason} (Can be the reason or the indication for writing the prescription.)
1546     */
1547    public CodeableConcept getReasonCodeableConcept() throws FHIRException { 
1548      if (!(this.reason instanceof CodeableConcept))
1549        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.reason.getClass().getName()+" was encountered");
1550      return (CodeableConcept) this.reason;
1551    }
1552
1553    public boolean hasReasonCodeableConcept() { 
1554      return this.reason instanceof CodeableConcept;
1555    }
1556
1557    /**
1558     * @return {@link #reason} (Can be the reason or the indication for writing the prescription.)
1559     */
1560    public Reference getReasonReference() throws FHIRException { 
1561      if (!(this.reason instanceof Reference))
1562        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.reason.getClass().getName()+" was encountered");
1563      return (Reference) this.reason;
1564    }
1565
1566    public boolean hasReasonReference() { 
1567      return this.reason instanceof Reference;
1568    }
1569
1570    public boolean hasReason() { 
1571      return this.reason != null && !this.reason.isEmpty();
1572    }
1573
1574    /**
1575     * @param value {@link #reason} (Can be the reason or the indication for writing the prescription.)
1576     */
1577    public VisionPrescription setReason(Type value) { 
1578      this.reason = value;
1579      return this;
1580    }
1581
1582    /**
1583     * @return {@link #dispense} (Deals with details of the dispense part of the supply specification.)
1584     */
1585    public List<VisionPrescriptionDispenseComponent> getDispense() { 
1586      if (this.dispense == null)
1587        this.dispense = new ArrayList<VisionPrescriptionDispenseComponent>();
1588      return this.dispense;
1589    }
1590
1591    public boolean hasDispense() { 
1592      if (this.dispense == null)
1593        return false;
1594      for (VisionPrescriptionDispenseComponent item : this.dispense)
1595        if (!item.isEmpty())
1596          return true;
1597      return false;
1598    }
1599
1600    /**
1601     * @return {@link #dispense} (Deals with details of the dispense part of the supply specification.)
1602     */
1603    // syntactic sugar
1604    public VisionPrescriptionDispenseComponent addDispense() { //3
1605      VisionPrescriptionDispenseComponent t = new VisionPrescriptionDispenseComponent();
1606      if (this.dispense == null)
1607        this.dispense = new ArrayList<VisionPrescriptionDispenseComponent>();
1608      this.dispense.add(t);
1609      return t;
1610    }
1611
1612    // syntactic sugar
1613    public VisionPrescription addDispense(VisionPrescriptionDispenseComponent t) { //3
1614      if (t == null)
1615        return this;
1616      if (this.dispense == null)
1617        this.dispense = new ArrayList<VisionPrescriptionDispenseComponent>();
1618      this.dispense.add(t);
1619      return this;
1620    }
1621
1622      protected void listChildren(List<Property> childrenList) {
1623        super.listChildren(childrenList);
1624        childrenList.add(new Property("identifier", "Identifier", "Business identifier which may be used by other parties to reference or identify the prescription.", 0, java.lang.Integer.MAX_VALUE, identifier));
1625        childrenList.add(new Property("dateWritten", "dateTime", "The date (and perhaps time) when the prescription was written.", 0, java.lang.Integer.MAX_VALUE, dateWritten));
1626        childrenList.add(new Property("patient", "Reference(Patient)", "A link to a resource representing the person to whom the vision products will be supplied.", 0, java.lang.Integer.MAX_VALUE, patient));
1627        childrenList.add(new Property("prescriber", "Reference(Practitioner)", "The healthcare professional responsible for authorizing the prescription.", 0, java.lang.Integer.MAX_VALUE, prescriber));
1628        childrenList.add(new Property("encounter", "Reference(Encounter)", "A link to a resource that identifies the particular occurrence of contact between patient and health care provider.", 0, java.lang.Integer.MAX_VALUE, encounter));
1629        childrenList.add(new Property("reason[x]", "CodeableConcept|Reference(Condition)", "Can be the reason or the indication for writing the prescription.", 0, java.lang.Integer.MAX_VALUE, reason));
1630        childrenList.add(new Property("dispense", "", "Deals with details of the dispense part of the supply specification.", 0, java.lang.Integer.MAX_VALUE, dispense));
1631      }
1632
1633      @Override
1634      public void setProperty(String name, Base value) throws FHIRException {
1635        if (name.equals("identifier"))
1636          this.getIdentifier().add(castToIdentifier(value));
1637        else if (name.equals("dateWritten"))
1638          this.dateWritten = castToDateTime(value); // DateTimeType
1639        else if (name.equals("patient"))
1640          this.patient = castToReference(value); // Reference
1641        else if (name.equals("prescriber"))
1642          this.prescriber = castToReference(value); // Reference
1643        else if (name.equals("encounter"))
1644          this.encounter = castToReference(value); // Reference
1645        else if (name.equals("reason[x]"))
1646          this.reason = (Type) value; // Type
1647        else if (name.equals("dispense"))
1648          this.getDispense().add((VisionPrescriptionDispenseComponent) value);
1649        else
1650          super.setProperty(name, value);
1651      }
1652
1653      @Override
1654      public Base addChild(String name) throws FHIRException {
1655        if (name.equals("identifier")) {
1656          return addIdentifier();
1657        }
1658        else if (name.equals("dateWritten")) {
1659          throw new FHIRException("Cannot call addChild on a primitive type VisionPrescription.dateWritten");
1660        }
1661        else if (name.equals("patient")) {
1662          this.patient = new Reference();
1663          return this.patient;
1664        }
1665        else if (name.equals("prescriber")) {
1666          this.prescriber = new Reference();
1667          return this.prescriber;
1668        }
1669        else if (name.equals("encounter")) {
1670          this.encounter = new Reference();
1671          return this.encounter;
1672        }
1673        else if (name.equals("reasonCodeableConcept")) {
1674          this.reason = new CodeableConcept();
1675          return this.reason;
1676        }
1677        else if (name.equals("reasonReference")) {
1678          this.reason = new Reference();
1679          return this.reason;
1680        }
1681        else if (name.equals("dispense")) {
1682          return addDispense();
1683        }
1684        else
1685          return super.addChild(name);
1686      }
1687
1688  public String fhirType() {
1689    return "VisionPrescription";
1690
1691  }
1692
1693      public VisionPrescription copy() {
1694        VisionPrescription dst = new VisionPrescription();
1695        copyValues(dst);
1696        if (identifier != null) {
1697          dst.identifier = new ArrayList<Identifier>();
1698          for (Identifier i : identifier)
1699            dst.identifier.add(i.copy());
1700        };
1701        dst.dateWritten = dateWritten == null ? null : dateWritten.copy();
1702        dst.patient = patient == null ? null : patient.copy();
1703        dst.prescriber = prescriber == null ? null : prescriber.copy();
1704        dst.encounter = encounter == null ? null : encounter.copy();
1705        dst.reason = reason == null ? null : reason.copy();
1706        if (dispense != null) {
1707          dst.dispense = new ArrayList<VisionPrescriptionDispenseComponent>();
1708          for (VisionPrescriptionDispenseComponent i : dispense)
1709            dst.dispense.add(i.copy());
1710        };
1711        return dst;
1712      }
1713
1714      protected VisionPrescription typedCopy() {
1715        return copy();
1716      }
1717
1718      @Override
1719      public boolean equalsDeep(Base other) {
1720        if (!super.equalsDeep(other))
1721          return false;
1722        if (!(other instanceof VisionPrescription))
1723          return false;
1724        VisionPrescription o = (VisionPrescription) other;
1725        return compareDeep(identifier, o.identifier, true) && compareDeep(dateWritten, o.dateWritten, true)
1726           && compareDeep(patient, o.patient, true) && compareDeep(prescriber, o.prescriber, true) && compareDeep(encounter, o.encounter, true)
1727           && compareDeep(reason, o.reason, true) && compareDeep(dispense, o.dispense, true);
1728      }
1729
1730      @Override
1731      public boolean equalsShallow(Base other) {
1732        if (!super.equalsShallow(other))
1733          return false;
1734        if (!(other instanceof VisionPrescription))
1735          return false;
1736        VisionPrescription o = (VisionPrescription) other;
1737        return compareValues(dateWritten, o.dateWritten, true);
1738      }
1739
1740      public boolean isEmpty() {
1741        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (dateWritten == null || dateWritten.isEmpty())
1742           && (patient == null || patient.isEmpty()) && (prescriber == null || prescriber.isEmpty())
1743           && (encounter == null || encounter.isEmpty()) && (reason == null || reason.isEmpty()) && (dispense == null || dispense.isEmpty())
1744          ;
1745      }
1746
1747  @Override
1748  public ResourceType getResourceType() {
1749    return ResourceType.VisionPrescription;
1750   }
1751
1752  @SearchParamDefinition(name="prescriber", path="VisionPrescription.prescriber", description="Who authorizes the vision product", type="reference" )
1753  public static final String SP_PRESCRIBER = "prescriber";
1754  @SearchParamDefinition(name="identifier", path="VisionPrescription.identifier", description="Return prescriptions with this external identifier", type="token" )
1755  public static final String SP_IDENTIFIER = "identifier";
1756  @SearchParamDefinition(name="patient", path="VisionPrescription.patient", description="The identity of a patient to list dispenses for", type="reference" )
1757  public static final String SP_PATIENT = "patient";
1758  @SearchParamDefinition(name="datewritten", path="VisionPrescription.dateWritten", description="Return prescriptions written on this date", type="date" )
1759  public static final String SP_DATEWRITTEN = "datewritten";
1760  @SearchParamDefinition(name="encounter", path="VisionPrescription.encounter", description="Return prescriptions with this encounter identifier", type="reference" )
1761  public static final String SP_ENCOUNTER = "encounter";
1762
1763}