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