
001package org.hl7.fhir.r5.model; 002 003 004/* 005 Copyright (c) 2011+, HL7, Inc. 006 All rights reserved. 007 008 Redistribution and use in source and binary forms, with or without modification, \ 009 are permitted provided that the following conditions are met: 010 011 * Redistributions of source code must retain the above copyright notice, this \ 012 list of conditions and the following disclaimer. 013 * Redistributions in binary form must reproduce the above copyright notice, \ 014 this list of conditions and the following disclaimer in the documentation \ 015 and/or other materials provided with the distribution. 016 * Neither the name of HL7 nor the names of its contributors may be used to 017 endorse or promote products derived from this software without specific 018 prior written permission. 019 020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \ 021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \ 022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \ 023 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \ 024 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \ 025 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \ 026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \ 027 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \ 028 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \ 029 POSSIBILITY OF SUCH DAMAGE. 030 */ 031 032// Generated on Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0 033 034import java.util.ArrayList; 035import java.util.Date; 036import java.util.List; 037import org.hl7.fhir.utilities.Utilities; 038import org.hl7.fhir.r5.model.Enumerations.*; 039import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; 040import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; 041import org.hl7.fhir.exceptions.FHIRException; 042import org.hl7.fhir.instance.model.api.ICompositeType; 043import ca.uhn.fhir.model.api.annotation.Child; 044import ca.uhn.fhir.model.api.annotation.ChildOrder; 045import ca.uhn.fhir.model.api.annotation.DatatypeDef; 046import ca.uhn.fhir.model.api.annotation.Description; 047import ca.uhn.fhir.model.api.annotation.Block; 048 049import org.hl7.fhir.instance.model.api.IBaseCoding; 050/** 051 * Coding Type: A reference to a code defined by a terminology system. 052 */ 053@DatatypeDef(name="Coding") 054public class Coding extends DataType implements IBaseCoding, ICompositeType, ICoding { 055 056 /** 057 * The identification of the code system that defines the meaning of the symbol in the code. 058 */ 059 @Child(name = "system", type = {UriType.class}, order=0, min=0, max=1, modifier=false, summary=true) 060 @Description(shortDefinition="Identity of the terminology system", formalDefinition="The identification of the code system that defines the meaning of the symbol in the code." ) 061 protected UriType system; 062 063 /** 064 * The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged. 065 */ 066 @Child(name = "version", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true) 067 @Description(shortDefinition="Version of the system - if relevant", formalDefinition="The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged." ) 068 protected StringType version; 069 070 /** 071 * A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination). 072 */ 073 @Child(name = "code", type = {CodeType.class}, order=2, min=0, max=1, modifier=false, summary=true) 074 @Description(shortDefinition="Symbol in syntax defined by the system", formalDefinition="A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination)." ) 075 protected CodeType code; 076 077 /** 078 * A representation of the meaning of the code in the system, following the rules of the system. 079 */ 080 @Child(name = "display", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true) 081 @Description(shortDefinition="Representation defined by the system", formalDefinition="A representation of the meaning of the code in the system, following the rules of the system." ) 082 protected StringType display; 083 084 /** 085 * Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays). 086 */ 087 @Child(name = "userSelected", type = {BooleanType.class}, order=4, min=0, max=1, modifier=false, summary=true) 088 @Description(shortDefinition="If this coding was chosen directly by the user", formalDefinition="Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays)." ) 089 protected BooleanType userSelected; 090 091 private static final long serialVersionUID = -1417514061L; 092 093 /** 094 * Constructor 095 */ 096 public Coding() { 097 super(); 098 } 099 100 /** 101 * Convenience constructor 102 * 103 * @param theSystem The {@link #setSystem(String) code system} 104 * @param theCode The {@link #setCode(String) code} 105 * @param theDisplay The {@link #setDisplay(String) human readable display} 106 */ 107 public Coding(String theSystem, String theCode, String theDisplay) { 108 setSystem(theSystem); 109 setCode(theCode); 110 setDisplay(theDisplay); 111 } 112 /** 113 * @return {@link #system} (The identification of the code system that defines the meaning of the symbol in the code.). This is the underlying object with id, value and extensions. The accessor "getSystem" gives direct access to the value 114 */ 115 public UriType getSystemElement() { 116 if (this.system == null) 117 if (Configuration.errorOnAutoCreate()) 118 throw new Error("Attempt to auto-create Coding.system"); 119 else if (Configuration.doAutoCreate()) 120 this.system = new UriType(); // bb 121 return this.system; 122 } 123 124 public boolean hasSystemElement() { 125 return this.system != null && !this.system.isEmpty(); 126 } 127 128 public boolean hasSystem() { 129 return this.system != null && !this.system.isEmpty(); 130 } 131 132 /** 133 * @param value {@link #system} (The identification of the code system that defines the meaning of the symbol in the code.). This is the underlying object with id, value and extensions. The accessor "getSystem" gives direct access to the value 134 */ 135 public Coding setSystemElement(UriType value) { 136 this.system = value; 137 return this; 138 } 139 140 /** 141 * @return The identification of the code system that defines the meaning of the symbol in the code. 142 */ 143 public String getSystem() { 144 return this.system == null ? null : this.system.getValue(); 145 } 146 147 /** 148 * @param value The identification of the code system that defines the meaning of the symbol in the code. 149 */ 150 public Coding setSystem(String value) { 151 if (Utilities.noString(value)) 152 this.system = null; 153 else { 154 if (this.system == null) 155 this.system = new UriType(); 156 this.system.setValue(value); 157 } 158 return this; 159 } 160 161 /** 162 * @return {@link #version} (The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged.). This is the underlying object with id, value and extensions. The accessor "getVersion" gives direct access to the value 163 */ 164 public StringType getVersionElement() { 165 if (this.version == null) 166 if (Configuration.errorOnAutoCreate()) 167 throw new Error("Attempt to auto-create Coding.version"); 168 else if (Configuration.doAutoCreate()) 169 this.version = new StringType(); // bb 170 return this.version; 171 } 172 173 public boolean hasVersionElement() { 174 return this.version != null && !this.version.isEmpty(); 175 } 176 177 public boolean hasVersion() { 178 return this.version != null && !this.version.isEmpty(); 179 } 180 181 /** 182 * @param value {@link #version} (The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged.). This is the underlying object with id, value and extensions. The accessor "getVersion" gives direct access to the value 183 */ 184 public Coding setVersionElement(StringType value) { 185 this.version = value; 186 return this; 187 } 188 189 /** 190 * @return The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged. 191 */ 192 public String getVersion() { 193 return this.version == null ? null : this.version.getValue(); 194 } 195 196 /** 197 * @param value The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged. 198 */ 199 public Coding setVersion(String value) { 200 if (Utilities.noString(value)) 201 this.version = null; 202 else { 203 if (this.version == null) 204 this.version = new StringType(); 205 this.version.setValue(value); 206 } 207 return this; 208 } 209 210 /** 211 * @return {@link #code} (A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination).). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value 212 */ 213 public CodeType getCodeElement() { 214 if (this.code == null) 215 if (Configuration.errorOnAutoCreate()) 216 throw new Error("Attempt to auto-create Coding.code"); 217 else if (Configuration.doAutoCreate()) 218 this.code = new CodeType(); // bb 219 return this.code; 220 } 221 222 public boolean hasCodeElement() { 223 return this.code != null && !this.code.isEmpty(); 224 } 225 226 public boolean hasCode() { 227 return this.code != null && !this.code.isEmpty(); 228 } 229 230 /** 231 * @param value {@link #code} (A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination).). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value 232 */ 233 public Coding setCodeElement(CodeType value) { 234 this.code = value; 235 return this; 236 } 237 238 /** 239 * @return A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination). 240 */ 241 public String getCode() { 242 return this.code == null ? null : this.code.getValue(); 243 } 244 245 /** 246 * @param value A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination). 247 */ 248 public Coding setCode(String value) { 249 if (Utilities.noString(value)) 250 this.code = null; 251 else { 252 if (this.code == null) 253 this.code = new CodeType(); 254 this.code.setValue(value); 255 } 256 return this; 257 } 258 259 /** 260 * @return {@link #display} (A representation of the meaning of the code in the system, following the rules of the system.). This is the underlying object with id, value and extensions. The accessor "getDisplay" gives direct access to the value 261 */ 262 public StringType getDisplayElement() { 263 if (this.display == null) 264 if (Configuration.errorOnAutoCreate()) 265 throw new Error("Attempt to auto-create Coding.display"); 266 else if (Configuration.doAutoCreate()) 267 this.display = new StringType(); // bb 268 return this.display; 269 } 270 271 public boolean hasDisplayElement() { 272 return this.display != null && !this.display.isEmpty(); 273 } 274 275 public boolean hasDisplay() { 276 return this.display != null && !this.display.isEmpty(); 277 } 278 279 /** 280 * @param value {@link #display} (A representation of the meaning of the code in the system, following the rules of the system.). This is the underlying object with id, value and extensions. The accessor "getDisplay" gives direct access to the value 281 */ 282 public Coding setDisplayElement(StringType value) { 283 this.display = value; 284 return this; 285 } 286 287 /** 288 * @return A representation of the meaning of the code in the system, following the rules of the system. 289 */ 290 public String getDisplay() { 291 return this.display == null ? null : this.display.getValue(); 292 } 293 294 /** 295 * @param value A representation of the meaning of the code in the system, following the rules of the system. 296 */ 297 public Coding setDisplay(String value) { 298 if (Utilities.noString(value)) 299 this.display = null; 300 else { 301 if (this.display == null) 302 this.display = new StringType(); 303 this.display.setValue(value); 304 } 305 return this; 306 } 307 308 /** 309 * @return {@link #userSelected} (Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).). This is the underlying object with id, value and extensions. The accessor "getUserSelected" gives direct access to the value 310 */ 311 public BooleanType getUserSelectedElement() { 312 if (this.userSelected == null) 313 if (Configuration.errorOnAutoCreate()) 314 throw new Error("Attempt to auto-create Coding.userSelected"); 315 else if (Configuration.doAutoCreate()) 316 this.userSelected = new BooleanType(); // bb 317 return this.userSelected; 318 } 319 320 public boolean hasUserSelectedElement() { 321 return this.userSelected != null && !this.userSelected.isEmpty(); 322 } 323 324 public boolean hasUserSelected() { 325 return this.userSelected != null && !this.userSelected.isEmpty(); 326 } 327 328 /** 329 * @param value {@link #userSelected} (Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).). This is the underlying object with id, value and extensions. The accessor "getUserSelected" gives direct access to the value 330 */ 331 public Coding setUserSelectedElement(BooleanType value) { 332 this.userSelected = value; 333 return this; 334 } 335 336 /** 337 * @return Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays). 338 */ 339 public boolean getUserSelected() { 340 return this.userSelected == null || this.userSelected.isEmpty() ? false : this.userSelected.getValue(); 341 } 342 343 /** 344 * @param value Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays). 345 */ 346 public Coding setUserSelected(boolean value) { 347 if (this.userSelected == null) 348 this.userSelected = new BooleanType(); 349 this.userSelected.setValue(value); 350 return this; 351 } 352 353 protected void listChildren(List<Property> children) { 354 super.listChildren(children); 355 children.add(new Property("system", "uri", "The identification of the code system that defines the meaning of the symbol in the code.", 0, 1, system)); 356 children.add(new Property("version", "string", "The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged.", 0, 1, version)); 357 children.add(new Property("code", "code", "A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination).", 0, 1, code)); 358 children.add(new Property("display", "string", "A representation of the meaning of the code in the system, following the rules of the system.", 0, 1, display)); 359 children.add(new Property("userSelected", "boolean", "Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).", 0, 1, userSelected)); 360 } 361 362 @Override 363 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 364 switch (_hash) { 365 case -887328209: /*system*/ return new Property("system", "uri", "The identification of the code system that defines the meaning of the symbol in the code.", 0, 1, system); 366 case 351608024: /*version*/ return new Property("version", "string", "The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged.", 0, 1, version); 367 case 3059181: /*code*/ return new Property("code", "code", "A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination).", 0, 1, code); 368 case 1671764162: /*display*/ return new Property("display", "string", "A representation of the meaning of the code in the system, following the rules of the system.", 0, 1, display); 369 case 423643014: /*userSelected*/ return new Property("userSelected", "boolean", "Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).", 0, 1, userSelected); 370 default: return super.getNamedProperty(_hash, _name, _checkValid); 371 } 372 373 } 374 375 @Override 376 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 377 switch (hash) { 378 case -887328209: /*system*/ return this.system == null ? new Base[0] : new Base[] {this.system}; // UriType 379 case 351608024: /*version*/ return this.version == null ? new Base[0] : new Base[] {this.version}; // StringType 380 case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeType 381 case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType 382 case 423643014: /*userSelected*/ return this.userSelected == null ? new Base[0] : new Base[] {this.userSelected}; // BooleanType 383 default: return super.getProperty(hash, name, checkValid); 384 } 385 386 } 387 388 @Override 389 public Base setProperty(int hash, String name, Base value) throws FHIRException { 390 switch (hash) { 391 case -887328209: // system 392 this.system = TypeConvertor.castToUri(value); // UriType 393 return value; 394 case 351608024: // version 395 this.version = TypeConvertor.castToString(value); // StringType 396 return value; 397 case 3059181: // code 398 this.code = TypeConvertor.castToCode(value); // CodeType 399 return value; 400 case 1671764162: // display 401 this.display = TypeConvertor.castToString(value); // StringType 402 return value; 403 case 423643014: // userSelected 404 this.userSelected = TypeConvertor.castToBoolean(value); // BooleanType 405 return value; 406 default: return super.setProperty(hash, name, value); 407 } 408 409 } 410 411 @Override 412 public Base setProperty(String name, Base value) throws FHIRException { 413 if (name.equals("system")) { 414 this.system = TypeConvertor.castToUri(value); // UriType 415 } else if (name.equals("version")) { 416 this.version = TypeConvertor.castToString(value); // StringType 417 } else if (name.equals("code")) { 418 this.code = TypeConvertor.castToCode(value); // CodeType 419 } else if (name.equals("display")) { 420 this.display = TypeConvertor.castToString(value); // StringType 421 } else if (name.equals("userSelected")) { 422 this.userSelected = TypeConvertor.castToBoolean(value); // BooleanType 423 } else 424 return super.setProperty(name, value); 425 return value; 426 } 427 428 @Override 429 public void removeChild(String name, Base value) throws FHIRException { 430 if (name.equals("system")) { 431 this.system = null; 432 } else if (name.equals("version")) { 433 this.version = null; 434 } else if (name.equals("code")) { 435 this.code = null; 436 } else if (name.equals("display")) { 437 this.display = null; 438 } else if (name.equals("userSelected")) { 439 this.userSelected = null; 440 } else 441 super.removeChild(name, value); 442 443 } 444 445 @Override 446 public Base makeProperty(int hash, String name) throws FHIRException { 447 switch (hash) { 448 case -887328209: return getSystemElement(); 449 case 351608024: return getVersionElement(); 450 case 3059181: return getCodeElement(); 451 case 1671764162: return getDisplayElement(); 452 case 423643014: return getUserSelectedElement(); 453 default: return super.makeProperty(hash, name); 454 } 455 456 } 457 458 @Override 459 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 460 switch (hash) { 461 case -887328209: /*system*/ return new String[] {"uri"}; 462 case 351608024: /*version*/ return new String[] {"string"}; 463 case 3059181: /*code*/ return new String[] {"code"}; 464 case 1671764162: /*display*/ return new String[] {"string"}; 465 case 423643014: /*userSelected*/ return new String[] {"boolean"}; 466 default: return super.getTypesForProperty(hash, name); 467 } 468 469 } 470 471 @Override 472 public Base addChild(String name) throws FHIRException { 473 if (name.equals("system")) { 474 throw new FHIRException("Cannot call addChild on a singleton property Coding.system"); 475 } 476 else if (name.equals("version")) { 477 throw new FHIRException("Cannot call addChild on a singleton property Coding.version"); 478 } 479 else if (name.equals("code")) { 480 throw new FHIRException("Cannot call addChild on a singleton property Coding.code"); 481 } 482 else if (name.equals("display")) { 483 throw new FHIRException("Cannot call addChild on a singleton property Coding.display"); 484 } 485 else if (name.equals("userSelected")) { 486 throw new FHIRException("Cannot call addChild on a singleton property Coding.userSelected"); 487 } 488 else 489 return super.addChild(name); 490 } 491 492 public String fhirType() { 493 return "Coding"; 494 495 } 496 497 public Coding copy() { 498 Coding dst = new Coding(); 499 copyValues(dst); 500 return dst; 501 } 502 503 public void copyValues(Coding dst) { 504 super.copyValues(dst); 505 dst.system = system == null ? null : system.copy(); 506 dst.version = version == null ? null : version.copy(); 507 dst.code = code == null ? null : code.copy(); 508 dst.display = display == null ? null : display.copy(); 509 dst.userSelected = userSelected == null ? null : userSelected.copy(); 510 } 511 512 protected Coding typedCopy() { 513 return copy(); 514 } 515 516 @Override 517 public boolean equalsDeep(Base other_) { 518 if (!super.equalsDeep(other_)) 519 return false; 520 if (!(other_ instanceof Coding)) 521 return false; 522 Coding o = (Coding) other_; 523 return compareDeep(system, o.system, true) && compareDeep(version, o.version, true) && compareDeep(code, o.code, true) 524 && compareDeep(display, o.display, true) && compareDeep(userSelected, o.userSelected, true); 525 } 526 527 @Override 528 public boolean equalsShallow(Base other_) { 529 if (!super.equalsShallow(other_)) 530 return false; 531 if (!(other_ instanceof Coding)) 532 return false; 533 Coding o = (Coding) other_; 534 return compareValues(system, o.system, true) && compareValues(version, o.version, true) && compareValues(code, o.code, true) 535 && compareValues(display, o.display, true) && compareValues(userSelected, o.userSelected, true); 536 } 537 538 public boolean isEmpty() { 539 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(system, version, code, display 540 , userSelected); 541 } 542 543// Manual code (from Configuration.txt): 544@Override 545 public boolean supportsVersion() { 546 return true; 547 } 548 549 @Override 550 public boolean supportsDisplay() { 551 return true; 552 } 553 554 555 public boolean is(String system, String code) { 556 return hasSystem() && hasCode() && this.getSystem().equals(system) && this.getCode().equals(code); 557 } 558 559 public String toString() { 560 String base = hasSystem() ? getSystem() : ""; 561 if (hasVersion()) 562 base = base+"|"+getVersion(); 563 base = base + "#"+getCode(); 564 if (hasDisplay()) 565 base = base+": '"+getDisplay()+"'"; 566 return base; 567 } 568 569 public static Coding fromLiteral(String value) { 570 String sv = value.contains("#") ? value.substring(0, value.indexOf("#")) : value; 571 String cp = value.contains("#") ? value.substring(value.indexOf("#")+1) : null; 572 573 String system = sv.contains("|") ? sv.substring(0, sv.indexOf("|")) : sv; 574 String version = sv.contains("|") ? sv.substring(sv.indexOf("|")+1) : null; 575 576 String code = cp != null && cp.contains("'") ? cp.substring(0, cp.indexOf("'")) : cp; 577 String display = cp != null && cp.contains("'") ? cp.substring(cp.indexOf("'")+1) : null; 578 if (display != null) { 579 display = display.trim(); 580 display = display.substring(0, display.length() -1); 581 } 582 if ((system == null || !Utilities.isAbsoluteUrl(system)) && code == null) { 583 return null; 584 } else { 585 return new Coding(system, version, code, display); 586 } 587 } 588 589 public boolean matches(Coding other) { 590 return other.hasCode() && this.hasCode() && other.hasSystem() && this.hasSystem() && this.getCode().equals(other.getCode()) && this.getSystem().equals(other.getSystem()) ; 591 } 592 593 594 public static Coding merge(Coding l, Coding r) { 595 Coding res = new Coding(); 596 if (l.hasSystem()) { 597 res.setSystem(l.getSystem()); 598 } else { 599 res.setSystem(r.getSystem()); 600 } 601 if (l.hasVersion()) { 602 res.setVersion(l.getVersion()); 603 } else { 604 res.setVersion(r.getVersion()); 605 } 606 if (l.hasCode()) { 607 res.setCode(l.getCode()); 608 } else { 609 res.setCode(r.getCode()); 610 } 611 if (l.hasDisplay()) { 612 res.setDisplay(l.getDisplay()); 613 } else { 614 res.setDisplay(r.getDisplay()); 615 } 616 if (l.hasUserSelected()) { 617 res.setUserSelected(l.getUserSelected()); 618 } else { 619 res.setUserSelected(r.getUserSelected()); 620 } 621 return res; 622 } 623 624 public static Coding intersect(Coding l, Coding r) { 625 Coding res = new Coding(); 626 if (l.hasSystem() && l.getSystem().equals(r.getSystem())) { 627 res.setSystem(l.getSystem()); 628 } 629 if (l.hasVersion() && l.getVersion().equals(r.getVersion())) { 630 res.setVersion(l.getVersion()); 631 } 632 if (l.hasCode() && l.getCode().equals(r.getCode())) { 633 res.setCode(l.getCode()); 634 } 635 if (l.hasDisplay() && l.getDisplay().equals(r.getDisplay())) { 636 res.setDisplay(l.getDisplay()); 637 } 638 if (l.hasUserSelected() && l.getUserSelected() == r.getUserSelected()) { 639 res.setUserSelected(l.getUserSelected()); 640 } 641 return res; 642 } 643 644 public Coding(String theSystem, String theVersion, String theCode, String theDisplay) { 645 setSystem(theSystem); 646 setVersion(theVersion); 647 setCode(theCode); 648 setDisplay(theDisplay); 649 } 650// end addition 651 652 public Coding(ValueSetExpansionContainsComponent cc) { 653 super(); 654 setSystem(cc.getSystem()); 655 setVersion(cc.getVersion()); 656 setCode(cc.getCode()); 657 setDisplay(cc.getDisplay()); 658 } 659 660 public String getVersionedSystem() { 661 return hasVersion() ? getSystem()+"|"+getVersion() : getSystem(); 662 } 663 664} 665