Search in sources :

Example 81 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.

the class PageProcessor method genAllSearchParams.

private String genAllSearchParams() throws Exception {
    List<SearchParameter> splist = new ArrayList<SearchParameter>();
    for (ResourceDefn rd : getDefinitions().getBaseResources().values()) addSearchParams(splist, rd);
    for (ResourceDefn rd : getDefinitions().getResources().values()) addSearchParams(splist, rd);
    for (Profile cp : getDefinitions().getPackList()) {
        addSearchParams(splist, cp);
    }
    StringBuilder b = new StringBuilder();
    genSearchParams(b, splist, "Resource");
    genSearchParams(b, splist, "DomainResource");
    genCommonSearchParams(b, splist);
    for (String n : definitions.sortedResourceNames()) genSearchParams(b, splist, n);
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile)

Example 82 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.

the class PageProcessor method dictForDt.

// private boolean notime;
private String dictForDt(String dt) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    DictHTMLGenerator gen = new DictHTMLGenerator(new FileOutputStream(tmp), this, "");
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e;
    if (t.getName().equals("Resource"))
        e = definitions.getBaseResources().get("DomainResource").getRoot();
    else
        e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate(e);
        gen.close();
    }
    String val = TextFile.fileToString(tmp.getAbsolutePath()) + "\r\n";
    tmp.delete();
    return val;
}
Also used : ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) DictHTMLGenerator(org.hl7.fhir.definitions.generators.specification.DictHTMLGenerator) TypeRef(org.hl7.fhir.definitions.model.TypeRef) FileOutputStream(java.io.FileOutputStream) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) 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)

Example 83 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.

the class PageProcessor method produceRefExtensions.

private String produceRefExtensions(ResourceDefn resource) {
    int count = 0;
    Map<String, StructureDefinition> map = new HashMap<String, StructureDefinition>();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean refers = false;
        for (ElementDefinition ed : sd.getSnapshot().getElement()) {
            for (TypeRefComponent tr : ed.getType()) {
                for (UriType u : tr.getTargetProfile()) if (u.getValue().endsWith("/" + resource.getName()))
                    refers = true;
            }
            if (refers)
                map.put(sd.getId(), sd);
        }
    }
    StringBuilder b = new StringBuilder();
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId().toLowerCase() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    if (count == 0)
        b.append("<tr><td colspan=\"\3\">No Extensions refer to this resource</td></tr>");
    map.clear();
    for (StructureDefinition sd : workerContext.getExtensionDefinitions()) {
        boolean refers = false;
        for (ElementDefinition ed : sd.getSnapshot().getElement()) {
            for (TypeRefComponent tr : ed.getType()) {
                for (UriType u : tr.getTargetProfile()) if (u.getValue().endsWith("/Any") || u.getValue().endsWith("/Resource") || u.getValue().endsWith("/DomainResource"))
                    refers = true;
            }
            if (refers)
                map.put(sd.getId(), sd);
        }
    }
    b.append("<tr><td colspan=\"\3\">Extensions that refer to Any resource</td></tr>");
    for (String s : sorted(map.keySet())) {
        StructureDefinition cs = map.get(s);
        count++;
        b.append("  <tr>\r\n");
        String ref = cs.getUserString("path");
        b.append("    <td><a href=\"").append(ref).append("\">").append(Utilities.escapeXml(cs.getId())).append("</a></td>\r\n");
        b.append("    <td>").append(Utilities.escapeXml(cs.getName())).append("</td>\r\n");
        Profile ap = (Profile) cs.getUserData("profile");
        if (ap == null)
            b.append("    <td></td>\r\n");
        else {
            ImplementationGuideDefn ig = definitions.getIgs().get(ap.getCategory());
            b.append("    <td>for <a href=\"" + ig.getPrefix() + ap.getId() + ".html\">" + Utilities.escapeXml(ap.getTitle()) + "</a></td>\r\n");
        }
        b.append(" </tr>\r\n");
    }
    return b.toString();
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Profile(org.hl7.fhir.definitions.model.Profile) UriType(org.hl7.fhir.r5.model.UriType)

Example 84 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.

the class PageProcessor method genExample.

private String genExample(Example example, int headerLevelContext, String genlevel) throws IOException, EOperationOutcome, FHIRException {
    String xml = XMLUtil.elementToString(example.getXml().getDocumentElement());
    Resource res = new XmlParser().parse(xml);
    if (!(res instanceof DomainResource))
        return "";
    DomainResource dr = (DomainResource) res;
    if (!dr.hasText() || !dr.getText().hasDiv()) {
        RenderingContext lrc = rc.copy().setHeaderLevelContext(headerLevelContext);
        RendererFactory.factory(dr, lrc).render(dr);
    }
    return new XhtmlComposer(XhtmlComposer.HTML).compose(dr.getText().getDiv());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) DomainResource(org.hl7.fhir.r5.model.DomainResource) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer)

Example 85 with DomainResource

use of org.hl7.fhir.r4b.model.DomainResource in project kindling by HL7.

the class SourceParser method loadResource.

private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean isAbstract, boolean isTemplate, String t, boolean isInterface) throws Exception {
    String folder = n;
    WorkGroup wg = definitions.getWorkgroups().get(ini.getStringProperty("workgroups", n));
    if (wg == null)
        throw new Exception("No Workgroup found for resource " + n + ": '" + ini.getStringProperty("workgroups", n) + "'");
    File f = new File(Utilities.path(srcDir, folder, n + ".svg"));
    if (isTemplate) {
        File spreadsheet = new CSFile((srcDir) + folder + File.separatorChar + n + "-spreadsheet.xml");
        OldSpreadsheetParser sparser = new OldSpreadsheetParser("core", new CSFileInputStream(spreadsheet), spreadsheet.getName(), spreadsheet.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        ResourceDefn root;
        try {
            root = sparser.parseResource(isTemplate);
        } catch (Exception e) {
            throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
        }
        root.setAbstract(isAbstract);
        root.setInterface(isInterface);
        errors.addAll(sparser.getErrors());
        setResourceProps(n, wg, root);
        String sc = ini.getStringProperty("security-categorization", root.getName().toLowerCase());
        if (sc != null) {
            root.setSecurityCategorization(SecurityCategorization.fromCode(sc));
        } else if (!Utilities.existsInList(root.getName(), "Resource", "DomainResource", "CanonicalResource", "MetadataResource", "MetadataPattern"))
            throw new Exception("Must have an entry in the security-categorization section of fhir.ini for the resource " + root.getName());
        for (EventDefn e : sparser.getEvents()) {
            processEvent(e, root.getRoot());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
            context.getResourceNames().add(root.getName());
        }
        if (root.getNormativeVersion() != null || root.getNormativePackage() != null) {
            root.setStatus(StandardsStatus.NORMATIVE);
        }
        if (f.exists()) {
            parseSvgFile(f, root.getLayout(), f.getName());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        return root;
    } else {
        try {
            new SpreadSheetReloader(context, srcDir, t, version.toCode()).process();
        } catch (Exception e) {
            System.out.println("Error loading spreadsheet for resource " + t + ": " + e.getMessage());
        }
        new SpreadSheetCreator(context, srcDir, t).generateSpreadsheet();
        ResourceDefn rootNew = new ResourceParser(srcDir, definitions, context, wg, registry, version.toCode(), page.getConceptMaps()).parse(n, t);
        if (f.exists()) {
            parseSvgFile(f, rootNew.getLayout(), f.getName());
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(rootNew.getName(), new DefinedCode(rootNew.getName(), rootNew.getRoot().getDefinition(), n));
            context.getResourceNames().add(rootNew.getName());
        }
        setResourceProps(n, wg, rootNew);
        if (map != null) {
            map.put(rootNew.getName(), rootNew);
        }
        return rootNew;
    }
}
Also used : SpreadSheetCreator(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetCreator) EventDefn(org.hl7.fhir.definitions.model.EventDefn) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkGroup(org.hl7.fhir.definitions.model.WorkGroup) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) SpreadSheetReloader(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetReloader) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 DomainResource (org.hl7.fhir.r4.model.DomainResource)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 IOException (java.io.IOException)15 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)15 FileOutputStream (java.io.FileOutputStream)12 ArrayList (java.util.ArrayList)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Test (org.junit.jupiter.api.Test)11 Resource (org.hl7.fhir.r4.model.Resource)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 FileNotFoundException (java.io.FileNotFoundException)8 List (java.util.List)8 NotImplementedException (org.apache.commons.lang3.NotImplementedException)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)7 File (java.io.File)7 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)7