SAN FRANCISCO (CBSN) — Scientists at the University of California San Francisco have cracked the code on getting a woman to be depression-free for the last year.

In a first-of-its-kind trial, researchers implanted a device in a patient’s brain that senses when they are having depressive thoughts and interrupts them with a burst of electrical stimulation.

READ MORE: Oakland City Council Votes To Increase Police Staffing

Researchers worked with a patient they referred to as ‘Sarah.’

The UCSF team mapped out areas of Sarah’s brain that showed positive feelings as well as locations that emitted waves when she was depressed. From there, they put Sarah under the knife and implanted the equivalent of a pacemaker for her brain.

Sarah had exhausted all treatment options for her severe depression that had lasted for 5 years until the trial.

“Within a few weeks the suicidal thoughts just disappeared,” Sarah said. “My lens on the world just changed.”

“When I first received the stimulation, the ‘Aha’ moment occurred,” she added. “I felt the most intensely joyous stimulation and my depression was a distant nightmare for a moment.”

The UCSF team has been working to get to this point since starting up in 2014 as part of President Barack Obama’s BRAIN (Brain Research through Advancing Innovative Neurotechnologies) Initiative.

Dr. Katherine Scangos, co-author of the trial, helped develop a strategy never used before in psychiatric research: mapping circuits of the brain related to depression and finding a neural biomarker. The biomarker showed a specific pattern of brain activity when the symptoms started.

“We identified a circuit in her brain that was specific to her depression and we deliver therapeutic stimulation to one area of that circuit,” Dr. Scangos said. “We sense neural activity in the other area of that circuit so we can monitor and treat in a loop but only when she needs it.”

READ MORE: Bay Area Remembers 1941 Attack On Pearl Harbor That Changed America Forever

After taking months for the whole process to get fully up and running, Sarah has felt no side effects from the device. Now, all of their findings have been published in Mature Medicine.

The scientists are quick to say this is just the first step in a very long process and because each person’s brain mapping needs to be personalized. This process won’t be scaled up in big numbers any time soon but they have added two new patients to the clinical trial and hope to add nine more.

Dr. Edward Chang, another co-author of the trial, is hopeful this form of treatment could make an impact.

“It affords us precision in a way we’ve never really had before when treating depression,” said Dr. Chang, who is the Joan and Sanford Weill Chair of Neurological Surgery. “I think there’s opportunities in the future to make it scalable in the future and more generalizable to a larger population. Right now it’s in its earliest phases.”

“It’s hard when you have a patient in your office and you’ve tried everything and there’s nothing left to offer,” Dr. Scangos added. “Evidence that this type of therapy can work gives hope to patients”

Around 17 million adults in the U.S. have severe depression, with as many as 6 million considered treatment-resistant. This potentially revolutionary type of treatment could have long reaching effects.

“There could be a whole other type of treatments that are based on biomarkers that can deliver treatment on short time frames rather than anti-depressants which act on much longer time frames so I think it has a lot of implications.” Dr. Scangos said. “The approach itself is not specific to depression. It can be broadly applied to many psychiatric and neurological conditions.”

“We’re starting to recognize some of the complexity that’s involved with how mood is regulated as a network,” Dr. Chang said. “Not just one particular node that’s responsible for all moods but interacting areas in the brain that give rise to really complex emotions that underlie things like depression and anxiety.”

The battery in Sarah’s device will last over 10 years and scientists are hopeful it can adapt with any feelings of depression she has. For now she’s is relishing her new found joy.

MORE NEWS: 'Prolific' San Francisco Retail Theft Suspect Back In Jail After New Arrest

“This is another option and I hope people hear this,” said Sarah. “And they reach out to their medical providers and ask if this is something that would work for them.”