PK.IOKEY,
"HDR",@1,
"IOSET",@4,
"PATS",@3,
"TRLR",@2,
END;

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

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

[3]::PATS
/ARGV[1]^DT,
2^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   "IOS",@6,
   nr+1^nr};

[4]::IOSET
"get list of queries to use",
^&(NP)NPARAM^PARMS,
""^ggv,
DO{+[PARMS,"INTAKE",ggv]^ggv "IO.DEF",@5},
""^ggv,
DO{+/CONF[.ios.additional.intake.queries][ggv]^ggv "IO.DEF",@5},
""^ggv,
DO{+[PARMS,"OUTPUT",ggv]^ggv "IO.DEF",@5},
""^ggv,
DO{+/CONF[.ios.additional.output.queries][ggv]^ggv "IO.DEF",@5};

[5]::IO.DEF
IF{ggv 0^/V.QRY[ggv]};

[6]::IOS
?(A)AAAI[ACT]^aa,
$(A)AA[aa]|3^MRN,
^$(N1)NPCW[aa,"I"]^NUR.DATA,
""^URN^SEQ^TD^TM^EDITNUM,
DO{<([NUR.DATA,URN,"O",SEQ,"TD",TD,TM,XXX],YYY)^XXX "got one",
      XXX#"0S"^CTR,
      IF{EDITNUM_.=. CTR^EDITNUM},
      L(EDITNUM,.)'=L(EDITNUM)^HASDOT,
      IF{(HASDOT)&(CTR'=EDITNUM) 1,
            "had edit, doesnt match most recent edit, dont show";
         ('HASDOT)&([NUR.DATA,URN,"O",SEQ,"TD",TD,TM,CTR]_.=.) 1,
            "no edits, but no root record, means deleted, dont show";
         XXX#"1S"="Q" "regular result",
            XXX#"2S"^ggv,
            IF{/V.QRY[ggv]_.=.;
               YYY|0_.=. "no value, dont display";
               "Q"^keyprefix,
               "SEND.DATA",@7};
         XXX#"1S"="R" "repeat result",
            XXX#"4S"^ggv,
            IF{/V.QRY[ggv]_.=.;
               YYY|0_.=. "no value, dont display";
               "R"_(XXX#"2S")^keyprefix,
               "SEND.DATA",@7}};
   ""^EDITNUM,-[NUR.DATA,URN,"O",SEQ,"TD",TD,TM]^TM;
   -[NUR.DATA,URN,"O",SEQ,"TD",TD]^TD'<DT;
   ""^TD,-[NUR.DATA,URN,"O",SEQ]^SEQ;
   -[NUR.DATA,URN]^URN};

[7]::SEND.DATA
"<IO>"^!,
"<IOMnemonic>"_aa_URN_SEQ_TD_TM_(XXX#"0S")_(keyprefix)_(ggv)_"</IOMnemonic>"^!,
"<Key>"_(TD)_(TM)_"</Key>"^!,
"<PersonMnemonic>"_MRN_"</PersonMnemonic>"^!,
"<EncounterMnemonic>"_ACT_"</EncounterMnemonic>"^!,
"<ResultUnits>units</ResultUnits>"^!,
"<Value>"_(YYY|0)_"</Value>"^!,
"<DateTime>"_(TD)_(TM)_"</DateTime>"^!,
"<EventCodeMnemonic>"_(ggv)_"</EventCodeMnemonic>"^!,
"</IO>"^!;
