Section 36A. All reports of examinations made to a court pursuant to sections one to eighteen, inclusive, section forty-seven and forty-eight shall be private except in the discretion of the court. All petitions for commitment, notices, orders of commitment and other commitment papers used in proceedings under sections one to eighteen and section thirty-five shall be private except in the discretion of the court. Each court shall keep a private docket of the cases of persons coming before it believed to be mentally ill, including proceedings under section thirty-five; provided that nothing in this section shall prevent public inspection of any complaints or indictments in a criminal case, or prevent any notation in the ordinary docket of criminal cases concerning commitment proceedings under sections one to eighteen against a defendant in a criminal case. Notwithstanding the provisions of this paragraph, any person who is the subject of an examination or a commitment proceeding, or his counsel, may inspect all reports and papers filed with the court in a pending proceeding, and the prosecutor in a criminal case may inspect all reports and papers concerning commitment proceedings that are filed with the court in a pending case.
Notwithstanding this section, a court may, pursuant to section 35 and section 36C, transmit information contained in court records to the department of criminal justice information services to provide: (i) licensing authorities as defined under section 121 of chapter 140 with information required or permitted to be considered under state or federal law to conduct background checks for firearm sales or licensing; and (ii) the attorney general of the United States with information required or permitted under federal law to be included in the National Instant Criminal Background Check System maintained to conduct background checks for firearms sales or licensing; provided, however, that the court shall not transmit information solely because a person seeks voluntary treatment or is involuntarily hospitalized for assessment or evaluation. Information transmitted to the department of criminal justice information services pursuant to this section and sections 35 and 36C shall not be considered public records pursuant to section 10 of chapter 66 and clause Twenty-sixth of section 7 of chapter 4.