PK.MARDATA
@OPEN.MED,
@INIT,
@HDR,
@ARGS,
@TRLR,
END;

OPEN.MED
@misdir,
O(&,@misdict),
@phadir,
O(*,@phadata),
O(\,@phadict),
@pkdir

INIT
"not used"

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

ARGS
1^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ARG,
   @RX,
   nr+1^nr}

RX
ARG$L(ARG,":")^ORDER,
ORDER$L(ORDER,.)^tr,
ORDER%L(ORDER,.)^trsub,
ARG%L(ARG,":")^traQ,
*TRA[tr,traQ]^TRA,
*TR[tr]|1^aa,
"<MedicationResult>"^!,
"<EventMnemonic>"_ARG_"</EventMnemonic>"^!,
"<Key>"_TRA|1_TRA|2_"</Key>"^!,
"<PatientNumber>"_*AA[aa]|3_"</PatientNumber>"^!,
"<OrderMnemonic>"_ORDER_"</OrderMnemonic>"^!,
"<AdministrationDateTime>"_TRA|1_TRA|2_"</AdministrationDateTime>"^!,
IF{TRA|14="Y" "not given",
   TRA|17_" "_TRA|27^dose,
   0^statusflags;
   "NOT GIVEN"^dose,
   4^statusflags},
"<StatusFlags>"_statusflags_"</StatusFlags>"^!,
"<AdministrationDoseAndUnit>"_dose_"</AdministrationDoseAndUnit>"^!,
"<AdministrationNote><![CDATA["^!,
DO{+*TRA[tr,traQ]RC[tdrc]^tdrc \TDRC[tdrc]|1_D(10)^!},
DO{+(*TRA[tr,traQ]T[t],TXT)^t TXT_D(10)^!},
"]]></AdministrationNote>"^!,
"use same logic here as in pk.users",
TRA|3^gu,
IF{&GU[gu]MR|4;gu}^USERNAME,
"<AdministrationProvider>"_USERNAME_"</AdministrationProvider>"^!,
"</MedicationResult>"^!

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