PK.ALLERGY.DATA
"HDR",@1,
"PATS",@2,
"TRLR",@7,
END;

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

[2]::PATS
1^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^UN,
   ?(E)EAU[UN]^ea,
   "CODED",@3,
   "UNCODED",@4,
   nr+1^nr};

[3]::CODED
""^Q,
""^algy,
DO{+(*(E1)EBA[ea]C[algy],Q)^algy "C"^ACODETYPE,@5,"ALLERGY"};

[4]::UNCODED
""^Q,
""^algy,
DO{+(*(E1)EBA[ea]U[algy],Q)^algy "U"^ACODETYPE,@5,"ALLERGY"};

[5]::ALLERGY
IF{ACODETYPE="C" *(E1)EBA[ea]C[algy]^Q,
&(G)GEL[algy]|2^ACATEGORY,
&(G)GEL[algy]|1^ASUBSTANCE,
Q|0^AREACTIONTYPE,
Q|1^ASEVERITY,
Q|2^ADATE,
Q|3^AVERIFIED,
Q|4^AREACTION;
*(E1)EBA[ea]U[algy]^Q,
"Uncoded"^ACATEGORY,
algy^ASUBSTANCE,
Q|0^AREACTIONTYPE,
Q|1^ASEVERITY,
Q|2^ADATE,
Q|3^AREACTION,
"N"^AVERIFIED},
ACATEGORY@LU^ACATEGORYMNEMONIC,
@6,"SEND";

[6]::SEND
IF{ACATEGORY_.=.;
"<Allergy>"^!,
UN_"."_ACODETYPE_"."_algy^algyID,
"<AllergyInstanceId><![CDATA["_algyID_"]]></AllergyInstanceId>"^!,
"<Key>"_"x"_SYNCKEY_"</Key>"^!,
"<PatientNumber>"_UN_"</PatientNumber>"^!,
"<SubstanceType>"^!,
"<TypeMnemonic>"_ACATEGORYMNEMONIC_"</TypeMnemonic>"^!,
"<Display>"_ACATEGORY_"</Display>"^!,
"</SubstanceType>"^!,
"<SubstanceDescription><![CDATA["_ASUBSTANCE_"]]></SubstanceDescription>"^!,
"<ReactionClass><Display><![CDATA["_AREACTIONTYPE_"]]></Display></ReactionClass>"^!,
"<Severity><Display><![CDATA["_ASEVERITY_"]]></Display></Severity>"^!,
"<OnsetDateTime>"_ADATE_"</OnsetDateTime>"^!,
"<VerifiedStatus>"_IF{AVERIFIED="Y" "true";"false"}_"</VerifiedStatus>"^!,
IF{AREACTION:0X:0S_"."=".";
"<Reactions>"^!,
"<Reaction>"^!,
"<ReactionDescription><![CDATA["_AREACTION_"]]></ReactionDescription>"^!,
"</Reaction>"^!,
"</Reactions>"^!},
"<AllergyComments>"^!,
0^counter,
IF{ACODETYPE="C" DO{+(*(E1)EBA[ea]C[algy]T[L],LN)^L counter+1^counter,
"<AllergyComment>"^!,
"<Comment><![CDATA["_LN_"]]></Comment>"^!,
"</AllergyComment>"^!};
DO{+(*(E1)EBA[ea]U[algy]T[L],LN)^L counter+1^counter,
"<AllergyComment>"^!,
"<Mnemonic><![CDATA["_algyID_"."_counter_"]]></Mnemonic>"^!,
"<Comment><![CDATA["_LN_"]]></Comment>"^!,
"</AllergyComment>"^!}},
"</AllergyComments>"^!,
"</Allergy>"^!};

[7]::TRLR
"</Allergies>"^!,
"</Payload>"^!,
"</ReplyMessage>"^!;
