pass dependent resources to server and make sure cache-id is filled out properly

This commit is contained in:
Grahame Grieve 2023-09-20 11:14:56 +10:00
parent 96469972de
commit 8d3fff4d4e
1 changed files with 23 additions and 18 deletions

View File

@ -124,6 +124,7 @@ import org.hl7.fhir.r5.terminologies.client.TerminologyClientContext;
import org.hl7.fhir.r5.utils.PackageHackerR5;
import org.hl7.fhir.r5.utils.ResourceUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.client.EFhirClientException;
import org.hl7.fhir.r5.utils.validation.ValidationContextCarrier;
import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.ToolingClientLogger;
@ -780,17 +781,21 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE, false);
}
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit ));
params.put("_incomplete", "true");
txLog("$expand on "+txCache.summary(vs));
if (addDependentResources(p, vs)) {
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
}
try {
ValueSet result = tcc.getClient().expandValueset(vs, p, params);
res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
} catch (Exception e) {
res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN, true);
if (txLog != null) {
res.setTxLink(txLog.getLastId());
}
@ -820,7 +825,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
throw new Error(formatMessage(I18nConstants.NO_PARAMETERS_PROVIDED_TO_EXPANDVS));
}
if (vs.getUrl().equals("http://hl7.org/fhir/ValueSet/all-time-units") || vs.getUrl().equals("http://hl7.org/fhir/ValueSet/all-distance-units")) {
return new ValueSetExpansionOutcome("This value set is not expanded correctly at this time (will be fixed in a future version)", TerminologyServiceErrorClass.VALUESET_UNSUPPORTED);
return new ValueSetExpansionOutcome("This value set is not expanded correctly at this time (will be fixed in a future version)", TerminologyServiceErrorClass.VALUESET_UNSUPPORTED, false);
}
Parameters p = pIn.copy();
@ -862,7 +867,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} catch (Exception e) {
allErrors.addAll(vse.getAllErrors());
e.printStackTrace();
res = new ValueSetExpansionOutcome(e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
res = new ValueSetExpansionOutcome(e.getMessage(), TerminologyServiceErrorClass.UNKNOWN, e instanceof EFhirClientException);
}
allErrors.addAll(vse.getAllErrors());
if (res.getValueset() != null) {
@ -873,17 +878,17 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return res;
}
if (res.getErrorClass() == TerminologyServiceErrorClass.INTERNAL_ERROR || isNoTerminologyServer()) { // this class is created specifically to say: don't consult the server
return new ValueSetExpansionOutcome(res.getError(), res.getErrorClass());
return new ValueSetExpansionOutcome(res.getError(), res.getErrorClass(), false);
}
// if that failed, we try to expand on the server
if (addDependentResources(p, vs)) {
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
}
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE, allErrors);
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE, allErrors, false);
}
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
addDependentResources(p, vs);
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit ));
params.put("_incomplete", "true");
@ -898,7 +903,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
} catch (Exception e) {
res = new ValueSetExpansionOutcome((e.getMessage() == null ? e.getClass().getName() : e.getMessage()), TerminologyServiceErrorClass.UNKNOWN, allErrors).setTxLink(txLog == null ? null : txLog.getLastId());
if (res != null && !res.isFromServer()) {
res = new ValueSetExpansionOutcome(res.getError()+" (and "+e.getMessage()+")", res.getErrorClass(), false);
} else {
res = new ValueSetExpansionOutcome((e.getMessage() == null ? e.getClass().getName() : e.getMessage()), TerminologyServiceErrorClass.UNKNOWN, allErrors, true).setTxLink(txLog == null ? null : txLog.getLastId());
}
}
txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
return res;
@ -1283,10 +1292,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !hierarchical);
boolean cached = addDependentResources(p, vs);
if (cached) {
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
}
addDependentResources(p, vs);
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
return p;
}
@ -1480,9 +1487,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
cache = true;
addDependentResources(pin, vs);
}
if (cache) {
pin.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
}
pin.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId()));
for (ParametersParameterComponent pp : pin.getParameter()) {
if (pp.getName().equals("profile")) {
throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT));