Medical marijuana is legal in California - except when it isn't. This is the situation people face when they are charged with a drug crime when they are just seeking relief from a medical problem.
The problem is conflicting laws between states and the federal justice system. States allow a certain amount of possession and cultivation of marijuana for medical purposes. But the federal government does not acknowledge exemptions made by the state.
California led the way
California was the first state, back in 1996, to pass medical marijuana law. Guidelines set limits on possession and cultivation. Conditions recognized by the state include (but are not limited to) arthritis, cancer and accompanying wasting syndrome, chronic pain, HIV/AIDS, epilepsy, migraine headaches and multiple sclerosis. (Source: California Health and Safety Code sections 11362.7-11362.83)
You can be charged with a crime if you violate any of the strictures expressed in the law. If that happens, you need an attorney experienced in this constantly changing area. California prisons are full of people who assumed they were on safe legal grounds, and that they did not need a lawyer to represent them.
Cases generally boil down to a single question: Did you overstep the limitations laid down by the state? It would take a criminal defense attorney experienced in defending medical marijuana cases to answer that question and defend you in such a case.
Federal drug crimes
The federal government has not altered its approach to medical marijuana. The Obama administration de-prioritized medical marijuana cases for a time, then resumed prosecution of users and caregivers. The Department of Justice under the Trump administration seems determined to hit marijuana use hard, regardless of state laws.
Do not assume that just because your doctor signed a letter or with the passage of Proposition 64 legalizing recreational marijuana use in California that you are off the hook for medical marijuana use. Talk to an experienced medical marijuana attorney who is in touch with changes in the law, and can help you navigate the state/federal conflicts.