Report Writing

Interoperability and EHR Optimization

Privacy and Security

Type-Ahead lookup (MAGIC Only)

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

It is possible to create a lookup field on an NPR report that exploits a “type-ahead” Z program available in MEDITECH MAGIC. The program works in both the 3.x and 4.x versions of the MEDITECH Remote Workstation. You get <OK> and <CANCEL> buttons if you are in the 4.x version.

“Type-ahead” behavior is useful if you want to zero in on the appropriate values rather than enter a partial value and then press the F9 key and hunt down or up the list.

As an example, we will create a report that does a “type-ahead” lookup on user names.

First, create a simple report in the main segment (mis.users) of the MIS.USER dictionary and add two select fields:

January Tip 1

Next, write a macro as a program and call the MEDITECH program in that macro.

For this report we call the macro “id” so the program is
There are a lot (A – R) of arguments that are documented at the top of the program, but here is what we pass:

A = ^/GUN or the “name of” the name index.
B = A (the value that the user entered in the report screen)
C = “Name”:30TL_” Mnemonic” this is the header we want per screenful of lookup entries
D = MN:30TL_”_D(34)_” “_D(34)_CD:41TL” or the line of code that will display each entry MN = the name subscript CD = the mnemonic
E = “AR” the lookup options (A for Active Only R for Reject New Entries)
F = “Users by Name”:50TL our title for the lookup window . Note that the length of the string determines the width of the lookup window. If you make it too narrow your data will wrap.
G = Number of lines “down” to start data listing
H = Q(30,0,0,””) Length of select prompt and start row and column
I = If true, show exact matches only
J = If true the structure is an index (we send 1 here as \GUN[lookup name, mnemonic] is the name index in MIS.USER)
K = If true the structure is a dictionary (we send nil here as \GUN is not a dictionary)

Our macro code (first line is broken here so the entire line is displayed):

January Tip 2

When we call the program, it returns the mnemonic of the selected entry, and we store that in /SELECT so that the report knows which user to print.
We return both the mnemonic and name, so both display in the free text prompt.

If we enter a partial name and hit the F9 key:

January Tip 3

We get a lookup which has type ahead behavior and we can add to the string to narrow down to the value we want to pick:

January Tip 4

A copy of this example report, has been posted to our MAGIC NPR report library.


The program has documentation of arguments as comments at the top of the program, as is typical of most NPR procedures. To view them, use the F4 key in a macro and then enter \ and the name of the procedure. A lookup is available of procedures. You can use the same technique to copy the source code of programmer NPR R/W macros, except that (in MAGIC only) you need to type the name of the macro exactly. In Client Server you can use the F5 key then enter the DPM, enter M<space>procedure name and get a lookup of macro names.


Topics: MEDITECH MAGIC, NPR Report Writing Tips, Report Writing Tips and Tricks, MEDITECH Remote Workstation,, Type-Ahead lookup

Subscribe to the Report Writing blog.

Receive the latest articles directly in your inbox.
Enter your email address and click SUBSCRIBE: