use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class Scanner method exceptionToOutcome.
protected OperationOutcome exceptionToOutcome(Exception ex) throws IOException, FHIRException, EOperationOutcome {
OperationOutcome op = new OperationOutcome();
op.addIssue().setCode(OperationOutcome.IssueType.EXCEPTION).setSeverity(OperationOutcome.IssueSeverity.FATAL).getDetails().setText(ex.getMessage());
RenderingContext rc = new RenderingContext(getContext(), null, null, "http://hl7.org/fhir", "", null, RenderingContext.ResourceRendererMode.END_USER);
RendererFactory.factory(op, rc).render(op);
return op;
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class Scanner method genScanOutput.
protected void genScanOutput(String folder, List<ScanOutputItem> items) throws IOException, FHIRException, EOperationOutcome {
String f = Utilities.path(folder, "comparison.zip");
download("http://fhir.org/archive/comparison.zip", f);
unzip(f, folder);
for (int i = 0; i < items.size(); i++) {
items.get(i).setId("c" + i);
genScanOutputItem(items.get(i), Utilities.path(folder, items.get(i).getId() + ".html"));
}
StringBuilder b = new StringBuilder();
b.append("<html>");
b.append("<head>");
b.append("<title>Implementation Guide Scan</title>");
b.append("<link rel=\"stylesheet\" href=\"fhir.css\"/>\r\n");
b.append("<style>\r\n");
b.append("th \r\n");
b.append("{\r\n");
b.append(" vertical-align: bottom;\r\n");
b.append(" text-align: center;\r\n");
b.append("}\r\n");
b.append("\r\n");
b.append("th span\r\n");
b.append("{\r\n");
b.append(" -ms-writing-mode: tb-rl;\r\n");
b.append(" -webkit-writing-mode: vertical-rl;\r\n");
b.append(" writing-mode: vertical-rl;\r\n");
b.append(" transform: rotate(180deg);\r\n");
b.append(" white-space: nowrap;\r\n");
b.append("}\r\n");
b.append("</style>\r\n");
b.append("</head>");
b.append("<body>");
b.append("<h2>Implementation Guide Scan</h2>");
// organise
Set<String> refs = new HashSet<>();
Set<String> igs = new HashSet<>();
Map<String, Set<String>> profiles = new HashMap<>();
for (ScanOutputItem item : items) {
refs.add(item.getRef());
if (item.getIg() != null) {
igs.add(item.getIg().getUrl());
if (!profiles.containsKey(item.getIg().getUrl())) {
profiles.put(item.getIg().getUrl(), new HashSet<>());
}
if (item.getProfile() != null)
profiles.get(item.getIg().getUrl()).add(item.getProfile().getUrl());
}
}
b.append("<h2>By reference</h2>\r\n");
b.append("<table class=\"grid\">");
b.append("<tr><th></th><th></th>");
for (String s : sort(igs)) {
ImplementationGuide ig = getContext().fetchResource(ImplementationGuide.class, s);
b.append("<th colspan=\"" + Integer.toString(profiles.get(s).size() + 1) + "\"><b title=\"" + s + "\">" + ig.present() + "</b></th>");
}
b.append("</tr>\r\n");
b.append("<tr><th><b>Source</b></th><th><span>Core Spec</span></th>");
for (String s : sort(igs)) {
ImplementationGuide ig = getContext().fetchResource(ImplementationGuide.class, s);
b.append("<th><span>Global</span></th>");
for (String sp : sort(profiles.get(s))) {
StructureDefinition sd = getContext().fetchResource(StructureDefinition.class, sp);
b.append("<th><b title=\"" + sp + "\"><span>" + sd.present() + "</span></b></th>");
}
}
b.append("</tr>\r\n");
for (String s : sort(refs)) {
b.append("<tr>");
b.append("<td>" + s + "</td>");
b.append(genOutcome(items, s, null, null));
for (String si : sort(igs)) {
ImplementationGuide ig = getContext().fetchResource(ImplementationGuide.class, si);
b.append(genOutcome(items, s, si, null));
for (String sp : sort(profiles.get(ig.getUrl()))) {
b.append(genOutcome(items, s, si, sp));
}
}
b.append("</tr>\r\n");
}
b.append("</table>\r\n");
b.append("<h2>By IG</h2>\r\n");
b.append("<table class=\"grid\">");
b.append("<tr><th></th><th></th>");
for (String s : sort(refs)) {
b.append("<th><span>" + s + "</span></th>");
}
b.append("</tr>\r\n");
b.append("<tr><td></td><td>Core Spec</td>");
for (String s : sort(refs)) {
b.append(genOutcome(items, s, null, null));
}
b.append("</tr>\r\n");
for (String si : sort(igs)) {
b.append("<tr>");
ImplementationGuide ig = getContext().fetchResource(ImplementationGuide.class, si);
b.append("<td><b title=\"" + si + "\">" + ig.present() + "</b></td>");
b.append("<td>Global</td>");
for (String s : sort(refs)) {
b.append(genOutcome(items, s, si, null));
}
b.append("</tr>\r\n");
for (String sp : sort(profiles.get(ig.getUrl()))) {
b.append("<tr>");
StructureDefinition sd = getContext().fetchResource(StructureDefinition.class, sp);
b.append("<td></td><td><b title=\"" + sp + "\">" + sd.present() + "</b></td>");
for (String s : sort(refs)) {
b.append(genOutcome(items, s, si, sp));
}
b.append("</tr>\r\n");
}
}
b.append("</table>\r\n");
b.append("</body>");
b.append("</html>");
TextFile.stringToFile(b.toString(), Utilities.path(folder, "scan.html"));
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
// testing entry point
public OperationOutcome validate(FhirFormat format, InputStream stream, List<String> profiles) throws FHIRException, IOException, EOperationOutcome {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
InstanceValidator validator = getValidator(format);
validator.validate(null, messages, stream, format, asSdList(profiles));
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method validate.
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
InstanceValidator validator = getValidator(cntType);
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
return ValidatorUtils.messagesToOutcome(messages, context, fhirPathEngine);
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ComparisonService method compareStructureDefinitions.
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);
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");
}
Aggregations