A doctor opened fire with an assault rifle inside a New York City hospital where he used to work, killing a woman and wounding six people before turning the gun on himself, law enforcement officials said.