001package org.hl7.fhir.r4.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 6, 2018 17:51-0400 for FHIR v3.4.0
033
034import java.util.*;
035
036import ca.uhn.fhir.model.api.annotation.Child;
037import ca.uhn.fhir.model.api.annotation.ChildOrder;
038import ca.uhn.fhir.model.api.annotation.Description;
039import ca.uhn.fhir.model.api.annotation.DatatypeDef;
040import ca.uhn.fhir.model.api.annotation.Block;
041import org.hl7.fhir.instance.model.api.*;
042import org.hl7.fhir.exceptions.FHIRException;
043/**
044 * A set of ordered Quantities defined by a low and high limit.
045 */
046@DatatypeDef(name="Range")
047public class Range extends Type implements ICompositeType {
048
049    /**
050     * The low limit. The boundary is inclusive.
051     */
052    @Child(name = "low", type = {SimpleQuantity.class}, order=0, min=0, max=1, modifier=false, summary=true)
053    @Description(shortDefinition="Low limit", formalDefinition="The low limit. The boundary is inclusive." )
054    protected SimpleQuantity low;
055
056    /**
057     * The high limit. The boundary is inclusive.
058     */
059    @Child(name = "high", type = {SimpleQuantity.class}, order=1, min=0, max=1, modifier=false, summary=true)
060    @Description(shortDefinition="High limit", formalDefinition="The high limit. The boundary is inclusive." )
061    protected SimpleQuantity high;
062
063    private static final long serialVersionUID = 1699187994L;
064
065  /**
066   * Constructor
067   */
068    public Range() {
069      super();
070    }
071
072    /**
073     * @return {@link #low} (The low limit. The boundary is inclusive.)
074     */
075    public SimpleQuantity getLow() { 
076      if (this.low == null)
077        if (Configuration.errorOnAutoCreate())
078          throw new Error("Attempt to auto-create Range.low");
079        else if (Configuration.doAutoCreate())
080          this.low = new SimpleQuantity(); // cc
081      return this.low;
082    }
083
084    public boolean hasLow() { 
085      return this.low != null && !this.low.isEmpty();
086    }
087
088    /**
089     * @param value {@link #low} (The low limit. The boundary is inclusive.)
090     */
091    public Range setLow(SimpleQuantity value) { 
092      this.low = value;
093      return this;
094    }
095
096    /**
097     * @return {@link #high} (The high limit. The boundary is inclusive.)
098     */
099    public SimpleQuantity getHigh() { 
100      if (this.high == null)
101        if (Configuration.errorOnAutoCreate())
102          throw new Error("Attempt to auto-create Range.high");
103        else if (Configuration.doAutoCreate())
104          this.high = new SimpleQuantity(); // cc
105      return this.high;
106    }
107
108    public boolean hasHigh() { 
109      return this.high != null && !this.high.isEmpty();
110    }
111
112    /**
113     * @param value {@link #high} (The high limit. The boundary is inclusive.)
114     */
115    public Range setHigh(SimpleQuantity value) { 
116      this.high = value;
117      return this;
118    }
119
120      protected void listChildren(List<Property> children) {
121        super.listChildren(children);
122        children.add(new Property("low", "SimpleQuantity", "The low limit. The boundary is inclusive.", 0, 1, low));
123        children.add(new Property("high", "SimpleQuantity", "The high limit. The boundary is inclusive.", 0, 1, high));
124      }
125
126      @Override
127      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
128        switch (_hash) {
129        case 107348: /*low*/  return new Property("low", "SimpleQuantity", "The low limit. The boundary is inclusive.", 0, 1, low);
130        case 3202466: /*high*/  return new Property("high", "SimpleQuantity", "The high limit. The boundary is inclusive.", 0, 1, high);
131        default: return super.getNamedProperty(_hash, _name, _checkValid);
132        }
133
134      }
135
136      @Override
137      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
138        switch (hash) {
139        case 107348: /*low*/ return this.low == null ? new Base[0] : new Base[] {this.low}; // SimpleQuantity
140        case 3202466: /*high*/ return this.high == null ? new Base[0] : new Base[] {this.high}; // SimpleQuantity
141        default: return super.getProperty(hash, name, checkValid);
142        }
143
144      }
145
146      @Override
147      public Base setProperty(int hash, String name, Base value) throws FHIRException {
148        switch (hash) {
149        case 107348: // low
150          this.low = castToSimpleQuantity(value); // SimpleQuantity
151          return value;
152        case 3202466: // high
153          this.high = castToSimpleQuantity(value); // SimpleQuantity
154          return value;
155        default: return super.setProperty(hash, name, value);
156        }
157
158      }
159
160      @Override
161      public Base setProperty(String name, Base value) throws FHIRException {
162        if (name.equals("low")) {
163          this.low = castToSimpleQuantity(value); // SimpleQuantity
164        } else if (name.equals("high")) {
165          this.high = castToSimpleQuantity(value); // SimpleQuantity
166        } else
167          return super.setProperty(name, value);
168        return value;
169      }
170
171      @Override
172      public Base makeProperty(int hash, String name) throws FHIRException {
173        switch (hash) {
174        case 107348:  return getLow(); 
175        case 3202466:  return getHigh(); 
176        default: return super.makeProperty(hash, name);
177        }
178
179      }
180
181      @Override
182      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
183        switch (hash) {
184        case 107348: /*low*/ return new String[] {"SimpleQuantity"};
185        case 3202466: /*high*/ return new String[] {"SimpleQuantity"};
186        default: return super.getTypesForProperty(hash, name);
187        }
188
189      }
190
191      @Override
192      public Base addChild(String name) throws FHIRException {
193        if (name.equals("low")) {
194          this.low = new SimpleQuantity();
195          return this.low;
196        }
197        else if (name.equals("high")) {
198          this.high = new SimpleQuantity();
199          return this.high;
200        }
201        else
202          return super.addChild(name);
203      }
204
205  public String fhirType() {
206    return "Range";
207
208  }
209
210      public Range copy() {
211        Range dst = new Range();
212        copyValues(dst);
213        dst.low = low == null ? null : low.copy();
214        dst.high = high == null ? null : high.copy();
215        return dst;
216      }
217
218      protected Range typedCopy() {
219        return copy();
220      }
221
222      @Override
223      public boolean equalsDeep(Base other_) {
224        if (!super.equalsDeep(other_))
225          return false;
226        if (!(other_ instanceof Range))
227          return false;
228        Range o = (Range) other_;
229        return compareDeep(low, o.low, true) && compareDeep(high, o.high, true);
230      }
231
232      @Override
233      public boolean equalsShallow(Base other_) {
234        if (!super.equalsShallow(other_))
235          return false;
236        if (!(other_ instanceof Range))
237          return false;
238        Range o = (Range) other_;
239        return true;
240      }
241
242      public boolean isEmpty() {
243        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(low, high);
244      }
245
246
247}
248