Can someone help me with converting a Fraction to a Decimal? Here is what I am trying to achieve:
I am working on a custom OB form and weeks gestation is auto-generated as a fraction. I would like to set a button/function to convert that fraction to a decimal. And then set a function to add problems to the patients problem list based on that decimal value as well as a couple of other patient factors (gest age and gravid).
Can you provide a sample or two of the typical output?
We do not use that form, so no idea what is stored. I am guessing something like '8 2/7 weeks'?
Example: 19 2/7
Stored to OBS term "GEST AGE EST"
Here is the form:
OBFLOWSHEET PROBMED COMMENTS5(2)
My hope is to add a button that will evaluate the converted gest age. maternal age and gravid and then add the correct ICD10 problems for Weeks Gestation and Trimester. While also factoring in whether or not those problems are already part of the patients problem list.
//seperate the whole number from the fraction by the space
gestAgeArray = getfield(gestAge," ","")
//find if there is a forward slash in the gestAge. this will get us the numbers on each side of the slash
indexVar = match(gestAgeArray[2],"/")
//if there is a fraction, then calcuate the value.
if indexVar >0 then
numerator = sub(gestAgeArray[2],indexVar -1,1)
denominator = sub(gestAgeArray[2],indexVar +1,1)
decValue = val(numerator ) / val(denominator )
//add the decimal to the whole number
return val(GestAgeArray[1]) + decValue
else
//return blank if the gestAge passed in was not formated as "XX X/X"
return ""
endif
}}