001package ca.uhn.fhir.model.base.composite;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
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
023import org.apache.commons.lang3.StringUtils;
024
025import ca.uhn.fhir.context.FhirContext;
026import ca.uhn.fhir.model.api.BaseIdentifiableElement;
027import ca.uhn.fhir.model.api.ICompositeDatatype;
028import ca.uhn.fhir.model.api.IQueryParameterType;
029import ca.uhn.fhir.model.primitive.StringDt;
030import ca.uhn.fhir.model.primitive.UriDt;
031import ca.uhn.fhir.rest.param.ParameterUtil;
032import ca.uhn.fhir.rest.param.StringParam;
033
034public abstract class BaseIdentifierDt extends BaseIdentifiableElement implements ICompositeDatatype, IQueryParameterType {
035
036        private static final long serialVersionUID = 4400972469749953077L;
037
038        @Override
039        public String getQueryParameterQualifier() {
040                return null;
041        }
042
043        /**
044         * 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>.
045         *
046         * <p>
047         * <b>Definition:</b> Establishes the namespace in which set of possible id values is unique.
048         * </p>
049         */
050        public abstract UriDt getSystemElement();
051
052        /**
053         * 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>.
054         *
055         * <p>
056         * <b>Definition:</b> The portion of the identifier typically displayed to the user and which is unique within the context of the system.
057         * </p>
058         */
059        public abstract StringDt getValueElement();
060
061        /**
062         * {@inheritDoc}
063         */
064        @Override
065        public String getValueAsQueryToken(FhirContext theContext) {
066                UriDt system = getSystemElement();
067                StringDt value = getValueElement();
068                if (system.getValueAsString() != null) {
069                        return ParameterUtil.escape(StringUtils.defaultString(system.getValueAsString())) + '|' + ParameterUtil.escape(value.getValueAsString());
070                }
071                return ParameterUtil.escape(value.getValueAsString());
072        }
073
074        /**
075         * Returns true if <code>this</code> identifier has the same {@link #getValueElement() value} and
076         * {@link #getSystemElement() system} (as compared by simple equals comparison). Does not compare other values (e.g.
077         * getUse()) or any extensions.
078         */
079        public boolean matchesSystemAndValue(BaseIdentifierDt theIdentifier) {
080                if (theIdentifier == null) {
081                        return false;
082                }
083                return getValueElement().equals(theIdentifier.getValueElement()) && getSystemElement().equals(theIdentifier.getSystemElement());
084        }
085
086        /**
087         * Sets the value for <b>system</b> (The namespace for the identifier)
088         *
089         * <p>
090         * <b>Definition:</b> Establishes the namespace in which set of possible id values is unique.
091         * </p>
092         */
093        public abstract BaseIdentifierDt setSystem(String theUri);
094
095        /**
096         * Sets the value for <b>value</b> (The value that is unique)
097         *
098         * <p>
099         * <b>Definition:</b> The portion of the identifier typically displayed to the user and which is unique within the context of the system.
100         * </p>
101         */
102        public abstract BaseIdentifierDt setValue(String theString);
103
104        /**
105         * {@inheritDoc}
106         */
107        @Override
108        public void setValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theParameter) {
109                int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|');
110                if (barIndex != -1) {
111                        setSystem(theParameter.substring(0, barIndex));
112                        setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
113                } else {
114                        setValue(ParameterUtil.unescape(theParameter));
115                }
116        }
117
118        
119        /**
120         * <b>Not supported!</b>
121         * 
122         * @deprecated get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you
123         * need this functionality
124         */
125        @Deprecated
126        @Override
127        public Boolean getMissing() {
128                return null;
129        }
130
131        /**
132         * <b>Not supported!</b>
133         * 
134         * @deprecated get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you
135         * need this functionality
136         */
137        @Deprecated
138        @Override
139        public IQueryParameterType setMissing(Boolean theMissing) {
140                throw new UnsupportedOperationException("get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you need this functionality");
141        }
142
143}