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