BLOGS
EASY SUBSCRIBE


Report Writing

Interoperability and EHR Optimization

Privacy and Security

Some unusual but useful MAGIC syntax—the “U(nqueue) function and a little known syntax for queuing.

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

A long time customer recently emailed me for help to put “the CPT/HCPCS codes” on a Billing/Accounts Receivable (BAR) export. Before even looking at her report, I knew that she either was failing to establish the alt.code.type or failing to establish the alt code effective date.

The problem is that there is no single “alt code” for a Billing Procedure, but a set of alternative codes stored by type and effective date. Before you can get “the CPT code” you need to have the correct value in the type subscript and the correct value in the effective date subscript. Many of you have learned to write a computed field similar to this to retrieve the alt code from the BAR.PROC dictionary.

NPR Image 1

(This code is from a MAGIC site, but would be identical for Client/Server.)

The code establishes the alt.code.type (CPT-4) by assigning that value to the dictionary subscript, then adds 1 to the transaction service date of the charge and then “backs up” to the effective date (with @Prev) that is the largest value not after the service date. Adding 1 is a cheat that takes advantage of the fact that if your service date was, for example, 20120331, you can just as easily back up from 20120332 as from 20120401.

When I connected to the hospital, I went to the BAR charge dictionary to check on the alt code mnemonics the site had created, so I would be sure to use the appropriate code and saw that there were multiple HCPCS mnemonics to choose from:

NPR Image 2

Let’s assume that we want to check the set of alt code types in the following sequence and take the first alt code we find that has an effective date on or before the transaction service date.

CPT-4,HCPCS,HCPCS MCD,HCPCS MCR,HCPCS MOD,HCPCS MRO

My assumption is that the general alt code type CPT-4 is best, followed by HCPCS, then followed by what looks like some payor specific variants.

One way to code this would be as follows:

 “”^CPT,
 <a href="http://twitter.com/#!/@txn">@txn</a>.procedure^BAR.PROC.mnemonic,
  “CPT-4”^BAR.PROC.alt.code.type,
 <a href="http://twitter.com/#!/@PROCESS">@PROCESS</a>,
  IF{‘CPT “HCPCS”^BAR.PROC.alt.code.type,
 <a href="http://twitter.com/#!/@PROCESS">@PROCESS</a>},
  IF{‘CPT “HCPCS-MCD”^BAR.PROC.alt.code.type},
 <a href="http://twitter.com/#!/@PROCESS">@PROCESS</a>,
  ..etc..
PROCESS
 <a href="http://twitter.com/#!/@txn">@txn</a>.ser.date+1^BAR.PROC.alt.code.eff.date
 <a href="http://twitter.com/#!/@Prev">@Prev</a>(BAR.PROC.alt.code.eff.date),
 IF{<a href="http://twitter.com/#!/@BAR">@BAR</a>.PROC.alt.code BAR.PROC.alt.code^CPT}

This ends up being a lot of typing because we have to put each of our set of values into BAR.PROC.alt.code.type and look for the alt code.

We could make a little temp dictionary of the alt codes in slash, subscripted by our desired sequence number, and loop on them, but it is easier to queue them into a “queued string” and then use the U() [unqueue] function in a DO loop to process them in the desired order.

There are three syntaxes for queuing and we will use the least known syntax because it is the most compact and convenient for our coding need in this example.

The following three lines of code do exactly the same thing:

Q(“CPT-4”,”HCPCS”,”HCPCS MCD”,”HCPCS MCR”,”HCPCS MOD”,”HCPCS MRO”)^x
  {“CPT-4”,”HCPCS”,”HCPCS MCD”,”HCPCS MCR”,”HCPCS MOD”,”HCPCS MRO”}^x
  `CPT-4,HCPCS,HCPCS MCD,HCPCS MCR,HCPCS MOD,HCPCS MRO'^x,

The first line uses a Q() command

Like all MAGIC commands except IF and DO, the “Queue” command is a single letter “Q” and the arguments are the strings we wish to queue, separated by commas. We could actually spell out the command, but you never see this in real code:

QUEUE(“CPT-4”,”HCPCS”,”HCPCS MCD”,”HCPCS MCR”,”HCPCS MOD”,”HCPCS MRO”)^x

(We could even do QUIGLEY(“CPT-4”,”HCPCS”) as the interpreter only pays attention to the first letter of the command.)

The second method saves one keystroke, using curly braces around the values to queue:

{“CPT-4”,”HCPCS”,”HCPCS MCD”,”HCPCS MCR”,”HCPCS MOD”,”HCPCS MRO”}^x

This syntax makes a kind of sense, because you can both Queue and Unqueue into variables with curly braces:

This queues 1,2, and 3 into the variable STRING

  {“1”,”2”,”3”}^STRING,

This puts STRING|0 into A, STRING|1 into B and STRING|3 into C

STRING^{A,B,C}

For our purposes in this example, we use the third syntax, where we use a left and right single apostrophe to automatically quote and queue a set of values. Even subtracting for the time it takes to find the left apostrophe on your keyboard, this is the most compact and easiest to write:

`CPT-4,HCPCS,HCPCS MCD,HCPCS MCR,HCPCS MOD,HCPCS MRO'^x,

Now we can write some pretty compact code in a macro to get the CPT code. We use the U() command to pop each of the values out of “x” (LOWER CASE!) from left to right. The Unqueue command removes the zeroth piece from the string each time it is executed.

Note the difference between using U() to get the pieces out of a queued string and using the | operator. The U() command takes the zero piece off of the string and removes it. The | operator leaves the string unaffected.

Using U allows us to build our string and then process each piece without coding for the total number of pieces we happen to have.

NPR Image 3

If you want to paste the code into your own report and modify the values to match your Alt code dictionary, here is the plain text:

""^CPT,
 IF{<a href="http://twitter.com/#!/@txn">@txn</a>.class="C" 1,
 <a href="http://twitter.com/#!/@txn">@txn</a>.ser.date+1^SDATE,
                    `CPT-4,HCPCS,HCPCS MCD,HCPCS MCR,HCPCS MOD,HCPCS MRO'^x,
                    DO{U(x)^BAR.PROC.alt.code.type 1,
                                                   IF{CPT;
                                                      SDATE^BAR.PROC.alt.code.eff.date,
 <a href="http://twitter.com/#!/@Prev">@Prev</a>(BAR.PROC.alt.code.eff.date),
 <a href="http://twitter.com/#!/@BAR">@BAR</a>.PROC.alt.code^y y^CPT}}}

Topics: U(nqueque), MEDITECH, MAGCIG, Client/Server, queuing, report writing, Report Writing Tips and Tricks, Newsletter

Subscribe to the Report Writing blog.

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

Comments

0 COMMENTS