001package org.hl7.fhir.r4.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 6, 2018 17:51-0400 for FHIR v3.4.0
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * A reference to a code defined by a terminology system.
046 */
047@DatatypeDef(name="Coding")
048public class Coding extends Type implements IBaseCoding, ICompositeType, ICoding {
049
050    /**
051     * The identification of the code system that defines the meaning of the symbol in the code.
052     */
053    @Child(name = "system", type = {UriType.class}, order=0, min=0, max=1, modifier=false, summary=true)
054    @Description(shortDefinition="Identity of the terminology system", formalDefinition="The identification of the code system that defines the meaning of the symbol in the code." )
055    protected UriType system;
056
057    /**
058     * 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.
059     */
060    @Child(name = "version", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
061    @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." )
062    protected StringType version;
063
064    /**
065     * 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).
066     */
067    @Child(name = "code", type = {CodeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
068    @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)." )
069    protected CodeType code;
070
071    /**
072     * A representation of the meaning of the code in the system, following the rules of the system.
073     */
074    @Child(name = "display", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
075    @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." )
076    protected StringType display;
077
078    /**
079     * Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
080     */
081    @Child(name = "userSelected", type = {BooleanType.class}, order=4, min=0, max=1, modifier=false, summary=true)
082    @Description(shortDefinition="If this coding was chosen directly by the user", formalDefinition="Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays)." )
083    protected BooleanType userSelected;
084
085    private static final long serialVersionUID = -1417514061L;
086
087  /**
088   * Constructor
089   */
090    public Coding() {
091      super();
092    }
093
094    /**
095     * Convenience constructor
096     * 
097     * @param theSystem The {@link #setSystem(String) code system}
098     * @param theCode The {@link #setCode(String) code}
099     * @param theDisplay The {@link #setDisplay(String) human readable display}
100     */
101      public Coding(String theSystem, String theCode, String theDisplay) {
102        setSystem(theSystem);
103        setCode(theCode);
104        setDisplay(theDisplay);
105      }
106    /**
107     * @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
108     */
109    public UriType getSystemElement() { 
110      if (this.system == null)
111        if (Configuration.errorOnAutoCreate())
112          throw new Error("Attempt to auto-create Coding.system");
113        else if (Configuration.doAutoCreate())
114          this.system = new UriType(); // bb
115      return this.system;
116    }
117
118    public boolean hasSystemElement() { 
119      return this.system != null && !this.system.isEmpty();
120    }
121
122    public boolean hasSystem() { 
123      return this.system != null && !this.system.isEmpty();
124    }
125
126    /**
127     * @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
128     */
129    public Coding setSystemElement(UriType value) { 
130      this.system = value;
131      return this;
132    }
133
134    /**
135     * @return The identification of the code system that defines the meaning of the symbol in the code.
136     */
137    public String getSystem() { 
138      return this.system == null ? null : this.system.getValue();
139    }
140
141    /**
142     * @param value The identification of the code system that defines the meaning of the symbol in the code.
143     */
144    public Coding setSystem(String value) { 
145      if (Utilities.noString(value))
146        this.system = null;
147      else {
148        if (this.system == null)
149          this.system = new UriType();
150        this.system.setValue(value);
151      }
152      return this;
153    }
154
155    /**
156     * @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
157     */
158    public StringType getVersionElement() { 
159      if (this.version == null)
160        if (Configuration.errorOnAutoCreate())
161          throw new Error("Attempt to auto-create Coding.version");
162        else if (Configuration.doAutoCreate())
163          this.version = new StringType(); // bb
164      return this.version;
165    }
166
167    public boolean hasVersionElement() { 
168      return this.version != null && !this.version.isEmpty();
169    }
170
171    public boolean hasVersion() { 
172      return this.version != null && !this.version.isEmpty();
173    }
174
175    /**
176     * @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
177     */
178    public Coding setVersionElement(StringType value) { 
179      this.version = value;
180      return this;
181    }
182
183    /**
184     * @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.
185     */
186    public String getVersion() { 
187      return this.version == null ? null : this.version.getValue();
188    }
189
190    /**
191     * @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.
192     */
193    public Coding setVersion(String value) { 
194      if (Utilities.noString(value))
195        this.version = null;
196      else {
197        if (this.version == null)
198          this.version = new StringType();
199        this.version.setValue(value);
200      }
201      return this;
202    }
203
204    /**
205     * @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
206     */
207    public CodeType getCodeElement() { 
208      if (this.code == null)
209        if (Configuration.errorOnAutoCreate())
210          throw new Error("Attempt to auto-create Coding.code");
211        else if (Configuration.doAutoCreate())
212          this.code = new CodeType(); // bb
213      return this.code;
214    }
215
216    public boolean hasCodeElement() { 
217      return this.code != null && !this.code.isEmpty();
218    }
219
220    public boolean hasCode() { 
221      return this.code != null && !this.code.isEmpty();
222    }
223
224    /**
225     * @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
226     */
227    public Coding setCodeElement(CodeType value) { 
228      this.code = value;
229      return this;
230    }
231
232    /**
233     * @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).
234     */
235    public String getCode() { 
236      return this.code == null ? null : this.code.getValue();
237    }
238
239    /**
240     * @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).
241     */
242    public Coding setCode(String value) { 
243      if (Utilities.noString(value))
244        this.code = null;
245      else {
246        if (this.code == null)
247          this.code = new CodeType();
248        this.code.setValue(value);
249      }
250      return this;
251    }
252
253    /**
254     * @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
255     */
256    public StringType getDisplayElement() { 
257      if (this.display == null)
258        if (Configuration.errorOnAutoCreate())
259          throw new Error("Attempt to auto-create Coding.display");
260        else if (Configuration.doAutoCreate())
261          this.display = new StringType(); // bb
262      return this.display;
263    }
264
265    public boolean hasDisplayElement() { 
266      return this.display != null && !this.display.isEmpty();
267    }
268
269    public boolean hasDisplay() { 
270      return this.display != null && !this.display.isEmpty();
271    }
272
273    /**
274     * @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
275     */
276    public Coding setDisplayElement(StringType value) { 
277      this.display = value;
278      return this;
279    }
280
281    /**
282     * @return A representation of the meaning of the code in the system, following the rules of the system.
283     */
284    public String getDisplay() { 
285      return this.display == null ? null : this.display.getValue();
286    }
287
288    /**
289     * @param value A representation of the meaning of the code in the system, following the rules of the system.
290     */
291    public Coding setDisplay(String value) { 
292      if (Utilities.noString(value))
293        this.display = null;
294      else {
295        if (this.display == null)
296          this.display = new StringType();
297        this.display.setValue(value);
298      }
299      return this;
300    }
301
302    /**
303     * @return {@link #userSelected} (Indicates that this coding was chosen by a user directly - i.e. 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
304     */
305    public BooleanType getUserSelectedElement() { 
306      if (this.userSelected == null)
307        if (Configuration.errorOnAutoCreate())
308          throw new Error("Attempt to auto-create Coding.userSelected");
309        else if (Configuration.doAutoCreate())
310          this.userSelected = new BooleanType(); // bb
311      return this.userSelected;
312    }
313
314    public boolean hasUserSelectedElement() { 
315      return this.userSelected != null && !this.userSelected.isEmpty();
316    }
317
318    public boolean hasUserSelected() { 
319      return this.userSelected != null && !this.userSelected.isEmpty();
320    }
321
322    /**
323     * @param value {@link #userSelected} (Indicates that this coding was chosen by a user directly - i.e. 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
324     */
325    public Coding setUserSelectedElement(BooleanType value) { 
326      this.userSelected = value;
327      return this;
328    }
329
330    /**
331     * @return Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
332     */
333    public boolean getUserSelected() { 
334      return this.userSelected == null || this.userSelected.isEmpty() ? false : this.userSelected.getValue();
335    }
336
337    /**
338     * @param value Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
339     */
340    public Coding setUserSelected(boolean value) { 
341        if (this.userSelected == null)
342          this.userSelected = new BooleanType();
343        this.userSelected.setValue(value);
344      return this;
345    }
346
347      protected void listChildren(List<Property> children) {
348        super.listChildren(children);
349        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));
350        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));
351        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));
352        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));
353        children.add(new Property("userSelected", "boolean", "Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).", 0, 1, userSelected));
354      }
355
356      @Override
357      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
358        switch (_hash) {
359        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);
360        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);
361        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);
362        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);
363        case 423643014: /*userSelected*/  return new Property("userSelected", "boolean", "Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).", 0, 1, userSelected);
364        default: return super.getNamedProperty(_hash, _name, _checkValid);
365        }
366
367      }
368
369      @Override
370      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
371        switch (hash) {
372        case -887328209: /*system*/ return this.system == null ? new Base[0] : new Base[] {this.system}; // UriType
373        case 351608024: /*version*/ return this.version == null ? new Base[0] : new Base[] {this.version}; // StringType
374        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeType
375        case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType
376        case 423643014: /*userSelected*/ return this.userSelected == null ? new Base[0] : new Base[] {this.userSelected}; // BooleanType
377        default: return super.getProperty(hash, name, checkValid);
378        }
379
380      }
381
382      @Override
383      public Base setProperty(int hash, String name, Base value) throws FHIRException {
384        switch (hash) {
385        case -887328209: // system
386          this.system = castToUri(value); // UriType
387          return value;
388        case 351608024: // version
389          this.version = castToString(value); // StringType
390          return value;
391        case 3059181: // code
392          this.code = castToCode(value); // CodeType
393          return value;
394        case 1671764162: // display
395          this.display = castToString(value); // StringType
396          return value;
397        case 423643014: // userSelected
398          this.userSelected = castToBoolean(value); // BooleanType
399          return value;
400        default: return super.setProperty(hash, name, value);
401        }
402
403      }
404
405      @Override
406      public Base setProperty(String name, Base value) throws FHIRException {
407        if (name.equals("system")) {
408          this.system = castToUri(value); // UriType
409        } else if (name.equals("version")) {
410          this.version = castToString(value); // StringType
411        } else if (name.equals("code")) {
412          this.code = castToCode(value); // CodeType
413        } else if (name.equals("display")) {
414          this.display = castToString(value); // StringType
415        } else if (name.equals("userSelected")) {
416          this.userSelected = castToBoolean(value); // BooleanType
417        } else
418          return super.setProperty(name, value);
419        return value;
420      }
421
422      @Override
423      public Base makeProperty(int hash, String name) throws FHIRException {
424        switch (hash) {
425        case -887328209:  return getSystemElement();
426        case 351608024:  return getVersionElement();
427        case 3059181:  return getCodeElement();
428        case 1671764162:  return getDisplayElement();
429        case 423643014:  return getUserSelectedElement();
430        default: return super.makeProperty(hash, name);
431        }
432
433      }
434
435      @Override
436      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
437        switch (hash) {
438        case -887328209: /*system*/ return new String[] {"uri"};
439        case 351608024: /*version*/ return new String[] {"string"};
440        case 3059181: /*code*/ return new String[] {"code"};
441        case 1671764162: /*display*/ return new String[] {"string"};
442        case 423643014: /*userSelected*/ return new String[] {"boolean"};
443        default: return super.getTypesForProperty(hash, name);
444        }
445
446      }
447
448      @Override
449      public Base addChild(String name) throws FHIRException {
450        if (name.equals("system")) {
451          throw new FHIRException("Cannot call addChild on a primitive type Coding.system");
452        }
453        else if (name.equals("version")) {
454          throw new FHIRException("Cannot call addChild on a primitive type Coding.version");
455        }
456        else if (name.equals("code")) {
457          throw new FHIRException("Cannot call addChild on a primitive type Coding.code");
458        }
459        else if (name.equals("display")) {
460          throw new FHIRException("Cannot call addChild on a primitive type Coding.display");
461        }
462        else if (name.equals("userSelected")) {
463          throw new FHIRException("Cannot call addChild on a primitive type Coding.userSelected");
464        }
465        else
466          return super.addChild(name);
467      }
468
469  public String fhirType() {
470    return "Coding";
471
472  }
473
474      public Coding copy() {
475        Coding dst = new Coding();
476        copyValues(dst);
477        dst.system = system == null ? null : system.copy();
478        dst.version = version == null ? null : version.copy();
479        dst.code = code == null ? null : code.copy();
480        dst.display = display == null ? null : display.copy();
481        dst.userSelected = userSelected == null ? null : userSelected.copy();
482        return dst;
483      }
484
485      protected Coding typedCopy() {
486        return copy();
487      }
488
489      @Override
490      public boolean equalsDeep(Base other_) {
491        if (!super.equalsDeep(other_))
492          return false;
493        if (!(other_ instanceof Coding))
494          return false;
495        Coding o = (Coding) other_;
496        return compareDeep(system, o.system, true) && compareDeep(version, o.version, true) && compareDeep(code, o.code, true)
497           && compareDeep(display, o.display, true) && compareDeep(userSelected, o.userSelected, true);
498      }
499
500      @Override
501      public boolean equalsShallow(Base other_) {
502        if (!super.equalsShallow(other_))
503          return false;
504        if (!(other_ instanceof Coding))
505          return false;
506        Coding o = (Coding) other_;
507        return compareValues(system, o.system, true) && compareValues(version, o.version, true) && compareValues(code, o.code, true)
508           && compareValues(display, o.display, true) && compareValues(userSelected, o.userSelected, true);
509      }
510
511      public boolean isEmpty() {
512        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(system, version, code, display
513          , userSelected);
514      }
515
516// added from java-adornments.txt:
517      @Override
518      public boolean supportsVersion() {
519        return true;
520      }
521
522      @Override
523      public boolean supportsDisplay() {
524        return true;
525      }
526
527
528      public boolean is(String system, String code) {
529        return hasSystem() && hasCode() &&  this.getSystem().equals(system) && this.getCode().equals(code);
530      }
531      
532
533// end addition
534
535}
536