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