From 682a590761896923d9d89a824537ee223c68f60c Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 6 Jan 2025 11:00:24 +1100 Subject: [PATCH 1/2] Add archetype processing, and also path-other support --- .../igtools/openehr/ArchetypeImporter.java | 84 +++++++++++++++-- .../hl7/fhir/igtools/openehr/OpenEHRTest.java | 5 +- .../hl7/fhir/igtools/publisher/Publisher.java | 92 +++++++++++++++++-- .../fhir/igtools/publisher/SimpleFetcher.java | 40 ++++++-- .../publisher/loaders/PublisherLoader.java | 8 ++ .../StructureDefinitionRenderer.java | 4 + pom.xml | 2 +- 7 files changed, 212 insertions(+), 23 deletions(-) diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java index 5ae9f245b..4ec8b780b 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java @@ -11,6 +11,7 @@ import javax.xml.parsers.ParserConfigurationException; +import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.Bundle; import org.hl7.fhir.r5.model.Bundle.BundleType; @@ -36,6 +37,7 @@ import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r5.utils.ToolingExtensions; +import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.xml.XMLUtil; import org.openehr.referencemodels.BuiltinReferenceModels; @@ -72,23 +74,89 @@ public class ArchetypeImporter { private StructureDefinition sd; private Bundle bnd; - protected ArchetypeImporter(IWorkerContext context, String canonicalBase) throws ParserConfigurationException, SAXException, IOException { + public static class ProcessedArchetype { + private Archetype archetype; + private StructureDefinition sd; + private Bundle bnd; + private String source; + protected ProcessedArchetype(String source, Archetype archetype, Bundle bnd, StructureDefinition sd) { + super(); + this.source = source; + this.archetype = archetype; + this.sd = sd; + this.bnd = bnd; + } + public String getSource() { + return source; + } + public Archetype getArchetype() { + return archetype; + } + public StructureDefinition getSd() { + return sd; + } + public Bundle getBnd() { + return bnd; + } + + } + public ArchetypeImporter(IWorkerContext context, String canonicalBase) throws ParserConfigurationException, SAXException, IOException { super(); this.context = context; this.canonicalBase = canonicalBase; // todo: check openehr-base is loaded, and if it's not, load it // todo: load this from the context.binaries - terminology = XMLUtil.parseFileToDom("/Users/grahamegrieve/Downloads/openehr_terminology.xml").getDocumentElement(); + byte[] tf = context.getBinaryForKey("openehr_terminology.xml"); + if (tf == null) { + // hack temp workaround + tf = TextFile.fileToBytes("/Users/grahamegrieve/Downloads/openehr_terminology.xml"); + } + terminology = XMLUtil.parseToDom(tf).getDocumentElement(); } - public Bundle importArchetype(byte[] content, boolean adl14) throws ParserConfigurationException, SAXException, IOException, ADLParseException { - return importArchetype(new ByteArrayInputStream(content), adl14); + + public void checkArchetype(byte[] content, String name) throws ParserConfigurationException, SAXException, IOException, ADLParseException { + checkArchetype(new ByteArrayInputStream(content), name); + } + + public void checkArchetype(InputStream stream, String name) throws ParserConfigurationException, SAXException, IOException, ADLParseException { + byte[] cnt = TextFile.streamToBytes(stream); + try { + archetype = load20(new ByteArrayInputStream(cnt)); + } catch (Exception e20) { + try { + archetype = load14(new ByteArrayInputStream(cnt)); + } catch (Exception e14) { + if (e20.getMessage().equals(e14.getMessage())) { + throw new FHIRException("Error reading "+name+": "+e20.getMessage(), e20); + } else { + throw new FHIRException("Error reading "+name+". ADL 1.4: "+e14.getMessage()+"; ADL 2: "+e20.getMessage(), e20); + } + } + } + } + + public ProcessedArchetype importArchetype(byte[] content, String name) throws ParserConfigurationException, SAXException, IOException, ADLParseException { + return importArchetype(new ByteArrayInputStream(content), name); } - public Bundle importArchetype(InputStream stream, boolean adl14) throws ParserConfigurationException, SAXException, IOException, ADLParseException { + public ProcessedArchetype importArchetype(InputStream stream, String name) throws ParserConfigurationException, SAXException, IOException, ADLParseException { atMap.clear(); - - archetype = adl14 ? load14(stream) : load20(stream); + + byte[] cnt = TextFile.streamToBytes(stream); + try { + archetype = load20(new ByteArrayInputStream(cnt)); + } catch (Exception e20) { + try { + archetype = load14(new ByteArrayInputStream(cnt)); + } catch (Exception e14) { + if (e20.getMessage().equals(e14.getMessage())) { + throw new FHIRException("Error reading "+name+": "+e20.getMessage(), e20); + } else { + throw new FHIRException("Error reading "+name+". ADL 1.4: "+e14.getMessage()+"; ADL 2: "+e20.getMessage(), e20); + } + } + } bnd = new Bundle(); bnd.setType(BundleType.COLLECTION); @@ -148,7 +216,7 @@ public Bundle importArchetype(InputStream stream, boolean adl14) throws ParserCo List defns = sd.getDifferential().getElement(); processDefinition(defns, null, defn, baseType, null, baseType, defn.getNodeId()); - return bnd; + return new ProcessedArchetype(new String(cnt), archetype, bnd, sd); } private Archetype load20(InputStream stream) throws ADLParseException, IOException { diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/OpenEHRTest.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/OpenEHRTest.java index f6af5500f..927c10bb4 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/OpenEHRTest.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/OpenEHRTest.java @@ -6,6 +6,7 @@ import javax.xml.parsers.ParserConfigurationException; +import org.hl7.fhir.igtools.openehr.ArchetypeImporter.ProcessedArchetype; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.model.Bundle; @@ -22,9 +23,9 @@ public static void main(String[] args) throws Exception { public void test() throws FileNotFoundException, ADLParseException, IOException, ParserConfigurationException, SAXException { ArchetypeImporter ai = new ArchetypeImporter(null, "http://openehr.org/fhir/uv/test"); - Bundle bnd = ai.importArchetype(new FileInputStream("/Users/grahamegrieve/Downloads/openEHR-EHR-OBSERVATION.blood_pressure.v2.adl"), true); + ProcessedArchetype pa = ai.importArchetype(new FileInputStream("/Users/grahamegrieve/Downloads/openEHR-EHR-OBSERVATION.blood_pressure.v2.adl"), "openEHR-EHR-OBSERVATION.blood_pressure.v2.adl"); System.out.println(); - String json = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(bnd); + String json = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(pa.getBnd()); TextFile.stringToFile(json, "/Users/grahamegrieve/temp/igs/FHIR-sample-ig#master/input/resources/Bundle-openEHR-EHR-OBSERVATION.blood-pressure.v2.json"); System.out.println("Done"); } diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java index 1511996bf..226b05a28 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java @@ -91,6 +91,8 @@ import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.igtools.openehr.ArchetypeImporter; +import org.hl7.fhir.igtools.openehr.ArchetypeImporter.ProcessedArchetype; import org.hl7.fhir.igtools.publisher.FetchedFile.FetchedBundleType; import org.hl7.fhir.igtools.publisher.IFetchFile.FetchState; import org.hl7.fhir.igtools.publisher.comparators.IpaComparator; @@ -704,6 +706,7 @@ public enum CacheOption { private List pagesDirs = new ArrayList(); private List testDirs = new ArrayList(); private List dataDirs = new ArrayList(); + private List otherDirs = new ArrayList(); private String tempDir; private String tempLangDir; private String outputDir; @@ -2877,6 +2880,9 @@ private void initializeFromIg(IniFile ini) throws Exception { case "path-data": dataDirs.add(Utilities.path(rootDir, p.getValue())); break; + case "path-other": + otherDirs.add(Utilities.path(rootDir, p.getValue())); + break; case "copyrightyear": copyrightYear = p.getValue(); break; @@ -3354,6 +3360,7 @@ else if (vsCache == null) { igpkp.setAutoPath(true); } fetcher.setPkp(igpkp); + fetcher.setContext(context); template.loadSummaryRows(igpkp.summaryRows()); if (VersionUtilities.isR4Plus(version) && !dependsOnExtensions(sourceIg.getDependsOn()) && !sourceIg.getPackageId().contains("hl7.fhir.uv.extensions")) { @@ -5689,16 +5696,73 @@ private boolean loadBundle(String name, boolean needToBuild, FetchedFile igf, St return changed || needToBuild; } + private boolean loadArchetype(FetchedFile f, String cause) throws Exception { + ProcessedArchetype pa = new ArchetypeImporter(context, igpkp.getCanonical()).importArchetype(f.getSource(), f.getName()); + Bundle bnd = pa.getBnd(); + pa.getSd().setUserData(UserDataNames.archetype, pa.getSource()); + + f.setBundle(new FetchedResource(f.getName()+" (bundle)")); + f.setBundleType(FetchedBundleType.NATIVE); + + boolean changed = noteFile("Bundle/"+bnd.getIdBase(), f); + int i = -1; + for (BundleEntryComponent be : bnd.getEntry()) { + i++; + Resource res = be.getResource(); + Element e = new ObjectConverter(context).convert(res); + checkResourceUnique(res.fhirType()+"/"+res.getIdBase(), f.getName(), cause); + FetchedResource r = f.addResource(f.getName()+"["+i+"]"); + r.setElement(e); + r.setResource(res); + r.setId(res.getIdBase()); + + r.setTitle(r.getElement().getChildValue("name")); + igpkp.findConfiguration(f, r); + } + for (FetchedResource r : f.getResources()) { + bndIds.add(r.fhirType()+"/"+r.getId()); + ImplementationGuideDefinitionResourceComponent res = findIGReference(r.fhirType(), r.getId()); + if (res == null) { + res = publishedIg.getDefinition().addResource(); + if (!res.hasName()) + if (r.hasTitle()) + res.setName(r.getTitle()); + else + res.setName(r.getId()); + if (!res.hasDescription() && r.getElement().hasChild("description")) { + res.setDescription(r.getElement().getChildValue("description").trim()); + } + res.setReference(new Reference().setReference(r.fhirType()+"/"+r.getId())); + } + res.setUserData(UserDataNames.pub_loaded_resource, r); + r.setResEntry(res); + if (r.getResource() instanceof CanonicalResource) { + CanonicalResource cr = (CanonicalResource)r.getResource(); + if (!canonicalResources.containsKey(cr.getUrl())) { + canonicalResources.put(cr.getUrl(), r); + if (cr.hasVersion()) + canonicalResources.put(cr.getUrl()+"#"+cr.getVersion(), r); + } + } + } + return changed; + } + private boolean loadResources(boolean needToBuild, FetchedFile igf) throws Exception { // igf is not currently used, but it was about relative references? List resources = fetcher.scan(sourceDir, context, igpkp.isAutoPath()); for (FetchedFile ff : resources) { ff.start("loadResources"); - try { - if (!ff.matches(igf) && !isBundle(ff)) { - needToBuild = loadResource(needToBuild, ff, "scan folder "+Utilities.getDirectoryForFile(ff.getStatedPath())); + if (ff.getContentType().equals("adl")) { + loadArchetype(ff, "scan folder "+Utilities.getDirectoryForFile(ff.getStatedPath())); + needToBuild = true; + } else { + try { + if (!ff.matches(igf) && !isBundle(ff)) { + needToBuild = loadResource(needToBuild, ff, "scan folder "+Utilities.getDirectoryForFile(ff.getStatedPath())); + } + } finally { + ff.finish("loadResources"); } - } finally { - ff.finish("loadResources"); } } return needToBuild; @@ -6630,7 +6694,7 @@ private ImplementationGuideDefinitionResourceComponent findIGReference(String ty } return null; } - + private Element loadFromMap(FetchedFile file) throws Exception { if (!VersionUtilities.isR4Plus(context.getVersion())) { throw new Error("Loading Map Files is not supported for version "+VersionUtilities.getNameForVersion(context.getVersion())); @@ -8083,6 +8147,18 @@ private void generate() throws Exception { for (String t : testDirs) { addTestDir(new File(t), t); } + for (String n : otherDirs) { + File f = new File(n); + if (f.exists()) { + for (File ff : f.listFiles()) { + if (!SimpleFetcher.isIgnoredFile(f.getName())) { + npm.addFile(Category.OTHER, ff.getName(), TextFile.fileToBytes(ff.getAbsolutePath())); + } + } + } else { + logMessage("Other Directory not found: "+n); + } + } npm.finish(); if (r4tor4b.canBeR4() && r4tor4b.canBeR4B()) { try { @@ -13172,6 +13248,10 @@ private void generateOutputsStructureDefinition(FetchedFile f, FetchedResource r fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-eview"+langSfx, sdr.eview(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, false), f.getOutputNames(), r, vars, null, start, "eview", "StructureDefinition"); fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-eview-all"+langSfx, sdr.eview(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, true), f.getOutputNames(), r, vars, null, start, "eview", "StructureDefinition"); } + if (igpkp.wantGen(r, "adl") && sd.hasUserData(UserDataNames.archetype)) { + long start = System.currentTimeMillis(); + fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-adl"+langSfx, sdr.adl(), f.getOutputNames(), r, vars, null, start, "adl", "StructureDefinition"); + } if (igpkp.wantGen(r, "diff")) { long start = System.currentTimeMillis(); fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-diff"+langSfx, sdr.diff(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, false), f.getOutputNames(), r, vars, null, start, "diff", "StructureDefinition"); diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/SimpleFetcher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/SimpleFetcher.java index c9353a9fb..3f2802c16 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/SimpleFetcher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/SimpleFetcher.java @@ -32,12 +32,14 @@ import java.util.List; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.igtools.openehr.ArchetypeImporter; import org.hl7.fhir.r5.context.ILoggingService; import org.hl7.fhir.r5.context.ILoggingService.LogCategory; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.elementmodel.FmlParser; import org.hl7.fhir.r5.elementmodel.ValidatedFragment; import org.hl7.fhir.r5.formats.FormatUtilities; +import org.hl7.fhir.r5.model.Bundle; import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.DataType; import org.hl7.fhir.r5.model.Reference; @@ -59,6 +61,7 @@ public int compare(FetchedFile o1, FetchedFile o2) { private static final String[] EXTENSIONS = new String[] {".xml", ".json", ".map", ".fml", ".phinvads"}; private IGKnowledgeProvider pkp; + private IWorkerContext context; private List resourceDirs; private ILoggingService log; private String rootDir; @@ -81,6 +84,14 @@ public void setPkp(IGKnowledgeProvider pkp) { this.pkp = pkp; } + public IWorkerContext getContext() { + return context; + } + + public void setContext(IWorkerContext context) { + this.context = context; + } + public String getRootDir() { return rootDir; } @@ -124,7 +135,7 @@ public FetchedFile fetch(String path) throws Exception { return ff; } - private boolean isIgnoredFile(String name) { + public static boolean isIgnoredFile(String name) { return name.startsWith(".") || Utilities.existsInList(Utilities.getFileExtension(name), "ini"); } @@ -351,7 +362,7 @@ public List scan(String sourceDir, IWorkerContext context, boolean } } } - if (!ok && !Utilities.existsInList(ext, "xml", "ttl", "html", "txt", "fml")) { + if (!ok && !Utilities.existsInList(ext, "xml", "ttl", "html", "txt", "fml", "adl")) { try { List el = new org.hl7.fhir.r5.elementmodel.JsonParser(context).parse(new FileInputStream(fn)); if (el.size() == 1) { @@ -370,7 +381,7 @@ public List scan(String sourceDir, IWorkerContext context, boolean } } } - if (!ok && !Utilities.existsInList(ext, "json", "xml", "html", "txt", "fml")) { + if (!ok && !Utilities.existsInList(ext, "json", "xml", "html", "txt", "fml", "adl")) { try { org.hl7.fhir.r5.elementmodel.Element e = new org.hl7.fhir.r5.elementmodel.TurtleParser(context).parseSingle(new FileInputStream(fn), null); addFile(res, f, e, "application/fhir+turtle"); @@ -388,7 +399,7 @@ public List scan(String sourceDir, IWorkerContext context, boolean } } } - if (!ok && !Utilities.existsInList(ext, "json", "xml", "html", "txt")) { + if (!ok && !Utilities.existsInList(ext, "json", "xml", "html", "txt", "adl")) { try { if (fp==null) { fp = new FmlParser(context); @@ -397,6 +408,23 @@ public List scan(String sourceDir, IWorkerContext context, boolean addFile(res, f, e, "fml"); count++; ok = true; + } catch (Exception e) { + if (!f.getName().startsWith("Binary-")) { // we don't notify here because Binary is special. + if (report) { + log.logMessage("ADL Error loading "+f+": "+e.getMessage()); + if (debug) { + e.printStackTrace(); + } + } + } + } + } + if (!ok && !Utilities.existsInList(ext, "json", "xml", "html", "txt", "ttl")) { + try { + new ArchetypeImporter(context, pkp.getCanonical()).checkArchetype(new FileInputStream(f), f.getName()); + addFile(res, f, null, "adl"); + count++; + ok = true; } catch (Exception e) { if (!f.getName().startsWith("Binary-")) { // we don't notify here because Binary is special. if (report) { @@ -421,14 +449,14 @@ public List scan(String sourceDir, IWorkerContext context, boolean private List fixedFileTypes() { return Utilities.strings( // known file types we have parsers for - "json", "ttl", "html", "txt", "fml", + "json", "ttl", "html", "txt", "fml", "adl", // known files types to not even try parsing "jpg", "png", "gif", "mp3", "mp4", "pfd", "doc", "docx", "ppt", "pptx", "svg"); } private void addFile(List res, File f, org.hl7.fhir.r5.elementmodel.Element e, String cnt) throws IOException { - if (!e.fhirType().equals("ImplementationGuide") && !(f.getName().startsWith("Binary") && !"Binary".equals(e.fhirType()))) { + if (( e == null || !e.fhirType().equals("ImplementationGuide")) && !(f.getName().startsWith("Binary") && !"Binary".equals(e.fhirType()))) { addFile(res, f, cnt); } } diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/PublisherLoader.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/PublisherLoader.java index 568102aa7..9e9e3e633 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/PublisherLoader.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/PublisherLoader.java @@ -16,7 +16,9 @@ import org.hl7.fhir.igtools.publisher.SpecMapManager.SpecialPackageType; import org.hl7.fhir.r5.context.IContextResourceLoader; import org.hl7.fhir.r5.model.CanonicalResource; +import org.hl7.fhir.r5.model.DomainResource; import org.hl7.fhir.r5.model.Resource; +import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.UserDataNames; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; @@ -106,6 +108,12 @@ private String getIgPath(Resource r) { } else { path = pathToSpec+"/"+ igpkp.doReplacements(p, r, null, null); } + if (r instanceof DomainResource) { + DomainResource dr = (DomainResource) r; + if (dr.hasExtension(ToolingExtensions.EXT_WEB_SOURCE)) { + path = ToolingExtensions.readStringExtension(dr, ToolingExtensions.EXT_WEB_SOURCE); + } + } r.setWebPath(path); if (path.contains("vsac")) { r.setUserData(UserDataNames.render_external_link, "https://vsac.nlm.nih.gov"); diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java index 3af0e798a..044dd05f5 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java @@ -2567,4 +2567,8 @@ public String experimentalWarning() { return ""; } } + + public String adl() { + return "
"+Utilities.escapeXml(sd.getUserString(UserDataNames.archetype))+"
"; + } } diff --git a/pom.xml b/pom.xml index 89563464c..f5f98e6a9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ pom - 6.5.4 + 6.5.5-SNAPSHOT 3.0.0-M5 5.2.1 1.18.32 From 1b9d4f752380994fc9dba067287687cae5ac017f Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 6 Jan 2025 13:52:34 +1100 Subject: [PATCH 2/2] Process Archetypes properly as both IG input and output + remove ig-r4.json --- .../igtools/openehr/ArchetypeImporter.java | 10 ++++++++-- .../igtools/publisher/IGPack2NpmConvertor.java | 4 +--- .../hl7/fhir/igtools/publisher/Publisher.java | 18 +++++++++--------- .../igtools/publisher/R4ToR4BAnalyser.java | 2 -- .../renderers/StructureDefinitionRenderer.java | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java index 4ec8b780b..d5b252e23 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/openehr/ArchetypeImporter.java @@ -79,9 +79,12 @@ public static class ProcessedArchetype { private StructureDefinition sd; private Bundle bnd; private String source; - protected ProcessedArchetype(String source, Archetype archetype, Bundle bnd, StructureDefinition sd) { + private String sourceName; + + protected ProcessedArchetype(String source,String sourceName, Archetype archetype, Bundle bnd, StructureDefinition sd) { super(); this.source = source; + this.sourceName = sourceName; this.archetype = archetype; this.sd = sd; this.bnd = bnd; @@ -89,6 +92,9 @@ protected ProcessedArchetype(String source, Archetype archetype, Bundle bnd, St public String getSource() { return source; } + public String getSourceName() { + return sourceName; + } public Archetype getArchetype() { return archetype; } @@ -216,7 +222,7 @@ public ProcessedArchetype importArchetype(InputStream stream, String name) throw List defns = sd.getDifferential().getElement(); processDefinition(defns, null, defn, baseType, null, baseType, defn.getNodeId()); - return new ProcessedArchetype(new String(cnt), archetype, bnd, sd); + return new ProcessedArchetype(new String(cnt), name, archetype, bnd, sd); } private Archetype load20(InputStream stream) throws ADLParseException, IOException { diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/IGPack2NpmConvertor.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/IGPack2NpmConvertor.java index 5b4b807d9..91732f336 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/IGPack2NpmConvertor.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/IGPack2NpmConvertor.java @@ -216,9 +216,7 @@ private void processValidatorPack(File f) throws IOException { String destFile = dest != null ? dest : Utilities.path(Utilities.getDirectoryForFile(f.getAbsolutePath()), "package.tgz"); String url = Utilities.noString(website) ? canonical : website; NPMPackageGenerator npm = new NPMPackageGenerator(destFile, canonical, url, PackageType.IG, ig, new Date(), false); - ByteArrayOutputStream bs = new ByteArrayOutputStream(); - new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(bs, ig); - npm.addFile(Category.OTHER, "ig-r4.jsonX", bs.toByteArray()); + npm.addFile(Category.RESOURCE, "ImplementationGuide-"+ig.getId()+".json", compose(ig, version)); diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java index 226b05a28..c4f41a28c 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java @@ -5697,9 +5697,10 @@ private boolean loadBundle(String name, boolean needToBuild, FetchedFile igf, St } private boolean loadArchetype(FetchedFile f, String cause) throws Exception { - ProcessedArchetype pa = new ArchetypeImporter(context, igpkp.getCanonical()).importArchetype(f.getSource(), f.getName()); + ProcessedArchetype pa = new ArchetypeImporter(context, igpkp.getCanonical()).importArchetype(f.getSource(), new File(f.getStatedPath()).getName()); Bundle bnd = pa.getBnd(); - pa.getSd().setUserData(UserDataNames.archetype, pa.getSource()); + pa.getSd().setUserData(UserDataNames.archetypeSource, pa.getSource()); + pa.getSd().setUserData(UserDataNames.archetypeName, pa.getSourceName()); f.setBundle(new FetchedResource(f.getName()+" (bundle)")); f.setBundleType(FetchedBundleType.NATIVE); @@ -8415,11 +8416,7 @@ private void updateImplementationGuide() throws Exception { } r.setResource(publishedIg); r.setElement(convertToElement(r, publishedIg)); - - ByteArrayOutputStream bs = new ByteArrayOutputStream(); - new org.hl7.fhir.r4.formats.JsonParser().compose(bs, VersionConvertorFactory_40_50.convertResource(publishedIg)); - npm.addFile(Category.OTHER, "ig-r4.jsonX", bs.toByteArray()); - + for (ImplementationGuideDefinitionResourceComponent res : publishedIg.getDefinition().getResource()) { FetchedResource rt = null; for (FetchedFile tf : fileList) { @@ -12411,7 +12408,10 @@ private byte[] saveNativeResourceOutputs(FetchedFile f, FetchedResource r) throw Element eNN = element; jp.compose(element, bsj, OutputStyle.NORMAL, igpkp.getCanonical()); if (!r.isCustomResource()) { - npm.addFile(isExample(f,r ) ? Category.EXAMPLE : Category.RESOURCE, element.fhirType()+"-"+r.getId()+".json", bsj.toByteArray()); + npm.addFile(isExample(f,r ) ? Category.EXAMPLE : Category.RESOURCE, element.fhirType()+"-"+r.getId()+".json", bsj.toByteArray()); + if (r.getResource() != null && r.getResource().hasUserData(UserDataNames.archetypeSource)) { + npm.addFile(Category.ADL, r.getResource().getUserString(UserDataNames.archetypeName), r.getResource().getUserString(UserDataNames.archetypeSource).getBytes(StandardCharsets.UTF_8)); + } } else if ("StructureDefinition".equals(r.fhirType())) { npm.addFile(Category.RESOURCE, element.fhirType()+"-"+r.getId()+".json", bsj.toByteArray()); StructureDefinition sdt = (StructureDefinition) r.getResource().copy(); @@ -13248,7 +13248,7 @@ private void generateOutputsStructureDefinition(FetchedFile f, FetchedResource r fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-eview"+langSfx, sdr.eview(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, false), f.getOutputNames(), r, vars, null, start, "eview", "StructureDefinition"); fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-eview-all"+langSfx, sdr.eview(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, true), f.getOutputNames(), r, vars, null, start, "eview", "StructureDefinition"); } - if (igpkp.wantGen(r, "adl") && sd.hasUserData(UserDataNames.archetype)) { + if (igpkp.wantGen(r, "adl") && sd.hasUserData(UserDataNames.archetypeSource)) { long start = System.currentTimeMillis(); fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-adl"+langSfx, sdr.adl(), f.getOutputNames(), r, vars, null, start, "adl", "StructureDefinition"); } diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/R4ToR4BAnalyser.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/R4ToR4BAnalyser.java index 565567f32..73a7eaac4 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/R4ToR4BAnalyser.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/R4ToR4BAnalyser.java @@ -467,8 +467,6 @@ private void processFileSame(NPMPackageGenerator gen, String folder, String file // System.out.println("** Exclude "+res.fhirType()+"/"+res.getId()+" from same version"); } } - } else if (filename.equals("ig-r4.json") || filename.equals("ig-r4.jsonX")) { - gen.addFile(folder, filename, updateIGR4(content, ver, pver)); } else if (filename.equals("spec.internals")) { gen.addFile(folder, filename, updateSpecInternals(content, ver, pver)); } else { diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java index 044dd05f5..6b2bc332d 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/renderers/StructureDefinitionRenderer.java @@ -2569,6 +2569,6 @@ public String experimentalWarning() { } public String adl() { - return "
"+Utilities.escapeXml(sd.getUserString(UserDataNames.archetype))+"
"; + return "
"+Utilities.escapeXml(sd.getUserString(UserDataNames.archetypeSource))+"
"; } }