I have a form from a vendor that records breathing measurements and writes values to obsterms with various units attached (litre's, % etc). I've created my own form and want to use those numbers for some calculations but I need to remove the units before it'll work. What i'm guessing to be the best approach would be some sort of button that converts it to a val and then overwrites the current obsterm? Is that possible/how is it done? I may want to shrink the numbers down as well if possible from say 72.678 to like 73
I won't think that the units should be an issue. For example we have the WEIGHT obs term on our vitals form. It has 'lbs' as the unit of measure. When I use obsnow, obsprev, etc. I just get the value and never the unit.
Regarding shrinking the number down you can use either sub() or round().
Sub will grab the number of characters you want.
Round will round to the number of decimal places. In this case the value may change slightly.
Brad
That only works if the unit of measure is built into the observation value you are using.
If you know which values/units you are looking for you could do a simple replacestr() on the values you want to remove. Also ,if there is always a space between the number and the unit, you could use getfield() to split it on the space character and then use the first entry in the array as the number. Once you get down to just the number you will need to wrap the number in the val() function before performing any calculations on it.
Using val() alone will not remove the 'unit characters' from the value. When invoked using non-numerical values, val() will return a Zero instead of the anticipated numerical value (it used to return an ASCII equivalent of the entire string, but that has thankfully been fixed).
To get around this, a function needs to be written that strips out the non-numerical characters while looping character by character. When the loop is complete and the value has been updated to the format desired, the value needs to be stored using an updated date/time stamp so that it appears later in the flowsheet than the original value.
Using LAST_SIGNED_OBS_DATE(obsname) + " 11:59 PM" will accomplish that step.
Using obsnow, you could then use the third parameter to store the updated value.
CAUTION: Ensure the user can click the button only once otherwise duplicate entries will be stored with each button click (using dates other than the date of the document produces a stored value upon each execution whereas using the document date causes the value to simply be updated).
To round the value, review the EMR Help file for the ROUND() data symbol. You might also want to review the TRUNCATE data symbol as well since the round symbol is prone to returning trailing zeros depending on context.
Hope this helps.
It appears the unit is built into the obsterm. For example with this form, obsterm POST FVC comes across as 5.405 L. My calculation doesn't work, but if I backspace L off then it works.
If you look at the OBSHEAD table there is a column called "UNIT". For example, if you look at the weight observation, the unit is "lb". The actual value stored in the database for patients weights is numeric, without the unit added to it.
If you have a form that manually adds units of measure to the end of an observation,it will be stored in the obs table with the units which means it will not be numeric. Your only way around it is to remove the non numeric values.
In your example, you could remove non numeric values with the following code.
local temp = getfield(obsany("POST FVC"), " ","")
local postFvc = temp[1]
I thought I had it figured out but I guess I don't. I assume that code needs to be setup in a function right? How should it be setup if I want to add it to PRE FVC? Would it be like val(postFVC) + val(preFVC)?
It would probably work best in a function.
The code that I posted was just a way to remove everything after the first space in the OBSVALUE. To convert it to something you can do math on, you would need to run it through val() first.
I don't have a great idea of what you are trying to do but here is a function that would add PRE FVC to POST FVC and return the value.
fn AddPostToPre(){
local tempPost = getfield(obsany("POST FVC"), " ","")
local postFvc = val(tempPost[1])
local tempPre = getfield(obsany("PRE FVC"), " ","")
local preFvc = val(tempPre[1])
return preFvc + postFvc
}
You're a genius! Works great!