Skip to content

Commit

Permalink
Merge pull request #257 from DBCG/fix-251-primary-library-resolution
Browse files Browse the repository at this point in the history
#251: Fixed primary library resolution incorrectly using id in some c…
  • Loading branch information
JPercival authored Oct 3, 2020
2 parents 38092eb + 6c47b10 commit 53c0e51
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions r4/src/main/java/org/opencds/cqf/r4/helpers/LibraryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,30 @@ public static LibraryLoader createLibraryLoader(org.cqframework.cql.cql2elm.Libr
return new LibraryLoader(libraryManager, modelManager);
}

public static org.hl7.fhir.r4.model.Library resolveLibraryReference(LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider, String reference) {
// Raw references to Library/libraryId or libraryId
if (reference.startsWith("Library/") || !reference.contains("/")) {
return libraryResourceProvider.resolveLibraryById(reference.replace("Library/", ""));
}
// Full url (e.g. http://hl7.org/fhir/us/Library/FHIRHelpers)
else if (reference.contains(("/Library/"))) {
return libraryResourceProvider.resolveLibraryByCanonicalUrl(reference);
}

return null;
}

public static List<org.cqframework.cql.elm.execution.Library> loadLibraries(Measure measure,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<org.cqframework.cql.elm.execution.Library>();

// load libraries
//TODO: if there's a bad measure argument, this blows up for an obscure error
org.hl7.fhir.r4.model.Library primaryLibrary = null;
for (CanonicalType ref : measure.getLibrary()) {
// if library is contained in measure, load it into server
String id = CanonicalHelper.getId(ref);
String id = ref.getValue(); //CanonicalHelper.getId(ref);
if (id.startsWith("#")) {
id = id.substring(1);
for (Resource resource : measure.getContained()) {
Expand All @@ -60,7 +74,11 @@ public static List<org.cqframework.cql.elm.execution.Library> loadLibraries(Meas
}

// We just loaded it into the server so we can access it by Id
org.hl7.fhir.r4.model.Library library = libraryResourceProvider.resolveLibraryById(id);
org.hl7.fhir.r4.model.Library library = resolveLibraryReference(libraryResourceProvider, id);
if (primaryLibrary == null) {
primaryLibrary = library;
}

if (library != null && isLogicLibrary(library)) {
libraries.add(
libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))
Expand All @@ -73,19 +91,12 @@ public static List<org.cqframework.cql.elm.execution.Library> loadLibraries(Meas
.format("Could not load library source for libraries referenced in Measure/%s.", measure.getId()));
}

VersionedIdentifier primaryLibraryId = libraries.get(0).getIdentifier();
org.hl7.fhir.r4.model.Library primaryLibrary = libraryResourceProvider.resolveLibraryByName(primaryLibraryId.getId(), primaryLibraryId.getVersion());
//VersionedIdentifier primaryLibraryId = libraries.get(0).getIdentifier();
//org.hl7.fhir.r4.model.Library primaryLibrary = libraryResourceProvider.resolveLibraryByName(primaryLibraryId.getId(), primaryLibraryId.getVersion());
for (RelatedArtifact artifact : primaryLibrary.getRelatedArtifact()) {
if (artifact.hasType() && artifact.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON) && artifact.hasResource()) {
org.hl7.fhir.r4.model.Library library = null;
// Raw references to Library/libraryId or libraryId
if (artifact.getResource().startsWith("Library/") || ! artifact.getResource().contains("/")) {
library = libraryResourceProvider.resolveLibraryById(artifact.getResource().replace("Library/", ""));
}
// Full url (e.g. http://hl7.org/fhir/us/Library/FHIRHelpers)
else if (artifact.getResource().contains(("/Library/"))) {
library = libraryResourceProvider.resolveLibraryByCanonicalUrl(artifact.getResource());
}
library = resolveLibraryReference(libraryResourceProvider, artifact.getResource());

if (library != null && isLogicLibrary(library)) {
libraries.add(
Expand Down

0 comments on commit 53c0e51

Please sign in to comment.