Search in sources :

Example 16 with EOperationOutcome

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;
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) EOperationOutcome(org.hl7.fhir.r5.utils.EOperationOutcome)

Example 17 with EOperationOutcome

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"));
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) ScanOutputItem(org.hl7.fhir.validation.cli.model.ScanOutputItem)

Example 18 with EOperationOutcome

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);
}
Also used : InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 19 with EOperationOutcome

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);
}
Also used : InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator)

Example 20 with EOperationOutcome

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");
}
Also used : ComparisonSession(org.hl7.fhir.r5.comparison.ComparisonSession) ComparisonRenderer(org.hl7.fhir.r5.comparison.ComparisonRenderer) File(java.io.File)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)52 FHIRException (org.hl7.fhir.exceptions.FHIRException)38 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)37 ArrayList (java.util.ArrayList)35 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)14 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)13 FileOutputStream (java.io.FileOutputStream)10 Test (org.junit.jupiter.api.Test)10 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 DomainResource (org.hl7.fhir.r5.model.DomainResource)7 DomainResource (org.hl7.fhir.r4b.model.DomainResource)6 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)6 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)6 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5