PSSHL1 ;BIR/RLW/WRT-BUILD HL7 MESSAGE TO POPULATE ORDERABLE ITEM FILE ;09/08/97
;;1.0;PHARMACY DATA MANAGEMENT;**38,68,125**;9/30/97;Build 2
;External reference to ORD(101 supported by DBIA 872
; PSJEC=event code from HL7 table 8.4.2.1
; PSJSPIEN=ien to super-primary drug file (#50.7)
; SPDNAME=.01 field (name) of super-primary drug
; LIMIT=number of fields in HL7 segment being built
;
W !!?3,"This routine should not be accessed through programmer mode!",!
Q
EN1 ; start here for pre-install auto load
N MENU,MENUP,ITEM
D PRO Q:$G(XPDABORT)
S PSSMFU=+$O(^PS(59.7,0)) I $P(^PS(59.7,PSSMFU,80),"^",2)=4 K PSSMFU Q
N APPL,CODE,FIELD,LIMIT,MFE,PSJI,SEGMENT,SPDNAME,SYN,SYNONYM,USAGE,X
I '$D(^XTMP("PSO_V7 INSTALL",0)) S X1=DT,X2=+7 D C^%DTC S ^XTMP("PSO_V7 INSTALL",0)=DT_"^"_X_"^OUTPATIENT V7 KIDS INSTALL" L +^XTMP("PSO_V7 INSTALL",0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) G SKIP
F Q:'$D(^XTMP("PSO_V7 INSTALL",0)) L +^XTMP("PSO_V7 INSTALL",0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) Q:$T
I '$D(^XTMP("PSO_V7 INSTALL",0)) S X1=DT,X2=+7 D C^%DTC S ^XTMP("PSO_V7 INSTALL",0)=DT_"^"_X_"^OUTPATIENT V7 KIDS INSTALL" L +^XTMP("PSO_V7 INSTALL",0):$S($G(DILOCKTM)>0:DILOCKTM,1:3)
I $P(^PS(59.7,PSSMFU,80),"^",2)=4 L -^XTMP("PSO_V7 INSTALL",0) K ^XTMP("PSO_V7 INSTALL",0) Q
SKIP ;
S PSJEC="MAD",CODE="REP"
D INIT
D LOOP,MF^PSSHLU(PSJI)
S PSLSITE=+$O(^PS(59.7,0)) S $P(^PS(59.7,PSLSITE,80),"^",2)=4 K PSLSITE
L -^XTMP("PSO_V7 INSTALL",0) K ^XTMP("PSO_V7 INSTALL",0)
K ^TMP("HLS",$J,"PS"),PSJEC,PSJSPIEN,PSJCLEAR,PSSMFU Q
;
EN2(PSJSPIEN,PSJEC) ; start here for "manual" update
S PSLSITE=+$O(^PS(59.7,0)) I +$P($G(^PS(59.7,PSLSITE,80)),"^",2)<4 K PSLSITE Q
; passed in: internal entry # of super-primary drug, entry code
S:'$P($G(^PS(50.7,PSJSPIEN,0)),"^",4) PSJEC="MAC"
K PSLSITE N APPL,CODE,FIELD,PSJI,LIMIT,MFE,SEGMENT,SPDNAME,SYN,SYNONYM,USAGE,X,ZCOUNT,ZUSAGE
S CODE="UPD"
D INIT
D MFE(PSSIVID),MF^PSSHLU(PSJI)
K ^TMP("HLS",$J,"PS")
Q
;
;
INIT ; initialize HL7 variables, set master file identification segment fields
S PSJI=0,LIMIT=6,HLMTN="MFN",PSSIVID=$$GTIVID()
D INIT^PSSHLU X PSJCLEAR
S FIELD(0)="MFI"
S FIELD(1)="50.7^PHARMACY ORDERABLE ITEM^99DD"
S FIELD(3)=CODE
S FIELD(6)="NE"
D SEGMENT^PSSHLU(LIMIT)
Q
;
LOOP ; loop through PHARMACY ORDERABLE ITEM file
;F L +^PS(59.7,PSSIVID,31) Q:$T H 1
S PSJSPIEN=0 F S PSJSPIEN=$O(^PS(50.7,PSJSPIEN)) Q:'PSJSPIEN D MFE(PSSIVID)
;L -^PS(59.7,PSSIVID,31)
Q
;
MFE(PSSIVID) ; set master file entry segment fields
; Input: PSSIVID-IV Identifier
S LIMIT=4 X PSJCLEAR
S X=$G(^PS(50.7,PSJSPIEN,0))
S FIELD(0)="MFE"
S FIELD(1)=PSJEC
S FIELD(3)=$P($G(^PS(50.7,PSJSPIEN,0)),"^",4) I FIELD(3) S FIELD(3)=$$HLDATE^HLFNC(FIELD(3))
S FIELD(4)="^^^"_PSJSPIEN_"^"_$P(X,"^")_"~"_$P($G(^PS(50.606,$P(X,"^",2),0)),"^")_"~"_$S($P($G(^PS(50.7,PSJSPIEN,0)),"^",3):$G(PSSIVID),1:"")_"^99PSP"
D SEGMENT^PSSHLU(LIMIT)
D ZPS,ZSY
Q
;
ZPS ; get USAGE from dispense drug(s), set ZPS segment
S LIMIT=2 X PSJCLEAR
S FIELD(0)="ZPS"
S USAGE=$$USAGE^PSSHLU(PSJSPIEN)
Q:USAGE=""&('$P($G(^PS(50.7,PSJSPIEN,0)),"^",9))&('$P($G(^PS(50.7,PSJSPIEN,0)),"^",12))
F I="I","O","A","B","V" S:+$P(USAGE,I,2)>0 FIELD(1)=FIELD(1)_I
S:$P($G(^PS(50.7,PSJSPIEN,0)),"^",9) FIELD(1)=FIELD(1)_"S"
S:$P($G(^PS(50.7,PSJSPIEN,0)),"^",10) FIELD(1)=FIELD(1)_"N"
S:$P($G(^PS(50.7,PSJSPIEN,0)),"^",12) FIELD(2)=1
D SEGMENT^PSSHLU(LIMIT)
Q
;
ZSY ; get SYNONYMs
S LIMIT=2 X PSJCLEAR
S FIELD(0)="ZSY"
S SYNONYM="",(J,SYNIEN)=0 F S SYNIEN=$O(^PS(50.7,PSJSPIEN,2,SYNIEN)) Q:'SYNIEN S SYNONYM=$P($G(^(SYNIEN,0)),"^") Q:SYNONYM="" D
.S FIELD(1)="1",FIELD(2)=SYNONYM D SEGMENT^PSSHLU(LIMIT)
Q
PRO ;Check for protocols
S MENU="PS MFSEND OR",ITEM="OR ITEM RECEIVE",MENUP=$O(^ORD(101,"B",MENU,0))
S X=$O(^ORD(101,"B",ITEM,0)) I 'X W !!?5,"Sorry, you need the OR ITEM RECEIVE protocol to proceed,",!?5,"which is exported with Order Entry/Results Reporting V3!",! S XPDABORT=1 Q
Q:$D(^ORD(101,MENUP,10,"B",X))
I $D(^ORD(101,MENUP,10,0))[0 S ^ORD(101,MENUP,10,0)="^"_"101.01PA"
K DD,DA,DO,DIC S DIC="^ORD(101,"_MENUP_",10,",DIC(0)="L",DLAYGO=101.01,DA(1)=MENUP D FILE^DICN K DD,DO
K DIC I Y<0 W !!?5,"Sorry, unable to add OR ITEM RECEIVE protocol as an Item to the PS MFSEND",!,"protocol, cannot proceed!",! S XPDABORT=1
Q
ENIVID ; Edit IV Identifier field to be displayed with IV Orderable Items.
Q
N DA,DIC,DIE,DRG,PSSOI,PSSIVID,PSSFIL,PSSDRG,X,Y
S DIC=59.7,DIC(0)="AEMQ" D ^DIC Q:Y<0
W !!!,"Changing the IV Identifier will update the name of ALL Orderable Items",!,"marked as an IV!",!!
S PSSIVID=$P($G(^PS(59.7,+Y,31)),U,2),DIE=59.7,(DA,PSSSITE)=+Y,DR=32 D ^DIE
Q:PSSIVID=$P($G(^PS(59.7,PSSSITE,31)),U,2)
W !!,"Updating Orderable Item names in OE/RR"
F PSSOI=0:0 S PSSOI=$O(^PS(50.7,"AIV",1,PSSOI)) Q:'PSSOI D:$D(^PS(50.7,PSSOI)) EN2^PSSHL1(PSSOI,"MUP") W "."
;F PSSFIL=52.6,52.7 F PSSOI=0:0 S PSSOI=$O(^PS(PSSFIL,"AOI",PSSOI)) Q:'PSSOI D:$D(^PS(50.7,PSSOI)) EN2^PSSHL1(PSSOI,"MUP") W "."
Q
;
GTIVID() ; Return IV Identifier. If being edited, wait until edit is done.
N X,PX S (X,PX)=$O(^PS(59.7,0)) Q:'X
F L +^PS(59.7,X,31):$S($G(DILOCKTM)>0:DILOCKTM,1:3) Q:$T H 2
S X=$P($G(^PS(59.7,X,31)),U,2)
L -^PS(59.7,PX,31)
Q X
PSSHL1 ;BIR/RLW/WRT-BUILD HL7 MESSAGE TO POPULATE ORDERABLE ITEM FILE ;09/08/97
+1 ;;1.0;PHARMACY DATA MANAGEMENT;**38,68,125**;9/30/97;Build 2
+2 ;External reference to ORD(101 supported by DBIA 872
+3 ; PSJEC=event code from HL7 table 8.4.2.1
+4 ; PSJSPIEN=ien to super-primary drug file (#50.7)
+5 ; SPDNAME=.01 field (name) of super-primary drug
+6 ; LIMIT=number of fields in HL7 segment being built
+7 ;
+8 WRITE !!?3,"This routine should not be accessed through programmer mode!",!
+9 QUIT
EN1 ; start here for pre-install auto load
+1 NEW MENU,MENUP,ITEM
+2 DO PRO
IF $GET(XPDABORT)
QUIT
+3 SET PSSMFU=+$ORDER(^PS(59.7,0))
IF $PIECE(^PS(59.7,PSSMFU,80),"^",2)=4
KILL PSSMFU
QUIT
+4 NEW APPL,CODE,FIELD,LIMIT,MFE,PSJI,SEGMENT,SPDNAME,SYN,SYNONYM,USAGE,X
+5 IF '$DATA(^XTMP("PSO_V7 INSTALL",0))
SET X1=DT
SET X2=+7
DO C^%DTC
SET ^XTMP("PSO_V7 INSTALL",0)=DT_"^"_X_"^OUTPATIENT V7 KIDS INSTALL"
LOCK +^XTMP("PSO_V7 INSTALL",0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
GOTO SKIP
+6 FOR
IF '$DATA(^XTMP("PSO_V7 INSTALL",0))
QUIT
LOCK +^XTMP("PSO_V7 INSTALL",0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
IF $TEST
QUIT
+7 IF '$DATA(^XTMP("PSO_V7 INSTALL",0))
SET X1=DT
SET X2=+7
DO C^%DTC
SET ^XTMP("PSO_V7 INSTALL",0)=DT_"^"_X_"^OUTPATIENT V7 KIDS INSTALL"
LOCK +^XTMP("PSO_V7 INSTALL",0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
+8 IF $PIECE(^PS(59.7,PSSMFU,80),"^",2)=4
LOCK -^XTMP("PSO_V7 INSTALL",0)
KILL ^XTMP("PSO_V7 INSTALL",0)
QUIT
SKIP ;
+1 SET PSJEC="MAD"
SET CODE="REP"
+2 DO INIT
+3 DO LOOP
DO MF^PSSHLU(PSJI)
+4 SET PSLSITE=+$ORDER(^PS(59.7,0))
SET $PIECE(^PS(59.7,PSLSITE,80),"^",2)=4
KILL PSLSITE
+5 LOCK -^XTMP("PSO_V7 INSTALL",0)
KILL ^XTMP("PSO_V7 INSTALL",0)
+6 KILL ^TMP("HLS",$JOB,"PS"),PSJEC,PSJSPIEN,PSJCLEAR,PSSMFU
QUIT
+7 ;
EN2(PSJSPIEN,PSJEC) ; start here for "manual" update
+1 SET PSLSITE=+$ORDER(^PS(59.7,0))
IF +$PIECE($GET(^PS(59.7,PSLSITE,80)),"^",2)<4
KILL PSLSITE
QUIT
+2 ; passed in: internal entry # of super-primary drug, entry code
+3 IF '$PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",4)
SET PSJEC="MAC"
+4 KILL PSLSITE
NEW APPL,CODE,FIELD,PSJI,LIMIT,MFE,SEGMENT,SPDNAME,SYN,SYNONYM,USAGE,X,ZCOUNT,ZUSAGE
+5 SET CODE="UPD"
+6 DO INIT
+7 DO MFE(PSSIVID)
DO MF^PSSHLU(PSJI)
+8 KILL ^TMP("HLS",$JOB,"PS")
+9 QUIT
+10 ;
+11 ;
INIT ; initialize HL7 variables, set master file identification segment fields
+1 SET PSJI=0
SET LIMIT=6
SET HLMTN="MFN"
SET PSSIVID=$$GTIVID()
+2 DO INIT^PSSHLU
XECUTE PSJCLEAR
+3 SET FIELD(0)="MFI"
+4 SET FIELD(1)="50.7^PHARMACY ORDERABLE ITEM^99DD"
+5 SET FIELD(3)=CODE
+6 SET FIELD(6)="NE"
+7 DO SEGMENT^PSSHLU(LIMIT)
+8 QUIT
+9 ;
LOOP ; loop through PHARMACY ORDERABLE ITEM file
+1 ;F L +^PS(59.7,PSSIVID,31) Q:$T H 1
+2 SET PSJSPIEN=0
FOR
SET PSJSPIEN=$ORDER(^PS(50.7,PSJSPIEN))
IF 'PSJSPIEN
QUIT
DO MFE(PSSIVID)
+3 ;L -^PS(59.7,PSSIVID,31)
+4 QUIT
+5 ;
MFE(PSSIVID) ; set master file entry segment fields
+1 ; Input: PSSIVID-IV Identifier
+2 SET LIMIT=4
XECUTE PSJCLEAR
+3 SET X=$GET(^PS(50.7,PSJSPIEN,0))
+4 SET FIELD(0)="MFE"
+5 SET FIELD(1)=PSJEC
+6 SET FIELD(3)=$PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",4)
IF FIELD(3)
SET FIELD(3)=$$HLDATE^HLFNC(FIELD(3))
+7 SET FIELD(4)="^^^"_PSJSPIEN_"^"_$PIECE(X,"^")_"~"_$PIECE($GET(^PS(50.606,$PIECE(X,"^",2),0)),"^")_"~"_$SELECT($PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",3):$GET(PSSIVID),1:"")_"^99PSP"
+8 DO SEGMENT^PSSHLU(LIMIT)
+9 DO ZPS
DO ZSY
+10 QUIT
+11 ;
ZPS ; get USAGE from dispense drug(s), set ZPS segment
+1 SET LIMIT=2
XECUTE PSJCLEAR
+2 SET FIELD(0)="ZPS"
+3 SET USAGE=$$USAGE^PSSHLU(PSJSPIEN)
+4 IF USAGE=""&('$PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",9))&('$PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",12))
QUIT
+5 FOR I="I","O","A","B","V"
IF +$PIECE(USAGE,I,2)>0
SET FIELD(1)=FIELD(1)_I
+6 IF $PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",9)
SET FIELD(1)=FIELD(1)_"S"
+7 IF $PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",10)
SET FIELD(1)=FIELD(1)_"N"
+8 IF $PIECE($GET(^PS(50.7,PSJSPIEN,0)),"^",12)
SET FIELD(2)=1
+9 DO SEGMENT^PSSHLU(LIMIT)
+10 QUIT
+11 ;
ZSY ; get SYNONYMs
+1 SET LIMIT=2
XECUTE PSJCLEAR
+2 SET FIELD(0)="ZSY"
+3 SET SYNONYM=""
SET (J,SYNIEN)=0
FOR
SET SYNIEN=$ORDER(^PS(50.7,PSJSPIEN,2,SYNIEN))
IF 'SYNIEN
QUIT
SET SYNONYM=$PIECE($GET(^(SYNIEN,0)),"^")
IF SYNONYM=""
QUIT
Begin DoDot:1
+4 SET FIELD(1)="1"
SET FIELD(2)=SYNONYM
DO SEGMENT^PSSHLU(LIMIT)
End DoDot:1
+5 QUIT
PRO ;Check for protocols
+1 SET MENU="PS MFSEND OR"
SET ITEM="OR ITEM RECEIVE"
SET MENUP=$ORDER(^ORD(101,"B",MENU,0))
+2 SET X=$ORDER(^ORD(101,"B",ITEM,0))
IF 'X
WRITE !!?5,"Sorry, you need the OR ITEM RECEIVE protocol to proceed,",!?5,"which is exported with Order Entry/Results Reporting V3!",!
SET XPDABORT=1
QUIT
+3 IF $DATA(^ORD(101,MENUP,10,"B",X))
QUIT
+4 IF $DATA(^ORD(101,MENUP,10,0))[0
SET ^ORD(101,MENUP,10,0)="^"_"101.01PA"
+5 KILL DD,DA,DO,DIC
SET DIC="^ORD(101,"_MENUP_",10,"
SET DIC(0)="L"
SET DLAYGO=101.01
SET DA(1)=MENUP
DO FILE^DICN
KILL DD,DO
+6 KILL DIC
IF Y<0
WRITE !!?5,"Sorry, unable to add OR ITEM RECEIVE protocol as an Item to the PS MFSEND",!,"protocol, cannot proceed!",!
SET XPDABORT=1
+7 QUIT
ENIVID ; Edit IV Identifier field to be displayed with IV Orderable Items.
+1 QUIT
+2 NEW DA,DIC,DIE,DRG,PSSOI,PSSIVID,PSSFIL,PSSDRG,X,Y
+3 SET DIC=59.7
SET DIC(0)="AEMQ"
DO ^DIC
IF Y<0
QUIT
+4 WRITE !!!,"Changing the IV Identifier will update the name of ALL Orderable Items",!,"marked as an IV!",!!
+5 SET PSSIVID=$PIECE($GET(^PS(59.7,+Y,31)),U,2)
SET DIE=59.7
SET (DA,PSSSITE)=+Y
SET DR=32
DO ^DIE
+6 IF PSSIVID=$PIECE($GET(^PS(59.7,PSSSITE,31)),U,2)
QUIT
+7 WRITE !!,"Updating Orderable Item names in OE/RR"
+8 FOR PSSOI=0:0
SET PSSOI=$ORDER(^PS(50.7,"AIV",1,PSSOI))
IF 'PSSOI
QUIT
IF $DATA(^PS(50.7,PSSOI))
DO EN2^PSSHL1(PSSOI,"MUP")
WRITE "."
+9 ;F PSSFIL=52.6,52.7 F PSSOI=0:0 S PSSOI=$O(^PS(PSSFIL,"AOI",PSSOI)) Q:'PSSOI D:$D(^PS(50.7,PSSOI)) EN2^PSSHL1(PSSOI,"MUP") W "."
+10 QUIT
+11 ;
GTIVID() ; Return IV Identifier. If being edited, wait until edit is done.
+1 NEW X,PX
SET (X,PX)=$ORDER(^PS(59.7,0))
IF 'X
QUIT
+2 FOR
LOCK +^PS(59.7,X,31):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
IF $TEST
QUIT
HANG 2
+3 SET X=$PIECE($GET(^PS(59.7,X,31)),U,2)
+4 LOCK -^PS(59.7,PX,31)
+5 QUIT X