iPACS reporting: Generating PowerPoint Presentations

iPACS reporting: Generating PowerPoint Presentations

After a VivoScript has been run, it is often useful to organize its output in a single document that can be used for a quality control check or to present the results. This is especially helpful in compiling many results into one document–reporting tools can loop through a study with hundreds of datasets and compile their relevant results into a single document, saving you a lot of time. You may be familiar with VivoScript reporting tools that create PDF presentations or XLS spreadsheets, but did you know you can also generate Microsoft PowerPoint Presentations from VivoScript? Keep reading for an overview of how it works and a few examples of cool features that give you a lot of freedom to control formatting, hyperlinks, and more in the resulting presentations.


How It Works

Just as VivoScripts can generate LaTeX files which can be used to produce PDFs, VivoScripts can generate Template Toolkit files that can be used to create Excel Spreadsheets or PowerPoints. Template Toolkit, which uses the filename extension *.tt, provides instructions for generating a report on the iPACS. Using the iPACS API, you can upload a VivoScript-generated *.tt template to a repository and run the reporting engine to generate a PowerPoint. The very first line of the template specifies what kind of report is being generated: in this case, it is a PowerPoint presentation. Here, we set up the working directory for the paths that the template will use in subsequent iPACS queries, and supplies a PowerPoint that already exists from which to take formatting and layout. Notice that an underscore is used for concatenating strings.

[% MODE=pptx %]
project = '/software/blog-examples';     # the iPACS path of the project
base = '/projects'_ project;             # add projects to the beginning of the path
PPTX.cwd(base);                          # set the working directory to which all subsequent paths will be relative
PPTX.unit('Inches');                     # set a unit for formatting
PPTX.template('SlideMaster.pptx');       # a PPT slide master for the layout, style, and background of the generated PPT

Look here for instructions on how to create a slide master (it’s in View>Slide Master). You will need to create the slide master and provide its path on the iPACS to the template in order for the template to grab formatting, header styles, and other PowerPoint attributes from it. This way, you can make style changes, such as setting a background image, to the slide master within PowerPoint and immediately see what they will look like, and will only use Template Toolkit commands to supply content and specific layout instructions.

Once you have set up your iPACS path and slide master location, it is time to start adding slides!

	layout => 0,
	title => 'Example Generated PowerPoint',

Each slide has a layout and a title. The layout comes from the way that formatting works in PowerPoints–when you were creating your slide master, did you notice the different kinds of slides described by the master?

To indicate which kind of slide you are creating, use its index in the list of slides in the slide master. Here, we are creating a title slide, so we use the first one.

Next, let’s add a more interesting slide with content from the iPACS.

WebDisk.scandir(base, '(.*).(jpg)', 'name ext');  # grab all files satisfying the filter and keep track of them in resultScanDir
FOR result IN WebDisk.resultScanDir;              # retrieve the file names found during the scanDir
		layout => 1,
		title => 'Adding ' _ result.name _ ' from the iPACS to a slide',

	img_path = result.name _ '.' _ result.ext;

	left_pos = 0.5;
	top_pos = 1;
	txt_height = 0.5;
	margin = 0.5;
	img_height = 5;

		filename => img_path,
		left => left_pos,
		top => top_pos,
		height => img_height,

		text => 'Here is picture ' _ result.name _ ' from the iPACS',
		'font.size' => '\Pt(16)',
		left => left_pos,
		top => top_pos + img_height + txt_margin,
		height => txt_height,
		alignment => '\PP_ALIGN.LEFT',

This slide will contain text and an image that is on the iPACS. We use WebDisk.scandir to access files from the iPACS and insert them into the PowerPoint. WebDisk.scandir looks for files matching a particular pattern at the given iPACS location, and keeps track of them in resultScanDir. You can then loop through all files matching that pattern, and access values from within the filename using variable names you specified as part of your filter. In the example above, all filenames with extension .jpg will be in resultScanDir. We can then add the filename without the extension to text on the slide because we set up our filter to put all the characters before .jpg in the variable `name`. To add the picture itself to the slide, we give it the whole filename, keeping in mind that this path will be relative to the working directory supplied at the beginning of the template.

In this example, the files are all in the same project on the iPACS.

Screenshot (100)

It is also useful to note the way that variables are used in this example to specify locations within the slide. It is much easier to use variables like this so layout can be adjusted simply and you do not have to recalculate where every item should go if you want to change the size of the image.

Another cool feature of the PPT reporting template is that we can add hyperlinks.

	text => 'Open the image',
	hlink => 'https://demo.ipacs.invicro.com/publiclink/dl/000000000',
	'font.size' => '\Pt(16)',
	left => left_pos,
	top => top_pos + img_height + margin + txt_height + margin,
	height => txt_height,
	alignment => '\PP_ALIGN.LEFT',


`END` closes the for loop cycling through the images found by WebDisk and `printAll` generates the PPTX.

The public link added as a hyperlink to the PowerPoint will allow you to click it to see the image on the iPACS.

Generating templates from VivoScripts

This is where VivoScript comes in! If you use VivoScript to generate the Template Toolkit file, you can make sure that all the filenames and template variables are in sync to achieve some pretty cool things. It’s easy to create a file from VivoScript:

var outputDir = //local dir
var wdDir = //iPACS dir

VQ.writeFile(outputDir + "Report.tt", createPPTXTemplate("https://demo.ipacs.invicro.com", wdDir));
WD.put(outputDir + "Report.tt", wdDir + "Report.tt");
function createPPTXTemplate(iPACSName, proj) {
	var text = 
	"[% MODE=pptx %]\n" +
	"[%\n" +

	"project = '" + proj + "';	# the iPACS path of the project\n" + 
	"base = '/projects'_ project; 			# add projects to the beginning of the path\n" +
	"PPTX.add_link(\n" +
	"	text => 'Open the image';\n" +
	"	hlink => '" + iPACSName + "/publiclink/dl/'_id;\n" + 
	"PPTX.printAll;\n" + 
	return text;

Because you are creating the template in VivoScript, you can now give it the same info that you used to create images and other results. You have given the template the same working directory within which you created your images by writing that variable from your VivoScript into your template, so if you create the image from your VivoScript using the relevant information:

MW.saveImage(outputDir + "/" + name + "_" + publiclink + ".jpg", 4);

…you can grab that file using WebDisk.scandir and use it to dynamically link to the image from a public link in a PowerPoint, as shown above.

Once your template has been generated and is on the iPACS as a .tt file, you can generate its PowerPoint by right clicking on it and choosing “Process”. Here is a slide from the example created in this post: