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 Thu, Sep 13, 2018 09:04-0400 for FHIR v3.5.0 033 034import java.util.*; 035 036import org.hl7.fhir.utilities.Utilities; 037import ca.uhn.fhir.model.api.annotation.Child; 038import ca.uhn.fhir.model.api.annotation.ChildOrder; 039import ca.uhn.fhir.model.api.annotation.Description; 040import ca.uhn.fhir.model.api.annotation.DatatypeDef; 041import ca.uhn.fhir.model.api.annotation.Block; 042import org.hl7.fhir.instance.model.api.*; 043import org.hl7.fhir.exceptions.FHIRException; 044/** 045 * A expression that is evaluated in a specified context and returns a value. The context of use of the expression must specify the context in which the expression is evaluated, and how the result of the expression is used. 046 */ 047@DatatypeDef(name="Expression") 048public class Expression extends Type implements ICompositeType { 049 050 public enum ExpressionLanguage { 051 /** 052 * Clinical Quality Language. 053 */ 054 TEXT_CQL, 055 /** 056 * FHIRPath. 057 */ 058 TEXT_FHIRPATH, 059 /** 060 * FHIR's RESTful query syntax - typically independent of base URL. 061 */ 062 APPLICATION_XFHIRQUERY, 063 /** 064 * added to help the parsers with the generic types 065 */ 066 NULL; 067 public static ExpressionLanguage fromCode(String codeString) throws FHIRException { 068 if (codeString == null || "".equals(codeString)) 069 return null; 070 if ("text/cql".equals(codeString)) 071 return TEXT_CQL; 072 if ("text/fhirpath".equals(codeString)) 073 return TEXT_FHIRPATH; 074 if ("application/x-fhir-query".equals(codeString)) 075 return APPLICATION_XFHIRQUERY; 076 if (Configuration.isAcceptInvalidEnums()) 077 return null; 078 else 079 throw new FHIRException("Unknown ExpressionLanguage code '"+codeString+"'"); 080 } 081 public String toCode() { 082 switch (this) { 083 case TEXT_CQL: return "text/cql"; 084 case TEXT_FHIRPATH: return "text/fhirpath"; 085 case APPLICATION_XFHIRQUERY: return "application/x-fhir-query"; 086 default: return "?"; 087 } 088 } 089 public String getSystem() { 090 switch (this) { 091 case TEXT_CQL: return "http://hl7.org/fhir/expression-language"; 092 case TEXT_FHIRPATH: return "http://hl7.org/fhir/expression-language"; 093 case APPLICATION_XFHIRQUERY: return "http://hl7.org/fhir/expression-language"; 094 default: return "?"; 095 } 096 } 097 public String getDefinition() { 098 switch (this) { 099 case TEXT_CQL: return "Clinical Quality Language."; 100 case TEXT_FHIRPATH: return "FHIRPath."; 101 case APPLICATION_XFHIRQUERY: return "FHIR's RESTful query syntax - typically independent of base URL."; 102 default: return "?"; 103 } 104 } 105 public String getDisplay() { 106 switch (this) { 107 case TEXT_CQL: return "CQL"; 108 case TEXT_FHIRPATH: return "FHIRPath"; 109 case APPLICATION_XFHIRQUERY: return "FHIR Query"; 110 default: return "?"; 111 } 112 } 113 } 114 115 public static class ExpressionLanguageEnumFactory implements EnumFactory<ExpressionLanguage> { 116 public ExpressionLanguage fromCode(String codeString) throws IllegalArgumentException { 117 if (codeString == null || "".equals(codeString)) 118 if (codeString == null || "".equals(codeString)) 119 return null; 120 if ("text/cql".equals(codeString)) 121 return ExpressionLanguage.TEXT_CQL; 122 if ("text/fhirpath".equals(codeString)) 123 return ExpressionLanguage.TEXT_FHIRPATH; 124 if ("application/x-fhir-query".equals(codeString)) 125 return ExpressionLanguage.APPLICATION_XFHIRQUERY; 126 throw new IllegalArgumentException("Unknown ExpressionLanguage code '"+codeString+"'"); 127 } 128 public Enumeration<ExpressionLanguage> fromType(Base code) throws FHIRException { 129 if (code == null) 130 return null; 131 if (code.isEmpty()) 132 return new Enumeration<ExpressionLanguage>(this); 133 String codeString = ((PrimitiveType) code).asStringValue(); 134 if (codeString == null || "".equals(codeString)) 135 return null; 136 if ("text/cql".equals(codeString)) 137 return new Enumeration<ExpressionLanguage>(this, ExpressionLanguage.TEXT_CQL); 138 if ("text/fhirpath".equals(codeString)) 139 return new Enumeration<ExpressionLanguage>(this, ExpressionLanguage.TEXT_FHIRPATH); 140 if ("application/x-fhir-query".equals(codeString)) 141 return new Enumeration<ExpressionLanguage>(this, ExpressionLanguage.APPLICATION_XFHIRQUERY); 142 throw new FHIRException("Unknown ExpressionLanguage code '"+codeString+"'"); 143 } 144 public String toCode(ExpressionLanguage code) { 145 if (code == ExpressionLanguage.TEXT_CQL) 146 return "text/cql"; 147 if (code == ExpressionLanguage.TEXT_FHIRPATH) 148 return "text/fhirpath"; 149 if (code == ExpressionLanguage.APPLICATION_XFHIRQUERY) 150 return "application/x-fhir-query"; 151 return "?"; 152 } 153 public String toSystem(ExpressionLanguage code) { 154 return code.getSystem(); 155 } 156 } 157 158 /** 159 * A brief, natural language description of the condition that effectively communicates the intended semantics. 160 */ 161 @Child(name = "description", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 162 @Description(shortDefinition="Natural language description of the condition", formalDefinition="A brief, natural language description of the condition that effectively communicates the intended semantics." ) 163 protected StringType description; 164 165 /** 166 * A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined. 167 */ 168 @Child(name = "name", type = {IdType.class}, order=1, min=0, max=1, modifier=false, summary=true) 169 @Description(shortDefinition="Short name assigned to expression for reuse", formalDefinition="A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined." ) 170 protected IdType name; 171 172 /** 173 * The media type of the language for the expression. 174 */ 175 @Child(name = "language", type = {CodeType.class}, order=2, min=1, max=1, modifier=false, summary=true) 176 @Description(shortDefinition="text/cql | text/fhirpath | application/x-fhir-query | etc.", formalDefinition="The media type of the language for the expression." ) 177 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/expression-language") 178 protected Enumeration<ExpressionLanguage> language; 179 180 /** 181 * An expression in the specified language that returns a value. 182 */ 183 @Child(name = "expression", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true) 184 @Description(shortDefinition="Expression in specified language", formalDefinition="An expression in the specified language that returns a value." ) 185 protected StringType expression; 186 187 /** 188 * A URI that defines where the expression is found. 189 */ 190 @Child(name = "reference", type = {UriType.class}, order=4, min=0, max=1, modifier=false, summary=true) 191 @Description(shortDefinition="Where the expression is found", formalDefinition="A URI that defines where the expression is found." ) 192 protected UriType reference; 193 194 private static final long serialVersionUID = -941986742L; 195 196 /** 197 * Constructor 198 */ 199 public Expression() { 200 super(); 201 } 202 203 /** 204 * Constructor 205 */ 206 public Expression(Enumeration<ExpressionLanguage> language) { 207 super(); 208 this.language = language; 209 } 210 211 /** 212 * @return {@link #description} (A brief, natural language description of the condition that effectively communicates the intended semantics.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value 213 */ 214 public StringType getDescriptionElement() { 215 if (this.description == null) 216 if (Configuration.errorOnAutoCreate()) 217 throw new Error("Attempt to auto-create Expression.description"); 218 else if (Configuration.doAutoCreate()) 219 this.description = new StringType(); // bb 220 return this.description; 221 } 222 223 public boolean hasDescriptionElement() { 224 return this.description != null && !this.description.isEmpty(); 225 } 226 227 public boolean hasDescription() { 228 return this.description != null && !this.description.isEmpty(); 229 } 230 231 /** 232 * @param value {@link #description} (A brief, natural language description of the condition that effectively communicates the intended semantics.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value 233 */ 234 public Expression setDescriptionElement(StringType value) { 235 this.description = value; 236 return this; 237 } 238 239 /** 240 * @return A brief, natural language description of the condition that effectively communicates the intended semantics. 241 */ 242 public String getDescription() { 243 return this.description == null ? null : this.description.getValue(); 244 } 245 246 /** 247 * @param value A brief, natural language description of the condition that effectively communicates the intended semantics. 248 */ 249 public Expression setDescription(String value) { 250 if (Utilities.noString(value)) 251 this.description = null; 252 else { 253 if (this.description == null) 254 this.description = new StringType(); 255 this.description.setValue(value); 256 } 257 return this; 258 } 259 260 /** 261 * @return {@link #name} (A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value 262 */ 263 public IdType getNameElement() { 264 if (this.name == null) 265 if (Configuration.errorOnAutoCreate()) 266 throw new Error("Attempt to auto-create Expression.name"); 267 else if (Configuration.doAutoCreate()) 268 this.name = new IdType(); // bb 269 return this.name; 270 } 271 272 public boolean hasNameElement() { 273 return this.name != null && !this.name.isEmpty(); 274 } 275 276 public boolean hasName() { 277 return this.name != null && !this.name.isEmpty(); 278 } 279 280 /** 281 * @param value {@link #name} (A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value 282 */ 283 public Expression setNameElement(IdType value) { 284 this.name = value; 285 return this; 286 } 287 288 /** 289 * @return A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined. 290 */ 291 public String getName() { 292 return this.name == null ? null : this.name.getValue(); 293 } 294 295 /** 296 * @param value A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined. 297 */ 298 public Expression setName(String value) { 299 if (Utilities.noString(value)) 300 this.name = null; 301 else { 302 if (this.name == null) 303 this.name = new IdType(); 304 this.name.setValue(value); 305 } 306 return this; 307 } 308 309 /** 310 * @return {@link #language} (The media type of the language for the expression.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value 311 */ 312 public Enumeration<ExpressionLanguage> getLanguageElement() { 313 if (this.language == null) 314 if (Configuration.errorOnAutoCreate()) 315 throw new Error("Attempt to auto-create Expression.language"); 316 else if (Configuration.doAutoCreate()) 317 this.language = new Enumeration<ExpressionLanguage>(new ExpressionLanguageEnumFactory()); // bb 318 return this.language; 319 } 320 321 public boolean hasLanguageElement() { 322 return this.language != null && !this.language.isEmpty(); 323 } 324 325 public boolean hasLanguage() { 326 return this.language != null && !this.language.isEmpty(); 327 } 328 329 /** 330 * @param value {@link #language} (The media type of the language for the expression.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value 331 */ 332 public Expression setLanguageElement(Enumeration<ExpressionLanguage> value) { 333 this.language = value; 334 return this; 335 } 336 337 /** 338 * @return The media type of the language for the expression. 339 */ 340 public ExpressionLanguage getLanguage() { 341 return this.language == null ? null : this.language.getValue(); 342 } 343 344 /** 345 * @param value The media type of the language for the expression. 346 */ 347 public Expression setLanguage(ExpressionLanguage value) { 348 if (this.language == null) 349 this.language = new Enumeration<ExpressionLanguage>(new ExpressionLanguageEnumFactory()); 350 this.language.setValue(value); 351 return this; 352 } 353 354 /** 355 * @return {@link #expression} (An expression in the specified language that returns a value.). This is the underlying object with id, value and extensions. The accessor "getExpression" gives direct access to the value 356 */ 357 public StringType getExpressionElement() { 358 if (this.expression == null) 359 if (Configuration.errorOnAutoCreate()) 360 throw new Error("Attempt to auto-create Expression.expression"); 361 else if (Configuration.doAutoCreate()) 362 this.expression = new StringType(); // bb 363 return this.expression; 364 } 365 366 public boolean hasExpressionElement() { 367 return this.expression != null && !this.expression.isEmpty(); 368 } 369 370 public boolean hasExpression() { 371 return this.expression != null && !this.expression.isEmpty(); 372 } 373 374 /** 375 * @param value {@link #expression} (An expression in the specified language that returns a value.). This is the underlying object with id, value and extensions. The accessor "getExpression" gives direct access to the value 376 */ 377 public Expression setExpressionElement(StringType value) { 378 this.expression = value; 379 return this; 380 } 381 382 /** 383 * @return An expression in the specified language that returns a value. 384 */ 385 public String getExpression() { 386 return this.expression == null ? null : this.expression.getValue(); 387 } 388 389 /** 390 * @param value An expression in the specified language that returns a value. 391 */ 392 public Expression setExpression(String value) { 393 if (Utilities.noString(value)) 394 this.expression = null; 395 else { 396 if (this.expression == null) 397 this.expression = new StringType(); 398 this.expression.setValue(value); 399 } 400 return this; 401 } 402 403 /** 404 * @return {@link #reference} (A URI that defines where the expression is found.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value 405 */ 406 public UriType getReferenceElement() { 407 if (this.reference == null) 408 if (Configuration.errorOnAutoCreate()) 409 throw new Error("Attempt to auto-create Expression.reference"); 410 else if (Configuration.doAutoCreate()) 411 this.reference = new UriType(); // bb 412 return this.reference; 413 } 414 415 public boolean hasReferenceElement() { 416 return this.reference != null && !this.reference.isEmpty(); 417 } 418 419 public boolean hasReference() { 420 return this.reference != null && !this.reference.isEmpty(); 421 } 422 423 /** 424 * @param value {@link #reference} (A URI that defines where the expression is found.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value 425 */ 426 public Expression setReferenceElement(UriType value) { 427 this.reference = value; 428 return this; 429 } 430 431 /** 432 * @return A URI that defines where the expression is found. 433 */ 434 public String getReference() { 435 return this.reference == null ? null : this.reference.getValue(); 436 } 437 438 /** 439 * @param value A URI that defines where the expression is found. 440 */ 441 public Expression setReference(String value) { 442 if (Utilities.noString(value)) 443 this.reference = null; 444 else { 445 if (this.reference == null) 446 this.reference = new UriType(); 447 this.reference.setValue(value); 448 } 449 return this; 450 } 451 452 protected void listChildren(List<Property> children) { 453 super.listChildren(children); 454 children.add(new Property("description", "string", "A brief, natural language description of the condition that effectively communicates the intended semantics.", 0, 1, description)); 455 children.add(new Property("name", "id", "A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.", 0, 1, name)); 456 children.add(new Property("language", "code", "The media type of the language for the expression.", 0, 1, language)); 457 children.add(new Property("expression", "string", "An expression in the specified language that returns a value.", 0, 1, expression)); 458 children.add(new Property("reference", "uri", "A URI that defines where the expression is found.", 0, 1, reference)); 459 } 460 461 @Override 462 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 463 switch (_hash) { 464 case -1724546052: /*description*/ return new Property("description", "string", "A brief, natural language description of the condition that effectively communicates the intended semantics.", 0, 1, description); 465 case 3373707: /*name*/ return new Property("name", "id", "A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.", 0, 1, name); 466 case -1613589672: /*language*/ return new Property("language", "code", "The media type of the language for the expression.", 0, 1, language); 467 case -1795452264: /*expression*/ return new Property("expression", "string", "An expression in the specified language that returns a value.", 0, 1, expression); 468 case -925155509: /*reference*/ return new Property("reference", "uri", "A URI that defines where the expression is found.", 0, 1, reference); 469 default: return super.getNamedProperty(_hash, _name, _checkValid); 470 } 471 472 } 473 474 @Override 475 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 476 switch (hash) { 477 case -1724546052: /*description*/ return this.description == null ? new Base[0] : new Base[] {this.description}; // StringType 478 case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // IdType 479 case -1613589672: /*language*/ return this.language == null ? new Base[0] : new Base[] {this.language}; // Enumeration<ExpressionLanguage> 480 case -1795452264: /*expression*/ return this.expression == null ? new Base[0] : new Base[] {this.expression}; // StringType 481 case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // UriType 482 default: return super.getProperty(hash, name, checkValid); 483 } 484 485 } 486 487 @Override 488 public Base setProperty(int hash, String name, Base value) throws FHIRException { 489 switch (hash) { 490 case -1724546052: // description 491 this.description = castToString(value); // StringType 492 return value; 493 case 3373707: // name 494 this.name = castToId(value); // IdType 495 return value; 496 case -1613589672: // language 497 value = new ExpressionLanguageEnumFactory().fromType(castToCode(value)); 498 this.language = (Enumeration) value; // Enumeration<ExpressionLanguage> 499 return value; 500 case -1795452264: // expression 501 this.expression = castToString(value); // StringType 502 return value; 503 case -925155509: // reference 504 this.reference = castToUri(value); // UriType 505 return value; 506 default: return super.setProperty(hash, name, value); 507 } 508 509 } 510 511 @Override 512 public Base setProperty(String name, Base value) throws FHIRException { 513 if (name.equals("description")) { 514 this.description = castToString(value); // StringType 515 } else if (name.equals("name")) { 516 this.name = castToId(value); // IdType 517 } else if (name.equals("language")) { 518 value = new ExpressionLanguageEnumFactory().fromType(castToCode(value)); 519 this.language = (Enumeration) value; // Enumeration<ExpressionLanguage> 520 } else if (name.equals("expression")) { 521 this.expression = castToString(value); // StringType 522 } else if (name.equals("reference")) { 523 this.reference = castToUri(value); // UriType 524 } else 525 return super.setProperty(name, value); 526 return value; 527 } 528 529 @Override 530 public Base makeProperty(int hash, String name) throws FHIRException { 531 switch (hash) { 532 case -1724546052: return getDescriptionElement(); 533 case 3373707: return getNameElement(); 534 case -1613589672: return getLanguageElement(); 535 case -1795452264: return getExpressionElement(); 536 case -925155509: return getReferenceElement(); 537 default: return super.makeProperty(hash, name); 538 } 539 540 } 541 542 @Override 543 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 544 switch (hash) { 545 case -1724546052: /*description*/ return new String[] {"string"}; 546 case 3373707: /*name*/ return new String[] {"id"}; 547 case -1613589672: /*language*/ return new String[] {"code"}; 548 case -1795452264: /*expression*/ return new String[] {"string"}; 549 case -925155509: /*reference*/ return new String[] {"uri"}; 550 default: return super.getTypesForProperty(hash, name); 551 } 552 553 } 554 555 @Override 556 public Base addChild(String name) throws FHIRException { 557 if (name.equals("description")) { 558 throw new FHIRException("Cannot call addChild on a primitive type Expression.description"); 559 } 560 else if (name.equals("name")) { 561 throw new FHIRException("Cannot call addChild on a primitive type Expression.name"); 562 } 563 else if (name.equals("language")) { 564 throw new FHIRException("Cannot call addChild on a primitive type Expression.language"); 565 } 566 else if (name.equals("expression")) { 567 throw new FHIRException("Cannot call addChild on a primitive type Expression.expression"); 568 } 569 else if (name.equals("reference")) { 570 throw new FHIRException("Cannot call addChild on a primitive type Expression.reference"); 571 } 572 else 573 return super.addChild(name); 574 } 575 576 public String fhirType() { 577 return "Expression"; 578 579 } 580 581 public Expression copy() { 582 Expression dst = new Expression(); 583 copyValues(dst); 584 dst.description = description == null ? null : description.copy(); 585 dst.name = name == null ? null : name.copy(); 586 dst.language = language == null ? null : language.copy(); 587 dst.expression = expression == null ? null : expression.copy(); 588 dst.reference = reference == null ? null : reference.copy(); 589 return dst; 590 } 591 592 protected Expression typedCopy() { 593 return copy(); 594 } 595 596 @Override 597 public boolean equalsDeep(Base other_) { 598 if (!super.equalsDeep(other_)) 599 return false; 600 if (!(other_ instanceof Expression)) 601 return false; 602 Expression o = (Expression) other_; 603 return compareDeep(description, o.description, true) && compareDeep(name, o.name, true) && compareDeep(language, o.language, true) 604 && compareDeep(expression, o.expression, true) && compareDeep(reference, o.reference, true); 605 } 606 607 @Override 608 public boolean equalsShallow(Base other_) { 609 if (!super.equalsShallow(other_)) 610 return false; 611 if (!(other_ instanceof Expression)) 612 return false; 613 Expression o = (Expression) other_; 614 return compareValues(description, o.description, true) && compareValues(name, o.name, true) && compareValues(language, o.language, true) 615 && compareValues(expression, o.expression, true) && compareValues(reference, o.reference, true); 616 } 617 618 public boolean isEmpty() { 619 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(description, name, language 620 , expression, reference); 621 } 622 623 624} 625