Section 18. If the department applies to the court for review of an order as provided in section seventeen, the court shall notify the person whose liberty is involved, and if he or she be not sui juris, his parent or guardian (if such person can be reached and if not the court shall appoint a person to act in the place of the parent or guardian), of the application, and shall afford him an opportunity to appear in court with the aid of counsel and of process to compel attendance of witnesses and production of evidence. When he is unable to provide his own counsel, the court shall appoint counsel to represent him. Said proceedings shall be conducted according to the provisions of sections fifty-five A, fifty-five B and fifty-six of chapter one hundred and nineteen.
If after a full hearing the court is of the opinion that discharge of the person to whom the court order applies would be physically dangerous to the public, the court shall confirm the order of the department. If the court is of opinion that discharge of the person from continued control of the department would not be physically dangerous to the public, the court shall disapprove the order of the department and shall order the person to be discharged from its control.