(CNN) The Trump administration has agreed to allow a Stanford University pediatrician to conduct an independent investigation into health conditions for migrant children at US Customs and Border Protection facilities.

The pediatrician, Dr. Paul Wise, toured detention centers at the border last summer and was critical of the conditions there, according to a Stanford publication

In that interview, Wise described how migrant children are kept in a "kind of cage-like" processing center.

"From there, they get moved to a different processing center, which is kind of cage-like, and labeled the 'perrera,' the dog pound," he said in the September 17, 2018 article. "And that's the photographs you saw of kids in cages."

"One major concern was that the infrastructure of health care for children and their families coming through the asylum process is woefully inadequate," he added.

JUST WATCHED See children's drawings of Border Patrol facilities Replay More Videos ... MUST WATCH See children's drawings of Border Patrol facilities 01:20

Under the agreement, arranged as part of a lawsuit against the government in federal court, Wise will be able to conduct inspection of CBP facilities and assess children in the agency's care. US District Judge Dolly Gee authorized Wise's appointment on Monday, according to court documents.

Advocates for children applauded the appointment of an independent investigation into what has been called deplorable and dangerous conditions for children in detention.

"I think it's a huge step forward," said Jennifer Podkul, senior director of policy and advocacy at Kids in Need of Defense, which is not part of the lawsuit. "Third-party oversight is crucial to ensuring that the government is living up to the minimum standards it agreed to when holding children. The fact that he's a medical professional who has expertise and knows what to look for is crucial."

The litigation between the government and the children's lawyers has been ongoing for years.

"It's a travesty it took this long," Podkul said. "It's devastating that it took the deaths of several children for this to happen."

JUST WATCHED Migrant mom: I watched my baby girl die slowly Replay More Videos ... MUST WATCH Migrant mom: I watched my baby girl die slowly 03:11

Since September, four children have died in or just after being released from CBP custody.

In the lawsuit, migrants and their advocates described "deplorable" and unsanitary conditions where babies were sick, flu was spreading and children didn't have access to essential and prompt medical care.

A spokesperson for US Customs and Border Protection said the agency could not comment on ongoing litigation.

A lawyer for the children said he fully supports Wise's appointment.

"We believe he will play a critically important role in developing a range of protocols that if adopted would substantially decrease the unsafe and unsanitary conditions children are currently experiencing in Border Patrol custody," said Peter Schey, president and executive director of the Center for Human Rights and Constitutional Law.

Wise will submit a draft report of his findings and recommendations on or before August 15, according to a court document filed late Friday in California.

Conditions for children at the border

Over the past five years, children have poured across the US border , seeking relief from violence and devastating economic conditions, mainly in Mexico, Honduras, Guatemala and El Salvador.

From October 2018 through May of this year, more than 230,000 children have been apprehended at the border. Of those, about 170,000 were accompanied by a parent or legal guardian and about 56,000 were unaccompanied.

In May, the Department of Homeland Security's Inspector General found that at one point, 900 migrants were crammed into an El Paso, Texas, Border Patrol processing facility that had a maximum capacity of 125 people.

According to court filings, Dr. Dolly Sevier, a pediatrician in Brownsville, Texas, who visited children in a detention center said they were kept in conditions that "could be compared to torture facilities. That is, extreme cold temperatures, lights on 24 hours a day, no adequate access to medical care, basic sanitation, water or adequate food."

In his interview for the Stanford publication, Wise referred to detainees being kept for a period of time in a "facility which is freezing cold. It's called the 'hielera,' the ice box."

He also mentioned that volunteer doctors working in border area clinics are often "overwhelmed."

"A caring volunteer neurosurgeon may help fill in, but when is the last time that this doc saw a 5-year-old with diarrhea and PTSD?" he said.

Wise declined to comment to CNN for this story.

As part of the current litigation , migrant families have given statements about health conditions at the detention facilities. For example, one mother said she had no way to wash her baby's bottle, and her baby developed vomiting and diarrhea. She said she asked for help twice, but guards said her baby did not need to see a doctor.

At a congressional hearing Friday, an attorney choked up as she recalled the conditions she witnessed for children at a Border Patrol facility in Texas.

"They were coughing, they had fevers," said Elora Mukherjee, director of the Immigrants' Rights Clinic at Columbia Law School. "There was a flu epidemic and lice."

She said children as young as 8 were taking care of younger children who were strangers to them.

"Guards would bring in the little ones, and demand, who is going to take care of this one?' " Mukherjee said.

Migrant children are supposed to be kept in Border Patrol custody for no more than 72 hours. But a recent report by an internal government watchdog found that nearly a third of children in the facilities they inspected were kept longer. Some children under age 7 had been held for more than two weeks.

In early June, Acting Homeland Security Secretary Kevin McAleenan told CNN that the facilities were overcrowded and "not an appropriate setting for kids."

On Tuesday, he told CNN that "we've been taking action" and that the agency was providing "additional medical care" from more than 200 certified providers. A CBP spokesperson said that includes nurse practitioners, physician assistants, emergency medical technicians, certified medical assistants and other medical support personnel.

He also said there were fewer than 200 unaccompanied children in Border Patrol stations and only a few were staying more than 72 hours.

A senior health official with Homeland Security told CNN last week that he was proud of the medical care being given to migrant children.

"I'm a doctor and a parent," he said. "I would do for these folks what I would want done for my own children."

CBP "makes extensive efforts," according to an agency spokesperson, "to ensure regular availability of appropriate food, water, sanitation, and hygiene in all of its facilities."

The spokesperson added that most of the facilities in their highest volume sectors have around-the-clock medical support available on-site to treat migrants and refer them as necessary to local hospitals.

'Stuck in a hellhole'

Friday's filing is the latest chapter in what's known as the Flores settlement . That 22-year-old agreement requires the government to provide detained minors a certain level of basic conditions, including food, drinking water, supervision and medical assistance in emergencies.

In April, President Trump complained about the "very bad" Flores decision.

"Judge Flores, whoever you may be, that decision is a disaster for our country," he said.

But there is no Judge Flores. The settlement is named for Jenny Lisette Flores, a migrant teenager who was a plaintiff in the now-famous legal case.

In June, Gee, the current judge in the case, gave the government just two weeks to come up with a plan to better the conditions for children.

"If 22 years has not been sufficient time for Defendants to refine that plan in a manner consistent with their 'concern for the particular vulnerability of minors,' and their obligation to maintain facilities that are consistently 'safe and sanitary,' it is imperative that they develop such a comprehensive plan forthwith," she wrote.

Podkul, the attorney at Kids in Need of Defense, said another part of upholding the Flores agreement is that the government must reunite children expeditiously with family members and guardians in the United States.

"With the kind of resources our government has, there's no reason this can't be done," she said. "It's a matter of will and implementing smart policies."

Mukherjee, the Columbia University attorney, said that was very much on her mind when she visited detained children in Texas.

She described meeting with a detained 6-year-old who sobbed nearly unconsolably for almost an hour.

"I had to break out of my role as a lawyer. I let him sit on my lap, I wiped away his tears," she said. "And I teared up too. Here was a child, the same age as my son, stuck in a hellhole."

Get CNN Health's weekly newsletter Sign up here to get The Results Are In with Dr. Sanjay Gupta every Tuesday from the CNN Health team.

She said a Border Patrol guard brought the little boy a lollipop as an incentive to go back to his cell. Mukherjee said she "pleaded" with a Border Patrol lawyer to give the child appropriate care.

She said the next day that lawyer informed her that the boy would be released and reunited with his brother.

"Why didn't that happen sooner? What would have happened if I didn't meet with him that day? What is happening to hundreds of thousands of other children like him?" she asked.