A Superior Court judge has ordered CVS Pharmacy to pay Alameda County and two other California counties fines totaling more than $658,000 to settle a lawsuit brought because their pharmacists failed to provide proper consultation for patients who filled prescriptions.

The court order, signed by San Diego County Superior Court Judge Lisa Schall on Friday, stemmed from charges that CVS violated California laws that require a pharmacist to personally discuss medications with patients who receive prescriptions for the first time or who refill orders for drugs calling for adjusted dosages.

The consumer protection lawsuit was filed by Alameda, Riverside and San Diego counties, according to a statement from Riverside County District Attorney Paul Zellerbach.

The three District Attorney's Offices worked with the California Board of Pharmacy and conducted undercover operations at various pharmacy chains operating in the state. Between 2008 and 2012, a number of violations were found, including instances where discussions about medications were handled by store employees who were not licensed pharmacists, and other instances where no consultations at all were offered.

The defendants in the case were Garfield Beach CVS and Longs Drug Stores, both California companies owned by Woonsocket, R.I.-based CVS. Together, these two companies operate 850 CVS-branded pharmacies across the state.

CVS, under the terms of the judgment, does not admit any liability, and the company was ordered to comply with the state's standards. CVS must also implement an internal compliance program to ensure that this does not happen again.

Riverside County will receive one-third of the penalty, which includes investigative costs.

According to the statement, CVS cooperated with the county prosecutors to resolve the matter.