commiting with FIXMEs so James can review

This commit is contained in:
Ken Stevens 2019-10-24 16:40:53 -04:00
parent df4376606d
commit 43f17534bb
10 changed files with 259 additions and 84 deletions

View File

@ -96,6 +96,11 @@ public enum RestSearchParameterTypeEnum {
*/ */
SPECIAL("special", "http://hl7.org/fhir/search-param-type"), SPECIAL("special", "http://hl7.org/fhir/search-param-type"),
/**
* _has parameter
*/
SOURCE("string", "http://hl7.org/fhir/search-param-type"),
; ;
@ -119,7 +124,7 @@ public enum RestSearchParameterTypeEnum {
static { static {
for (RestSearchParameterTypeEnum next : RestSearchParameterTypeEnum.values()) { for (RestSearchParameterTypeEnum next : RestSearchParameterTypeEnum.values()) {
if (next == HAS) { if (next == HAS || next == SOURCE) {
continue; continue;
} }

View File

@ -68,35 +68,39 @@ public class ParameterUtil {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
case DATE: case DATE:
binder = new QueryParameterAndBinder(DateAndListParam.class, binder = new QueryParameterAndBinder(DateAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case NUMBER: case NUMBER:
binder = new QueryParameterAndBinder(NumberAndListParam.class, binder = new QueryParameterAndBinder(NumberAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case QUANTITY: case QUANTITY:
binder = new QueryParameterAndBinder(QuantityAndListParam.class, binder = new QueryParameterAndBinder(QuantityAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case REFERENCE: case REFERENCE:
binder = new QueryParameterAndBinder(ReferenceAndListParam.class, binder = new QueryParameterAndBinder(ReferenceAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case STRING: case STRING:
binder = new QueryParameterAndBinder(StringAndListParam.class, binder = new QueryParameterAndBinder(StringAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case TOKEN: case TOKEN:
binder = new QueryParameterAndBinder(TokenAndListParam.class, binder = new QueryParameterAndBinder(TokenAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case URI: case URI:
binder = new QueryParameterAndBinder(UriAndListParam.class, binder = new QueryParameterAndBinder(UriAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
case HAS: case HAS:
binder = new QueryParameterAndBinder(HasAndListParam.class, binder = new QueryParameterAndBinder(HasAndListParam.class,
Collections.<Class<? extends IQueryParameterType>> emptyList()); Collections.<Class<? extends IQueryParameterType>>emptyList());
break;
case SOURCE:
binder = new QueryParameterAndBinder(SourceAndListParam.class,
Collections.<Class<? extends IQueryParameterType>>emptyList());
break; break;
} }

View File

@ -0,0 +1,41 @@
package ca.uhn.fhir.rest.param;
import ca.uhn.fhir.util.CoverageIgnore;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2019 University Health Network
* %%
* 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%
*/
public class SourceAndListParam extends BaseAndListParam<SourceOrListParam> {
@Override
SourceOrListParam newInstance() {
return new SourceOrListParam();
}
@CoverageIgnore
@Override
public SourceAndListParam addAnd(SourceOrListParam theValue) {
addValue(theValue);
return this;
}
}

View File

@ -0,0 +1,41 @@
package ca.uhn.fhir.rest.param;
import ca.uhn.fhir.util.CoverageIgnore;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2019 University Health Network
* %%
* 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%
*/
public class SourceOrListParam extends BaseOrListParam<SourceOrListParam, SourceParam> {
@CoverageIgnore
@Override
SourceParam newInstance() {
return new SourceParam();
}
@CoverageIgnore
@Override
public SourceOrListParam addOr(SourceParam theParameter) {
add(theParameter);
return this;
}
}

View File

@ -0,0 +1,83 @@
package ca.uhn.fhir.rest.param;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.left;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2019 University Health Network
* %%
* 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%
*/
/**
* Implementation of the _has method parameter
*/
public class SourceParam extends BaseParam implements IQueryParameterType {
private static final long serialVersionUID = 1L;
private String myParameterValue;
private String mySourceUri;
private String myRequestId;
public SourceParam() {}
public SourceParam(String theParameterValue) {
setValue(theParameterValue);
}
private void setValue(String theParameterValue) {
myParameterValue = theParameterValue;
String requestId;
int lastHashValueIndex = theParameterValue.lastIndexOf('#');
if (lastHashValueIndex == -1) {
mySourceUri = theParameterValue;
requestId = null;
} else {
mySourceUri = theParameterValue.substring(0, lastHashValueIndex);
requestId = theParameterValue.substring(lastHashValueIndex + 1);
}
myRequestId = left(requestId, Constants.REQUEST_ID_LENGTH);
}
@Override
String doGetQueryParameterQualifier() {
return myParameterValue;
}
@Override
String doGetValueAsQueryToken(FhirContext theContext) {
return myParameterValue;
}
@Override
void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) {
setValue(theValue);
}
public String getSourceUri() {
return mySourceUri;
}
public String getRequestId() {
return myRequestId;
}
}

View File

@ -243,7 +243,7 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
int qIndex = url.indexOf('?'); int qIndex = url.indexOf('?');
ArrayListMultimap<String, String> paramValues = ArrayListMultimap.create(); ArrayListMultimap<String, String> paramValues = ArrayListMultimap.create();
requestDetails.setParameters(new HashMap<String, String[]>()); requestDetails.setParameters(new HashMap<>());
if (qIndex != -1) { if (qIndex != -1) {
String params = url.substring(qIndex); String params = url.substring(qIndex);
List<NameValuePair> parameters = myMatchUrlService.translateMatchUrl(params); List<NameValuePair> parameters = myMatchUrlService.translateMatchUrl(params);

View File

@ -861,19 +861,10 @@ public class SearchBuilder implements ISearchBuilder {
List<Predicate> codePredicates = new ArrayList<>(); List<Predicate> codePredicates = new ArrayList<>();
for (IQueryParameterType nextParameter : theList) { for (IQueryParameterType nextParameter : theList) {
String nextParamValue = nextParameter.getValueAsQueryToken(myContext); // FIXME KHS this works, but is it right?
int lastHashValueIndex = nextParamValue.lastIndexOf('#'); SourceParam sourceParameter = new SourceParam(nextParameter.getValueAsQueryToken(myContext));
String sourceUri; String sourceUri = sourceParameter.getSourceUri();
String requestId; String requestId = sourceParameter.getRequestId();
if (lastHashValueIndex == -1) {
sourceUri = nextParamValue;
requestId = null;
} else {
sourceUri = nextParamValue.substring(0, lastHashValueIndex);
requestId = nextParamValue.substring(lastHashValueIndex + 1);
}
requestId = left(requestId, Constants.REQUEST_ID_LENGTH);
Predicate sourceUriPredicate = myBuilder.equal(join.get("mySourceUri"), sourceUri); Predicate sourceUriPredicate = myBuilder.equal(join.get("mySourceUri"), sourceUri);
Predicate requestIdPredicate = myBuilder.equal(join.get("myRequestId"), requestId); Predicate requestIdPredicate = myBuilder.equal(join.get("myRequestId"), requestId);
if (isNotBlank(sourceUri) && isNotBlank(requestId)) { if (isNotBlank(sourceUri) && isNotBlank(requestId)) {
@ -1280,6 +1271,7 @@ public class SearchBuilder implements ISearchBuilder {
retVal = createPredicateQuantity(leftValue, theResourceName, theParam.getName(), myBuilder, dateJoin); retVal = createPredicateQuantity(leftValue, theResourceName, theParam.getName(), myBuilder, dateJoin);
break; break;
} }
case SOURCE:
case COMPOSITE: case COMPOSITE:
case HAS: case HAS:
case NUMBER: case NUMBER:
@ -2747,6 +2739,7 @@ public class SearchBuilder implements ISearchBuilder {
throw new InvalidRequestException("Unexpected search parameter type encountered, expected string type for language search"); throw new InvalidRequestException("Unexpected search parameter type encountered, expected string type for language search");
} }
} else if (searchParam.getName().equals(Constants.PARAM_SOURCE)) { } else if (searchParam.getName().equals(Constants.PARAM_SOURCE)) {
// FIXME KHS remove this
if (searchParam.getParamType() == RestSearchParameterTypeEnum.TOKEN) { if (searchParam.getParamType() == RestSearchParameterTypeEnum.TOKEN) {
TokenParam param = new TokenParam(); TokenParam param = new TokenParam();
param.setValueAsQueryToken(null, null, null, theFilter.getValue()); param.setValueAsQueryToken(null, null, null, theFilter.getValue());
@ -3008,6 +3001,9 @@ public class SearchBuilder implements ISearchBuilder {
case REFERENCE: case REFERENCE:
qp = new ReferenceParam(); qp = new ReferenceParam();
break; break;
case SOURCE:
qp = new SourceParam();
break;
case SPECIAL: case SPECIAL:
case URI: case URI:
case HAS: case HAS:

View File

@ -93,16 +93,10 @@ public class MatchUrlService {
paramMap.setLastUpdated(p1); paramMap.setLastUpdated(p1);
} }
} }
continue; } else if (Constants.PARAM_HAS.equals(nextParamName)) {
}
if (Constants.PARAM_HAS.equals(nextParamName)) {
IQueryParameterAnd<?> param = ParameterUtil.parseQueryParams(myContext, RestSearchParameterTypeEnum.HAS, nextParamName, paramList); IQueryParameterAnd<?> param = ParameterUtil.parseQueryParams(myContext, RestSearchParameterTypeEnum.HAS, nextParamName, paramList);
paramMap.add(nextParamName, param); paramMap.add(nextParamName, param);
continue; } else if (Constants.PARAM_COUNT.equals(nextParamName)) {
}
if (Constants.PARAM_COUNT.equals(nextParamName)) {
if (paramList.size() > 0 && paramList.get(0).size() > 0) { if (paramList.size() > 0 && paramList.get(0).size() > 0) {
String intString = paramList.get(0).get(0); String intString = paramList.get(0).get(0);
try { try {
@ -111,16 +105,16 @@ public class MatchUrlService {
throw new InvalidRequestException("Invalid " + Constants.PARAM_COUNT + " value: " + intString); throw new InvalidRequestException("Invalid " + Constants.PARAM_COUNT + " value: " + intString);
} }
} }
continue; } else if (ResourceMetaParams.RESOURCE_META_PARAMS.containsKey(nextParamName)) {
}
if (ResourceMetaParams.RESOURCE_META_PARAMS.containsKey(nextParamName)) {
if (isNotBlank(paramList.get(0).getQualifier()) && paramList.get(0).getQualifier().startsWith(".")) { if (isNotBlank(paramList.get(0).getQualifier()) && paramList.get(0).getQualifier().startsWith(".")) {
throw new InvalidRequestException("Invalid parameter chain: " + nextParamName + paramList.get(0).getQualifier()); throw new InvalidRequestException("Invalid parameter chain: " + nextParamName + paramList.get(0).getQualifier());
} }
IQueryParameterAnd<?> type = newInstanceAnd(nextParamName); IQueryParameterAnd<?> type = newInstanceAnd(nextParamName);
type.setValuesAsQueryTokens(myContext, nextParamName, (paramList)); type.setValuesAsQueryTokens(myContext, nextParamName, (paramList));
paramMap.add(nextParamName, type); paramMap.add(nextParamName, type);
} else if (Constants.PARAM_SOURCE.equals(nextParamName)) {
IQueryParameterAnd<?> param = ParameterUtil.parseQueryParams(myContext, RestSearchParameterTypeEnum.SOURCE, nextParamName, paramList);
paramMap.add(nextParamName, param);
} else if (nextParamName.startsWith("_")) { } else if (nextParamName.startsWith("_")) {
// ignore these since they aren't search params (e.g. _sort) // ignore these since they aren't search params (e.g. _sort)
} else { } else {

View File

@ -179,6 +179,7 @@ public class InMemoryResourceMatcher {
case COMPOSITE: case COMPOSITE:
case HAS: case HAS:
case SPECIAL: case SPECIAL:
case SOURCE:
default: default:
return InMemoryMatchResult.unsupportedFromParameterAndReason(theParamName, InMemoryMatchResult.PARAM); return InMemoryMatchResult.unsupportedFromParameterAndReason(theParamName, InMemoryMatchResult.PARAM);
} }

View File

@ -7,6 +7,7 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams; import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.model.primitive.BaseDateTimeDt; import ca.uhn.fhir.model.primitive.BaseDateTimeDt;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
import ca.uhn.fhir.rest.param.ParamPrefixEnum; import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.param.TokenParamModifier;
@ -15,6 +16,7 @@ import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.DateTimeType; import org.hl7.fhir.r5.model.DateTimeType;
import org.hl7.fhir.r5.model.Observation; import org.hl7.fhir.r5.model.Observation;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -88,6 +90,14 @@ public class InMemoryResourceMatcherR5Test {
mySearchParams = extractDateSearchParam(myObservation); mySearchParams = extractDateSearchParam(myObservation);
} }
// FIXME KHS get this test to work
@Ignore
@Test
public void testSupportedSource() {
InMemoryMatchResult result = myInMemoryResourceMatcher.match(Constants.PARAM_SOURCE + "=FOO", myObservation, mySearchParams);
assertTrue(result.supported());
}
@Test @Test
public void testUnsupportedChained() { public void testUnsupportedChained() {
InMemoryMatchResult result = myInMemoryResourceMatcher.match("encounter.class=FOO", myObservation, mySearchParams); InMemoryMatchResult result = myInMemoryResourceMatcher.match("encounter.class=FOO", myObservation, mySearchParams);