001/* 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.model.base.composite; 021 022import ca.uhn.fhir.context.FhirContext; 023import ca.uhn.fhir.i18n.Msg; 024import ca.uhn.fhir.model.api.BaseIdentifiableElement; 025import ca.uhn.fhir.model.api.ICompositeDatatype; 026import ca.uhn.fhir.model.api.IQueryParameterType; 027import ca.uhn.fhir.model.primitive.StringDt; 028import ca.uhn.fhir.model.primitive.UriDt; 029import ca.uhn.fhir.rest.param.ParameterUtil; 030import ca.uhn.fhir.rest.param.StringParam; 031import org.apache.commons.lang3.StringUtils; 032 033public abstract class BaseIdentifierDt extends BaseIdentifiableElement implements ICompositeDatatype, IQueryParameterType { 034 035 private static final long serialVersionUID = 4400972469749953077L; 036 037 @Override 038 public String getQueryParameterQualifier() { 039 return null; 040 } 041 042 /** 043 * Gets the value(s) for <b>system</b> (The namespace for the identifier). creating it if it does not exist. Will not return <code>null</code>. 044 * 045 * <p> 046 * <b>Definition:</b> Establishes the namespace in which set of possible id values is unique. 047 * </p> 048 */ 049 public abstract UriDt getSystemElement(); 050 051 /** 052 * Gets the value(s) for <b>value</b> (The value that is unique). creating it if it does not exist. Will not return <code>null</code>. 053 * 054 * <p> 055 * <b>Definition:</b> The portion of the identifier typically displayed to the user and which is unique within the context of the system. 056 * </p> 057 */ 058 public abstract StringDt getValueElement(); 059 060 /** 061 * {@inheritDoc} 062 */ 063 @Override 064 public String getValueAsQueryToken(FhirContext theContext) { 065 UriDt system = getSystemElement(); 066 StringDt value = getValueElement(); 067 if (system.getValueAsString() != null) { 068 return ParameterUtil.escape(StringUtils.defaultString(system.getValueAsString())) + '|' + ParameterUtil.escape(value.getValueAsString()); 069 } 070 return ParameterUtil.escape(value.getValueAsString()); 071 } 072 073 /** 074 * Returns true if <code>this</code> identifier has the same {@link #getValueElement() value} and 075 * {@link #getSystemElement() system} (as compared by simple equals comparison). Does not compare other values (e.g. 076 * getUse()) or any extensions. 077 */ 078 public boolean matchesSystemAndValue(BaseIdentifierDt theIdentifier) { 079 if (theIdentifier == null) { 080 return false; 081 } 082 return getValueElement().equals(theIdentifier.getValueElement()) && getSystemElement().equals(theIdentifier.getSystemElement()); 083 } 084 085 /** 086 * Sets the value for <b>system</b> (The namespace for the identifier) 087 * 088 * <p> 089 * <b>Definition:</b> Establishes the namespace in which set of possible id values is unique. 090 * </p> 091 */ 092 public abstract BaseIdentifierDt setSystem(String theUri); 093 094 /** 095 * Sets the value for <b>value</b> (The value that is unique) 096 * 097 * <p> 098 * <b>Definition:</b> The portion of the identifier typically displayed to the user and which is unique within the context of the system. 099 * </p> 100 */ 101 public abstract BaseIdentifierDt setValue(String theString); 102 103 /** 104 * {@inheritDoc} 105 */ 106 @Override 107 public void setValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theParameter) { 108 int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|'); 109 if (barIndex != -1) { 110 setSystem(theParameter.substring(0, barIndex)); 111 setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1))); 112 } else { 113 setValue(ParameterUtil.unescape(theParameter)); 114 } 115 } 116 117 118 /** 119 * <b>Not supported!</b> 120 * 121 * @deprecated get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you 122 * need this functionality 123 */ 124 @Deprecated 125 @Override 126 public Boolean getMissing() { 127 return null; 128 } 129 130 /** 131 * <b>Not supported!</b> 132 * 133 * @deprecated get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you 134 * need this functionality 135 */ 136 @Deprecated 137 @Override 138 public IQueryParameterType setMissing(Boolean theMissing) { 139 throw new UnsupportedOperationException(Msg.code(1907) + "get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you need this functionality"); 140 } 141 142}