refactored the JS. Switching patients works well. switching to open tabs from tree still has a bug that tries to replicate the widgets that are already loaded leading to DOM ID duplication and widget clash.