org.hl7.fhir.core
org.hl7.fhir.core copied to clipboard
Resolve references on disk
When validating a file on disk using the HL7 Validator, it's not possible to resolve a relative reference. However, sometimes it is required for proper validation to consider the referenced resource. I'm not sure if a "proper" mechanism exists, but it would seem logical to make the Validator treat a relative reference in the form of "ResourceType/id" as a relative reference on disk, so it would search for a file that represents this resource type and id.
Some considerations:
- This behavior could be activated using a switch command line switch.
- There could be rules regarding file names of referenced resources, like naming them according to the id or combination of resource type and id.
- Referenced resources could be required to be in the same folder, or they some command line option could be used to set the folder of referenced resources.
Just opened a draft PR as a demo of a simple approach.
is this a good feature, is it? How would it work from a user point of view?
Suppose I have a file representing an Observation resource that I want to validate using the Validator. This Observation needs to reference a Patient resource (which also only exists as a file). It would seem logical if in the Observation I could just use:
<subject>
<reference value="Patient/Everyman01"/>
<display value="Adam Everyman"/>
</subject>
And that the Validator then would look for a file in the same directory called "Patient-Everyman01.xml" or "Everyman01.xml" and try to read them as the Patient resource. This would align with the way relative references work on a server.
discussion amongst the committers:
- we won't enable this by default (may have unexpected side effects in existing deployments)
- whatever we do, has to work for validator.fhir.org as well as the CLI validator
- there's lots of patterns that people use. For a survey see line 204 of org.hl7.fhir.igtools.publisher.SimpleFetcher
- so you'd have to provide a pattern, something like a parameter -resolve={type}/{id}.{fmt} which operates from the current directory
- validator.fhir.org would use the same pattern approach inside an uploaded zip file
(link to line 204: https://github.com/HL7/fhir-ig-publisher/blob/be10fd8c5e22415fa5446d4757df905962ea947d/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/SimpleFetcher.java#L204)
Seeing the variety of file naming approaches, providing a pattern seems like a good approach. However, maybe there could be simpler alternatives:
- Introduce a flag that behaves similar to
-ig
in that it scans all json, xml and turtle files in the provided directory and indexes their type and id to resolve references. - Treat references as (relative or absolute) paths (activated by a command-line flag). The downside is that you cannot just re-use the same files as on a server.
Committer discussion: we like the first option. @dotasek is going to add a parameter -references that works like the -ig parameter and is used to resolve references
@grahamegrieve @dotasek good to hear, please let me know if I can help out.
in our set-up we use *.example.xml
as file-extension for instances that need to be validated along with the profiles - either in the subfolder tree from our profiling repo or in the NPM package being validated, and hence the scope of the logical IDs.
again running into this :)
we are now forced to fall back to contain <contained>
the referenced examples - which may be ok design/test-time for a self-contained test-set, but not practical
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.
Committer discussion: we like the first option. @dotasek is going to add a parameter -references that works like the -ig parameter and is used to resolve references
curious if this was implemented?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.