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