(a) Whenever, from sickness or other infirmity of the person directed to be produced by a writ of habeas corpus, the person cannot, without danger, be brought before the court or judge before whom the writ is returnable, the person in whose custody he or she is may state the fact in his or her return, verifying the fact by his or her oath. The court or judge, if satisfied of the truth of the allegations, if the return is otherwise sufficient, shall proceed thereon to dispose of the matter in the same manner, as if the prisoner were brought before him or her, except as provided in subsection (b) of this section.
(b) If, in the case mentioned in subsection (a) of this section, it appears that the prisoner is legally imprisoned or restrained and not bailable, the judge shall proceed no further therein. If the prisoner ought to be held to answer for a bailable offense, an order shall be made accordingly. When it appears the prisoner is entitled to his or her discharge, the judge shall make an order to that effect.