FHIR Chat · Profile Validation Questions · implementers

Stream: implementers

Topic: Profile Validation Questions


view this post on Zulip Michael Calderero (Jun 09 2017 at 22:05):

Hi,

This is a question for the STU3 version of this profile.

The http://hl7.org/fhir/StructureDefinition/lipidprofile profile contains a discriminator for "reference.code" with discriminator type "value".

It references the following profiles:
a. http://hl7.org/fhir/StructureDefinition/cholesterol
b. http://hl7.org/fhir/StructureDefinition/triglyceride
c. http://hl7.org/fhir/StructureDefinition/hdlcholesterol
d. http://hl7.org/fhir/StructureDefinition/ldlcholesterol

My questions are:
1. Profiles (a) and (c) both have .fixed and .binding values. In this scenario, which takes precedence when a conformant validator slices the elements? The spec http://hl7.org/fhir/STU3/profiling.html#discriminator is not very clear to me on the precedence:
"If the type is 'value', then the element definition must use either ElementDefinition.fixed[x] or, if the element has a terminology binding, a required binding with a Value Set that enumerates the list of possible codes in the value set ("extensional definition")."
2. Followup on #1, should a conformant validator validate on both .fixed and .binding if both are present? Or is it just enough to just validate on .fixed?
3. Profile (b) has both .pattern and .binding values. As per my understanding of the profiling rules at http://hl7.org/fhir/STU3/profiling.html#discriminator a conformant validator should slice on .binding. Should a conformant validator still try to validate the given element using .pattern?

view this post on Zulip Grahame Grieve (Jun 09 2017 at 22:29):

This is a timely question. I just spent a couple of days getting this profile correct and validating. So check the current build for what it looks like when it's actually working correctly

view this post on Zulip Grahame Grieve (Jun 09 2017 at 22:30):

fixed overrides the binding

view this post on Zulip Grahame Grieve (Jun 09 2017 at 22:30):

validator just validates the fixed if it finds it, since fixed must be true irrespective of the binding

view this post on Zulip Grahame Grieve (Jun 09 2017 at 22:31):

pattern also overrides the binding - but oh, it might not. That's nasty. I'll have to think about that

view this post on Zulip Eric Haas (Jun 10 2017 at 01:32):

.... the fixed value must be a member of bound code set too. Can the pattern be used as a discriminator too? I thought not

view this post on Zulip Grahame Grieve (Jun 10 2017 at 02:01):

pattern can be used as a discriminator. It makes real sense for CodeableConcept

view this post on Zulip Michael Calderero (Jun 12 2017 at 11:57):

Thank you for the answers.

view this post on Zulip Eric Haas (Jun 13 2017 at 16:53):

Stupid FHIRPath question.... What is the FHIRpath for self "."? E.g. if I want to discriminate Identifier on its own pattern what is the (relative) path.

view this post on Zulip Bryn Rhodes (Jun 13 2017 at 16:59):

If you're in an iterator (e.g. .where()), use $this

view this post on Zulip Bryn Rhodes (Jun 13 2017 at 17:00):

You can also use %context to get to the original node passed to the execution engine.

view this post on Zulip Michael Calderero (Jun 20 2017 at 22:42):

I have a question about .fixed[x] validation.

Let's say I have the following fixed[x] value:

<fixedString value="abc">
  <extension url="url1">
    <valueBoolean value="true"/>
  </extension>
  <extension url="url2">
    <valueBoolean value="true"/>
  </extension>
</fixedString>

If I understood http://hl7.org/fhir/STU3/elementdefinition-definitions.html#ElementDefinition.fixed_x_ correctly, then the following should fail validation?
1. Because it's missing one of the extensions:

<someStringProperty value="abc">
  <extension url="url1">
    <valueBoolean value="true"/>
  </extension>
</someStringProperty>

2. Because the extensions are out of order:

<someStringProperty value="abc">
  <extension url="url2">
    <valueBoolean value="true"/>
  </extension>
  <extension url="url1">
    <valueBoolean value="true"/>
  </extension>
</someStringProperty>

view this post on Zulip Lloyd McKenzie (Jun 20 2017 at 22:45):

Yes, that sounds right. If you find the validator isn't actually enforcing this (it's entirely possible it isn't), feel free to submit a change request.

view this post on Zulip Michael Calderero (Jun 21 2017 at 19:45):

I'm trying to verify this using the validator in build.fhir.org but I'm getting this error:
C:\DevTools\fhirvalidator\latest>java -jar org.hl7.fhir.validator.jar Patient_fixed_exactlyAsFixed.xml
.. load FHIR from http://build.fhir.org/
.. connect to tx server @ http://tx.fhir.org/r3
Exception in thread "main" java.lang.Exception: Unable to find definitions at URL 'http://build.fhir.org/igpack.zip': http://build.fhir.org/igpack.zip
at org.hl7.fhir.r4.validation.ValidationEngine.loadIgFromUrl(ValidationEngine.java:282)
at org.hl7.fhir.r4.validation.ValidationEngine.loadIgSource(ValidationEngine.java:262)
at org.hl7.fhir.r4.validation.ValidationEngine.loadDefinitions(ValidationEngine.java:183)
at org.hl7.fhir.r4.validation.ValidationEngine.<init>(ValidationEngine.java:178)
at org.hl7.fhir.r4.validation.Validator.main(Validator.java:249)
Caused by: java.io.FileNotFoundException: http://build.fhir.org/igpack.zip
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.hl7.fhir.r4.validation.ValidationEngine.loadIgFromUrl(ValidationEngine.java:279)
... 4 more

And sure enough, the http://build.fhir.org/igpack.zip link returns 404.

view this post on Zulip Eric Haas (Jun 21 2017 at 20:05):

I download and run it all locally like so...
java -jar /Users/ehaas/Downloads/validator/org.hl7.fhir.validator.jar ${fs} -defn /Users/ehaas/Downloads/igpack.zip -ig "${path}"/output/validator.pack

view this post on Zulip Michael Calderero (Jun 21 2017 at 20:16):

I can't download the igpack.zip from build.fhir.org because it's not there.

So I downloaded the STU3 one and it seems it's just similar to definitions.xml.zip but with the version.info file in it.

So...I created a fakeigpack.zip file that is a copy of definitions.xml.zip from build.fhir.org and put in the version.info file from STU3 igpack.zip.

Seems to work, though I'm not sure if it'll affect validator functionality.

view this post on Zulip Eric Haas (Jun 21 2017 at 20:29):

You can also use one of the definitions file here: http://build.fhir.org/downloads.html instead

view this post on Zulip Michael Calderero (Jun 21 2017 at 21:00):

Ok, using this fakeigpack.zip, I proceeded to validate the following:
PatientProfile_fixedGenderWithExtension.xml
Patient_fixed_exactlyAsFixedProfile.xml
PatientProfile_fixedGenderWithExtension.xml is just a copy of the standard Patient profile resource with a <fixedCode> on Patient.gender.
Patient_fixed_exactlyAsFixedProfile.xml is an instance of the Patient resource with a .gender value that matches the values in .fixed.

The validator fails with the following:
C:\DevTools\fhirvalidator\latest>java -jar org.hl7.fhir.validator.jar Patient_fixed_exactlyAsFixedProfile.xml -defn fakeigpack.zip -profile PatientProfile_fixedGenderWithExtension.xml
.. load FHIR from fakeigpack.zip
.. connect to tx server @ http://tx.fhir.org/r3
(v3.0.1-11917)
Fetch Profile from PatientProfile_fixedGenderWithExtension.xml
.. validate
Exception in thread "main" java.lang.NullPointerException
at org.hl7.fhir.r4.validation.InstanceValidator.checkFixedValue(InstanceValidator.java:1234)
at org.hl7.fhir.r4.validation.InstanceValidator.checkPrimitive(InstanceValidator.java:1375)
at org.hl7.fhir.r4.validation.InstanceValidator.validateElement(InstanceValidator.java:3206)
at org.hl7.fhir.r4.validation.InstanceValidator.start(InstanceValidator.java:2369)
at org.hl7.fhir.r4.validation.InstanceValidator.validateResource(InstanceValidator.java:3450)
at org.hl7.fhir.r4.validation.InstanceValidator.validate(InstanceValidator.java:642)
at org.hl7.fhir.r4.validation.InstanceValidator.validate(InstanceValidator.java:491)
at org.hl7.fhir.r4.validation.ValidationEngine.validate(ValidationEngine.java:555)
at org.hl7.fhir.r4.validation.ValidationEngine.validate(ValidationEngine.java:483)
at org.hl7.fhir.r4.validation.Validator.main(Validator.java:300)

I also verified this against HAPI FHIR 2.4 and got the same NullPointerException.

The code:

        for (Extension e : fixed.getExtension()) {
          Element ex = getExtensionByUrl(extensions, e.getUrl());
          if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, ex != null, "Extension count mismatch: unable to find extension: " + e.getUrl())) {
            checkFixedValue(errors, path, ex.getNamedChild("extension").getNamedChild("value"), e.getValue(), "extension.value", ex.getNamedChild("extension"));
          }
        }

I traced this and it seems like the NullPointer happens with this: ex.getNamedChild("extension")

I think it makes sense because 'ex' is already the extension, so there should be no need to call ex.getNamedChild("extension") just to get the actual extension.
Please correct me if I'm wrong.


Last updated: Apr 12 2022 at 19:14 UTC