RSLTDATA.TXT,
"HDR",@1,
"HANDLE.ARGS",@2,
"TRLR",@5,
END;

[1]::HDR
"<?xml version="_D(34)_1.0_D(34)_" ?>"^!,
           "<ReplyMessage>"^!,
           "<TransactionId>"_1234_"</TransactionId>"^!,
           "<Status>Success</Status>"^!,
           "<Payload>"^!;

[2]::HANDLE.ARGS
%open("LAB"),
%open("RAD"),
1^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^arg,
   "HANDLE.ARG",@3,
   nr+1^nr};

[3]::HANDLE.ARG
K(/T.INFO),
K(/T.HEADER),
K(/T.REC),
arg$1^prefix,
arg'$1^mnemonic,
IF{prefix="B" %labbdata.txt(prefix,mnemonic);
   prefix="M" %labmdata.txt(prefix,mnemonic);
   prefix="R" %raddata.txt(prefix,mnemonic);
   prefix="P" %labpdata.txt(prefix,mnemonic)},
"SEND.TEST",@4,
K(/T.INFO),
K(/T.HEADER),
K(/T.REC);

[4]::SEND.TEST
"<Document>"^!,
"<Display><![CDATA["_(/T.INFO["TESTNAME"])_"]]></Display>"^!,
"<EventMnemonic></EventMnemonic>"^!,
"<EventCode><Mnemonic></Mnemonic></EventCode>"^!,
"<PersonMnemonic>"_(/T.INFO["MRN"])_"</PersonMnemonic>"^!,
"<EncounterMnemonic>"_(/T.INFO["ACCT"])_"</EncounterMnemonic>"^!,
"<EventEndDateTime>"_(/T.INFO["TESTDATE"])_"</EventEndDateTime>"^!,
"<InstanceMnemonic>"_prefix_mnemonic_"</InstanceMnemonic>"^!,
"append x to key to ensure that its not empty",
"<Key>"_"x"_(/T.INFO["UPDATENODE"])_"</Key>"^!,
"<EventSetMnemonic>"_(/T.INFO["TESTTYPE"])_"</EventSetMnemonic>"^!,
"<ResultStatus>"^!,
"<Display>"^!,
IF{/T.INFO["STATUS"]="ORD" "Ordered";
   /T.INFO["STATUS"]="COLB" "Collection Batch";
   /T.INFO["STATUS"]="RECD" "Received";
   /T.INFO["STATUS"]="UNV" "Unverified Results";
   /T.INFO["STATUS"]="RES" "Resulted";
   /T.INFO["STATUS"]="COMP" "Completed";
   /T.INFO["STATUS"]="CAN" "Cancelled";
   /T.INFO["STATUS"]="WKST" "Pending";
   /T.INFO["STATUS"]="SOUT" "Signed";
   /T.INFO["STATUS"]="ENT" "Entered";
   /T.INFO["STATUS"]}^stat^!,
"</Display>"^!,
"<Meaning>"_(stat)_"</Meaning>"^!,
"<Value></Value>"^!,
"</ResultStatus>"^!,
"<DocumentComponents>"^!,
IF{+/T.REC[""] "got a report",
      ""^T,
      "<Section>"^!,
      "<Title><![CDATA["_/T.INFO["RPTSECTION"]_"]]></Title>"^!,
      "<SectionId>1</SectionId>"^!,
      "<Body>"^!,
      "<![CDATA["^!,
      DO{+(/T.REC[T],XX)^T XX_D(10)^!},
      "]]>"^!,
      "</Body>"^!,
      "</Section>"^!},
IF{+/T.HEADER[""] "got a header",
      ""^T,
      "<Section>"^!,
      "<Title><![CDATA["_/T.INFO["HEADERSECTION"]_"]]></Title>"^!,
      "<SectionId>2</SectionId>"^!,
      "<Body>"^!,
      "<![CDATA["^!,
      DO{+(/T.HEADER[T],XX)^T XX_D(10)^!},
      "]]>"^!,
      "</Body>"^!,
      "</Section>"^!},
"</DocumentComponents>"^!,
"</Document>"^!;

[5]::TRLR
"</Payload>"^!,
"</ReplyMessage>"^!;
