A Survey of Large Language Models in Medicine: Principles, Applications, and Challenges