RICHMOND, VA (AP) — By the time drug enforcement agents swooped into his small medical office in Martinsville, Virginia, in 2017, Dr. Joel Smithers had prescribed about a half a million doses of highly addictive opioids in two years.

Patients from five states drove hundreds of miles to see him, spending up to 16 hours on the road to get prescriptions for oxycodone and other powerful painkillers.

“He’s done great damage and contributed … to the overall problem in the heartland of the opioid crisis,” said Christopher Dziedzic, a supervisory special agent for the Drug Enforcement Administration who oversaw the investigation into Smithers.

In the past two decades, opioids have killed about 400,000 Americans, ripped families apart and left communities — many in Appalachia — grappling with ballooning costs of social services like law enforcement, foster care and drug rehab.

Smithers, a 36-year-old married father of five, is facing the possibility of life in prison after being convicted in May of more than 800 counts of illegally prescribing drugs, including the oxycodone and oxymorphone that caused the death of a West Virginia woman. When he is sentenced Wednesday, the best Smithers can hope for is a mandatory minimum of 20 years.

Authorities say that, instead of running a legitimate medical practice, Smithers headed an interstate drug distribution ring that contributed to the opioid abuse epidemic in West Virginia, Kentucky, Ohio, Tennessee and Virginia.

In court filings and at trial, they described an office that lacked basic medical supplies, a receptionist who lived out of a back room during the work week, and patients who slept outside and urinated in the parking lot.

At trial, one woman who described herself as an addict compared Smithers’ practice to pill mills she frequented in Florida.

“I went and got medication without — I mean, without any kind of physical exam or bringing medical records, anything like that,” the woman testified.

A receptionist testified that patients would wait up to 12 hours to see Smithers, who sometimes kept his office open past midnight. Smithers did not accept insurance and took in close to $700,000 in cash and credit card payments over two years.

“People only went there for one reason, and that was just to get pain medication that they (could) abuse themselves or sell it for profit,” Dziedzic said.

The opioid crisis has been decades in the making and has been fueled by a mix of prescription and street drugs.

From 2000 to 2010, annual deaths linked to prescription opioids increased nearly fourfold. By the 2010s, with more crackdowns on pill mills and more restrictive guidelines on prescriptions, the number of prescriptions declined. Then people with addictions turned to even deadlier opioids. But the number of deaths tied to prescription opioids didn’t begin to decline until last year, according to data from the U.S. Centers for Disease Control and Prevention.

Martinsville, where Smithers set up shop, has been particularly hard hit.

A city of about 14,000 near Virginia’s southern border, Martinsville once was a thriving furniture and textile manufacturing center that billed itself as the “Sweatshirt Capital of the World.” But when factories began closing in the 1990s, thousands of jobs were lost. Between 2006 and 2012, the city had the nation’s third-highest number of opioid pills received per capita, according to an Associated Press analysis of federal data.

Andrew Kolodny, a Brandeis University doctor who has long been critical of opioids, said that in recent years, doctors became less comfortable writing lots of opioid prescriptions and many big prescribers retired. That opened an opportunity for others.

“If you’re one of the guys still doing this,” he said, “you’re going to have tons of patients knocking down your door.”

During his trial, Smithers testified that after he moved to Virginia, he found himself flooded with patients from other states who said many nearby pain clinics had been shut down. Smithers said he reluctantly began treating these patients, with the goal of weaning them off high doses of immediate-release drugs.

He acknowledged during testimony that he sometimes wrote and mailed prescriptions for patients he had not examined but insisted that he had spoken to them over the phone.

Once, he met a woman in the parking lot of a Starbucks, she handed him $300 and he gave her a prescription for fentanyl, an opioid pain reliever that is 50 to 100 times more potent than morphine.

When area pharmacists started refusing to fill prescriptions written by Smithers, he directed patients to far-flung pharmacies, including two in West Virginia. Prosecutors say Smithers also used some patients to distribute drugs to other patients. Four people were indicted in Kentucky on conspiracy charges.

At his trial, Smithers portrayed himself as a caring doctor who was deceived by some patients.

“I learned several lessons the hard way about trusting people that I should not have trusted,” he said.

Smithers’ lawyer told the judge he had been diagnosed with depression and anxiety. Family members said through a spokesperson that they believe his decisions were influenced by personal stress, and emotional and mental strain.

Even before he opened his Martinsville practice in August 2015, Smithers had raised suspicions. West Virginia authorities approached him in June 2015 about a complaint with his practice there, but when they returned the next day with a subpoena, they found his office cleaned out and a dumpster filled with shredded papers and untested urine samples.

Some of Smithers’ patients have remained fiercely loyal to him, insisting their severe chronic pain was eased by the powerful painkillers he prescribed.

Lennie Hartshorn Jr., the father of the West Virginia woman who died two days after taking drugs Smithers prescribed, testified for the defense.

Hartshorn said his daughter, Heather Hartshorn, told someone “she would rather be dead than in pain all the time.” According to a form Heather Hartshorn filled out when she went to see Smithers, she had chronic pain in her lower back, legs, hips and neck from a severe car accident and a fall.

When asked by Smithers’ lawyer if he blames Smithers for anything, Lennie Hartshorn said he does not.

Smithers has been denied bond while he awaits sentencing. His attorney did not respond to inquiries from AP. Smithers has said he plans to appeal.