Section 5. Whenever the provisions of this chapter require that a hearing be conducted in any court for the commitment or further retention of a person to a facility or to the Bridgewater state hospital or for medical treatment including treatment with antipsychotic medication, it shall be held as hereinafter provided. Such person shall have the right to be represented by counsel and shall have the right to present independent testimony. The court shall appoint counsel for such person whom it finds to be indigent and who is not represented by counsel, unless such person refuses the appointment of counsel. The court may provide an independent medical examination for such indigent person upon request of his counsel or upon his request if he is not represented by counsel. The person shall be allowed not less than two days after the appearance of his counsel in which to prepare his case and a hearing shall be conducted forthwith after such period unless counsel requests a delay. Notice of the time and place of hearing shall be furnished by the court to the department, the person, his counsel, and his nearest relative or guardian. The court may hold the hearing at the facility or said hospital.