From a65de7b98024a1b00c895d0da335d1194101694b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 1 Nov 2024 08:04:28 +1030 Subject: [PATCH] Correct fix for bug parsing json-property-key values --- .../org/hl7/fhir/r5/elementmodel/Element.java | 11 +--- .../hl7/fhir/r5/elementmodel/JsonParser.java | 2 +- .../instance/InstanceValidator.java | 63 +++++++++++-------- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java index 627fd8a66..31e90c933 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java @@ -163,8 +163,7 @@ public class Element extends Base implements NamedItem { private Object nativeObject; private List sliceDefinitions; private boolean elided; - private ElementDefinition valueProperty; // used to track the property value for JSON Key properties in logical models - + public Element(String name) { super(); this.name = name; @@ -1649,13 +1648,5 @@ public class Element extends Base implements NamedItem { public boolean isElided() { return this.elided; } - - public ElementDefinition getValueProperty() { - return valueProperty; - } - - public void setValueProperty(ElementDefinition valueProperty) { - this.valueProperty = valueProperty; - } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index 190e0c9bd..c9ad7c052 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -469,7 +469,6 @@ public class JsonParser extends ParserBase { nKey.setPath(fpathKey); n.getChildren().add(nKey); nKey.setValue(pv.getName()); - nKey.setValueProperty(propV.getDefinition()); boolean ok = true; Property pvl = propV; @@ -483,6 +482,7 @@ public class JsonParser extends ParserBase { ok = true; } else if (propV.getDefinition().getType().size() == 1 && propV.typeIsConsistent(type)) { pvl = new Property(propV.getContext(), propV.getDefinition(), propV.getStructure(), propV.getUtils(), propV.getContextUtils(), propV.getType()); + ok = true; } else { logError(errors, ValidationMessage.NO_RULE_DATE, line(pv.getValue()), col(pv.getValue()), path, IssueType.STRUCTURE, this.context.formatMessage(I18nConstants.UNRECOGNISED_PROPERTY_TYPE_WRONG, describeType(pv.getValue()), propV.getName(), type, propV.typeSummary()), IssueSeverity.ERROR); } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index d75ef2d30..08f4b3d5a 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -33,20 +33,30 @@ package org.hl7.fhir.validation.instance; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import javax.annotation.Nonnull; import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; import org.fhir.ucum.Decimal; - import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.PathEngineException; @@ -55,7 +65,6 @@ import org.hl7.fhir.r5.conformance.profile.ProfileUtilities; import org.hl7.fhir.r5.conformance.profile.ProfileUtilities.SourcedChildDefinitions; import org.hl7.fhir.r5.context.ContextUtilities; import org.hl7.fhir.r5.context.IWorkerContext; -import org.hl7.fhir.r5.context.IWorkerContext.OIDDefinition; import org.hl7.fhir.r5.context.IWorkerContext.OIDSummary; import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element.SpecialElement; @@ -65,17 +74,17 @@ import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.ObjectConverter; import org.hl7.fhir.r5.elementmodel.ParserBase; import org.hl7.fhir.r5.elementmodel.ParserBase.ValidationPolicy; -import org.hl7.fhir.r5.fhirpath.ExpressionNode; -import org.hl7.fhir.r5.fhirpath.FHIRPathEngine; -import org.hl7.fhir.r5.fhirpath.TypeDetails; -import org.hl7.fhir.r5.fhirpath.ExpressionNode.CollectionStatus; -import org.hl7.fhir.r5.fhirpath.FHIRLexer.FHIRLexerException; -import org.hl7.fhir.r5.fhirpath.FHIRPathEngine.IEvaluationContext; -import org.hl7.fhir.r5.fhirpath.FHIRPathUtilityClasses.FunctionDetails; -import org.hl7.fhir.r5.fhirpath.FHIRPathUtilityClasses.TypedElementDefinition; import org.hl7.fhir.r5.elementmodel.ResourceParser; import org.hl7.fhir.r5.elementmodel.ValidatedFragment; import org.hl7.fhir.r5.elementmodel.XmlParser; +import org.hl7.fhir.r5.fhirpath.ExpressionNode; +import org.hl7.fhir.r5.fhirpath.ExpressionNode.CollectionStatus; +import org.hl7.fhir.r5.fhirpath.FHIRLexer.FHIRLexerException; +import org.hl7.fhir.r5.fhirpath.FHIRPathEngine; +import org.hl7.fhir.r5.fhirpath.FHIRPathEngine.IEvaluationContext; +import org.hl7.fhir.r5.fhirpath.FHIRPathUtilityClasses.FunctionDetails; +import org.hl7.fhir.r5.fhirpath.FHIRPathUtilityClasses.TypedElementDefinition; +import org.hl7.fhir.r5.fhirpath.TypeDetails; import org.hl7.fhir.r5.formats.FormatUtilities; import org.hl7.fhir.r5.model.Address; import org.hl7.fhir.r5.model.Attachment; @@ -114,7 +123,6 @@ import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent; import org.hl7.fhir.r5.model.Enumeration; import org.hl7.fhir.r5.model.Enumerations.BindingStrength; import org.hl7.fhir.r5.model.Enumerations.CodeSystemContentMode; -import org.hl7.fhir.r5.model.Enumerations.PublicationStatus; import org.hl7.fhir.r5.model.Extension; import org.hl7.fhir.r5.model.HumanName; import org.hl7.fhir.r5.model.Identifier; @@ -148,7 +156,6 @@ import org.hl7.fhir.r5.model.UrlType; import org.hl7.fhir.r5.model.UsageContext; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; -import org.hl7.fhir.r5.renderers.DataRenderer; import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass; import org.hl7.fhir.r5.terminologies.utilities.ValidationResult; import org.hl7.fhir.r5.utils.BuildExtensions; @@ -159,27 +166,22 @@ import org.hl7.fhir.r5.utils.XVerExtensionManager.XVerExtensionStatus; import org.hl7.fhir.r5.utils.sql.Validator; import org.hl7.fhir.r5.utils.sql.Validator.TrueFalseOrUnknown; import org.hl7.fhir.r5.utils.validation.BundleValidationRule; -import org.hl7.fhir.r5.utils.validation.IMessagingServices; import org.hl7.fhir.r5.utils.validation.IResourceValidator; -import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor; -import org.hl7.fhir.r5.utils.validation.IValidationProfileUsageTracker; -import org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher; import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.CodedContentValidationAction; import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.ElementValidationAction; +import org.hl7.fhir.r5.utils.validation.IValidationProfileUsageTracker; +import org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher; import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; import org.hl7.fhir.r5.utils.validation.constants.BindingKind; import org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption; -import org.hl7.fhir.r5.utils.validation.constants.CodedContentValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.IdStatus; import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; -import org.hl7.fhir.utilities.FhirPublication; import org.hl7.fhir.utilities.HL7WorkGroups; import org.hl7.fhir.utilities.HL7WorkGroups.HL7WorkGroup; import org.hl7.fhir.utilities.MarkDownProcessor; import org.hl7.fhir.utilities.SIDUtilities; -import org.hl7.fhir.utilities.StandardsStatus; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.UnicodeUtilities; import org.hl7.fhir.utilities.Utilities; @@ -201,8 +203,6 @@ import org.hl7.fhir.validation.BaseValidator; import org.hl7.fhir.validation.cli.model.HtmlInMarkdownCheck; import org.hl7.fhir.validation.cli.utils.QuestionnaireMode; import org.hl7.fhir.validation.codesystem.CodingsObserver; -import org.hl7.fhir.validation.instance.InstanceValidator.BindingContext; -import org.hl7.fhir.validation.instance.advisor.BasePolicyAdvisorForFullValidation; import org.hl7.fhir.validation.instance.type.BundleValidator; import org.hl7.fhir.validation.instance.type.CodeSystemValidator; import org.hl7.fhir.validation.instance.type.ConceptMapValidator; @@ -216,7 +216,20 @@ import org.hl7.fhir.validation.instance.type.StructureMapValidator; import org.hl7.fhir.validation.instance.type.StructureMapValidator.VariableDefn; import org.hl7.fhir.validation.instance.type.StructureMapValidator.VariableSet; import org.hl7.fhir.validation.instance.type.ValueSetValidator; -import org.hl7.fhir.validation.instance.utils.*; +import org.hl7.fhir.validation.instance.utils.Base64Util; +import org.hl7.fhir.validation.instance.utils.CanonicalResourceLookupResult; +import org.hl7.fhir.validation.instance.utils.CanonicalTypeSorter; +import org.hl7.fhir.validation.instance.utils.ChildIterator; +import org.hl7.fhir.validation.instance.utils.ElementInfo; +import org.hl7.fhir.validation.instance.utils.EnableWhenEvaluator; +import org.hl7.fhir.validation.instance.utils.FHIRPathExpressionFixer; +import org.hl7.fhir.validation.instance.utils.IndexedElement; +import org.hl7.fhir.validation.instance.utils.NodeStack; +import org.hl7.fhir.validation.instance.utils.ResolvedReference; +import org.hl7.fhir.validation.instance.utils.ResourceValidationTracker; +import org.hl7.fhir.validation.instance.utils.StructureDefinitionSorterByUrl; +import org.hl7.fhir.validation.instance.utils.UrlUtil; +import org.hl7.fhir.validation.instance.utils.ValidationContext; import org.w3c.dom.Document; @@ -6933,7 +6946,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat slices = profileUtilities.getSliceList(profile, ed); } for (ElementInfo ei : children) { - if (ei.definition == ed || (ei.getElement().getValueProperty() == ed)) { + if (ei.definition == ed) { count++; } else if (slices != null) { for (ElementDefinition sed : slices) {