To diagnose insomnia, your doctor will ask about your sleep patterns and habits, stress levels, medical history, level of physical activity, and use of medications, alcohol, caffeine, tobacco, and illegal substances. You'll also get a physical exam, and you might need to keep a sleep diary. In some cases, your doctor may refer you to a sleep disorders specialist for an evaluation. The specialist may ask you to do an overnight sleep study at home or at a special sleep center.