001package org.hl7.fhir.r4.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 032import static org.apache.commons.lang3.StringUtils.defaultString; 033 034import org.hl7.fhir.utilities.Utilities; 035 036import ca.uhn.fhir.model.api.annotation.DatatypeDef; 037 038/** 039 * Primitive type "code" in FHIR, when not bound to an enumerated list of codes 040 */ 041@DatatypeDef(name = "code", profileOf = StringType.class) 042public class CodeType extends StringType implements Comparable<CodeType>, ICoding { 043 044 private static final long serialVersionUID = 3L; 045 046 public CodeType() { 047 super(); 048 } 049 050 public CodeType(String theCode) { 051 setValue(theCode); 052 } 053 054 public CodeType(String theCode, Element source) { 055 setValue(theCode); 056 setId(source.getId()); 057 getExtension().addAll(source.getExtension()); 058 } 059 060 public int compareTo(CodeType theCode) { 061 if (theCode == null) { 062 return 1; 063 } 064 return defaultString(getValue()).compareTo(defaultString(theCode.getValue())); 065 } 066 067 @Override 068 protected String parse(String theValue) { 069 return theValue.trim(); 070 } 071 072 @Override 073 protected String encode(String theValue) { 074 return theValue; 075 } 076 077 @Override 078 public CodeType copy() { 079 CodeType ret = new CodeType(getValue()); 080 copyValues(ret); 081 return ret; 082 } 083 084 public String fhirType() { 085 return "code"; 086 } 087 088 private String system; 089 090 @Override 091 public String getSystem() { 092 return system; 093 } 094 095 @Override 096 public boolean hasSystem() { 097 return system != null; 098 } 099 100 public CodeType setSystem(String system) { 101 this.system = system; 102 return this; 103 } 104 105 @Override 106 public String getVersion() { 107 return null; 108 } 109 110 @Override 111 public boolean hasVersion() { 112 return false; 113 } 114 115 @Override 116 public String getDisplay() { 117 return null; 118 } 119 120 @Override 121 public boolean hasDisplay() { 122 return false; 123 } 124 125 @Override 126 public String getCode() { 127 return asStringValue(); 128 } 129 130 @Override 131 public boolean hasCode() { 132 return !Utilities.noString(asStringValue()); 133 } 134 135 @Override 136 public boolean supportsVersion() { 137 return false; 138 } 139 140 @Override 141 public boolean supportsDisplay() { 142 return false; 143 } 144}