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