Correctly index Observation.applies[x] in JPA server
This commit is contained in:
parent
32ad3ab22c
commit
da1d49a108
|
@ -149,9 +149,13 @@ public class FhirTerser {
|
|||
if (nextDef instanceof RuntimeChildChoiceDefinition) {
|
||||
for (IBase next : values) {
|
||||
if (next != null) {
|
||||
String childName = nextDef.getChildNameByDatatype(next.getClass());
|
||||
if (theSubList.get(0).equals(childName)) {
|
||||
if (name.endsWith("[x]")) {
|
||||
retVal.add(next);
|
||||
} else {
|
||||
String childName = nextDef.getChildNameByDatatype(next.getClass());
|
||||
if (theSubList.get(0).equals(childName)) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,8 +180,8 @@ public abstract class BaseFhirDao implements IDao {
|
|||
if (nextValue.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (nextValue.getReference().getValue().startsWith("#")) {
|
||||
// This is a contained resource reference
|
||||
if (nextValue.getReference().isEmpty() || nextValue.getReference().getValue().startsWith("#")) {
|
||||
// This is a blank or contained resource reference
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
|
||||
public class BaseSearchParamExtractor {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSearchParamExtractor.class);
|
||||
private FhirContext myContext;
|
||||
|
||||
public BaseSearchParamExtractor(FhirContext theContext) {
|
||||
myContext = theContext;
|
||||
}
|
||||
|
||||
protected FhirContext getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
protected List<Object> extractValues(String thePaths, IResource theResource) {
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
String[] nextPathsSplit = thePaths.split("\\|");
|
||||
FhirTerser t = myContext.newTerser();
|
||||
for (String nextPath : nextPathsSplit) {
|
||||
String nextPathTrimmed = nextPath.trim();
|
||||
try {
|
||||
values.addAll(t.getValues(theResource, nextPathTrimmed));
|
||||
} catch (Exception e) {
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
ourLog.warn("Failed to index values from path[{}] in resource type[{}]: ", nextPathTrimmed, def.getName(), e.toString());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -63,21 +63,18 @@ import ca.uhn.fhir.model.primitive.BaseDateTimeDt;
|
|||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
|
||||
class SearchParamExtractorDstu1 implements ISearchParamExtractor {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchParamExtractorDstu1.class);
|
||||
private FhirContext myContext;
|
||||
class SearchParamExtractorDstu1 extends BaseSearchParamExtractor implements ISearchParamExtractor {
|
||||
|
||||
public SearchParamExtractorDstu1(FhirContext theContext) {
|
||||
myContext = theContext;
|
||||
super(theContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamDate> retVal = new ArrayList<ResourceIndexedSearchParamDate>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.DATE) {
|
||||
continue;
|
||||
|
@ -134,7 +131,7 @@ class SearchParamExtractorDstu1 implements ISearchParamExtractor {
|
|||
public ArrayList<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamNumber> retVal = new ArrayList<ResourceIndexedSearchParamNumber>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.NUMBER) {
|
||||
continue;
|
||||
|
@ -231,7 +228,7 @@ class SearchParamExtractorDstu1 implements ISearchParamExtractor {
|
|||
public List<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamQuantity> retVal = new ArrayList<ResourceIndexedSearchParamQuantity>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.QUANTITY) {
|
||||
continue;
|
||||
|
@ -281,7 +278,7 @@ class SearchParamExtractorDstu1 implements ISearchParamExtractor {
|
|||
public List<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamString> retVal = new ArrayList<ResourceIndexedSearchParamString>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.STRING) {
|
||||
continue;
|
||||
|
@ -369,7 +366,7 @@ class SearchParamExtractorDstu1 implements ISearchParamExtractor {
|
|||
public List<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<BaseResourceIndexedSearchParam> retVal = new ArrayList<BaseResourceIndexedSearchParam>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.TOKEN) {
|
||||
continue;
|
||||
|
@ -475,20 +472,4 @@ class SearchParamExtractorDstu1 implements ISearchParamExtractor {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private List<Object> extractValues(String thePaths, IResource theResource) {
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
String[] nextPathsSplit = thePaths.split("\\|");
|
||||
FhirTerser t = myContext.newTerser();
|
||||
for (String nextPath : nextPathsSplit) {
|
||||
String nextPathTrimmed = nextPath.trim();
|
||||
try {
|
||||
values.addAll(t.getValues(theResource, nextPathTrimmed));
|
||||
} catch (Exception e) {
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
ourLog.warn("Failed to index values from path[{}] in resource type[{}]: ", nextPathTrimmed, def.getName(), e.toString());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ package ca.uhn.fhir.jpa.dao;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
@ -64,14 +63,11 @@ import ca.uhn.fhir.model.primitive.BaseDateTimeDt;
|
|||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
|
||||
class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchParamExtractorDstu2.class);
|
||||
private FhirContext myContext;
|
||||
class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implements ISearchParamExtractor {
|
||||
|
||||
public SearchParamExtractorDstu2(FhirContext theContext) {
|
||||
myContext = theContext;
|
||||
super(theContext);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -84,7 +80,7 @@ class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
|||
public List<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamDate> retVal = new ArrayList<ResourceIndexedSearchParamDate>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.DATE) {
|
||||
continue;
|
||||
|
@ -147,7 +143,7 @@ class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
|||
public ArrayList<ResourceIndexedSearchParamNumber> extractSearchParamNumber(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamNumber> retVal = new ArrayList<ResourceIndexedSearchParamNumber>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.NUMBER) {
|
||||
continue;
|
||||
|
@ -250,7 +246,7 @@ class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
|||
public List<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamQuantity> retVal = new ArrayList<ResourceIndexedSearchParamQuantity>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.QUANTITY) {
|
||||
continue;
|
||||
|
@ -306,7 +302,7 @@ class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
|||
public List<ResourceIndexedSearchParamString> extractSearchParamStrings(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<ResourceIndexedSearchParamString> retVal = new ArrayList<ResourceIndexedSearchParamString>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.STRING) {
|
||||
continue;
|
||||
|
@ -400,7 +396,7 @@ class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
|||
public List<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) {
|
||||
ArrayList<BaseResourceIndexedSearchParam> retVal = new ArrayList<BaseResourceIndexedSearchParam>();
|
||||
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource);
|
||||
for (RuntimeSearchParam nextSpDef : def.getSearchParams()) {
|
||||
if (nextSpDef.getParamType() != SearchParamTypeEnum.TOKEN) {
|
||||
continue;
|
||||
|
@ -506,20 +502,4 @@ class SearchParamExtractorDstu2 implements ISearchParamExtractor {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private List<Object> extractValues(String thePaths, IResource theResource) {
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
String[] nextPathsSplit = thePaths.split("\\|");
|
||||
FhirTerser t = myContext.newTerser();
|
||||
for (String nextPath : nextPathsSplit) {
|
||||
String nextPathTrimmed = nextPath.trim();
|
||||
try {
|
||||
values.addAll(t.getValues(theResource, nextPathTrimmed));
|
||||
} catch (Exception e) {
|
||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||
ourLog.warn("Failed to index values from path[{}] in resource type[{}]: ", nextPathTrimmed, def.getName(), e.toString());
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -294,6 +294,23 @@ public class FhirResourceDaoTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChoiceParamDateAlt() {
|
||||
Observation o2 = new Observation();
|
||||
o2.getCode().addCoding().setSystem("foo").setCode("testChoiceParamDateAlt02");
|
||||
o2.setApplies(new DateTimeDt("2015-03-08T11:11:11"));
|
||||
IdDt id2 = ourObservationDao.create(o2).getId();
|
||||
|
||||
{
|
||||
Set<Long> found = ourObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2001-01-02"));
|
||||
assertThat(found, contains(id2.getIdPartAsLong()));
|
||||
}
|
||||
{
|
||||
Set<Long> found = ourObservationDao.searchForIds(Observation.SP_DATE, new DateParam(">2016-01-02"));
|
||||
assertThat(found, not(contains(id2.getIdPartAsLong())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChoiceParamQuantity() {
|
||||
Observation o3 = new Observation();
|
||||
|
|
|
@ -135,6 +135,10 @@
|
|||
specification, for the Generic Client, Annotation Client, and
|
||||
Server.
|
||||
</action>
|
||||
<action type="fix">
|
||||
Observation.applies[x] and other similar search fields with multiple allowable
|
||||
value types were not being correctly indexed in the JPA server.
|
||||
</action>
|
||||
</release>
|
||||
<release version="0.8" date="2014-Dec-17">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue