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