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 CodeType ret = new CodeType(getValue()); 073 copyValues(ret); 074 return ret; 075 } 076 077 public String fhirType() { 078 return "code"; 079 } 080 081 private String system; 082 083 @Override 084 public String getSystem() { 085 return system; 086 } 087 088 @Override 089 public boolean hasSystem() { 090 return system != null; 091 } 092 093 public CodeType setSystem(String system) { 094 this.system = system; 095 return this; 096 } 097 098 @Override 099 public String getVersion() { 100 return null; 101 } 102 103 @Override 104 public boolean hasVersion() { 105 return false; 106 } 107 108 @Override 109 public String getDisplay() { 110 return null; 111 } 112 113 @Override 114 public boolean hasDisplay() { 115 return false; 116 } 117 118 @Override 119 public String getCode() { 120 return asStringValue(); 121 } 122 123 @Override 124 public boolean hasCode() { 125 return !Utilities.noString(asStringValue()); 126 } 127 128 @Override 129 public boolean supportsVersion() { 130 return false; 131 } 132 133 @Override 134 public boolean supportsDisplay() { 135 return false; 136 } 137}