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