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.
Subscribe or register today to discover more from DonegalLive.ie
Buy the e-paper of the Donegal Democrat, Donegal People's Press, Donegal Post and Inish Times here for instant access to Donegal's premier news titles.
Keep up with the latest news from Donegal with our daily newsletter featuring the most important stories of the day delivered to your inbox every evening at 5pm.