PK.PAT.LAB.P,
A^prefix,
B^specimen,
"FORMAT.SPEC",@1,
END;

[1]::FORMAT.SPEC
D(64)^atsign,
0^T^THDR,
^$(SP)SPS[specimen]^MAIN,
$(SP)SPS[specimen]^MAIN.VAR,
"SPECIMEN.DATA",@2,
IF{MAIN.VAR|2="CAN" "**SPECIMEN CANCELLED***"^/T.REC[T+1^T],
      ""^CC,
      DO{+([MAIN,"CC",CC],XX)^CC IF{XX:0S#0=atsign;XX^/T.REC[T+1^T]}};
   +[MAIN,"FS",""]^FS_.=. "NO FINAL SIGN OUTS YET"^/T.REC[T+1^T];
   "got a good one",
      "ORDERED.PROCS",@3,
      "COMMENTS",@4,
      "MARKERS",@5,
      " "^/T.REC[T+1^T],
      "FINAL.SIGNOUTS",@6,
      "FINDINGS",@7};

[2]::SPECIMEN.DATA
[MAIN]|1^aa,
$(A)AA[aa]|3^/T.INFO["MRN"],
$(A)AA[aa]|0^/T.INFO["ACCT"],
%(Z)date.in.magic([MAIN]|13)_%(Z)time.out([MAIN]|13)^/T.INFO["TESTDATE"],
$(SP)SPS[specimen]A|10^/T.INFO["UPDATENODE"],
"AP"^/T.INFO["TESTTYPE"],
"Specimen"^/T.INFO["HEADERSECTION"],
"Report"^/T.INFO["RPTSECTION"],
MAIN.VAR|2^/T.INFO["STATUS"],
"Specimen: "_MAIN.VAR|0_" ("_MAIN.VAR|2_")"^/T.HEADER[THDR+1^THDR],
"Status: "_MAIN.VAR|2^/T.HEADER[THDR+1^THDR],
"Requisition: "_$(S)SCR[[MAIN]|8]|0^/T.HEADER[THDR+1^THDR],
"Specimen Type: "_&(SP)SPO[[MAIN]|5]|1^/T.HEADER[THDR+1^THDR],
"Recv Date: "_IF{MAIN.VAR|3_.=. "Not Received";%(Z)date.out(MAIN.VAR|3)_"-"_(MAIN.VAR|4)_"  "_(MAIN.VAR|12)}^/T.HEADER[THDR+1^THDR],
"Submitted By: "_MAIN.VAR|11^/T.HEADER[THDR+1^THDR];

[3]::ORDERED.PROCS
"Ordered Procedures:"^/T.REC[T+1^T],
""^spt^/T.INFO["TESTNAME"],
DO{+([MAIN,"OP",spt],XX)^spt 1,
   IF{L(/T.INFO["TESTNAME"])=0 &(SP)SPT[spt]|1^/T.INFO["TESTNAME"]},
   " "_&(SP)SPT[spt]|1^/T.REC[T+1^T]};

[4]::COMMENTS
0^GOT,
DO{(GOT=0)&(+([MAIN,"C",CC],XX)^CC) IF{XX:0S#0=atsign;1^GOT}},
IF{GOT=1 "Comments:"^/T.REC[T+1^T],
   ""^CC,
   DO{+([MAIN,"C",CC],XX)^CC IF{XX:0S#0=atsign;" "_XX^/T.REC[T+1^T]}}};

[5]::MARKERS
IF{+[MAIN,"MK",""]_.=.;
   "Markers:"^/T.REC[T+1^T],
   ""^MK,
   DO{+([MAIN,"MK",MK],XX)^MK " "_XX^/T.REC[T+1^T]}};

[6]::FINAL.SIGNOUTS
IF{+[MAIN,"FS",""]_.=. "No Final Signatures"^/T.REC[T+1^T];
   "Final Signatures:"^/T.REC[T+1^T],
   ""^FS,
   DO{+([MAIN,"FS",FS],XX)^FS 1,
      " "_IF{XX|0;XX|3}_"   "_%(Z)date.out(XX|1)^/T.REC[T+1^T]}};

[7]::FINDINGS
K(/T.FINDINGS),
"SORT.FINDINGS",@15,
""^n,
DO{+(/T.FINDINGS[n],SPR)^n "got the next one",
   "Findings: "_&(SP)SPR[SPR]|1^/T.REC[T+1^T],
   "HISTOLOGY",@14,
   "FIND.QUES",@8,
   "FIND.TEXT",@9,
   "FIND.CODES",@10,
   "FIND.CONCEPTS",@11,
   "ADDENDA",@12,
   " "^/T.REC[T+1^T]},
K(/T.FINDINGS);

[8]::FIND.QUES
EMPTY;

[9]::FIND.TEXT
""^FT,
DO{+([MAIN,"F",SPR,"T",FT],YY)^FT YY^/T.REC[T+1^T]};

[10]::FIND.CODES
""^CT,
DO{+([MAIN,"F",SPR,"C",CT],YY)^CT &(SP)SPT[CT]|1$45^/T.REC[T+1^T]};

[11]::FIND.CONCEPTS
""^SP,
DO{+([MAIN,"F",SPR,"CT",SP],YY)^SP &(S)SSP[SP]NM$55^/T.REC[T+1^T]};

[12]::ADDENDA
IF{+[MAIN,"F",SPR,"A",""]_.=.;
   ""^AQ,
   DO{+([MAIN,"F",SPR,"A",AQ],YY)^AQ 1,
      IF{+[MAIN,"F",SPR,"A",AQ,"FS",""]_.=. "Not Final Signed";
         "Addenda:"^/T.REC[T+1^T],
         "Final Signatures:"^/T.REC[T+1^T],
         DO{+([MAIN,"F",SPR,"A",AQ,"FS",FS],ZZ)^FS 1,
            IF{ZZ|0;ZZ|3}_"  "_%(Z)date.out(ZZ|1)^/T.REC[T+1^T]},
         " "^/T.REC[T+1^T],""^AT,
         DO{+([MAIN,"F",SPR,"A",AQ,"T",AT],ZZ)^AT ZZ:0X^/T.REC[T+1^T]}}}};

[13]::RTF
"RTF PROCEDURE IS NOT CURRENTLY BEING USED",
""^RF,
DO{+([MAIN,"RTF","XXEMR","T",RF],YY)^RF YY^/T.REC[T+1^T]};

[14]::HISTOLOGY
""^H,
DO{+([MAIN,"F",SPR,"H",H],XX)^H IF{XX|3_.=.;XX|0^/T.REC[T+1^T]}};

[15]::SORT.FINDINGS
""^SPR,
DO{+([MAIN,"F",SPR],XX)^SPR "got one",
   IF{XX|7="Y" "Internal";
      XX|0=0 "Nothing Entered";
      SPR^/T.FINDINGS[XX|0]}};
