PK.LABSET,
@OPEN.LAB,
@HDR,
@TESTS,
@TRLR,
END;

OPEN.LAB
IF{/CONF[.labs.source]="lab" "regular labs",
  @labdir,
  O(\,@labdict);
"if not regular labs, assume mock labs",
  @mocklabdir,
  "need mocklabindx because mocklabdict defn refers to &",
  O(&,@mocklabindx),
  O(\,@mocklabdict)},
@pkdir

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

TRLR
"</Payload>"^!,
"</ReplyMessage>"^!

TESTS
IF{"T"=A "doing component defs",
      "<ComponentDefinition>"^A1,
      "</ComponentDefinition>"^A2,
      "<ComponentDefinitionMnemonic>"^A3,
      "</ComponentDefinitionMnemonic>"^A4;
   "doing panel defs",
      "<PanelDefinition>"^A1,
      "</PanelDefinition>"^A2,
      "<PanelDefinitionMnemonic>"^A3,
      "</PanelDefinitionMnemonic>"^A4},
""^slt,
DO{@NEXT.TEST "got a test",
   @GET.TEST.TYPE,
   IF{@IS.OUTPUTABLE @SEND}}

NEXT.TEST
IF{/CONF[.labs.source]="lab" "regular labs",
      +\SLT[slt];
   "mock labs",
      +\LAB.TE[slt]}^slt

GET.TEST.TYPE
IF{/CONF[.labs.source]="lab" "regular labs",
      \SLT[slt]|3;
   "mock labs",
      \LAB.TE[slt]A|3}^typ

IS.OUTPUTABLE
@IS.PROFILE.OR.GROUP^cntr,
@IS.REPORTABLE^rptbl,
@IS.ORDERABLE^ordrbl,
IF{("T"=A)&(cntr) "generating comps, ignore containers",
      "N";
   ("T"=A)&('rptbl) "generating comps, ignore not reportable ttests",
      "N";
   ("T"'=A)&('ordrbl) "generating panels, should ignore non-orderable",
      "but for now will pass them thru in case data refers to them",
      "Y";
   "otherwise we have something to output",
      "Y"}^tmp,
("Y"=tmp)

IS.PROFILE.OR.GROUP
("P"=typ)!("G"=typ)

IS.TTEST.OR.C
"type of C might be charge, but we havent filtered out in the past, so include here",
("T"=typ)!("C"=typ)

IS.REPORTABLE
IF{/CONF[.labs.source]="lab" "regular labs",
      \SLT[slt]|8;
   "mock labs",
      \LAB.TE[slt]A|8}^tmp,
("Y"=tmp)

IS.ORDERABLE
IF{/CONF[.labs.source]="lab" "regular labs",
      \SLT[slt]|9;
   "mock labs",
      "mock labs doesnt have an orderable flag, assume true",
      "Y"}^tmp,
("Y"=tmp)

SEND
K(/T.COMPONENTS),
IF{/CONF[.labs.source]="lab" "regular labs",
      \SLD[\SLT[slt]|4]|1^CATEGORY,
      \SLT[slt]|6^SHORTNAME,
      \SLT[slt]|1^LONGNAME;
   "if not regular labs, assume mock labs",
      \LAB.TE[slt]A|0^CATEGORY,
      \LAB.TE[slt]|1^SHORTNAME,
      \LAB.TE[slt]|4^LONGNAME},
slt'#(L(slt,.))^SEQ,
A1^!,
A3_slt_A4^!,
"<Category>"_CATEGORY_"</Category>"^!,
IF{("T"=A)!(@IS.PROFILE.OR.GROUP) 1,
   "any compdef OR (paneldef for container), put longname into name",
      "<Name><![CDATA["_LONGNAME_"]]></Name>"^!,
      "<Display><![CDATA["_SHORTNAME_"]]></Display>"^!;
   "paneldef for component, put shortname into name",
      "<Name><![CDATA["_SHORTNAME_"]]></Name>"^!,
      "<Display><![CDATA["_LONGNAME_"]]></Display>"^!},
"<CollatingSequence>"_SEQ_"</CollatingSequence>"^!,
"<Key>"_"x"_slt_\SLT[slt]UPD_"</Key>"^!,
"<EventCodes>"^!,
IF{@IS.TTEST.OR.C "individual ttest, just put on list",
      slt^/T.COMPONENTS[slt][slt];
   "group/profile, populate components",
      ""^slt2,
      "GET.COMPONENTS",%PK.LABSETLIST(slt,slt)},
DO{@NEXT.TTEST "got one",
   "<EventCode>"^!,
      IF{/CONF[.labs.source]="lab" "regular labs",
      \SLT[slt2]|6^SHORTNAME,
      \SLT[slt2]|1^LONGNAME;
   "if not regular labs, assume mock labs",
      \LAB.TE[slt2]|4^SHORTNAME,
      \LAB.TE[slt2]|1^LONGNAME},
   "<DefinitionCode>"_slt2_"</DefinitionCode>"^!,
   "<Name><![CDATA["_SHORTNAME_"]]></Name>"^!,
   "<Display><![CDATA["_LONGNAME_"]]></Display>"^!,
   "<Key>"_"x"_\SLT[slt2]UPD_"</Key>"^!,
   "</EventCode>"^!},
"</EventCodes>"^!,
A2^!,
K(/T.COMPONENTS)

NEXT.TTEST
+/T.COMPONENTS[slt][slt2]^slt2
