PATACT
@PATACT.OPEN.PREFIXES,
@PATACT.HDR,
@PATACT.PATS,
@PATACT.TRLR,
END;

PATACT.OPEN.PREFIXES
@misdir,
O(&,@misdict),
@admdir,
O(*,@admdata),
IF{/CONF[.usesch] 1,
   @schdir,
   O(:,@schdata),
   O(?,@schdict)},
IF{/CONF[.usemsm] 1,
   @msmdir,
   O(#,@msmdata)},
@pkdir

PATACT.HDR
"<?xml version="_D(34)_1.0_D(34)_" ?>"^!,
"<ReplyMessage>"^!,
"<TransactionId>"_7801_"</TransactionId>"^!,
"<Status>Success</Status>"^!,
"<StatusDescription>Accounts read: 1</StatusDescription>"^!,
"<Payload>"^!,
"<Accounts>"^!

PATACT.PATS
%Z.db.today(0)^TODAY,
0^nr,
DO{nr+1^nr</ARGC 1,
   /ARGV[nr]^ACT,
   @PATACT.SWITCH}

; Account numbers that begin with "MSM" come from the surgery system,
; and should be routed through that code.
; Account numbers containing "_PK" (patient.outpat.exp) are exploded
; with the form ACC_PKYYYYMMDDHHMM. We separate it into aa and appt.
; In the end, aa is the account index, and appt is set if it's an
; outpatient appointment.
PATACT.SWITCH
IF{ACT$3="MSM" 1,
   ACT^sch,
   @PATACT.MSM.PAT;
   ""^aa,
   IF{/CONF[.patient.outpat.exp] 1,
      L(ACT,/CONF[.patient.outpat.exp])^POS,
      IF{POS'=L(ACT) 1,
         *AAAI[ACT$POS]^aa,
         ACT%(POS+L(/CONF[.patient.outpat.exp])-1)^appt}},
   IF{'aa 1,
      *AAAI[ACT]^aa,
      ""^appt},
   IF{aa @PATACT.PAT}}

PATACT.PAT
IF{appt 1,
   *AA[aa]|0_/CONF[.patient.outpat.exp]_appt^Q1;
   *AA[aa]|0^Q1},
*AA[aa]|3^Q3,
*AA[aa]|2^STATTYPE,
STATTYPE%(L(STATTYPE," "))^TYPE,
IF{/CONF[.patient.outpat.exp]&(appt!(TYPE'="IN")) 1,
   Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
"<Account>"^!,
"<PatientNumber>"_Q3_"</PatientNumber>"^!,
"<VisitNumber>"_Q1_"</VisitNumber>"^!,
"<PatientName>"_*AA[aa]|1_"</PatientName>"^!,
*AA[aa]B|0^Q2,
<*AA[aa]EV[""]^/tmp,
Q2_(/tmp#0S)_(/tmp#1S)^Q2,
""^ggg,
DO{+*AA[aa]CDR[ggg]^ggg Q2_ggg^Q2},
""^Mwz,
IF{appt 1,
   ""^wz,
   "19040101"^DATE,
   "0000"^TIME,
   "[cancelled or rescheduled]"^LOCATION,
   DO{+*AA[aa]WZ[wz]^wz 1,
      *AA[aa]WZ[wz]|0^dt,
      *AA[aa]WZ[wz]|1^tm,
      IF{dt_tm=appt 1,
         dt^DATE,
         tm^TIME,
         *AA[aa]WZ[wz]|2^LOCATION,
         wz^Mwz}}},
IF{'appt!((appt$8)<TODAY) 1,
   (*AA[aa]|12)_" "_(*AA[aa]|10)_"-"_(*AA[aa]|11)^LOCATION,
   (*AA[aa]|13!*AA[aa]|15!*AA[aa]O3|1!*AA[aa]T|0)^DATE,
   (*AA[aa]|14!*AA[aa]|16!*AA[aa]O3|2!*AA[aa]T|1)^TIME},
"<ArriveDate>"_DATE_TIME_"</ArriveDate>"^!,
IF{Mwz 1,
   "<AppointmentStatus>"_:WZ[Mwz]|5_"</AppointmentStatus>"^!},
"<RegistrationDate>"_*AA[aa]|13_*AA[aa]|14_"</RegistrationDate>"^!,
"<DischargeDate>"_*AA[aa]|17_*AA[aa]|18_"</DischargeDate>"^!,
"<ReasonForVisit><![CDATA["_*AA[aa]CO|1_"]]></ReasonForVisit>"^!,
"<FinancialNumber>"_*AA[aa]|0_"</FinancialNumber>"^!,
"<NurseUnitName><![CDATA["_&GGN[*AA[aa]|12]|1_"]]></NurseUnitName>"^!,
"<NurseUnitMnemonic><![CDATA[LOC."_*AA[aa]|12_"]]></NurseUnitMnemonic>"^!,
"<MedicalService>"_&GGS[*AA[aa]|9]|1_"</MedicalService>"^!,
"<FinancialClass>"_&GGK[*AA[aa]A|3]|1_"</FinancialClass>"^!,
"<Insurance><![CDATA["_*AA[aa]IO[1]|0_"]]></Insurance>"^!,
"<Location>"_LOCATION_"</Location>"^!,
"<AdmittingPrsnlUserNumber>"_*AA[aa]DR|0_"</AdmittingPrsnlUserNumber>"^!,
"<AttendingPrsnlUserNumber>"_*AA[aa]DR|1_"</AttendingPrsnlUserNumber>"^!,
"<PrimaryCarePrsnlUserNumber>"_*AA[aa]DR|5_"</PrimaryCarePrsnlUserNumber>"^!,
"<DynamicProperty>"^!,
"<DyPropName>MEDITECH ADT</DyPropName>"^!,
"<DyPropMeaning>MEDITECH ADT</DyPropMeaning>"^!,
"</DynamicProperty>"^!,
IF{*AA[aa]O3|10 1,
   "<DynamicProperty>"^!,
   "<DyPropName>OBSV</DyPropName>"^!,
   "<DyPropMeaning>PTTY.OBSV</DyPropMeaning>"^!,
   "<DyPropValue><![CDATA["_*AA[aa]O3|10_"]]></DyPropValue>"^!,
   "</DynamicProperty>"^!},
"<DynamicProperty>"^!,
"<DyPropName><![CDATA["_*AA[aa]|2_"]]></DyPropName>"^!,
"<DyPropMeaning><![CDATA[PTST."_*AA[aa]|2_"]]></DyPropMeaning>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
*AA[aa]|2^Q,
Q%(L(Q," "))^Q1,
"<DyPropName><![CDATA["_Q1_"]]></DyPropName>"^!,
"<DyPropMeaning><![CDATA[PTTY."_Q1_"]]></DyPropMeaning>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
IF{Q1="IN" "Inpatient"^PATTYP;"Outpatient"^PATTYP},
"<DyPropName>"_PATTYP_"</DyPropName>"^!,
"<DyPropMeaning>VisitType."_PATTYP_"</DyPropMeaning>"^!,
"<DyPropValue><![CDATA[VisitType."_PATTYP_"]]></DyPropValue>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
*AA[aa]IO[1]|0^ggm,
"<DyPropName>PrimaryInsurance.Company</DyPropName>"^!,
"<DyPropValue><![CDATA["_ggm_"]]></DyPropValue>"^!,
"<DyPropId>50</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Street1</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|0;&GGM[ggm]|2}_"]]></DyPropValue>"^!,
"<DyPropId>51</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Street2</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|6;&GGM[ggm]B|5}_"]]></DyPropValue>"^!,
"<DyPropId>52</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.City</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|1;&GGM[ggm]|3}_"]]></DyPropValue>"^!,
"<DyPropId>53</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.State</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|2;&GGM[ggm]|4}_"]]></DyPropValue>"^!,
"<DyPropId>54</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.ZipCode</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|3;&GGM[ggm]|5}_"]]></DyPropValue>"^!,
"<DyPropId>55</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|4;&GGM[ggm]|6}_"]]></DyPropValue>"^!,
"<DyPropId>56</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Type</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|9_"]]></DyPropValue>"^!,
"<DyPropId>57</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Policy</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|2_"]]></DyPropValue>"^!,
"<DyPropId>58</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Guarantor</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|10_"]]></DyPropValue>"^!,
"<DyPropId>59</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.GroupAuthorization</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|8_"]]></DyPropValue>"^!,
"<DyPropId>60</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
*AA[aa]IO[2]|0^ggm,
"<DyPropName>SecondaryInsurance.Company</DyPropName>"^!,
"<DyPropValue><![CDATA["_ggm_"]]></DyPropValue>"^!,
"<DyPropId>70</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.Street1</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|0;&GGM[ggm]|2}_"]]></DyPropValue>"^!,
"<DyPropId>71</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.Street2</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|6;&GGM[ggm]B|5}_"]]></DyPropValue>"^!,
"<DyPropId>72</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.City</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|1;&GGM[ggm]|3}_"]]></DyPropValue>"^!,
"<DyPropId>73</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.State</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|2;&GGM[ggm]|4}_"]]></DyPropValue>"^!,
"<DyPropId>74</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.ZipCode</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|3;&GGM[ggm]|5}_"]]></DyPropValue>"^!,
"<DyPropId>75</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|4;&GGM[ggm]|6}_"]]></DyPropValue>"^!,
"<DyPropId>76</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.Type</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|9_"]]></DyPropValue>"^!,
"<DyPropId>77</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.Policy</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|2_"]]></DyPropValue>"^!,
"<DyPropId>78</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.Guarantor</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|10_"]]></DyPropValue>"^!,
"<DyPropId>79</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>SecondaryInsurance.GroupAuthorization</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|8_"]]></DyPropValue>"^!,
"<DyPropId>80</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
*AA[aa]IO[3]|0^ggm,
"<DyPropName>TertiaryInsurance.Company</DyPropName>"^!,
"<DyPropValue><![CDATA["_ggm_"]]></DyPropValue>"^!,
"<DyPropId>90</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.Street1</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|0;&GGM[ggm]|2}_"]]></DyPropValue>"^!,
"<DyPropId>91</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.Street2</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|6;&GGM[ggm]B|5}_"]]></DyPropValue>"^!,
"<DyPropId>92</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.City</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|1;&GGM[ggm]|3}_"]]></DyPropValue>"^!,
"<DyPropId>93</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.State</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|2;&GGM[ggm]|4}_"]]></DyPropValue>"^!,
"<DyPropId>94</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.ZipCode</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|3;&GGM[ggm]|5}_"]]></DyPropValue>"^!,
"<DyPropId>95</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_IF{*AA[aa]I[ggm]|4;&GGM[ggm]|6}_"]]></DyPropValue>"^!,
"<DyPropId>96</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.Type</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|9_"]]></DyPropValue>"^!,
"<DyPropId>97</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.Policy</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|2_"]]></DyPropValue>"^!,
"<DyPropId>98</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.Guarantor</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|10_"]]></DyPropValue>"^!,
"<DyPropId>99</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>TertiaryInsurance.GroupAuthorization</DyPropName>"^!,
"<DyPropValue><![CDATA["_*AA[aa]I[ggm]N|8_"]]></DyPropValue>"^!,
"<DyPropId>100</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName><![CDATA["_&GGK[*AA[aa]A|3]|1_"]]></DyPropName>"^!,
"<DyPropMeaning><![CDATA[FC."_*AA[aa]A|3_"]]></DyPropMeaning>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName><![CDATA["_&GGN[*AA[aa]|12]|1_"]]></DyPropName>"^!,
"<DyPropMeaning><![CDATA[LOC."_*AA[aa]|12_"]]></DyPropMeaning>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName><![CDATA["_&GGS[*AA[aa]|9]|1_"]]></DyPropName>"^!,
"<DyPropMeaning><![CDATA[SVC."_*AA[aa]|9_"]]></DyPropMeaning>"^!,
"</DynamicProperty>"^!,
"<AcctPrsnlReltns>"^!,
IF{/CONF[.patient.scheduledrelsonly]&appt;
   @PATACT.DO.BASIC.DOCS,
   @PATACT.DO.OTH.DOCS},
@PATACT.DO.SCH.DOCS,
"</AcctPrsnlReltns>"^!,
"<Key>"_Q2_Q2A_"</Key>"^!,
"</Account>"^!

PATACT.DO.BASIC.DOCS
IF{*AA[aa]DR|0 "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[*AA[aa]DR|0]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_*AA[aa]DR|0_"]]></PersonnelUserNumber>"^!,
   "<Display>Admitting Physician</Display>"^!,
   "<AbbrevName>ADMITDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{*AA[aa]DR|1 "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[*AA[aa]DR|1]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_*AA[aa]DR|1_"]]></PersonnelUserNumber>"^!,
   "<Display>Attending Physician</Display>"^!,
   "<AbbrevName>ATTENDDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{*AA[aa]DR|2 "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[*AA[aa]DR|2]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_*AA[aa]DR|2_"]]></PersonnelUserNumber>"^!,
   "<Display>Other Physician</Display>"^!,
   "<AbbrevName>OTHERDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{*AA[aa]DR|3 "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[*AA[aa]DR|3]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_*AA[aa]DR|3_"]]></PersonnelUserNumber>"^!,
   "<Display>Family Physician</Display>"^!,
   "<AbbrevName>FAMILYDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{*AA[aa]DR|4 "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[*AA[aa]DR|4]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_*AA[aa]DR|4_"]]></PersonnelUserNumber>"^!,
   "<Display>ER Physician</Display>"^!,
   "<AbbrevName>ERDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
IF{*AA[aa]DR|5 "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[*AA[aa]DR|5]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_*AA[aa]DR|5_"]]></PersonnelUserNumber>"^!,
   "<Display>Primary Care Physician</Display>"^!,
   "<AbbrevName>PRIMCAREDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!}

PATACT.DO.OTH.DOCS
""^ggg,
DO{+*AA[aa]CDR[ggg]^ggg 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[ggg]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_ggg_"]]></PersonnelUserNumber>"^!,
   "<Display>Consulting Physician</Display>"^!,
   "<AbbrevName>CONSULTDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!}

PATACT.DO.SCH.DOCS
""^Q2A,
IF{Mwz 1,
   ""^wzQ,
   DO{+:WZ[Mwz]E[wzQ]^wzQ 1,
      "<AcctPrsnlReltn>"^!,
      :WZ[Mwz]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 Q2A_"a"^Q2A}

PATACT.TRLR
"</Accounts>"^!,
"</Payload>"^!,
"</ReplyMessage>"^!

PATACT.MSM.PAT
sch%2^sch,
"MSM"_sch^Q1,
#SCH[sch,"PB","unum"]^Q3,
IF{/CONF[.patient.outpat.exp] 1,
   Q3_/CONF[.patient.outpat.exp]_Q1^Q3},
"<Account>"^!,
"<PatientNumber>"_Q3_"</PatientNumber>"^!,
"<VisitNumber>"_Q1_"</VisitNumber>"^!,
"<FinancialNumber>MSM"_sch_"</FinancialNumber>"^!,
"<PatientName>"_#SCH[sch,"PB","nm"]_"</PatientName>"^!,
#SCH[sch]D|0_"_"_-#SCH[sch]AT[""]^Q2,
""^ggg^Q,
DO{+(#SCH[sch,"DR",Q],qq)^Q 1,
   qq|0^ggg,
   Q2_ggg^Q2},
"<Key>"_Q2_"</Key>"^!,
"<ArriveDate>"^!,
%Z.date.clin.to.npr(#SCH[sch]|0)^!,
IF{#SCH[sch,"MOVED"] 1,
   @PATACT.FIND.MOVED;
   #SCH[sch,"AT",1]|3^sinf},
%Z.time.in(sinf%(L(sinf)-5))^st,
%Z.time.out(st+(60*(#SCH[sch]|6)))^!,
"</ArriveDate>"^!,
"<ReasonForVisit><![CDATA["_#SCH[sch,"PB","DIAGNOSIS",1]_"]]></ReasonForVisit>"^!,
"<Location>"_#SCH[sch]|11_" - "_#SCH[sch]|3_"</Location>"^!,
"<AttendingPrsnlUserNumber>"_#SCH[sch]|1_"</AttendingPrsnlUserNumber>"^!,
"<DynamicProperty>"^!,
"<DyPropName>MSM OR</DyPropName>"^!,
"<DyPropMeaning>MSM OR</DyPropMeaning>"^!,
"<DyPropValue>MSM OR</DyPropValue>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
#SCH[sch,"PB","pre.ptyp"]^Q,
Q%(L(Q," "))^Q1,
"<DyPropName>"_Q1_"</DyPropName>"^!,
"<DyPropMeaning>PTTY."_Q1_"</DyPropMeaning>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
IF{Q1="IN" 1,
   "Inpatient"^PATTYP;
   "Outpatient"^PATTYP},
"<DyPropName>"_PATTYP_"</DyPropName>"^!,
"<DyPropMeaning>VisitType."_PATTYP_"</DyPropMeaning>"^!,
"<DyPropValue><![CDATA[VisitType."_PATTYP_"]]></DyPropValue>"^!,
"</DynamicProperty>"^!,
"<Insurance><![CDATA["_#SCH[sch,"PB","pre.ins"]_"]]></Insurance>"^!,
"<DynamicProperty>"^!,
#SCH[sch,"PB","pre.ins"]^ggm,
"<DyPropName>PrimaryInsurance.Company</DyPropName>"^!,
"<DyPropValue><![CDATA["_ggm_"]]></DyPropValue>"^!,
"<DyPropId>50</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Street1</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|2_"]]></DyPropValue>"^!,
"<DyPropId>51</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Street2</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]B|5_"]]></DyPropValue>"^!,
"<DyPropId>52</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.City</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|3_"]]></DyPropValue>"^!,
"<DyPropId>53</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.State</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|4_"]]></DyPropValue>"^!,
"<DyPropId>54</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.ZipCode</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|5_"]]></DyPropValue>"^!,
"<DyPropId>55</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|6_"]]></DyPropValue>"^!,
"<DyPropId>56</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>PrimaryInsurance.Type</DyPropName>"^!,
"<DyPropValue><![CDATA["_&GGM[ggm]|9_"]]></DyPropValue>"^!,
"<DyPropId>57</DyPropId>"^!,
"</DynamicProperty>"^!,
"<AcctPrsnlReltns>"^!,
IF{#SCH[sch]|1 1,
   "<AcctPrsnlReltn>"^!,
   "<PersonnelName>"_&GGG[#SCH[sch]|1]|1_"</PersonnelName>"^!,
   "<PersonnelUserNumber><![CDATA["_#SCH[sch]|1_"]]></PersonnelUserNumber>"^!,
   "<Display>Attending Physician</Display>"^!,
   "<AbbrevName>ATTENDDOC</AbbrevName>"^!,
   "</AcctPrsnlReltn>"^!},
@PATACT.MSM.RELTNS,
"</AcctPrsnlReltns>"^!,
"</Account>"^!

PATACT.FIND.MOVED
1^i,
DO{#SCH[sch,"AT",i]^chk 1,
   1+i^i,
   IF{(chk|0="BOOKED")!(chk|0="MOVED")!(chk|0="REARRANGE") 1,
      chk|3^sinf}}

PATACT.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}
