Clinical_rules tests for dates of demograhic filters in exist_lists_item - why?

Hi. I found what I think is a significant logic issue in clinical_rules.php (7.0.1 (1), but has probably been present for a long time).

It relates to date checks being applied when processing demographic filters.

Suppose you design a rule, with warning: 1 month, past due: 2 months, that has a demographic filter checking to see if the patient has COPD (icd10: J44;9)

You also have a rule target checking to see if a CUSTOM form has been completed in the past year

For processing the target, the rules engine defines three intervals: T-11 months to T+1 month to see if the target is “not due”, if not, then T-12 months to T to see if the target is “due soon”, and if not, T-14 months to T-2 months to see if the target is “due”. And if none of these are true, then the target is “past due”

But the right-side timepoint of these 3 intervals (T+1 month, T, and T-2 months) is also used in evaluating demographic filters. Why???

I’m guessing it was thought that the engine should see if the diagnosis was active at the time being examined for the target. But this logic seems flawed

The sql generated for the demographic filter examines the lists table and includes this clause in the Where expression:

AND ( (`begdate` IS NULL AND `date`<=?) OR (`begdate` IS NOT NULL AND `begdate`<=?) ) 
AND ( (`enddate` IS NULL) OR (`enddate` IS NOT NULL AND `enddate`>=?) )

The rules engine tests both the demographic filters and the targets against all three of these intervals/timepoints.

Suppose I entered a diagnosis of COPD for a patient 2 weeks ago, and the form has not been completed

The first analysis (T-11 months to T+1 month) finds the diagnosis was valid during this interval, so the demographic filter passes and the rule is applicable to the patient. Then the target is examined, and found to not be present, to the rule status is not “not due”, but is instead temporarily set to “due soon”

Then the next interval (T-12 months to T) is tested. The diagnosis is valid in this interval, and again the target is not found, so the rule status is temporarily changed to “due”

Then the third interval (T-14 months to T-2 months) is tested. Now the diagnosis is not valid in this interval since it was entered after the end of this enterval. Processing stops, and the temporary status of “due” becomes the actual status and is shown to the user.

What I believe should have happened is the diagnosis should have been considered valid regardless of the intervals being used in examining the target. Demographic filters should be evaluated independent of time. Or if time is to be considered, that should be explicit in the rule building user interface and and made clear how demographic filter test intervals relate to the intervals used for target analysis.

For my purposes, I am removing the time tests in exist_list_items() (this function is used only in examining demographic filters, not for examining targets)

I’m open to a discussion of what a better solution should be

Thanks
– Hank

I am also setting the 3rd parameter to null in the calls to test_filter() in test_rules_clinic() so $dateTarget will get set to the current timestamp when processing filters, in preparation for processing targets