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