The first time the patient met Naga Thota was in February 2013, during a “flirty” consultation at the doctor's pain-management clinic near San Diego.

The doctor asked about her nipple rings, saying he'd be really excited if his girlfriend had similar piercings, court documents say. Then he scrawled a prescription for hydrocodone.

Three days later, he called and asked his 25-year-old patient out for Valentine's Day.

Court documents say it was the beginning of an illicit sexual relationship full of raunchy texts, sex, and 1,070 tablets of addictive painkillers.

Ultimately, the relationship would cost Thota his medical career and his freedom.

On Monday, Thota was sentenced to more than two years in federal prison for distributing controlled substances without a legitimate purpose, part of what the San Diego Union-Tribune called a “quid pro quo situation in which he exchanged drugs, gifts and money for sex.”

A criminal complaint accuses him of having similar arrangements with two other patients — all of them in their 20s and addicted to pain pills.

The relationships followed a similar pattern, according to a news release from the U.S. attorney's office in the Southern District of California. Thota and the women would exchange sexually explicit texts, then Thota would write prescriptions in exchange for sexual favors.

His victims told investigators he switched them to more powerful painkillers, then increased the dosages — and their dependence on him as a supplier.

“Prescription drug abuse and overdoses have reached alarming levels,” U.S. Attorney Laura Duffy said in a news release announcing the charges against Thota last year. “We are going after doctors who abuse their power to prescribe and exploit the desperation of addicts for their own gratification.”

Thota told the Los Angeles Times that he went into pain management because of seeing his father's struggle with chronic pain after he fractured a hip. Doctors refused to prescribe the older man morphine because they feared he would become addicted.

So Thota became an anesthesiologist and opened a pain-management clinic, although he admitted that it was a challenge treating the chronic pain of people who were at risk of becoming addicted to powerful painkillers.

The clinic made him wealthy — at one time he told the Times that he made $1 million annually, enough to own a home in the affluent seaside community of La Jolla.

Thota was one of three California doctors interviewed in 2012 by the Times after the newspaper found that 15 of the patients to whom he had prescribed drugs had died.

In the interview, he conceded that there are pain-management challenges but said he would continue operating his clinic.

“Somebody has to take care of these people,” he said in an interview. “And I am the chosen one.”

At his sentencing Monday, Thota's attorney told a judge that things soured for the doctor when his marriage of 29 years dissolved and he was lonely and vulnerable, according to the Union-Tribune.

That's about the time he met the victim, identified in court documents by her initials, J.S. She was young and attractive — and a burgeoning addict.

Their relationship quickly turned sexual, and over several months, he wrote 33 prescriptions for her.

Shortly after the initial consultation, the woman told investigators, Thota changed her prescription from hydrocodone to the more addictive oxycodone. Then he doubled the dosage.

“She liked how she felt when taking the oxycodone,” investigators said, according to court documents, “and subsequently became addicted.”

Thota would lavish her with money and gifts and take her on fancy dates, court documents say.

But Thota said he feared losing his license. He replied to one request with, “No babe no meds please.”

But he kept writing prescriptions. At times, she'd simply text him, “I am here downstairs” or “I'm here love at my normal parking spot,” and he'd rush down and hand over a prescription, court documents say.

Pharmacists have safeguards and access to databases to prevent doctor-shopping addicts from filling prescriptions with too frequently.

But court documents say Thota helped J.S. circumvent the safeguards by writing prescriptions in the names of family members or a friend.

The details of their relationship was a raunchy tableau in the nation's fight against prescription drug abuse.

As The Washington Post's Ariana Eunjung Cha wrote in October:

Opioid prescriptions alone have skyrocketed from 112 million in 1992 to nearly 249 million in 2015 … and America’s dependence on the drugs has reached crisis levels.

Millions are addicted to or abusing prescription painkillers such as OxyContin, Vicodin and Percocet. Statistics from the Centers for Disease Control and Prevention show that, from 1999 to 2014, more than 165,000 people died in the United States from prescription-opioid overdoses, which have contributed to a startling increase in early mortality among whites, particularly women — a devastating toll that has hit hardest in small towns and rural areas.

A few months after it started, Thota's relationship with J.S. began to spiral downward, according to court documents.

He worried that she was selling some of the drugs he helped her get, court documents say. He also suspected that she was sleeping with other men even though they were having unprotected sex.

Once, to punish her, he cut service to the phone he'd bought for her. But she texted him from her brother's phone, outraged and hurling threats.

“I swear on my mother's grave I will share with everyone our text messages that we've shared ever since we first met,” she wrote. “I will show them how you pursued me and how you bribed me with drugs and how you let me get all these drugs under different people's name. I will also share how much you pay me to f--- me.”

She made good on the threat in 2014. According to court documents, J.S. was arrested for prescription drug fraud and agreed to talk with investigators about the person supplying her with pills.

Investigators say she told them about Thota voluntarily and wasn't offered anything in return.

Read more:

A 7-year-old told her bus driver she couldn’t wake her parents. Police found them dead at home.

A shocking video captured a man’s overdose. He calls it ‘the best thing that happened to me.’

The first thing cancer patients saw when they got to this hospital: An ad for a funeral home