Fixed multiple bugs in linking patient notes to documents.