A few more fixes
This commit is contained in:
parent
2b8426114f
commit
493ec707ca
|
@ -1,21 +1,21 @@
|
||||||
package ca.uhn.fhir.jpa.searchparam.extractor;
|
package ca.uhn.fhir.jpa.searchparam.extractor;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import ca.uhn.fhir.context.RuntimeSearchParam;
|
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||||
import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam;
|
import ca.uhn.fhir.jpa.model.entity.*;
|
||||||
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
|
|
||||||
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString;
|
|
||||||
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken;
|
|
||||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
|
||||||
import ca.uhn.fhir.jpa.model.util.StringNormalizer;
|
import ca.uhn.fhir.jpa.model.util.StringNormalizer;
|
||||||
import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam;
|
import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam;
|
||||||
|
import ca.uhn.fhir.jpa.searchparam.SearchParamConstants;
|
||||||
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
||||||
|
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport;
|
import org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport;
|
||||||
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
|
import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
|
||||||
import org.hl7.fhir.dstu3.model.Observation;
|
import org.hl7.fhir.dstu3.model.*;
|
||||||
import org.hl7.fhir.dstu3.model.Questionnaire;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -37,63 +37,7 @@ public class SearchParamExtractorDstu3Test {
|
||||||
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 MySearchParamRegistry();
|
||||||
@Override
|
|
||||||
public void forceRefresh() {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean refreshCacheIfNecessary() {
|
|
||||||
// nothing
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 requestRefresh() {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RuntimeSearchParam getSearchParamByName(RuntimeResourceDefinition theResourceDef, String theParamName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<RuntimeSearchParam> getSearchParamsByResourceType(RuntimeResourceDefinition theResourceDef) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
extractor.start();
|
extractor.start();
|
||||||
|
@ -116,63 +60,7 @@ public class SearchParamExtractorDstu3Test {
|
||||||
Questionnaire questionnaire = new Questionnaire();
|
Questionnaire questionnaire = new Questionnaire();
|
||||||
questionnaire.setDescription(value);
|
questionnaire.setDescription(value);
|
||||||
|
|
||||||
ISearchParamRegistry searchParamRegistry = new ISearchParamRegistry() {
|
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry();
|
||||||
@Override
|
|
||||||
public void forceRefresh() {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean refreshCacheIfNecessary() {
|
|
||||||
// nothing
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 requestRefresh() {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RuntimeSearchParam getSearchParamByName(RuntimeResourceDefinition theResourceDef, String theParamName) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<RuntimeSearchParam> getSearchParamsByResourceType(RuntimeResourceDefinition theResourceDef) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
extractor.start();
|
extractor.start();
|
||||||
|
@ -180,6 +68,183 @@ public class SearchParamExtractorDstu3Test {
|
||||||
assertEquals(1, params.size());
|
assertEquals(1, params.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncounterDuration_Normalized() {
|
||||||
|
|
||||||
|
Encounter enc = new Encounter();
|
||||||
|
Duration value = new Duration();
|
||||||
|
value.setSystem(SearchParamConstants.UCUM_NS);
|
||||||
|
value.setCode("min");
|
||||||
|
value.setValue(2 * 24 * 60);
|
||||||
|
enc.setLength(value);
|
||||||
|
|
||||||
|
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry();
|
||||||
|
|
||||||
|
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
|
extractor.start();
|
||||||
|
Set<ResourceIndexedSearchParamNumber> params = extractor.extractSearchParamNumber(enc);
|
||||||
|
assertEquals(1, params.size());
|
||||||
|
// Normalized to days
|
||||||
|
assertEquals("2", params.iterator().next().getValue().toPlainString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncounterDuration_NotNormalized() {
|
||||||
|
|
||||||
|
Encounter enc = new Encounter();
|
||||||
|
Duration value = new Duration();
|
||||||
|
value.setValue(15);
|
||||||
|
enc.setLength(value);
|
||||||
|
|
||||||
|
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry();
|
||||||
|
|
||||||
|
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
|
extractor.start();
|
||||||
|
Set<ResourceIndexedSearchParamNumber> params = extractor.extractSearchParamNumber(enc);
|
||||||
|
assertEquals(1, params.size());
|
||||||
|
// Normalized to days
|
||||||
|
assertEquals("15", params.iterator().next().getValue().toPlainString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidType() {
|
||||||
|
|
||||||
|
MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry();
|
||||||
|
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
|
||||||
|
extractor.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.STRING, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE));
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractSearchParamStrings(resource);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.TOKEN, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE));
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractSearchParamTokens(resource);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.QUANTITY, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE));
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractSearchParamQuantity(resource);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.DATE, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE));
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractSearchParamDates(resource);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.NUMBER, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE));
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractSearchParamNumber(resource);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.URI, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE));
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractSearchParamUri(resource);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
RuntimeSearchParam sp = new RuntimeSearchParam("foo", "foo", "Patient", RestSearchParameterTypeEnum.REFERENCE, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE);
|
||||||
|
searchParamRegistry.addSearchParam(sp);
|
||||||
|
Patient resource = new Patient();
|
||||||
|
extractor.extractResourceLinks(resource, sp);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
assertEquals("Search param foo is of unexpected datatype: class org.hl7.fhir.dstu3.model.Patient", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class MySearchParamRegistry implements ISearchParamRegistry {
|
||||||
|
|
||||||
|
private List<RuntimeSearchParam> myAddedSearchParams = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addSearchParam(RuntimeSearchParam... theSearchParam) {
|
||||||
|
myAddedSearchParams.clear();
|
||||||
|
for (RuntimeSearchParam next : theSearchParam) {
|
||||||
|
myAddedSearchParams.add(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forceRefresh() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuntimeSearchParam getActiveSearchParam(String theResourceName, String theParamName) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean refreshCacheIfNecessary() {
|
||||||
|
// nothing
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
for (RuntimeSearchParam next : myAddedSearchParams) {
|
||||||
|
sps.put(next.getName(), next);
|
||||||
|
}
|
||||||
|
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 requestRefresh() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuntimeSearchParam getSearchParamByName(RuntimeResourceDefinition theResourceDef, String theParamName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<RuntimeSearchParam> getSearchParamsByResourceType(RuntimeResourceDefinition theResourceDef) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
public static void afterClassClearContext() {
|
||||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||||
|
|
|
@ -14,80 +14,65 @@ public class SearchParamFinder {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
FhirContext ctx = FhirContext.forR5();
|
RestSearchParameterTypeEnum type = RestSearchParameterTypeEnum.TOKEN;
|
||||||
RestSearchParameterTypeEnum wantType = RestSearchParameterTypeEnum.NUMBER;
|
process(FhirContext.forDstu2(), type);
|
||||||
|
process(FhirContext.forDstu3(), type);
|
||||||
for (String nextResourceName : ctx.getResourceNames()) {
|
process(FhirContext.forR4(), type);
|
||||||
RuntimeResourceDefinition nextResDef = ctx.getResourceDefinition(nextResourceName);
|
process(FhirContext.forR5(), type);
|
||||||
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
|
||||||
|
|
||||||
if (nextSp.getParamType() == wantType) {
|
|
||||||
|
|
||||||
boolean logged = false;
|
|
||||||
for (String nextPath : nextSp.getPathsSplit()) {
|
|
||||||
|
|
||||||
List<String> pathsPart = new ArrayList<>(Arrays.asList(nextPath.split("\\.")));
|
|
||||||
|
|
||||||
BaseRuntimeElementCompositeDefinition def = null;
|
|
||||||
|
|
||||||
traverse(ctx, pathsPart, def);
|
|
||||||
// for (int i = 0; i < pathsPart.length; i++) {
|
|
||||||
// String nextPart = pathsPart[i];
|
|
||||||
//
|
|
||||||
// if (i == 0) {
|
|
||||||
// def = ctx.getResourceDefinition(nextPart);
|
|
||||||
// } else {
|
|
||||||
// BaseRuntimeChildDefinition child = def.getChildByName(nextPart);
|
|
||||||
// if (child == null) {
|
|
||||||
// child = def.getChildByName(nextPart + "[x]");
|
|
||||||
// }
|
|
||||||
// BaseRuntimeElementDefinition<?> childDef = child.getChildByName(nextPart);
|
|
||||||
// if (childDef instanceof RuntimePrimitiveDatatypeDefinition) {
|
|
||||||
// ourLog.info("SearchParam {} : {} : {} has {}", nextResourceName, nextSp.getName(), nextSp.getPath(), childDef.getName());
|
|
||||||
// logged = true;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// def = (BaseRuntimeElementCompositeDefinition) childDef;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!logged) {
|
|
||||||
ourLog.info("SearchParam {} : {} : {}", nextResourceName, nextSp.getName(), nextSp.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void traverse(FhirContext theContext, List<String> thePathsPart, BaseRuntimeElementCompositeDefinition theDef) {
|
public static void process(FhirContext theCtx, RestSearchParameterTypeEnum theWantType) {
|
||||||
|
for (String nextResourceName : theCtx.getResourceNames()) {
|
||||||
|
RuntimeResourceDefinition nextResDef = theCtx.getResourceDefinition(nextResourceName);
|
||||||
|
for (RuntimeSearchParam nextSp : nextResDef.getSearchParams()) {
|
||||||
|
if (nextSp.getParamType() == theWantType) {
|
||||||
|
for (String nextPath : nextSp.getPathsSplit()) {
|
||||||
|
List<String> pathsPart = new ArrayList<>(Arrays.asList(nextPath.split("\\.")));
|
||||||
|
BaseRuntimeElementCompositeDefinition def = null;
|
||||||
|
traverse(theCtx, nextSp, pathsPart, theCtx, pathsPart, def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void traverse(FhirContext theCtx, RuntimeSearchParam theSearchParam, List<String> theFullPath, FhirContext theContext, List<String> thePathsPart, BaseRuntimeElementCompositeDefinition theDef) {
|
||||||
if (thePathsPart.size() == 0) {
|
if (thePathsPart.size() == 0) {
|
||||||
ourLog.info("{} - {}", thePathsPart, theDef.getName());
|
ourLog.info("Found {} - {} - {} - {}", theCtx.getVersion().getVersion(), theSearchParam.getName(), String.join(".", theFullPath), theDef.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String nextName = thePathsPart.get(0);
|
String nextName = thePathsPart.get(0);
|
||||||
if (theDef == null) {
|
if (theDef == null) {
|
||||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(nextName);
|
RuntimeResourceDefinition def = theContext.getResourceDefinition(nextName);
|
||||||
traverse(theContext, thePathsPart.subList(1, thePathsPart.size()), def);
|
traverse(theCtx, theSearchParam, theFullPath, theContext, thePathsPart.subList(1, thePathsPart.size()), def);
|
||||||
} else {
|
} else {
|
||||||
BaseRuntimeChildDefinition child = theDef.getChildByName(nextName);
|
BaseRuntimeChildDefinition child = theDef.getChildByName(nextName);
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
BaseRuntimeElementCompositeDefinition def = (BaseRuntimeElementCompositeDefinition) child.getChildByName(nextName);
|
BaseRuntimeElementDefinition<?> subChild = child.getChildByName(nextName);
|
||||||
traverse(theContext, thePathsPart.subList(1, thePathsPart.size()), def);
|
if (subChild instanceof RuntimePrimitiveDatatypeDefinition) {
|
||||||
|
assert thePathsPart.size() == 1;
|
||||||
|
ourLog.info("Found {} - {} - {} - {}", theCtx.getVersion().getVersion(), theSearchParam.getName(), String.join(".", theFullPath), subChild.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseRuntimeElementCompositeDefinition def = (BaseRuntimeElementCompositeDefinition) subChild;
|
||||||
|
traverse(theCtx, theSearchParam, theFullPath, theContext, thePathsPart.subList(1, thePathsPart.size()), def);
|
||||||
}
|
}
|
||||||
|
|
||||||
RuntimeChildChoiceDefinition choiceChild = (RuntimeChildChoiceDefinition) theDef.getChildByName(nextName + "[x]");
|
RuntimeChildChoiceDefinition choiceChild = (RuntimeChildChoiceDefinition) theDef.getChildByName(nextName + "[x]");
|
||||||
if (choiceChild != null){
|
if (choiceChild != null){
|
||||||
for (String nextChildName : choiceChild.getValidChildNames()) {
|
for (String nextChildName : choiceChild.getValidChildNames()) {
|
||||||
if (nextChildName.startsWith(nextName)) {
|
if (nextChildName.startsWith(nextName)) {
|
||||||
BaseRuntimeElementCompositeDefinition def = (BaseRuntimeElementCompositeDefinition) choiceChild.getChildByName(nextChildName);
|
BaseRuntimeElementDefinition<?> subChild = choiceChild.getChildByName(nextChildName);
|
||||||
traverse(theContext, thePathsPart.subList(1, thePathsPart.size()), def);
|
if (subChild instanceof RuntimePrimitiveDatatypeDefinition) {
|
||||||
|
assert thePathsPart.size() == 1;
|
||||||
|
ourLog.info("Found {} - {} - {} - {}", theCtx.getVersion().getVersion(), theSearchParam.getName(), String.join(".", theFullPath), subChild.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BaseRuntimeElementCompositeDefinition def = (BaseRuntimeElementCompositeDefinition) subChild;
|
||||||
|
traverse(theCtx, theSearchParam, theFullPath, theContext, thePathsPart.subList(1, thePathsPart.size()), def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue