From 76eb85308cabd31b7d70cfc6ac61109d3f3aa822 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Tue, 13 Nov 2018 08:27:10 +0200 Subject: [PATCH] Way to inject custom enablewhen evaluator added --- .../hapi/validation/FhirInstanceValidator.java | 14 ++++++++++++++ .../hl7/fhir/r4/validation/InstanceValidator.java | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java index 83a227a6541..c09e9ea9115 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidator.java @@ -31,6 +31,8 @@ import org.hl7.fhir.r4.utils.INarrativeGenerator; import org.hl7.fhir.r4.utils.IResourceValidator; import org.hl7.fhir.r4.utils.IResourceValidator.BestPracticeWarningLevel; import org.hl7.fhir.r4.utils.IResourceValidator.IdStatus; +import org.hl7.fhir.r4.validation.DefaultEnableWhenEvaluator; +import org.hl7.fhir.r4.validation.IEnableWhenEvaluator; import org.hl7.fhir.r4.validation.InstanceValidator; import org.hl7.fhir.utilities.TranslationServices; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -47,6 +49,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.function.Function; @SuppressWarnings({"PackageAccessibility", "Duplicates"}) public class FhirInstanceValidator extends BaseValidatorBridge implements IValidatorModule { @@ -60,6 +63,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid private IValidationSupport myValidationSupport; private boolean noTerminologyChecks = false; private volatile WorkerContextWrapper myWrappedWorkerContext; + private Function enableWhenEvaluatorSupplier = ctx -> new DefaultEnableWhenEvaluator(); /** * Constructor @@ -202,6 +206,15 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid public boolean isNoTerminologyChecks() { return noTerminologyChecks; } + + /** + * Sets a customized {@link IEnableWhenEvaluator} which is injected to created InstanceValidators + * @param myEnableWhenEvaluator + */ + public void setEnableWhenEvaluatorSupplier( + Function enableWhenEvaluatorSupplier) { + this.enableWhenEvaluatorSupplier = enableWhenEvaluatorSupplier; + } /** * If set to {@literal true} (default is false) the valueSet will not be validate @@ -235,6 +248,7 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid v.setAnyExtensionsAllowed(isAnyExtensionsAllowed()); v.setResourceIdRule(IdStatus.OPTIONAL); v.setNoTerminologyChecks(isNoTerminologyChecks()); + v.setMyEnableWhenEvaluator(enableWhenEvaluatorSupplier.apply(wrappedWorkerContext)); List messages = new ArrayList<>(); diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/InstanceValidator.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/InstanceValidator.java index 1f6de3dd1e1..9b8a01bfee4 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/InstanceValidator.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/r4/validation/InstanceValidator.java @@ -2379,6 +2379,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat public void setAllowXsiLocation(boolean allowXsiLocation) { this.allowXsiLocation = allowXsiLocation; } + + public void setMyEnableWhenEvaluator(IEnableWhenEvaluator myEnableWhenEvaluator) { + this.myEnableWhenEvaluator = myEnableWhenEvaluator; + } /** *