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