Adjust unit tests to deal with asynchronous search parameter registry
This commit is contained in:
parent
e6253b7f22
commit
4f45ad87f3
|
@ -632,7 +632,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mySearchParamRegistry.forceRefresh();
|
mySearchParamRegistry.requestRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,12 +61,18 @@ public abstract class BaseSearchParamRegistry<SP extends IBaseResource> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forceRefresh() {
|
public void requestRefresh() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
myLastRefresh = 0;
|
myLastRefresh = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forceRefresh() {
|
||||||
|
requestRefresh();
|
||||||
|
refreshCacheIfNecessary();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
||||||
RuntimeSearchParam retVal = null;
|
RuntimeSearchParam retVal = null;
|
||||||
|
|
|
@ -29,6 +29,9 @@ import java.util.Set;
|
||||||
|
|
||||||
public interface ISearchParamRegistry {
|
public interface ISearchParamRegistry {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the cache be refreshed now, in the current thread
|
||||||
|
*/
|
||||||
void forceRefresh();
|
void forceRefresh();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,13 +39,18 @@ public interface ISearchParamRegistry {
|
||||||
*/
|
*/
|
||||||
RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName);
|
RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName);
|
||||||
|
|
||||||
Map<String, RuntimeSearchParam> getActiveSearchParams(String theResourceName);
|
|
||||||
|
|
||||||
Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams();
|
Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams();
|
||||||
|
|
||||||
List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName);
|
Map<String, RuntimeSearchParam> getActiveSearchParams(String theResourceName);
|
||||||
|
|
||||||
List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName, Set<String> theParamNames);
|
List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName, Set<String> theParamNames);
|
||||||
|
|
||||||
|
List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName);
|
||||||
|
|
||||||
void refreshCacheIfNecessary();
|
void refreshCacheIfNecessary();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request that the cache be refreshed at the next convenient time (in a different thread)
|
||||||
|
*/
|
||||||
|
void requestRefresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.internal.util.collections.ListUtil;
|
import org.mockito.internal.util.collections.ListUtil;
|
||||||
import org.thymeleaf.util.ListUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -54,93 +53,6 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOverrideAndDisableBuiltInSearchParametersWithOverridingEnabled() {
|
|
||||||
myDaoConfig.setDefaultSearchParamsCanBeOverridden(true);
|
|
||||||
|
|
||||||
SearchParameter memberSp = new SearchParameter();
|
|
||||||
memberSp.setCode("member");
|
|
||||||
memberSp.setBase(ResourceTypeEnum.GROUP);
|
|
||||||
memberSp.setType(SearchParamTypeEnum.REFERENCE);
|
|
||||||
memberSp.setXpath("Group.member.entity");
|
|
||||||
memberSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
|
||||||
memberSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
|
||||||
mySearchParameterDao.create(memberSp, mySrd);
|
|
||||||
|
|
||||||
SearchParameter identifierSp = new SearchParameter();
|
|
||||||
identifierSp.setCode("identifier");
|
|
||||||
identifierSp.setBase(ResourceTypeEnum.GROUP);
|
|
||||||
identifierSp.setType(SearchParamTypeEnum.TOKEN);
|
|
||||||
identifierSp.setXpath("Group.identifier");
|
|
||||||
identifierSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
|
||||||
identifierSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
|
||||||
mySearchParameterDao.create(identifierSp, mySrd);
|
|
||||||
|
|
||||||
mySearchParamRegsitry.forceRefresh();
|
|
||||||
|
|
||||||
Patient p = new Patient();
|
|
||||||
p.addName().addGiven("G");
|
|
||||||
IIdType pid = myPatientDao.create(p).getId().toUnqualifiedVersionless();
|
|
||||||
|
|
||||||
Group g = new Group();
|
|
||||||
g.addIdentifier().setSystem("urn:foo").setValue("bar");
|
|
||||||
g.addMember().getEntity().setReference(pid);
|
|
||||||
myGroupDao.create(g);
|
|
||||||
|
|
||||||
assertThat(myResourceLinkDao.findAll(), empty());
|
|
||||||
assertThat(ListUtil.filter(myResourceIndexedSearchParamTokenDao.findAll(), new ListUtil.Filter<ResourceIndexedSearchParamToken>() {
|
|
||||||
@Override
|
|
||||||
public boolean isOut(ResourceIndexedSearchParamToken object) {
|
|
||||||
return !object.getResourceType().equals("Group") || object.isMissing();
|
|
||||||
}
|
|
||||||
}), empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOverrideAndDisableBuiltInSearchParametersWithOverridingDisabled() {
|
|
||||||
myDaoConfig.setDefaultSearchParamsCanBeOverridden(false);
|
|
||||||
|
|
||||||
SearchParameter memberSp = new SearchParameter();
|
|
||||||
memberSp.setCode("member");
|
|
||||||
memberSp.setBase(ResourceTypeEnum.GROUP);
|
|
||||||
memberSp.setType(SearchParamTypeEnum.REFERENCE);
|
|
||||||
memberSp.setXpath("Group.member.entity");
|
|
||||||
memberSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
|
||||||
memberSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
|
||||||
mySearchParameterDao.create(memberSp, mySrd);
|
|
||||||
|
|
||||||
SearchParameter identifierSp = new SearchParameter();
|
|
||||||
identifierSp.setCode("identifier");
|
|
||||||
identifierSp.setBase(ResourceTypeEnum.GROUP);
|
|
||||||
identifierSp.setType(SearchParamTypeEnum.TOKEN);
|
|
||||||
identifierSp.setXpath("Group.identifier");
|
|
||||||
identifierSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
|
||||||
identifierSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
|
||||||
mySearchParameterDao.create(identifierSp, mySrd);
|
|
||||||
|
|
||||||
mySearchParamRegsitry.forceRefresh();
|
|
||||||
|
|
||||||
Patient p = new Patient();
|
|
||||||
p.addName().addGiven("G");
|
|
||||||
IIdType pid = myPatientDao.create(p).getId().toUnqualifiedVersionless();
|
|
||||||
|
|
||||||
Group g = new Group();
|
|
||||||
g.addIdentifier().setSystem("urn:foo").setValue("bar");
|
|
||||||
g.addMember().getEntity().setReference(pid);
|
|
||||||
myGroupDao.create(g);
|
|
||||||
|
|
||||||
assertThat(myResourceLinkDao.findAll(), not(empty()));
|
|
||||||
assertThat(ListUtil.filter(myResourceIndexedSearchParamTokenDao.findAll(), new ListUtil.Filter<ResourceIndexedSearchParamToken>() {
|
|
||||||
@Override
|
|
||||||
public boolean isOut(ResourceIndexedSearchParamToken object) {
|
|
||||||
return !object.getResourceType().equals("Group") || object.isMissing();
|
|
||||||
}
|
|
||||||
}), not(empty()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateInvalidParamInvalidResourceName() {
|
public void testCreateInvalidParamInvalidResourceName() {
|
||||||
SearchParameter fooSp = new SearchParameter();
|
SearchParameter fooSp = new SearchParameter();
|
||||||
|
@ -228,7 +140,7 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomReferenceParameter() throws Exception {
|
public void testCustomReferenceParameter() {
|
||||||
SearchParameter sp = new SearchParameter();
|
SearchParameter sp = new SearchParameter();
|
||||||
sp.setBase(ResourceTypeEnum.PATIENT);
|
sp.setBase(ResourceTypeEnum.PATIENT);
|
||||||
sp.setCode("myDoctor");
|
sp.setCode("myDoctor");
|
||||||
|
@ -238,6 +150,8 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu
|
||||||
sp.setStatus(ConformanceResourceStatusEnum.ACTIVE);
|
sp.setStatus(ConformanceResourceStatusEnum.ACTIVE);
|
||||||
mySearchParameterDao.create(sp);
|
mySearchParameterDao.create(sp);
|
||||||
|
|
||||||
|
mySearchParamRegsitry.forceRefresh();
|
||||||
|
|
||||||
Practitioner pract = new Practitioner();
|
Practitioner pract = new Practitioner();
|
||||||
pract.setId("A");
|
pract.setId("A");
|
||||||
pract.getName().addFamily("PRACT");
|
pract.getName().addFamily("PRACT");
|
||||||
|
@ -316,6 +230,90 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOverrideAndDisableBuiltInSearchParametersWithOverridingDisabled() {
|
||||||
|
myDaoConfig.setDefaultSearchParamsCanBeOverridden(false);
|
||||||
|
|
||||||
|
SearchParameter memberSp = new SearchParameter();
|
||||||
|
memberSp.setCode("member");
|
||||||
|
memberSp.setBase(ResourceTypeEnum.GROUP);
|
||||||
|
memberSp.setType(SearchParamTypeEnum.REFERENCE);
|
||||||
|
memberSp.setXpath("Group.member.entity");
|
||||||
|
memberSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
||||||
|
memberSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
||||||
|
mySearchParameterDao.create(memberSp, mySrd);
|
||||||
|
|
||||||
|
SearchParameter identifierSp = new SearchParameter();
|
||||||
|
identifierSp.setCode("identifier");
|
||||||
|
identifierSp.setBase(ResourceTypeEnum.GROUP);
|
||||||
|
identifierSp.setType(SearchParamTypeEnum.TOKEN);
|
||||||
|
identifierSp.setXpath("Group.identifier");
|
||||||
|
identifierSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
||||||
|
identifierSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
||||||
|
mySearchParameterDao.create(identifierSp, mySrd);
|
||||||
|
|
||||||
|
mySearchParamRegsitry.forceRefresh();
|
||||||
|
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName().addGiven("G");
|
||||||
|
IIdType pid = myPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
Group g = new Group();
|
||||||
|
g.addIdentifier().setSystem("urn:foo").setValue("bar");
|
||||||
|
g.addMember().getEntity().setReference(pid);
|
||||||
|
myGroupDao.create(g);
|
||||||
|
|
||||||
|
assertThat(myResourceLinkDao.findAll(), not(empty()));
|
||||||
|
assertThat(ListUtil.filter(myResourceIndexedSearchParamTokenDao.findAll(), new ListUtil.Filter<ResourceIndexedSearchParamToken>() {
|
||||||
|
@Override
|
||||||
|
public boolean isOut(ResourceIndexedSearchParamToken object) {
|
||||||
|
return !object.getResourceType().equals("Group") || object.isMissing();
|
||||||
|
}
|
||||||
|
}), not(empty()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOverrideAndDisableBuiltInSearchParametersWithOverridingEnabled() {
|
||||||
|
myDaoConfig.setDefaultSearchParamsCanBeOverridden(true);
|
||||||
|
|
||||||
|
SearchParameter memberSp = new SearchParameter();
|
||||||
|
memberSp.setCode("member");
|
||||||
|
memberSp.setBase(ResourceTypeEnum.GROUP);
|
||||||
|
memberSp.setType(SearchParamTypeEnum.REFERENCE);
|
||||||
|
memberSp.setXpath("Group.member.entity");
|
||||||
|
memberSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
||||||
|
memberSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
||||||
|
mySearchParameterDao.create(memberSp, mySrd);
|
||||||
|
|
||||||
|
SearchParameter identifierSp = new SearchParameter();
|
||||||
|
identifierSp.setCode("identifier");
|
||||||
|
identifierSp.setBase(ResourceTypeEnum.GROUP);
|
||||||
|
identifierSp.setType(SearchParamTypeEnum.TOKEN);
|
||||||
|
identifierSp.setXpath("Group.identifier");
|
||||||
|
identifierSp.setXpathUsage(XPathUsageTypeEnum.NORMAL);
|
||||||
|
identifierSp.setStatus(ConformanceResourceStatusEnum.RETIRED);
|
||||||
|
mySearchParameterDao.create(identifierSp, mySrd);
|
||||||
|
|
||||||
|
mySearchParamRegsitry.forceRefresh();
|
||||||
|
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName().addGiven("G");
|
||||||
|
IIdType pid = myPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
Group g = new Group();
|
||||||
|
g.addIdentifier().setSystem("urn:foo").setValue("bar");
|
||||||
|
g.addMember().getEntity().setReference(pid);
|
||||||
|
myGroupDao.create(g);
|
||||||
|
|
||||||
|
assertThat(myResourceLinkDao.findAll(), empty());
|
||||||
|
assertThat(ListUtil.filter(myResourceIndexedSearchParamTokenDao.findAll(), new ListUtil.Filter<ResourceIndexedSearchParamToken>() {
|
||||||
|
@Override
|
||||||
|
public boolean isOut(ResourceIndexedSearchParamToken object) {
|
||||||
|
return !object.getResourceType().equals("Group") || object.isMissing();
|
||||||
|
}
|
||||||
|
}), empty());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchForExtensionReferenceWithNonMatchingTarget() {
|
public void testSearchForExtensionReferenceWithNonMatchingTarget() {
|
||||||
SearchParameter siblingSp = new SearchParameter();
|
SearchParameter siblingSp = new SearchParameter();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,58 +29,58 @@ public class SearchParamExtractorDstu3Test {
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu3();
|
private static FhirContext ourCtx = FhirContext.forDstu3();
|
||||||
private static IValidationSupport ourValidationSupport;
|
private static IValidationSupport ourValidationSupport;
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void afterClassClearContext() {
|
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() {
|
|
||||||
ourValidationSupport = new DefaultProfileValidationSupport();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParamWithOrInPath() {
|
public void testParamWithOrInPath() {
|
||||||
Observation obs = new Observation();
|
Observation obs = new Observation();
|
||||||
obs.addCategory().addCoding().setSystem("SYSTEM").setCode("CODE");
|
obs.addCategory().addCoding().setSystem("SYSTEM").setCode("CODE");
|
||||||
|
|
||||||
ISearchParamRegistry searchParamRegistry = new ISearchParamRegistry() {
|
ISearchParamRegistry searchParamRegistry = new ISearchParamRegistry() {
|
||||||
@Override
|
|
||||||
public Map<String,RuntimeSearchParam> getActiveSearchParams(String theResourceName) {
|
|
||||||
RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName);
|
|
||||||
Map<String, RuntimeSearchParam> sps = new HashMap<String, RuntimeSearchParam>();
|
|
||||||
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
|
||||||
sps.put(nextSp.getName(), nextSp);
|
|
||||||
}
|
|
||||||
return sps;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName, Set<String> theParamNames) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forceRefresh() {
|
public void forceRefresh() {
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
|
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
public Map<String,RuntimeSearchParam> getActiveSearchParams(String theResourceName) {
|
||||||
|
RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName);
|
||||||
|
Map<String, RuntimeSearchParam> sps = new HashMap<>();
|
||||||
|
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
||||||
|
sps.put(nextSp.getName(), nextSp);
|
||||||
|
}
|
||||||
|
return sps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName, Set<String> theParamNames) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshCacheIfNecessary() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestRefresh() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(ourCtx, ourValidationSupport, searchParamRegistry);
|
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(new ResourceTable(), obs);
|
Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(new ResourceTable(), obs);
|
||||||
assertEquals(1, tokens.size());
|
assertEquals(1, tokens.size());
|
||||||
|
@ -89,5 +89,15 @@ public class SearchParamExtractorDstu3Test {
|
||||||
assertEquals("SYSTEM", token.getSystem());
|
assertEquals("SYSTEM", token.getSystem());
|
||||||
assertEquals("CODE", token.getValue());
|
assertEquals("CODE", token.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void afterClassClearContext() {
|
||||||
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
ourValidationSupport = new DefaultProfileValidationSupport();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,8 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
|
||||||
sp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE);
|
sp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE);
|
||||||
mySearchParameterDao.create(sp);
|
mySearchParameterDao.create(sp);
|
||||||
|
|
||||||
|
mySearchParamRegsitry.forceRefresh();
|
||||||
|
|
||||||
org.hl7.fhir.r4.model.Practitioner pract = new org.hl7.fhir.r4.model.Practitioner();
|
org.hl7.fhir.r4.model.Practitioner pract = new org.hl7.fhir.r4.model.Practitioner();
|
||||||
pract.setId("A");
|
pract.setId("A");
|
||||||
pract.addName().setFamily("PRACT");
|
pract.addName().setFamily("PRACT");
|
||||||
|
|
|
@ -1,25 +1,94 @@
|
||||||
package ca.uhn.fhir.jpa.dao.r4;
|
package ca.uhn.fhir.jpa.dao.r4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import java.util.*;
|
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||||
|
import ca.uhn.fhir.jpa.dao.ISearchParamRegistry;
|
||||||
|
import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam;
|
||||||
|
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken;
|
||||||
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import ca.uhn.fhir.jpa.search.JpaRuntimeSearchParam;
|
import ca.uhn.fhir.jpa.search.JpaRuntimeSearchParam;
|
||||||
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
|
import org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport;
|
||||||
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
|
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
|
||||||
import org.hl7.fhir.r4.model.Observation;
|
import org.hl7.fhir.r4.model.Observation;
|
||||||
import org.junit.*;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.*;
|
import java.util.HashMap;
|
||||||
import ca.uhn.fhir.jpa.dao.ISearchParamRegistry;
|
import java.util.List;
|
||||||
import ca.uhn.fhir.jpa.entity.*;
|
import java.util.Map;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SearchParamExtractorR4Test {
|
public class SearchParamExtractorR4Test {
|
||||||
|
|
||||||
private static FhirContext ourCtx = FhirContext.forR4();
|
private static FhirContext ourCtx = FhirContext.forR4();
|
||||||
private static IValidationSupport ourValidationSupport;
|
private static IValidationSupport ourValidationSupport;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParamWithOrInPath() {
|
||||||
|
Observation obs = new Observation();
|
||||||
|
obs.addCategory().addCoding().setSystem("SYSTEM").setCode("CODE");
|
||||||
|
|
||||||
|
ISearchParamRegistry searchParamRegistry = new ISearchParamRegistry() {
|
||||||
|
@Override
|
||||||
|
public void forceRefresh() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, RuntimeSearchParam> getActiveSearchParams(String theResourceName) {
|
||||||
|
RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName);
|
||||||
|
Map<String, RuntimeSearchParam> sps = new HashMap<>();
|
||||||
|
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
||||||
|
sps.put(nextSp.getName(), nextSp);
|
||||||
|
}
|
||||||
|
return sps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName, Set<String> theParamNames) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshCacheIfNecessary() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestRefresh() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SearchParamExtractorR4 extractor = new SearchParamExtractorR4(ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
@ -29,56 +98,5 @@ public class SearchParamExtractorR4Test {
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
ourValidationSupport = new DefaultProfileValidationSupport();
|
ourValidationSupport = new DefaultProfileValidationSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParamWithOrInPath() {
|
|
||||||
Observation obs = new Observation();
|
|
||||||
obs.addCategory().addCoding().setSystem("SYSTEM").setCode("CODE");
|
|
||||||
|
|
||||||
ISearchParamRegistry searchParamRegistry = new ISearchParamRegistry() {
|
|
||||||
@Override
|
|
||||||
public Map<String,RuntimeSearchParam> getActiveSearchParams(String theResourceName) {
|
|
||||||
RuntimeResourceDefinition nextResDef = ourCtx.getResourceDefinition(theResourceName);
|
|
||||||
Map<String, RuntimeSearchParam> sps = new HashMap<String, RuntimeSearchParam>();
|
|
||||||
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
|
||||||
sps.put(nextSp.getName(), nextSp);
|
|
||||||
}
|
|
||||||
return sps;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<JpaRuntimeSearchParam> getActiveUniqueSearchParams(String theResourceName, Set<String> theParamNames) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void forceRefresh() {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Map<String, RuntimeSearchParam>> getActiveSearchParams() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SearchParamExtractorR4 extractor = new SearchParamExtractorR4(ourCtx, ourValidationSupport, searchParamRegistry);
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ public class ResourceProviderCustomSearchParamDstu3Test extends BaseResourceProv
|
||||||
.resource(eyeColourSp)
|
.resource(eyeColourSp)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// mySearchParamRegsitry.forceRefresh();
|
mySearchParamRegsitry.forceRefresh();
|
||||||
|
|
||||||
Patient p1 = new Patient();
|
Patient p1 = new Patient();
|
||||||
p1.setActive(true);
|
p1.setActive(true);
|
||||||
|
|
|
@ -306,7 +306,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide
|
||||||
.resource(eyeColourSp)
|
.resource(eyeColourSp)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// mySearchParamRegsitry.forceRefresh();
|
mySearchParamRegsitry.forceRefresh();
|
||||||
|
|
||||||
Patient p1 = new Patient();
|
Patient p1 = new Patient();
|
||||||
p1.setActive(true);
|
p1.setActive(true);
|
||||||
|
|
Loading…
Reference in New Issue