CPS vs. Medical confidentiality and 4th amendment

Me and my wife were discussing this practice at her hospital. Although I agree with the end result I question the legality and or patient confidentiality issues attached to it and as a legal-acedemic excersize I present the following scenario.

Mom X comes into a hospital in labor, and will deliver within the next few hours.

The usual battery of tests are ordered to check on moms current state of health. They will also ask mom X if she has taken drugs, smoked, consumed alcohol during her pregnancy.

If mom admits to drug use, baby is tested to determine if baby is positive for illegal drugs. If baby tests positive, CPS is called in to take custody of the baby due to mom’s drug use endangering the health of her child.

If mom refuses to allow a drug screen to be done on the baby, CPS can supposedly take custody of the child on the basis that mom is doing so for the purposes of hiding her drug use.

Now I can see a drug screen being ordered as part of a check on an unknown problem and is just covering all of the bases, but targeting something with a criminal component, while asking these questions under the premise that the answers are needed for proper treatment to be conducted, then turning them over to a state agency to use as evidence to strip custody of your child…

IF CPS was requesting this information on a mom who came in who was a known drug abuser, and had appropriate warrants/court order to obtain this information I would see it as a totally clean bust, but hovering at a hospital (they have an office on the L&D floor) waiting for drug positive moms to come in and admit their problem seems a little evil.

It seems to me that CPS is abusing the fact that women have little choice but to seek medical assistance with the delivery of their child.
My questions become as follows:

1: Criminal charges for child endangerment could be brought against a mom who has taken drugs which were passed on to her baby. If she refuses the test and CPS seizes the child to test it, has an illegal search or seizure, for the purposes of pursuing a criminal charge against the mother, taken place?

2: Has the mom technically endangered her child when the child was still part of her? Why would smoking not count in the same way since its also very damaging to the unborn child.

3: Has a violation of medical confidentiality taken place by releasing this information to personell not involved in the care of the mom and or infant in question.

I do not believe from my (admittedly limited) knowledge of the law, wouldn’t this be illegal.