Search in sources :

Example 1 with RDFValidator

use of org.hl7.fhir.rdf.RDFValidator in project kindling by HL7.

the class Publisher method processRDF.

private void processRDF() throws Exception, FileNotFoundException {
    // first, process the RIM file
    String rim = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "tools", "tx", "v3", "rim.ttl"));
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    FhirTurtleGenerator ttl = new FhirTurtleGenerator(tmp, page.getDefinitions(), page.getWorkerContext(), page.getValidationErrors());
    ttl.executeV3(page.getValueSets(), page.getCodeSystems());
    rim = rim + tmp.toString();
    TextFile.stringToFile(rim, Utilities.path(page.getFolders().dstDir, "rim.ttl"));
    ttl = new FhirTurtleGenerator(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "fhir.ttl")), page.getDefinitions(), page.getWorkerContext(), page.getValidationErrors());
    ttl.executeMain();
    W5TurtleGenerator w5 = new W5TurtleGenerator(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "w5.ttl")), page.getDefinitions(), page.getWorkerContext(), page.getValidationErrors());
    w5.executeMain();
    RDFValidator val = new RDFValidator();
    val.validate(Utilities.path(page.getFolders().dstDir, "fhir.ttl"));
    val.validate(Utilities.path(page.getFolders().dstDir, "rim.ttl"));
    val.validate(Utilities.path(page.getFolders().dstDir, "w5.ttl"));
    ZipGenerator zip = new ZipGenerator(Utilities.path(page.getFolders().dstDir, "fhir.rdf.ttl.zip"));
    zip.addFileName("fhir.ttl", Utilities.path(page.getFolders().dstDir, "fhir.ttl"), false);
    zip.addFileName("rim.ttl", Utilities.path(page.getFolders().dstDir, "rim.ttl"), false);
    zip.addFileName("w5.ttl", Utilities.path(page.getFolders().dstDir, "w5.ttl"), false);
    zip.close();
    // now that the RDF is generated, run any sparql rules that have been defined
    Element test = loadDom(new FileInputStream(Utilities.path(page.getFolders().srcDir, "sparql-rules.xml")), false).getDocumentElement();
    test = XMLUtil.getFirstChild(test);
    while (test != null) {
        if (test.getNodeName().equals("assertion")) {
            String sparql = test.getTextContent();
            page.getValidationErrors().addAll(val.assertion(sparql, test.getAttribute("id"), test.getAttribute("rowtype"), test.getAttribute("message"), test.getAttribute("description"), IssueSeverity.fromCode(test.getAttribute("level"))));
        }
        test = XMLUtil.getNextSibling(test);
    }
    checkAllOk();
}
Also used : FileOutputStream(java.io.FileOutputStream) Element(org.w3c.dom.Element) RDFValidator(org.hl7.fhir.rdf.RDFValidator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) W5TurtleGenerator(org.hl7.fhir.definitions.generators.specification.W5TurtleGenerator) FhirTurtleGenerator(org.hl7.fhir.definitions.generators.specification.FhirTurtleGenerator) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FhirTurtleGenerator (org.hl7.fhir.definitions.generators.specification.FhirTurtleGenerator)1 W5TurtleGenerator (org.hl7.fhir.definitions.generators.specification.W5TurtleGenerator)1 RDFValidator (org.hl7.fhir.rdf.RDFValidator)1 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)1 ZipGenerator (org.hl7.fhir.utilities.ZipGenerator)1 Element (org.w3c.dom.Element)1