001package org.hl7.fhir.r4.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.r4 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.List; 054 055import org.hl7.fhir.exceptions.FHIRException; 056import org.hl7.fhir.instance.model.api.ICompositeType; 057 058import ca.uhn.fhir.model.api.annotation.Child; 059import ca.uhn.fhir.model.api.annotation.DatatypeDef; 060import ca.uhn.fhir.model.api.annotation.Description; 061/** 062 * A set of ordered Quantities defined by a low and high limit. 063 */ 064@DatatypeDef(name="Range") 065public class Range extends Type implements ICompositeType { 066 067 /** 068 * The low limit. The boundary is inclusive. 069 */ 070 @Child(name = "low", type = {Quantity.class}, order=0, min=0, max=1, modifier=false, summary=true) 071 @Description(shortDefinition="Low limit", formalDefinition="The low limit. The boundary is inclusive." ) 072 protected Quantity low; 073 074 /** 075 * The high limit. The boundary is inclusive. 076 */ 077 @Child(name = "high", type = {Quantity.class}, order=1, min=0, max=1, modifier=false, summary=true) 078 @Description(shortDefinition="High limit", formalDefinition="The high limit. The boundary is inclusive." ) 079 protected Quantity high; 080 081 private static final long serialVersionUID = -474933350L; 082 083 /** 084 * Constructor 085 */ 086 public Range() { 087 super(); 088 } 089 090 /** 091 * @return {@link #low} (The low limit. The boundary is inclusive.) 092 */ 093 public Quantity getLow() { 094 if (this.low == null) 095 if (Configuration.errorOnAutoCreate()) 096 throw new Error("Attempt to auto-create Range.low"); 097 else if (Configuration.doAutoCreate()) 098 this.low = new Quantity(); // cc 099 return this.low; 100 } 101 102 public boolean hasLow() { 103 return this.low != null && !this.low.isEmpty(); 104 } 105 106 /** 107 * @param value {@link #low} (The low limit. The boundary is inclusive.) 108 */ 109 public Range setLow(Quantity value) { 110 this.low = value; 111 return this; 112 } 113 114 /** 115 * @return {@link #high} (The high limit. The boundary is inclusive.) 116 */ 117 public Quantity getHigh() { 118 if (this.high == null) 119 if (Configuration.errorOnAutoCreate()) 120 throw new Error("Attempt to auto-create Range.high"); 121 else if (Configuration.doAutoCreate()) 122 this.high = new Quantity(); // cc 123 return this.high; 124 } 125 126 public boolean hasHigh() { 127 return this.high != null && !this.high.isEmpty(); 128 } 129 130 /** 131 * @param value {@link #high} (The high limit. The boundary is inclusive.) 132 */ 133 public Range setHigh(Quantity value) { 134 this.high = value; 135 return this; 136 } 137 138 protected void listChildren(List<Property> children) { 139 super.listChildren(children); 140 children.add(new Property("low", "SimpleQuantity", "The low limit. The boundary is inclusive.", 0, 1, low)); 141 children.add(new Property("high", "SimpleQuantity", "The high limit. The boundary is inclusive.", 0, 1, high)); 142 } 143 144 @Override 145 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 146 switch (_hash) { 147 case 107348: /*low*/ return new Property("low", "SimpleQuantity", "The low limit. The boundary is inclusive.", 0, 1, low); 148 case 3202466: /*high*/ return new Property("high", "SimpleQuantity", "The high limit. The boundary is inclusive.", 0, 1, high); 149 default: return super.getNamedProperty(_hash, _name, _checkValid); 150 } 151 152 } 153 154 @Override 155 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 156 switch (hash) { 157 case 107348: /*low*/ return this.low == null ? new Base[0] : new Base[] {this.low}; // Quantity 158 case 3202466: /*high*/ return this.high == null ? new Base[0] : new Base[] {this.high}; // Quantity 159 default: return super.getProperty(hash, name, checkValid); 160 } 161 162 } 163 164 @Override 165 public Base setProperty(int hash, String name, Base value) throws FHIRException { 166 switch (hash) { 167 case 107348: // low 168 this.low = castToQuantity(value); // Quantity 169 return value; 170 case 3202466: // high 171 this.high = castToQuantity(value); // Quantity 172 return value; 173 default: return super.setProperty(hash, name, value); 174 } 175 176 } 177 178 @Override 179 public Base setProperty(String name, Base value) throws FHIRException { 180 if (name.equals("low")) { 181 this.low = castToQuantity(value); // Quantity 182 } else if (name.equals("high")) { 183 this.high = castToQuantity(value); // Quantity 184 } else 185 return super.setProperty(name, value); 186 return value; 187 } 188 189 @Override 190 public Base makeProperty(int hash, String name) throws FHIRException { 191 switch (hash) { 192 case 107348: return getLow(); 193 case 3202466: return getHigh(); 194 default: return super.makeProperty(hash, name); 195 } 196 197 } 198 199 @Override 200 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 201 switch (hash) { 202 case 107348: /*low*/ return new String[] {"SimpleQuantity"}; 203 case 3202466: /*high*/ return new String[] {"SimpleQuantity"}; 204 default: return super.getTypesForProperty(hash, name); 205 } 206 207 } 208 209 @Override 210 public Base addChild(String name) throws FHIRException { 211 if (name.equals("low")) { 212 this.low = new Quantity(); 213 return this.low; 214 } 215 else if (name.equals("high")) { 216 this.high = new Quantity(); 217 return this.high; 218 } 219 else 220 return super.addChild(name); 221 } 222 223 public String fhirType() { 224 return "Range"; 225 226 } 227 228 public Range copy() { 229 Range dst = new Range(); 230 copyValues(dst); 231 dst.low = low == null ? null : low.copy(); 232 dst.high = high == null ? null : high.copy(); 233 return dst; 234 } 235 236 protected Range typedCopy() { 237 return copy(); 238 } 239 240 @Override 241 public boolean equalsDeep(Base other_) { 242 if (!super.equalsDeep(other_)) 243 return false; 244 if (!(other_ instanceof Range)) 245 return false; 246 Range o = (Range) other_; 247 return compareDeep(low, o.low, true) && compareDeep(high, o.high, true); 248 } 249 250 @Override 251 public boolean equalsShallow(Base other_) { 252 if (!super.equalsShallow(other_)) 253 return false; 254 if (!(other_ instanceof Range)) 255 return false; 256 Range o = (Range) other_; 257 return true; 258 } 259 260 public boolean isEmpty() { 261 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(low, high); 262 } 263 264 265} 266