I. Any person confined in a county department of corrections facility, state prison or other place of detention may, under necessary precautions, be taken by some regular or specially authorized officer from such place of detention to a medical facility for the purpose of receiving medical examination or treatment upon recommendation of a physician, a physician’s assistant, or an advanced practice registered nurse (APRN) and upon approval of the superintendent of the institution in which the person is confined. In the case of a transfer of a pretrial prisoner for medical purposes for a period in excess of 10 days, the justice of the court who originally ordered the prisoner’s commitment shall be given written notice of the transfer within 15 days of said transfer, and shall be given notice upon the return of the prisoner within 15 days of the prisoner’s return, provided the prisoner is not in the custody of correctional personnel while at the medical facility. The provisions of RSA 402:79 shall apply to payments for medical care provided pursuant to this section.
   II. Any person confined in a county department of corrections facility, state prison or other place of detention may be temporarily taken from his place of confinement because of the imminently approaching death or funeral of a member of his immediate family or for other imperative and extraordinary purpose, including treatment, counseling or rehabilitation programs, for a period not exceeding 72 hours without approval by a justice of the superior court.
   III, IV. [Repealed.]