Congratulations on being almost done with your pregnancy!! Yay! I understand your dilemma here. I am going to ask a hard question hon. Do you think you have a problem with pills? You've taken a lot. And pain is a reason to take them but . . . you've broken down and taken pills while very pregnant that were not even your own prescription. Things point to perhaps you need to consider that this problem is deeper and that getting help for a pain pill problem would be important. AA is a good place to start. Just even read online for a start. Please. You are about to be a parent and baby needs a healthy mom who isn't going to turn easily to pain pills.
As to this situation of taking them ---- my best advice is to come clean for your doctor. Many hospitals do test newborns. Pain pills can occasionally be prescribed by a doctor while a woman is pregnant but that is controlled. Just showing up with narcotics in the system is a red flag. So, you should tell your doctor to stop any action that might be taken. Don't try to hide it. They may talk to you as well about possibly a brewing addiction. But this is something you should listen too. The reason why these meds are so dangerous and so controlled is because it is so easy to begin a dependency on them. And then your life isn't yours anymore.
So, talk to your doctor and let us know how it goes sweetie. hugs