Often, in analytical applications, users need to periodically generate and send PDF reports consisting of elements of an analytical panel. In the development on the InterSystems technologies this task is solved by the DSW Reports project, which is an extension of DeepSeeWeb. This article will describe how to use DSW Reports to generate PDF reports and send them by e-mail.
An integral part of the InterSystems IRIS Data Platform is the technology for developing analytical applications of the InterSystems IRIS Business Intelligence (formerly known as DeepSee). There is a separate project DeepSeeWeb , which uses a more modern web-interface (AngularJS) for visualizing Dashboards InterSystems IRIS BI. To communicate with the server side, DeepSeeWeb uses MDX2JSON , a project that provides REST API access to InterSystems IRIS BI.
About DeepSeeWeb and MDX2JSON we already wrote in articles one and two .
DSW Reports is a DSW extension written in AngularJS that implements the basic functionality for automatic report generation. DSW Reports uses DeepSeeWeb to render widgets and MDX2JSON for processing MDX requests.
To generate a report in DSW Reports, it is enough to create at least 2 files:
The report configuration file must contain the getConfiguration function.
// function getConfiguration(params){...}
The getConfiguration function accepts a params object, which contains parameters from the URL string and the optional " server " parameter, which is the server address. The " server " parameter has the form: protocol://host:port
.
Thanks to the params object, you can report any data to the report via a URL string. For example, if you want to change widget filters as desired, then we pass the " filter " URL parameter and it will be accessible via the params object.
//<protocol://host:port>/dsw/reports/report_dir/index.html?filter=NOW function getConfiguration(params){ var filter = params["filter"]; // filter = "NOW" }
The getConfiguration function returns an object containing 3 properties:
Let's take a closer look at an array of BLOCKS blocks. Block - an object with the settings of the widget, the settings of the calculated fields, etc.
{ "title": String, // "note": String, // . HTML "widget": { // iframe : "url": String, //URL iframe "height": Number, // iframe "width": Number // iframe }, "totals":[{ // MDX "mdx": String //MDX- "strings": [{ // "title": String, // . HTML. "value": String, // "value_append": String, // . // %, $ .. //% (x * 100). // HTML. "row": Number // MDX-, // . // 0. },{...}] },{...}]}
All fields are required if the field is not better to set it as a blank line.
{ title: "Persons", note: "", widget: { url: server + "/dsw/index.html#!/d/KHAB/Khabarovsk%20Map.dashboard" + "?widget=1&height=420&ns=" + namespace, width: 700, height: 420 } }
{ title: "Khabarovsky krai", note: "Something note (only static)", widget: { url: server + "/dsw/index.html#!/d/KHAB/Khabarovsk%20Map.dashboard" + "?widget=0&height=420&isLegend=true&ns=" + namespace, width: 495, height: 420 }, totals: [{ mdx: "SELECT NON EMPTY " + "[Region].[H1].[Region].CurrentMember.Properties(\"Population\") ON 0,"+ "NON EMPTY {[Region].[H1].[Region].&[]," + "[Region].[H1].[Region].&[--],"+ "[Region].[H1].[Region].&[ ]} ON 1 FROM [KHABCUBE]", strings: [{ title: "Khabarovsk: ", value: "None", value_append: " ." }, { title: "Komsomolsk-on-Amur: <br />", value: "None", value_append: " .", row: 1 }, { title: "Komsomolsky district: <br />", value: "None", value_append: " .", row: 2 }] }] }
The main fields for filling in the block are the url for the widget settings and mdx for the calculated values settings.
Along with the report libraries, a style.css file is supplied that allows you to edit the appearance of the report. It contains a standard set of classes that controls all elements of the report. You can also add your own style classes and use them in the index.html file.
Suppose the report is ready and placed in the report folder in DeepSeeWeb. Those. An interactive HTML report is now available by reference. What should I do to convert it to PDF and send it by mail? This will be automatically done by pthantomjs and the built-in SMTP client. How to install and configure phantomjs can be found here ( windows , ubuntu ). Next, you need to configure the SMTP client and create a task in the Task Manager .
All settings are made in the terminal.
// SMTP do ##class(DSW.Report.EmailSender).setConfig(server, port, username, password, sender, SSLConfig)
// do ##class(DSW.Report.EmailSender).addRecipient(email) // do ##class(DSW.Report.EmailSender).deleteRecipient(email)
// do ##class(DSW.Report.Task).Run(url, reportname)
To automate the distribution we will use the Task Manager . Create a new task with the following parameters:
Everything, after all these manipulations, we have got an auto-generated report consisting of DeepSeeWeb widgets, which at a given time is sent by mail in the form of PDF.
→ An example of the finished report can be found here.
→ The configuration file of this report is available here.
→ And here you can subscribe to weekly report delivery.
→ Link to repository
Source: https://habr.com/ru/post/419433/