Skip to content

Conversation

@lukedegruchy
Copy link
Contributor

@lukedegruchy lukedegruchy commented Oct 7, 2025

  • Validate that the measure library canonical URL is coherent before constructing a VersionedIdentifier from it.
  • Make use of Canonicals to do this
  • Enhance Canonicals with hashCode(), equals(), and toString()
  • Enhance Canonicals with system
  • Refactor VersionedIdentifiers to make use of Canonicals and enhance by adding the URL's system

Closes #766

…e library if the URL from the measure is in conflict.
@github-actions
Copy link

github-actions bot commented Oct 7, 2025

Formatting check succeeded!

@lukedegruchy lukedegruchy changed the title Ensure that the VersionedIdentifier we pass to CQL is derived from th… Ensure that the VersionedIdentifier we pass to CQL is derived from the library if the URL from the measure is in conflict. Oct 7, 2025
@lukedegruchy lukedegruchy marked this pull request as ready for review October 7, 2025 20:26
@codecov
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

❌ Patch coverage is 61.53846% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.93%. Comparing base (0bd34e3) to head (c4413a4).

Files with missing lines Patch % Lines
.../java/org/opencds/cqf/fhir/utility/Canonicals.java 48.78% 19 Missing and 2 partials ⚠️
.../measure/r4/R4VersionedLibraryIdentifierUtils.java 53.33% 10 Missing and 4 partials ⚠️
...org/opencds/cqf/fhir/cql/VersionedIdentifiers.java 69.23% 1 Missing and 3 partials ⚠️
...hir/cr/measure/r4/utils/R4MeasureServiceUtils.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #768      +/-   ##
============================================
- Coverage     73.01%   72.93%   -0.08%     
  Complexity      235      235              
============================================
  Files           538      539       +1     
  Lines         25170    25237      +67     
  Branches       3190     3207      +17     
============================================
+ Hits          18377    18406      +29     
- Misses         5270     5300      +30     
- Partials       1523     1531       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@brynrhodes brynrhodes left a comment

Choose a reason for hiding this comment

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

This is quite a bit of logic to handle non-compliant libraries. Why not just require the libraries to be compliant?

Copy link
Member

@brynrhodes brynrhodes left a comment

Choose a reason for hiding this comment

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

It seems to me that we ought to be using this class:

https://github.com/cqframework/clinical-reasoning/blob/master/cqf-fhir-utility/src/main/java/org/opencds/cqf/fhir/utility/Canonicals.java#L10

There are some tricky edge cases in dealing with canonical references, and this class wraps them all up nicely, we shouldn't be re-inventing that logic here, just re-use what's in the Canonicals class, yes?

@lukedegruchy lukedegruchy changed the title Ensure that the VersionedIdentifier we pass to CQL is derived from the library if the URL from the measure is in conflict. Validate measure library URL before CQL evaluation Oct 10, 2025
Copy link
Member

@brynrhodes brynrhodes left a comment

Choose a reason for hiding this comment

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

Looking good, a few comments on the Canonicals class

String url = getUrl(canonical);
String id = getIdPart(canonical);
String resourceType = getResourceType(canonical);
String system = getSystem(canonical, resourceType);
Copy link
Member

Choose a reason for hiding this comment

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

I suggest that we call this "canonicalBase", that's the term that is used to describe this portion of a FHIR canonical URL, whereas the term "system" typically means the canonical URL of a naming or code system.

For a VersionedIdentifier, we are using the "canonicalBase" of the FHIR URL as the "system" for our identifiers, so when we talk about it in VersionIdentifier, system is the right term, but here in the general utilities for dealing with FHIR canonical URLs, it's the canonicalBase.

checkNotNull(canonical);

String url = getUrl(canonical);
String id = getIdPart(canonical);
Copy link
Member

Choose a reason for hiding this comment

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

While we're in here making changes, I strongly recommend that we change the name of this part to "tail", not "id" to help avoid the almost universal confusion between FHIR ids and FHIR canonical urls.

I suggest that we deprecate getIdPart() and that we introduce getTail()

}

@Nonnull
private static Library validateBundle(
Copy link
Member

Choose a reason for hiding this comment

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

So, I'm not really sure what to do here because this validation will in general fail in ways that it shouldn't because it's not doing version resolution, and I really don't know that we should be doing version resolution here as part of validation.

If you have a version-less reference from a measure, it's not wrong for there to be multiple versions of that library on the server, the version-less reference should resolve to the latest.

If you have a versioned reference from a measure, then it should only resolve to that version of the library.

But.... putting that logic here means that we're making decisions about how to do version selection as part of this validation. Seems wrong to me.

I think all we ought to be saying here is:

  1. If the reference from the measure is version less, then any library that matches that url, regardless of version, is valid.
  2. If the reference from the measure is versioned, then only a library matching that url and version is valid.

Copy link
Member

Choose a reason for hiding this comment

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

But then... in the case of a versionless reference do you validate each possible library and make sure that it's name matches it's URL?

@sonarqubecloud
Copy link

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CQL Naming enforcement with Library

3 participants