As a defense attorney, I would have requested a mitigation hearing prior to sentencing.
At that hearing I would have presented all the medical issues at hand. I may have even brought the doctor to court to testify as to the negative effects of a jail sentence for this person. That would be far more impactful than an attorney stating so. A medical professional with nothing to be gained by sharing a diagnosis and prognosis resonates more to the court, for these facts, than an attorney.
I would have also disclosed medical documents to the court and the prosecutor in advance of sentencing and/or in advance of the acceptance of a plea agreement. (The best time to have done this would have been during plea negotiations). Finally, I would have included letters of support from family members and friends. I am not sure if it is too late for you because you indicated: "[H]e took a deal..." which leads me to believe that sentencing may be over with or stipulated. However, an attorney may always try to help by submitting an: Emergency Motion For Reconsideration of Imposed Sentence.
Assuming the jail term was not a stipulated term in a plea agreement, I would have presented the court with a hybrid of alternatives such as electronic monitoring via ankle bracelet or a GPS tracking device, random drug testing, house arrest, curfew, etc. I would have had a family member or close friend inform the court of their willingness to assume some responsibility for the person should they not comply with any such terms. That said, jurisdictions have different rules and you would need to determine what your state would preclude or include as possibilities.