Changed query that gets the date of the last encounter for date calculations. It is still the date of the last encounter with a cpt4 associated with it, but it gets the date from the form_encounter table (with a join to billing) rather than just getting the date from billing. This accounts for users that might enter their billing codes at a later date. The reason for checking for a cpt4 entry at all is to account for users who put notes in form_encounter for events that are not billable (phone calls, pharmacy call-ins etc...) If you do not enter cpt4 codes at all for an encounter, then you will have to modify this query yourself.