Generating Reports in Eclipse Visual Scripting
An underutilized component of the Eclipse Treatment Planning System is Visual Scripting, specifically the reporting capabilities offered by the included Visual Scripting Action Packs. While I cannot provide here a complete introduction to the reporting action packs in this post, I do want to build a sample report that you can use to test the ideas below. For more information on Visual Scripting, refer to the Varian API Book and the Visual Scripting webinars on My Varian.
To begin, open a patient in Eclipse and ensure that a plan with a structure set and calculated dose is loaded. Arrange the orthogonal views and 3D structure view so that the view ports are mostly filled and centered. Open the DVH view port and then right click to show the menu. Select "Show DVH on white background."


Notice that the context window is wider than usual. This is so the embedded screenshots will look nicer in the report. You will have to adjust this for best results.
Open the Visual Scripting application from the Tools menu. Pull in the PlanSetup and Begin Report, To Table, To Report, Embed Screenshot, and End Report action packs as shown in the screenshot below.

Click the i in the center of the To Table Action Pack. This opens the DesignTimeDetails for the To Table action pack. For simplicity, we will use the Add Default values to build the table rows. Click on the Custom radio button and enter a title for the table (Plan Information).

Click the i on each Embed Screenshot Action Pack and enter an appropriate image caption (Orthogonal View and DVH). When the Visual Script runs, the Embed Screenshot runtime window will show the caption. Remember to adjust the view ports for the correct screenshot before capturing.


Run the Visual Script by clicking on Menu then Save and Execute in Eclipse. Give the script a name (Sample_Table_Report in this example) and follow the prompts. You will need to choose a location and save the report, then capture each of the screenshots. When the script finishes, the PDF of the report should open for inspection.
The Default Report Style
Below is a screenshot of the beginning of the generated report with the default styling. There is nothing wrong with the report, but it does have some deficiencies I'd like to improve. Briefly, the report starts with the word Report, which isn't very descriptive and is just taking up extra space. The table has the Plan Information title that we entered, but the table border is bland. I don't like that the row labels (Course ID, Plan ID, etc.) are the same font as the row values.

An Accidental Discovery
Create ESAPI Project
One way to attempt to change the report style is to convert the Visual Script to an ESAPI project. This is done by clicking on Menu, then Export, then Create ESAPI Project. This doesn't reveal too much new information because overriding the default behavior would have been harder than creating a full ESAPI report from scratch.
"If the generated project requires an html to pdf library, can I inject html tags into the report somehow and change the style?"
However, in the created ESAPI project folder there is a required library wnvhtmltopdf.dll. A light bulb moment: "If the generated project requires an html to pdf library, can I inject html tags into the report somehow and change the style?"
So, I tried.
First Attempts
You may notice that the To Table DesignTimeDetails View allows the user to enter free text. I tried entering something simple.
<b>Plan Information</b>
This should make the table caption bold.

Voila! Success!

Now that we know we can add some html tags to the free text portions of the Visual Script, let's see just how far we can go.
In the To Table DesignTimeView, add a paragraph tag before the bold tag:
<p>Patient plan report for GatewayScripts Hospital</p><br/>
The <br> tag should add a line break before the table caption.
Let's also add some styles to the table row labels. See the screenshot below with the i, u, and span with a style attribute for effect. Try different styles to meet your need.

Here is a screenshot of the resulting report. The paragraph below has been inserted, the requested styles have been added to the table rows, and the Total Dose color is now green. Excellent!

Another Accidental Discovery
Crashing Visual Scripting
During a recent Visual Scripting Immersion Clinical School class, we built a Visual Script using the ForEach action pack. The Visual Script crashed because the End Report Action Pack was not able to find a needed file. We don't need to show the details of the Visual Script, but we need to examine the files that were left in the output folder after the crash.

As can be seen from the screenshot, there are files created in the output folder, reportstyle.css, footer.html, and Report_xxxxx.html (The xxxxx is a random string generated by Visual Scripting). Inspecting the Report.html file, we can see that the report is using the reportstyle.css file to style the report. We can also see where the word Report is being generated.
Inspecting the reportstyle.css we can see that the Boostrap V3.3 library is being used for the styles. We will refer back to this below

Styling HTML with CSS
This blog does not have enough space to go into the details of HTML and CSS. Fortunately, we only need to know that HTML will respect the most recent styles that it finds in the HTML file. This means that we can override properties defined in the reportstyle.css file by adding our own styles further down in the body of the html. We can add that style in the custom caption for the first table we define, then our styles will be applied to all elements we choose to style.
We can override properties defined in the reportstyle.css file by adding our own styles further down the body of the html.
Let's see if we can remove the word Report at the top of the report. Notice that the Report.html use the h1 tag to style the word and it only uses the h1 tag here. We can override the h1 tag like so

Another Success! By making the font-size equal to 0px the word Report, while still technically there, is gone from the report

Better Tables
You will notice that each time we add more characters to the report caption the width of the DesignTimeDetails view expands. Eventually we will run out of space to see everything. Let's move our styles to a new .css file.
To do this properly, in the folder where you will always save the final report (my folder is Reports on a shared network drive) create a folder called css and a folder called img. We will use the img folder below. For this to work, you must always save reports in this same folder. You can move the final PDF later.
While we are at it, download the Bootstrap v3.3 minified CSS file and add it to the css folder as well. Using Bootstrap will help us keep a consistent look for the final report parts. In the screenshot below, see the contents of MyStyle.css. Examine the image as each section is explained below

Lines 1-4 are the CSS definition to remove the word Report. Instead of overriding all h1 tags this code only overrides the h1 with the class page-header which is contained in a div with a class col-md-12 which is defined in a div with a class row which is contained in a div with a class container. It helps read the style from left to right.
Line 5-8 override all h2 tags. This allows us to write Table Caption in the custom table captions and they will all be styled the same. We don't have to worry about adding the b tag each time. You could also change the font-family, but I like this font.
Line 9 - 11 override all table elements that also have a class of table to remove the border.
Lines 12-20 override the th (table header) elements contained in a table element that also has a class of table and a class of table-bordered and a class of compact. This same structure is used for the tr (table row) and td (table cell) elements (lines 21-33).
Line 34-36 tells the HTML parser to make every odd number row in a table to have a background color of LightGrey. This is not a necessary styling. I think it is fun. And shows that you can use more complicated CSS to adjust the styles.
Finally, in lines 37-48, I am styling the images and the h3 element which acts as the caption for the images.
To use these new styles, we have to tell the HTML where our styles live. In the To Table custom caption add the following:

Printing the report, we can see the newly formatted tables, headers, and images.

Final Touches
Adding a Header with a Logo
The report is looking a lot nicer than the original, but we got rid of the header (the word Report). Now let's add a new header with a logo to the report. (I like the default footer, so I'm not going to change it here.)
In the reports folder where you created the css and img folders, add a file named Logo.html. The screenshot below shows the contents of the file.

Logo.html is a simple HTML document that uses the Bootstrap css file we saved to the css folder above. The body of the html file is a div with a centered report title of Patient Plan Report. Next, there is a table with two columns. The first column is an image of the logo we want to use in the header. The second column is the name of your hospital or department. While I have used the default style for hospital name and department, you could style these as well to match your hospital branding.
The logo image will be read from the img folder that we created above. Be sure to change the name of the image to your logo and put your logo in the corresponding folder.
Adjust the Sample_Table_Report Visual Script
We need a place to add the Logo.html file in the report. It makes sense to have the header, then the patient information. Adjust the Visual Script to match the screenshot below.

Add the Patient element and connect it to the new To Table element. Add a properties element to get the Beams from the plan. Finally, add a ScriptContext element and select the CurrentUser as the return value. Wire the elements as shown. You don't need to add the comments.
Embed the Logo.html File
In the same way we added our stylesheet with a link element, we will add the Logo.html page with an iframe element. The iframe needs to be styled so that the border is hidden, the scroll bars are not visible and it is centered on the page property. The styling can be done in the MyStyle.css file, but here it is shown how to do it in the ToTable caption. You can see that the row labels have been styled to bold.

Embed the freeText.html file
We are not limited to just one iframe element. That means that we can add any number of unique parts, defined as html files, to the report. However, we won't be able to pass any variables to the html in the iframe. Thus, the utility is limited. If, on the other hand, you need to add text that is always the same across reports, this method works quite nicely.

The image above shows the freeText.html file contents. This is another simple HTML document containing one paragraph element. This html file is added in the same way as the Logo.html file above. I put it into the ToTable caption for the current user. The screenshot below shows the beginning of the report with the logo. The full final report PDF is linked at the end.

The Final Report
The Report
The Folder Structure

About the Author
Dr. Haywood is a clinical medical physicist at True North Medical Physics. During his tenure, he has developed software for plan reviews, data mining, and electron Monte Carlo second checks using a variety of programming languages like Python, SQL, C#, CUDA, and OpenCL. He is currently developing a pre-initial physics review script that is compliant with MPPG 8a using a combination of Aria Web Services and ESAPI. He is eager to exchange knowledge with all.

Comments