Fix #331 - Don't split paths on or within words

This commit is contained in:
jamesagnew 2016-04-07 10:53:49 -04:00
parent b81a343f5d
commit 8588bdfd1f
2 changed files with 36 additions and 1 deletions

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -31,6 +32,7 @@ import ca.uhn.fhir.util.FhirTerser;
public class BaseSearchParamExtractor {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSearchParamExtractor.class);
private static final Pattern SPLIT = Pattern.compile("\\||( or )");
private FhirContext myContext;
public BaseSearchParamExtractor(FhirContext theContext) {
@ -43,7 +45,7 @@ public class BaseSearchParamExtractor {
protected List<Object> extractValues(String thePaths, IBaseResource theResource) {
List<Object> values = new ArrayList<Object>();
String[] nextPathsSplit = thePaths.split("\\||or");
String[] nextPathsSplit = SPLIT.split(thePaths);
FhirTerser t = myContext.newTerser();
for (String nextPath : nextPathsSplit) {
String nextPathTrimmed = nextPath.trim();

View File

@ -0,0 +1,33 @@
package ca.uhn.fhir.jpa.dao.dstu3;
import static org.junit.Assert.*;
import java.util.Set;
import org.hl7.fhir.dstu3.model.Observation;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.entity.ResourceTable;
public class SearchParamExtractorDstu3Test {
private static final FhirContext ourCtx = FhirContext.forDstu3();
@Test
public void testParamWithOrInPath() {
Observation obs = new Observation();
obs.getCategory().addCoding().setSystem("SYSTEM").setCode("CODE");
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(ourCtx);
Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(new ResourceTable(), obs);
assertEquals(1, tokens.size());
ResourceIndexedSearchParamToken token = (ResourceIndexedSearchParamToken) tokens.iterator().next();
assertEquals("category", token.getParamName());
assertEquals("SYSTEM", token.getSystem());
assertEquals("CODE", token.getValue());
}
}