fix profile comparison

This commit is contained in:
Grahame Grieve 2021-10-21 06:18:17 +11:00
parent 2e075f674e
commit b60afcb608
3 changed files with 34 additions and 37 deletions

View File

@ -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("<table class=\"grid\">\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("</table>\r\n");
Map<String, Base> 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<String> list, StringBuilder b, String name) throws IOException {

View File

@ -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);
}

View File

@ -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) {