A framework for inferring and analyzing pharmacotherapy treatment patterns