From 78f6a1656b4987dbdcf32b0226183143a6cf0cc8 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 19 Mar 2024 20:50:55 +1100 Subject: [PATCH 1/2] Fix narrative generation --- .../hl7/fhir/tools/publisher/Publisher.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/hl7/fhir/tools/publisher/Publisher.java b/src/main/java/org/hl7/fhir/tools/publisher/Publisher.java index 3104c8f..8f6db9c 100644 --- a/src/main/java/org/hl7/fhir/tools/publisher/Publisher.java +++ b/src/main/java/org/hl7/fhir/tools/publisher/Publisher.java @@ -824,6 +824,7 @@ public void execute(String folder, String[] args) throws IOException { if (isGenerate && buildFlags.get("all")) produceQA(); + page.log("Max Memory Used = "+Utilities.describeSize(page.getMaxMemory()), LogMessageType.Process); if (!buildFlags.get("all")) { page.log("This was a Partial Build", LogMessageType.Process); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); @@ -1871,13 +1872,13 @@ private void addTypes(CodeSystem cs, StructureDefinition sd, List", "").trim(); - e.setElement(new Manager().parseSingle(page.getWorkerContext(), new StringInputStream(xml), FhirFormat.XML)); - e.setResource(new XmlParser().parse(xml)); - } } catch (Throwable ex) { StringWriter errors = new StringWriter(); System.out.println("Error generating narrative for example "+e.getName()+": "+ex.getMessage()); -// ex.printStackTrace(); + ex.printStackTrace(); XhtmlNode xhtml = new XhtmlNode(NodeType.Element, "div"); xhtml.addTag("p").setAttribute("style", "color: maroon").addText("Error processing narrative: " + ex.getMessage()); xhtml.addTag("p").setAttribute("style", "color: maroon").addText(errors.toString()); narrative = new XhtmlComposer(XhtmlComposer.HTML).compose(xhtml); } - + try { + if (e.getResource() == null && e.getElement() == null) { + String xml = XMLUtil.elementToString(e.getXml().getDocumentElement()).replace("", "").trim(); + e.setElement(new Manager().parseSingle(page.getWorkerContext(), new StringInputStream(xml), FhirFormat.XML)); + e.setResource(new XmlParser().parse(xml)); + } + } catch (Throwable ex) { + System.out.println("Error reparsing example "+e.getName()+": "+ex.getMessage()); + } if (rt.equals("ValueSet")) { try { ValueSet vs = (ValueSet) loadExample(file); From b88bc8b68192882020c791822a519ec38212e0b0 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 19 Mar 2024 20:51:46 +1100 Subject: [PATCH 2/2] Fix problems loading packages that are now R5 not R4 + upgrade core --- build.gradle.kts | 2 +- gradle.properties | 2 +- .../TerminologyNotesGenerator.java | 6 ++--- .../tools/publisher/ExampleInspector.java | 9 ++++++-- .../fhir/tools/publisher/PageProcessor.java | 22 +++++++++++++++++-- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f4ab6d0..b673a40 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "org.hl7.fhir" -version = "1.9.1-SNAPSHOT" +version = "1.9.2-SNAPSHOT" java { withJavadocJar() diff --git a/gradle.properties b/gradle.properties index 4712144..fdfd921 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -fhirCoreVersion = 6.2.15-SNAPSHOT +fhirCoreVersion = 6.3.2 apachePoiVersion = 5.2.1 jacksonVersion = 2.16.0 apacheHttpcomponentsVersion = 4.5.13 diff --git a/src/main/java/org/hl7/fhir/definitions/generators/specification/TerminologyNotesGenerator.java b/src/main/java/org/hl7/fhir/definitions/generators/specification/TerminologyNotesGenerator.java index 0c07078..e3e3ede 100644 --- a/src/main/java/org/hl7/fhir/definitions/generators/specification/TerminologyNotesGenerator.java +++ b/src/main/java/org/hl7/fhir/definitions/generators/specification/TerminologyNotesGenerator.java @@ -225,9 +225,9 @@ else if (name.equals("FHIRAllTypes")) } } } else if (cd.getBinding() == BindingSpecification.BindingMethod.ValueSet) { - if (Utilities.noString(cd.getReference())) - write("??"); - else if (cd.getReference().startsWith("valueset-")) + if (Utilities.noString(cd.getReference())) { + System.out.println("no value set for "+cd.getName()); + } else if (cd.getReference().startsWith("valueset-")) write("http://hl7.org/fhir/ValueSet/"+cd.getReference().substring(9)+""); else if (cd.getReference().startsWith("http://hl7.org/fhir")) { if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v3-")) { diff --git a/src/main/java/org/hl7/fhir/tools/publisher/ExampleInspector.java b/src/main/java/org/hl7/fhir/tools/publisher/ExampleInspector.java index 2e9ac7a..631b222 100644 --- a/src/main/java/org/hl7/fhir/tools/publisher/ExampleInspector.java +++ b/src/main/java/org/hl7/fhir/tools/publisher/ExampleInspector.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -651,7 +652,6 @@ else if (SIDUtilities.isKnownSID(url) || Utilities.existsInList(url, "http://hl7 return true; } - @Override public IValidatorResourceFetcher setLocale(Locale locale) { // don't need to do anything here @@ -669,7 +669,7 @@ public byte[] fetchRaw(IResourceValidator validator, String source) throws Malfo @Override - public CanonicalResource fetchCanonicalResource(IResourceValidator validator, String url) throws URISyntaxException { + public CanonicalResource fetchCanonicalResource(IResourceValidator validator, Object appContext, String url) throws URISyntaxException { for (CanonicalResource t : context.fetchResourcesByType(CanonicalResource.class)) { if (t.getUrl().equals(url)) { return t; @@ -863,6 +863,11 @@ public boolean paramIsType(String name, int index) { throw new NotImplementedException(); } + @Override + public Set fetchCanonicalResourceVersions(IResourceValidator validator, Object appContext, String url) { + return new HashSet<>(); + } + } diff --git a/src/main/java/org/hl7/fhir/tools/publisher/PageProcessor.java b/src/main/java/org/hl7/fhir/tools/publisher/PageProcessor.java index b592359..2d8d39c 100644 --- a/src/main/java/org/hl7/fhir/tools/publisher/PageProcessor.java +++ b/src/main/java/org/hl7/fhir/tools/publisher/PageProcessor.java @@ -75,6 +75,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS import org.hl7.fhir.convertors.SpecDifferenceEvaluator; import org.hl7.fhir.convertors.TypeLinkProvider; import org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader; +import org.hl7.fhir.convertors.loaders.loaderR5.R5ToR5Loader; import org.hl7.fhir.definitions.Config; import org.hl7.fhir.definitions.generators.specification.BaseGenerator; import org.hl7.fhir.definitions.generators.specification.DataTypeTableGenerator; @@ -479,6 +480,7 @@ public int compare(String arg0, String arg1) { private String webLocation; private String searchLocation; private String extensionsLocation; + private long maxMemory = 0; private String getComputerName() { @@ -10446,10 +10448,10 @@ public void setDefinitions(Definitions definitions) throws Exception { workerContext.setAllowLoadingDuplicates(true); log("Load UTG Terminology", LogMessageType.Process); utg = new FilesystemPackageCacheManager.Builder().build().loadPackage("hl7.terminology"); - workerContext.loadFromPackage(utg, new R4ToR5Loader(BuildWorkerContext.defaultTypesToLoad(), new UTGLoader(utg.version()), workerContext.getVersion())); + workerContext.loadFromPackage(utg, new R5ToR5Loader(BuildWorkerContext.defaultTypesToLoad(), new UTGLoader(utg.version()))); log("Load Extensions", LogMessageType.Process); ext = new FilesystemPackageCacheManager.Builder().build().loadPackage("hl7.fhir.uv.extensions", "current"); - workerContext.loadFromPackage(ext, new R4ToR5Loader(BuildWorkerContext.extensionTypesToLoad(), new ExtensionsLoader(ext.version(), extensionsLocation), workerContext.getVersion())); + workerContext.loadFromPackage(ext, new R5ToR5Loader(BuildWorkerContext.extensionTypesToLoad(), new ExtensionsLoader(ext.version(), extensionsLocation))); log("Load DICOM Terminology", LogMessageType.Process); dicom = new FilesystemPackageCacheManager.Builder().build().loadPackage("fhir.dicom"); workerContext.loadFromPackage(dicom, new R4ToR5Loader(BuildWorkerContext.defaultTypesToLoad(), new DICOMLoader(utg.version()), workerContext.getVersion())); @@ -10530,6 +10532,16 @@ public void log(String content, LogMessageType type) { System.out.println(String.format("%1$-74s", content)+" "+String.format("%1$8s", Float.toString(gap))+" "+String.format("%1$3s", Long.toString(secs))+"sec "+String.format("%1$4s", Long.toString(used))+"MB"); } else System.out.println(content); + + + Runtime runtime = Runtime.getRuntime(); + long totalMemory = runtime.totalMemory(); + long freeMemory = runtime.freeMemory(); + long usedMemory = totalMemory - freeMemory; + if (usedMemory > maxMemory) { + maxMemory = usedMemory; + } + } // public void logNoEoln(String content) { @@ -12442,4 +12454,10 @@ public String processMarkdown(String location, String text) throws FHIRException throw new FHIRException(e); } } + + public long getMaxMemory() { + return maxMemory; + } + + }