The 22 immigrants who died in the nation's sprawling network of detention centers over the past two years came to the United States from countries as far-flung as Vietnam, and as close as Mexico. Some had been longtime legal residents, arriving as refugees or students. Others were recent asylum seekers. Many were young — half were not yet 45 years old.

Roxana Hernandez was one. Hers was among the most high-profile of the deaths in Immigration and Customs Enforcement custody during the Trump administration.

The 33-year-old transgender woman from Honduras arrived at the U.S. border seeking asylum as part of a migrant caravan. She died within two weeks of entering ICE custody. Hernandez's death, along with the recent deaths of two young children held by U.S. Customs and Border Protection, has brought renewed scrutiny to immigrants in the federal government's custody.

Roxana Hernandez, right, a transgender woman who was part of the caravan of Central American migrants, died in ICE custody at a hospital in Albuquerque, New Mexico on May 25, 2018. Annie Rose Ramos

"One death is too many," said Homeland Security Secretary Kirstjen Nielsen during testimony before the House Judiciary Committee on Dec. 20, in the wake of the first child's death.

Nielsen's agency oversees both CBP, which apprehends unauthorized migrants at the border and holds them for short stints, and ICE, which arrests immigrants in the interior of the country, and operates a large network of longer-term detention centers. The DHS detention centers, said Nielsen, have "some of the highest standards in the world."

But an NBC News review of dozens of government reports, death reviews and audits of ICE detention centers reveals a system long riddled with problems. Within the last year, the DHS Office of Inspector General has issued three reports finding poor treatment and spotty oversight in ICE facilities.

While the issues predate President Donald Trump, his administration has expanded ICE's enforcement priorities. Advocates said the rollback of discretion as detention expands puts vulnerable immigrants at risk.

"You'll see someone who is clearly an asylum seeker who came into custody with a serious medical condition, whether a heart condition or otherwise, and you have to ask, 'Why is this person in jail?'" said Heidi Altman, director of policy at the National Immigrant Justice Center. "There's no reason for it."

Two years into the Trump administration, 22 immigrants have died in ICE detention, according to an NBC News analysis of 188 detainee deaths since 2003, when the Department of Homeland Security was formed in the wake of the Sept. 11 attacks.

This remains below the peak of 32 deaths in 2004, the first full calendar year records were kept. Deaths rose and then fell during the Obama administration, from 10 in 2008 to five in 2012, a period in which ICE implemented policies to improve detention conditions and oversight. But deaths then ticked up to 12 in President Obama's last full year in office, 2016, as the number of detainees grew.

Under Trump, as the immigrant detainee population has surged still higher, the annual number of deaths was 10 in 2017 and 12 in 2018.

ICE has said deaths in detention are "exceedingly rare," involving a fraction of those detained by the agency.

The tally does not include the recent deaths of two Guatemalan children in CBP custody. Jakelin Caal Maquin, 7, and Felipe Alonzo-Gomez, 8, died within weeks of each other in December. Nor does it include the March death of a 20-month old girl, Mariee Juárez, nearly two months after she was held at an ICE family detention center in Texas with her mother. Her mother is now suing the government, alleging neglect.

Alonzo-Gomez's death on Christmas Eve prompted DHS to order increased medical screenings of children and look into bringing in medical staff from other federal agencies.

In a tweet last week, Trump foisted responsibility for the children's deaths onto Democrats as he remained firm in maintaining the government shutdown until Congress approved funding for the border wall. Nielsen also pointed to politics and failures in the courts for the problems at the border.

Any deaths of children or others at the Border are strictly the fault of the Democrats and their pathetic immigration policies that allow people to make the long trek thinking they can enter our country illegally. They can’t. If we had a Wall, they wouldn’t even try! The two..... — Donald J. Trump (@realDonaldTrump) December 29, 2018

"The system is clearly overwhelmed and we must work together to address this humanitarian crisis and protect vulnerable populations," Nielsen said in a statement released after meeting with officials in El Paso. "We know that if Congress were to act, or the courts were to enforce the law as written, we could address this crisis tomorrow."

Audits question medical care

ICE held an average of about 42,000 people a day in its network of more than 200 detention centers and jails last fiscal year. This is a 30 percent increase over the average in the Obama years, DHS data shows, and more than double the average under Bush. In its most recent budget, the Trump administration pushed to expand the number of beds to more than 51,000.

A significant piece of that recent jump in those detained came not from a flood of migrants crossing the border, but from increasing ICE arrests in communities across the U.S. Since Trump signed an executive order nearly two years ago broadening the types of immigrants considered priories for ICE enforcement, "administrative" arrests for violations of civil immigration law have risen 44 percent.

A boy carries a picture Jakelin Caal while her coffin is carried to the cemetery in San Antonio Secortez, Guatemala, on Dec. 25, 2018. Johan Ordonez / AFP - Getty Images

Troubles with medical care in ICE detention began long before Trump's election. In the late 2000s, a series of exposes led the agency to overhaul detention standards and set up more rigorous oversight.

Dora Schriro helped put those in place as the founding director of ICE's Office of Detention Policy and Planning, formed under Obama. The standards focused on increasing transparency and oversight and ensuring that only those who presented an immediate risk were detained. She said the changes lowered the risk of harm in detention, too. It was "good policy and good practice," she said.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

The Trump administration has sought to curtail and even shutter the office she founded as it pushed for a quick expansion of detention, which Schriro highlights as a pattern within the agency.

"There are these whiplash changes in policy and practice but without any of the planning and preparation," Schriro said. Whatever one thinks of the detention policies of a given administration, she said, "it's the lack of readiness" that poses the greatest risks.

Felipe Gomez Alonzo on Dec. 12, 2018 near his half-sister's home in Yalambojoch, Guatemala. Catarina Gomez / via AP

Poor planning and oversight can prove fatal, according to a string of reports from both advocates and DHS's own watchdog.

A report released this summer by a group of human-rights advocates asserted that ICE provided "dangerously substandard care in immigration detention." The problems included delays, incompetence and botched emergency care that they believe contributed to the deaths of 15 immigrants between December 2015 and April 2017.

"We uncovered a pretty shocking picture of inadequate, substandard care," said Clara Long, a senior researcher with Human Rights Watch who co-authored the report.

In late 2017, the DHS inspector general found "problems that undermine the protection of detainees' rights, their humane treatment, and the provision of a safe and healthy environment" at four facilities. A second audit said that ICE failed to adequately inspect and monitor the more than 200 federal, local and private facilities it uses across the country. Some problems "remained unaddressed for years," according to the report, in which some within ICE described higher-ups as "reluctantly responsive" to addressing issues.

Secretary of Homeland Security Kirstjen Nielsen is sworn in before testifying to the House Judiciary Committee hearing on oversight of the Department of Homeland Security on Capitol Hill on Dec. 20, 2018. Joshua Roberts / Reuters

An ICE spokesperson told NBC News in a statement that it is ramping up its "already robust inspections program," and plans to do follow-up inspections to address "areas of concern."

The agency said it is "confident in conditions and high standards of care at its detention facilities," and that immigrants get medical, dental and mental health screenings upon arrival, follow-ups within two weeks, and access to round-the-clock emergency care.

The spokesperson added that many detainees arrive with medical conditions, and may never have received treatment before being detained.

New details emerging

This summer, Hernandez's death brought renewed scrutiny to ICE's detention facilities, spurring a group of Democratic lawmakers to demand that the agency comply with a Congressional mandate to release information within 90 days of any death.

On Dec. 19, the agency released reports on six people who died in 2018, including Hernandez.

Documents show she requested asylum at the U.S.-Mexico border in San Diego on May 9, and was taken into CBP custody. Four days later she was transferred to ICE.

In the week prior to her death, she was moved four times: from California to Arizona, then to Texas and finally to New Mexico, where she was rushed to the hospital upon arriving on May 17. She was dehydrated, starving and feverish, according to details released by ICE. Doctors discovered that, in addition to untreated HIV, she was in septic shock. She died on May 25.

It’s been nearly 200 days since Roxsana Hernández’s death and we still don’t have any answers. That’s why Senators @tomudall, @MartinHeinrich and I are demanding her full and complete death review be released. — Kamala Harris (@KamalaHarris) December 12, 2018

An independent autopsy disputed the initial determination that Hernandez died from cardiac arrest, finding that she likely died from complications due to severe dehydration and HIV — and that her body showed evidence of "physical abuse."

Advocates, including the attorney representing the families of Hernandez and three other immigrants who died in custody, said the newly released documents lack important details and a critical analysis about the deaths.

This summer, NBC News submitted a records request for the death reviews of all detainees who have passed away in the past two years. ICE has not yet fulfilled that request, making it difficult to get a complete picture of the deaths.

The following details of the deaths come from publicly released reports, autopsies, investigation files obtained by NBC News, as well as documents obtained by advocates. In some cases, documents show troubling delays in providing care to detainees with serious medical conditions, from diabetes and hypertension to mental illness. ICE's own internal reviews found that the agency fell short in providing adequate medical attention to immigrants in its care.

Since January 2017, five men have taken their lives while in ICE custody. Three of the men were mentally ill and had spent days or weeks in segregation or solitary confinement.

In March 2017, Osmar Epifanio Gonzalez-Gadba fashioned a noose from a bedsheet and hung himself in a cell at the Adelanto Detention Center in California. Leading up to his death, the 32-year-old Nicaraguan asylum seeker was in a segregation cell, and had become withdrawn and began hallucinating, according to an ICE detainee death review, which found the facility failed to follow proper protocols in his care.

An unannounced visit to Adelanto by the inspector general a year later found nooses in cells, harsh use of segregation and "untimely and inadequate medical care."

Weeks after Gonzalez-Gadba's death, Jeancarlo Jimenez-Joseph was in solitary confinement at the Stewart Detention Center in Georgia when a fellow detainee heard him tell officers "I'm suffering from psychosis," according to a state death investigation obtained by NBC News. In May 2017, the day before the 27-year-old was scheduled to see a doctor, he hung himself in his cell with a bedsheet.

A year later at the same facility, Efrain Romero De La Rosa, a 40-year-old with schizophrenia, had been in solitary confinement for three weeks when he began to hear voices. He claimed he was the "Anti-Christ," according to ICE records. He was transferred to a treatment facility for a month and a half. A week after returning to Stewart, De La Rosa was put again into isolation as punishment for making "sexual proposals." On July 10, three weeks into isolation, he took his own life.

A sixth detainee died in an apparent suicide in the Cairo airport, according to ICE, while being deported back to Eritrea. An ICE spokesperson said the agency did count it as an in-custody death because he had been handed over to Egyptian officials.

Several others died of cardiac issues.

Huy Chi Tran, 47, arrived from Vietnam in 1984 and became a legal permanent resident. ICE records show Tran also suffered from schizophrenia. After being convicted of assault, he was stripped of his green card and ordered deported in the mid-2000s.

Vietnamese immigrants like Tran who arrived before 1993 have been considered protected from deportation since 2008, when the U.S. and Vietnam signed a repatriation agreement. Over the last year the Trump administration has moved to reverse those protections, detaining Vietnamese regardless of when they arrived amid a wider effort to deport immigrants whose countries would not previously take them back.

ICE picked Tran up in May 2018 from an Arizona prison where he was serving time for disorderly conduct. He was slated to be deported before he died of a heart attack in June.

In a statement, ICE said, "The U.S. position is that every country has an international legal obligation to accept its nationals that another country seeks to remove, expel, or deport."

Some suffered from drug withdrawals.

When Sergio Alonso Lopez, 55, entered Adelanto in February 2017, he had been undergoing methadone treatment for 17 years.

A doctor at Adelanto ordered him to taper off methadone over 12 days, an ICE review shows. Staff failed to administer several doses of methadone. A nurse told investigators there was little direction about prioritizing patients and too few staff.

On April 1, Lopez was rushed to the hospital. Officers cuffed his swollen leg to a hospital bed. Doctors treated him for cirrhosis, sepsis and serious internal bleeding. On the afternoon of April 13, he began vomiting blood. One officer with the Geo Group, a private prison company, guarding him tipped Lopez's head so he would not choke, while another ran into the hall to yell "Code Blue," according to the report. Lopez died three hours later of massive internal bleeding, cirrhosis, and substance abuse.

The Geo Group did not respond to a request for comment.

Seven months later, at a facility 1,000 miles away in Denver, the Geo Group would receive another detainee with a history of methadone use, an Iranian-born father of two named Kamyar Samimi.

In November 2017, ICE agents arrested the 64-year-old outside his suburban Denver home. He had lived in the U.S. since 1976.

Twelve years earlier, Samimi was convicted of a possession of a gram or less of cocaine, a low-level felony that stripped him of his green card. Soon after his arrest, he was taken to the Aurora Detention Facility, which has a history of substandard medical care.

In 2012, a 46-year-old Gabon man died from a heart attack after medical staff failed to immediately call 911. An ICE investigation of his death found he "did not have access to appropriate medical care" at the facility. This summer, two immigration groups filed a complaint with DHS claiming Aurora's "inadequate medical and mental health care" threatened the "health and well being of its detainees."

Samimi had been taken off methadone upon arriving in detention, according to records reviewed by NBC News. His autopsy stated that Samimi "had been 'clean' for two weeks in the ICE facility and was being watched for withdrawal, dehydration, nausea and vomiting." He was also on suicide watch.

On the morning of Dec. 2, he began spitting up blood, according to the autopsy. He was taken to a nearby hospital, where he was pronounced dead. While rare, "methadone withdrawal cannot be ruled out as the cause of death," the coroner noted in his report.

Soon after his death, the ACLU of Colorado began looking into what happened to Samimi. "Mr. Samimi's arrest, detention, and death in custody display the inhumanity of our current federal immigration policies," said ACLU Attorney Arash Jahanian.

One year has passed since Samimi died. "We are still looking for answers," Jahanian said.