Skip to content

Implement conformsTo - #109

Open
FikriMilano wants to merge 5 commits into
ohs-foundation:mainfrom
FikriMilano:conforms-to
Open

Implement conformsTo#109
FikriMilano wants to merge 5 commits into
ohs-foundation:mainfrom
FikriMilano:conforms-to

Conversation

@FikriMilano

Copy link
Copy Markdown
Member

Implements the FHIR-specific conformsTo(structure) function (https://hl7.org/fhir/R4/fhirpath.html#functions) for the base FHIR profiles: a structure of the form http://hl7.org/fhir/StructureDefinition/<Type> is resolved to the type and compared against the input element's type.

  • true / false for resolvable structures.
  • An error for anything that cannot be resolved to a valid profile.
  • Empty input returns empty, multiple input elements error.

Custom profiles would need profile validation, which is not implemented, this is documented in the readme.

@FikriMilano
FikriMilano requested a review from jingtang10 August 1, 2026 05:51
@FikriMilano FikriMilano self-assigned this Aug 1, 2026
@FikriMilano
FikriMilano requested a review from a team August 1, 2026 05:51
@FikriMilano FikriMilano moved this from Todo to In Progress in FHIR Foundations Aug 1, 2026
Comment thread README.md Outdated
Comment thread README.md Outdated
The `conformsTo()` function supports the base FHIR profiles
(`http://hl7.org/fhir/StructureDefinition/<Type>`): the input element's type is compared to the
type named by the structure. Custom profiles (e.g. US Core) would require profile validation,
which is not implemented. Passing a custom profile URL results in an error, consistent with the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec does say this:

If the input is not a single item, the structure is empty, or the structure cannot be resolved to a valid profile, the result is empty.

so does it not mean we should return emtpy collection rather than throwing an error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me clarify, that's the current spec text, but R4 says:

If the structure cannot be resolved to a valid profile, an error is thrown 

https://hl7.org/fhir/R4/fhirpath.html#functions

and testConformsTo3 expects an execution error for conformsTo('http://trash')

<test name="testConformsTo3" inputfile="patient-example.xml"><expression invalid="execution">conformsTo('http://trash')</expression></test>

so returning empty would fail conformance.

The doc link was pointing at the versionless (current, https://hl7.org/fhir/fhirpath.html#functions) spec though, which is misleading. I can fix the R4 link.

But main point is, do we want to follow the latest spec, or refer to R4?
We might want to refer to the latest spec, since it's the up to date spec.
Or, we might pick R4 bcz our test case refers to tests-fhir-r4.xml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good question - one thing to note is that this part of the spec is part of FHIR and not actually part of FHIRPath... and we DO have FHIR version specific implementations - we have FhirEngine.forR4 forR4B and forR5... so if we're to be really serious about this, we can actually implement different behaviors for different verions... but I'm not sure if it's worth the effort.

I don't have a super strong view here - but if we're not going to diverge between different fhir versions, it seems to make sense to implement the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants