PHOENIX (AP) — The Arizona Court of Appeals has ruled that the Costco warehouse store chain can be sued for privacy violations by a Phoenix-area man because a pharmacist joked with his ex-wife about an erectile dysfunction prescription he had never picked up.

The ruling issued Tuesday revived the lawsuit the man filed after the pharmacist told his ex-wife about the prescription when she went to pick up another prescription with his approval. The man had called Costco twice to cancel the prescription before his ex-wife went to the north Phoenix store in early 2016, but the pharmacist did not do so, according to the ruling.

Attorney Joshua Carden filed the lawsuit for the man alleging a variety of violations, but it was dismissed by a trial-court judge. The Court of Appeals revived sections alleging negligence under federal health care privacy law commonly called HIPAA. The ruling potentially allows him to seek punitive damages.

The ruling is the first to say that negligence claims under HIPAA can be brought in Arizona courts, Carden said.

"If there is a big deal in the case it's that the court went ahead and said yes to negligence claims based on HIPAA violations," Carden said. "That's not ever been announced in Arizona before."

The federal health privacy law doesn't allow individuals to sue for violations in federal court, he said, and state courts haven't always been clear about that right.

Costco hasn't responded to a request for comment sent Tuesday.

The court ruling says the Phoenix-area man in his 50s received a sample for an erectile dysfunction drug in January 2016 and later got a call from Costco saying a full prescription was ready for pickup. The man canceled the prescription and then canceled it a second time about a month later when he called to check on an unrelated prescription and was told it was still there.

The court ruling says the man then authorized Costco to allow his ex-wife to pick up his regular prescription refill, and that's when the pharmacist told her about the ED pills and they joked about them.

The ruling says the man was trying to reconcile with his ex-wife, but after the pharmacy incident that failed.

Costco apologized after the man complained, Carden said, sending him a letter saying that telling his ex-wife this information violated both HIPPA and the company's own privacy policies.

The case now returns to a lower court for further proceedings. Carden said he suspects the pharmacist never canceled the prescription because they may get bonuses for selling high-profit drugs like Viagra.

"I don't have a smoking gun yet by Costco yet, but I'll be asking for things like does Costco have some sort of contract with Viagra, the makers of Viagra, where they get a bonus if they sell more," Carden said.

He said the pharmacist clearly had a responsibility to protect his client's privacy.

"What I'm saying is as a pharmacist you have a duty to keep my client's information private," Carden said. "And on top of that you have a duty to cancel his unwanted prescriptions so that (stuff) like this doesn't happen. And that's where the breakdown came."