fix cloudcare 500 resulting from mistakenly looking up referral details

introduced here: https://github.com/dimagi/commcare-hq/pull/3707#discussion_r14267786