Fix tests + renaming

This commit is contained in:
dotasek 2024-01-08 12:35:12 -05:00
parent d74b0e2b4a
commit 3e2039a514
4 changed files with 88 additions and 83 deletions

View File

@ -38,7 +38,6 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -48,7 +47,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import lombok.Getter; import lombok.Getter;
@ -56,7 +54,6 @@ import org.apache.commons.lang3.StringUtils;
import org.fhir.ucum.UcumService; import org.fhir.ucum.UcumService;
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.NoTerminologyServiceException;
import org.hl7.fhir.exceptions.TerminologyServiceException; import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities; import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy; import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
@ -114,7 +111,6 @@ import org.hl7.fhir.r5.model.Bundle.BundleType;
import org.hl7.fhir.r5.model.Bundle.HTTPVerb; import org.hl7.fhir.r5.model.Bundle.HTTPVerb;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent;
import org.hl7.fhir.r5.profilemodel.PEDefinition;
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy; import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
import org.hl7.fhir.r5.profilemodel.PEBuilder; import org.hl7.fhir.r5.profilemodel.PEBuilder;
import org.hl7.fhir.r5.renderers.OperationOutcomeRenderer; import org.hl7.fhir.r5.renderers.OperationOutcomeRenderer;
@ -131,7 +127,6 @@ import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache.CacheToken;
import org.hl7.fhir.r5.terminologies.validation.VSCheckerException; import org.hl7.fhir.r5.terminologies.validation.VSCheckerException;
import org.hl7.fhir.r5.terminologies.validation.ValueSetValidator; import org.hl7.fhir.r5.terminologies.validation.ValueSetValidator;
import org.hl7.fhir.r5.terminologies.ValueSetUtilities; import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientR5.TerminologyClientR5Factory; import org.hl7.fhir.r5.terminologies.client.TerminologyClientR5.TerminologyClientR5Factory;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager; import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientContext; import org.hl7.fhir.r5.terminologies.client.TerminologyClientContext;
@ -148,16 +143,10 @@ import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.i18n.I18nBase; import org.hl7.fhir.utilities.i18n.I18nBase;
import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.json.JsonException;
import org.hl7.fhir.utilities.json.model.JsonArray;
import org.hl7.fhir.utilities.json.model.JsonProperty;
import org.hl7.fhir.utilities.json.parser.JsonParser;
import org.hl7.fhir.utilities.npm.NpmPackageIndexBuilder;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.validation.ValidationOptions;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -242,7 +231,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; // although the internal resources are all R5, the version of FHIR they describe may not be protected String version; // although the internal resources are all R5, the version of FHIR they describe may not be
protected TerminologyClientManager tcc = new TerminologyClientManager(new TerminologyClientR5Factory()); protected TerminologyClientManager terminologyClientManager = new TerminologyClientManager(new TerminologyClientR5Factory());
private boolean minimalMemory = false; private boolean minimalMemory = false;
private Map<String, Map<String, ResourceProxy>> allResourcesById = new HashMap<String, Map<String, ResourceProxy>>(); private Map<String, Map<String, ResourceProxy>> allResourcesById = new HashMap<String, Map<String, ResourceProxy>>();
@ -360,7 +349,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
tlogging = other.tlogging; tlogging = other.tlogging;
locator = other.locator; locator = other.locator;
userAgent = other.userAgent; userAgent = other.userAgent;
tcc.copy(other.tcc); terminologyClientManager.copy(other.terminologyClientManager);
cachingAllowed = other.cachingAllowed; cachingAllowed = other.cachingAllowed;
} }
} }
@ -785,18 +774,18 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (noTerminologyServer) { if (noTerminologyServer) {
return false; return false;
} }
if (tcc.getTxcaps() == null) { if (terminologyClientManager.getTxCapabilities() == null) {
try { try {
logger.logMessage("Terminology server: Check for supported code systems for "+system); logger.logMessage("Terminology server: Check for supported code systems for "+system);
final TerminologyCapabilities capabilityStatement = txCache.hasTerminologyCapabilities() ? txCache.getTerminologyCapabilities() : tcc.getMasterClient().getTerminologyCapabilities(); final TerminologyCapabilities capabilityStatement = txCache.hasTerminologyCapabilities() ? txCache.getTerminologyCapabilities() : terminologyClientManager.getMasterClient().getTerminologyCapabilities();
txCache.cacheTerminologyCapabilities(capabilityStatement); txCache.cacheTerminologyCapabilities(capabilityStatement);
setTxCaps(capabilityStatement); setTxCaps(capabilityStatement);
} catch (Exception e) { } catch (Exception e) {
if (canRunWithoutTerminology) { if (canRunWithoutTerminology) {
noTerminologyServer = true; noTerminologyServer = true;
logger.logMessage("==============!! Running without terminology server !! =============="); logger.logMessage("==============!! Running without terminology server !! ==============");
if (tcc.getMasterClient() != null) { if (terminologyClientManager.getMasterClient() != null) {
logger.logMessage("txServer = "+tcc.getMasterClient().getId()); logger.logMessage("txServer = "+ terminologyClientManager.getMasterClient().getId());
logger.logMessage("Error = "+e.getMessage()+""); logger.logMessage("Error = "+e.getMessage()+"");
} }
logger.logMessage("====================================================================="); logger.logMessage("=====================================================================");
@ -860,7 +849,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return res; return res;
} }
Set<String> systems = findRelevantSystems(vs); Set<String> systems = findRelevantSystems(vs);
TerminologyClientContext tc = tcc.chooseServer(systems, true); TerminologyClientContext tc = terminologyClientManager.chooseServer(systems, true);
Parameters p = constructParameters(tc, vs, hierarchical); Parameters p = constructParameters(tc, vs, hierarchical);
for (ConceptSetComponent incl : vs.getCompose().getInclude()) { for (ConceptSetComponent incl : vs.getCompose().getInclude()) {
codeSystemsUsed.add(incl.getSystem()); codeSystemsUsed.add(incl.getSystem());
@ -877,7 +866,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
params.put("_incomplete", "true"); params.put("_incomplete", "true");
txLog("$expand on "+txCache.summary(vs)+" on "+tc.getAddress()); txLog("$expand on "+txCache.summary(vs)+" on "+tc.getAddress());
if (addDependentResources(tc, p, vs)) { if (addDependentResources(tc, p, vs)) {
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId())); p.addParameter().setName("cache-id").setValue(new IdType(terminologyClientManager.getCacheId()));
} }
try { try {
@ -975,9 +964,9 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE, allErrors, false); 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())); p.addParameter().setName("cache-id").setValue(new IdType(terminologyClientManager.getCacheId()));
Set<String> systems = findRelevantSystems(vs); Set<String> systems = findRelevantSystems(vs);
TerminologyClientContext tc = tcc.chooseServer(systems, true); TerminologyClientContext tc = terminologyClientManager.chooseServer(systems, true);
addDependentResources(tc, p, vs); addDependentResources(tc, p, vs);
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
@ -1060,7 +1049,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (!t.hasResult()) { if (!t.hasResult()) {
try { try {
ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs == null ? t.getVsObj() : vs); ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs == null ? t.getVsObj() : vs);
vsc.setThrowToServer(options.isUseServer() && tcc.hasClient()); vsc.setThrowToServer(options.isUseServer() && terminologyClientManager.hasClient());
ValidationResult res = vsc.validateCode("Coding", t.getCoding()); ValidationResult res = vsc.validateCode("Coding", t.getCoding());
if (txCache != null) { if (txCache != null) {
txCache.cacheValidation(t.getCacheToken(), res, TerminologyCache.TRANSIENT); txCache.cacheValidation(t.getCacheToken(), res, TerminologyCache.TRANSIENT);
@ -1110,7 +1099,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
if (batch.getEntry().size() > 0) { if (batch.getEntry().size() > 0) {
TerminologyClientContext tc = tcc.chooseServer(systems, false); TerminologyClientContext tc = terminologyClientManager.chooseServer(systems, false);
Bundle resp = processBatch(tc, batch, systems); Bundle resp = processBatch(tc, batch, systems);
for (int i = 0; i < batch.getEntry().size(); i++) { for (int i = 0; i < batch.getEntry().size(); i++) {
CodingValidationRequest t = (CodingValidationRequest) batch.getEntry().get(i).getUserData("source"); CodingValidationRequest t = (CodingValidationRequest) batch.getEntry().get(i).getUserData("source");
@ -1130,7 +1119,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
private Bundle processBatch(TerminologyClientContext tc, Bundle batch, Set<String> systems) { private Bundle processBatch(TerminologyClientContext tc, Bundle batch, Set<String> systems) {
txLog("$batch validate for "+batch.getEntry().size()+" codes on systems "+systems.toString()); txLog("$batch validate for "+batch.getEntry().size()+" codes on systems "+systems.toString());
if (tcc == null) { if (terminologyClientManager == null) {
throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE)); throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
} }
if (txLog != null) { if (txLog != null) {
@ -1167,7 +1156,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (!t.hasResult()) { if (!t.hasResult()) {
try { try {
ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs); ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs);
vsc.setThrowToServer(options.isUseServer() && tcc.hasClient()); vsc.setThrowToServer(options.isUseServer() && terminologyClientManager.hasClient());
ValidationResult res = vsc.validateCode("Coding", t.getCoding()); ValidationResult res = vsc.validateCode("Coding", t.getCoding());
if (txCache != null) { if (txCache != null) {
txCache.cacheValidation(t.getCacheToken(), res, TerminologyCache.TRANSIENT); txCache.cacheValidation(t.getCacheToken(), res, TerminologyCache.TRANSIENT);
@ -1215,7 +1204,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
systems.add(codingValidationRequest.getCoding().getSystem()); systems.add(codingValidationRequest.getCoding().getSystem());
} }
} }
TerminologyClientContext tc = tcc.chooseServer(systems, false); TerminologyClientContext tc = terminologyClientManager.chooseServer(systems, false);
if (batch.getEntry().size() > 0) { if (batch.getEntry().size() > 0) {
Bundle resp = processBatch(tc, batch, systems); Bundle resp = processBatch(tc, batch, systems);
@ -1291,7 +1280,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
try { try {
ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs, ctxt); ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs, ctxt);
vsc.setUnknownSystems(unknownSystems); vsc.setUnknownSystems(unknownSystems);
vsc.setThrowToServer(options.isUseServer() && tcc.hasClient()); vsc.setThrowToServer(options.isUseServer() && terminologyClientManager.hasClient());
if (!ValueSetUtilities.isServerSide(code.getSystem())) { if (!ValueSetUtilities.isServerSide(code.getSystem())) {
res = vsc.validateCode(path, code); res = vsc.validateCode(path, code);
if (txCache != null && cachingAllowed) { if (txCache != null && cachingAllowed) {
@ -1320,14 +1309,14 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
} }
if (localError != null && !tcc.hasClient()) { if (localError != null && !terminologyClientManager.hasClient()) {
if (unknownSystems.size() > 0) { if (unknownSystems.size() > 0) {
return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED, issues).setUnknownSystems(unknownSystems); return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED, issues).setUnknownSystems(unknownSystems);
} else { } else {
return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.UNKNOWN, issues); return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.UNKNOWN, issues);
} }
} }
if (localWarning != null && !tcc.hasClient()) { if (localWarning != null && !terminologyClientManager.hasClient()) {
return new ValidationResult(IssueSeverity.WARNING,formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER, localWarning), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS, issues); return new ValidationResult(IssueSeverity.WARNING,formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER, localWarning), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS, issues);
} }
if (!options.isUseServer()) { if (!options.isUseServer()) {
@ -1348,7 +1337,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
Set<String> systems = findRelevantSystems(code, vs); Set<String> systems = findRelevantSystems(code, vs);
TerminologyClientContext tc = tcc.chooseServer(systems, false); TerminologyClientContext tc = terminologyClientManager.chooseServer(systems, false);
String csumm =cachingAllowed && txCache != null ? txCache.summary(code) : null; String csumm =cachingAllowed && txCache != null ? txCache.summary(code) : null;
if (cachingAllowed && txCache != null) { if (cachingAllowed && txCache != null) {
@ -1385,11 +1374,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
protected ValueSetValidator constructValueSetCheckerSimple(ValidationOptions options, ValueSet vs, ValidationContextCarrier ctxt) { protected ValueSetValidator constructValueSetCheckerSimple(ValidationOptions options, ValueSet vs, ValidationContextCarrier ctxt) {
return new ValueSetValidator(this, new TerminologyOperationContext(this, options), options, vs, ctxt, expParameters, tcc.getTxcaps()); return new ValueSetValidator(this, new TerminologyOperationContext(this, options), options, vs, ctxt, expParameters, terminologyClientManager.getTxCapabilities());
} }
protected ValueSetValidator constructValueSetCheckerSimple( ValidationOptions options, ValueSet vs) { protected ValueSetValidator constructValueSetCheckerSimple( ValidationOptions options, ValueSet vs) {
return new ValueSetValidator(this, new TerminologyOperationContext(this, options), options, vs, expParameters, tcc.getTxcaps()); return new ValueSetValidator(this, new TerminologyOperationContext(this, options), options, vs, expParameters, terminologyClientManager.getTxCapabilities());
} }
protected Parameters constructParameters(TerminologyClientContext tcd, ValueSet vs, boolean hierarchical) { protected Parameters constructParameters(TerminologyClientContext tcd, ValueSet vs, boolean hierarchical) {
@ -1398,7 +1387,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
p.setParameter("excludeNested", !hierarchical); p.setParameter("excludeNested", !hierarchical);
addDependentResources(tcd, p, vs); addDependentResources(tcd, p, vs);
p.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId())); p.addParameter().setName("cache-id").setValue(new IdType(terminologyClientManager.getCacheId()));
return p; return p;
} }
@ -1494,7 +1483,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
try { try {
ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs); ValueSetValidator vsc = constructValueSetCheckerSimple(options, vs);
vsc.setUnknownSystems(unknownSystems); vsc.setUnknownSystems(unknownSystems);
vsc.setThrowToServer(options.isUseServer() && tcc.hasClient()); vsc.setThrowToServer(options.isUseServer() && terminologyClientManager.hasClient());
res = vsc.validateCode("CodeableConcept", code); res = vsc.validateCode("CodeableConcept", code);
if (cachingAllowed) { if (cachingAllowed) {
txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT); txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT);
@ -1520,14 +1509,14 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
} }
if (localError != null && !tcc.hasClient()) { if (localError != null && !terminologyClientManager.hasClient()) {
if (unknownSystems.size() > 0) { if (unknownSystems.size() > 0) {
return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED, issues).setUnknownSystems(unknownSystems); return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED, issues).setUnknownSystems(unknownSystems);
} else { } else {
return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.UNKNOWN, issues); return new ValidationResult(IssueSeverity.ERROR, localError, TerminologyServiceErrorClass.UNKNOWN, issues);
} }
} }
if (localWarning != null && !tcc.hasClient()) { if (localWarning != null && !terminologyClientManager.hasClient()) {
return new ValidationResult(IssueSeverity.WARNING,formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER, localWarning), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS, issues); return new ValidationResult(IssueSeverity.WARNING,formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER, localWarning), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS, issues);
} }
@ -1540,7 +1529,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return new ValidationResult(IssueSeverity.ERROR, "Error validating code: running without terminology services", TerminologyServiceErrorClass.NOSERVICE, null); return new ValidationResult(IssueSeverity.ERROR, "Error validating code: running without terminology services", TerminologyServiceErrorClass.NOSERVICE, null);
} }
Set<String> systems = findRelevantSystems(code, vs); Set<String> systems = findRelevantSystems(code, vs);
TerminologyClientContext tc = tcc.chooseServer(systems, false); TerminologyClientContext tc = terminologyClientManager.chooseServer(systems, false);
txLog("$validate "+txCache.summary(code)+" for "+ txCache.summary(vs)+" on "+tc.getAddress()); txLog("$validate "+txCache.summary(code)+" for "+ txCache.summary(vs)+" on "+tc.getAddress());
try { try {
@ -1650,23 +1639,23 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return processValidationResult(pOut, vs == null ? null : vs.getUrl(), tc.getClient().getAddress()); return processValidationResult(pOut, vs == null ? null : vs.getUrl(), tc.getClient().getAddress());
} }
protected void addServerValidationParameters(TerminologyClientContext tcd, ValueSet vs, Parameters pin, ValidationOptions options) { protected void addServerValidationParameters(TerminologyClientContext terminologyClientContext, ValueSet vs, Parameters pin, ValidationOptions options) {
boolean cache = false; boolean cache = false;
if (vs != null) { if (vs != null) {
if (tcc.isTxCaching() && tcc.getCacheId() != null && vs.getUrl() != null && tcd.getCached().contains(vs.getUrl()+"|"+ vs.getVersion())) { if (terminologyClientManager.isTxCaching() && terminologyClientManager.getCacheId() != null && vs.getUrl() != null && terminologyClientContext.getCached().contains(vs.getUrl()+"|"+ vs.getVersion())) {
pin.addParameter().setName("url").setValue(new UriType(vs.getUrl()+(vs.hasVersion() ? "|"+ vs.getVersion() : ""))); pin.addParameter().setName("url").setValue(new UriType(vs.getUrl()+(vs.hasVersion() ? "|"+ vs.getVersion() : "")));
} else if (options.getVsAsUrl()){ } else if (options.getVsAsUrl()){
pin.addParameter().setName("url").setValue(new UriType(vs.getUrl())); pin.addParameter().setName("url").setValue(new UriType(vs.getUrl()));
} else { } else {
pin.addParameter().setName("valueSet").setResource(vs); pin.addParameter().setName("valueSet").setResource(vs);
if (vs.getUrl() != null) { if (vs.getUrl() != null) {
tcd.getCached().add(vs.getUrl()+"|"+ vs.getVersion()); terminologyClientContext.getCached().add(vs.getUrl()+"|"+ vs.getVersion());
} }
} }
cache = true; cache = true;
addDependentResources(tcd, pin, vs); addDependentResources(terminologyClientContext, pin, vs);
} }
pin.addParameter().setName("cache-id").setValue(new IdType(tcc.getCacheId())); pin.addParameter().setName("cache-id").setValue(new IdType(terminologyClientManager.getCacheId()));
for (ParametersParameterComponent pp : pin.getParameter()) { for (ParametersParameterComponent pp : pin.getParameter()) {
if (pp.getName().equals("profile")) { if (pp.getName().equals("profile")) {
throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT)); throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT));
@ -1713,7 +1702,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
private boolean checkAddToParams(TerminologyClientContext tc, Parameters pin, CanonicalResource cr) { private boolean checkAddToParams(TerminologyClientContext tc, Parameters pin, CanonicalResource cr) {
boolean cache = false; boolean cache = false;
boolean addToParams = false; boolean addToParams = false;
if (tcc.usingCache()) { if (terminologyClientManager.usingCache()) {
if (!tc.alreadyCached(cr)) { if (!tc.alreadyCached(cr)) {
tc.addToCache(cr); tc.addToCache(cr);
if (logger.isDebugLogging()) { if (logger.isDebugLogging()) {
@ -1869,7 +1858,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
Utilities.createDirectory(cachePath); Utilities.createDirectory(cachePath);
} }
txCache = new TerminologyCache(lock, cachePath); txCache = new TerminologyCache(lock, cachePath);
tcc.setCache(txCache); terminologyClientManager.setCache(txCache);
} }
public void clearTSCache(String url) throws Exception { public void clearTSCache(String url) throws Exception {
@ -1902,7 +1891,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
@Override @Override
public boolean isNoTerminologyServer() { public boolean isNoTerminologyServer() {
return noTerminologyServer || !tcc.hasClient(); return noTerminologyServer || !terminologyClientManager.hasClient();
} }
public void setNoTerminologyServer(boolean noTerminologyServer) { public void setNoTerminologyServer(boolean noTerminologyServer) {
@ -2979,39 +2968,39 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
public int getClientRetryCount() { public int getClientRetryCount() {
return tcc.getRetryCount(); return terminologyClientManager.getRetryCount();
} }
public IWorkerContext setClientRetryCount(int value) { public IWorkerContext setClientRetryCount(int value) {
tcc.setRetryCount(value); terminologyClientManager.setRetryCount(value);
return this; return this;
} }
public TerminologyClientManager getTxClientManager() { public TerminologyClientManager getTxClientManager() {
return tcc; return terminologyClientManager;
} }
public String getCacheId() { public String getCacheId() {
return tcc.getCacheId(); return terminologyClientManager.getCacheId();
} }
public void setCacheId(String cacheId) { public void setCacheId(String cacheId) {
tcc.setCacheId(cacheId); terminologyClientManager.setCacheId(cacheId);
} }
public TerminologyCapabilities getTxCaps() { public TerminologyCapabilities getTxCaps() {
return tcc.getTxcaps(); return terminologyClientManager.getTxCapabilities();
} }
public void setTxCaps(TerminologyCapabilities txCaps) { public void setTxCaps(TerminologyCapabilities txCaps) {
this.tcc.setTxcaps(txCaps); this.terminologyClientManager.setTxCapabilities(txCaps);
if (txCaps != null) { if (txCaps != null) {
for (TerminologyCapabilitiesExpansionParameterComponent t : tcc.getTxcaps().getExpansion().getParameter()) { for (TerminologyCapabilitiesExpansionParameterComponent t : terminologyClientManager.getTxCapabilities().getExpansion().getParameter()) {
if ("cache-id".equals(t.getName())) { if ("cache-id".equals(t.getName())) {
tcc.setTxCaching(true); terminologyClientManager.setTxCaching(true);
} }
} }
for (TerminologyCapabilitiesCodeSystemComponent tccs : tcc.getTxcaps().getCodeSystem()) { for (TerminologyCapabilitiesCodeSystemComponent tccs : terminologyClientManager.getTxCapabilities().getCodeSystem()) {
supportedCodeSystems.add(tccs.getUri()); supportedCodeSystems.add(tccs.getUri());
} }
} }
@ -3046,7 +3035,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
protected void setUserAgent(String userAgent) { protected void setUserAgent(String userAgent) {
this.userAgent = userAgent; this.userAgent = userAgent;
tcc.setUserAgent(userAgent); terminologyClientManager.setUserAgent(userAgent);
} }

View File

@ -36,7 +36,6 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -63,9 +62,6 @@ import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.StructureMap.StructureMapModelMode; import org.hl7.fhir.r5.model.StructureMap.StructureMapModelMode;
import org.hl7.fhir.r5.model.StructureMap.StructureMapStructureComponent; import org.hl7.fhir.r5.model.StructureMap.StructureMapStructureComponent;
import org.hl7.fhir.r5.profilemodel.PEDefinition;
import org.hl7.fhir.r5.profilemodel.PEBuilder;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.terminologies.JurisdictionUtilities; import org.hl7.fhir.r5.terminologies.JurisdictionUtilities;
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient; import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager; import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager;
@ -251,7 +247,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
public SimpleWorkerContext fromPackage(NpmPackage pi) throws IOException, FHIRException { public SimpleWorkerContext fromPackage(NpmPackage pi) throws IOException, FHIRException {
SimpleWorkerContext context = getSimpleWorkerContextInstance(); SimpleWorkerContext context = getSimpleWorkerContextInstance();
context.setAllowLoadingDuplicates(allowLoadingDuplicates); context.setAllowLoadingDuplicates(allowLoadingDuplicates);
context.tcc = new TerminologyClientManager(TerminologyClientR5.factory()); context.terminologyClientManager = new TerminologyClientManager(TerminologyClientR5.factory());
context.loadFromPackage(pi, null); context.loadFromPackage(pi, null);
return build(context); return build(context);
} }
@ -260,7 +256,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
SimpleWorkerContext context = getSimpleWorkerContextInstance(); SimpleWorkerContext context = getSimpleWorkerContextInstance();
context.setAllowLoadingDuplicates(allowLoadingDuplicates); context.setAllowLoadingDuplicates(allowLoadingDuplicates);
context.version = pi.getNpm().asString("version"); context.version = pi.getNpm().asString("version");
context.tcc.setFactory(loader.txFactory()); context.terminologyClientManager.setFactory(loader.txFactory());
context.loadFromPackage(pi, loader); context.loadFromPackage(pi, loader);
context.finishLoading(genSnapshots); context.finishLoading(genSnapshots);
return build(context); return build(context);
@ -335,20 +331,20 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
public String connectToTSServer(ITerminologyClientFactory factory, ITerminologyClient client, String log) { public String connectToTSServer(ITerminologyClientFactory factory, ITerminologyClient client, String log) {
try { try {
txLog("Connect to "+client.getAddress()); txLog("Connect to "+client.getAddress());
tcc.setFactory(factory); terminologyClientManager.setFactory(factory);
tcc.setMasterClient(client); terminologyClientManager.setMasterClient(client);
if (log != null && (log.endsWith(".htm") || log.endsWith(".html"))) { if (log != null && (log.endsWith(".htm") || log.endsWith(".html"))) {
txLog = new HTMLClientLogger(log); txLog = new HTMLClientLogger(log);
} else { } else {
txLog = new TextClientLogger(log); txLog = new TextClientLogger(log);
} }
tcc.setLogger(txLog); terminologyClientManager.setLogger(txLog);
tcc.setUserAgent(userAgent); terminologyClientManager.setUserAgent(userAgent);
final CapabilityStatement capabilitiesStatementQuick = txCache.hasCapabilityStatement() ? txCache.getCapabilityStatement() : tcc.getMasterClient().getCapabilitiesStatementQuick(); final CapabilityStatement capabilitiesStatementQuick = txCache.hasCapabilityStatement() ? txCache.getCapabilityStatement() : terminologyClientManager.getMasterClient().getCapabilitiesStatementQuick();
txCache.cacheCapabilityStatement(capabilitiesStatementQuick); txCache.cacheCapabilityStatement(capabilitiesStatementQuick);
final TerminologyCapabilities capabilityStatement = txCache.hasTerminologyCapabilities() ? txCache.getTerminologyCapabilities() : tcc.getMasterClient().getTerminologyCapabilities(); final TerminologyCapabilities capabilityStatement = txCache.hasTerminologyCapabilities() ? txCache.getTerminologyCapabilities() : terminologyClientManager.getMasterClient().getTerminologyCapabilities();
txCache.cacheTerminologyCapabilities(capabilityStatement); txCache.cacheTerminologyCapabilities(capabilityStatement);
setTxCaps(capabilityStatement); setTxCaps(capabilityStatement);
@ -539,7 +535,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
} }
} }
if (loader != null) { if (loader != null) {
tcc.setFactory(loader.txFactory()); terminologyClientManager.setFactory(loader.txFactory());
} }
return t; return t;
} }

View File

@ -11,13 +11,10 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.hl7.fhir.exceptions.TerminologyServiceException; import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.TerminologyCapabilities; import org.hl7.fhir.r5.model.TerminologyCapabilities;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache; import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache;
import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.JsonException;
import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.utilities.json.parser.JsonParser; import org.hl7.fhir.utilities.json.parser.JsonParser;
@ -198,11 +195,11 @@ public class TerminologyClientManager {
return map; return map;
} }
public TerminologyCapabilities getTxcaps() { public TerminologyCapabilities getTxCapabilities() {
return hasClient() ? serverList.get(0).getTxcaps() : null; return hasClient() ? serverList.get(0).getTxcaps() : null;
} }
public void setTxcaps(TerminologyCapabilities txCaps) { public void setTxCapabilities(TerminologyCapabilities txCaps) {
serverList.get(0).setTxcaps(txCaps); serverList.get(0).setTxcaps(txCaps);
} }

View File

@ -5,8 +5,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -21,6 +20,7 @@ import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.TerminologyCapabilities; import org.hl7.fhir.r5.model.TerminologyCapabilities;
import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient; import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientContext;
import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpander; import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpander;
import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpansionOutcome; import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache; import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache;
@ -91,9 +91,11 @@ public class SimpleWorkerContextTests {
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
Mockito.doReturn(DUMMY_URL).when(terminologyClient).getAddress();
context.txCache = terminologyCache; context.txCache = terminologyCache;
context.expParameters = expParameters; context.expParameters = expParameters;
context.tcc.setMasterClient(terminologyClient); context.terminologyClientManager.setMasterClient(terminologyClient);
context.txLog = txLog; context.txLog = txLog;
} }
@ -138,6 +140,20 @@ public class SimpleWorkerContextTests {
} }
} }
public class TerminologyClientContextMatcher implements ArgumentMatcher<TerminologyClientContext> {
final private TerminologyClientContext left;
TerminologyClientContextMatcher(TerminologyClientContext left) {
this.left = left;
}
@Override
public boolean matches(TerminologyClientContext argument) {
return left.getAddress().equals(argument.getAddress());
}
}
@Test @Test
public void testValidateCodingWithCache() throws IOException { public void testValidateCodingWithCache() throws IOException {
ValidationOptions validationOptions = new ValidationOptions(FhirPublication.R5).withGuessSystem().withVersionFlexible(false); ValidationOptions validationOptions = new ValidationOptions(FhirPublication.R5).withGuessSystem().withVersionFlexible(false);
@ -189,7 +205,10 @@ public class SimpleWorkerContextTests {
Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, coding, valueSet, expParameters); Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, coding, valueSet, expParameters);
Mockito.doReturn(pIn).when(context).constructParameters(validationOptions, coding); Mockito.doReturn(pIn).when(context).constructParameters(validationOptions, coding);
Mockito.doReturn(expectedValidationResult).when(context).validateOnServer(context.getTxClientManager().getMaster(), valueSet, pIn, validationOptions);
TerminologyClientContext terminologyClientContext = context.getTxClientManager().getMaster();
Mockito.doReturn(expectedValidationResult).when(context).validateOnServer(terminologyClientContext, valueSet, pIn, validationOptions);
ValidationContextCarrier ctxt = mock(ValidationContextCarrier.class); ValidationContextCarrier ctxt = mock(ValidationContextCarrier.class);
@ -233,7 +252,7 @@ public class SimpleWorkerContextTests {
Mockito.verify(valueSetCheckerSimple).validateCode("CodeableConcept", codeableConcept); Mockito.verify(valueSetCheckerSimple).validateCode("CodeableConcept", codeableConcept);
Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, false); Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, false);
Mockito.verify(context, times(0)).validateOnServer(context.getTxClientManager().getMaster(), any(), any(), any()); Mockito.verify(context, times(0)).validateOnServer(any(), any(), any(), any());
} }
@ -246,7 +265,9 @@ public class SimpleWorkerContextTests {
ValidationOptions validationOptions = CacheTestUtils.validationOptions.withNoClient(); ValidationOptions validationOptions = CacheTestUtils.validationOptions.withNoClient();
Mockito.doReturn(pIn).when(context).constructParameters(validationOptions, codeableConcept); Mockito.doReturn(pIn).when(context).constructParameters(validationOptions, codeableConcept);
Mockito.doReturn(expectedValidationResult).when(context).validateOnServer(context.getTxClientManager().getMaster(), valueSet, pIn, validationOptions); TerminologyClientContext terminologyClientContext = context.getTxClientManager().getMaster();
Mockito.doReturn(expectedValidationResult).when(context).validateOnServer(terminologyClientContext, valueSet, pIn, validationOptions);
Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, codeableConcept, valueSet, expParameters); Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, codeableConcept, valueSet, expParameters);
@ -256,7 +277,7 @@ public class SimpleWorkerContextTests {
Mockito.verify(valueSetCheckerSimple, times(0)).validateCode("CodeableConcept", codeableConcept); Mockito.verify(valueSetCheckerSimple, times(0)).validateCode("CodeableConcept", codeableConcept);
Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, true); Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, true);
Mockito.verify(context).validateOnServer(context.getTxClientManager().getMaster(),valueSet, pIn, validationOptions); Mockito.verify(context).validateOnServer(terminologyClientContext, valueSet, pIn, validationOptions);
} }
@Test @Test
@ -295,8 +316,10 @@ public class SimpleWorkerContextTests {
Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(argThat(new ValueSetMatcher(vs)),eq(true)); Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(argThat(new ValueSetMatcher(vs)),eq(true));
// #FIXME TerminologyClientContext terminologyClientContext = context.getTxClientManager().getMaster();
// Mockito.doReturn(expParameters).when(context).constructParameters(argThat(new ValueSetMatcher(vs)), eq(true));
Mockito.doReturn(expParameters).when(context).constructParameters(argThat(new TerminologyClientContextMatcher(terminologyClientContext)),argThat(new ValueSetMatcher(vs)), eq(true));
ValueSet expectedValueSet = new ValueSet(); ValueSet expectedValueSet = new ValueSet();