I'm asking a question I think I know the answer to, because I hope that I'm wrong.
Here's the situation: We have a protocol form that automatically assigns between 6 - 12 medications to a patient's chart. This happens using MEL_ADD_MEDICATION().
The new ask is to add an attending physician to each medication automatically. And here's where I hope I'm wrong.
- I need to add a medication using MEL_ADD_MEDICATION
- Then I need to use getfield(MEDS_NEW) to access the MID of that medication
- Then I need to use that MID with MEL_CHANGE_MEDICATION to add the provider's name to the medication
Is this right? If I only had to automate one medication, this wouldn't be an issue. It'd be a pain, but not impossible. But, again, I have between 6 - 12... And each time I add one, that adds a medication to the list that's returned, requiring further filtering in my for loop...
Am I missing something really obvious? Like a way to add a provider to a med with MEL_ADD_MEDICATION?
Follow up question that I hope I'm wrong about:
In order to instantiate an empty array, does it have to be global? I'm struggling to get an empty array built that I can insert objects into, and I've only been able to get it to work by making it a global variable. Please say I'm missing something...
(Here's my idea of an easier way to do the thing above: MEL_ADD_MEDICATION for all meds, use MEDS_NEW in a for loop to pull out all MIDs and insert them into an array, use the array contents with MEL_CHANGE_MEDICATION)
Hey here's another fun discovery! I don't think you can use MEL_CHANGE_MEDICATION to add/change the authorizing provider unless you also change the dose. Unfortunately, MEDS_NEW doesn't grab the dose, so I may have just hit the point where this task becomes impossible...
If I want to change the attending provider, I have to put in a dose and the authID for every single medication. But if I run MEL_CHANGE_MEDICATION while leaving the dose blank, the dose changes to "" and the authID doesn't stick. If I put a "0" in there, it works, but then that means that NO med can have a dose auto assigned.
I REALLY hope this is just a matter of it being 3:30 on a Friday, because otherwise...
I don't have any direct experience with this situation in particular, but glancing at the document it appears you are on the right track. The authByUserId is probably the authorizing provider for a prescription, which is probably why it requires a dose, you may want to double check that you are not adding a prescription (unless that is what you want). Some of the newer symbols return the id of the new row, which would have been nice in your scenario, but MEL_ADD_MEDICATION still returns an empty string so your out of luck there as well. These data symbols could use some work...
For an array, it does not need to be global. I usually initiate it like this
local temp = array()
Then you can you insert like this -
insert(temp,1,"Hello")
insert(temp,2,"World")
And you end up with an array like this -
["Hello", "World"]
You can reset an element using set -
set(temp,2,"Bob")
Resulting in ["Hello", "Bob"]
Those strings could also be arrays, which is probably what you mean by object. You can't insert and object into an array as you can in other languages like php, but almost everything in mel is a string or array so you shouldn't really need to. I hope that helps.
Arrays are so touchy in MEL... I was able to get a locally instantiated array to work a few times, but never with any consistency. I also think my idea of storing MIDs in an array was the result of Friday at 3PM...
I think you're right about the authID needing a dose in order to work. I was trying it on a historical prescription, so that might be a bug or a case where the thought was a historical prescription wouldn't need a prescriber.
Regardless, I was able to make it all work! A colleague was looking on CHUG for some help and came across this: https://forum.centricityusers.com/forum/mel_change_medication-issues/
Yes. I wrote that. A year ago. When I was last working on the same form I am currently working on...
I ended up using MEL_ADD_MEDICATION to create an active medication with a dose of 0. I then used MEDS_NEW in a for loop to grab all new medications and get the MIDs, then used those MIDs in the same loop with MEL_CHANGE_MEDICATION, where the dose was still 0.
Basically, the dose had to be instantiated first, even a 0 dose would do it when an empty value wouldn't.