From b60afcb60836cee48e41a1554ad47ce47d95bf9d Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 21 Oct 2021 06:18:17 +1100 Subject: [PATCH] fix profile comparison --- .../r5/comparison/ComparisonRenderer.java | 5 +- .../org/hl7/fhir/validation/ValidatorCli.java | 1 + .../cli/services/ComparisonService.java | 65 +++++++++---------- 3 files changed, 34 insertions(+), 37 deletions(-) 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 45f3514ed..baf9aad14 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 @@ -1,5 +1,6 @@ package org.hl7.fhir.r5.comparison; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; @@ -56,7 +57,7 @@ public class ComparisonRenderer implements IEvaluationContext { return templates; } - public void render(String leftName, String rightName) throws IOException { + public File render(String leftName, String rightName) throws IOException { dumpBinaries(); StringBuilder b = new StringBuilder(); b.append("\r\n"); @@ -71,6 +72,7 @@ public class ComparisonRenderer implements IEvaluationContext { processList(list, b, "CodeSystem"); processList(list, b, "ValueSet"); processList(list, b, "StructureDefinition"); + processList(list, b, "CapabilityStatement"); b.append("
\r\n"); Map vars = new HashMap<>(); @@ -79,6 +81,7 @@ public class ComparisonRenderer implements IEvaluationContext { String template = templates.get("Index"); String cnt = processTemplate(template, "CodeSystem", vars); TextFile.stringToFile(cnt, file("index.html")); + return new File(file("index.html")); } private void processList(List list, StringBuilder b, String name) throws IOException { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java index bfdca65e4..1515dcedc 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java @@ -222,6 +222,7 @@ public class ValidatorCli { String v = VersionUtilities.getCurrentVersion(cliContext.getSv()); String definitions = VersionUtilities.packageForVersion(v) + "#" + v; ValidationEngine validator = validationService.initializeValidator(cliContext, definitions, tt); + validator.loadPackage("hl7.fhir.pubpack", null); ComparisonService.doLeftRightComparison(args, Params.getParam(args, Params.DESTINATION), validator); } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ComparisonService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ComparisonService.java index a5589d145..1fcb1b204 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ComparisonService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ComparisonService.java @@ -5,6 +5,9 @@ import java.io.File; import java.io.IOException; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r5.comparison.ComparisonRenderer; +import org.hl7.fhir.r5.comparison.ComparisonSession; +import org.hl7.fhir.r5.comparison.ProfileComparer; import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.CapabilityStatement; import org.hl7.fhir.r5.model.Resource; @@ -41,45 +44,35 @@ public class ComparisonService { } public static void compareCapabilityStatements(String[] args, String dest, ValidationEngine validator, String left, String right, CanonicalResource resLeft, CanonicalResource resRight) throws IOException { - String nameLeft = chooseName(args, "leftName", resLeft); - String nameRight = chooseName(args, "rightName", resRight); - System.out.println("Comparing CapabilityStatements " + left + " to " + right); -// CapabilityStatementUtilities pc = new CapabilityStatementUtilities(validator.getContext(), dest, new KeyGenerator("http://fhir.org/temp/" + UUID.randomUUID().toString().toLowerCase())); -// CapabilityStatement capL = (CapabilityStatement) resLeft; -// CapabilityStatement capR = (CapabilityStatement) resRight; -// CapabilityStatementUtilities.CapabilityStatementComparisonOutput output = pc.isCompatible(nameLeft, nameRight, capL, capR); -// -// String destTxt = Utilities.path(dest, "output.txt"); -// System.out.println("Generating output to " + destTxt + "..."); -// StringBuilder b = new StringBuilder(); -// for (ValidationMessage msg : output.getMessages()) { -// b.append(msg.summary()); -// b.append("\r\n"); -// } -// TextFile.stringToFile(b.toString(), destTxt); -// new XmlParser().setOutputStyle(IParser.OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "CapabilityStatement-union.xml")), output.getSuperset()); -// new XmlParser().setOutputStyle(IParser.OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "CapabilityStatement-intersection.xml")), output.getSubset()); -// new XmlParser().setOutputStyle(IParser.OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "OperationOutcome-issues.xml")), output.getOutcome()); -// new JsonParser().setOutputStyle(IParser.OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "CapabilityStatement-union.json")), output.getSuperset()); -// new JsonParser().setOutputStyle(IParser.OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "CapabilityStatement-intersection.json")), output.getSubset()); -// new JsonParser().setOutputStyle(IParser.OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "OperationOutcome-issues.json")), output.getOutcome()); -// - String destHtml = Utilities.path(dest, "public/index.html"); - File htmlFile = new File(destHtml); - Desktop.getDesktop().browse(htmlFile.toURI()); - System.out.println("Done"); + throw new Error("CapabilityStatement comparison is not implemented at this time (WIP)"); +// System.out.println("Comparing CapabilityStatements " + left + " to " + right); +// ComparisonSession session = new ComparisonSession(validator.getContext(), validator.getContext(), "Comparing Capability Statements", null); +// session.compare(resLeft, resRight); +// ComparisonRenderer cr = new ComparisonRenderer(validator.getContext(), validator.getContext(), dest, session); +// cr.getTemplates().put("CodeSystem", new String(validator.getContext().getBinaries().get("template-comparison-CodeSystem.html"))); +// cr.getTemplates().put("ValueSet", new String(validator.getContext().getBinaries().get("template-comparison-ValueSet.html"))); +// cr.getTemplates().put("Profile", new String(validator.getContext().getBinaries().get("template-comparison-Profile.html"))); +// cr.getTemplates().put("Index", new String(validator.getContext().getBinaries().get("template-comparison-index.html"))); +// File htmlFile = cr.render(left, right); +// Desktop.getDesktop().browse(htmlFile.toURI()); +// System.out.println("Done"); } public static void compareStructureDefinitions(String dest, ValidationEngine validator, String left, String right, StructureDefinition resLeft, StructureDefinition resRight) throws IOException, FHIRException, EOperationOutcome { -// System.out.println("Comparing StructureDefinitions " + left + " to " + right); -// ProfileComparer pc = new ProfileComparer(validator.getContext(), dest); -// StructureDefinition sdL = resLeft; -// StructureDefinition sdR = resRight; -// pc.compareProfiles(sdL, sdR); -// System.out.println("Generating output to " + dest + "..."); -// File htmlFile = new File(pc.generate()); -// Desktop.getDesktop().browse(htmlFile.toURI()); -// System.out.println("Done"); + System.out.println("Comparing StructureDefinitions " + left + " to " + right); + ComparisonSession session = new ComparisonSession(validator.getContext(), validator.getContext(), "Comparing Profiles", null); + session.compare(resLeft, resRight); + + System.out.println("Generating output to " + dest + "..."); + Utilities.createDirectory(dest); + ComparisonRenderer cr = new ComparisonRenderer(validator.getContext(), validator.getContext(), dest, session); + cr.getTemplates().put("CodeSystem", new String(validator.getContext().getBinaries().get("template-comparison-CodeSystem.html"))); + cr.getTemplates().put("ValueSet", new String(validator.getContext().getBinaries().get("template-comparison-ValueSet.html"))); + cr.getTemplates().put("Profile", new String(validator.getContext().getBinaries().get("template-comparison-Profile.html"))); + cr.getTemplates().put("Index", new String(validator.getContext().getBinaries().get("template-comparison-index.html"))); + File htmlFile = cr.render(left, right); + Desktop.getDesktop().browse(htmlFile.toURI()); + System.out.println("Done"); } private static String chooseName(String[] args, String name, CanonicalResource mr) {