001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
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 {
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> childrenList) {
348        super.listChildren(childrenList);
349        childrenList.add(new Property("system", "uri", "The identification of the code system that defines the meaning of the symbol in the code.", 0, java.lang.Integer.MAX_VALUE, system));
350        childrenList.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, java.lang.Integer.MAX_VALUE, version));
351        childrenList.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, java.lang.Integer.MAX_VALUE, code));
352        childrenList.add(new Property("display", "string", "A representation of the meaning of the code in the system, following the rules of the system.", 0, java.lang.Integer.MAX_VALUE, display));
353        childrenList.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, java.lang.Integer.MAX_VALUE, userSelected));
354      }
355
356      @Override
357      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
358        switch (hash) {
359        case -887328209: /*system*/ return this.system == null ? new Base[0] : new Base[] {this.system}; // UriType
360        case 351608024: /*version*/ return this.version == null ? new Base[0] : new Base[] {this.version}; // StringType
361        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeType
362        case 1671764162: /*display*/ return this.display == null ? new Base[0] : new Base[] {this.display}; // StringType
363        case 423643014: /*userSelected*/ return this.userSelected == null ? new Base[0] : new Base[] {this.userSelected}; // BooleanType
364        default: return super.getProperty(hash, name, checkValid);
365        }
366
367      }
368
369      @Override
370      public Base setProperty(int hash, String name, Base value) throws FHIRException {
371        switch (hash) {
372        case -887328209: // system
373          this.system = castToUri(value); // UriType
374          return value;
375        case 351608024: // version
376          this.version = castToString(value); // StringType
377          return value;
378        case 3059181: // code
379          this.code = castToCode(value); // CodeType
380          return value;
381        case 1671764162: // display
382          this.display = castToString(value); // StringType
383          return value;
384        case 423643014: // userSelected
385          this.userSelected = castToBoolean(value); // BooleanType
386          return value;
387        default: return super.setProperty(hash, name, value);
388        }
389
390      }
391
392      @Override
393      public Base setProperty(String name, Base value) throws FHIRException {
394        if (name.equals("system")) {
395          this.system = castToUri(value); // UriType
396        } else if (name.equals("version")) {
397          this.version = castToString(value); // StringType
398        } else if (name.equals("code")) {
399          this.code = castToCode(value); // CodeType
400        } else if (name.equals("display")) {
401          this.display = castToString(value); // StringType
402        } else if (name.equals("userSelected")) {
403          this.userSelected = castToBoolean(value); // BooleanType
404        } else
405          return super.setProperty(name, value);
406        return value;
407      }
408
409      @Override
410      public Base makeProperty(int hash, String name) throws FHIRException {
411        switch (hash) {
412        case -887328209:  return getSystemElement();
413        case 351608024:  return getVersionElement();
414        case 3059181:  return getCodeElement();
415        case 1671764162:  return getDisplayElement();
416        case 423643014:  return getUserSelectedElement();
417        default: return super.makeProperty(hash, name);
418        }
419
420      }
421
422      @Override
423      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
424        switch (hash) {
425        case -887328209: /*system*/ return new String[] {"uri"};
426        case 351608024: /*version*/ return new String[] {"string"};
427        case 3059181: /*code*/ return new String[] {"code"};
428        case 1671764162: /*display*/ return new String[] {"string"};
429        case 423643014: /*userSelected*/ return new String[] {"boolean"};
430        default: return super.getTypesForProperty(hash, name);
431        }
432
433      }
434
435      @Override
436      public Base addChild(String name) throws FHIRException {
437        if (name.equals("system")) {
438          throw new FHIRException("Cannot call addChild on a primitive type Coding.system");
439        }
440        else if (name.equals("version")) {
441          throw new FHIRException("Cannot call addChild on a primitive type Coding.version");
442        }
443        else if (name.equals("code")) {
444          throw new FHIRException("Cannot call addChild on a primitive type Coding.code");
445        }
446        else if (name.equals("display")) {
447          throw new FHIRException("Cannot call addChild on a primitive type Coding.display");
448        }
449        else if (name.equals("userSelected")) {
450          throw new FHIRException("Cannot call addChild on a primitive type Coding.userSelected");
451        }
452        else
453          return super.addChild(name);
454      }
455
456  public String fhirType() {
457    return "Coding";
458
459  }
460
461      public Coding copy() {
462        Coding dst = new Coding();
463        copyValues(dst);
464        dst.system = system == null ? null : system.copy();
465        dst.version = version == null ? null : version.copy();
466        dst.code = code == null ? null : code.copy();
467        dst.display = display == null ? null : display.copy();
468        dst.userSelected = userSelected == null ? null : userSelected.copy();
469        return dst;
470      }
471
472      protected Coding typedCopy() {
473        return copy();
474      }
475
476      @Override
477      public boolean equalsDeep(Base other) {
478        if (!super.equalsDeep(other))
479          return false;
480        if (!(other instanceof Coding))
481          return false;
482        Coding o = (Coding) other;
483        return compareDeep(system, o.system, true) && compareDeep(version, o.version, true) && compareDeep(code, o.code, true)
484           && compareDeep(display, o.display, true) && compareDeep(userSelected, o.userSelected, true);
485      }
486
487      @Override
488      public boolean equalsShallow(Base other) {
489        if (!super.equalsShallow(other))
490          return false;
491        if (!(other instanceof Coding))
492          return false;
493        Coding o = (Coding) other;
494        return compareValues(system, o.system, true) && compareValues(version, o.version, true) && compareValues(code, o.code, true)
495           && compareValues(display, o.display, true) && compareValues(userSelected, o.userSelected, true);
496      }
497
498      public boolean isEmpty() {
499        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(system, version, code, display
500          , userSelected);
501      }
502
503
504}
505