001package ca.uhn.fhir.rest.gclient; 002 003import static org.apache.commons.lang3.StringUtils.defaultString; 004 005import java.util.Arrays; 006import java.util.List; 007 008import ca.uhn.fhir.model.base.composite.BaseIdentifierDt; 009 010/* 011 * #%L 012 * HAPI FHIR - Core Library 013 * %% 014 * Copyright (C) 2014 - 2016 University Health Network 015 * %% 016 * Licensed under the Apache License, Version 2.0 (the "License"); 017 * you may not use this file except in compliance with the License. 018 * You may obtain a copy of the License at 019 * 020 * http://www.apache.org/licenses/LICENSE-2.0 021 * 022 * Unless required by applicable law or agreed to in writing, software 023 * distributed under the License is distributed on an "AS IS" BASIS, 024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 025 * See the License for the specific language governing permissions and 026 * limitations under the License. 027 * #L% 028 */ 029 030 031/** 032 * Token parameter type for use in fluent client interfaces 033 */ 034public class TokenClientParam extends BaseClientParam implements IParam { 035 036 private String myParamName; 037 038 @Override 039 public String getParamName() { 040 return myParamName; 041 } 042 043 public TokenClientParam(String theParamName) { 044 myParamName = theParamName; 045 } 046 047 public IMatches exactly() { 048 return new IMatches() { 049 @Override 050 public ICriterion<TokenClientParam> systemAndCode(String theSystem, String theCode) { 051 return new TokenCriterion(getParamName(), defaultString(theSystem), theCode); 052 } 053 054 @Override 055 public ICriterion<TokenClientParam> systemAndIdentifier(String theSystem, String theCode) { 056 return new TokenCriterion(getParamName(), defaultString(theSystem), theCode); 057 } 058 059 @Override 060 public ICriterion<TokenClientParam> code(String theCode) { 061 return new TokenCriterion(getParamName(), null, theCode); 062 } 063 064 @Override 065 public ICriterion<TokenClientParam> identifier(String theIdentifier) { 066 return new TokenCriterion(getParamName(), null, theIdentifier); 067 } 068 069 @Override 070 public ICriterion<TokenClientParam> identifier(BaseIdentifierDt theIdentifier) { 071 return new TokenCriterion(getParamName(), theIdentifier.getSystemElement().getValueAsString(), theIdentifier.getValueElement().getValue()); 072 } 073 074 @Override 075 public ICriterion<TokenClientParam> identifiers(List<BaseIdentifierDt> theIdentifiers) { 076 return new TokenCriterion(getParamName(), theIdentifiers); 077 } 078 079 @Override 080 public ICriterion<TokenClientParam> identifiers(BaseIdentifierDt... theIdentifiers) { 081 return new TokenCriterion(getParamName(), Arrays.asList(theIdentifiers)); 082 } 083}; 084 } 085 086 public interface IMatches { 087 /** 088 * Creates a search criterion that matches against the given code system and code 089 * 090 * @param theSystem 091 * The code system (should be a URI) 092 * @param theCode 093 * The code 094 * @return A criterion 095 */ 096 ICriterion<TokenClientParam> systemAndCode(String theSystem, String theCode); 097 098 /** 099 * Creates a search criterion that matches against the given system and identifier 100 * 101 * @param theSystem 102 * The code system (should be a URI) 103 * @param theIdentifier 104 * The identifier 105 * @return A criterion 106 */ 107 ICriterion<TokenClientParam> systemAndIdentifier(String theSystem, String theIdentifier); 108 109 /** 110 * Creates a search criterion that matches against the given identifier, with no system specified 111 * 112 * @param theIdentifier 113 * The identifier 114 * @return A criterion 115 */ 116 ICriterion<TokenClientParam> identifier(String theIdentifier); 117 118 /** 119 * Creates a search criterion that matches against the given code, with no code system specified 120 * 121 * @param theIdentifier 122 * The identifier 123 * @return A criterion 124 */ 125 ICriterion<TokenClientParam> code(String theIdentifier); 126 127 /** 128 * Creates a search criterion that matches against the given identifier (system and code if both are present, or whatever is present) 129 * 130 * @param theIdentifier 131 * The identifier 132 * @return A criterion 133 */ 134 ICriterion<TokenClientParam> identifier(BaseIdentifierDt theIdentifier); 135 136 /** 137 * Creates a search criterion that matches against the given collection of identifiers (system and code if both are present, or whatever is present). 138 * In the query URL that is generated, identifiers will be joined with a ',' to create an OR query. 139 * 140 * @param theIdentifiers 141 * The identifier 142 * @return A criterion 143 */ 144 ICriterion<TokenClientParam> identifiers(List<BaseIdentifierDt> theIdentifiers); 145 146 /** 147 * Creates a search criterion that matches against the given collection of identifiers (system and code if both are present, or whatever is present). 148 * In the query URL that is generated, identifiers will be joined with a ',' to create an OR query. 149 * 150 * @param theIdentifiers 151 * The identifier 152 * @return A criterion 153 */ 154 ICriterion<TokenClientParam> identifiers(BaseIdentifierDt... theIdentifiers); 155 156 } 157 158}