org.hl7.fhir.core icon indicating copy to clipboard operation
org.hl7.fhir.core copied to clipboard

Resolve references on disk

Open pieter-edelman-nictiz opened this issue 3 years ago • 11 comments

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.

pieter-edelman-nictiz avatar Nov 07 '21 13:11 pieter-edelman-nictiz

Just opened a draft PR as a demo of a simple approach.

pieter-edelman-nictiz avatar Nov 07 '21 14:11 pieter-edelman-nictiz

is this a good feature, is it? How would it work from a user point of view?

grahamegrieve avatar Nov 09 '21 00:11 grahamegrieve

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.

pieter-edelman-nictiz avatar Nov 09 '21 10:11 pieter-edelman-nictiz

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

grahamegrieve avatar Nov 09 '21 22:11 grahamegrieve

(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.

pieter-edelman-nictiz avatar Nov 11 '21 12:11 pieter-edelman-nictiz

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 avatar Nov 16 '21 21:11 grahamegrieve

@grahamegrieve @dotasek good to hear, please let me know if I can help out.

pieter-edelman-nictiz avatar Nov 17 '21 15:11 pieter-edelman-nictiz

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.

david-simons avatar Dec 23 '21 10:12 david-simons

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

david-simons avatar Apr 06 '22 08:04 david-simons

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.

stale[bot] avatar Sep 28 '22 18:09 stale[bot]

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?

david-simons avatar Sep 29 '22 07:09 david-simons

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.

stale[bot] avatar Mar 24 '23 01:03 stale[bot]