All information and records obtained in the course of an investigation, an evaluation, an examination, or treatment under this chapter and the presence or past presence of a patient in a treatment facility are confidential, but the information and records may be disclosed to and be used by a court as required to carry out the purposes of this chapter, and as authorized under title 45, Code of Federal Regulations, part 164. Courts also may release nonclinical identifying information of persons subject to proceedings under this chapter for the purposes of section 62.1-02-01.2. Any information disclosed to a court remains confidential information, except as provided in section 62.1-02-01.2.