mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-13 08:14:46 +00:00
Significant improvement to performance rendering value sets, and only use server side caching if the server declares it supports it
This commit is contained in:
parent
7021969ea2
commit
7771c7f231
@ -3439,6 +3439,8 @@ public class VersionConvertor_10_50 {
|
|||||||
for (ParametersParameterComponent p : src.getParameter()) {
|
for (ParametersParameterComponent p : src.getParameter()) {
|
||||||
if (p.getName().equals("system"))
|
if (p.getName().equals("system"))
|
||||||
res.addCodeSystem().setUri(p.getValue().primitiveValue());
|
res.addCodeSystem().setUri(p.getValue().primitiveValue());
|
||||||
|
if (p.getName().equals("expansion.parameter"))
|
||||||
|
res.getExpansion().addParameter().setName(p.getValue().primitiveValue());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -5539,6 +5539,8 @@ public class VersionConvertor_30_50 {
|
|||||||
for (ParametersParameterComponent p : src.getParameter()) {
|
for (ParametersParameterComponent p : src.getParameter()) {
|
||||||
if (p.getName().equals("system"))
|
if (p.getName().equals("system"))
|
||||||
res.addCodeSystem().setUri(p.getValue().primitiveValue());
|
res.addCodeSystem().setUri(p.getValue().primitiveValue());
|
||||||
|
if (p.getName().equals("expansion.parameter"))
|
||||||
|
res.getExpansion().addParameter().setName(p.getValue().primitiveValue());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
|
|||||||
import org.hl7.fhir.r5.model.StructureMap;
|
import org.hl7.fhir.r5.model.StructureMap;
|
||||||
import org.hl7.fhir.r5.model.TerminologyCapabilities;
|
import org.hl7.fhir.r5.model.TerminologyCapabilities;
|
||||||
import org.hl7.fhir.r5.model.TerminologyCapabilities.TerminologyCapabilitiesCodeSystemComponent;
|
import org.hl7.fhir.r5.model.TerminologyCapabilities.TerminologyCapabilitiesCodeSystemComponent;
|
||||||
|
import org.hl7.fhir.r5.model.TerminologyCapabilities.TerminologyCapabilitiesExpansionParameterComponent;
|
||||||
import org.hl7.fhir.r5.model.UriType;
|
import org.hl7.fhir.r5.model.UriType;
|
||||||
import org.hl7.fhir.r5.model.ValueSet;
|
import org.hl7.fhir.r5.model.ValueSet;
|
||||||
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
||||||
@ -156,6 +157,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
private Object lock = new Object(); // used as a lock for the data that follows
|
private Object lock = new Object(); // used as a lock for the data that follows
|
||||||
protected String version;
|
protected String version;
|
||||||
private String cacheId;
|
private String cacheId;
|
||||||
|
private boolean isTxCaching;
|
||||||
private Set<String> cached = new HashSet<>();
|
private Set<String> cached = new HashSet<>();
|
||||||
|
|
||||||
private Map<String, Map<String, Resource>> allResourcesById = new HashMap<String, Map<String, Resource>>();
|
private Map<String, Map<String, Resource>> allResourcesById = new HashMap<String, Map<String, Resource>>();
|
||||||
@ -504,7 +506,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
if (txcaps == null) {
|
if (txcaps == null) {
|
||||||
try {
|
try {
|
||||||
log("Terminology server: Check for supported code systems for "+system);
|
log("Terminology server: Check for supported code systems for "+system);
|
||||||
txcaps = txClient.getTerminologyCapabilities();
|
setTxCaps(txClient.getTerminologyCapabilities());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (canRunWithoutTerminology) {
|
if (canRunWithoutTerminology) {
|
||||||
noTerminologyServer = true;
|
noTerminologyServer = true;
|
||||||
@ -520,11 +522,6 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
throw new TerminologyServiceException(e);
|
throw new TerminologyServiceException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (txcaps != null) {
|
|
||||||
for (TerminologyCapabilitiesCodeSystemComponent tccs : txcaps.getCodeSystem()) {
|
|
||||||
supportedCodeSystems.add(tccs.getUri());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (supportedCodeSystems.contains(system)) {
|
if (supportedCodeSystems.contains(system)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -588,7 +585,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
Parameters p = expParameters.copy();
|
Parameters p = expParameters.copy();
|
||||||
p.setParameter("includeDefinition", false);
|
p.setParameter("includeDefinition", false);
|
||||||
p.setParameter("excludeNested", !hierarchical);
|
p.setParameter("excludeNested", !hierarchical);
|
||||||
if (cacheId != null) {
|
if (isTxCaching && cacheId != null) {
|
||||||
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
|
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
|
||||||
}
|
}
|
||||||
addDependentResources(p, vs);
|
addDependentResources(p, vs);
|
||||||
@ -663,7 +660,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if that failed, we try to expand on the server
|
// if that failed, we try to expand on the server
|
||||||
if (cacheId != null) {
|
if (isTxCaching && cacheId != null) {
|
||||||
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
|
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
|
||||||
}
|
}
|
||||||
addDependentResources(p, vs);
|
addDependentResources(p, vs);
|
||||||
@ -927,11 +924,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
|
private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
|
||||||
if (cacheId != null) {
|
if (isTxCaching && cacheId != null) {
|
||||||
pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
|
pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
|
||||||
}
|
}
|
||||||
if (vs != null) {
|
if (vs != null) {
|
||||||
if (cacheId != null && cached.contains(vs.getUrl()+"|"+vs.getVersion())) {
|
if (isTxCaching && cacheId != null && cached.contains(vs.getUrl()+"|"+vs.getVersion())) {
|
||||||
pin.addParameter().setName("url").setValue(new UriType(vs.getUrl()+"|"+vs.getVersion()));
|
pin.addParameter().setName("url").setValue(new UriType(vs.getUrl()+"|"+vs.getVersion()));
|
||||||
} else {
|
} else {
|
||||||
pin.addParameter().setName("valueSet").setResource(vs);
|
pin.addParameter().setName("valueSet").setResource(vs);
|
||||||
@ -976,7 +973,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
for (CanonicalType c : inc.getValueSet()) {
|
for (CanonicalType c : inc.getValueSet()) {
|
||||||
ValueSet vs = fetchResource(ValueSet.class, c.getValue());
|
ValueSet vs = fetchResource(ValueSet.class, c.getValue());
|
||||||
if (vs != null) {
|
if (vs != null) {
|
||||||
if (cacheId == null || !cached.contains(vs.getVUrl())) {
|
if (isTxCaching && cacheId == null || !cached.contains(vs.getVUrl())) {
|
||||||
pin.addParameter().setName("tx-resource").setResource(vs);
|
pin.addParameter().setName("tx-resource").setResource(vs);
|
||||||
cached.add(vs.getVUrl());
|
cached.add(vs.getVUrl());
|
||||||
}
|
}
|
||||||
@ -985,7 +982,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
}
|
}
|
||||||
CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem());
|
CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem());
|
||||||
if (cs != null) {
|
if (cs != null) {
|
||||||
if (cacheId == null || !cached.contains(cs.getVUrl())) {
|
if (isTxCaching && cacheId == null || !cached.contains(cs.getVUrl())) {
|
||||||
pin.addParameter().setName("tx-resource").setResource(cs);
|
pin.addParameter().setName("tx-resource").setResource(cs);
|
||||||
cached.add(cs.getVUrl());
|
cached.add(cs.getVUrl());
|
||||||
}
|
}
|
||||||
@ -1859,4 +1856,23 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
this.cacheId = cacheId;
|
this.cacheId = cacheId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TerminologyCapabilities getTxCaps() {
|
||||||
|
return txcaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTxCaps(TerminologyCapabilities txCaps) {
|
||||||
|
this.txcaps = txCaps;
|
||||||
|
if (txCaps != null) {
|
||||||
|
for (TerminologyCapabilitiesExpansionParameterComponent t : txcaps.getExpansion().getParameter()) {
|
||||||
|
if ("cache-id".equals(t.getName())) {
|
||||||
|
isTxCaching = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (TerminologyCapabilitiesCodeSystemComponent tccs : txcaps.getCodeSystem()) {
|
||||||
|
supportedCodeSystems.add(tccs.getUri());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -63,6 +63,7 @@ import org.hl7.fhir.r5.formats.XmlParser;
|
|||||||
import org.hl7.fhir.r5.model.Bundle;
|
import org.hl7.fhir.r5.model.Bundle;
|
||||||
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
||||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||||
|
import org.hl7.fhir.r5.model.CapabilityStatement;
|
||||||
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
|
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
|
||||||
import org.hl7.fhir.r5.model.Questionnaire;
|
import org.hl7.fhir.r5.model.Questionnaire;
|
||||||
import org.hl7.fhir.r5.model.Resource;
|
import org.hl7.fhir.r5.model.Resource;
|
||||||
@ -293,7 +294,9 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||||||
txLog = new HTMLClientLogger(log);
|
txLog = new HTMLClientLogger(log);
|
||||||
}
|
}
|
||||||
txClient.setLogger(txLog);
|
txClient.setLogger(txLog);
|
||||||
return txClient.getCapabilitiesStatementQuick().getSoftware().getVersion();
|
CapabilityStatement cps = txClient.getCapabilitiesStatementQuick();
|
||||||
|
setTxCaps(txClient.getTerminologyCapabilities());
|
||||||
|
return cps.getSoftware().getVersion();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER_USE_PARAMETER_TX_NA_TUN_RUN_WITHOUT_USING_TERMINOLOGY_SERVICES_TO_VALIDATE_LOINC_SNOMED_ICDX_ETC_ERROR__, e.getMessage()), e);
|
throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER_USE_PARAMETER_TX_NA_TUN_RUN_WITHOUT_USING_TERMINOLOGY_SERVICES_TO_VALIDATE_LOINC_SNOMED_ICDX_ETC_ERROR__, e.getMessage()), e);
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,23 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hl7.fhir.exceptions.DefinitionException;
|
import org.hl7.fhir.exceptions.DefinitionException;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||||
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
||||||
|
import org.hl7.fhir.r5.context.IWorkerContext.CodingValidationRequest;
|
||||||
import org.hl7.fhir.r5.context.IWorkerContext.ValidationResult;
|
import org.hl7.fhir.r5.context.IWorkerContext.ValidationResult;
|
||||||
import org.hl7.fhir.r5.model.BooleanType;
|
import org.hl7.fhir.r5.model.BooleanType;
|
||||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||||
import org.hl7.fhir.r5.model.CodeSystem;
|
import org.hl7.fhir.r5.model.CodeSystem;
|
||||||
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
|
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
|
||||||
|
import org.hl7.fhir.r5.model.Coding;
|
||||||
import org.hl7.fhir.r5.model.ConceptMap;
|
import org.hl7.fhir.r5.model.ConceptMap;
|
||||||
import org.hl7.fhir.r5.model.DataType;
|
import org.hl7.fhir.r5.model.DataType;
|
||||||
import org.hl7.fhir.r5.model.DomainResource;
|
import org.hl7.fhir.r5.model.DomainResource;
|
||||||
@ -182,7 +188,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||||||
p.addText(" and may be missing codes, or include codes that are not valid");
|
p.addText(" and may be missing codes, or include codes that are not valid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateVersionNotice(x, vs.getExpansion());
|
generateVersionNotice(x, vs.getExpansion());
|
||||||
|
|
||||||
CodeSystem allCS = null;
|
CodeSystem allCS = null;
|
||||||
@ -737,6 +743,9 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||||||
li.code(inc.getVersion());
|
li.code(inc.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for performance reasons, we do all the fetching in one batch
|
||||||
|
Map<String, ConceptDefinitionComponent> definitions = getConceptsForCodes(e, inc);
|
||||||
|
|
||||||
XhtmlNode t = li.table("none");
|
XhtmlNode t = li.table("none");
|
||||||
boolean hasComments = false;
|
boolean hasComments = false;
|
||||||
boolean hasDefinition = false;
|
boolean hasDefinition = false;
|
||||||
@ -750,7 +759,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||||||
for (ConceptReferenceComponent c : inc.getConcept()) {
|
for (ConceptReferenceComponent c : inc.getConcept()) {
|
||||||
XhtmlNode tr = t.tr();
|
XhtmlNode tr = t.tr();
|
||||||
XhtmlNode td = tr.td();
|
XhtmlNode td = tr.td();
|
||||||
ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc);
|
ConceptDefinitionComponent cc = definitions.get(c.getCode());
|
||||||
addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay()? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
|
addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay()? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
|
||||||
|
|
||||||
td = tr.td();
|
td = tr.td();
|
||||||
@ -844,24 +853,13 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ConceptDefinitionComponent getConceptForCode(CodeSystem e, String code, ConceptSetComponent inc) {
|
private Map<String, ConceptDefinitionComponent> getConceptsForCodes(CodeSystem e, ConceptSetComponent inc) {
|
||||||
if (code == null) {
|
if (e == null) {
|
||||||
return null;
|
e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
|
||||||
}
|
}
|
||||||
// first, look in the code systems
|
|
||||||
if (e == null)
|
|
||||||
e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
|
|
||||||
if (e != null) {
|
|
||||||
ConceptDefinitionComponent v = getConceptForCode(e.getConcept(), code);
|
|
||||||
if (v != null)
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.isNoSlowLookup())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (!getContext().getWorker().hasCache()) {
|
ValueSetExpansionComponent vse = null;
|
||||||
ValueSetExpansionComponent vse;
|
if (!context.isNoSlowLookup() && !getContext().getWorker().hasCache()) {
|
||||||
try {
|
try {
|
||||||
ValueSetExpansionOutcome vso = getContext().getWorker().expandVS(inc, false);
|
ValueSetExpansionOutcome vso = getContext().getWorker().expandVS(inc, false);
|
||||||
ValueSet valueset = vso.getValueset();
|
ValueSet valueset = vso.getValueset();
|
||||||
@ -872,16 +870,39 @@ public class ValueSetRenderer extends TerminologyRenderer {
|
|||||||
} catch (TerminologyServiceException e1) {
|
} catch (TerminologyServiceException e1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (vse != null) {
|
|
||||||
ConceptDefinitionComponent v = getConceptForCodeFromExpansion(vse.getContains(), code);
|
|
||||||
if (v != null)
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, ConceptDefinitionComponent> results = new HashMap<>();
|
||||||
|
List<CodingValidationRequest> serverList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 1st pass, anything we can resolve internally
|
||||||
|
for (ConceptReferenceComponent cc : inc.getConcept()) {
|
||||||
|
String code = cc.getCode();
|
||||||
|
ConceptDefinitionComponent v = null;
|
||||||
|
if (e != null) {
|
||||||
|
v = getConceptForCode(e.getConcept(), code);
|
||||||
|
}
|
||||||
|
if (v == null && vse != null) {
|
||||||
|
v = getConceptForCodeFromExpansion(vse.getContains(), code);
|
||||||
|
}
|
||||||
|
if (v != null) {
|
||||||
|
results.put(code, v);
|
||||||
|
} else {
|
||||||
|
serverList.add(new CodingValidationRequest(new Coding(inc.getSystem(), code, null)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!context.isNoSlowLookup() && !serverList.isEmpty()) {
|
||||||
return getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), code, null).asConceptDefinition();
|
getContext().getWorker().validateCodeBatch(getContext().getTerminologyServiceOptions(), serverList, null);
|
||||||
|
for (CodingValidationRequest vr : serverList) {
|
||||||
|
ConceptDefinitionComponent v = vr.getResult().asConceptDefinition();
|
||||||
|
if (v != null) {
|
||||||
|
results.put(vr.getCoding().getCode(), v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConceptDefinitionComponent getConceptForCode(List<ConceptDefinitionComponent> list, String code) {
|
private ConceptDefinitionComponent getConceptForCode(List<ConceptDefinitionComponent> list, String code) {
|
||||||
for (ConceptDefinitionComponent c : list) {
|
for (ConceptDefinitionComponent c : list) {
|
||||||
if (code.equals(c.getCode()))
|
if (code.equals(c.getCode()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user