From b9d2579d745d3c8e1823bc0cd17ccec6a44ebf2b Mon Sep 17 00:00:00 2001 From: Bryn Rhodes Date: Fri, 14 Aug 2020 11:09:10 -0600 Subject: [PATCH 1/2] #110: Add library stub generation to the library refresh process. --- .../cqf/tooling/processor/CqlProcessor.java | 16 +++++++++++++ .../tooling/processor/LibraryProcessor.java | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/main/java/org/opencds/cqf/tooling/processor/CqlProcessor.java b/src/main/java/org/opencds/cqf/tooling/processor/CqlProcessor.java index ba1bc96f3..55f4ddc54 100644 --- a/src/main/java/org/opencds/cqf/tooling/processor/CqlProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/processor/CqlProcessor.java @@ -30,12 +30,19 @@ public class CqlProcessor { * information about a cql file */ public class CqlSourceFileInformation { + private VersionedIdentifier identifier; private byte[] elm; private byte[] jsonElm; private List errors = new ArrayList<>(); private List relatedArtifacts = new ArrayList<>(); private List dataRequirements = new ArrayList<>(); private List parameters = new ArrayList<>(); + public VersionedIdentifier getIdentifier() { + return identifier; + } + public void setIdentifier(VersionedIdentifier identifier) { + this.identifier = identifier; + } public byte[] getElm() { return elm; } @@ -168,6 +175,14 @@ public CqlSourceFileInformation getFileInformation(String filename) { return this.fileMap.remove(filename); } + public Collection getAllFileInformation() { + if (fileMap == null) { + throw new IllegalStateException("CQL File map is not available, execute has not been called"); + } + + return this.fileMap.values(); + } + /** * Called at the end after all getFileInformation have been called * return any errors that didn't have any particular home, and also @@ -306,6 +321,7 @@ private void translateFile(ModelManager modelManager, LibraryManager libraryMana // convert to base64 bytes // NOTE: Publication tooling requires XML content result.setElm(translator.toXml().getBytes()); + result.setIdentifier(translator.toELM().getIdentifier()); if (options.getFormats().contains(CqlTranslator.Format.JSON)) { result.setJsonElm(translator.toJson().getBytes()); } diff --git a/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java b/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java index 3d6940487..33191c9ce 100644 --- a/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java @@ -164,6 +164,30 @@ protected List refreshGeneratedContent(List sourceLibraries) { cqlProcessor.execute(); + // For each CQL file, ensure that there is a Library resource with a matching name and version + for (CqlProcessor.CqlSourceFileInformation fileInfo : cqlProcessor.getAllFileInformation()) { + if (fileInfo.getIdentifier() != null && fileInfo.getIdentifier().getId() != null && !fileInfo.getIdentifier().getId().equals("")) { + Library existingLibrary = null; + for (Library sourceLibrary : sourceLibraries) { + if (fileInfo.getIdentifier().getId().equals(sourceLibrary.getName()) + && (fileInfo.getIdentifier().getVersion() == null || fileInfo.getIdentifier().getVersion().equals(sourceLibrary.getVersion())) + ) { + existingLibrary = sourceLibrary; + break; + } + } + + if (existingLibrary == null) { + Library newLibrary = new Library(); + newLibrary.setId(fileInfo.getIdentifier().getId()); + newLibrary.setName(fileInfo.getIdentifier().getId()); + newLibrary.setVersion(fileInfo.getIdentifier().getVersion()); + newLibrary.setUrl(String.format("%s/Library/%s", canonicalBase, fileInfo.getIdentifier().getId())); + sourceLibraries.add(newLibrary); + } + } + } + List resources = new ArrayList(); for (Library library : sourceLibraries) { resources.add(refreshGeneratedContent(library)); From fe98132c88779f9fcc2ddff616a34f6c951cf94c Mon Sep 17 00:00:00 2001 From: rob-reynolds <4z&ChMu6yGn%IL> Date: Fri, 14 Aug 2020 17:23:43 -0600 Subject: [PATCH 2/2] Format library id so that it doesn't skip processing Set library filePath in the case the file doesn't exist --- .../cqf/tooling/processor/LibraryProcessor.java | 5 ++--- .../cqf/tooling/processor/MeasureProcessor.java | 1 + .../tooling/processor/R4LibraryProcessor.java | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java b/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java index 33191c9ce..f22a108a2 100644 --- a/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/processor/LibraryProcessor.java @@ -57,7 +57,6 @@ public static List refreshIgLibraryContent(BaseProcessor parentContext, params.fhirContext = fhirContext; params.encoding = outputEncoding; params.versioned = versioned; - params.libraryPath = libraryPath; return libraryProcessor.refreshLibraryContent(params); } @@ -179,10 +178,10 @@ protected List refreshGeneratedContent(List sourceLibraries) { if (existingLibrary == null) { Library newLibrary = new Library(); - newLibrary.setId(fileInfo.getIdentifier().getId()); newLibrary.setName(fileInfo.getIdentifier().getId()); newLibrary.setVersion(fileInfo.getIdentifier().getVersion()); - newLibrary.setUrl(String.format("%s/Library/%s", canonicalBase, fileInfo.getIdentifier().getId())); + newLibrary.setUrl(String.format("%s/Library/%s", (newLibrary.getName().equals("FHIRHelpers") ? "http://hl7.org/fhir" : canonicalBase), fileInfo.getIdentifier().getId())); + newLibrary.setId(LibraryProcessor.getId(newLibrary.getName()) + (versioned ? "-" + newLibrary.getVersion() : "")); sourceLibraries.add(newLibrary); } } diff --git a/src/main/java/org/opencds/cqf/tooling/processor/MeasureProcessor.java b/src/main/java/org/opencds/cqf/tooling/processor/MeasureProcessor.java index e2b9d126d..74b284969 100644 --- a/src/main/java/org/opencds/cqf/tooling/processor/MeasureProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/processor/MeasureProcessor.java @@ -107,6 +107,7 @@ public static void bundleMeasures(ArrayList refreshedLibraryNames, Strin if (path.endsWith(refreshedLibraryFileName)) { measureSourcePath = path; + break; } } diff --git a/src/main/java/org/opencds/cqf/tooling/processor/R4LibraryProcessor.java b/src/main/java/org/opencds/cqf/tooling/processor/R4LibraryProcessor.java index 35945eada..2424c6ee5 100644 --- a/src/main/java/org/opencds/cqf/tooling/processor/R4LibraryProcessor.java +++ b/src/main/java/org/opencds/cqf/tooling/processor/R4LibraryProcessor.java @@ -43,7 +43,7 @@ public class R4LibraryProcessor extends LibraryProcessor { /* Refresh all library resources in the given libraryPath */ - protected List refreshLibraries(String libraryPath) { + protected List refreshLibraries(String libraryPath, Encoding encoding) { File file = new File(libraryPath); Map fileMap = new HashMap(); List libraries = new ArrayList<>(); @@ -76,10 +76,19 @@ protected List refreshLibraries(String libraryPath) { List refreshedLibraryNames = new ArrayList(); List refreshedLibraries = super.refreshGeneratedContent(libraries); for (org.hl7.fhir.r5.model.Library refreshedLibrary : refreshedLibraries) { - String filePath = fileMap.get(refreshedLibrary.getId()); Library library = (Library) VersionConvertor_40_50.convertResource(refreshedLibrary); + String filePath = null; + Encoding fileEncoding = null; + if (fileMap.containsKey(refreshedLibrary.getId())) + { + filePath = fileMap.get(refreshedLibrary.getId()); + fileEncoding = IOUtils.getEncoding(filePath); + } else { + filePath = libraryPath; + fileEncoding = encoding; + } cqfmHelper.ensureToolingExtensionAndDevice(library, fhirContext); - IOUtils.writeResource(library, filePath, IOUtils.getEncoding(filePath), fhirContext); + IOUtils.writeResource(library, filePath, fileEncoding, fhirContext); refreshedLibraryNames.add(refreshedLibrary.getName()); } @@ -102,7 +111,7 @@ public List refreshLibraryContent(RefreshLibraryParameters params) { encoding = params.encoding; versioned = params.versioned; - return refreshLibraries(libraryPath); + return refreshLibraries(libraryPath, encoding); /* CqlTranslator translator = getTranslator(cqlContentPath);