a. If a physician to a jail or in case of a vacancy a physician acting as such and the warden or jailer certify in writing that a prisoner confined in a jail, either in a civil cause or upon a criminal charge, is in such a state of mental health that he or she is in need of involuntary care and treatment and in their opinion should be removed to a psychiatric hospital for treatment, the warden or jailer shall immediately notify the director who shall have the responsibility for providing treatment for such prisoner. If such director after examination of the prisoner by an examining physician designated by him or her shall determine that such prisoner is in need of involuntary care and treatment, the director shall file an application for the involuntary hospitalization of such prisoner pursuant to article nine of the mental hygiene law in a hospital or secure facility, as defined in paragraph b of this subdivision, operated by the office of mental health or in the case of a prisoner confined in a jail in a city or county which maintains or operates a general hospital containing a psychiatric prison ward approved by the office of mental health to such prison ward for care and treatment or to any other psychiatric hospital if such prison ward is filled to capacity. Such application shall be supported by the certificate of two physicians in accordance with the requirements of section 9.27 of the mental hygiene law and thereupon such prisoner shall be admitted forthwith to the hospital or secure facility in which such application is filed, and the procedures of the mental hygiene law governing the hospitalization of such prisoner. The jailer or warden having custody of the prisoner shall deliver the prisoner to the hospital or secure facility with which the director has filed the application. If such jailer or warden shall certify that such prisoner has a mental illness which is likely to result in serious harm to himself, herself or others and for which care in a psychiatric hospital is appropriate such jailer or warden shall effect the admission of such prisoner to a hospital or secure facility forthwith in accordance with the provisions of section 9.37 or 9.39 of the mental hygiene law and the hospital shall admit such prisoner. Upon admission of the prisoner, pursuant to section 9.37 or 9.39 of the mental hygiene law, the jailer or warden shall notify the director, the prisoner's attorney, and his or her family, where information about the family is available. While the prisoner is in the hospital, other than a secure facility, he or she shall remain in the custody under sufficient guard of the jailer or warden in charge of the jail from which he or she came. When the prisoner is in a secure facility, the jailer or warden may transfer custody of the incarcerated individual to the commissioner of mental health, pursuant to an agreement between such jailer or warden and such commissioner. A prisoner admitted to a psychiatric hospital pursuant to section 9.27, 9.37 or 9.39 of the mental hygiene law may be retained at the hospital or secure facility pursuant to the provisions of the mental hygiene law until he or she has improved sufficiently in his or her mental illness so that hospitalization is no longer necessary or until ordered by the court to be returned to the jail whichever comes first and in either event, the prisoner shall thereupon be returned to jail. The cost of the care and treatment of such prisoners in the hospital or secure facility shall be defrayed in accordance with the provisions of the mental hygiene law in such cases provided.
From the time of admission of a prisoner to a hospital under this section the retention of such prisoner for care and treatment shall be subject to the provisions for notice, hearing, review and judicial approval of continued retention or transfer and continued retention provided by article nine of the mental hygiene law for the admission and retention of involuntary patients.