MC/Stillbirth

I was wondering if you go to the hospital during a miscarriage or stillbirth if they take your child away or if you can still see it and have a funeral. I know they're not fully developed but I don't want my baby ripped away from me if it happens. 
I'm 21 weeks tomorrow and I think most of my anxiety comes from thinking something is going to go wrong with the baby and that they'll take him from me. 
Does anyone know what the laws are or what happens? Do they still get a birth certificate? I just don't want something to go wrong and for everyone to think my pregnancy was insignificant if he doesn't make it because he matters to me and there's a good chance due to severe health issues I won't be able to conceive again. 
Help.