FirelyTeam / firely-validator-api

Firely's official FHIR validator API for validating HL7 FHIR resources against profiles.
Other
8 stars 2 forks source link

[SnapshotGenerator] Adding a type slice to an already closed slice should give an error #328

Open mmsmits opened 4 years ago

mmsmits commented 4 years ago

Test created: Test_obs1_2

baseProfile:

<differential>
    <element>
      <path value="Observation.value[x]" />
      <slicing>
        <rules value="closed" />
      </slicing>
      <type>
        <code value="CodeableConcept" />
      </type>
    </element>
    <element>
      <path value="Observation.value[x]" />
      <sliceName value="valueCodeableConcept" />
      <type>
        <code value="CodeableConcept" />
      </type>
      <binding>
        <strength value="required" />
        <valueSet value="http://somewhere/something" />
      </binding>
    </element>
  </differential>

profile on Profile:

<differential>
    <element>
      <path value="Observation.value[x]" />
      <slicing>
        <rules value="closed" />
      </slicing>
      <type>
        <code value="Quantity" />
      </type>
    </element>
    <element>
      <path value="Observation.value[x]" />
      <sliceName value="valueQuantity" />
      <type>
        <code value="Quantity" />
      </type>
      <binding>
        <strength value="required" />
        <valueSet value="http://somewhere/something-else" />
      </binding>
    </element>
  </differential>

Should give an error, because the baseProfile already defined a typeSlice (closed), but the snapshot generator generates a faulty snapshot with both slices in it, where it should give an error that you can't add a slice to closed slicing array.

mmsmits commented 4 months ago

This issue triggers multiple problems:

  1. IResourceResolver can't report any issues when trying to resolve an artifact meaning we can't communicate any issues from the SnapshotGenerator to the user. https://github.com/FirelyTeam/firely-net-sdk/issues/2808
  2. This issue results in a faulty snapshot, we could report this during generation. Normally we let the validator do this, but not all users validate their StructureDefinitions.
  3. If we want to validate this using the validator-api, we need to add a looooot of extra logic -> A ElementDefinitionNavigator-like class on ITypedElement to have all the slice logic and being able to resolve the base and using that for validation.