Two police officers were attacked by a man they were "supervising" at the Causeway Hospital in Coleraine.
The man had earlier been arrested in connection with an attempted knife robbery at an off-licence in Limavady.
A person working in the off-licence recognised Adam Hogg as someone he knew for more than ten years and the defendant fled empty-handed.
Hogg, 29, of Benevenagh Drive, Limavady, was arrested at an address and a small quantity of cannabis was recovered.
The defendant was taken to Coleraine Police Station and then had to be transferred to the Causeway Hospital where he assaulted two police officers who were "supervising" him.
During the incident he threw a "barrage of punches" and attempted to headbutt one officer.
One of the officers needed treatment and the other had difficulty walking because of injuries sustained.
The attempted robbery charge had already been sent to the Crown Court but Hogg appeared at court via video link from prison, on Monday, in connection with two assaults on police and possession of cannabis relating to August 5 last year.
The defendant was also sentenced in relation to possessing cannabis on New Year's Day 2017 and sending a threatening message to a man.
A defence barrister said Hogg was bipolar and had a "significant" drug problem and matters came to a head with the attempted robbery but he is now addressing his addiction issues.
Hogg was given a four months jail term.
If you have a story or want to send a photo or video to us please contact the Derry Now editorial team on 028 7129 6600 for Derry City stories Or 028 7774 3970 for County Derry stories. Or you can email firstname.lastname@example.org or email@example.com at any time.
Subscribe or register today to discover more from Derrynow.com
Buy the e-paper of the Derry News and the County Derry Post here for instant access to Derry's premier news titles.
Keep up with the latest news from Derry with our daily newsletter featuring the most important stories of the day delivered to your inbox every evening at 5pm.