1. Notwithstanding section 812.8, the defendant shall not remain under placement pursuant to section 812.6 beyond the expiration of the maximum term of confinement for the criminal offense of which the defendant is accused, or eighteen months from the date of the original adjudication of incompetence to stand trial, including time in jail, or the time when the court finds by a preponderance of the evidence that there is no substantial probability that the defendant will be restored to competency in a reasonable amount of time under section 812.8, subsection 8, whichever occurs first. When the defendant’s placement in an inpatient facility equals the length of the maximum term of confinement, the complaint for the criminal offense of which the defendant is accused shall be dismissed with prejudice.
 2. When the defendant’s commitment equals eighteen months, the court shall schedule a hearing to determine whether the defendant is competent to stand trial pursuant to section 812.8, subsection 5. If the defendant is not competent to stand trial after eighteen months, the court shall terminate the placement under section 812.6 in accordance with the provisions of subsection 1.
 3. Upon the termination of the defendant’s placement pursuant to subsection 1, or pursuant to section 812.8, subsection 8, the state may commence civil commitment proceedings or any other appropriate commitment proceedings.
 4. If the defendant’s placement is terminated pursuant to subsection 2 or pursuant to section 812.8, subsection 8, and it appears thereafter that the defendant has regained competency, the state may make application to reinstate the prosecution of the defendant and hearing shall be held on the matter in the same manner as if the court has received notice under section 812.8, subsection 4.