Search in sources :

Example 6 with Dictionary

use of org.hl7.fhir.definitions.model.Dictionary in project kindling by HL7.

the class SourceParser method loadDictionaries.

private void loadDictionaries() throws IOException {
    String[] dicts = ini.getPropertyNames("dictionaries");
    if (dicts != null) {
        for (String dict : dicts) {
            String[] s = ini.getStringProperty("dictionaries", dict).split("\\:");
            definitions.getDictionaries().put(dict, new Dictionary(dict, s[1], s[0], Utilities.path(page.getFolders().srcDir, "dictionaries", dict + ".xml"), null));
        }
    }
}
Also used : Dictionary(org.hl7.fhir.definitions.model.Dictionary)

Example 7 with Dictionary

use of org.hl7.fhir.definitions.model.Dictionary in project kindling by HL7.

the class PageProcessor method processExtensionIncludes.

public String processExtensionIncludes(String filename, StructureDefinition ed, String xml, String json, String ttl, String tx, String src, String pagePath, ImplementationGuideDefn ig) throws Exception {
    String workingTitle = null;
    int level = ig.isCore() ? 0 : 1;
    while (src.contains("<%") || src.contains("[%")) {
        int i1 = src.indexOf("<%");
        int i2 = src.indexOf("%>");
        if (i1 == -1) {
            i1 = src.indexOf("[%");
            i2 = src.indexOf("%]");
        }
        String s1 = src.substring(0, i1);
        String s2 = src.substring(i1 + 2, i2).trim();
        String s3 = src.substring(i2 + 2);
        String[] com = s2.split(" ");
        if (com[0].equals("file")) {
            if (new File(folders.templateDir + com[1] + ".html").exists()) {
                src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
            } else {
                src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
            }
        } else if (com[0].equals("extDefnHeader"))
            src = s1 + extDefnHeader(filename, com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("extension-table"))
            src = s1 + generateExtensionTable(ed, filename, com[1], genlevel(level)) + s3;
        else if (com[0].equals("settitle")) {
            workingTitle = s2.substring(9).replace("{", "<%").replace("}", "%>");
            src = s1 + s3;
        } else if (com.length != 1)
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
        else if (com[0].equals("pageheader"))
            src = s1 + pageHeader(ed.getName()) + s3;
        else if (com[0].equals("newheader"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
        else if (com[0].equals("newheader1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
        else if (com[0].equals("footer"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
        else if (com[0].equals("newfooter"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
        else if (com[0].equals("footer1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
        else if (com[0].equals("footer2"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
        else if (com[0].equals("footer3"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
        else if (com[0].equals("title"))
            src = s1 + (workingTitle == null ? Utilities.escapeXml(ed.getName()) : workingTitle) + s3;
        else if (com[0].equals("xtitle"))
            src = s1 + "Extension: " + Utilities.escapeXml(ed.getName()) + s3;
        else if (com[0].equals("filetitle"))
            src = s1 + (filename.contains(".") ? filename.substring(0, filename.lastIndexOf(".")) : filename) + s3;
        else if (com[0].equals("name"))
            src = s1 + filename + s3;
        else if (com[0].equals("date")) {
            if (ed.hasDate())
                src = s1 + ed.getDateElement().toHumanDisplay() + s3;
            else
                src = s1 + "[no date]" + s3;
        } else if (com[0].equals("version"))
            src = s1 + ini.getStringProperty("FHIR", "version") + s3;
        else if (com[0].equals("gendate"))
            src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
        else if (com[0].equals("definition"))
            src = s1 + processor.process(Utilities.escapeXml(ed.getDescription()), "Definition on " + ed.getId()) + s3;
        else if (com[0].equals("ext-comments")) {
            if (ed.getDifferential().getElementFirstRep().hasComment())
                src = s1 + "<p><b>Comment</b>: " + processor.process(Utilities.escapeXml(ed.getDifferential().getElementFirstRep().getComment()), "Definition on " + ed.getId()) + "</p>" + s3;
            else
                src = s1 + s3;
        } else if (com[0].equals("status"))
            src = s1 + (ed.getStatus() == null ? "??" : ed.getStatus().toCode()) + s3;
        else if (com[0].equals("author"))
            src = s1 + Utilities.escapeXml(ed.getPublisher()) + s3;
        else if (com[0].equals("xml"))
            src = s1 + xml + s3;
        else if (com[0].equals("json"))
            src = s1 + json + s3;
        else if (com[0].equals("ttl"))
            src = s1 + ttl + s3;
        else if (com[0].equals("tx"))
            src = s1 + tx + s3;
        else if (com[0].equals("inv"))
            src = s1 + genExtensionConstraints(ed) + s3;
        else if (com[0].equals("plural"))
            src = s1 + Utilities.pluralizeMe(filename) + s3;
        else if (com[0].equals("notes"))
            src = s1 + "todo" + /*Utilities.fileToString(folders.srcDir + filename+File.separatorChar+filename+".html")*/
            s3;
        else if (com[0].equals("dictionary"))
            src = s1 + definitionsProfile(ed, genlevel(level)) + s3;
        else if (com[0].equals("breadcrumb"))
            src = s1 + breadCrumbManager.make(filename) + s3;
        else if (com[0].equals("navlist"))
            src = s1 + breadCrumbManager.navlist(filename, genlevel(level)) + s3;
        else if (com[0].equals("breadcrumblist")) {
            String crumbTitle = ed.getUrl();
            src = s1 + ((ig == null || ig.isCore()) ? breadCrumbManager.makelist(filename, "extension:" + ed.getName(), genlevel(level), crumbTitle) : ig.makeList(filename, "extension:" + ed.getName(), genlevel(level), crumbTitle)) + s3;
        } else if (com[0].equals("year"))
            src = s1 + new SimpleDateFormat("yyyy").format(new Date()) + s3;
        else if (com[0].equals("buildId"))
            src = s1 + buildId + s3;
        else if (com[0].equals("level"))
            src = s1 + genlevel(level) + s3;
        else if (com[0].equals("pub-type"))
            src = s1 + publicationType + s3;
        else if (com[0].equals("pub-notice"))
            src = s1 + publicationNotice + s3;
        else if (com[0].equals("pagepath"))
            src = s1 + pagePath + s3;
        else if (com[0].equals("extensionurl"))
            src = s1 + ed.getUrl() + s3;
        else if (com[0].equals("rellink")) {
            if (!pagePath.contains(".html"))
                throw new Error("Invalid link: " + pagePath + " at " + workingTitle);
            src = s1 + Utilities.URLEncode(pagePath) + s3;
        } else if (com[0].equals("baseURL"))
            src = s1 + Utilities.URLEncode(baseURL) + s3;
        else if (com[0].equals("baseURLn"))
            src = s1 + Utilities.appendForwardSlash(baseURL) + s3;
        else if (com[0].equals("mappings"))
            src = s1 + mappingsExtension(ed) + s3;
        else if (com[0].equals("definitions"))
            src = s1 + definitionsExtension(ed, "") + s3;
        else if (com[0].equals("pubdetails")) {
            src = s1 + "Extension maintained by: " + Utilities.escapeXml(ed.getPublisher()) + s3;
        } else if (com[0].equals("extref"))
            src = s1 + "" + s3;
        else if (com[0].equals("context-info"))
            src = s1 + describeExtensionContext(ed) + s3;
        else if (com[0].equals("ext-name"))
            src = s1 + Utilities.escapeXml(ed.getName()) + s3;
        else if (com[0].equals("search-footer"))
            src = s1 + searchFooter(level) + s3;
        else if (com[0].equals("search-header"))
            src = s1 + searchHeader(level) + s3;
        else if (com[0].startsWith("!"))
            src = s1 + s3;
        else if (com[0].equals("wg")) {
            String wg = ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_WORKGROUP);
            src = s1 + (wg == null || !definitions.getWorkgroups().containsKey(wg) ? "(No assigned work group) (" + wg + ") (3)" : "<a _target=\"blank\" href=\"" + definitions.getWorkgroups().get(wg).getUrl() + "\">" + definitions.getWorkgroups().get(wg).getName() + "</a> Work Group") + s3;
        } else if (com[0].equals("fmm-style")) {
            String fmm = ed == null ? "N/A" : ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_FMM_LEVEL);
            StandardsStatus ss = ToolingExtensions.getStandardsStatus(ed);
            src = s1 + fmmBarColorStyle(ss, fmm) + s3;
        } else if (com[0].equals("fmm")) {
            String fmm = ToolingExtensions.readStringExtension(ed, ToolingExtensions.EXT_FMM_LEVEL);
            StandardsStatus ss = ToolingExtensions.getStandardsStatus(ed);
            if (StandardsStatus.EXTERNAL == ss)
                src = s1 + getFmmFromlevel(genlevel(level), "N/A") + s3;
            else if (StandardsStatus.NORMATIVE == ss)
                src = s1 + getFmmFromlevel(genlevel(level), "<a href=\"" + genlevel(level) + "versions.html#std-process\">N</a>") + s3;
            else
                src = s1 + getFmmFromlevel(genlevel(level), fmm) + s3;
        } else if (com[0].equals("sstatus")) {
            StandardsStatus ss = ToolingExtensions.getStandardsStatus(ed);
            if (ss == null)
                ss = StandardsStatus.INFORMATIVE;
            src = s1 + "<a href=\"" + genlevel(level) + "versions.html#std-process\">Informative</a>" + s3;
        } else if (com[0].equals("profile-context")) {
            src = s1 + getProfileContext(ed, genlevel(level)) + s3;
        } else if (com[0].equals("res-type-count")) {
            src = s1 + definitions.getResources().size() + s3;
        } else if (macros.containsKey(com[0])) {
            src = s1 + macros.get(com[0]) + s3;
        } else
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing resource " + filename);
    }
    return src;
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) SimpleDateFormat(java.text.SimpleDateFormat) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Date(java.util.Date)

Example 8 with Dictionary

use of org.hl7.fhir.definitions.model.Dictionary in project kindling by HL7.

the class LogicalModelProcessor method processCommand.

@Override
protected String processCommand(String command, String[] com) throws Exception {
    if (com[0].equals("lmheader"))
        return lmHeader(name, definition.getId(), com.length > 1 ? com[1] : null, true);
    else if (com[0].equals("svg"))
        return new SvgGenerator(page, genlevel(), null, true, false, version).generate(definition, com[1], "");
    else if (com[0].equals("draft-note"))
        return page.getDraftNote(definition);
    else if (com[0].equals("definition"))
        return definition.getDescription();
    else if (com[0].equals("tx"))
        return tx;
    else if (com[0].equals("inv"))
        return genConstraints(definition);
    else if (com[0].equals("resource-table"))
        return genLogicalModelTable(definition, genlevel());
    else if (com[0].equals("dictionary"))
        return dict;
    else if (com[0].equals("lmexamples"))
        return genExampleList();
    else if (com[0].equals("resref"))
        return "{todo}";
    else if (com[0].equals("maponthispage"))
        return "{todo}";
    else if (com[0].equals("mappings"))
        return "{todo}";
    else if (com[0].equals("fmm-style")) {
        String fmm = ToolingExtensions.readStringExtension(definition, ToolingExtensions.EXT_FMM_LEVEL);
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(definition);
        if (StandardsStatus.EXTERNAL == ss)
            return "colse";
        else
            return "colsi";
    } else if (com[0].equals("fmm")) {
        String fmm = ToolingExtensions.readStringExtension(definition, ToolingExtensions.EXT_FMM_LEVEL);
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(definition);
        if (StandardsStatus.EXTERNAL == ss)
            return getFmmFromlevel("", "N/A");
        else
            return getFmmFromlevel("", fmm);
    } else if (com[0].equals("wg")) {
        String wg = ToolingExtensions.readStringExtension(definition, ToolingExtensions.EXT_WORKGROUP);
        return (wg == null || !definitions.getWorkgroups().containsKey(wg) ? "(No assigned work group)" : "<a _target=\"blank\" href=\"" + definitions.getWorkgroups().get(wg).getUrl() + "\">" + definitions.getWorkgroups().get(wg).getName() + "</a> Work Group");
    } else if (com[0].equals("fmm-style")) {
        String fmm = ToolingExtensions.readStringExtension(definition, ToolingExtensions.EXT_FMM_LEVEL);
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(definition);
        if (StandardsStatus.EXTERNAL == ss)
            return "colse";
        else
            return "colsi";
    } else if (com[0].equals("wgt")) {
        String fmm = ToolingExtensions.readStringExtension(definition, ToolingExtensions.EXT_FMM_LEVEL);
        StandardsStatus ss = ToolingExtensions.getStandardsStatus(definition);
        if (StandardsStatus.EXTERNAL == ss)
            return getFmmFromlevel("", "N/A");
        else
            return getFmmFromlevel("", fmm);
    } else
        return super.processCommand(command, com);
}
Also used : SvgGenerator(org.hl7.fhir.definitions.generators.specification.SvgGenerator) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Example 9 with Dictionary

use of org.hl7.fhir.definitions.model.Dictionary in project kindling by HL7.

the class IgParser method load.

public void load(String rootDir, ImplementationGuideDefn igd, List<ValidationMessage> issues, Set<String> loadedIgs) throws Exception {
    logger.log(" ..." + igd.getName(), LogMessageType.Process);
    // first: parse the IG, then use it
    String myRoot = Utilities.path(rootDir, "guides", igd.getCode());
    CSFile file = new CSFile(Utilities.path(rootDir, igd.getSource()));
    ImplementationGuide ig = (ImplementationGuide) new XmlParser().parse(new FileInputStream(file));
    if (// for things published in the hl7.org/fhir namespace...
    !ig.getUrl().startsWith("http://hl7.org/fhir/"))
        throw new Exception("Illegal namespace");
    if (!ig.getUrl().equals("http://hl7.org/fhir/" + ig.getId()))
        throw new Exception("Illegal URL");
    if (!ig.hasName())
        throw new Exception("no name on IG");
    ig.setDateElement(new DateTimeType(genDate));
    igd.setName(ig.getName());
    igd.setIg(ig);
    Map<String, Resource> resources = new HashMap<String, Resource>();
    for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
        if (!loadedIgs.contains(d.getUri()))
            throw new Exception("Dependency on " + ig.getName() + " not satisfied: " + d.getUri());
    }
    loadedIgs.add(ig.getUrl());
    // for (UriType bin : ig.getBinary()) {
    // if (!new File(Utilities.path(myRoot, bin.getValue())).exists())
    // throw new Exception("Binary dependency in "+ig.getName()+" not found: "+bin.getValue());
    // igd.getImageList().add(bin.getValue());
    // }
    processPage(ig.getDefinition().getPage(), igd);
    List<Example> exr = new ArrayList<Example>();
    // first pass - verify the resources can be loaded
    for (ImplementationGuideDefinitionResourceComponent r : ig.getDefinition().getResource()) {
        if (!r.hasReference())
            throw new Exception("no source on resource in IG " + ig.getName());
        CSFile fn = new CSFile(Utilities.path(myRoot, r.getReference().getReference()));
        if (!fn.exists())
            throw new Exception("Source " + r.getReference().getReference() + " resource in IG " + ig.getName() + " could not be located @ " + fn.getAbsolutePath());
        String id = Utilities.changeFileExt(fn.getName(), "");
        // we're going to try and load the resource directly.
        // if that fails, then we'll treat it as an example.
        boolean isExample = r.hasExample();
        ResourceType rt = null;
        try {
            rt = new XmlParser().parse(new FileInputStream(fn)).getResourceType();
        } catch (Exception e) {
            rt = null;
            isExample = true;
        }
        if (isExample) {
            if (// which means that non conformance resources must be named
            !r.hasName())
                throw new Exception("no name on resource in IG " + ig.getName());
            Example example = new Example(r.getName(), id, r.getDescription(), fn, false, ExampleType.XmlFile, false);
            example.setIg(igd.getCode());
            if (r.hasExampleCanonicalType()) {
                example.setExampleFor(r.getExampleCanonicalType().asStringValue());
                example.setRegistered(true);
                exr.add(example);
            }
            igd.getExamples().add(example);
            r.setUserData(ToolResourceUtilities.NAME_RES_EXAMPLE, example);
            r.setReference(new Reference(example.getId() + ".html"));
        } else if (rt == ResourceType.ValueSet) {
            ValueSet vs = (ValueSet) new XmlParser().parse(new FileInputStream(fn));
            if (id.startsWith("valueset-"))
                id = id.substring(9);
            vs.setId(id);
            if (vs.getUrl() == null) {
                // Asserting this all the time causes issues for non-HL7 URL value sets
                vs.setUrl("http://hl7.org/fhir/ValueSet/" + id);
            }
            vs.setUserData(ToolResourceUtilities.NAME_RES_IG, igd);
            vs.setUserData("path", igd.getPath() + "valueset-" + id + ".html");
            vs.setUserData("filename", "valueset-" + id);
            if (committee != null) {
                if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
                    vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
                } else {
                    String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
                    if (!ec.equals(committee.getCode()))
                        System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 2: is " + ec + ", want to set to " + committee);
                }
            }
            new CodeSystemConvertor(codeSystems).convert(new XmlParser(), vs, fn.getAbsolutePath(), packageInfo);
            // if (id.contains(File.separator))
            igd.getValueSets().add(vs);
            if (!r.hasName())
                r.setName(vs.getName());
            if (!r.hasDescription())
                r.setDescription(vs.getDescription());
            r.setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
            r.setReference(new Reference(fn.getName()));
        } else if (rt == ResourceType.StructureDefinition) {
            StructureDefinition sd;
            sd = (StructureDefinition) new XmlParser().parse(new CSFileInputStream(fn));
            new ProfileUtilities(context, null, pkp).setIds(sd, false);
            if (sd.getKind() == StructureDefinitionKind.LOGICAL) {
                fn = new CSFile(Utilities.path(myRoot, r.getReference().getReference()));
                LogicalModel lm = new LogicalModel(sd);
                lm.setSource(fn.getAbsolutePath());
                lm.setId(sd.getId());
                igd.getLogicalModels().add(lm);
            } else if ("Extension".equals(sd.getType())) {
                sd.setId(tail(sd.getUrl()));
                sd.setUserData(ToolResourceUtilities.NAME_RES_IG, igd.getCode());
                ToolResourceUtilities.updateUsage(sd, igd.getCode());
                this.context.cacheResource(sd);
            } else {
                Profile pr = new Profile(igd.getCode());
                pr.setSource(fn.getAbsolutePath());
                pr.setTitle(sd.getName());
                if (!sd.hasId())
                    sd.setId(tail(sd.getUrl()));
                // Lloyd: This causes issues for profiles & extensions defined outside of HL7
                // sd.setUrl("http://hl7.org/fhir/StructureDefinition/"+sd.getId());
                pr.forceMetadata("id", sd.getId() + "-profile");
                pr.setSourceType(ConformancePackageSourceType.StructureDefinition);
                ConstraintStructure cs = new ConstraintStructure(sd, igd, wg(sd), fmm(sd), sd.getExperimental());
                pr.getProfiles().add(cs);
                igd.getProfiles().add(pr);
            }
        } else if (rt == ResourceType.Bundle) {
            Dictionary d = new Dictionary(id, r.getName(), igd.getCode(), fn.getAbsolutePath(), igd);
            igd.getDictionaries().add(d);
        } else
            logger.log("Implementation Guides do not yet support " + rt.toString(), LogMessageType.Process);
    // throw new Error("Not implemented yet - type = "+rt.toString());
    // if (r.hasExampleFor()) {
    // if (!resources.containsKey(r.getExampleFor().getReference()))
    // throw new Exception("Unable to resolve example-for reference to "+r.getExampleFor().getReference());
    // }
    }
    // second pass: load the spreadsheets
    for (ImplementationGuideDefinitionGroupingComponent p : ig.getDefinition().getGrouping()) {
        if (!p.hasName())
            throw new Exception("no name on package in IG " + ig.getName());
        for (Extension ex : p.getExtension()) {
            if (ex.getUrl().equals(ToolResourceUtilities.EXT_PROFILE_SPREADSHEET)) {
                String s = ((UriType) ex.getValue()).getValue();
                File fn = new File(Utilities.path(myRoot, s));
                if (!fn.exists())
                    throw new Exception("Spreadsheet " + s + " in package " + p.getName() + " in IG " + ig.getName() + " could not be located");
                Profile pr = new Profile(igd.getCode());
                ex.setUserData(ToolResourceUtilities.NAME_RES_PROFILE, pr);
                pr.setSource(fn.getAbsolutePath());
                pr.setSourceType(ConformancePackageSourceType.Spreadsheet);
                OldSpreadsheetParser sparser = new OldSpreadsheetParser(pr.getCategory(), new CSFileInputStream(pr.getSource()), Utilities.noString(pr.getId()) ? pr.getSource() : pr.getId(), pr.getSource(), igd, rootDir, logger, registry, FHIRVersion.fromCode(context.getVersion()), context, genDate, false, pkp, false, committee, mappings, profileIds, codeSystems, maps, workgroups, exceptionIfExcelNotNormalised);
                sparser.getBindings().putAll(commonBindings);
                sparser.setFolder(Utilities.getDirectoryForFile(pr.getSource()));
                sparser.parseConformancePackage(pr, null, Utilities.getDirectoryForFile(pr.getSource()), pr.getCategory(), issues, null);
                // System.out.println("load "+pr.getId()+" from "+s);
                igd.getProfiles().add(pr);
                // what remains to be done now is to update the package with the loaded resources, but we need to wait for all the profiles to generated, so we'll do that later
                for (BindingSpecification bs : sparser.getBindings().values()) {
                    if (!commonBindings.containsValue(bs) && bs.getValueSet() != null) {
                        ValueSet vs = bs.getValueSet();
                        String path = vs.getUserString("path");
                        path = path.substring(path.lastIndexOf("/") + 1);
                        ig.getDefinition().addResource().setName(vs.getName()).setDescription(vs.getDescription()).setReference(new Reference(path)).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
                    }
                }
                // now, register resources for all the things in the spreadsheet
                for (ValueSet vs : sparser.getValuesets()) ig.getDefinition().addResource().setExample(new BooleanType(false)).setName(vs.getName()).setDescription(vs.getDescription()).setReference(new Reference("valueset-" + vs.getId() + ".html")).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
                for (StructureDefinition exd : pr.getExtensions()) ig.getDefinition().addResource().setExample(new BooleanType(false)).setName(exd.getName()).setDescription(exd.getDescription()).setReference(new Reference("extension-" + exd.getId().toLowerCase() + ".html")).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, exd);
                for (ConstraintStructure cs : pr.getProfiles()) {
                    cs.setResourceInfo(ig.getDefinition().addResource());
                    cs.getResourceInfo().setExample(new BooleanType(false)).setName(cs.getDefn().getName()).setDescription(cs.getDefn().getDefinition()).setReference(new Reference(cs.getId().toLowerCase() + ".html"));
                }
            }
            if (ex.getUrl().equals(ToolResourceUtilities.EXT_LOGICAL_SPREADSHEET)) {
                File fn = new CSFile(Utilities.path(myRoot, ((UriType) ex.getValue()).getValue()));
                // String source = Utilities.path(file.getParent(), e.getAttribute("source"));
                String s = fn.getName();
                if (s.endsWith("-spreadsheet.xml"))
                    s = s.substring(0, s.length() - 16);
                String id = igd.getCode() + "-" + s;
                OldSpreadsheetParser sparser = new OldSpreadsheetParser(igd.getCode(), new CSFileInputStream(fn), id, fn.getAbsolutePath(), igd, rootDir, logger, registry, FHIRVersion.fromCode(context.getVersion()), context, genDate, false, pkp, false, committee, mappings, profileIds, codeSystems, maps, workgroups, exceptionIfExcelNotNormalised);
                sparser.getBindings().putAll(commonBindings);
                sparser.setFolder(Utilities.getDirectoryForFile(fn.getAbsolutePath()));
                LogicalModel lm = sparser.parseLogicalModel();
                lm.setId(id);
                lm.setSource(fn.getAbsolutePath());
                lm.getResource().setName(lm.getId());
                igd.getLogicalModels().add(lm);
            }
        }
        ToolingExtensions.removeExtension(p, ToolResourceUtilities.EXT_PROFILE_SPREADSHEET);
        ToolingExtensions.removeExtension(p, ToolResourceUtilities.EXT_LOGICAL_SPREADSHEET);
    }
    for (Example ex : exr) {
        Profile tp = null;
        for (Profile pr : igd.getProfiles()) {
            if (("StructureDefinition/" + pr.getId()).equals(ex.getExampleFor())) {
                tp = pr;
                break;
            } else
                for (ConstraintStructure cc : pr.getProfiles()) {
                    if (("StructureDefinition/" + cc.getId()).equals(ex.getExampleFor())) {
                        tp = pr;
                        break;
                    }
                }
        }
        if (tp != null)
            tp.getExamples().add(ex);
        else
            throw new Exception("no profile found matching exampleFor = " + ex.getExampleFor());
    }
    igd.numberPages();
// // second, parse the old ig, and use that. This is being phased out
// CSFile file = new CSFile(Utilities.path(rootDir, igd.getSource()));
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware(true);
// DocumentBuilder builder = factory.newDocumentBuilder();
// Document xdoc = builder.parse(new CSFileInputStream(file));
// Element root = xdoc.getDocumentElement();
// if (!root.getNodeName().equals("ig"))
// throw new Exception("wrong base node");
// Element e = XMLUtil.getFirstChild(root);
// while (e != null) {
// if (e.getNodeName().equals("dependsOn")) {
// // we ignore this for now
// } else if (e.getNodeName().equals("publishing")) {
// //        if (e.hasAttribute("homepage"))
// //          igd.setPage(e.getAttribute("homepage"));
// } else if (e.getNodeName().equals("page")) {
// //        igd.getPageList().add(e.getAttribute("source"));
// } else if (e.getNodeName().equals("image")) {
// //        moved above igd.getImageList().add(e.getAttribute("source"));
// } else if (e.getNodeName().equals("valueset")) {
// //        XmlParser xml = new XmlParser();
// //        ValueSet vs = (ValueSet) xml.parse(new CSFileInputStream(Utilities.path(file.getParent(), e.getAttribute("source"))));
// //        String id = Utilities.changeFileExt(new File(Utilities.path(file.getParent(), e.getAttribute("source"))).getName(), "");
// //        if (id.startsWith("valueset-"))
// //          id = id.substring(9);
// //        if (!vs.hasId() || !vs.hasUrl()) {
// //          vs.setId(id);
// //          vs.setUrl("http://hl7.org/fhir/ValueSet/"+vs.getId());
// //        }
// //        vs.setUserData(ToolResourceUtilities.NAME_RES_IG, igd);
// //        vs.setUserData("path", igd.getCode()+File.separator+"valueset-"+vs.getId()+".html");
// //        vs.setUserData("filename", "valueset-"+vs.getId());
// //        vs.setUserData("committee", committee);
// //        igd.getValueSets().add(vs);
// } else if (e.getNodeName().equals("acronym")) {
// igd.getTlas().put(e.getAttribute("target"), e.getAttribute("id"));
// } else if (e.getNodeName().equals("example")) {
// //        String filename = e.getAttribute("source");
// //        File efile = new File(Utilities.path(file.getParent(), filename));
// //        Example example = new Example(e.getAttribute("name"), Utilities.changeFileExt(efile.getName(), ""), e.getAttribute("name"), efile, false, ExampleType.XmlFile, false);
// //        example.setIg(igd.getCode());
// //        igd.getExamples().add(example);
// } else if (e.getNodeName().equals("profile")) {
// //        moved above
// //        Profile p = new Profile(igd.getCode());
// //        p.setSource(Utilities.path(file.getParent(), e.getAttribute("source")));
// //        if ("spreadsheet".equals(e.getAttribute("type"))) {
// //          p.setSourceType(ConformancePackageSourceType.Spreadsheet);
// //          SpreadsheetParser sparser = new SpreadsheetParser(p.getCategory(), new CSFileInputStream(p.getSource()), Utilities.noString(p.getId()) ? p.getSource() : p.getId(), igd,
// //              rootDir, logger, null, context.getVersion(), context, genDate, false, igd.getExtensions(), pkp, false, committee, mappings);
// //          sparser.getBindings().putAll(commonBindings);
// //          sparser.setFolder(Utilities.getDirectoryForFile(p.getSource()));
// //          sparser.parseConformancePackage(p, null, Utilities.getDirectoryForFile(p.getSource()), p.getCategory(), issues);
// //          for (BindingSpecification bs : sparser.getBindings().values()) {
// //            if (!commonBindings.containsValue(bs) && bs.getValueSet() != null) {
// //              ValueSet vs  = bs.getValueSet();
// //              String path = vs.getUserString("filename")+".xml";
// //              ig.getPackage().get(0).addResource().setName(vs.getName()).setDescription(vs.getDescription()).setSource(new UriType(path)).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
// //            }
// //          }
// //        } else {
// //          throw new Exception("Unknown profile type in IG : "+e.getNodeName());
// //          // parseConformanceDocument(p, p.getId(), new File(p.getSource()), p.getCategory());
// //        }
// //
// //        String id = e.getAttribute("id");
// //        if (Utilities.noString(id))
// //          id = Utilities.changeFileExt(e.getAttribute("source"), "");
// //        igd.getProfiles().add(p);
// //        Element ex = XMLUtil.getFirstChild(e);
// //        while (ex != null) {
// //          if (ex.getNodeName().equals("example")) {
// //            String filename = ex.getAttribute("source");
// //            Example example = new Example(ex.getAttribute("name"), Utilities.changeFileExt(Utilities.getFileNameForName(filename), ""), ex.getAttribute("name"), new File(Utilities.path(file.getParent(), filename)), false, ExampleType.XmlFile, false);
// //            p.getExamples().add(example);
// //          } else
// //            throw new Exception("Unknown element name in IG: "+ex.getNodeName());
// //          ex = XMLUtil.getNextSibling(ex);
// //        }
// } else if (e.getNodeName().equals("dictionary")) {
// //        Dictionary d = new Dictionary(e.getAttribute("id"), e.getAttribute("name"), igd.getCode(), Utilities.path(Utilities.path(file.getParent(), e.getAttribute("source"))), igd);
// //        igd.getDictionaries().add(d);
// } else if (e.getNodeName().equals("logicalModel")) {
// //        String source = Utilities.path(file.getParent(), e.getAttribute("source"));
// //        String id = igd.getCode()+"-"+e.getAttribute("id");
// //        SpreadsheetParser sparser = new SpreadsheetParser(igd.getCode(), new CSFileInputStream(source), id, igd, rootDir, logger, null, context.getVersion(), context, genDate, false, igd.getExtensions(), pkp, false, committee, mappings);
// //        sparser.getBindings().putAll(commonBindings);
// //        sparser.setFolder(Utilities.getDirectoryForFile(source));
// //        LogicalModel lm = sparser.parseLogicalModel(source);
// //        lm.setId(id);
// //        lm.setSource(source);
// //        lm.getResource().setName(lm.getId());
// //        igd.getLogicalModels().add(lm);
// } else
// throw new Exception("Unknown element name in IG: "+e.getNodeName());
// e = XMLUtil.getNextSibling(e);
// }
}
Also used : Dictionary(org.hl7.fhir.definitions.model.Dictionary) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CSFile(org.hl7.fhir.utilities.CSFile) Profile(org.hl7.fhir.definitions.model.Profile) UriType(org.hl7.fhir.r5.model.UriType) LogicalModel(org.hl7.fhir.definitions.model.LogicalModel) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) ValueSet(org.hl7.fhir.r5.model.ValueSet) ImplementationGuideDefinitionGroupingComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent) XmlParser(org.hl7.fhir.r5.formats.XmlParser) Reference(org.hl7.fhir.r5.model.Reference) Resource(org.hl7.fhir.r5.model.Resource) BooleanType(org.hl7.fhir.r5.model.BooleanType) ResourceType(org.hl7.fhir.r5.model.ResourceType) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) FileInputStream(java.io.FileInputStream) Extension(org.hl7.fhir.r5.model.Extension) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) ImplementationGuideDependsOnComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) CodeType(org.hl7.fhir.r5.model.CodeType) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 10 with Dictionary

use of org.hl7.fhir.definitions.model.Dictionary in project kindling by HL7.

the class SourceParser method parse.

public void parse(Calendar genDate, List<ValidationMessage> issues) throws Exception {
    logger.log("Loading", LogMessageType.Process);
    loadNormativePackages();
    loadWorkGroups();
    loadW5s();
    loadMappingSpaces();
    loadGlobalBindings();
    loadExternals();
    loadTLAs();
    loadIgs();
    loadTypePages();
    loadDictionaries();
    loadStyleExemptions();
    logger.log("Load Code Systems", LogMessageType.Process);
    String[] pn = ini.getPropertyNames("codesystems");
    if (pn != null) {
        for (String n : pn) {
            loadCodeSystem(n);
        }
    }
    logger.log("Load Value Sets", LogMessageType.Process);
    pn = ini.getPropertyNames("valuesets");
    if (pn != null) {
        for (String n : pn) {
            loadValueSet(n);
        }
    }
    loadCommonSearchParameters();
    loadPrimitives();
    for (String id : ini.getPropertyNames("search-rules")) {
        definitions.seachRule(id, ini.getStringProperty("search-rules", id));
    }
    for (String id : ini.getPropertyNames("valueset-fixup")) {
        definitions.getVsFixups().add(id);
    }
    for (String n : ini.getPropertyNames("infrastructure")) {
        loadCompositeType(n, definitions.getInfrastructure(), "5", "abstract".equals(ini.getStringProperty("infrastructure", n)));
    }
    for (String n : ini.getPropertyNames("types")) {
        loadCompositeType(n, definitions.getTypes(), "5", "abstract".equals(ini.getStringProperty("types", n)));
    }
    String[] shared = ini.getPropertyNames("shared");
    if (shared != null) {
        for (String n : shared) {
            definitions.getShared().add(loadCompositeType(n, definitions.getTypes(), "2", "abstract".equals(ini.getStringProperty("shared", n))));
        }
    }
    String[] logical = ini.getPropertyNames("logical");
    if (logical != null) {
        for (String n : logical) {
            definitions.getIgs().get("core").getLogicalModels().add(loadLogicalModel(n));
        }
    }
    // basic infrastructure
    for (String n : ini.getPropertyNames("resource-infrastructure")) {
        String[] parts = ini.getStringProperty("resource-infrastructure", n).split("\\,");
        boolean isAbstract = false;
        boolean isInterface = false;
        if (parts[0].equals("abstract")) {
            isAbstract = true;
        } else if (parts[0].equals("interface")) {
            isAbstract = true;
            isInterface = true;
        }
        ResourceDefn r = loadResource(n, null, isAbstract, false, parts[1], isInterface);
        r.setAbstract(isAbstract);
        r.setInterface(isInterface);
        definitions.getBaseResources().put(parts[1], r);
    }
    if (ini.getPropertyNames("resource-templates") != null) {
        logger.log("Load Resource Templates", LogMessageType.Process);
        for (String n : ini.getPropertyNames("resource-templates")) {
            loadResource(n, definitions.getResourceTemplates(), false, true, ini.getStringProperty("resource-templates", n), false);
        }
    }
    logger.log("Load Resources", LogMessageType.Process);
    for (String n : ini.getPropertyNames("resources")) {
        loadResource(n, definitions.getResources(), false, false, ini.getStringProperty("resources", n), false);
    }
    processSearchExpressions();
    processContainerExamples();
    logger.log("Load Extras", LogMessageType.Process);
    loadCompartments();
    loadStatusCodes();
    buildSpecialValues();
    for (String n : ini.getPropertyNames("svg")) {
        definitions.getDiagrams().put(n, ini.getStringProperty("svg", n));
    }
    for (String n : ini.getPropertyNames("special-resources")) {
        definitions.getAggregationEndpoints().add(n);
    }
    logger.log("Load Profiles", LogMessageType.Process);
    for (String n : ini.getPropertyNames("profiles")) {
        // todo-profile: rename this
        loadConformancePackages(n, issues);
    }
    for (ResourceDefn r : definitions.getBaseResources().values()) {
        findValueSets(r.getRoot());
    }
    for (ResourceDefn r : definitions.getResources().values()) {
        findValueSets(r.getRoot());
    }
    for (ResourceDefn r : definitions.getBaseResources().values()) {
        for (Profile p : r.getConformancePackages()) {
            loadConformancePackage(p, issues, r.getWg());
        }
    }
    for (ResourceDefn r : definitions.getResources().values()) {
        for (Profile p : r.getConformancePackages()) {
            loadConformancePackage(p, issues, r.getWg());
        }
    }
    definitions.setLoaded(true);
    for (ImplementationGuideDefn ig : definitions.getSortedIgs()) {
        if (!Utilities.noString(ig.getSource())) {
            try {
                new IgParser(page, page.getWorkerContext(), page.getGenDate(), page, definitions.getCommonBindings(), wg(ig.getCommittee()), definitions.getMapTypes(), definitions.getProfileIds(), definitions.getCodeSystems(), registry, page.getConceptMaps(), definitions.getWorkgroups(), exceptionIfExcelNotNormalised, page.packageInfo()).load(rootDir, ig, issues, igNames);
                // register what needs registering
                for (ValueSet vs : ig.getValueSets()) {
                    definitions.getExtraValuesets().put(vs.getId(), vs);
                    context.cacheResource(vs);
                }
                for (Example ex : ig.getExamples()) {
                    definitions.getResourceByName(ex.getResourceName()).getExamples().add(ex);
                }
                for (Profile p : ig.getProfiles()) {
                    if (definitions.getPackMap().containsKey(p.getId())) {
                        throw new Exception("Duplicate Pack id " + p.getId());
                    }
                    definitions.getPackList().add(p);
                    definitions.getPackMap().put(p.getId(), p);
                }
                for (Dictionary d : ig.getDictionaries()) {
                    definitions.getDictionaries().put(d.getId(), d);
                }
            } catch (Exception e) {
                throw new Exception("Error reading IG " + ig.getSource() + ": " + e.getMessage(), e);
            }
        }
    }
    closeTemplates();
}
Also used : Dictionary(org.hl7.fhir.definitions.model.Dictionary) Example(org.hl7.fhir.definitions.model.Example) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) ValueSet(org.hl7.fhir.r5.model.ValueSet) Profile(org.hl7.fhir.definitions.model.Profile) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

File (java.io.File)7 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 CSFile (org.hl7.fhir.utilities.CSFile)7 URISyntaxException (java.net.URISyntaxException)6 Date (java.util.Date)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 TransformerException (javax.xml.transform.TransformerException)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)6 UcumException (org.fhir.ucum.UcumException)6 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)6 ValueSet (org.hl7.fhir.r5.model.ValueSet)6 IniFile (org.hl7.fhir.utilities.IniFile)6 TextFile (org.hl7.fhir.utilities.TextFile)6 SimpleDateFormat (java.text.SimpleDateFormat)5 StandardsStatus (org.hl7.fhir.utilities.StandardsStatus)5 ArrayList (java.util.ArrayList)4