mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-27 16:56:07 +00:00
Fix #331 - Don't split paths on or within words
This commit is contained in:
parent
b81a343f5d
commit
8588bdfd1f
@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.dao;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ import ca.uhn.fhir.util.FhirTerser;
|
|||||||
|
|
||||||
public class BaseSearchParamExtractor {
|
public class BaseSearchParamExtractor {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSearchParamExtractor.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSearchParamExtractor.class);
|
||||||
|
private static final Pattern SPLIT = Pattern.compile("\\||( or )");
|
||||||
private FhirContext myContext;
|
private FhirContext myContext;
|
||||||
|
|
||||||
public BaseSearchParamExtractor(FhirContext theContext) {
|
public BaseSearchParamExtractor(FhirContext theContext) {
|
||||||
@ -43,7 +45,7 @@ public class BaseSearchParamExtractor {
|
|||||||
|
|
||||||
protected List<Object> extractValues(String thePaths, IBaseResource theResource) {
|
protected List<Object> extractValues(String thePaths, IBaseResource theResource) {
|
||||||
List<Object> values = new ArrayList<Object>();
|
List<Object> values = new ArrayList<Object>();
|
||||||
String[] nextPathsSplit = thePaths.split("\\||or");
|
String[] nextPathsSplit = SPLIT.split(thePaths);
|
||||||
FhirTerser t = myContext.newTerser();
|
FhirTerser t = myContext.newTerser();
|
||||||
for (String nextPath : nextPathsSplit) {
|
for (String nextPath : nextPathsSplit) {
|
||||||
String nextPathTrimmed = nextPath.trim();
|
String nextPathTrimmed = nextPath.trim();
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user