PK.ALLERGY.KEY,
@OPEN.ALRGKEY,
@HDR,
@PATS,
@TRLR,
END;

OPEN.ALRGKEY
@admdir,
O(&,@misdict),
O(:,@admdata),
@phadir,
O(*,@phadata),
O(\,@phadict),
@pkdir

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

PATS
1^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   *AAAI[ACT]^aa,
   @XMIT,
   nr+1^nr}

XMIT
"INGRED"^TYP,"Ingredient"^TYPNAM,
"Allergy"^REACTION,
""^algy,
DO{+(*TAA[aa]AC[algy],Q)^algy "<Allergy>"^!,
                              \TTA[algy]|1^DESC,
                              Q|0^ENTDT,
                              @SEND,
                              ""^QK,
                              "<AllergyComments>"^!,
                              DO{+(*TAA[aa]AC[algy]R[QK],Q)^QK @SEND.LN},
                              "</AllergyComments>"^!,
                              "</Allergy>"^!},
""^algy,
"Adverse Drug Reaction"^REACTION,
DO{+(*TAA[aa]ACR[algy],Q)^algy "<Allergy>"^!,
                              \TTA[algy]|1^DESC,
                              Q|0^ENTDT,
                              @SEND,
                              ""^QK,
                              "<AllergyComments>"^!,
                              DO{+(*TAA[aa]ACR[algy]R[QK],Q)^QK @SEND.LN},
                              "</AllergyComments>"^!,
                              "</Allergy>"^!},
"CLASS"^TYP,"Class"^TYPNAM,
"Allergy"^REACTION,
""^algy,
DO{+(*TAA[aa]CA[algy],Q)^algy "<Allergy>"^!,
                              \TDC[algy]|1^DESC,
                              Q|0^ENTDT,
                              @SEND,
                              ""^QK,
                              "<AllergyComments>"^!,
                              DO{+(*TAA[aa]CA[algy]R[QK],Q)^QK @SEND.LN},
                              "</AllergyComments>"^!,
                              "</Allergy>"^!},
"Adverse Drug Reaction"^REACTION,
""^algy,
DO{+(*TAA[aa]CAR[algy],Q)^algy "<Allergy>"^!,
                              \TDC[algy]|1^DESC,
                              Q|0^ENTDT,
                              @SEND,
                              ""^QK,
                              "<AllergyComments>"^!,
                              DO{+(*TAA[aa]CAR[algy]R[QK],Q)^QK @SEND.LN},
                              "</AllergyComments>"^!,
                              "</Allergy>"^!},
"GEN"^TYP,"Generic"^TYPNAM,
"Allergy"^REACTION,
""^algy,
DO{+(*TAA[aa]GA[algy],Q)^algy "<Allergy>"^!,
                              \TDG[algy]|1^DESC,
                              Q|0^ENTDT,
                              @SEND,
                              ""^QK,
                              "<AllergyComments>"^!,
                              DO{+(*TAA[aa]GA[algy]R[QK],Q)^QK @SEND.LN},
                              "</AllergyComments>"^!,
                              "</Allergy>"^!},
"Adverse Drug Reaction"^REACTION,
""^algy,
DO{+(*TAA[aa]GAR[algy],Q)^algy "<Allergy>"^!,
                              \TDG[algy]|1^DESC,
                              Q|0^ENTDT,
                              @SEND,
                              ""^QK,
                              "<AllergyComments>"^!,
                              DO{+(*TAA[aa]GAR[algy]R[QK],Q)^QK @SEND.LN},
                              "</AllergyComments>"^!,
                              "</Allergy>"^!},
"Allergy"^REACTION,
""^algy,
DO{>(*TAA[aa]OAN[algy],Q)^algy Q|0:0S^DESC,
                              IF{L(DESC)>0 "<Allergy>"^!,
                              algy#0S^TYP,
                              IF{L(TYP,"MED")'=L(TYP) "MED"^TYP,"Med"^TYPNAM;
                                 L(TYP,"FOOD")'=L(TYP) "FOOD"^TYP,"Food"^TYPNAM;
                                 "OTH"^TYP,"Other"^TYPNAM},
                               ""^ENTDT,
                               @SEND,
                               "no comments in this type of allergy",
                               "</Allergy>"^!}}

SEND
"<AllergyInstanceId>"_ACT_"."_TYP_"."_algy:0X_"</AllergyInstanceId>"^!,
"<Key>"_"x"_ENTDT_"</Key>"^!,
"<PatientNumber>"_:AA[aa]|3_"</PatientNumber>"^!,
"<SubstanceType>"^!,
"<TypeMnemonic>"_TYP_"</TypeMnemonic>"^!,
"<Display>"_TYPNAM_"</Display>"^!,
"</SubstanceType>"^!,
"<SubstanceDescription><![CDATA["_DESC_"]]></SubstanceDescription>"^!,
"<ReactionClass><Display><![CDATA["_REACTION_"]]></Display></ReactionClass>"^!,
"note: this is entered date, not onset date",
"<OnsetDateTime>"_%Z.date.in.magic(ENTDT)_" "_%Z.time.out(ENTDT)_"</OnsetDateTime>"^!

SEND.LN
"<AllergyComment>"^!,
"<Mnemonic>"_algy_"."_QK_"</Mnemonic>"^!,
"<Comment>"_Q_"</Comment>"^!,
"</AllergyComment>"^!

TRLR
"</Allergies>"^!,
"</Payload>"^!,
"</ReplyMessage>"^!
