According to Morgan Carvajal, a legislative advocate at the California Medical Association, it is crucial to test for H.I.V. before starting PrEP or PEP. If a patient who has H.I.V. takes those drugs, she said, the virus can become resistant to key ingredients that are also found in medicines used to treat the virus. That could limit a patient’s treatment options down the road.

She added that regular medical checkups for PrEP users are also essential to check renal function every six months — the drug can have adverse side effects on the liver, kidneys and bones — and to test for other sexually transmitted diseases.

Besides worries about the drug’s side effects, several other factors may contribute to low rates of Truvada use, including its high cost — about $20,000 a year, if one is paying full price — and stigma associated with its use .

“We have this highly effective drug and the ability to prevent H.I.V., but getting it to people who need it is more of a challenge,” Jen Kates, director of global health and H.I.V. policy at the Kaiser Family Foundation, said on Tuesday. “Being able to go to a pharmacy is much easier than going to a primary doctor. More people who are at risk will be able to get the medication that will prevent them from becoming H.I.V. positive.”

Truvada, made by Gilead Sciences, has been the only H.I.V.-prevention drug on the market since its approval in 2012. But last week, the F.D.A. approved a second H.I.V.-prevention drug, Descovy, also made by Gilead, which may have fewer side effects. That drug has not been tested on everyone, however, and was approved for use only by cisgender men and transgender women.

Dr. Aaron S. Lord, an N.Y.U. School of Medicine neurologist and a founder of a campaign that calls on the government to break Gilead’s patent on Truvada to make PrEP more affordable, applauded the new law.

“I think what California is doing is exactly the kind of innovative response that we need in order to end the epidemic of H.I.V. infections,” he said.