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 reference to a code defined by a terminology system.
049 */
050@DatatypeDef(name="Coding")
051public class Coding extends Type implements IBaseCoding, ICompositeType, ICoding {
052
053    /**
054     * The identification of the code system that defines the meaning of the symbol in the code.
055     */
056    @Child(name = "system", type = {UriType.class}, order=0, min=0, max=1, modifier=false, summary=true)
057    @Description(shortDefinition="Identity of the terminology system", formalDefinition="The identification of the code system that defines the meaning of the symbol in the code." )
058    protected UriType system;
059
060    /**
061     * 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.
062     */
063    @Child(name = "version", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
064    @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." )
065    protected StringType version;
066
067    /**
068     * 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).
069     */
070    @Child(name = "code", type = {CodeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
071    @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)." )
072    protected CodeType code;
073
074    /**
075     * A representation of the meaning of the code in the system, following the rules of the system.
076     */
077    @Child(name = "display", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
078    @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." )
079    protected StringType display;
080
081    /**
082     * Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).
083     */
084    @Child(name = "userSelected", type = {BooleanType.class}, order=4, min=0, max=1, modifier=false, summary=true)
085    @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)." )
086    protected BooleanType userSelected;
087
088    private static final long serialVersionUID = -1417514061L;
089
090  /**
091   * Constructor
092   */
093    public Coding() {
094      super();
095    }
096
097    /**
098     * Convenience constructor
099     * 
100     * @param theSystem The {@link #setSystem(String) code system}
101     * @param theCode The {@link #setCode(String) code}
102     * @param theDisplay The {@link #setDisplay(String) human readable display}
103     */
104      public Coding(String theSystem, String theCode, String theDisplay) {
105        setSystem(theSystem);
106        setCode(theCode);
107        setDisplay(theDisplay);
108      }
109    /**
110     * @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
111     */
112    public UriType getSystemElement() { 
113      if (this.system == null)
114        if (Configuration.errorOnAutoCreate())
115          throw new Error("Attempt to auto-create Coding.system");
116        else if (Configuration.doAutoCreate())
117          this.system = new UriType(); // bb
118      return this.system;
119    }
120
121    public boolean hasSystemElement() { 
122      return this.system != null && !this.system.isEmpty();
123    }
124
125    public boolean hasSystem() { 
126      return this.system != null && !this.system.isEmpty();
127    }
128
129    /**
130     * @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
131     */
132    public Coding setSystemElement(UriType value) { 
133      this.system = value;
134      return this;
135    }
136
137    /**
138     * @return The identification of the code system that defines the meaning of the symbol in the code.
139     */
140    public String getSystem() { 
141      return this.system == null ? null : this.system.getValue();
142    }
143
144    /**
145     * @param value The identification of the code system that defines the meaning of the symbol in the code.
146     */
147    public Coding setSystem(String value) { 
148      if (Utilities.noString(value))
149        this.system = null;
150      else {
151        if (this.system == null)
152          this.system = new UriType();
153        this.system.setValue(value);
154      }
155      return this;
156    }
157
158    /**
159     * @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
160     */
161    public StringType getVersionElement() { 
162      if (this.version == null)
163        if (Configuration.errorOnAutoCreate())
164          throw new Error("Attempt to auto-create Coding.version");
165        else if (Configuration.doAutoCreate())
166          this.version = new StringType(); // bb
167      return this.version;
168    }
169
170    public boolean hasVersionElement() { 
171      return this.version != null && !this.version.isEmpty();
172    }
173
174    public boolean hasVersion() { 
175      return this.version != null && !this.version.isEmpty();
176    }
177
178    /**
179     * @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
180     */
181    public Coding setVersionElement(StringType value) { 
182      this.version = value;
183      return this;
184    }
185
186    /**
187     * @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.
188     */
189    public String getVersion() { 
190      return this.version == null ? null : this.version.getValue();
191    }
192
193    /**
194     * @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.
195     */
196    public Coding setVersion(String value) { 
197      if (Utilities.noString(value))
198        this.version = null;
199      else {
200        if (this.version == null)
201          this.version = new StringType();
202        this.version.setValue(value);
203      }
204      return this;
205    }
206
207    /**
208     * @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
209     */
210    public CodeType getCodeElement() { 
211      if (this.code == null)
212        if (Configuration.errorOnAutoCreate())
213          throw new Error("Attempt to auto-create Coding.code");
214        else if (Configuration.doAutoCreate())
215          this.code = new CodeType(); // bb
216      return this.code;
217    }
218
219    public boolean hasCodeElement() { 
220      return this.code != null && !this.code.isEmpty();
221    }
222
223    public boolean hasCode() { 
224      return this.code != null && !this.code.isEmpty();
225    }
226
227    /**
228     * @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
229     */
230    public Coding setCodeElement(CodeType value) { 
231      this.code = value;
232      return this;
233    }
234
235    /**
236     * @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).
237     */
238    public String getCode() { 
239      return this.code == null ? null : this.code.getValue();
240    }
241
242    /**
243     * @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).
244     */
245    public Coding setCode(String value) { 
246      if (Utilities.noString(value))
247        this.code = null;
248      else {
249        if (this.code == null)
250          this.code = new CodeType();
251        this.code.setValue(value);
252      }
253      return this;
254    }
255
256    /**
257     * @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
258     */
259    public StringType getDisplayElement() { 
260      if (this.display == null)
261        if (Configuration.errorOnAutoCreate())
262          throw new Error("Attempt to auto-create Coding.display");
263        else if (Configuration.doAutoCreate())
264          this.display = new StringType(); // bb
265      return this.display;
266    }
267
268    public boolean hasDisplayElement() { 
269      return this.display != null && !this.display.isEmpty();
270    }
271
272    public boolean hasDisplay() { 
273      return this.display != null && !this.display.isEmpty();
274    }
275
276    /**
277     * @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
278     */
279    public Coding setDisplayElement(StringType value) { 
280      this.display = value;
281      return this;
282    }
283
284    /**
285     * @return A representation of the meaning of the code in the system, following the rules of the system.
286     */
287    public String getDisplay() { 
288      return this.display == null ? null : this.display.getValue();
289    }
290
291    /**
292     * @param value A representation of the meaning of the code in the system, following the rules of the system.
293     */
294    public Coding setDisplay(String value) { 
295      if (Utilities.noString(value))
296        this.display = null;
297      else {
298        if (this.display == null)
299          this.display = new StringType();
300        this.display.setValue(value);
301      }
302      return this;
303    }
304
305    /**
306     * @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
307     */
308    public BooleanType getUserSelectedElement() { 
309      if (this.userSelected == null)
310        if (Configuration.errorOnAutoCreate())
311          throw new Error("Attempt to auto-create Coding.userSelected");
312        else if (Configuration.doAutoCreate())
313          this.userSelected = new BooleanType(); // bb
314      return this.userSelected;
315    }
316
317    public boolean hasUserSelectedElement() { 
318      return this.userSelected != null && !this.userSelected.isEmpty();
319    }
320
321    public boolean hasUserSelected() { 
322      return this.userSelected != null && !this.userSelected.isEmpty();
323    }
324
325    /**
326     * @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
327     */
328    public Coding setUserSelectedElement(BooleanType value) { 
329      this.userSelected = value;
330      return this;
331    }
332
333    /**
334     * @return Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).
335     */
336    public boolean getUserSelected() { 
337      return this.userSelected == null || this.userSelected.isEmpty() ? false : this.userSelected.getValue();
338    }
339
340    /**
341     * @param value Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).
342     */
343    public Coding setUserSelected(boolean value) { 
344        if (this.userSelected == null)
345          this.userSelected = new BooleanType();
346        this.userSelected.setValue(value);
347      return this;
348    }
349
350      protected void listChildren(List<Property> children) {
351        super.listChildren(children);
352        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));
353        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));
354        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));
355        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));
356        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));
357      }
358
359      @Override
360      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
361        switch (_hash) {
362        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);
363        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);
364        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);
365        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);
366        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);
367        default: return super.getNamedProperty(_hash, _name, _checkValid);
368        }
369
370      }
371
372      @Override
373      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
374        switch (hash) {
375        case -887328209: /*system*/ return this.system == null ? new Base[0] : new Base[] {this.system}; // UriType
376        case 351608024: /*version*/ return this.version == null ? new Base[0] : new Base[] {this.version}; // StringType
377        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeType
378        case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType
379        case 423643014: /*userSelected*/ return this.userSelected == null ? new Base[0] : new Base[] {this.userSelected}; // BooleanType
380        default: return super.getProperty(hash, name, checkValid);
381        }
382
383      }
384
385      @Override
386      public Base setProperty(int hash, String name, Base value) throws FHIRException {
387        switch (hash) {
388        case -887328209: // system
389          this.system = castToUri(value); // UriType
390          return value;
391        case 351608024: // version
392          this.version = castToString(value); // StringType
393          return value;
394        case 3059181: // code
395          this.code = castToCode(value); // CodeType
396          return value;
397        case 1671764162: // display
398          this.display = castToString(value); // StringType
399          return value;
400        case 423643014: // userSelected
401          this.userSelected = castToBoolean(value); // BooleanType
402          return value;
403        default: return super.setProperty(hash, name, value);
404        }
405
406      }
407
408      @Override
409      public Base setProperty(String name, Base value) throws FHIRException {
410        if (name.equals("system")) {
411          this.system = castToUri(value); // UriType
412        } else if (name.equals("version")) {
413          this.version = castToString(value); // StringType
414        } else if (name.equals("code")) {
415          this.code = castToCode(value); // CodeType
416        } else if (name.equals("display")) {
417          this.display = castToString(value); // StringType
418        } else if (name.equals("userSelected")) {
419          this.userSelected = castToBoolean(value); // BooleanType
420        } else
421          return super.setProperty(name, value);
422        return value;
423      }
424
425      @Override
426      public Base makeProperty(int hash, String name) throws FHIRException {
427        switch (hash) {
428        case -887328209:  return getSystemElement();
429        case 351608024:  return getVersionElement();
430        case 3059181:  return getCodeElement();
431        case 1671764162:  return getDisplayElement();
432        case 423643014:  return getUserSelectedElement();
433        default: return super.makeProperty(hash, name);
434        }
435
436      }
437
438      @Override
439      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
440        switch (hash) {
441        case -887328209: /*system*/ return new String[] {"uri"};
442        case 351608024: /*version*/ return new String[] {"string"};
443        case 3059181: /*code*/ return new String[] {"code"};
444        case 1671764162: /*display*/ return new String[] {"string"};
445        case 423643014: /*userSelected*/ return new String[] {"boolean"};
446        default: return super.getTypesForProperty(hash, name);
447        }
448
449      }
450
451      @Override
452      public Base addChild(String name) throws FHIRException {
453        if (name.equals("system")) {
454          throw new FHIRException("Cannot call addChild on a primitive type Coding.system");
455        }
456        else if (name.equals("version")) {
457          throw new FHIRException("Cannot call addChild on a primitive type Coding.version");
458        }
459        else if (name.equals("code")) {
460          throw new FHIRException("Cannot call addChild on a primitive type Coding.code");
461        }
462        else if (name.equals("display")) {
463          throw new FHIRException("Cannot call addChild on a primitive type Coding.display");
464        }
465        else if (name.equals("userSelected")) {
466          throw new FHIRException("Cannot call addChild on a primitive type Coding.userSelected");
467        }
468        else
469          return super.addChild(name);
470      }
471
472  public String fhirType() {
473    return "Coding";
474
475  }
476
477      public Coding copy() {
478        Coding dst = new Coding();
479        copyValues(dst);
480        return dst;
481      }
482
483      public void copyValues(Coding dst) {
484        super.copyValues(dst);
485        dst.system = system == null ? null : system.copy();
486        dst.version = version == null ? null : version.copy();
487        dst.code = code == null ? null : code.copy();
488        dst.display = display == null ? null : display.copy();
489        dst.userSelected = userSelected == null ? null : userSelected.copy();
490      }
491
492      protected Coding typedCopy() {
493        return copy();
494      }
495
496      @Override
497      public boolean equalsDeep(Base other_) {
498        if (!super.equalsDeep(other_))
499          return false;
500        if (!(other_ instanceof Coding))
501          return false;
502        Coding o = (Coding) other_;
503        return compareDeep(system, o.system, true) && compareDeep(version, o.version, true) && compareDeep(code, o.code, true)
504           && compareDeep(display, o.display, true) && compareDeep(userSelected, o.userSelected, true);
505      }
506
507      @Override
508      public boolean equalsShallow(Base other_) {
509        if (!super.equalsShallow(other_))
510          return false;
511        if (!(other_ instanceof Coding))
512          return false;
513        Coding o = (Coding) other_;
514        return compareValues(system, o.system, true) && compareValues(version, o.version, true) && compareValues(code, o.code, true)
515           && compareValues(display, o.display, true) && compareValues(userSelected, o.userSelected, true);
516      }
517
518      public boolean isEmpty() {
519        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(system, version, code, display
520          , userSelected);
521      }
522
523// added from java-adornments.txt:
524      @Override
525      public boolean supportsVersion() {
526        return true;
527      }
528
529      @Override
530      public boolean supportsDisplay() {
531        return true;
532      }
533
534
535      public boolean is(String system, String code) {
536        return hasSystem() && hasCode() &&  this.getSystem().equals(system) && this.getCode().equals(code);
537      }
538      
539
540// end addition
541
542}