001package ca.uhn.fhir.rest.gclient; 002 003import ca.uhn.fhir.model.primitive.IdDt; 004 005/* 006 * #%L 007 * HAPI FHIR - Core Library 008 * %% 009 * Copyright (C) 2014 - 2016 University Health Network 010 * %% 011 * Licensed under the Apache License, Version 2.0 (the "License"); 012 * you may not use this file except in compliance with the License. 013 * You may obtain a copy of the License at 014 * 015 * http://www.apache.org/licenses/LICENSE-2.0 016 * 017 * Unless required by applicable law or agreed to in writing, software 018 * distributed under the License is distributed on an "AS IS" BASIS, 019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 020 * See the License for the specific language governing permissions and 021 * limitations under the License. 022 * #L% 023 */ 024 025 026public class ReferenceClientParam extends BaseClientParam implements IParam { 027 028 private String myName; 029 030 public ReferenceClientParam(String theName) { 031 myName = theName; 032 } 033 034 @Override 035 public String getParamName() { 036 return myName; 037 } 038 039 public ICriterion<ReferenceClientParam> hasChainedProperty(ICriterion<?> theCriterion) { 040 return new ReferenceChainCriterion(getParamName(), theCriterion); 041 } 042 043 /** 044 * Match the referenced resource if the resource has the given ID (this can be 045 * the logical ID or the absolute URL of the resource) 046 */ 047 public ICriterion<ReferenceClientParam> hasId(IdDt theId) { 048 return new StringCriterion<ReferenceClientParam>(getParamName(), theId.getValue()); 049 } 050 051 /** 052 * Match the referenced resource if the resource has the given ID (this can be 053 * the logical ID or the absolute URL of the resource) 054 */ 055 public ICriterion<ReferenceClientParam> hasId(String theId) { 056 return new StringCriterion<ReferenceClientParam>(getParamName(), theId); 057 } 058 059 private static class ReferenceChainCriterion implements ICriterion<ReferenceClientParam>, ICriterionInternal { 060 061 private String myParamName; 062 private ICriterionInternal myWrappedCriterion; 063 064 public ReferenceChainCriterion(String theParamName, ICriterion<?> theWrappedCriterion) { 065 myParamName = theParamName; 066 myWrappedCriterion = (ICriterionInternal) theWrappedCriterion; 067 } 068 069 @Override 070 public String getParameterName() { 071 return myParamName + "." + myWrappedCriterion.getParameterName(); 072 } 073 074 @Override 075 public String getParameterValue() { 076 return myWrappedCriterion.getParameterValue(); 077 } 078 079 } 080 081}