implement in-memory match
This commit is contained in:
parent
b7aa327118
commit
5379ab8c2c
|
@ -3,6 +3,8 @@ 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 org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.left;
|
||||
|
||||
|
@ -50,7 +52,9 @@ public class SourceParam extends BaseParam implements IQueryParameterType {
|
|||
mySourceUri = theParameterValue;
|
||||
requestId = null;
|
||||
} else {
|
||||
if (lastHashValueIndex != 0) {
|
||||
mySourceUri = theParameterValue.substring(0, lastHashValueIndex);
|
||||
}
|
||||
requestId = theParameterValue.substring(lastHashValueIndex + 1);
|
||||
}
|
||||
myRequestId = left(requestId, Constants.REQUEST_ID_LENGTH);
|
||||
|
@ -58,7 +62,7 @@ public class SourceParam extends BaseParam implements IQueryParameterType {
|
|||
|
||||
@Override
|
||||
String doGetQueryParameterQualifier() {
|
||||
return myParameterValue;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,11 +30,9 @@ import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
|||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.param.BaseParamWithPrefix;
|
||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.util.MetaUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
@ -125,7 +123,6 @@ public class InMemoryResourceMatcher {
|
|||
|
||||
switch (theParamName) {
|
||||
case IAnyResource.SP_RES_ID:
|
||||
|
||||
return InMemoryMatchResult.fromBoolean(matchIdsAndOr(theAndOrParams, theResource));
|
||||
|
||||
case IAnyResource.SP_RES_LANGUAGE:
|
||||
|
@ -133,16 +130,39 @@ public class InMemoryResourceMatcher {
|
|||
case Constants.PARAM_TAG:
|
||||
case Constants.PARAM_PROFILE:
|
||||
case Constants.PARAM_SECURITY:
|
||||
|
||||
return InMemoryMatchResult.unsupportedFromParameterAndReason(theParamName, InMemoryMatchResult.PARAM);
|
||||
|
||||
case Constants.PARAM_SOURCE:
|
||||
return InMemoryMatchResult.fromBoolean(matchSourcesAndOr(theAndOrParams, theResource));
|
||||
default:
|
||||
|
||||
|
||||
return matchResourceParam(theParamName, theAndOrParams, theSearchParams, resourceName, paramDef);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME KHS move these clustered methods out
|
||||
private boolean matchSourcesAndOr(List<List<IQueryParameterType>> theAndOrParams, IBaseResource theResource) {
|
||||
if (theResource == null) {
|
||||
return true;
|
||||
}
|
||||
return theAndOrParams.stream().allMatch(nextAnd -> matchSourcesOr(nextAnd, theResource));
|
||||
}
|
||||
|
||||
private boolean matchSourcesOr(List<IQueryParameterType> theOrParams, IBaseResource theResource) {
|
||||
return theOrParams.stream().anyMatch(param -> matchSource(param, theResource));
|
||||
}
|
||||
|
||||
private boolean matchSource(IQueryParameterType theSourceParam, IBaseResource theResource) {
|
||||
SourceParam paramSource = new SourceParam(theSourceParam.getValueAsQueryToken(myFhirContext));
|
||||
SourceParam resourceSource = new SourceParam(MetaUtil.getSource(myFhirContext, theResource.getMeta()));
|
||||
boolean matches = true;
|
||||
if (paramSource.getSourceUri() != null) {
|
||||
matches = paramSource.getSourceUri().equals(resourceSource.getSourceUri());
|
||||
}
|
||||
if (paramSource.getRequestId() != null) {
|
||||
matches &= paramSource.getRequestId().equals(resourceSource.getRequestId());
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private boolean matchIdsAndOr(List<List<IQueryParameterType>> theAndOrParams, IBaseResource theResource) {
|
||||
if (theResource == null) {
|
||||
return true;
|
||||
|
@ -151,9 +171,6 @@ public class InMemoryResourceMatcher {
|
|||
}
|
||||
|
||||
private boolean matchIdsOr(List<IQueryParameterType> theOrParams, IBaseResource theResource) {
|
||||
if (theResource == null) {
|
||||
return true;
|
||||
}
|
||||
return theOrParams.stream().anyMatch(param -> param instanceof StringParam && matchId(((StringParam) param).getValue(), theResource.getIdElement()));
|
||||
}
|
||||
|
||||
|
@ -176,8 +193,6 @@ public class InMemoryResourceMatcher {
|
|||
} else {
|
||||
return InMemoryMatchResult.fromBoolean(theAndOrParams.stream().anyMatch(nextAnd -> matchParams(theResourceName, theParamName, theParamDef, nextAnd, theSearchParams)));
|
||||
}
|
||||
case SOURCE:
|
||||
// FIXME KHS implement
|
||||
case COMPOSITE:
|
||||
case HAS:
|
||||
case SPECIAL:
|
||||
|
|
|
@ -11,6 +11,9 @@ 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;
|
||||
import org.hl7.fhir.dstu3.model.Patient;
|
||||
import org.hl7.fhir.dstu3.model.StringType;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r5.model.BaseDateTimeType;
|
||||
import org.hl7.fhir.r5.model.CodeableConcept;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
|
@ -40,6 +43,9 @@ public class InMemoryResourceMatcherR5Test {
|
|||
private static final String EARLY_DATE = "1965-08-09";
|
||||
private static final String LATE_DATE = "2000-06-29";
|
||||
public static final String OBSERVATION_CODE = "MATCH";
|
||||
private static final String SOURCE_URI = "urn:source:0";
|
||||
private static final String REQUEST_ID = "a_request_id";
|
||||
private static final String TEST_SOURCE = SOURCE_URI + "#" + REQUEST_ID;
|
||||
|
||||
@Autowired
|
||||
private
|
||||
|
@ -83,6 +89,7 @@ public class InMemoryResourceMatcherR5Test {
|
|||
when(mySearchParamRegistry.getActiveSearchParam("Observation", "encounter")).thenReturn(encSearchParam);
|
||||
|
||||
myObservation = new Observation();
|
||||
myObservation.getMeta().setSource(TEST_SOURCE);
|
||||
myObservation.setEffective(new DateTimeType(OBSERVATION_DATE));
|
||||
CodeableConcept codeableConcept = new CodeableConcept();
|
||||
codeableConcept.addCoding().setCode(OBSERVATION_CODE);
|
||||
|
@ -90,12 +97,24 @@ 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());
|
||||
{
|
||||
InMemoryMatchResult result = myInMemoryResourceMatcher.match(Constants.PARAM_SOURCE + "=" + TEST_SOURCE, myObservation, mySearchParams);
|
||||
assertTrue(result.matched());
|
||||
}
|
||||
{
|
||||
InMemoryMatchResult result = myInMemoryResourceMatcher.match(Constants.PARAM_SOURCE + "=" + SOURCE_URI, myObservation, mySearchParams);
|
||||
assertTrue(result.matched());
|
||||
}
|
||||
{
|
||||
InMemoryMatchResult result = myInMemoryResourceMatcher.match(Constants.PARAM_SOURCE + "=" + REQUEST_ID, myObservation, mySearchParams);
|
||||
assertFalse(result.matched());
|
||||
}
|
||||
{
|
||||
InMemoryMatchResult result = myInMemoryResourceMatcher.match(Constants.PARAM_SOURCE + "=#" + REQUEST_ID, myObservation, mySearchParams);
|
||||
assertTrue(result.matched());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue