An "armed and extremely dangerous" man who allegedly fired shots at a Hudson Valley hospital and at officers is heading to prison.

On Friday in Ulster County Court, Joshua Stuart was sentenced on his robbery conviction to 25 years in prison, he also received consecutive sentences of ten years each on two separate residential burglaries which occurred after the Ellenville Hospital robbery, as well as a consecutive sentence of 2 1/3 to 7 years on a conviction of criminal trespass and a sentence of 1 1/3 to 4 years in prison which for his conviction for stealing a car during his crime spree.

In total, Stuart was sentenced to over 47 years in prison, but under New York State law will be capped at 40 years. Stuart also faces separate consecutive sentences in Federal Court as a result of an armed robbery in Brooklyn.

The sentences stem from what officials say was a "series of violent crimes in the Town of Wawarsing in September of 2018."

On Sept. 28, 2018, Stuart of Kerhonkson allegedly entered the Ellenville Regional Hospital with a loaded handgun and forcibly stole numerous vials of drugs classified as opioids.

During the course of the robbery, he fired one shot from his gun inside the hospital, police say.

After fleeing the hospital, Stuart’s car was spotted in a wooded area off Cutler Road in Wawarsing. As the officers attempted to apprehend him Stuart fired several rounds from a 9MM handgun at officers and then fled into a large wooded area, officials say.

An intense manhunt ensued. Many local police agencies including the State Police, Ulster County Sheriff’s Office, DEP, the Ellenville Police Department and the Ulster County District Attorney’s Office searched for Stuart.

The next morning, Stuart is accused of burglarized a home on State Route 55, entering a second home looking to take a car and stealing from a third home.

While inside the third home, Stuart allegedly stole a purse and car keys and fled the property in the homeowner’s 2005 Honda Pilot.

The Honda Pilot was spotted in Brooklyn on Oct. 1. He was soon spotted near a Whole Foods Market in Brooklyn. Stuart attempted to flee into the Gowanus Canal and was captured shortly thereafter, police say.

At sentencing, Stuart stated to the Court “that none of these crimes would have happened if the people at the hospital just gave me what I needed," according to the Ulster County District Attorney's Office.