Written by Joe Cocuzzo, Senior VP of Report Writing Services - iatricSystems
A BAR analyst from a C/S hospital posted a request to the "Meditech-L" mailing list, asking for help in including the last billing comment and last billing comment date on a BAR.PAT report.
MEDITECH had provided code to loop back through the transactions and get the last "c" type transaction and then get the date, but this would stop on system comments also. MEDITECH also tried to provide code to get the comment itself, but the logic provided was not quite correct.
There are two issues to overcome for this report:
Step one is to take a look in a billing system and see what system comments look like, so we can figure out which transactions to exclude from our logic that will "back up" to the most recent comment made by a human, vs. the comments from automatic stuff in B/AR.
Even those of us that write NPR reports all day don’t exactly recall what system vs. user comments look like, so we write a quick report at the transaction text level to see what things look like; we need to write our quick report here:
Our quick report just gets some accounts and shows us all the "c" type transactions:
So, how do we write some computed fields or attributes or macro code to get the last "real" comment date, and the comment text from that comment?
First, the date, we go "backward" (@Prev goes from largest to smallest transaction urn) until we hit a "c" type transaction where the user is anybody but BKG DAEMON. Hang on to the txn urn in the variable FND, which also serves as a flag to stop our backward looping.
[MAGIC Users Please Note:
In MAGIC, it appears that comments from automatic processes have the user that happened to start the BAR background job, so you’d need to do some more sophisticated screening of system stuff than you need to do in C/S. Possibly looking at @txn.comment for "NSD" and other automatic comments would work.]
Note that at the end of this loop, FND holds the @txn.urn we want and txn.urn is one less than that transaction, because the @Prev happens one more time before we check FND and stop looping because it has a value (i.e. NOT FND no longer true).
Now we need to write some code to show all the transaction text for the comment. We could build an MV array and load it with the transaction text, but then you either have to use a utility to keep the field number subscript dynamic and unbreakable (highly recommended) or hardcode a field number and take the risk that an edit could break your report. Instead, lets write one computed field for the first text line, and wrap a DO loop around a second computed field to handle the rest of the text lines.
The first comment line is a simple computed field that just uses the txn.urn from FND and has a hardcoded 1 to print the first line
For the rest of the lines, we wrap a loop around a second "D" line as follows:
The field to print line 2 through N is:
So our report written at the "top" (main) level is now smart enough to go through the transactions in the child segment and find the last comment, then go through the text in the grandchild segment and print the lines out.
I have added a horizontal line between accounts to make output clearer:
A sample report, in MAGIC and C/S BAR.PAT.zcus.is.last.comment.and.text has been placed in our report library.