1. Before the expiration of the twenty-one-day inpatient detention and treatment period ordered pursuant to section 632.335, the court may order the respondent to be detained and treated involuntarily for an additional period not to exceed ninety inpatient days or may order the respondent to be detained for outpatient detention and treatment for a period not to exceed one hundred eighty days; provided, that:

(1) The respondent is mentally ill and continues to present a likelihood of serious harm to himself or others; and

(2) The court, after a hearing, orders the respondent detained and treated for the additional period.

2. If, within seventeen days of the court hearing described in section 632.335, the head of the mental health program or the mental health coordinator has reasonable cause to believe that the respondent is mentally ill and as a result presents a likelihood of serious harm to himself or others, and believes that further detention and treatment is necessary, he shall file, or cause to be filed, with the court a petition for ninety days additional detention and treatment or a petition for outpatient detention and treatment for a period not to exceed one hundred eighty days. The court shall immediately set a date and time for a hearing on the petition, which shall take place within four judicial days of the date of the filing of the petition. The court shall serve a copy of the petition and the notice of the date and time of the hearing upon the petitioner, the respondent, and their attorneys as promptly as possible, but not later than two judicial days after the filing of the petition. The petitioner shall also file with the court, for the court to serve upon the respondent’s attorney not later than two judicial days after the filing of the petition, a list of the proposed witnesses for the petitioner. The head of the mental health program shall notify the mental health coordinator if the petition is not filed by the mental health coordinator. The petition shall comply with the requirements of section 632.330, and an individualized treatment plan for the respondent shall be attached thereto.