LOS ANGELES — A federal judge has ordered a mediator to move swiftly to improve health and sanitation at Border Patrol facilities in Texas, where observers reported migrant children were subject to filthy conditions that imperiled their health.

Judge Dolly M. Gee of the Central District of California asked late on Friday that an independent monitor, whom she appointed last year, ensure that conditions in detention centers are promptly addressed. She set a deadline of July 12 for the government to report on what it has accomplished “post haste” to remedy them.

“We are hoping we can act expeditiously to resolve the conditions for children in Border Patrol custody,” said Holly Cooper, part of a team of lawyers who asked the federal court to intervene.

The lawyers’ reports on conditions at a Border Patrol facility in Clint, Tex., where they said children were unable to bathe, were living in filthy clothes and diapers and were often hungry, prompted a public outcry and a new motion asking the court to force the government to move more aggressively to improve accommodations along the border for the thousands of migrants arriving from Central America.