Hi
I’ve been trying to figure out the rule processing behavior for a long time, and it has not made sense to me. Finally did a lot of debugging and looking at the code in library\clinical_rules.php and found the source of the confusion.
The code has a bug (and probably has for a very long time)
I’ve only examined the case when a target of type “custom” is being used.
I’m looking at version 5.0.2 patch 4
In test_rules_clinic(), the logic tests a rule target against 3 target dates, in this order:
– today + the warning interval
– today
– today - the past due interval
The logic examines the interval: target date less target interval -> target date, checking the rule_patient_data table to see if a row in the table exists for the patient that matches this interval, category/item pair, and frequency (as defined by the rule target)
So, for example, if the target specifies
– reminder, prostate cancer screening, completed=yes, frequency > 0, interval 12 months
then a db query is done looking for at least one row with the interval described above and the specified category/item combination and completed status
If the target criteria is found in the db, the rule status is set to “not due”, and processing stops.
If the target criteria is not satisfied, the status is set to “soon_due”, “due”, or “past_due” depending whether the first, second, or third target date is being examined, and then the next target date is tried (if there is another target date to try)
To me this seems wrong!
To me, the logic should be:
– if, for the first target date, the target criteria is satisfied, then status = “not due”
– else, if, for the second target date, the target criteria is satisfied, then status = “soon_due”
– else, if, for the third target date, the target criteria is satisfied, then status = “due”
– else, status = “past_due”
Example: suppose the warning interval is 1 month, the past due interval is 3 months, and the target interval is 12 months. This should mean:
– the target action should be performed every 12 months
– if today, the last time the action was performed was within the past 11 months, the rule is “not due”
– if it was last done between 11 and 12 months ago, the rule is “due soon”
– if it was last done between 12 and 15 months ago, the rule is “due”
– if it was last done more than 15 months ago, or never done, the rule is “past due”
I modified clinical_rules.php to match my desired logic, replacing
$action_plus[‘due_status’] = “not_due”;
with
if ($dateCounter == 1)
$action_plus[‘due_status’] = “not_due”;
elseif ($dateCounter == 2)
$action_plus[‘due_status’] = “soon_due”;
else // $dateCounter == 3
$action_plus[‘due_status’] = “due”;
This change is made below this code, which exists in two places:
// send to reminder results
if ($mode == “reminders-all”) {
// place the completed actions into the reminder return array
$actionArray = resolve_action_sql($rowRule[‘id’], ‘1’);
foreach ($actionArray as $action) {
with this change, the reminder status is calculated according to my expectation described above.
Without this change, by hard coding the status to “not due” whenever rule target criteria is satisfied, the rule always shows as either “not due” (if the target is satisfied any time between target_date3 less target interval -> target_date1) or “past due” (if satisfied prior to target_date3). It never gets the “due” or “soon_due” status.
Not sure how to get this reviewed or part of an official release (I’m new to this community)
Hope this helps someone