diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/packaging/Package.java b/tooling/src/main/java/org/opencds/cqf/tooling/packaging/Package.java index b5786ea07..995a4feea 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/packaging/Package.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/packaging/Package.java @@ -79,18 +79,23 @@ public void resolvePrimaryLibraryDependencies(IBaseResource mainArtifact, FhirCo var primaryLibrary = IOUtils.getLibraryUrlMap(fhirContext).get( ResourceUtils.getPrimaryLibraryUrl(mainArtifact, fhirContext)); if (getPrimaryLibrary() == null) { // we want to save the primary library for the artifact being bundled not dependency libraries + if (primaryLibrary == null && mainArtifact.getIdElement() != null && mainArtifact.getIdElement().getValue() != null) { + logger.warn("Unable to resolve primary library for artifact {}", mainArtifact.getIdElement().getValue()); + } setPrimaryLibrary(primaryLibrary); } var missingDependencies = new HashSet(); if (includeDependencies) { - dependencies.add(primaryLibrary); - var dependencyLibraries = ResourceUtils.getDepLibraryResources( - primaryLibrary, fhirContext, true, false, missingDependencies); - dependencies.addAll(dependencyLibraries.values()); + if (primaryLibrary != null) { + dependencies.add(primaryLibrary); + var dependencyLibraries = ResourceUtils.getDepLibraryResources( + primaryLibrary, fhirContext, true, false, missingDependencies); + dependencies.addAll(dependencyLibraries.values()); + } } - if (includeTerminology) { + if (includeTerminology && primaryLibrary != null) { var dependencyValueSets = ResourceUtils.getDepValueSetResources( primaryLibrary, fhirContext, true, missingDependencies); dependencies.addAll(dependencyValueSets.values()); diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/packaging/r4/PackageMeasure.java b/tooling/src/main/java/org/opencds/cqf/tooling/packaging/r4/PackageMeasure.java index 77df4f66f..ef31c4fac 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/packaging/r4/PackageMeasure.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/packaging/r4/PackageMeasure.java @@ -116,7 +116,9 @@ public void output() { measureId + "-files"); IOUtils.initializeDirectory(measureFilesOutputPath); IOUtils.writeResource(mainArtifact, measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext()); - IOUtils.writeResource(getPrimaryLibrary(), measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext()); + if (getPrimaryLibrary() != null) { + IOUtils.writeResource(getPrimaryLibrary(), measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext()); + } // TODO: Is this correct? Do we just exclude the dependencies from the bundle? if (isIncludeDependencies()) { @@ -134,9 +136,11 @@ public void output() { measureFilesOutputPath, IOUtils.Encoding.JSON, getFhirContext(), valueSetDependencyBundleId); } - var cqlFileOutputPath = IOUtils.concatFilePath(measureFilesOutputPath, - ((Library) getPrimaryLibrary()).getIdPart() + ".cql"); - IOUtils.writeCqlToFile(ResourceUtils.getCqlFromR4Library((Library) getPrimaryLibrary()), cqlFileOutputPath); + if (getPrimaryLibrary() != null) { + var cqlFileOutputPath = IOUtils.concatFilePath(measureFilesOutputPath, + ((Library) getPrimaryLibrary()).getIdPart() + ".cql"); + IOUtils.writeCqlToFile(ResourceUtils.getCqlFromR4Library((Library) getPrimaryLibrary()), cqlFileOutputPath); + } if (isIncludeTests() && testPackage != null) { logger.info("Packaging {} Tests...", testPackage.getTests().size());