From cff693eb10eed4ce87399bb06f8f95415ae63cde Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 2 Dec 2024 06:49:00 +0300 Subject: [PATCH] Add supplements for used systems as well as for value set systems when validating on server --- .../fhir/r5/context/BaseWorkerContext.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index 242be319e..f3513fef7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -1375,7 +1375,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } try { Parameters pIn = constructParameters(options, code); - res = validateOnServer(tc, vs, pIn, options); + res = validateOnServer2(tc, vs, pIn, options, systems); } catch (Exception e) { res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage(), null).setTxLink(txLog == null ? null : txLog.getLastId()).setErrorClass(TerminologyServiceErrorClass.SERVER_ERROR); } @@ -1645,7 +1645,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte txLog("$validate "+txCache.summary(code)+" for "+ txCache.summary(vs)+" on "+tc.getAddress()); try { Parameters pIn = constructParameters(options, code); - res = validateOnServer(tc, vs, pIn, options); + res = validateOnServer2(tc, vs, pIn, options, systems); } catch (Exception e) { issues.clear(); OperationOutcomeIssueComponent iss = new OperationOutcomeIssueComponent(org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity.ERROR, org.hl7.fhir.r5.model.OperationOutcome.IssueType.EXCEPTION); @@ -1727,6 +1727,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } protected ValidationResult validateOnServer(TerminologyClientContext tc, ValueSet vs, Parameters pin, ValidationOptions options) throws FHIRException { + return validateOnServer2(tc, vs, pin, options, null); + } + + protected ValidationResult validateOnServer2(TerminologyClientContext tc, ValueSet vs, Parameters pin, ValidationOptions options, Set systems) throws FHIRException { if (vs != null) { for (ConceptSetComponent inc : vs.getCompose().getInclude()) { @@ -1737,7 +1741,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } } - addServerValidationParameters(tc, vs, pin, options); + addServerValidationParameters(tc, vs, pin, options, systems); if (txLog != null) { txLog.clearLastId(); @@ -1755,6 +1759,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } protected void addServerValidationParameters(TerminologyClientContext terminologyClientContext, ValueSet vs, Parameters pin, ValidationOptions options) { + addServerValidationParameters(terminologyClientContext, vs, pin, options, null); + } + + protected void addServerValidationParameters(TerminologyClientContext terminologyClientContext, ValueSet vs, Parameters pin, ValidationOptions options, Set systems) { boolean cache = false; if (vs != null) { if (terminologyClientContext != null && terminologyClientContext.isTxCaching() && terminologyClientContext.getCacheId() != null && vs.getUrl() != null && terminologyClientContext.getCached().contains(vs.getUrl()+"|"+ vs.getVersion())) { @@ -1777,6 +1785,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte cache = true; addDependentResources(terminologyClientContext, pin, vs); } + if (systems != null) { + for (String s : systems) { + cache = addDependentCodeSystem(terminologyClientContext, pin, s, null) || cache; + } + } pin.addParameter().setName("cache-id").setValue(new IdType(terminologyClientManager.getCacheId())); for (ParametersParameterComponent pp : pin.getParameter()) { if (pp.getName().equals("profile")) { @@ -1823,13 +1836,20 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } } } - CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem(), src); + String sys = inc.getSystem(); + cache = addDependentCodeSystem(tc, pin, sys, src) || cache; + return cache; + } + + public boolean addDependentCodeSystem(TerminologyClientContext tc, Parameters pin, String sys, Resource src) { + boolean cache = false; + CodeSystem cs = fetchResource(CodeSystem.class, sys, src); if (cs != null && !hasCanonicalResource(pin, "tx-resource", cs.getVUrl()) && (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) { cache = checkAddToParams(tc, pin, cs) || cache; } for (CodeSystem supp : codeSystems.getSupplements(cs)) { //if (supp.getContent() == CodeSystemContentMode.SUPPLEMENT && supp.getSupplements().equals(inc.getSystem())) { - assert supp.getContent() == CodeSystemContentMode.SUPPLEMENT && supp.getSupplements().equals(inc.getSystem()); + assert supp.getContent() == CodeSystemContentMode.SUPPLEMENT && supp.getSupplements().equals(sys); cache = checkAddToParams(tc, pin, supp) || cache; //} }