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

View File

@ -98,6 +98,10 @@ public class ParameterUtil {
binder = new QueryParameterAndBinder(HasAndListParam.class,
Collections.<Class<? extends IQueryParameterType>>emptyList());
break;
case SOURCE:
binder = new QueryParameterAndBinder(SourceAndListParam.class,
Collections.<Class<? extends IQueryParameterType>>emptyList());
break;
}
// FIXME null access

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('?');
ArrayListMultimap<String, String> paramValues = ArrayListMultimap.create();
requestDetails.setParameters(new HashMap<String, String[]>());
requestDetails.setParameters(new HashMap<>());
if (qIndex != -1) {
String params = url.substring(qIndex);
List<NameValuePair> parameters = myMatchUrlService.translateMatchUrl(params);

View File

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

View File

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

View File

@ -179,6 +179,7 @@ public class InMemoryResourceMatcher {
case COMPOSITE:
case HAS:
case SPECIAL:
case SOURCE:
default:
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.registry.ISearchParamRegistry;
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.param.ParamPrefixEnum;
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.Observation;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -88,6 +90,14 @@ public class InMemoryResourceMatcherR5Test {
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
public void testUnsupportedChained() {
InMemoryMatchResult result = myInMemoryResourceMatcher.match("encounter.class=FOO", myObservation, mySearchParams);