ALBANY -— A Woodstock doctor whose medical license was suspended in 2004 for practicing while mentally impaired has been charged with prescribing thousands of painkillers to patients who paid cash and had no legitimate need for the drug, according to a federal complaint.

Dr. Wayne D. Longmore, 62, was arrested Wednesday when a federal task force that included FBI and Drug Enforcement Administration agents raided his Ulster County office. He could not be reached for comment.

The investigation began around March 2009 when pharmacies in the area of Longmore's medical practice notified state and federal authorities that Longmore was prescribing an extremely high number of powerful and addictive painkillers.

A federal complaint filed in U.S. District Court in Albany says that during a one-month period in September Longmore wrote 659 prescriptions for hydrocodone from his practice, Walk-In Doctor's Office, on Mill Hill Road in the small town of Woodstock. The 659 hydrocodone prescriptions Longmore wrote that month was topped only by Albany Medical Center Hospital and Syracuse's University Hospital Pharmacy, records show.

Federal agents said prescription records filed with the state Health Department's Bureau of Narcotic Enforcement show Longmore has been the fifth highest prescriber of painkillers, including among medical institutions, in an area stretching from Kingston to the Canadian border.

Longmore, a former emergency room physician in Brooklyn, had his medical license suspended in 2004 when a state medical review board determined he was an "imminent danger" to the public and practicing medicine while mentally impaired. The records say Longmore was diagnosed as having a psychiatric condition, bipolar disorder.

In December 2005 Longmore's medical license was restored by the Health Department. A spokesman on Thursday said he was directed not to discuss the details of Longmore's case or the circumstances that led to his license being restored.

Between December 2010 and January 2012, Longmore wrote approximately 9,939 prescriptions for hydrocodone, according to a complaint filed by an FBI special agent, Julie Kelly Mounce. Of those prescriptions, nearly half were prescribed to patients under the age of 35, the agent said. More than 85 percent of Longmore's prescriptions to patients were for hydrocodone, an opiate that is widely considered as addictive as heroin.

The investigation showed some patients were under the care of other doctors for opiate addiction at a time when Longmore was prescribing them hydrocone.

"Throughout the investigation of Longmore, multiple pharmacies contacted the FBI and DEA regarding his unusual and suspicious prescribing practices," Kelly Mounce wrote in the federal complaint used to arrest Longmore. "From conversations with these pharmacists, I learned that some of Longmore's patients travel a long distance to obtain prescriptions for controlled substances from him. One pharmacist reported that Longmore almost always writes prescriptions for 45 hydrocodone tablets at a time, which is approximately a one-week supply."

The patients usually paid $60 cash to Longmore after being examined and receiving a prescription.

Last August, the FBI installed a camera on a utility pole outside Longmore's office that's within a few blocks of two commercial pharmacies. The agents said Longmore saw a high volume of patients in exams that in some cases lasted only a couple minutes. "I know that Longmore saw an average 72 patients per day, which averages approximately nine patients per hour, or approximately six and a half minutes per patient," the complaint by Kelly Mounce states.

The FBI also sent undercover informants into Longmore's office. They said his physical examinations often consisted of a quick blood-pressure check and that he rarely asked patients if they were taking other drugs or provided them detailed information on the addictive and long-term effects of the painkillers he was prescribing.

Two months ago, an undercover informant who posed as a patient told the FBI that during a medical examination Longmore had explained he could not write two weeks worth of hydrocodone prescriptions in one visit because of his prior suspension from practice by the Health Department.

"Longmore further stated that when he was writing prescriptions for 60 tablets at a time, 'they' thought he was writing too many," the FBI's complaint states. Longmore said that since he has been writing prescriptions for 45 tablets at a time, he has not had any problems with the Department of Health."

Longmore is charged with felony drug distribution. He was released on his own recognizance after appearing before a U.S. magistrate on Wednesday.