001package org.hl7.fhir.instance.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
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.*;
041/**
042 * A reference to a code defined by a terminology system.
043 */
044@DatatypeDef(name="Coding")
045public class Coding extends Type implements IBaseCoding, ICompositeType {
046
047    /**
048     * The identification of the code system that defines the meaning of the symbol in the code.
049     */
050    @Child(name = "system", type = {UriType.class}, order=0, min=0, max=1, modifier=false, summary=true)
051    @Description(shortDefinition="Identity of the terminology system", formalDefinition="The identification of the code system that defines the meaning of the symbol in the code." )
052    protected UriType system;
053
054    /**
055     * 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.
056     */
057    @Child(name = "version", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
058    @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." )
059    protected StringType version;
060
061    /**
062     * 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).
063     */
064    @Child(name = "code", type = {CodeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
065    @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)." )
066    protected CodeType code;
067
068    /**
069     * A representation of the meaning of the code in the system, following the rules of the system.
070     */
071    @Child(name = "display", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
072    @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." )
073    protected StringType display;
074
075    /**
076     * Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
077     */
078    @Child(name = "userSelected", type = {BooleanType.class}, order=4, min=0, max=1, modifier=false, summary=true)
079    @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)." )
080    protected BooleanType userSelected;
081
082    private static final long serialVersionUID = -1417514061L;
083
084  /*
085   * Constructor
086   */
087    public Coding() {
088      super();
089    }
090
091    /**
092     * @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
093     */
094    public UriType getSystemElement() { 
095      if (this.system == null)
096        if (Configuration.errorOnAutoCreate())
097          throw new Error("Attempt to auto-create Coding.system");
098        else if (Configuration.doAutoCreate())
099          this.system = new UriType(); // bb
100      return this.system;
101    }
102
103    public boolean hasSystemElement() { 
104      return this.system != null && !this.system.isEmpty();
105    }
106
107    public boolean hasSystem() { 
108      return this.system != null && !this.system.isEmpty();
109    }
110
111    /**
112     * @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
113     */
114    public Coding setSystemElement(UriType value) { 
115      this.system = value;
116      return this;
117    }
118
119    /**
120     * @return The identification of the code system that defines the meaning of the symbol in the code.
121     */
122    public String getSystem() { 
123      return this.system == null ? null : this.system.getValue();
124    }
125
126    /**
127     * @param value The identification of the code system that defines the meaning of the symbol in the code.
128     */
129    public Coding setSystem(String value) { 
130      if (Utilities.noString(value))
131        this.system = null;
132      else {
133        if (this.system == null)
134          this.system = new UriType();
135        this.system.setValue(value);
136      }
137      return this;
138    }
139
140    /**
141     * @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
142     */
143    public StringType getVersionElement() { 
144      if (this.version == null)
145        if (Configuration.errorOnAutoCreate())
146          throw new Error("Attempt to auto-create Coding.version");
147        else if (Configuration.doAutoCreate())
148          this.version = new StringType(); // bb
149      return this.version;
150    }
151
152    public boolean hasVersionElement() { 
153      return this.version != null && !this.version.isEmpty();
154    }
155
156    public boolean hasVersion() { 
157      return this.version != null && !this.version.isEmpty();
158    }
159
160    /**
161     * @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
162     */
163    public Coding setVersionElement(StringType value) { 
164      this.version = value;
165      return this;
166    }
167
168    /**
169     * @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.
170     */
171    public String getVersion() { 
172      return this.version == null ? null : this.version.getValue();
173    }
174
175    /**
176     * @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.
177     */
178    public Coding setVersion(String value) { 
179      if (Utilities.noString(value))
180        this.version = null;
181      else {
182        if (this.version == null)
183          this.version = new StringType();
184        this.version.setValue(value);
185      }
186      return this;
187    }
188
189    /**
190     * @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
191     */
192    public CodeType getCodeElement() { 
193      if (this.code == null)
194        if (Configuration.errorOnAutoCreate())
195          throw new Error("Attempt to auto-create Coding.code");
196        else if (Configuration.doAutoCreate())
197          this.code = new CodeType(); // bb
198      return this.code;
199    }
200
201    public boolean hasCodeElement() { 
202      return this.code != null && !this.code.isEmpty();
203    }
204
205    public boolean hasCode() { 
206      return this.code != null && !this.code.isEmpty();
207    }
208
209    /**
210     * @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
211     */
212    public Coding setCodeElement(CodeType value) { 
213      this.code = value;
214      return this;
215    }
216
217    /**
218     * @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).
219     */
220    public String getCode() { 
221      return this.code == null ? null : this.code.getValue();
222    }
223
224    /**
225     * @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).
226     */
227    public Coding setCode(String value) { 
228      if (Utilities.noString(value))
229        this.code = null;
230      else {
231        if (this.code == null)
232          this.code = new CodeType();
233        this.code.setValue(value);
234      }
235      return this;
236    }
237
238    /**
239     * @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
240     */
241    public StringType getDisplayElement() { 
242      if (this.display == null)
243        if (Configuration.errorOnAutoCreate())
244          throw new Error("Attempt to auto-create Coding.display");
245        else if (Configuration.doAutoCreate())
246          this.display = new StringType(); // bb
247      return this.display;
248    }
249
250    public boolean hasDisplayElement() { 
251      return this.display != null && !this.display.isEmpty();
252    }
253
254    public boolean hasDisplay() { 
255      return this.display != null && !this.display.isEmpty();
256    }
257
258    /**
259     * @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
260     */
261    public Coding setDisplayElement(StringType value) { 
262      this.display = value;
263      return this;
264    }
265
266    /**
267     * @return A representation of the meaning of the code in the system, following the rules of the system.
268     */
269    public String getDisplay() { 
270      return this.display == null ? null : this.display.getValue();
271    }
272
273    /**
274     * @param value A representation of the meaning of the code in the system, following the rules of the system.
275     */
276    public Coding setDisplay(String value) { 
277      if (Utilities.noString(value))
278        this.display = null;
279      else {
280        if (this.display == null)
281          this.display = new StringType();
282        this.display.setValue(value);
283      }
284      return this;
285    }
286
287    /**
288     * @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
289     */
290    public BooleanType getUserSelectedElement() { 
291      if (this.userSelected == null)
292        if (Configuration.errorOnAutoCreate())
293          throw new Error("Attempt to auto-create Coding.userSelected");
294        else if (Configuration.doAutoCreate())
295          this.userSelected = new BooleanType(); // bb
296      return this.userSelected;
297    }
298
299    public boolean hasUserSelectedElement() { 
300      return this.userSelected != null && !this.userSelected.isEmpty();
301    }
302
303    public boolean hasUserSelected() { 
304      return this.userSelected != null && !this.userSelected.isEmpty();
305    }
306
307    /**
308     * @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
309     */
310    public Coding setUserSelectedElement(BooleanType value) { 
311      this.userSelected = value;
312      return this;
313    }
314
315    /**
316     * @return Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
317     */
318    public boolean getUserSelected() { 
319      return this.userSelected == null || this.userSelected.isEmpty() ? false : this.userSelected.getValue();
320    }
321
322    /**
323     * @param value Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
324     */
325    public Coding setUserSelected(boolean value) { 
326        if (this.userSelected == null)
327          this.userSelected = new BooleanType();
328        this.userSelected.setValue(value);
329      return this;
330    }
331
332      protected void listChildren(List<Property> childrenList) {
333        super.listChildren(childrenList);
334        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));
335        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));
336        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));
337        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));
338        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));
339      }
340
341      @Override
342      public void setProperty(String name, Base value) throws FHIRException {
343        if (name.equals("system"))
344          this.system = castToUri(value); // UriType
345        else if (name.equals("version"))
346          this.version = castToString(value); // StringType
347        else if (name.equals("code"))
348          this.code = castToCode(value); // CodeType
349        else if (name.equals("display"))
350          this.display = castToString(value); // StringType
351        else if (name.equals("userSelected"))
352          this.userSelected = castToBoolean(value); // BooleanType
353        else
354          super.setProperty(name, value);
355      }
356
357      @Override
358      public Base addChild(String name) throws FHIRException {
359        if (name.equals("system")) {
360          throw new FHIRException("Cannot call addChild on a primitive type Coding.system");
361        }
362        else if (name.equals("version")) {
363          throw new FHIRException("Cannot call addChild on a primitive type Coding.version");
364        }
365        else if (name.equals("code")) {
366          throw new FHIRException("Cannot call addChild on a primitive type Coding.code");
367        }
368        else if (name.equals("display")) {
369          throw new FHIRException("Cannot call addChild on a primitive type Coding.display");
370        }
371        else if (name.equals("userSelected")) {
372          throw new FHIRException("Cannot call addChild on a primitive type Coding.userSelected");
373        }
374        else
375          return super.addChild(name);
376      }
377
378  public String fhirType() {
379    return "Coding";
380
381  }
382
383      public Coding copy() {
384        Coding dst = new Coding();
385        copyValues(dst);
386        dst.system = system == null ? null : system.copy();
387        dst.version = version == null ? null : version.copy();
388        dst.code = code == null ? null : code.copy();
389        dst.display = display == null ? null : display.copy();
390        dst.userSelected = userSelected == null ? null : userSelected.copy();
391        return dst;
392      }
393
394      protected Coding typedCopy() {
395        return copy();
396      }
397
398      @Override
399      public boolean equalsDeep(Base other) {
400        if (!super.equalsDeep(other))
401          return false;
402        if (!(other instanceof Coding))
403          return false;
404        Coding o = (Coding) other;
405        return compareDeep(system, o.system, true) && compareDeep(version, o.version, true) && compareDeep(code, o.code, true)
406           && compareDeep(display, o.display, true) && compareDeep(userSelected, o.userSelected, true);
407      }
408
409      @Override
410      public boolean equalsShallow(Base other) {
411        if (!super.equalsShallow(other))
412          return false;
413        if (!(other instanceof Coding))
414          return false;
415        Coding o = (Coding) other;
416        return compareValues(system, o.system, true) && compareValues(version, o.version, true) && compareValues(code, o.code, true)
417           && compareValues(display, o.display, true) && compareValues(userSelected, o.userSelected, true);
418      }
419
420      public boolean isEmpty() {
421        return super.isEmpty() && (system == null || system.isEmpty()) && (version == null || version.isEmpty())
422           && (code == null || code.isEmpty()) && (display == null || display.isEmpty()) && (userSelected == null || userSelected.isEmpty())
423          ;
424      }
425
426
427}
428