From c05ad6cb2cde4328f99d3ed82e70d9bb5d5d6b39 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 25 Feb 2024 19:21:58 +1100 Subject: [PATCH] fix bug using wrong version constant for R3 --- .../utils/validation/IResourceValidator.java | 4 ++++ .../hl7/fhir/utilities/FhirPublication.java | 2 +- .../hl7/fhir/validation/BaseValidator.java | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java index 837945ebb..aa465b531 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/validation/IResourceValidator.java @@ -34,6 +34,7 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.model.Coding; import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.r5.model.UsageContext; import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; import org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption; import org.hl7.fhir.r5.utils.validation.constants.IdStatus; @@ -105,6 +106,9 @@ public interface IResourceValidator { boolean isExample(); IResourceValidator setExample(boolean example); + // used to decide whether additional bindings, constraints etc apply + public List getUsageContexts(); + public boolean isWarnOnDraftOrExperimental(); public IResourceValidator setWarnOnDraftOrExperimental(boolean warnOnDraftOrExperimental); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FhirPublication.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FhirPublication.java index 33fc9e451..751fead07 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FhirPublication.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FhirPublication.java @@ -39,7 +39,7 @@ public enum FhirPublication { case DSTU1: return "0.01"; case DSTU2: return "1.0.2"; case DSTU2016May: return "1.4.0"; - case STU3: return "3.0.1"; + case STU3: return "3.0.2"; case R4: return "4.0.1"; case R4B: return "4.3.0"; case R5: return "5.0.0"; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java index 94cbb8cd8..557ec5756 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java @@ -59,6 +59,7 @@ import org.hl7.fhir.r5.model.Constants; import org.hl7.fhir.r5.model.DomainResource; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.r5.model.UsageContext; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.Enumerations.PublicationStatus; import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent; @@ -75,6 +76,7 @@ import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.Source; @@ -173,6 +175,8 @@ public class BaseValidator implements IValidationContextResourceLoader { protected Set statusWarnings = new HashSet<>(); protected BestPracticeWarningLevel bpWarnings = BestPracticeWarningLevel.Warning; protected String sessionId = Utilities.makeUuidLC(); + protected List usageContexts = new ArrayList(); + protected ValidationOptions baseOptions = new ValidationOptions(FhirPublication.R5); public BaseValidator(IWorkerContext context, XVerExtensionManager xverManager, boolean debug) { @@ -204,6 +208,8 @@ public class BaseValidator implements IValidationContextResourceLoader { this.statusWarnings = parent.statusWarnings; this.bpWarnings = parent.bpWarnings; this.urlRegex = parent.urlRegex; + this.usageContexts.addAll(parent.usageContexts); + this.baseOptions = parent.baseOptions; } private boolean doingLevel(IssueSeverity error) { @@ -1599,4 +1605,20 @@ public class BaseValidator implements IValidationContextResourceLoader { return true; } + public List getUsageContexts() { + return usageContexts; + } + + protected boolean hasUseContext(Coding use, Coding value) { + for (UsageContext usage : usageContexts) { + if (isContext(use, value, usage)) { + return true; + } + } + return false; + } + + private boolean isContext(Coding use, Coding value, UsageContext usage) { + return usage.getValue() instanceof Coding && context.subsumes(baseOptions, usage.getCode(), use) && context.subsumes(baseOptions, (Coding) usage.getValue(), value); + } } \ No newline at end of file