Unit 19 Magic Math 1
MAGIC expressions are strictly evaluated from left to right. There is no precedence based on the operator used within an expression. To control the order of operations you must use parentheses in order to group sub expressions within an expression. This allows for a value to be computed prior to performing the rest of the expression from left to right. For example, if you have the expression 9-1*2 you would get 16 in Report Writer as there is no precedence on multiplication being evaluated prior to subtraction. To make this work as you would expect you must format the expression like this 9-(1*2) which would then compute 1*2 first before going left to right and thus provide the correct result of 7.
Decimal Places
Report Writer will return the expected decimal precision based for addition, subtraction and multiplication. The number of decimal places returned by the division operation is the number of decimal places in the numerator minus the number of decimal places in the denominator. In order to return the desired decimal precision for the division operation, you can expand the decimal places within the numerator to ensure that the result will contain the desired amount of decimal places. Simply, changing the data type of a computed field to DEC2 or DEC3 will not give the correct number of decimal places when working with division.
Remainder
The remainder of division is most commonly used in Report Writer to do computations with days and weeks. Say you are able to compute the amount of days between two specific dates in a report, you could then use the remainder of division to break this down into weeks and days instead. For example in BAR.PAT you can compute the amount of days an account has been at their current status using the following expression:
%Z.date.sub(@.today,@status.date)
This expression would return an integer representing the number of days between today and the status date, for example 115 days. However, what if we wanted that number broken down into the total number of weeks and days instead of just the total number of days? To do this you would first take the total number of days and divide by 7 which will provide the number of weeks.
%Z.date.sub(@.today,@status.date)/7
115/7 = 16 (No Decimals due to Rules of Division)
Then we can use the remainder of division between the number of days and 7 to return the remaining number of days.
%Z.date.sub(@.today,@status.date)\7
115\7 = 3
Finally these two expressions can be combined in one expression:
%Z.date.sub(@.today,@status.date)/7_“Wks ”_(%Z.date.sub(@.today,@status.date)\7)_ “Days”
So the original number of days 115 would now be returned as 16 Wks 3 Days.
Workshop
Compute a percentage of the number of patients with balances greater than or equal to 1000
Format Operator
The <Colon> is the format operator which can repeat a value, truncate a value and provide decimal precision for a numeric value. The format operator can be used for a number of formatting options. The colon’s main use is to round to a specified amount of decimal places. For example, 6:2D would be 6.00. The colon operator can be used to set the numerator of a division operation to the appropriate number of decimal places in order to force the result to have the desired amount of decimal places. The following two statements would be equivalent:
- Multiplication Expansion of Numerator - @los*1.00/10
- Colon Operator to Expand Numerator - @los:2D/10
For a listing of all the colon operator functions please see the following link:
Operators:
MEDITECH
Level One - NPR Report Writer Workshop