Merge pull request #1309 from hapifhir/do-20230615-tx-request-lenient-display

Add lenient-display-validation param
This commit is contained in:
Grahame Grieve 2023-06-19 02:33:17 +10:00 committed by GitHub
commit 8bd4fc3ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 137 additions and 28 deletions

View File

@ -1261,7 +1261,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
protected ValidationResult validateOnServer(ValueSet vs, Parameters pin, ValidationOptions options) throws FHIRException { protected ValidationResult validateOnServer(ValueSet vs, Parameters pin, ValidationOptions options) throws FHIRException {
boolean cache = false;
if (vs != null) { if (vs != null) {
for (ConceptSetComponent inc : vs.getCompose().getInclude()) { for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
codeSystemsUsed.add(inc.getSystem()); codeSystemsUsed.add(inc.getSystem());
@ -1271,15 +1271,34 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
} }
addServerValidationParameters(vs, pin, options);
if (txLog != null) {
txLog.clearLastId();
}
if (tcc.getClient() == null) {
throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
}
Parameters pOut;
if (vs == null) {
pOut = tcc.getClient().validateCS(pin);
} else {
pOut = tcc.getClient().validateVS(pin);
}
return processValidationResult(pOut);
}
protected void addServerValidationParameters(ValueSet vs, Parameters pin, ValidationOptions options) {
boolean cache = false;
if (vs != null) { if (vs != null) {
if (tcc.isTxCaching() && tcc.getCacheId() != null && vs.getUrl() != null && tcc.getCached().contains(vs.getUrl()+"|"+vs.getVersion())) { if (tcc.isTxCaching() && tcc.getCacheId() != null && vs.getUrl() != null && tcc.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) {
tcc.getCached().add(vs.getUrl()+"|"+vs.getVersion()); tcc.getCached().add(vs.getUrl()+"|"+ vs.getVersion());
} }
} }
cache = true; cache = true;
@ -1297,19 +1316,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
throw new Error(formatMessage(I18nConstants.NO_EXPANSIONPROFILE_PROVIDED)); throw new Error(formatMessage(I18nConstants.NO_EXPANSIONPROFILE_PROVIDED));
} }
pin.addParameter().setName("profile").setResource(expParameters); pin.addParameter().setName("profile").setResource(expParameters);
if (txLog != null) {
txLog.clearLastId(); if (options.isDisplayWarningMode()) {
pin.addParameter("mode","lenient-display-validation");
} }
if (tcc.getClient() == null) {
throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
}
Parameters pOut;
if (vs == null) {
pOut = tcc.getClient().validateCS(pin);
} else {
pOut = tcc.getClient().validateVS(pin);
}
return processValidationResult(pOut);
} }
private boolean addDependentResources(Parameters pin, ValueSet vs) { private boolean addDependentResources(Parameters pin, ValueSet vs) {

View File

@ -0,0 +1,99 @@
package org.hl7.fhir.r5.context;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.PackageInformation;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.utilities.npm.BasePackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.junit.jupiter.api.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class BaseWorkerContextTests {
private BaseWorkerContext getBaseWorkerContext() throws IOException {
BaseWorkerContext baseWorkerContext = new BaseWorkerContext() {
@Override
public String getVersion() {
return null;
}
@Override
public IResourceValidator newValidator() throws FHIRException {
return null;
}
@Override
public void cachePackage(PackageInformation packageInfo) {
}
@Override
public List<String> getResourceNames() {
return null;
}
@Override
public int loadFromPackage(NpmPackage pi, IContextResourceLoader loader) throws FileNotFoundException, IOException, FHIRException {
return 0;
}
@Override
public int loadFromPackage(NpmPackage pi, IContextResourceLoader loader, List<String> types) throws FileNotFoundException, IOException, FHIRException {
return 0;
}
@Override
public int loadFromPackageAndDependencies(NpmPackage pi, IContextResourceLoader loader, BasePackageCacheManager pcm) throws FileNotFoundException, IOException, FHIRException {
return 0;
}
@Override
public boolean hasPackage(String id, String ver) {
return false;
}
@Override
public boolean hasPackage(PackageInformation pack) {
return false;
}
@Override
public PackageInformation getPackage(String id, String ver) {
return null;
}
@Override
public String getSpecUrl() {
return null;
}
};
baseWorkerContext.expParameters = new Parameters();
return baseWorkerContext;
}
@Test
public void testAddServerValidationParametersDisplayWarning() throws IOException {
BaseWorkerContext baseWorkerContext = getBaseWorkerContext();
Parameters pin = new Parameters();
baseWorkerContext.addServerValidationParameters(new ValueSet(), pin, new ValidationOptions().setDisplayWarningMode(true));
assertEquals("lenient-display-validation", pin.getParameter("mode").getValue().primitiveValue());
}
@Test
public void testAddServerValidationParametersDisplayError() throws IOException {
BaseWorkerContext baseWorkerContext = getBaseWorkerContext();
Parameters pin = new Parameters();
baseWorkerContext.addServerValidationParameters(new ValueSet(), pin, new ValidationOptions());
assertNull(pin.getParameter("mode"));
}
}