Saoirse Kennedy Hill may have had part of the answer to the mass shootings plaguing the nation. But although she shouted it to the rooftops, no one in authority would listen.

They must listen now. Three years before her death last week at age 22 from an apparent overdose at her family’s compound on Cape Cod, Saoirse, a granddaughter of Robert F. Kennedy, wrote a heartbreaking piece in her school newspaper about her struggles with depression and other forms of mental illness. She was scared, suicidal. She cried out for help.

But as she told it, the law of the land prevented people on whom she depended from getting close. It isn’t known if she ­intentionally ended her life. But she was drowning.

“My sense of well-being was already compromised, and I totally lost it after someone I knew and loved broke serious sexual boundaries with me,” Saoirse wrote in The Deerfield Scroll, the newspaper for the elite Deerfield Academy in Massachusetts. “I did the worst thing a victim can do, and I pretended it hadn’t happened. This all became too much, and I attempted to take my own life.”

Saoirse then pointed a finger of blame in an unexpected direction. She blasted the federal law that prevented her school’s faculty and staff from reaching out and talking to her about her demons: the Health Insurance Portability and Accountability Act — a pernicious set of regulations that is meant to protect patient privacy but in effect protects schools and other institutions from liability while leaving the ill untreated.

“Federal laws designed to protect patient privacy constrain what information can be shared in workplaces and schools,” Saoirse wrote, quoting the school’s director of counseling. “HIPAA was designed to protect patient privacy, yet in my experience, it left me feeling very much alone.”

As Saoirse learned, the law builds insurmountable obstacles between troubled young people and the help they desperately need.

How many angry young men have come up against the same barrier?

Mass shootings in El Paso, Texas, and Dayton, Ohio, have sparked a national conversation about how insanely easy it is for psychos to obtain powerful firearms. We need more and better gun control and universal background checks.

But laws that prevent us from even discovering the identities of dangerous people, and stopping them before they do their worst, help no one — except the would-be killers.

We, as a nation, have made a choice. We shield privacy at the expense of human life. Signed into law in 1996, HIPAA does allow mental health professionals to discuss specific threats made to the safety of patients or others with family members or law enforcement.

Yet as Saoirse wrote, instead of protecting her, the law made her feel isolated and much, much worse. She added that if staffers at her school “had reached out to me, I would have let them know that I wanted my circumstances shared with my teachers and advisers before I returned to campus; this would have made my transition back a lot easier.”

But HIPAA only allows patients to give express permission to allow the sharing of information with others. So no one approached Saoirse to offer help.

Apparently, some in the mental health community have realized that the law may hinder the treatment of patients for opioid abuse in the current crisis, and a group of state attorneys general is urging Congress to change the law and to smooth the sharing of information, at least related to drug use. But change is slow and onerous. In the meantime, too many people live in agony, needlessly.

“Many people are suffering, but because many people feel uncomfortable talking about it, no one is aware of the sufferers.” She asked only that people “come forward and talk freely about mental-health ­issues.” She added: “We are all either struggling or know someone who is battling an ­illness. Let’s come together to make our community more inclusive and comfortable.”

A noble goal, but incredibly hard to achieve. And people continue to die at a dizzying pace. Lawmakers must act, and act now. Relaxing HIPAA will save lives.