fix bug using wrong version constant for R3

This commit is contained in:
Grahame Grieve 2024-02-25 19:21:58 +11:00
parent 13342f09a3
commit c05ad6cb2c
3 changed files with 27 additions and 1 deletions

View File

@ -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<UsageContext> getUsageContexts();
public boolean isWarnOnDraftOrExperimental();
public IResourceValidator setWarnOnDraftOrExperimental(boolean warnOnDraftOrExperimental);

View File

@ -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";

View File

@ -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<String> statusWarnings = new HashSet<>();
protected BestPracticeWarningLevel bpWarnings = BestPracticeWarningLevel.Warning;
protected String sessionId = Utilities.makeUuidLC();
protected List<UsageContext> usageContexts = new ArrayList<UsageContext>();
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<UsageContext> 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);
}
}