PK.DEPTKEY,
A^prefix,
B^depts,
@OPEN.OE,
@PATS,
END;

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

PATS
/ARGV[1]^DT,
2^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   :AAAI[ACT]^aa,
   @RPT,
   nr+1^nr}

RPT
DO{+*PTP[ggn]^ggn 1,
   IF{('/CONF[depts]["all"])&('/CONF[depts][ggn]);
      :AA[aa]|3^mrn,
      ""^pt,DO{+*PTP[ggn,aa,pt]^pt @SEND},
      "Stuff might also be stored under 'U ea'.",
      "U "_?EAU[mrn]^faa,
      ""^pt,DO{+*PTP[ggn,faa,pt]^pt @SEND}}}

SEND
IF{"check report dates against date from pk",
   *PT[pt]|8^DATE,
   DATE<DT;
   "filter out draft status if necessary",
   *PT[pt]|3'="Draft" @SEND2;
   /CONF[.oe.allow.drafts]["all"] @SEND2;
   /CONF[.oe.allow.drafts][*PT[pt]|0] @SEND2}

SEND2
   "<Document>"^!,
   "<InstanceMnemonic>"_prefix_pt_"_PK"_aa_"</InstanceMnemonic>"^!,
   "ask kevin about this",SEC^UPD,
   "<Key>"_"x"_*PT[pt]UPD|3_*PT[pt]UPD|4_"</Key>"^!,
   "<PersonMnemonic>"_mrn_"</PersonMnemonic>"^!,
   "<EventEndDateTime>"_*PT[pt]|8_"</EventEndDateTime>"^!,
   "<EventSetMnemonic>"_"OE."_*PT[pt]|0_"</EventSetMnemonic>"^!,
   "</Document>"^!
