Stream: conformance
Topic: issue with boundsDuration
Ilia Kaplan (Mar 25 2022 at 01:45):
Hi there !
drt-1.xml
I'm trying to validate the attached observation file . Both Java validator and hapi server (https://hapi.fhir.org/baseR4/Observation/$validate)
state about 2 violated rules : drt-1 and qty-3 when examining Observation.effective.ofType(Timing).repeat.bounds.ofType(Duration).
drt-1 rule dictates "There SHALL be a code if there is a value and it SHALL be an expression of time. If system is present, it SHALL be UCUM"
My boundsDuration look as below , and as I understand it doesn't violates what the rule dictates. however Java validator and hapi server consider it as violation . What I'm missing here ?
<effectiveTiming>
<repeat>
<boundsDuration>
<value value="10"/>
<unit value="day"/>
<code value="d"/>
</boundsDuration>
</repeat>
</effectiveTiming>
qty-3 rule
According to observation.sch (schematron definition for observation ) qty-3 rule is not defined on effectiveTiming/f:repeat/f:boundsDuration at all . So how come the rule is violated ?
I would appreciate if you could enlighten me what I' missing here .
Thanks ,
Ilia
Richard Townley-O'Neill (Mar 25 2022 at 02:02):
qty-3 requires that system be present when code is.
drt-1 does not mention that in its text, but does include it in its FHIRPath
There SHALL be a code if there is a value and it SHALL be an expression of time. If system is present, it SHALL be UCUM.
code.exists() implies ((system = %ucum) and value.exists())
You need to include the system
<value value="10"/>
<unit value="day"/>
<system value="http://unitsofmeasure.org"/>
<code value="d"/>
Richard Townley-O'Neill (Mar 25 2022 at 02:05):
(deleted)
Ilia Kaplan (Mar 25 2022 at 02:33):
qty-3 - I'm aware of "system to be present when code is" requirement of qty-3 . What I can't understand is why it's fired on
f:Observation/f:effectiveTiming/f:repeat/f:boundsDuration . I mean this rule even not defined for f:Observation/f:effectiveTiming/f:repeat/f:boundsDuration, only drt-1 supposed to be validated when examining this Xpath .
see attached observation.sch
drt-1 - Looking into FHIRPath makes it more clear - the system should be present . What is misleading here is schematron definition
(f:code or not(f:value)) and (not(exists(f:system)) or f:system/@value='http://unitsofmeasure.org')
that defines system as optional element. Then the question is what should be the source of truth when it comes to validation:
FHIRPath or schematron ?
Richard Townley-O'Neill (Mar 25 2022 at 05:30):
@Ilia Kaplan
qty-3 duration inherits from quantity, see http://hl7.org/fhir/R4/datatypes.html#QuantityVariations
drt-1 FHIRPath is what is in formal definitions, e.g. of duration . FHIRPath is more expressive than Schematron and the Schematrons are generated from the FHIRPath.
Have you seen https://hl7.org/fhir/R4/validation.html and https://hl7.org/fhir/R4/conformance-rules.html#constraints ?
Ilia Kaplan (Mar 29 2022 at 03:48):
Hi
I've seen those pages , but some essential things are still unclear for me.
Given the attached sample - how the rule defined on quantity datatype is validated ?
- Is it defined in some sort of another schematron file ? where the validator has to access in order to check it
- how the validators actually knows that in Observation/f:effectiveTiming/f:repeat/f:boundsDuration it has to check not only the schematron based rules but also to expand its search to the rules defined on datatype level ?
Richard Townley-O'Neill (Mar 29 2022 at 05:15):
The validator does not use Schematron, or any of the other validation methods. It is written in Java and the source is in GitHub if you want to see the details. I just use it. :smile:
Lloyd McKenzie (Mar 29 2022 at 14:09):
If using Schematron and not the HL7 validator, the fully generated Schematron sets the context for each element and lists all inherited invariants.
Grahame Grieve (Mar 29 2022 at 22:48):
The validator always checks both element and type constraints.
Ilia Kaplan (Apr 05 2022 at 17:31):
Hi again
thank you for the clarifications .
Our team has started to work on building FHIR validator which is based on Schematron , and I have some concerns if we adopt the right approach.
-
Is Schematron validation reliable in a long term perspective ? I noticed this warning message on hapi page
https://hapifhir.io/hapi-fhir/docs/validation/schema_validator.html -
Is it correct assumption that most of the FHIR providers just use Java validator or something that's built on top of it ?
-
The drt-1 issue mentioned above basically claims that Schematron is not really source of truth when it comes to validation . FHIRPath definition of the rule is more reliable . If that's the case - to what extent we can trust schematron ? BTw , is there any repository of rules expressed using FHIRPath like schematron files ?
-
Is there any way to validate inherited rules as it's required in case of qty-3 mentioned above? @Lloyd McKenzie what is fully generated Schematron ? I have Schematron files per resource and fhir-invariants.sch. I couldn't find anything in these files that can invoke qty-3 on f:Observation/f:effectiveTiming/f:repeat/f:boundsDuration
-
Schematron validation has no coverage for validating system codes and resources (ex. "Unable to resolve resource" ).
Validating system codes and resources seem to be much more wider and complicated rather than validating schematron rules.
Could you point me to some resources that guide how to approach these topics ?
Lloyd McKenzie (Apr 05 2022 at 20:38):
- Schematron is incapable of checking value sets, certain types of invariants, resolving references, and doing a number of other things. Also, it obviously only works on XML and well over 50% of FHIR instances are JSON. In short, Schematron can work for the things it's good at, but unless there's a reason you must use Schematron, you're probably better starting with the existing Java or .NET validator
- Most systems do their own validation based on business rules plus, possibly some light-weight schema validation to do a sanity check. However, for those systems that do full validation, then yes, either the Java or .NET validator as the most common foundation. (Writing a FHIR validator is a lot of work and hard to get right - slicing can be downright miserable, so leveraging existing work often makes more sense than rolling your own.)
- Existing models are supposed to be expressed in both FHIRPath and XPath. However, the requirement for XPath is being dropped in R5. And in practice, some invariants simply can't be expressed in XPath (e.g. anything that depends on 'resolve()'). And I know of a number of IGs that just fill the XPath for their invariants with 'true()' and don't bother - even if the invariant could be expressed in XPath because the XPath isn't visible in their specs and it's their belief that no-one cares. (And few people know how to write XPath 2.) The fact that XPath errors get picked up this late is a symptom of the fact that XPath/Schematron aren't widely used
- The generated schematron files are supposed to handle this. However, it's possible they don't and no-one's noticed. You could file a change request and we can fix it as a tooling bug.
- If you mean "how to approach these topics using schematron", the answer is 'no'. XPath has no capability to do it. That's one of the reasons we chose to create FHIRPath. (Lack of library support for XPath 2, need to support other syntaxes, and a few other considerations came into play too.)
Ilia Kaplan (Apr 06 2022 at 03:50):
In 5. I meant how tp approach value sets, resolving references and other things that can't be covered by Schematron
Lloyd McKenzie (Apr 06 2022 at 04:00):
You'll need to do them by writing code - or you could just leverage one of the existing open-source validators. What is your objective in writing your own?
Ilia Kaplan (Apr 06 2022 at 05:33):
writing my own was not my decision , I tend to think that leveraging existing code for validator will require less effort and it eventually will do better job
Lloyd McKenzie (Apr 06 2022 at 13:32):
I would agree. There's a lot of development effort that's gone into the existing ones. If you decide (or are told) that you must create your own, do check out the test cases, which are maintained here: https://github.com/FHIR/fhir-test-cases/tree/master/validator
Last updated: Apr 12 2022 at 19:14 UTC