001/*
002Copyright (c) 2011+, HL7, Inc
003All rights reserved.
004
005Redistribution and use in source and binary forms, with or without modification, 
006are permitted provided that the following conditions are met:
007
008 * Redistributions of source code must retain the above copyright notice, this 
009   list of conditions and the following disclaimer.
010 * Redistributions in binary form must reproduce the above copyright notice, 
011   this list of conditions and the following disclaimer in the documentation 
012   and/or other materials provided with the distribution.
013 * Neither the name of HL7 nor the names of its contributors may be used to 
014   endorse or promote products derived from this software without specific 
015   prior written permission.
016
017THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
018ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
019WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
020IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
021INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
022NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
023PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
024WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
025ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
026POSSIBILITY OF SUCH DAMAGE.
027
028 */
029package org.hl7.fhir.r4.model;
030
031import static org.apache.commons.lang3.StringUtils.defaultString;
032
033import org.hl7.fhir.utilities.Utilities;
034
035import ca.uhn.fhir.model.api.annotation.DatatypeDef;
036
037/**
038 * Primitive type "code" in FHIR, when not bound to an enumerated list of codes
039 */
040@DatatypeDef(name="code", profileOf=StringType.class)
041public class CodeType extends StringType implements Comparable<CodeType>, ICoding  {
042
043        private static final long serialVersionUID = 3L;
044
045        public CodeType() {
046                super();
047        }
048
049        public CodeType(String theCode) {
050                setValue(theCode);
051        }
052
053        public int compareTo(CodeType theCode) {
054                if (theCode == null) {
055                        return 1;
056                }
057                return defaultString(getValue()).compareTo(defaultString(theCode.getValue()));
058        }       
059
060        @Override
061        protected String parse(String theValue) {
062                return theValue.trim();
063        }
064
065        @Override
066        protected String encode(String theValue) {
067                return theValue;
068        }
069
070        @Override
071        public CodeType copy() {
072                return new CodeType(getValue());
073        }
074
075        public String fhirType() {
076                return "code";          
077        }
078
079  private String system;
080  
081  @Override
082  public String getSystem() {
083    return system;
084  }
085
086  @Override
087  public boolean hasSystem() {
088    return system != null;
089  }
090  
091  public CodeType setSystem(String system) {
092    this.system = system;
093    return this;
094  }
095
096  @Override
097  public String getVersion() {
098    return null;
099  }
100
101  @Override
102  public boolean hasVersion() {
103    return false;
104  }
105  
106  @Override
107  public String getDisplay() {
108    return null;
109  }
110
111  @Override
112  public boolean hasDisplay() {
113    return false;
114  }
115
116  @Override
117  public String getCode() {
118    return asStringValue();
119  }
120
121  @Override
122  public boolean hasCode() {
123    return !Utilities.noString(asStringValue());
124  }
125
126  @Override
127  public boolean supportsVersion() {
128    return false;
129  }
130
131  @Override
132  public boolean supportsDisplay() {
133    return false;
134  }
135}