Absolutely yes! A defense of "medical necessity" is always an option in court. Ideally, you could even claim medical necessity without having any medical recommendation at all.
Of course, I recommend that you do go and obtain a recommendation, IMMEDIATELY, from a doctor of your choosing. Preferably, a doctor who won't be under investigation or out of business come time for your trial.
Next, I recommend that you register with your county's ID card program, if applicable. This is an extra step requiring that you put forth more money. But when we're talking about the cost of your freedom, money should be your last concern. The ID card will make your medical status 100% legit, because you're paying the State of California their money. Thats right, the same State that is prosecuting you.. Maybe you can see why this could potentially benefit you in court?
I would guess that with a good lawyer, you will likely have the charges dropped all together. There really isn't a whole lot that they can do in regards to your defense. Keeping in mind, that the State needs to prove beyond a reasonable doubt that you are NOT a patient using marijuana for medicinal purposes. The burden of proof lies on the State of California to prove that your doctor unlawfully recommended marijuana to you. How do they prove that to 12 jurors? Easy.. They don't.
Long story short, your likely to be in good shape if you go and register. If you have any other legal questions, let us know and we'll be happy to help you in any way that we can!