Skip to content

Commit

Permalink
Merge pull request #238 from FirelyTeam/fix/214-location-incorrect
Browse files Browse the repository at this point in the history
Solving an index element at the start of a location state.
  • Loading branch information
ewoutkramer authored Dec 19, 2023
2 parents 1ecb390 + 387f14b commit 1df6843
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/Firely.Fhir.Validation/Schema/InstancePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ Current is null
/// Update the path to include an index of a child element.
/// </summary>
/// <param name="index">The index of the child element.</param>
public InstancePath ToIndex(int index) => new(new IndexNavEvent(Current, index));
public InstancePath ToIndex(int index) =>
Current is not null
? new(new IndexNavEvent(Current, index)) // Cannot start at the beginning of the path.
: this;

/// <summary>
/// Update the path to include a set of indices of a group element, which can be used later with a <see cref="IndexNavEvent"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,25 @@ public void RunValidateOnErrorDemoBundle()
var result = runValidation("MainBundle-with-errors.bundle.xml");

var checkedResult = """
Overall result: FAILURE (20 errors and 1 warnings)
[ERROR] Instance failed constraint bdl-1 "total only when a search or history" (at [0], element Bundle(http://example.org/StructureDefinition/DocumentBundle))
[ERROR] Instance count is 1, which is not within the specified cardinality of 0..0 (at [0].total, element Bundle(http://example.org/StructureDefinition/DocumentBundle).total)
[ERROR] Encountered a reference (http://example.org/fhir/Practitioner/Hippocrates) of kind 'Referenced', which is not one of the allowed kinds (Bundled). (at [0].entry[0].resource[0].author[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).author)
Overall result: FAILURE (13 errors and 1 warnings)
[ERROR] Instance failed constraint bdl-1 "total only when a search or history" (at Bundle, element Bundle(http://example.org/StructureDefinition/DocumentBundle))
[ERROR] Instance count is 1, which is not within the specified cardinality of 0..0 (at Bundle.total, element Bundle(http://example.org/StructureDefinition/DocumentBundle).total)
[ERROR] Encountered a reference (http://example.org/fhir/Practitioner/Hippocrates) of kind 'Referenced', which is not one of the allowed kinds (Bundled). (at Bundle.entry[0].resource[0].author[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).author)
[ERROR] Element does not validate against any of the expected profiles (http://example.org/StructureDefinition/WeightQuantity, http://example.org/StructureDefinition/HeightQuantity). (at Bundle.entry[1].resource[0].valueQuantity[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][Quantity])
[ERROR] Value '75600' is larger than 200) (at Bundle.entry[1].resource[0].valueQuantity[0].value[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/WeightQuantity).value)
[ERROR] Value 'http://unitsofmeasurex.org' is not exactly equal to fixed value 'http://unitsofmeasure.org' (at Bundle.entry[1].resource[0].valueQuantity[0].system[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/WeightQuantity).system)
[ERROR] Value 'g' is not exactly equal to fixed value 'kg' (at Bundle.entry[1].resource[0].valueQuantity[0].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/WeightQuantity).code)
[ERROR] Value '75600' is larger than 350) (at Bundle.entry[1].resource[0].valueQuantity[0].value[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/HeightQuantity).value)
[ERROR] Value 'g' is not exactly equal to fixed value 'cm' (at Bundle.entry[1].resource[0].valueQuantity[0].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/HeightQuantity).code)
[ERROR] Element is of type 'boolean', which is not one of the allowed choice types ('string','Quantity') (at Bundle.entry[2].resource[0].valueBoolean[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.entry->Observation.value[x][@default])
[WARNING] Code '10154-3' from system 'http://loinc.org' has incorrect display 'Hoofdklacht', should be 'Chief complaint' (at [0].entry[0].resource[0].section[2].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.code)
[ERROR] Value 'Misc internal annotations' is too long (maximum length is 20 (at [0].entry[0].resource[0].section[4].title[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.title)
[ERROR] Code 'internal notes' from system 'http://example.org/fhir/demo-section-titles' does not exist in the value set 'MainBundle Section title codes' (http://example.org/ValueSet/SectionTitles) (at [0].entry[0].resource[0].section[4].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.code)
[ERROR] Instance count is 2, which is not within the specified cardinality of 1..1 (at [0].entry[0].resource[0].section, element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section[vitalSigns])
[ERROR] Element does not validate against any of the expected profiles (http://example.org/StructureDefinition/WeightQuantity, http://example.org/StructureDefinition/HeightQuantity). (at [0].entry[1].resource[0].valueQuantity[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][Quantity])
[ERROR] Value '75600' is larger than 200) (at [0].entry[1].resource[0].valueQuantity[0].value[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/WeightQuantity).value)
[ERROR] Value 'http://unitsofmeasurex.org' is not exactly equal to fixed value 'http://unitsofmeasure.org' (at [0].entry[1].resource[0].valueQuantity[0].system[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/WeightQuantity).system)
[ERROR] Value 'g' is not exactly equal to fixed value 'kg' (at [0].entry[1].resource[0].valueQuantity[0].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/WeightQuantity).code)
[ERROR] Value '75600' is larger than 350) (at [0].entry[1].resource[0].valueQuantity[0].value[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/HeightQuantity).value)
[ERROR] Value 'g' is not exactly equal to fixed value 'cm' (at [0].entry[1].resource[0].valueQuantity[0].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][Quantity]->Quantity(http://example.org/StructureDefinition/HeightQuantity).code)
[ERROR] Element is of type 'boolean', which is not one of the allowed choice types ('string','Quantity') (at [0].entry[2].resource[0].valueBoolean[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Observation.value[x][@default])
[WARNING] Code '10154-3' from system 'http://loinc.org' has incorrect display 'Hoofdklacht', should be 'Chief complaint' (at Bundle.entry[0].resource[0].section[2].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.code)
[ERROR] Value 'Misc internal annotations' is too long (maximum length is 20 (at Bundle.entry[0].resource[0].section[4].title[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.title)
[ERROR] Code 'internal notes' from system 'http://example.org/fhir/demo-section-titles' does not exist in the value set 'MainBundle Section title codes' (http://example.org/ValueSet/SectionTitles) (at Bundle.entry[0].resource[0].section[4].code[0], element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section.code)
[ERROR] Instance count is 2, which is not within the specified cardinality of 1..1 (at Bundle.entry[0].resource[0].section, element Bundle(http://example.org/StructureDefinition/DocumentBundle).entry.resource->Composition(http://example.org/StructureDefinition/DocumentComposition).section[vitalSigns])
""".Trim('\t', '\n', '\r', ' ');

result.Success.Should().BeFalse();
result.Errors.Should().Be(20);
result.Errors.Should().Be(13);
result.Warnings.Should().Be(1);
var resultString = result.ToString().Trim('\t', '\n', '\r', ' ');
resultString.Should().Be(checkedResult);
Expand Down

0 comments on commit 1df6843

Please sign in to comment.