PK.PATDOC
@PATDOC.OPEN.PREFIXES,
@PATDOC.PARSEOPTIONAL,
@PATDOC.HDR,
@PATDOC.ACCT,
@PATDOC.OPT.PATS,
@PATDOC.TRLR,
END;

PATDOC.OPEN.PREFIXES
@admdir,
O(*,@admdata),
@pkdir

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

PATDOC.PARSEOPTIONAL
1^nr,
""^provider,
IF{/CONF[.patdoc.providerarg] @PATDOC.DOPCISTUFF},
0^NUMLOCS,
IF{/CONF[.patient.locationfiltering] @PATDOC.LOADLOCATIONS}

PATDOC.LOADLOCATIONS
K(/LOCS),
"Copy locations into structure",
/ARGV[nr]^NUMLOCS,
nr+1^nr,
0^i,
DO{i<NUMLOCS 1,
   /ARGV[nr+i]^loc,
   1^/LOCS[loc%3],
   loc%3^/LOCLIST[i],
   i+1^i},
nr+i^nr

PATDOC.DOPCISTUFF
/ARGV[nr]^usr,
@pcidir,
O(:S,@pcidata),
O(?S,@pciindx),
O(\,$.data[:.CDFN]),
@misdir,
O(&S,@misdict),
@pkdir,
IF{&GUIX[usr]^usr2 usr2^usr},
&GU[usr]|13^provider,
nr+1^nr,
@PATDOC.GETPCILIST,
@PATDOC.GETGROUPPCILIST,
C(:U),
C(?U),
C(&U)

PATDOC.GETPCILIST
usr^mpiidx,
DO{>:UL[mpiidx]^mpiidx&(mpiidx#0S=usr) 1,
   mpiidx#2S^mpi,
   1^/PCI[?M[mpi]|0]},
provider^mpiidx,
DO{>:CONS.DR[mpiidx]^mpiidx&(mpiidx#0S=provider) 1,
   mpiidx#1S^mpi,
   ?M[mpi]|0^acc,
   IF{/PCI[acc] "only add consult if on short list already",
      1^/PCICONS[acc]}}

PATDOC.GETGROUPPCILIST
\.DR[provider]GC^grp,"Doc's default group",
""^doc,
DO{>\.DRPG[grp,doc]^doc "iterate through the docs in our group",
   IF{:DUS[doc]^us "look up the doc's user in PCI",
      IF{us'=usr "don't do this for ourselves",
         us^mpiidx,
         DO{>:UL[mpiidx]^mpiidx&(mpiidx#0S=us) 1,
            mpiidx#2S^mpi,
            ?M[mpi]|0^acc,
            IF{'/PCI[acc] "add to group list if not on personal short list",
               1^/PCIGROUP[acc]}}}}},
grp^mpiidx,
DO{>:CONS.DG[mpiidx]^mpiidx&(mpiidx#0S=grp) 1,
   mpiidx#1S^mpi,
   ?M[mpi]|0^acc,
   IF{/PCI[acc]!/PCIGROUP[acc] "only add group consult if on short lists already",
      1^/PCIGROUPCONS[acc]}}

PATDOC.ACCT
""^Q,
DO{>(*AARB[Q],aa)^Q *AA[aa]^/aa,
   /aa|0^Q1,
   /aa|3^Q3,
   "Make sure this account has MRN, is properly indexed, and in location list",
   IF{(*AAAI[Q1]=aa)&(NUMLOCS=0!/LOCS[/aa|12])&(Q3_.'=.) 1,
      *AA[aa]B|0^Q2,
      <*AA[aa]EV[""]^/tmp,
      Q2_(/tmp#0S)_(/tmp#1S)^Q2,
      /aa^ZQ,
      *AA[aa]DR^DQ,
      /aa|2^STATTYPE,
      STATTYPE%(L(STATTYPE," "))^TYPE,
      IF{/CONF[.patient.outpat.exp]&(TYPE'="IN") Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
      "Add consulting docs to key.",
      ""^ggg,
      DO{+*AA[aa]CDR[ggg]^ggg Q2_ggg^Q2},
      "Also add PCI list and PCI consults",
      IF{/PCI[Q3] Q2_provider^Q2},
      IF{/PCICONS[Q3] Q2_provider^Q2},
      IF{/PCIGROUP[Q3] Q2_provider^Q2},
      IF{/PCIGROUPCONS[Q3] Q2_provider^Q2},
      "<HUPL>"^!,
      "<Person>"^!,
      "<VisitNumber>"_Q1_"</VisitNumber>"^!,
      "<PatientNumber>"_Q3_"</PatientNumber>"^!,
      "<Key>"_Q2_"</Key>"^!,
      "</Person>"^!,
      "</HUPL>"^!,
      "<HEL>"^!,
      "<Encounter>"^!,
      "<VisitNumber>"_Q1_"</VisitNumber>"^!,
      "<PatientNumber>"_Q3_"</PatientNumber>"^!,
      "<Key>"_Q2_"</Key>"^!,
      "<NurseUnitMnemonic>LOC."_ZQ|12_"</NurseUnitMnemonic>"^!,
      "<DynamicProperty>"^!,
      "<DyPropMeaning>SVC."_ZQ|9_"</DyPropMeaning>"^!,
      "</DynamicProperty>"^!,
      "<AcctPrsnlReltns>"^!,
      IF{DQ|0 "<AcctPrsnlReltn>"^!,
         "<PersonnelUserNumber><![CDATA["_DQ|0_"]]></PersonnelUserNumber>"^!,
         "<AbbrevName>ADMITDOC</AbbrevName>"^!,
         "</AcctPrsnlReltn>"^!},
      IF{DQ|1 "<AcctPrsnlReltn>"^!,
         "<PersonnelUserNumber><![CDATA["_DQ|1_"]]></PersonnelUserNumber>"^!,
         "<AbbrevName>ATTENDDOC</AbbrevName>"^!,
         "</AcctPrsnlReltn>"^!},
      IF{DQ|2 "<AcctPrsnlReltn>"^!,
         "<PersonnelUserNumber><![CDATA["_DQ|2_"]]></PersonnelUserNumber>"^!,
         "<AbbrevName>OTHERDOC</AbbrevName>"^!,
         "</AcctPrsnlReltn>"^!},
      IF{DQ|3 "<AcctPrsnlReltn>"^!,
         "<PersonnelUserNumber><![CDATA["_DQ|3_"]]></PersonnelUserNumber>"^!,
         "<AbbrevName>FAMILYDOC</AbbrevName>"^!,
         "</AcctPrsnlReltn>"^!},
      IF{DQ|4 "<AcctPrsnlReltn>"^!,
         "<PersonnelUserNumber><![CDATA["_DQ|4_"]]></PersonnelUserNumber>"^!,
         "<AbbrevName>ERDOC</AbbrevName>"^!,
         "</AcctPrsnlReltn>"^!},
      IF{DQ|5 "<AcctPrsnlReltn>"^!,
         "<PersonnelUserNumber><![CDATA["_DQ|5_"]]></PersonnelUserNumber>"^!,
         "<AbbrevName>PRIMCAREDOC</AbbrevName>"^!,
         "</AcctPrsnlReltn>"^!},
      @PATDOC.DO.OTH.DOCS,
      "</AcctPrsnlReltns>"^!,
      "</Encounter>"^!,
      "</HEL>"^!}}

PATDOC.OPT.PATS
DO{nr+1</ARGC 1,
   /ARGV[nr]^TYP,
   /ARGV[nr+1]^BEGIN.END.DT,
   nr+2^nr,
   @PATDOC.OPT.BYTYPE}

PATDOC.OPT.BYTYPE
BEGIN.END.DT$L(BEGIN.END.DT,"-")^BDT,
BEGIN.END.DT%L(BEGIN.END.DT,"-")^EDT,
IF{TYP="DIS" @PATDOC.DIS.PATS;
   TYP="MSM" IF{/CONF[.usemsm]&(NUMLOCS=0!/LOCS["OR"]) @PATDOC.MSM};
   TYP="SCHEDULING" IF{/CONF[.usesch] @PATDOC.SCHEDULING.PATS};
   @PATDOC.OUT.PATS,@PATDOC.SCH.PATS}

PATDOC.DIS.PATS
""^FAC,
"<HUPL>"^!,
DO{+*AADI[FAC]^FAC 1,
   BDT^DT,
   DO{>*AADI[FAC,DT]^DT&(DT#0S'>EDT) 1,
      DT#2S^aa,
      IF{(*AAAI[*AA[aa]|0]=aa)&(NUMLOCS=0!/LOCS[*AA[aa]|12]) 1,
         @PATDOC.HUPL.ENTRY}}},
"</HUPL>"^!,
""^FAC,
"<HEL>"^!,
DO{+*AADI[FAC]^FAC 1,
   BDT^DT,
   DO{>*AADI[FAC,DT]^DT&(DT#0S'>EDT) 1,
      DT#2S^aa,
      IF{(*AAAI[*AA[aa]|0]=aa)&(NUMLOCS=0!/LOCS[*AA[aa]|12]) 1,
         @PATDOC.HEL.ENTRY}}},
"</HEL>"^!

PATDOC.OUT.PATS
"<HUPL>"^!,
""^FAC,
DO{+*AAEI[FAC]^FAC 1,
   BDT^DT,
   DO{>*AAEI[FAC,TYP,DT]^DT&(DT#0S'>EDT) 1,
      DT#2S^aa,
      IF{(*AAAI[*AA[aa]|0]=aa)&(NUMLOCS=0!/LOCS[*AA[aa]|12]) 1,
         @PATDOC.HUPL.ENTRY}}},
"</HUPL>"^!,
"<HEL>"^!,
""^FAC,
DO{+*AAEI[FAC]^FAC 1,
   BDT^DT,
   DO{>*AAEI[FAC,TYP,DT]^DT&(DT#0S'>EDT) 1,
      DT#2S^aa,
      IF{(*AAAI[*AA[aa]|0]=aa)&(NUMLOCS=0!/LOCS[*AA[aa]|12]) 1,
         @PATDOC.HEL.ENTRY}}},
"</HEL>"^!

PATDOC.SCH.PATS
"<HUPL>"^!,
""^FAC,
DO{+*AASI[FAC]^FAC 1,
   BDT^DT,
   DO{>*AASI[FAC,TYP,DT]^DT&(DT#0S'>EDT) 1,
      DT#1S^aa,
      IF{(*AAAI[*AA[aa]|0]=aa)&(*AA[aa]|3&(NUMLOCS=0!/LOCS[*AA[aa]|12])) 1,
         @PATDOC.HUPL.ENTRY}}},
"</HUPL>"^!,
"<HEL>"^!,
""^FAC,
DO{+*AASI[FAC]^FAC 1,
   BDT^DT,
   DO{>*AASI[FAC,TYP,DT]^DT&(DT#0S'>EDT) 1,
      DT#1S^aa,
      IF{(*AAAI[*AA[aa]|0]=aa)&(*AA[aa]|3&(NUMLOCS=0!/LOCS[*AA[aa]|12])) 1,
         @PATDOC.HEL.ENTRY}}},
"</HEL>"^!

PATDOC.SCHEDULING.PATS
@schdir,
O(:,@schdata),
O(?,@schdict),
@pkdir,
"<HUPL>"^!,
0^i,
DO{i<NUMLOCS 1,
   /LOCLIST[i]^ggn,
   ggn^lcur,
   DO{>?WACD[lcur]^lcur&(lcur#0S=ggn) 1,
      lcur#1S^wac,
      wac^gcur,
      DO{>?WATG[gcur]^gcur&(gcur#0S=wac) 1,
         gcur#1S^wat,
         BDT^DT,
         DO{>:WZT[wat,DT]^DT&(DT#0S'>EDT) 1,
            DT#3S^wz,
            :WZ[wz]#7S^aa,
            IF{/CONF[.patient.outpat.exp] 1,
               (/CONF[.patient.outpat.exp])_(DT#0S)_(DT#1S)^AAPP},
            IF{(':WZ[wz]|8)&(*AA[aa]|3)&(*AAAI[*AA[aa]|0]=aa) 1,
               @PATDOC.HUPL.ENTRY}}}},
   i+1^i},
"</HUPL>"^!,
"<HEL>"^!,
0^i,
DO{i<NUMLOCS 1,
   /LOCLIST[i]^ggn,
   ggn^lcur,
   DO{>?WACD[lcur]^lcur&(lcur#0S=ggn) 1,
      lcur#1S^wac,
      wac^gcur,
      DO{>?WATG[gcur]^gcur&(gcur#0S=wac) 1,
         gcur#1S^wat,
         BDT^DT,
         DO{>:WZT[wat,DT]^DT&(DT#0S'>EDT) 1,
            DT#3S^wz,
            :WZ[wz]#7S^aa,
            IF{/CONF[.patient.outpat.exp] 1,
               (/CONF[.patient.outpat.exp])_(DT#0S)_(DT#1S)^AAPP},
            IF{(':WZ[wz]|8)&(*AA[aa]|3)&(*AAAI[*AA[aa]|0]=aa) 1,
               @PATDOC.HEL.ENTRY}}}},
   i+1^i},
"</HEL>"^!,
""^AAPP,
""^wz,
C(:),
C(?)

PATDOC.HUPL.ENTRY
(*AA[aa]|0)_AAPP^Q1,
*AA[aa]|3^Q3,
IF{Q3_.'=. 1,
   *AA[aa]B|0^Q2,
   <*AA[aa]EV[""]^/tmp,
   Q2_(/tmp#0S)_(/tmp#1S)^Q2,
   *AA[aa]^ZQ,
   *AA[aa]|2^STATTYPE,
   STATTYPE%(L(STATTYPE," "))^TYPE,
   ""^ggg,
   DO{+*AA[aa]CDR[ggg]^ggg Q2_ggg^Q2},
   IF{/PCI[Q3] Q2_provider^Q2},
   IF{/PCICONS[Q3] Q2_provider^Q2},
   IF{/PCIGROUP[Q3] Q2_provider^Q2},
   IF{/PCIGROUPCONS[Q3] Q2_provider^Q2},
   IF{/CONF[.patient.outpat.exp]&(AAPP!(TYPE'="IN")) 1,
      Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
   "<Person>"^!,
   "<VisitNumber>"_Q1_"</VisitNumber>"^!,
   "<PatientNumber>"_Q3_"</PatientNumber>"^!,
   "<Key>"_Q2_"</Key>"^!,
   "</Person>"^!}

PATDOC.HEL.ENTRY
(*AA[aa]|0)_AAPP^Q1,
*AA[aa]|3^Q3,
IF{Q3_.=.;
   *AA[aa]B|0^Q2,
   <*AA[aa]EV[""]^/tmp,
   Q2_(/tmp#0S)_(/tmp#1S)^Q2,
   *AA[aa]DR^DQ,
   *AA[aa]|2^STATTYPE,
   STATTYPE%(L(STATTYPE," "))^TYPE,
   ""^ggg,
   DO{+*AA[aa]CDR[ggg]^ggg Q2_ggg^Q2},
   IF{/PCI[Q3] Q2_provider^Q2},
   IF{/PCICONS[Q3] Q2_provider^Q2},
   IF{/PCIGROUP[Q3] Q2_provider^Q2},
   IF{/PCIGROUPCONS[Q3] Q2_provider^Q2},
   IF{/CONF[.patient.outpat.exp]&(AAPP!(TYPE'="IN")) 1,
      Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
   "<Encounter>"^!,
   "<VisitNumber>"_Q1_"</VisitNumber>"^!,
   "<PatientNumber>"_Q3_"</PatientNumber>"^!,
   "<DischargeDate>"_*AA[aa]|17_*AA[aa]|18_"</DischargeDate>"^!,
   "<NurseUnitMnemonic>LOC."_ZQ|12_"</NurseUnitMnemonic>"^!,
   IF{wz 1,
      "<AppointmentStatus>"_:WZ[wz]|5_"</AppointmentStatus>"^!},
   "<DynamicProperty>"^!,
   "<DyPropMeaning>SVC."_ZQ|9_"</DyPropMeaning>"^!,
   "</DynamicProperty>"^!,
   "<DynamicProperty>"^!,
   IF{TYPE="IN" "Inpatient"^PATTYP;"Outpatient"^PATTYP},
   "<DyPropName>"_PATTYP_"</DyPropName>"^!,
   "<DyPropMeaning>VisitType."_PATTYP_"</DyPropMeaning>"^!,
   "<DyPropValue><![CDATA[VisitType."_PATTYP_"]]></DyPropValue>"^!,
   "</DynamicProperty>"^!,
   "<AcctPrsnlReltns>"^!,
   IF{/CONF[.patient.scheduledrelsonly]&wz;
      @PATDOC.DO.BASIC.DOCS,
      @PATDOC.DO.OTH.DOCS},
   @PATDOC.DO.SCH.DOCS,
   "</AcctPrsnlReltns>"^!,
   "<Key>"_Q2_Q2A_"</Key>"^!,
   "</Encounter>"^!}

PATDOC.DO.BASIC.DOCS
IF{DQ|0 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_DQ|0_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>ADMITDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{DQ|1 "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_DQ|1_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>ATTENDDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{DQ|2 "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_DQ|2_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>OTHERDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{DQ|3 "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_DQ|3_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>FAMILYDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{DQ|4 "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_DQ|4_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>ERDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{DQ|5 "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_DQ|5_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>PRIMCAREDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!}

PATDOC.DO.OTH.DOCS
""^ggg,
DO{+*AA[aa]CDR[ggg]^ggg 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_ggg_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>CONSULTDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{/PCICONS[*AA[aa]|3] 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_provider_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>CONSULTDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{/PCIGROUPCONS[Q3] "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_provider_"]]></PersonnelUserNumber>"^!,
   "<AbbrevName>CONSULTDOC.GROUP</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{/PCI[*AA[aa]|3] 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_provider_"]]></PersonnelUserNumber>"^!,
   "<Display>Meditech List</Display>"^!,
   "<AbbrevName>MEDITECHLIST</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{/PCIGROUP[Q3] "<AcctPrsnlReltn>"^!,
   "<PersonnelUserNumber><![CDATA["_provider_"]]></PersonnelUserNumber>"^!,
   "<Display>Meditech Group List</Display>"^!,
   "<AbbrevName>MEDITECHLIST.GROUP</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!}

PATDOC.DO.SCH.DOCS
""^Q2A,
IF{wz "This code only relevant when called by SCHEDULING.",
   ""^wzQ,
   DO{+:WZ[wz]E[wzQ]^wzQ 1,
      "<AcctPrsnlReltn>"^!,
      :WZ[wz]E[wzQ]|1^WHO,
      ?WRE[WHO]|13^WHO2,
      IF{WHO2 1,
         WHO2^WHO},
      Q2A_WHO^Q2A,
      "<PersonnelUserNumber><![CDATA["_WHO_"]]></PersonnelUserNumber>"^!,
      "<Display>Appt. Resource</Display>"^!,
      "<AbbrevName>APPTRESOURCE</AbbrevName>"^!,
      "</AcctPrsnlReltn>"^!}},
IF{Q2A 1,
   Q2A_"a"^Q2A}

PATDOC.TRLR
"</PatientManagerList>"^!,
"</Payload>"^!,
"</ReplyMessage>"^!

PATDOC.MSM
@msmdir,
O(&S,@msmdata),
@misdir,
O(:S,@misdict),
@pkdir,
%Z.date.clinical(BDT)-1^DT^\DT,
%Z.date.clinical(EDT)^EDT^\EDT,
"<HEL>"^!,
DO{+&SCHDI[DT]^DT'>EDT 1,
   ""^sch,
   DO{+&SCHDI[DT,sch]^sch 1,
      IF{'&SCH[sch,"CAN"]&&SCH[sch,"PB","unum"] 1,
         @PATDOC.MSM.ACCT}}},
"</HEL>"^!,
"<HUPL>"^!,
%Z.date.clinical(BDT)-1^DT^\DT,
%Z.date.clinical(EDT)^EDT^\EDT,
DO{+&SCHDI[DT]^DT'>EDT 1,
   ""^sch,
   DO{+&SCHDI[DT,sch]^sch 1,
      IF{'&SCH[sch,"CAN"]&&SCH[sch,"PB","unum"] 1,
         @PATDOC.MSM.PAT}}},
"</HUPL>"^!,
C(&U),
C(:U)

PATDOC.MSM.ACCT
"MSM"_sch^Q1,
&SCH[sch,"PB","unum"]^Q3,
&SCH[sch]D|0_"_"_-&SCH[sch]AT[""]^Q2,
""^ggg^Q,
DO{+(&SCH[sch]DR[Q],ggg)^Q 1,
   ggg|0^ggg,
   Q2_ggg^Q2},
IF{/CONF[.patient.outpat.exp] 1,
   Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
"<Encounter>"^!,
"<VisitNumber>"_Q1_"</VisitNumber>"^!,
"<PatientNumber>"_Q3_"</PatientNumber>"^!,
"<Key>"_Q2_"</Key>"^!,
"<AcctPrsnlReltns>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelUserNumber><![CDATA["_&SCH[sch]|1_"]]></PersonnelUserNumber>"^!,
"<AbbrevName>ATTENDDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
@PATDOC.MSM.RELTNS,
"</AcctPrsnlReltns>"^!,
"</Encounter>"^!

PATDOC.MSM.PAT
"MSM"_sch^Q1,
&SCH[sch,"PB","unum"]^Q3,
&SCH[sch]D|0_"_"_-&SCH[sch]AT[""]^Q2,
""^ggg^Q,
DO{+(&SCH[sch]DR[Q],ggg)^Q 1,
   ggg|0^ggg,
   Q2_ggg^Q2},
IF{/CONF[.patient.outpat.exp] 1,
   Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
"<Person>"^!,
"<VisitNumber>"_Q1_"</VisitNumber>"^!,
"<PatientNumber>"_Q3_"</PatientNumber>"^!,
"<Key>"_Q2_"</Key>"^!,
"</Person>"^!

PATDOC.MSM.RELTNS
1^i,
DO{&SCH[sch,"DR",i]^chk 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_:GGG[chk|0]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_chk|0_"]]></PersonnelUserNumber>"^!,
   "<Display>Surgeon</Display>"^!,
   "<AbbrevName>SURGEON</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!,
   1^j,
   DO{&SCH[sch,"DR",i,"A",j]^chk 1,
      "<AcctPrsnlReltn>"^!,
      "<PersonnelName>"_:GGG[chk]|1_"</PersonnelName>"^!,
      "<PersonnelUserNumber><![CDATA["_chk_"]]></PersonnelUserNumber>"^!,
      "<Display>Asst. Surgeon</Display>"^!,
      "<AbbrevName>ASSTSURGEON</AbbrevName>"^!,
      "</AcctPrsnlReltn>"^!,
      j+1^j},
   i+1^i}
