Mapping noExtensibleWarnings and noBindingMsgSuppressed between FhirInstanceValidator and InstanceValidator (#2054)

Co-authored-by: ahn <anders.havn@systematic.com>
This commit is contained in:
vedion 2021-01-17 15:21:08 +01:00 committed by GitHub
parent 57bebe50e8
commit 99b646eed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.util.HapiExtensions; import ca.uhn.fhir.util.HapiExtensions;
import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.util.UrlUtil;
import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -65,6 +66,7 @@ import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu3.model.Bundle.SearchEntryMode; import org.hl7.fhir.dstu3.model.Bundle.SearchEntryMode;
import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Condition; import org.hl7.fhir.dstu3.model.Condition;
import org.hl7.fhir.dstu3.model.DateTimeType; import org.hl7.fhir.dstu3.model.DateTimeType;
@ -79,6 +81,7 @@ import org.hl7.fhir.dstu3.model.Enumerations;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Identifier;
import org.hl7.fhir.dstu3.model.ImagingStudy; import org.hl7.fhir.dstu3.model.ImagingStudy;
import org.hl7.fhir.dstu3.model.InstantType; import org.hl7.fhir.dstu3.model.InstantType;
import org.hl7.fhir.dstu3.model.IntegerType; import org.hl7.fhir.dstu3.model.IntegerType;
@ -110,8 +113,10 @@ import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus;
import org.hl7.fhir.dstu3.model.Task;
import org.hl7.fhir.dstu3.model.UnsignedIntType; import org.hl7.fhir.dstu3.model.UnsignedIntType;
import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.dstu3.model.codesystems.DeviceStatus;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -235,6 +240,56 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
assertEquals(0, returnedBundle.getEntry().size()); assertEquals(0, returnedBundle.getEntry().size());
} }
@Test
public void testSuppressNoExtensibleWarnings() {
RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor();
interceptor.setFailOnSeverity(ResultSeverityEnum.INFORMATION);
FhirInstanceValidator val = new FhirInstanceValidator(myValidationSupport);
val.setNoExtensibleWarnings(true);
interceptor.addValidatorModule(val);
ourRestServer.registerInterceptor(interceptor);
try {
CodeableConcept codeableConcept = new CodeableConcept();
Coding codingCode = codeableConcept.addCoding();
codingCode.setCode(DeviceStatus.ACTIVE.toCode());
codingCode.setSystem(DeviceStatus.ACTIVE.getSystem());
Device device = new Device();
Identifier identifier = device.addIdentifier();
identifier.setType(codeableConcept); // Not valid against valueset with 'Extensible' binding strength
ourClient.create().resource(device).execute().getId();
} finally {
ourRestServer.unregisterInterceptor(interceptor);
}
}
@Test
public void testSuppressNoBindingMessage() {
RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor();
interceptor.setFailOnSeverity(ResultSeverityEnum.INFORMATION);
FhirInstanceValidator val = new FhirInstanceValidator(myValidationSupport);
val.setNoBindingMsgSuppressed(true);
interceptor.addValidatorModule(val);
ourRestServer.registerInterceptor(interceptor);
try {
CodeableConcept codeableConcept = new CodeableConcept();
Coding codingCode = codeableConcept.addCoding();
codingCode.setSystem(DeviceStatus.ACTIVE.toCode());
codingCode.setSystem(DeviceStatus.ACTIVE.getSystem());
Task task = new Task();
task.setStatus(Task.TaskStatus.DRAFT);
task.setIntent(Task.TaskIntent.FILLERORDER);
task.setCode(codeableConcept); // Task.code has no source/binding
ourClient.create().resource(task).execute().getId();
} finally {
ourRestServer.unregisterInterceptor(interceptor);
}
}
/** /**
* See #872 * See #872
*/ */

View File

@ -29,6 +29,8 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IInsta
private BestPracticeWarningLevel myBestPracticeWarningLevel; private BestPracticeWarningLevel myBestPracticeWarningLevel;
private IValidationSupport myValidationSupport; private IValidationSupport myValidationSupport;
private boolean noTerminologyChecks = false; private boolean noTerminologyChecks = false;
private boolean noExtensibleWarnings = false;
private boolean noBindingMsgSuppressed = false;
private volatile VersionSpecificWorkerContextWrapper myWrappedWorkerContext; private volatile VersionSpecificWorkerContextWrapper myWrappedWorkerContext;
private boolean errorForUnknownProfiles; private boolean errorForUnknownProfiles;
private boolean assumeValidRestReferences; private boolean assumeValidRestReferences;
@ -184,6 +186,34 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IInsta
noTerminologyChecks = theNoTerminologyChecks; noTerminologyChecks = theNoTerminologyChecks;
} }
/**
* If set to {@literal true} (default is false) no extensible warnings suppressed
*/
public boolean isNoExtensibleWarnings() {
return noExtensibleWarnings;
}
/**
* If set to {@literal true} (default is false) no extensible warnings is suppressed
*/
public void setNoExtensibleWarnings(final boolean theNoExtensibleWarnings) {
noExtensibleWarnings = theNoExtensibleWarnings;
}
/**
* If set to {@literal true} (default is false) no binding message is suppressed
*/
public boolean isNoBindingMsgSuppressed() {
return noBindingMsgSuppressed;
}
/**
* If set to {@literal true} (default is false) no binding message is suppressed
*/
public void setNoBindingMsgSuppressed(final boolean theNoBindingMsgSuppressed) {
noBindingMsgSuppressed = theNoBindingMsgSuppressed;
}
public List<String> getExtensionDomains() { public List<String> getExtensionDomains() {
return myExtensionDomains; return myExtensionDomains;
} }
@ -198,6 +228,8 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IInsta
.setErrorForUnknownProfiles(isErrorForUnknownProfiles()) .setErrorForUnknownProfiles(isErrorForUnknownProfiles())
.setExtensionDomains(getExtensionDomains()) .setExtensionDomains(getExtensionDomains())
.setNoTerminologyChecks(isNoTerminologyChecks()) .setNoTerminologyChecks(isNoTerminologyChecks())
.setNoExtensibleWarnings(isNoExtensibleWarnings())
.setNoBindingMsgSuppressed(isNoBindingMsgSuppressed())
.setValidatorResourceFetcher(getValidatorResourceFetcher()) .setValidatorResourceFetcher(getValidatorResourceFetcher())
.setAssumeValidRestReferences(isAssumeValidRestReferences()) .setAssumeValidRestReferences(isAssumeValidRestReferences())
.validate(wrappedWorkerContext, theValidationCtx); .validate(wrappedWorkerContext, theValidationCtx);

View File

@ -38,6 +38,8 @@ class ValidatorWrapper {
private boolean myErrorForUnknownProfiles; private boolean myErrorForUnknownProfiles;
private boolean myNoTerminologyChecks; private boolean myNoTerminologyChecks;
private boolean myAssumeValidRestReferences; private boolean myAssumeValidRestReferences;
private boolean myNoExtensibleWarnings;
private boolean myNoBindingMsgSuppressed;
private Collection<? extends String> myExtensionDomains; private Collection<? extends String> myExtensionDomains;
private IResourceValidator.IValidatorResourceFetcher myValidatorResourceFetcher; private IResourceValidator.IValidatorResourceFetcher myValidatorResourceFetcher;
@ -77,6 +79,16 @@ class ValidatorWrapper {
return this; return this;
} }
public ValidatorWrapper setNoExtensibleWarnings(boolean theNoExtensibleWarnings) {
myNoExtensibleWarnings = theNoExtensibleWarnings;
return this;
}
public ValidatorWrapper setNoBindingMsgSuppressed(boolean theNoBindingMsgSuppressed) {
myNoBindingMsgSuppressed = theNoBindingMsgSuppressed;
return this;
}
public ValidatorWrapper setExtensionDomains(Collection<? extends String> theExtensionDomains) { public ValidatorWrapper setExtensionDomains(Collection<? extends String> theExtensionDomains) {
myExtensionDomains = theExtensionDomains; myExtensionDomains = theExtensionDomains;
return this; return this;
@ -105,6 +117,8 @@ class ValidatorWrapper {
v.setErrorForUnknownProfiles(myErrorForUnknownProfiles); v.setErrorForUnknownProfiles(myErrorForUnknownProfiles);
v.getExtensionDomains().addAll(myExtensionDomains); v.getExtensionDomains().addAll(myExtensionDomains);
v.setFetcher(myValidatorResourceFetcher); v.setFetcher(myValidatorResourceFetcher);
v.setNoExtensibleWarnings(myNoExtensibleWarnings);
v.setNoBindingMsgSuppressed(myNoBindingMsgSuppressed);
v.setAllowXsiLocation(true); v.setAllowXsiLocation(true);
List<ValidationMessage> messages = new ArrayList<>(); List<ValidationMessage> messages = new ArrayList<>();