001package org.hl7.fhir.dstu2.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.dstu2
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/*
025  Copyright (c) 2011+, HL7, Inc.
026  All rights reserved.
027  
028  Redistribution and use in source and binary forms, with or without modification, 
029  are permitted provided that the following conditions are met:
030  
031   * Redistributions of source code must retain the above copyright notice, this 
032     list of conditions and the following disclaimer.
033   * Redistributions in binary form must reproduce the above copyright notice, 
034     this list of conditions and the following disclaimer in the documentation 
035     and/or other materials provided with the distribution.
036   * Neither the name of HL7 nor the names of its contributors may be used to 
037     endorse or promote products derived from this software without specific 
038     prior written permission.
039  
040  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
041  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
042  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
043  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
044  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
045  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
046  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
047  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
048  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
049  POSSIBILITY OF SUCH DAMAGE.
050  
051*/
052
053// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
054import java.util.List;
055
056import ca.uhn.fhir.model.api.annotation.Child;
057import ca.uhn.fhir.model.api.annotation.DatatypeDef;
058import ca.uhn.fhir.model.api.annotation.Description;
059import org.hl7.fhir.instance.model.api.IBaseCoding;
060import org.hl7.fhir.instance.model.api.ICompositeType;
061import org.hl7.fhir.exceptions.FHIRException;
062import org.hl7.fhir.utilities.Utilities;
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 {
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 - i.e. 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 - i.e. 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     * @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
115     */
116    public UriType getSystemElement() { 
117      if (this.system == null)
118        if (Configuration.errorOnAutoCreate())
119          throw new Error("Attempt to auto-create Coding.system");
120        else if (Configuration.doAutoCreate())
121          this.system = new UriType(); // bb
122      return this.system;
123    }
124
125    public boolean hasSystemElement() { 
126      return this.system != null && !this.system.isEmpty();
127    }
128
129    public boolean hasSystem() { 
130      return this.system != null && !this.system.isEmpty();
131    }
132
133    /**
134     * @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
135     */
136    public Coding setSystemElement(UriType value) { 
137      this.system = value;
138      return this;
139    }
140
141    /**
142     * @return The identification of the code system that defines the meaning of the symbol in the code.
143     */
144    public String getSystem() { 
145      return this.system == null ? null : this.system.getValue();
146    }
147
148    /**
149     * @param value The identification of the code system that defines the meaning of the symbol in the code.
150     */
151    public Coding setSystem(String value) { 
152      if (Utilities.noString(value))
153        this.system = null;
154      else {
155        if (this.system == null)
156          this.system = new UriType();
157        this.system.setValue(value);
158      }
159      return this;
160    }
161
162    /**
163     * @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
164     */
165    public StringType getVersionElement() { 
166      if (this.version == null)
167        if (Configuration.errorOnAutoCreate())
168          throw new Error("Attempt to auto-create Coding.version");
169        else if (Configuration.doAutoCreate())
170          this.version = new StringType(); // bb
171      return this.version;
172    }
173
174    public boolean hasVersionElement() { 
175      return this.version != null && !this.version.isEmpty();
176    }
177
178    public boolean hasVersion() { 
179      return this.version != null && !this.version.isEmpty();
180    }
181
182    /**
183     * @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
184     */
185    public Coding setVersionElement(StringType value) { 
186      this.version = value;
187      return this;
188    }
189
190    /**
191     * @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.
192     */
193    public String getVersion() { 
194      return this.version == null ? null : this.version.getValue();
195    }
196
197    /**
198     * @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.
199     */
200    public Coding setVersion(String value) { 
201      if (Utilities.noString(value))
202        this.version = null;
203      else {
204        if (this.version == null)
205          this.version = new StringType();
206        this.version.setValue(value);
207      }
208      return this;
209    }
210
211    /**
212     * @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
213     */
214    public CodeType getCodeElement() { 
215      if (this.code == null)
216        if (Configuration.errorOnAutoCreate())
217          throw new Error("Attempt to auto-create Coding.code");
218        else if (Configuration.doAutoCreate())
219          this.code = new CodeType(); // bb
220      return this.code;
221    }
222
223    public boolean hasCodeElement() { 
224      return this.code != null && !this.code.isEmpty();
225    }
226
227    public boolean hasCode() { 
228      return this.code != null && !this.code.isEmpty();
229    }
230
231    /**
232     * @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
233     */
234    public Coding setCodeElement(CodeType value) { 
235      this.code = value;
236      return this;
237    }
238
239    /**
240     * @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).
241     */
242    public String getCode() { 
243      return this.code == null ? null : this.code.getValue();
244    }
245
246    /**
247     * @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).
248     */
249    public Coding setCode(String value) { 
250      if (Utilities.noString(value))
251        this.code = null;
252      else {
253        if (this.code == null)
254          this.code = new CodeType();
255        this.code.setValue(value);
256      }
257      return this;
258    }
259
260    /**
261     * @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
262     */
263    public StringType getDisplayElement() { 
264      if (this.display == null)
265        if (Configuration.errorOnAutoCreate())
266          throw new Error("Attempt to auto-create Coding.display");
267        else if (Configuration.doAutoCreate())
268          this.display = new StringType(); // bb
269      return this.display;
270    }
271
272    public boolean hasDisplayElement() { 
273      return this.display != null && !this.display.isEmpty();
274    }
275
276    public boolean hasDisplay() { 
277      return this.display != null && !this.display.isEmpty();
278    }
279
280    /**
281     * @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
282     */
283    public Coding setDisplayElement(StringType value) { 
284      this.display = value;
285      return this;
286    }
287
288    /**
289     * @return A representation of the meaning of the code in the system, following the rules of the system.
290     */
291    public String getDisplay() { 
292      return this.display == null ? null : this.display.getValue();
293    }
294
295    /**
296     * @param value A representation of the meaning of the code in the system, following the rules of the system.
297     */
298    public Coding setDisplay(String value) { 
299      if (Utilities.noString(value))
300        this.display = null;
301      else {
302        if (this.display == null)
303          this.display = new StringType();
304        this.display.setValue(value);
305      }
306      return this;
307    }
308
309    /**
310     * @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
311     */
312    public BooleanType getUserSelectedElement() { 
313      if (this.userSelected == null)
314        if (Configuration.errorOnAutoCreate())
315          throw new Error("Attempt to auto-create Coding.userSelected");
316        else if (Configuration.doAutoCreate())
317          this.userSelected = new BooleanType(); // bb
318      return this.userSelected;
319    }
320
321    public boolean hasUserSelectedElement() { 
322      return this.userSelected != null && !this.userSelected.isEmpty();
323    }
324
325    public boolean hasUserSelected() { 
326      return this.userSelected != null && !this.userSelected.isEmpty();
327    }
328
329    /**
330     * @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
331     */
332    public Coding setUserSelectedElement(BooleanType value) { 
333      this.userSelected = value;
334      return this;
335    }
336
337    /**
338     * @return 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 boolean getUserSelected() { 
341      return this.userSelected == null || this.userSelected.isEmpty() ? false : this.userSelected.getValue();
342    }
343
344    /**
345     * @param value Indicates that this coding was chosen by a user directly - i.e. off a pick list of available items (codes or displays).
346     */
347    public Coding setUserSelected(boolean value) { 
348        if (this.userSelected == null)
349          this.userSelected = new BooleanType();
350        this.userSelected.setValue(value);
351      return this;
352    }
353
354      protected void listChildren(List<Property> childrenList) {
355        super.listChildren(childrenList);
356        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));
357        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));
358        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));
359        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));
360        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));
361      }
362
363      @Override
364      public void setProperty(String name, Base value) throws FHIRException {
365        if (name.equals("system"))
366          this.system = castToUri(value); // UriType
367        else if (name.equals("version"))
368          this.version = castToString(value); // StringType
369        else if (name.equals("code"))
370          this.code = castToCode(value); // CodeType
371        else if (name.equals("display"))
372          this.display = castToString(value); // StringType
373        else if (name.equals("userSelected"))
374          this.userSelected = castToBoolean(value); // BooleanType
375        else
376          super.setProperty(name, value);
377      }
378
379      @Override
380      public Base addChild(String name) throws FHIRException {
381        if (name.equals("system")) {
382          throw new FHIRException("Cannot call addChild on a primitive type Coding.system");
383        }
384        else if (name.equals("version")) {
385          throw new FHIRException("Cannot call addChild on a primitive type Coding.version");
386        }
387        else if (name.equals("code")) {
388          throw new FHIRException("Cannot call addChild on a primitive type Coding.code");
389        }
390        else if (name.equals("display")) {
391          throw new FHIRException("Cannot call addChild on a primitive type Coding.display");
392        }
393        else if (name.equals("userSelected")) {
394          throw new FHIRException("Cannot call addChild on a primitive type Coding.userSelected");
395        }
396        else
397          return super.addChild(name);
398      }
399
400  public String fhirType() {
401    return "Coding";
402
403  }
404
405      public Coding copy() {
406        Coding dst = new Coding();
407        copyValues(dst);
408        dst.system = system == null ? null : system.copy();
409        dst.version = version == null ? null : version.copy();
410        dst.code = code == null ? null : code.copy();
411        dst.display = display == null ? null : display.copy();
412        dst.userSelected = userSelected == null ? null : userSelected.copy();
413        return dst;
414      }
415
416      protected Coding typedCopy() {
417        return copy();
418      }
419
420      @Override
421      public boolean equalsDeep(Base other) {
422        if (!super.equalsDeep(other))
423          return false;
424        if (!(other instanceof Coding))
425          return false;
426        Coding o = (Coding) other;
427        return compareDeep(system, o.system, true) && compareDeep(version, o.version, true) && compareDeep(code, o.code, true)
428           && compareDeep(display, o.display, true) && compareDeep(userSelected, o.userSelected, true);
429      }
430
431      @Override
432      public boolean equalsShallow(Base other) {
433        if (!super.equalsShallow(other))
434          return false;
435        if (!(other instanceof Coding))
436          return false;
437        Coding o = (Coding) other;
438        return compareValues(system, o.system, true) && compareValues(version, o.version, true) && compareValues(code, o.code, true)
439           && compareValues(display, o.display, true) && compareValues(userSelected, o.userSelected, true);
440      }
441
442      public boolean isEmpty() {
443        return super.isEmpty() && (system == null || system.isEmpty()) && (version == null || version.isEmpty())
444           && (code == null || code.isEmpty()) && (display == null || display.isEmpty()) && (userSelected == null || userSelected.isEmpty())
445          ;
446      }
447
448
449}
450