Clinical_rules - incorrect logic if have multiple targets

Continuing my annual trip down the rabbit hole that is clinical_rules (which is mostly a great tool, but with quirks)

I find that rule status is not calculated properly when more than one clinical target clause is defined in a target/action group

Example: rule has a target checking to see if two different custom forms have been completed in the past year. Intervals: warning: 1 month, past due: 2 months. Both targets display in the rule editor as “optional inclusion” (meaning they both have to be satisfied) (note the display text is backwards: optional means required, and vice versa – has been this way since the dawn of clinical_rules)

If form A was last completed 2 weeks ago, and form B was last completed 13 months ago, the rule status will show as “past due” instead of “due”

Reason this happens:
First pass looks at both targets during T-11 months to T+1 month. Form A passes, form B does not. So overall is failure, and status is temporarily set to “due soon”

Second pass looks at both targets during T-12 months to T. Again form A passes, form B does not. Overall: failure, and status is temporarily changed to “due”

Third pass looks at both targets during T-14 months to T-2 months. Now form A does not pass (even though it should), and form B passes. Overall: failure, and status is changed to “past due”, when overall should have been success an the prior temporary status of “due” should have persisted

My solution is to change sql_interval_string() so all of its compares are against now() on the right side of the interval, instead of $dateTarget. Not sure this is the right approach, but it works for me

Thoughts?
– Hank