Not sure what the question is. Sounds like you have an ongoing prescription for a medicine available only by prescription, but there were a few pills left on a renewable prescription. That being the case, you can certainly take the pills after the renewal date if you still have them. More complicated would be whether you could take the drug after your prescription ends without any renewal allowed.
Finally, I'm not sure where the drug test comes in. If you have an ongoing prescription for a medication, one would think that that would be permissible. However, if the terms of whatever order precludes you from any trace of a certain type of drug (e.g., amphetamines), then it should have been sorted out at the time the prescription was issued. I think you might want to consult with a criminal attorney in that case.
Otherwise, a prescription medication taken in accordance with doctor's orders, should not be a disqualifying event, unless a job description requires that you are not allowed, for legitimate reasons of the employer or applicable law, to have that class of drug in your system. I don't think it would matter if the particular pills were from a prior prescription, as long as you are only taking the amount prescribed by the doctor. You should consult with an employment attorney if you are having issues.