Blogs Home
Saturday, March 20, 2010 5:37 PM

Collated Copies from NPR report (MAGIC or C/S)

Written by Joe Cocuzzo, Senior VP of Report Writing Services - iatricSystems

In MAGIC you can send the HP number of copies command, and in Client/Server you can request a number of copies in the print dialog. This gives you Page 1, Page 1, Page 2, Page 2 when you ask for two copies, which is easy for the printer, but annoying for anyone who wants sets.

This month we will show you an easy way to get collated output out of a multi-page report.

It is possible to split your report into a main report and a fragment and call the fragment the required number of times to get collated output, but this amounts to multiple compiles and that is not very efficient. Additionally, you would need to build the page header in the 'main' report and the output in the fragment, and if you have a page break on a sort field things get ugly.

A better method is to manipulate the temporary sort file to produce a desired number of copies. Here's how:

1) Add a computed sort field as the very first sort field. Set the value of the computed sort field to 1

2) Prompt the user for the desired number of copies. In our example report we create a computed select field with the "IG" operator and we make the select field integer with a length of 1. That prevents the user from asking for more than nine sets, which is probably a good thing as there is an invention called the "copy machine" which is usually a less expensive duplication technology than the HP/Canon invention called "overpriced toner cartridge".

3) Create a macro that runs at the very start of the report to 'expand' the temp file to create a complete new set of entries per each collated copy requested.

Here is a demonstration report that prints patients by location with a page break on the location field:

Shot 1

Setup a "fake sort (xx.sort)" and prompt the user for a number of copies (xx.copies) with IG

With the "fake sort", the temp file will look like this after your records are compiled. The first sort is 1 for the entire temp file, as when the report writer looked at xx.sort with VAL=1, it was the same value for all records as the temp sort file was built.

To get multiple copies, we just loop thru all the entries with xx.sort =1 and create matching entries with 2 (for second copy) 3 (for third copy), and so on.

To change the temporary file, we call a macro AL HP with a flag so that we only expand the file once.

The client server code for the "page" macro looks like this:

In MAGIC, the temp file gets swapped to the disk when the size of the file hits a certain (MIS parameter driven) number of records. In our MAGIC code, since we probably do not want to expand a temporary file for a compile that large, we do not expand the temporary file if we have exceeded the maximum records that are allowed to compile in the memory based temporary sort file.

If we run for 2 copies, we see that the number of pages doubles (in my test example from 15 to 30 pages) and at page 16 we see the first page of the second collated set of pages:

The example report for both C/S and MAGIC has been placed in our report library.