As mentioned there is an exemption for any services offered in office. For my field (urology) that means in office path, urorads, maybe pharmacy. The law is basically a farce these days, where most doctors work for some mega group/academic center/hospital, where your referrals are strongly suggested to be in house. Basically outside of the exemption it’s illegal to profit on your referral to ancillary service. However it’s perfectly legal for the giant medical center that employs you (likely in part supporting your salary through the ancillary revenue you generate) and suggests you refer in house to profit from your referrals.