Yes, it is legal and is considered a refusal and non compliance. Someone obviously was with your child that could have stayed with them, long enough for you to provide a urine sample before leaving.
Despite the Emergency, you were there for almost 2 hours prior and failed to provide the sample requested.
You should be able to provide documentation of the accident (police report), and ER records documenting your child's accident, and visit to the ER.
Doctors are under no obligation to care for a patient, and not under any obligation to continue scheduled medications or taper you off if you fail to follow the policies.
For all the doctor or office staff knows, you could have had a friend or family member contact you to give you a reason to leave. NOT saying you did that, but it happens far more often than you might think.
In today's environment and scheduled medications, patients need to be prepared to give a urine sample at every visit.