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