001package ca.uhn.fhir.rest.gclient;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2017 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 java.util.Arrays;
024import java.util.List;
025
026import ca.uhn.fhir.model.primitive.StringDt;
027import ca.uhn.fhir.rest.api.Constants;
028
029/**
030 * 
031 * @author james
032 *
033 */
034public class StringClientParam extends BaseClientParam implements IParam {
035
036        private final String myParamName;
037
038        public StringClientParam(String theParamName) {
039                myParamName = theParamName;
040        }
041
042        @Override
043        public String getParamName() {
044                return myParamName;
045        }
046
047        /**
048         * The string matches the given value (servers will often, but are not required to) implement this as a left match,
049         * meaning that a value of "smi" would match "smi" and "smith".
050         */
051        public IStringMatch matches() {
052                return new StringMatches();
053        }
054
055        /**
056         * The string matches exactly the given value
057         */
058        public IStringMatch matchesExactly() {
059                return new StringExactly();
060        }
061
062        public interface IStringMatch {
063
064                /**
065                 * Requests that resources be returned which match the given value
066                 */
067                ICriterion<StringClientParam> value(String theValue);
068
069                /**
070                 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
071                 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
072                 * parameter.
073                 */
074                ICriterion<StringClientParam> values(List<String> theValues);
075
076                /**
077                 * Requests that resources be returned which match the given value
078                 */
079                ICriterion<StringClientParam> value(StringDt theValue);
080
081                /**
082                 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
083                 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
084                 * parameter.
085                 */
086                ICriterion<?> values(String... theValues);
087
088        }
089
090        private class StringExactly implements IStringMatch {
091                @Override
092                public ICriterion<StringClientParam> value(String theValue) {
093                        return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
094                }
095
096                @Override
097                public ICriterion<StringClientParam> value(StringDt theValue) {
098                        return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue.getValue());
099                }
100
101                @Override
102                public ICriterion<StringClientParam> values(List<String> theValue) {
103                        return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
104                }
105
106                @Override
107                public ICriterion<?> values(String... theValues) {
108                        return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, Arrays.asList(theValues));
109                }
110        }
111
112        private class StringMatches implements IStringMatch {
113                @Override
114                public ICriterion<StringClientParam> value(String theValue) {
115                        return new StringCriterion<StringClientParam>(getParamName(), theValue);
116                }
117
118                @Override
119                public ICriterion<StringClientParam> value(StringDt theValue) {
120                        return new StringCriterion<StringClientParam>(getParamName(), theValue.getValue());
121                }
122
123                @Override
124                public ICriterion<StringClientParam> values(List<String> theValue) {
125                        return new StringCriterion<StringClientParam>(getParamName(), theValue);
126                }
127
128                @Override
129                public ICriterion<?> values(String... theValues) {
130                        return new StringCriterion<StringClientParam>(getParamName(), Arrays.asList(theValues));
131                }
132
133        }
134
135}