I think you may be overcomplicating your process.
You can create a Running Total (or a variable formula) to count per row. Not knowing your data it is hard to say but your original description leads me to believe a RT would be fine.
I assume you have agroup on the doctor field.
Create a RT as "RoutineCount"
Field to Summarize=PK field per Visit or PK field for each patient depending on what you want to count (patients or visits)
Summary Type=DistinctCount
Evaluate = Use a formula...make a formula to look at the diagnosis that is a 'Rountine' Diag, likely something like this....
{LEDGER.CODE} in ['code1','code2','code3',etc.]
Reset=On change of group (select doctor group)
place on Group footer (RTs do not work in headers) for the Doctor level group.