All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.uhn.fhir.rest.gclient.StringClientParam Maven / Gradle / Ivy

Go to download

Builds the hapi fhir base. Requires Common lang, commons-text, and guava be built first.

There is a newer version: 7.0.2-r12
Show newest version
/*
 * #%L
 * HAPI FHIR - Core Library
 * %%
 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package ca.uhn.fhir.rest.gclient;

import ca.uhn.fhir.rest.api.Constants;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import java.util.Arrays;
import java.util.List;

/**
 *
 * @author james
 *
 */
public class StringClientParam extends BaseClientParam implements IParam {

	private final String myParamName;

	public StringClientParam(String theParamName) {
		myParamName = theParamName;
	}

	@Override
	public String getParamName() {
		return myParamName;
	}

	/**
	 * The string matches the given value (servers will often, but are not required to) implement this as a left match,
	 * meaning that a value of "smi" would match "smi" and "smith".
	 */
	public IStringMatch matches() {
		return new StringMatches();
	}

	/**
	 * The string matches exactly the given value
	 */
	public IStringMatch matchesExactly() {
		return new StringExactly();
	}

	/**
	 * The string contains given value
	 */
	public IStringMatch contains() {
		return new StringContains();
	}

	public interface IStringMatch {

		/**
		 * Requests that resources be returned which match the given value
		 */
		ICriterion value(String theValue);

		/**
		 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
		 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
		 * parameter.
		 */
		ICriterion values(List theValues);

		/**
		 * Requests that resources be returned which match the given value
		 */
		ICriterion value(IPrimitiveType theValue);

		/**
		 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
		 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
		 * parameter.
		 */
		ICriterion values(String... theValues);
	}

	private class StringExactly implements IStringMatch {
		@Override
		public ICriterion value(String theValue) {
			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
		}

		@Override
		public ICriterion value(IPrimitiveType theValue) {
			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue.getValue());
		}

		@Override
		public ICriterion values(List theValue) {
			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
		}

		@Override
		public ICriterion values(String... theValues) {
			return new StringCriterion(
					getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, Arrays.asList(theValues));
		}
	}

	private class StringContains implements IStringMatch {
		@Override
		public ICriterion value(String theValue) {
			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue);
		}

		@Override
		public ICriterion value(IPrimitiveType theValue) {
			return new StringCriterion<>(
					getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue.getValue());
		}

		@Override
		public ICriterion values(List theValue) {
			return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue);
		}

		@Override
		public ICriterion values(String... theValues) {
			return new StringCriterion(
					getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, Arrays.asList(theValues));
		}
	}

	private class StringMatches implements IStringMatch {
		@Override
		public ICriterion value(String theValue) {
			return new StringCriterion<>(getParamName(), theValue);
		}

		@Override
		public ICriterion value(IPrimitiveType theValue) {
			return new StringCriterion<>(getParamName(), theValue.getValue());
		}

		@Override
		public ICriterion values(List theValue) {
			return new StringCriterion<>(getParamName(), theValue);
		}

		@Override
		public ICriterion values(String... theValues) {
			return new StringCriterion(getParamName(), Arrays.asList(theValues));
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy