From 3adbd0020956a09362e65c50dbc3a33f96f0f71a Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 2 Dec 2024 06:47:12 +0300 Subject: [PATCH] Fix presentation issues and union and intersection links in previous version comparison --- .../r5/comparison/CodeSystemComparer.java | 22 +++++++++++ .../r5/comparison/ComparisonRenderer.java | 39 +++++++++++++++++-- .../fhir/r5/comparison/ResourceComparer.java | 2 +- .../fhir/r5/comparison/ValueSetComparer.java | 21 ++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java index 38cbf1068..9c7914bbb 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java @@ -9,6 +9,8 @@ import java.util.Map; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.r5.comparison.StructureDefinitionComparer.ProfileComparison; import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.CodeSystem.CodeSystemFilterComponent; @@ -16,16 +18,26 @@ import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent; import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent; import org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent; import org.hl7.fhir.r5.model.CodeSystem.PropertyComponent; +import org.hl7.fhir.r5.renderers.StructureDefinitionRenderer; +import org.hl7.fhir.r5.renderers.CodeSystemRenderer; +import org.hl7.fhir.r5.renderers.Renderer.RenderingStatus; +import org.hl7.fhir.r5.renderers.utils.RenderingContext; +import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules; +import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; +import org.hl7.fhir.r5.renderers.utils.ResourceWrapper; +import org.hl7.fhir.r5.utils.EOperationOutcome; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.RenderingI18nContext; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.Source; +import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row; import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel; +import org.hl7.fhir.utilities.xhtml.XhtmlDocument; import org.hl7.fhir.utilities.xhtml.XhtmlNode; public class CodeSystemComparer extends CanonicalResourceComparer { @@ -628,4 +640,14 @@ public class CodeSystemComparer extends CanonicalResourceComparer { return "CodeSystem"; } + public XhtmlNode renderUnion(CodeSystemComparison comp, String id, String prefix, String corePath) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome { + CodeSystemRenderer csr = new CodeSystemRenderer(new RenderingContext(session.getContextLeft(), null, new ValidationOptions(), corePath, prefix, null, ResourceRendererMode.TECHNICAL, GenerationRules.IG_PUBLISHER)); + return csr.buildNarrative(ResourceWrapper.forResource(csr.getContext(), comp.union)); + } + + public XhtmlNode renderIntersection(CodeSystemComparison comp, String id, String prefix, String corePath) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome { + CodeSystemRenderer csr = new CodeSystemRenderer(new RenderingContext(session.getContextLeft(), null, new ValidationOptions(), corePath, prefix, null, ResourceRendererMode.TECHNICAL, GenerationRules.IG_PUBLISHER)); + return csr.buildNarrative(ResourceWrapper.forResource(csr.getContext(), comp.intersection)); + } + } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java index 8583c96e4..b9d29fae0 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ComparisonRenderer.java @@ -12,7 +12,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.exceptions.PathEngineException; import org.hl7.fhir.r5.comparison.CapabilityStatementComparer.CapabilityStatementComparison; import org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison; @@ -32,6 +34,7 @@ import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.StringType; import org.hl7.fhir.r5.model.Tuple; import org.hl7.fhir.r5.model.ValueSet; +import org.hl7.fhir.r5.utils.EOperationOutcome; import org.hl7.fhir.r5.utils.LiquidEngine; import org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument; import org.hl7.fhir.utilities.FhirPublication; @@ -109,7 +112,7 @@ public class ComparisonRenderer implements IEvaluationContext { if (comp.fhirType().equals(name)) { if (first) { first = false; - b.append(""+Utilities.pluralize(name, 2)+"\r\n"); + b.append(""+Utilities.pluralize(name, 2)+"\r\n"); } try { renderComparison(id, comp); @@ -143,7 +146,7 @@ public class ComparisonRenderer implements IEvaluationContext { } } - private void renderComparison(String id, ResourceComparison comp) throws IOException { + private void renderComparison(String id, ResourceComparison comp) throws IOException, FHIRFormatError, DefinitionException, FHIRException, EOperationOutcome { if (comp instanceof ProfileComparison) { renderProfile(id, (ProfileComparison) comp); } else if (comp instanceof ValueSetComparison) { @@ -169,7 +172,7 @@ public class ComparisonRenderer implements IEvaluationContext { TextFile.stringToFile(cnt, file(comp.getId()+".html")); } - private void renderCodeSystem(String id, CodeSystemComparison comp) throws IOException { + private void renderCodeSystem(String id, CodeSystemComparison comp) throws IOException, FHIRFormatError, DefinitionException, FHIRException, EOperationOutcome { String template = templates.get("CodeSystem"); Map vars = new HashMap<>(); CodeSystemComparer cs = new CodeSystemComparer(session); @@ -183,17 +186,32 @@ public class ComparisonRenderer implements IEvaluationContext { vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp)))); vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", "")))); vars.put("concepts", new StringType(new XhtmlComposer(true).compose(cs.renderConcepts(comp, "", "")))); + String cnt = processTemplate(template, "CodeSystem", vars); TextFile.stringToFile(cnt, file(comp.getId()+".html")); new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion()); new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection()); + + String union = new XhtmlComposer(true).compose(cs.renderUnion(comp, "", folder, "http://hl7.org/fhir")); + String intersection = new XhtmlComposer(true).compose(cs.renderIntersection(comp, "", folder, "http://hl7.org/fhir")); + vars.put("union", new StringType(union)); + vars.put("intersection", new StringType(intersection)); + + template = templates.get("CodeSystem-Union"); + cnt = processTemplate(template, "CodeSystem-Union", vars); + TextFile.stringToFile(cnt, file(comp.getId()+"-union.html")); + + template = templates.get("CodeSystem-Intersection"); + cnt = processTemplate(template, "CodeSystem-Intersection", vars); + TextFile.stringToFile(cnt, file(comp.getId()+"-intersection.html")); + } private String file(String name) throws IOException { return Utilities.path(folder, name); } - private void renderValueSet(String id, ValueSetComparison comp) throws FHIRException, IOException { + private void renderValueSet(String id, ValueSetComparison comp) throws FHIRException, IOException, EOperationOutcome { String template = templates.get("ValueSet"); Map vars = new HashMap<>(); ValueSetComparer cs = new ValueSetComparer(session); @@ -212,6 +230,19 @@ public class ComparisonRenderer implements IEvaluationContext { TextFile.stringToFile(cnt, file(comp.getId()+".html")); new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(folder, comp.getId() + "-union.json")), comp.getUnion()); new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(folder, comp.getId() + "-intersection.json")), comp.getIntersection()); + + String union = new XhtmlComposer(true).compose(cs.renderUnion(comp, "", folder, "http://hl7.org/fhir")); + String intersection = new XhtmlComposer(true).compose(cs.renderIntersection(comp, "", folder, "http://hl7.org/fhir")); + vars.put("union", new StringType(union)); + vars.put("intersection", new StringType(intersection)); + + template = templates.get("ValueSet-Union"); + cnt = processTemplate(template, "ValueSet-Union", vars); + TextFile.stringToFile(cnt, file(comp.getId()+"-union.html")); + + template = templates.get("ValueSet-Intersection"); + cnt = processTemplate(template, "ValueSet-Intersection", vars); + TextFile.stringToFile(cnt, file(comp.getId()+"-intersection.html")); } private void renderProfile(String id, ProfileComparison comp) throws IOException { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ResourceComparer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ResourceComparer.java index 2d37d4fab..2a323a142 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ResourceComparer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ResourceComparer.java @@ -202,7 +202,7 @@ public class ResourceComparer { s = s + "Failed"; color = COLOR_ISSUE; } - s = s + ""+(e != null ? Utilities.escapeXml(e.getMessage()) : "")+""; + s = s + ""+(e != null ? Utilities.escapeXml(e.getMessage()) : "")+""; return ""+s+"\r\n"; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ValueSetComparer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ValueSetComparer.java index 3594ac32f..c9a98df2c 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ValueSetComparer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/ValueSetComparer.java @@ -7,6 +7,8 @@ import java.util.List; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.Element; @@ -16,10 +18,18 @@ import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; +import org.hl7.fhir.r5.renderers.CodeSystemRenderer; +import org.hl7.fhir.r5.renderers.ValueSetRenderer; +import org.hl7.fhir.r5.renderers.utils.RenderingContext; +import org.hl7.fhir.r5.renderers.utils.ResourceWrapper; +import org.hl7.fhir.r5.renderers.utils.RenderingContext.GenerationRules; +import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpansionOutcome; +import org.hl7.fhir.r5.utils.EOperationOutcome; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.RenderingI18nContext; import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.Source; @@ -904,4 +914,15 @@ public class ValueSetComparer extends CanonicalResourceComparer { return false; } + + public XhtmlNode renderUnion(ValueSetComparison comp, String id, String prefix, String corePath) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome { + ValueSetRenderer vsr = new ValueSetRenderer(new RenderingContext(session.getContextLeft(), null, new ValidationOptions(), corePath, prefix, null, ResourceRendererMode.TECHNICAL, GenerationRules.IG_PUBLISHER)); + return vsr.buildNarrative(ResourceWrapper.forResource(vsr.getContext(), comp.union)); + } + + public XhtmlNode renderIntersection(ValueSetComparison comp, String id, String prefix, String corePath) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome { + ValueSetRenderer vsr = new ValueSetRenderer(new RenderingContext(session.getContextLeft(), null, new ValidationOptions(), corePath, prefix, null, ResourceRendererMode.TECHNICAL, GenerationRules.IG_PUBLISHER)); + return vsr.buildNarrative(ResourceWrapper.forResource(vsr.getContext(), comp.intersection)); + } + } \ No newline at end of file