Search in sources :

Example 16 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class BindingsParser method loadValueSet.

private ValueSet loadValueSet(String ref, String committee) throws Exception {
    String folder = new File(filename).getParent();
    String srcName;
    IParser p;
    if (new File(Utilities.path(folder, ref + ".xml")).exists()) {
        p = new XmlParser();
        srcName = Utilities.path(folder, ref + ".xml");
    } else if (new File(Utilities.path(folder, ref + ".json")).exists()) {
        p = new JsonParser();
        srcName = Utilities.path(folder, ref + ".json");
    } else
        throw new Exception("Unable to find source for " + ref + " in " + filename + " (" + Utilities.path(folder, ref + ".xml/json)"));
    FileInputStream input = new FileInputStream(srcName);
    try {
        ValueSet result = ValueSetUtilities.makeShareable((ValueSet) p.parse(input));
        result.setId(ref.substring(9));
        if (!result.hasExperimental())
            result.setExperimental(false);
        // if (!result.hasUrl())
        result.setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(9));
        if (!result.hasVersion() || result.getUrl().startsWith("http://hl7.org/fhir"))
            result.setVersion(version);
        if (!Utilities.noString(committee)) {
            if (!result.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
                result.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee));
            } else {
                String ec = ToolingExtensions.readStringExtension(result, ToolingExtensions.EXT_WORKGROUP);
                if (!ec.equals(committee))
                    System.out.println("ValueSet " + result.getUrl() + " WG mismatch 1: is " + ec + ", want to set to " + committee);
            }
        }
        result.setUserData("filename", "valueset-" + ref.substring(9));
        result.setUserData("path", "valueset-" + ref.substring(9) + ".html");
        new CodeSystemConvertor(codeSystems).convert(p, result, srcName, packageInfo);
        return result;
    } finally {
        IOUtils.closeQuietly(input);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) CodeSystemConvertor(org.hl7.fhir.definitions.parsers.CodeSystemConvertor) CodeType(org.hl7.fhir.r5.model.CodeType) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) URISyntaxException(java.net.URISyntaxException) FileInputStream(java.io.FileInputStream) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 17 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class OldSpreadsheetParser method findContext.

private ElementDefn findContext(ElementDefn root, String pathname, String source) throws Exception {
    String[] path = pathname.split("\\.");
    if (!path[0].equals(root.getName()))
        throw new Exception("Element Path '" + pathname + "' is not legal found at " + source);
    ElementDefn res = root;
    for (int i = 1; i < path.length; i++) {
        String en = path[i];
        if (en.length() == 0)
            throw new Exception("Improper path " + pathname + " found at " + source);
        if (en.charAt(en.length() - 1) == '*')
            throw new Exception("no-list wrapper found at " + source);
        ElementDefn t = res.getElementByName(en, true, definitions, "find context", false);
        if (t == null) {
            throw new Exception("Reference to undefined Element " + pathname + " found at " + source);
        }
        res = t;
    }
    return res;
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 18 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class SourceParser method loadIgs.

private void loadIgs() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(srcDir + "igs.xml"));
    Element root = xdoc.getDocumentElement();
    if (root.getNodeName().equals("igs")) {
        Element ig = XMLUtil.getFirstChild(root);
        while (ig != null) {
            if (ig.getNodeName().equals("ig") && (!ig.hasAttribute("local") || isOkLocally(ig.getAttribute("code"))) && !isRuledOutLocally(ig.getAttribute("code"))) {
                ImplementationGuideDefn igg = new ImplementationGuideDefn(ig.getAttribute("committee"), ig.getAttribute("code"), ig.getAttribute("name"), ig.getAttribute("brief"), ig.getAttribute("source").replace('\\', File.separatorChar), "1".equals(ig.getAttribute("review")), ig.getAttribute("ballot"), ig.getAttribute("fmm"), ig.getAttribute("section"), "yes".equals(ig.getAttribute("core")), page.getValidationErrors());
                definitions.getIgs().put(igg.getCode(), igg);
                definitions.getSortedIgs().add(igg);
            }
            ig = XMLUtil.getNextSibling(ig);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 19 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class SourceParser method checkConditions.

public void checkConditions(List<String> errors, Map<String, Long> dates) throws Exception {
    Utilities.checkFolder(srcDir, errors);
    Utilities.checkFolder(termDir, errors);
    Utilities.checkFolder(imgDir, errors);
    this.dates = dates;
    checkFile("required", termDir, "bindings.xml", errors, "all");
    checkFile("required", dtDir, "primitives.xml", errors, "all");
    for (String n : ini.getPropertyNames("types")) if (ini.getStringProperty("types", n).equals("")) {
        TypeRef t = new TypeParser(version.toString()).parse(n, false, null, context, true).get(0);
        checkFile("type definition", dtDir, t.getName().toLowerCase() + ".xml", errors, "all");
    }
    String[] shared = ini.getPropertyNames("shared");
    if (shared != null)
        for (String n : shared) checkFile("shared structure definition", dtDir, n.toLowerCase() + ".xml", errors, "all");
    for (String n : ini.getPropertyNames("infrastructure")) checkFile("infrastructure definition", dtDir, n.toLowerCase() + ".xml", errors, "all");
    for (String n : ini.getPropertyNames("resources")) {
        if (!new File(srcDir + n).exists())
            errors.add("unable to find folder for resource " + n);
        else {
            for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n);
        }
    }
    for (String n : ini.getPropertyNames("special-resources")) {
        // now iterate all the files in the directory checking data
        for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n);
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile)

Example 20 with Source

use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.

the class ADLImporter method execute.

private void execute() throws Exception {
    // load config
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
    // load ADL
    builder = factory.newDocumentBuilder();
    adl = builder.parse(new FileInputStream(source)).getDocumentElement();
    check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
    check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
    check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
    String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
    String baseType = XMLUtil.getNamedChild(XMLUtil.getNamedChild(adl, "definition"), "rm_type_name").getTextContent();
    if (!baseType.equals("OBSERVATION"))
        return;
    // load texts from ontology
    List<Element> set = new ArrayList<Element>();
    Element ontology = XMLUtil.getNamedChild(adl, "ontology");
    Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
    set.clear();
    XMLUtil.getNamedChildren(term_definitions, "items", set);
    for (Element item : set) {
        processTextItem(item);
    }
    // create structure definition
    StructureDefinition sd = new StructureDefinition();
    sd.setId("netha-" + id);
    sd.setUrl("http://hl7.org/fhir/StructureDefinition/" + sd.getId());
    sd.setKind(StructureDefinitionKind.LOGICAL);
    populateMetadata(set, sd);
    // load data and protocol
    Element definition = XMLUtil.getNamedChild(adl, "definition");
    NodeTreeEntry root = new NodeTreeEntry();
    root.typeName = XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent();
    root.atCode = XMLUtil.getNamedChild(definition, "node_id").getTextContent();
    root.name = generateToken(root.atCode, true);
    sd.setName(root.name);
    root.cardinality = readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences"));
    set.clear();
    XMLUtil.getNamedChildren(definition, "attributes", set);
    for (Element item : set) {
        // we're actually skipping this level - we don't care about data protocol etc.
        // XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
        Element attributes = item;
        loadChildren(root.atCode, root, attributes);
    }
    dumpChildren("", root);
    genElements(sd, root.name, root);
    // save
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
    System.out.println("done. saved as " + dest);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)125 FileInputStream (java.io.FileInputStream)59 FileOutputStream (java.io.FileOutputStream)55 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)48 File (java.io.File)45 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)45 TextFile (org.hl7.fhir.utilities.TextFile)41 CSFile (org.hl7.fhir.utilities.CSFile)35 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)35 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)30 XmlParser (org.hl7.fhir.r5.formats.XmlParser)28 Date (java.util.Date)27 HashMap (java.util.HashMap)26 Reference (org.hl7.fhir.r4.model.Reference)26 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)24 Coding (org.hl7.fhir.r4.model.Coding)24 JsonObject (com.google.gson.JsonObject)22 NotImplementedException (org.apache.commons.lang3.NotImplementedException)22