I have this code which I placed in VFE's function view. It is supposed to add an order to read a TB test, but only if that order does not already exist in the current update (I don't want the order to duplicate). After some very thorough troubleshooting I can confirm the match(ORDERS_NEW("List"), "TB/TST Read") part of the code is indeed return a value greater than zero once that order had been placed. When I place the encounter on Hold and re-open it the order is being placed again so it seems like the order is being placed before the match part of the code can be read.
{
If (OBSNOW("TBARMPlace") "") and (match(ORDERS_NEW("List"), "TB/TST Read")==0) then MEL_ADD_ORDER("T", "Tuberculin Skin Tests (TST)", "TB/TST Read", "", "", "", "TST Read Due.", "1", "U", "", ADDDATES(str(._TODAYSDATE), "0", "0", "3")) and
userok("Order placed for TST Read. TST Read to be completed in approximately 72 Hours.")
else ""
endif
}
Any suggestions on how to fix this? I have tried placing this watcher statement above it in the function view {! match(ORDERS_NEW("List"), "TB/TST Read"} in my futile attempt at forcing it to read the match code as soon as possible, but that didn't work.
I'm not exactly sure what roll TBARMPlace has in your form but you are missing the , ==, =, <=, association there. I generally use Orders_After for something like this instead of Orders_New but they should be interchangeable.
Additionally to Scott's comments, there seems to be an extra "and" between the MEL_ADD_orders() and the USEROK().
If (OBSNOW(“TBARMPlace”) “”) ... should probably read If (OBSNOW(“TBARMPlace”) == “”)... or something similar. You need to compare the value of TBARMPlace to something (equal empty string, not equal empty string, etc).
I'm always extra cautious when using MATCH() and GETFIELD(), as MEL can have issues if you are evaluating a blank string in argument #1. For that reason and because I think it makes it easier to troubleshoot future issues, I like to use a lot of cond/case/endcond statements to walk through scenarios. I would write it up something like below...disclaimer, I didn't test this at all, so please thoroughly test before deploying.
fn orderTB()
{
local orderIt = ""
cond
case OBSNOW("TBARMPlace") <> "": //do nothing
case ORDERS_NEW("List") == "": orderIt = "Y"
case match(ORDERS_NEW("List"), 1, "TB/TST Read") <= 0: orderIt = "Y"
endcond
if orderIt == "Y" then
MEL_ADD_ORDER(“T”, “Tuberculin Skin Tests (TST)”, “TB/TST Read”, “”, “”, “”, “TST Read Due.”, “1″, “U”, “”, ADDDATES(str(._TODAYSDATE), “0″, “0″, “3″))
userok(“Order placed for TST Read. TST Read to be completed in approximately 72 Hours.”)
endif
}
Chad - thank you for the information I adjusted the code slightly to work for my needs, and it did the trick.
{fn orderTB()
{
local orderIt = ""
cond
case OBSNOW("TBARMPlace") == "": //do nothing
case match(ORDERS_NEW("List"), 1, "TB/TST Read") <= 0: orderIt = "Y"
endcond
if orderIt "Y" then "" else
MEL_ADD_ORDER("T", "Tuberculin Skin Tests (TST)", "TB/TST Read", "", "", "", "TST Read Due.", "1", "U", "", ADDDATES(str(._TODAYSDATE), "0", "0", "3"))
userok("Order placed for TST Read. TST Read to be completed in approximately 72 Hours.")
endif
}}
Scott and hermes - I did have a already when evaluating the first obs term, but I can see it didn't paste correctly into my post. I appreciate your feedback as well. Thanks so much guys, mission accomplished!