Trouble sleeping after total shoulder replacement surgery

I had total shoulder replacement surgery on February 13. Since March 1 I have only had two nights of maybe 6 hours week. Otherwise I have only like 2 hours sleep. Many nights I may not fall asleep till after 4 or 5 am. I usually go to bed around 11:30 pm. I do not have the tv on. I just close my eyes and try to fall asleep. Between having this sling on my arm and having to sleep on my back is causing these sleepless nights. I am a side sleeper by the way. I tried melatonin, magnesium and chamomile tea with no help. I asked the doctor for a sleeping pill. It only worked twice after using it for about a week. I feel like by sleep rhythm is seriously messed up. Can anyone offer any advice for me? I have never been in a situation like this before and not sleeping really scares me for my health and healing process.