(CNN) A federal judge has ordered lawyers representing detained migrants and US Customs and Border Protection to quickly resolve a demand that health experts be allowed to examine children and inspect detention facilities.

The order encompasses all facilities in the CBP's El Paso and Rio Grande Valley sectors, which are the subject of a lawsuit.

Last week, lawyers asked US District Judge Dolly Gee to hold President Donald Trump's administration in contempt and order immediate improvements at the facilities. The lawyers are part of a team of doctors and advocates that warned last week of what they said were major health and hygiene problems at Customs and Border Protection facilities in Texas following visits to the facilities.

"Children are held for weeks in deplorable conditions, without access to soap, clean water, showers, clean clothing, toilets, toothbrushes, adequate nutrition or adequate sleep. The children, including infants and expectant mothers, are dirty, cold, hungry and sleep-deprived," the court filing said.

The attorneys asked that the court force CBP to allow a public health expert to inspect the facilities and create a binding plan to ensure the centers are "safe and sanitary," and to permit medical experts to examine the detained children and address their medical needs.

Gee, who sits on the federal bench for the central district of California, made her ruling late Friday, despite Attorney General William Barr and other defendants' request that the court "set a schedule for briefing these issues that provides defendants with a full and fair opportunity to respond to the allegations that plaintiffs have lodged against them."

Gee set a deadline of July 12 for the parties to "file a joint status report regarding their mediation efforts and what has been done to address post haste the conditions described."

A monitor previously appointed by the court "may, in her discretion, set other deadlines and take other measures appropriate to facilitate the prompt remediation of the conditions at issue, including the retention of an independent public health expert," Gee wrote.

Judge cites previous violations

The detention centers have become a political volleyball, with critics likening them to concentration camps and torture facilities, while supporters say they're necessary to an effective immigration policy.

At issue is the 1997 Flores Agreement, which sets standards for detaining child migrants and requires the government to release children to their parents, adult relatives or licensed programs without unnecessary delay.

"The Court has already issued several orders that have set forth in detail what it considers to be violations of the Flores Agreement," Gee wrote in her Friday ruling. "Thus, the parties need not use divining tools to extrapolate from those orders what does or does not constitute non-compliance. The Court has made that clear beyond peradventure."

JUST WATCHED The sandwich shop feeding migrants waiting at the border Replay More Videos ... MUST WATCH The sandwich shop feeding migrants waiting at the border 02:53

The judge cited a July 2015 order chronicling "widespread and deplorable conditions in holding cells" and a June 2017 order documenting "unsanitary conditions at certain CBP facilities."

"Plaintiffs claim that CBP has continued to commit many of the same violations years later," Gee wrote.

The judge wrote in the order that she is aware that a sudden influx of migrants presents challenges and that the conditions at the facilities are not static, but the 1997 agreement demands defendants compose a plan outlining its efforts "to place all minors as expeditiously as possible."

"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," Gee wrote, using italics for emphasis.

Teens describe desperation

Among the detention centers in question is a Clint, Texas, facility that reporters toured on Wednesday, but were barred from taking any photographs or video.

While border patrol officials showed journalists pallets of food, boxes of toiletries and children playing soccer and braiding hair, a CBP source with firsthand knowledge of the facility told CNN , "Typical. The agency prepped for you guys."

Lawyers in Flores v. Barr presented as exhibits dozens of anecdotes from children and teen mothers complaining of mistreatment, filthy conditions and lack of access to clothing, adequate food and medical care.

JUST WATCHED Castro: Trump likes to terrorize immigrant families Replay More Videos ... MUST WATCH Castro: Trump likes to terrorize immigrant families 01:51

"I am in a room with dozens of other boys," a 17-year-old told lawyers fighting for the migrant children. "Some have been as young as 3 or 4 years old. Some cry. Right now, there is a 12-year-old who cries a lot. Others try to comfort him. One of the officers makes fun of those who cry."

15-year-old girl from El Salvador said , "A Border Patrol agent came in our room with a 2-year-old boy and asked us, 'Who wants to take care of this little boy?' Another girl said she would take care of him but lost interest after a few hours and so I started taking care of him. ... I feed the 2-year-old boy, change his diaper and play with him. He is sick. He has a cough and a runny nose and scabs on his lips."

Dr. Dolly Lucio Sevier, who interviewed 39 children, likened the conditions in the detention centers to "torture facilities," according to a court filing.

"That is, extreme cold temperatures, lights on 24 hours a day, no adequate access to medical care, basic sanitation, water or adequate food," the pediatrician said. "All 39 detainees had no access to hand-washing during their entire time in custody, including no hand-washing available after bathroom use."

CORRECTION: An earlier version of this story stated that the federal judge ordered CBP to allow doctors and health experts into the detention facilities for inspection. The judge, in fact, ordered the two sides to mediate the migrants' demands that experts be allowed into the facilities.