View Javadoc
1   package ca.uhn.fhir.model.base.composite;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.apache.commons.lang3.StringUtils;
24  
25  import ca.uhn.fhir.context.FhirContext;
26  import ca.uhn.fhir.model.api.BaseIdentifiableElement;
27  import ca.uhn.fhir.model.api.ICompositeDatatype;
28  import ca.uhn.fhir.model.api.IQueryParameterType;
29  import ca.uhn.fhir.model.primitive.StringDt;
30  import ca.uhn.fhir.model.primitive.UriDt;
31  import ca.uhn.fhir.rest.param.ParameterUtil;
32  import ca.uhn.fhir.rest.param.StringParam;
33  
34  public abstract class BaseIdentifierDt extends BaseIdentifiableElement implements ICompositeDatatype, IQueryParameterType {
35  
36  	private static final long serialVersionUID = 4400972469749953077L;
37  
38  	@Override
39  	public String getQueryParameterQualifier() {
40  		return null;
41  	}
42  
43  	/**
44  	 * 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>.
45  	 *
46  	 * <p>
47  	 * <b>Definition:</b> Establishes the namespace in which set of possible id values is unique.
48  	 * </p>
49  	 */
50  	public abstract UriDt getSystemElement();
51  
52  	/**
53  	 * 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>.
54  	 *
55  	 * <p>
56  	 * <b>Definition:</b> The portion of the identifier typically displayed to the user and which is unique within the context of the system.
57  	 * </p>
58  	 */
59  	public abstract StringDt getValueElement();
60  
61  	/**
62  	 * {@inheritDoc}
63  	 */
64  	@Override
65  	public String getValueAsQueryToken(FhirContext theContext) {
66  		UriDt system = getSystemElement();
67  		StringDt value = getValueElement();
68  		if (system.getValueAsString() != null) {
69  			return ParameterUtil.escape(StringUtils.defaultString(system.getValueAsString())) + '|' + ParameterUtil.escape(value.getValueAsString());
70  		}
71  		return ParameterUtil.escape(value.getValueAsString());
72  	}
73  
74  	/**
75  	 * Returns true if <code>this</code> identifier has the same {@link #getValueElement() value} and
76  	 * {@link #getSystemElement() system} (as compared by simple equals comparison). Does not compare other values (e.g.
77  	 * getUse()) or any extensions.
78  	 */
79  	public boolean matchesSystemAndValue(BaseIdentifierDt theIdentifier) {
80  		if (theIdentifier == null) {
81  			return false;
82  		}
83  		return getValueElement().equals(theIdentifier.getValueElement()) && getSystemElement().equals(theIdentifier.getSystemElement());
84  	}
85  
86  	/**
87  	 * Sets the value for <b>system</b> (The namespace for the identifier)
88  	 *
89  	 * <p>
90  	 * <b>Definition:</b> Establishes the namespace in which set of possible id values is unique.
91  	 * </p>
92  	 */
93  	public abstract BaseIdentifierDt setSystem(String theUri);
94  
95  	/**
96  	 * Sets the value for <b>value</b> (The value that is unique)
97  	 *
98  	 * <p>
99  	 * <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 }