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