PK.PAT.DEMO,
"HDR",@1,
"PATS",@2,
"TRLR",@4,
END;

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

[2]::PATS
1^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   ?(A)AAAI[ACT]^aa,
   "PAT",@3,
   nr+1^nr};

[3]::PAT
"<Person>"^!,
"<PatientNumber>"_$(A)AA[aa]|3_"</PatientNumber>"^!,
"<VisitNumber>"_$(A)AA[aa]|0_"</VisitNumber>"^!,
$(A)AA[aa]B|0^Q2,
<$(A)AA[aa]EV[""]^/tmp,
Q2_(/tmp#0S)_(/tmp#1S)^Q2,
""^ggg,
DO{+$(A)AA[aa]CDR[ggg]^ggg Q2_ggg^Q2},
"<Key>"_Q2_"</Key>"^!,
"<BirthDate>"_$(A)AA[aa]|5_"</BirthDate>"^!,
"<Gender>"_$(A)AA[aa]|7_"</Gender>"^!,
"<Race>"_$(A)AA[aa]A|5_"</Race>"^!,
$(A)AA[aa]|1^NM,
NM$(L(NM,","))^LNM,
NM%(L(NM,","))^NM,
NM$(L(NM," "))^FNM,
NM%(L(NM," "))^MNM,
"<FirstName>"_FNM_"</FirstName>"^!,
"<MiddleName>"_MNM_"</MiddleName>"^!,
"<LastName>"_LNM_"</LastName>"^!,
"<SocialSecurityNumber>"_$(A)AA[aa]A|2_"</SocialSecurityNumber>"^!,
"<MedicalRecordNumber>"_$(A)AA[aa]|3_"</MedicalRecordNumber>"^!,
"<MothersMaidenName></MothersMaidenName>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Address</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|0_"]]></DyPropValue>"^!,
"<DyPropMeaning>Street1</DyPropMeaning>"^!,
"<DyPropId>41</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Address</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|1_"]]></DyPropValue>"^!,
"<DyPropMeaning>Street2</DyPropMeaning>"^!,
"<DyPropId>42</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Address</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|2_"]]></DyPropValue>"^!,
"<DyPropMeaning>City</DyPropMeaning>"^!,
"<DyPropId>43</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Address</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|3_"]]></DyPropValue>"^!,
"<DyPropMeaning>State</DyPropMeaning>"^!,
"<DyPropId>44</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Address</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|4_"]]></DyPropValue>"^!,
"<DyPropMeaning>ZipCode</DyPropMeaning>"^!,
"<DyPropId>45</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Home Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|5_"]]></DyPropValue>"^!,
"<DyPropMeaning>HomePhone</DyPropMeaning>"^!,
"<DyPropId>46</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Work Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]E|7_"]]></DyPropValue>"^!,
"<DyPropMeaning>WorkPhone</DyPropMeaning>"^!,
"<DyPropId>47</DyPropId>"^!,
"</DynamicProperty>"^!,
"<DynamicProperty>"^!,
"<DyPropName>Other Phone</DyPropName>"^!,
"<DyPropValue><![CDATA["_$(A)AA[aa]AD|8_"]]></DyPropValue>"^!,
"<DyPropMeaning>OtherPhone</DyPropMeaning>"^!,
"<DyPropId>48</DyPropId>"^!,
"</DynamicProperty>"^!,
"</Person>"^!;

[4]::TRLR
"</Persons>"^!,
"</Payload>"^!,
"</ReplyMessage>"^!;

[98]::old.PATS
""^Q,
DO{>(?(A)AARB[Q],aa)^Q "PAT",@3};

[99]::OLD.PAT
"<Account>"^!,
"<ArriveDateTime>"_$(A)AA[aa]|13_$(A)AA[aa]|14_"</ArriveDateTime>"^!,
"<Bed>"_$(A)AA[aa]|11_"</Bed>"^!,
"<ContributorSystem>"^!,
"<Display>MEDITECH_ADT</Display>"^!,
"<Meaning>MEDITECH_ADT</Meaning>"^!,
"</ContributorSystem>"^!,
"<Accountnumber>"_$(A)AA[aa]|0_"</Accountnumber>"^!,
"<AccountStatus>"^!,
"<Display>ADM IN</Display>"^!,
"<Meaning>ADM IN</Meaning>"^!,
"</AccountStatus>"^!,
"<AccountType>"^!,
"<Display>IN</Display>"^!,
"</AccountType>"^!,
"<AccountTypeClass>"^!,
"<Display>Inpatient</Display>"^!,
"<Meaning>IN</Meaning>"^!,
"</AccountTypeClass>"^!,
"<Facility>"^!,
"<Display>"_&(G)GQB[$(A)AA[aa]B|7]|1_"</Display>"^!,
"<Meaning>"_$(A)AA[aa]B|7_"</Meaning>"^!,
"</Facility>"^!,
"<FinancialClass>"^!,
"<Display>"_&(G)GGK[$(A)AA[aa]A|3]|1_"</Display>"^!,
"<Meaning>"_$(A)AA[aa]A|3_"</Meaning>"^!,
"</FinancialClass>"^!,
"<Location>"^!,
"<Display>"_&(G)GGN[$(A)AA[aa]|12]|1_"</Display>"^!,
"<Meaning>"_$(A)AA[aa]|12_"</Meaning>"^!,
"</Location>"^!,
"<MedicalService>"^!,
"<Display>"_&(G)GGS[$(A)AA[aa]|9]|1_"</Display>"^!,
"<Meaning>"_$(A)AA[aa]|9_"</Meaning>"^!,
"</MedicalService>"^!,
"<Organization>"^!,
"<OrganizationId>BEV</OrganizationId>"^!,
"<Name>Northeast Health Systems</Name>"^!,
"</Organization>"^!,
"<RegistrationDateTime>"_$(A)AA[aa]|13_$(A)AA[aa]|14_"</RegistrationDateTime>"^!,
"<Room>"_$(A)AA[aa]|10_"</Room>"^!,
"<UnitNumber>"_$(A)AA[aa]|3_"</UnitNumber>"^!,
"<PatName>"_$(A)AA[aa]|1_"</PatName>"^!,
"<AcctPrsnlReltns>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelName>"_&(G)GGG[$(A)AA[aa]DR|0]|1_"</PersonnelName>"^!,
"<PersonnelUserName>"_$(A)AA[aa]DR|0_"</PersonnelUserName>"^!,
"<Display>Admitting Physician</Display>"^!,
"<AbbrevName>ADMITDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelName>"_&(G)GGG[$(A)AA[aa]DR|1]|1_"</PersonnelName>"^!,
"<Username>"_$(A)AA[aa]DR|1_"</Username>"^!,
"<Display>Attending Physician</Display>"^!,
"<AbbrevName>ATTENDDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelName>"_&(G)GGG[$(A)AA[aa]DR|2]|1_"</PersonnelName>"^!,
"<Username>"_$(A)AA[aa]DR|2_"</Username>"^!,
"<Display>Other Physician</Display>"^!,
"<AbbrevName>OTHERDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelName>"_&(G)GGG[$(A)AA[aa]DR|3]|1_"</PersonnelName>"^!,
"<Username>"_$(A)AA[aa]DR|3_"</Username>"^!,
"<Display>Family Physician</Display>"^!,
"<AbbrevName>FAMILYDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelName>"_&(G)GGG[$(A)AA[aa]DR|4]|1_"</PersonnelName>"^!,
"<Username>"_$(A)AA[aa]DR|4_"</Username>"^!,
"<Display>ER Physician</Display>"^!,
"<AbbrevName>ERDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
"<AcctPrsnlReltn>"^!,
"<PersonnelName>"_&(G)GGG[$(A)AA[aa]DR|5]|1_"</PersonnelName>"^!,
"<Username>"_$(A)AA[aa]DR|5_"</Username>"^!,
"<Display>PrimCare Physician</Display>"^!,
"<AbbrevName>PRIMCAREDOC</AbbrevName>"^!,
"</AcctPrsnlReltn>"^!,
"</AcctPrsnlReltns>"^!,
"</Account>"^!;