(h) In any case in which a defendant has been placed in a diagnostic facility pursuant to this section and, in the course of his confinement, he is determined to be suffering from a remediable condition relevant to his criminal conduct, the department may, with the permission of defendant, administer treatment for such condition.
If such treatment will require a longer period of confinement than the period for which defendant was placed in the diagnostic facility, the Director of Corrections may file with the court which placed defendant in the facility a petition for extension of the period of confinement, to which shall be attached a writing signed by defendant giving his consent to the extension. If the court finds the petition and consent in order, it may order the extension, and transmit a copy of the order to the Director of Corrections.