Written by Joe Cocuzzo, Senior VP of Report Writing Services - iatricSystems
Someone from Mid Columbia Medical Center in Oregon asked for a way to stop at a query only if a patient was "on coumadin." I am going to interpret that to mean any active PHA order for Warfarin (administration of the drug not checked, although you could add this if needed).
Since it is tip time, I thought I would show how you can write a generic macro that will go from any application to Pharmacy and check for an active order for a particular medication and return a flag if such an order is found. We will use the MEDITECH MAGIC "Z.link" utility to "open" PHA.
First we need to write a fake "holder" report in "Z" or "MIS" so our programming can be available from any segment. If we wrote our report in NUR, we would only be safe using the utility from NUR CDSs.
If you have ever noticed the "copying files to:" message you get when you file and translate a report in MIS or Z, that is an indication that the translator is making the object code available on every segment and therefore from every application.
Next we write a macro called "check"
We can make our code modular by breaking the macro into "submacros." By ending the code with a semi colon, we make it a program. When you call a program, you use %, then the name of the program, then one or more arguments in parenthesis, for example:
%Z.name.inversion("SMITH,JOE")
In our example, the program is %Z.zcus.is.warfarin.M.check and we are passing in the patient’s admission urn.
The program then returns a value from the last expression in the code, which in our example is the value of the variable OK. We put a 1 into OK if we find an ACTIVE (status = AC) order for Warfarin for the patient we are checking.
Inside the program the first argument (in this example it is the only argument) becomes the variable A.
We test for A before having the program do anything. Since the CDS filer will check the code by running it with no A argument, we can avoid bogus CDS "syntax error – file as draft" issues by testing for A and skipping all the code in the program when A is nil.
MEDITECH MAGIC has a utility program called %Z.link that will open any prefix to any data or dictionary file.
The general way you use the program is:
When your are working with prefixes "yourself," it is a very good idea to test your code in the TEST system first, before using it in the LIVE directory. Bad programming can crash and leave records locked when your macro runs from a CDS.
STEP ONE – "OPEN PHA"
First we need to "open PHA." When we are in Nursing, prefixes are "open to" NUR, ADM, and MIS, but not PHA.
Z.link goes over to the PHA segment and directory and opens the prefixes and then comes back to the segment it started from. This means that you can then get to PHA fields and dictionaries, but you need to be careful not to try to use any PHA fields that call PHA programs or you will likely crash. This is because the PHA programs are only available in the PHA segment and directory (and the NPR master segment) and you might call the Z program from some other segment.
PHA.combo.dose.and.unit is an example of a field that calls some PHA program, see the %PHA.RX program call in the VAL column that is your tip off:
STEP TWO "CHECK ORDERS"
To check orders, we need to make sure that all the PHA fields we use translate using the one prefix (:) that we opened to the PHA data file with the Z.link program. Looking at the date definition we can see that indexes translate with :, which is fine, but data fields use ? which won’t work. The @Chg.prefix translator macro will fix this.
This code uses an index by patient ADM urn, status, and order type, so we can put the patient’s admission urn into PHA.RX.patient, and "AC" (that is the status of PHA active orders) into PHA.RX.status and then loop through just the active orders for just the one patient and then check the generic of each @med to see if we have any active orders with Warfarin. Just change the generic mnemonic to the value used at your hospital.
I try very hard to avoid writing any reports in PHA with hardcoded drug mnemonics, as these change quite often and your report will "break" because you won’t add new ones. This is why I opened the PHA dictionary file as well, so I could go from the @med field on each order over to the generic to select based on a value which changes far less often. There is usually just one value, although nothing prevents a site from creating multiple different generic mnemonics for what is actually the same medication.
If the medication you are looking for might be a compound, split, or IV with additives, the @med field based selection would fail. Since Warfarin is not that kind of medication, we can just check @med’s.generic and be fine.
STEP THREE "CLOSE PHA" (put everything back or else!)
After we check PHA, we need to be very careful to restore : and &, otherwise we will likely crash back in NUR. The "CLOSE.PHA" macro does this as follows:
We used the C(:S) "close and stack" syntax to save the value of our prefixes to "the stack".
If we use C(:U) we restore the prefixes to their previous state (typically open to the previous file).
It may seem funny to use a "Close" command and have a prefix be Open, but these two comands do just the same thing C(:U) O(:U). The advantage of using C is that the syntax checker does not complain.
To use our utility macro from an IFE, we attach it like this:
If we select a patient with an Active PHA order for Warfarin, the cursor will stop at the "IAT.WARED" field, because our utility program returns a value if such an order is found.
A copy of the Z report has been added to our MAGIC report library. Z.zcus.is.warfarin
http://www.iatric.com/Information/NPRReportLibrarySearch.aspx
Make sure you change the PHA database in the "check" macro to match YOUR HOSPITAL, and the generic mnemonic to match what you use. Otherwise the utility is generic and will work at any MAGIC site.
You can find additional Report Writing Tips on our website at http://www.iatric.com/Information/NPRTips.aspx, as well as information about our on-site Report Writer Training and Report Writing Services.
To subscribe for email notifications for new Report Writing classes, please follow this link:
http://www.iatric.com/Information/Classes.aspx.
For more information, please contact our NPR report writing team at reportwriting@iatric.com.
This article originally appeared in the November 2014 issue of Iatric Systems Updates! newsletter.