The copy of the records shall remain sealed and shall be opened only at the time of trial, deposition or other hearing, upon the direction of the judge, court, officer, attorney, body or tribunal conducting the proceeding, in the presence of all parties who have appeared in person or by counsel at the trial, deposition or hearing. Before directing that the inner envelope or wrapper be opened, the judge, court, officer, attorney, body or tribunal shall first ascertain that either:
(1) the records have been subpoenaed in accordance with this subchapter; or
(2) the patient involved or someone authorized in his behalf to do so for him has consented thereto.