PK.DEPTDATA,
A^prefix,
B^ptaa,
@OPEN.OE,
@REPORT,
END;

OPEN.OE
@misdir,
O(&,@misdict),
@admdir,
O(:,@admdata),
@oedir,
O(*,@oedata),
O(\,@oedict),
@pkdir

REPORT
K(/T.REC),
0^T,
IF{"" "**NO SIGNED RESULTS TO REPORT**"^/T.REC[T+1^T];
   @REPORT.HEADER,
   @REPORT.LINES,
   @REPORT.FOOTER,
   @REPORT.DONE}

REPORT.HEADER
"aa/mrn not always uniquely derivable from note, so aa passed from key call",
L(ptaa,"_PK")^pos,
IF{L(ptaa)'=pos 1,
   ptaa$pos^pt,
   ptaa%(pos+2)^aa;
   ptaa^pt,
   *PT[pt]|2^aa},
:AA[aa]|3^/T.INFO["MRN"],
:AA[aa]|0^/T.INFO["ACCT"],
*PT[pt]C|0^/T.INFO["TESTNAME"],
*PT[pt]UPD|3_*PT[pt]UPD|4^/T.INFO["UPDATENODE"],
*PT[pt]|25_*PT[pt]|26^/T.INFO["TESTDATE"],
"OE."_*PT[pt]|0^/T.INFO["TESTTYPE"],
*PT[pt]|3^/T.INFO["STATUS"],
IF{*PT[pt]|20^ggg &GGG[ggg]|1^/T.INFO["AUTHOR"]},
"STATUS: "_*PT[pt]|3^/T.REC[T+1^T],
" "^/T.REC[T+1^T]

OLD.REPORT.LINES
""^prs,
DO{+*PT[pt]S[prs]^prs IF{"Text"'=*PT[pt]S[prs]|1;
                         "0"^poL,
                         DO{+*PT[pt]S[prs,poL]^poL *PT[pt]S[prs,poL]^/T.REC[T+1^T]}}}

REPORT.LINES
0^CH,
""^/TRANS,
DO{/TRANS_IF{CH>32<126 D(CH);" "}^/TRANS,CH+1^CH<255},
M(*PT[pt],/PT[pt]),*PT[pt]^/PT[pt],
92^WID,
IF{/PT[pt]C|7;92-/PT[pt]C|1}^ptw,
""^ptLN,
0^LN,
K(/TXT),
DO{+/PT[pt]C[ptLN]^ptLN,
   ptLN IF{IF{L(/PT[pt]C[ptLN],"//")^CLM<L(/PT[pt]C[ptLN]) 1,
              /PT[pt]C[ptLN]%(CLM+1)$4^FLD,
              (L(FLD'="name"'="ivnm"'="add1"'="add2"'="add3")=0)&FLD} 1,
           /PT[pt]C[ptLN]$CLM_(" ":8)_(/PT[pt]C[ptLN]'$(CLM+8))^/TXT[LN+1^LN],
           /PT[pt]C[ptLN]A^/TXT[LN]A;
           IF{(/PT[pt]C[ptLN]):0S 0^cnt;1+cnt^cnt},
           IF{cnt>3 "nuking blank lines after 3 in a row";
              /PT[pt]C[ptLN]^/TXT[LN+1^LN],
              /PT[pt]C[ptLN]A^/TXT[LN]A}}},
""^LN,DO{+/TXT[LN]^LN /TXT[LN]~/TRANS^/T.REC[T+1^T]}

REPORT.FOOTER
" "^/T.REC[T+1^T],
" "^/T.REC[T+1^T],
"REPORT: "_*PT[pt]|5_" - "_*PT[pt]C|0^/T.REC[T+1^T],
IF{*PT[pt]|20^ggg "Dictated by: "_(&GGG[ggg]|1)_" "_%Z.date.out(*PT[pt]T|7,"",10)_"-"_(*PT[pt]T|8)^/T.REC[T+1^T]},
IF{*PT[pt]|21^gu "Transcribed by: "_(&GU[gu]|1)_" "_%Z.date.out(*PT[pt]T|5,"",10)_"-"_(*PT[pt]T|6)^/T.REC[T+1^T]},
IF{*PT[pt]SGN|2^ggg "Signed by: "_(&GGG[ggg]|1)_" "_%Z.date.out(*PT[pt]|17,"",10)_"-"_(*PT[pt]|18)^/T.REC[T+1^T]}

REPORT.DONE
K(/TXT),
K(/PT[pt]),""^/pt
