BOPUVER ;IHS/ILC/DUG/CIA/PLS - Create Unverified Prescription;24-Jul-2006 22:41;SM
;;1.0;AUTOMATED DISPENSING INTERFACE;**1**;Jul 26, 2005
;
;Process entries in File 90355.44 into unverified prescriptions.
;get record number from RUN+2^BOPROC to get data from file 90355.44
;then create a record in prescription file 52 so that the pharmacist
;can verify later.
;
ENTRY(BOPDAS) ;EP
;Assume variables:
; BOPSITE - IEN to File 59
N NODE0,NODE2,NODE3,DIC,DFN,PROV,CLINIC,DIV,DRUG
N QTY,USER,SIG,HRN,VER,X,DD,DO,SIGOK,PSONEW,PSODRUG
Q:'$G(BOPDAS)
S NODE0=$G(^BOP(90355.44,BOPDAS,0)) Q:NODE0="" ;PID info
S NODE2=$G(^BOP(90355.44,BOPDAS,2)) ;Q:NODE2=""
S NODE3=$G(^BOP(90355.44,BOPDAS,3)) Q:NODE3=""
;Q:$P(NODE0,U,2)'="D" ;is not a drug
S DFN=$P(NODE0,U,4) ;Patient
S HRN=$P(NODE0,U,5) ;HRN
S PROV=+$P($P(NODE3,"|",22),U) ;provider IEN =>200
S:'$D(^VA(200,PROV,0)) PROV="" ;must be a valid user
;S:'PROV PROV=$P($G(^BOP(90355,1,"SITE")),U,7) ; Use default provider
S USER=$P($P(NODE3,"|",21),U) ;user IEN entering order
S:'USER USER=$P($G(^BOP(90355,1,"SITE")),U,8) ; Use default user
S DRUG=+$$DRGIEN^BOPROC(NODE3)
I '$D(^PSDRUG(DRUG,0)) D MAIL Q ; Drug not found
S QTY=$P(NODE3,"|",11) ;Quantity
S CLINIC=$$FIND1^DIC(44,,"O",$P($P(NODE2,"|",4),U)) ; Clinic Name
S:'CLINIC CLINIC=+$P($G(^BOP(90355,1,"SITE")),U,6)
S:'CLINIC CLINIC=""
D
.S SIG(1)=$$GET1^DIQ(90355,1,402) Q:$L(SIG(1))
.S SIG(1)=$P(^PSDRUG(DRUG,0),U,4)_" MAXIMUM DOSES PER DAY" Q:SIG(1)
.S SIG(1)="ASK PHYSICIAN FOR DOSE INSTRUCTIONS"
S SIGOK=1
S NDC=$$NDCLKP(+DRUG) ;
;
CREATE ;creating a prescription record
S PSONEW("DFLG")=0
S PSOSITE=BOPSITE
I $D(^APSPCTRL(PSOSITE,0)) S %APSITE=^(0)
D AUTO^PSONRXN
S PSOX=PSONEW("RX #")
S PSONEW("ISSUE DATE")=$P(DT,".",1)
S PSONEW("DAYS SUPPLY")=7
S PSONEW("# OF REFILLS")=0
S BOPSTPDT=""
S BOPSTPDT=$$FMADD^XLFDT(DT,7)
S PSONEW("STOP DATE")=BOPSTPDT
S PSONEW("FILL DATE")=$P(DT,".",1)
S PSONEW("CM")="N"
S PSONEW("PHARM")=PROV
S PSONEW("PROVIDER")=PROV
S PSONEW("CLINIC")=CLINIC
S PSODRUG("IEN")=DRUG
S PSONEW("QTY")=QTY
S PSODRUG("NDC")=NDC
S PSONEW("COST")=$$COST^APSQDAWP(NDC,DRUG)
S PSONEW("LAST DISPENSED DATE")=PSONEW("FILL DATE")
S PSODRUG("DEA")=$P(^PSDRUG(DRUG,0),U,3)
S PSODRUG("OI")=+^PSDRUG(DRUG,2)
S PSONEW("ENT")=0
S PSOCOU="",PSOCOUU=0,PSONOOR=""
S PSONEW("NDC")=NDC
I DFN="" S DFN=$P(NODE0,"^",5)
S (PSODFN,BOPDFN)=DFN
S PSONEW("PATIENT STATUS")=1
S PSONEW("STATUS")=1 ; field 100
S PSONEW("MAIL/WINDOW")="W"
S PSONEW("CLERK CODE")=USER
S PSONEW("DISPENSED DATE")=$P(DT,".",1)
S PSONEW("RX #")=PSONEW("RX #") ; for nfile^pson52
;S PSONEW("STOP DATE")=PSOX("STOP DATE") ; for ps55
S PSORX("VERIFY")=1 ; for anq^pson52 to create verify 52.4 entry
S PSONEW("POE")=1
D EN^PSON52(.PSONEW) ; file entry in file 52
; Returns RX IEN in PSONEW("IRXN")
S %APSITE=$G(%APSITE)
S BOPPSRX="" S BOPPSRX=$O(^PSRX("B",PSOX,BOPPSRX))
S $P(^BOP(90355.44,BOPDAS,0),U,8)=BOPPSRX
S ^BOP(90355.44,"DRUG",DFN,DRUG,BOPPSRX)=DT
; Update the CLERK field of the RX VERIFY file (52.4) to reflect
; the dispensing person and not the user associated with the interface process.
D VERIFY(+$G(PSONEW("IRXN")),USER)
K PSOX,APSPDOC1,APSRX,PSODRUG
Q
;
VERIFY(IEN,VAL) ;setting record for Rx Verify File
N FDA,MSG,TIME
Q:'$D(^PS(52.4,IEN,0))
S FDA(52.4,IEN_",",2)=VAL
D FILE^DIE(,"FDA","MSG")
Q
;
MAIL ;mail alert for bad drug entry
N XMDUZ,XMTEXT,XMY,XMSUB,XMZ,TEXT,BOPMGRP
S BOPMGRP=$$GET1^DIQ(90355,1,.06)
I BOPMGRP="" D
.S XMY(DUZ)=""
E D
.S XMY("G."_BOPMGRP)=""
S XMDUZ=USER
S TEXT(1)="An error has occurred in the Automated Dispensing Interface."
S TEXT(2)="The drug that was selected is not in the Drug file (50)"
S TEXT(3)="for patient: "_$P(^DPT(DFN,0),U)_"(Health Record #:"_HRN_")."
S TEXT(4)="Drug IEN is "_DRUG
S XMTEXT="TEXT(",XMSUB="BOP DRUG NOT ON FILE ERROR"
D ^XMD
Q
; Return NDC value from the HL7 (Omnicell) or from Drug File (Pyxis)
NDCLKP(DRUG) ;EP
;N VEND
;S VEND=$$VENDTYP^BOPROC()
;I VEND="O" Q $P(NODE3,"|",8)
;I VEND="P"
Q $P($G(^PSDRUG(+DRUG,2)),"^",4)
;Q ""
BOPUVER ;IHS/ILC/DUG/CIA/PLS - Create Unverified Prescription;24-Jul-2006 22:41;SM
+1 ;;1.0;AUTOMATED DISPENSING INTERFACE;**1**;Jul 26, 2005
+2 ;
+3 ;Process entries in File 90355.44 into unverified prescriptions.
+4 ;get record number from RUN+2^BOPROC to get data from file 90355.44
+5 ;then create a record in prescription file 52 so that the pharmacist
+6 ;can verify later.
+7 ;
ENTRY(BOPDAS) ;EP
+1 ;Assume variables:
+2 ; BOPSITE - IEN to File 59
+3 NEW NODE0,NODE2,NODE3,DIC,DFN,PROV,CLINIC,DIV,DRUG
+4 NEW QTY,USER,SIG,HRN,VER,X,DD,DO,SIGOK,PSONEW,PSODRUG
+5 IF '$GET(BOPDAS)
QUIT
+6 ;PID info
SET NODE0=$GET(^BOP(90355.44,BOPDAS,0))
IF NODE0=""
QUIT
+7 ;Q:NODE2=""
SET NODE2=$GET(^BOP(90355.44,BOPDAS,2))
+8 SET NODE3=$GET(^BOP(90355.44,BOPDAS,3))
IF NODE3=""
QUIT
+9 ;Q:$P(NODE0,U,2)'="D" ;is not a drug
+10 ;Patient
SET DFN=$PIECE(NODE0,U,4)
+11 ;HRN
SET HRN=$PIECE(NODE0,U,5)
+12 ;provider IEN =>200
SET PROV=+$PIECE($PIECE(NODE3,"|",22),U)
+13 ;must be a valid user
IF '$DATA(^VA(200,PROV,0))
SET PROV=""
+14 ;S:'PROV PROV=$P($G(^BOP(90355,1,"SITE")),U,7) ; Use default provider
+15 ;user IEN entering order
SET USER=$PIECE($PIECE(NODE3,"|",21),U)
+16 ; Use default user
IF 'USER
SET USER=$PIECE($GET(^BOP(90355,1,"SITE")),U,8)
+17 SET DRUG=+$$DRGIEN^BOPROC(NODE3)
+18 ; Drug not found
IF '$DATA(^PSDRUG(DRUG,0))
DO MAIL
QUIT
+19 ;Quantity
SET QTY=$PIECE(NODE3,"|",11)
+20 ; Clinic Name
SET CLINIC=$$FIND1^DIC(44,,"O",$PIECE($PIECE(NODE2,"|",4),U))
+21 IF 'CLINIC
SET CLINIC=+$PIECE($GET(^BOP(90355,1,"SITE")),U,6)
+22 IF 'CLINIC
SET CLINIC=""
+23 Begin DoDot:1
+24 SET SIG(1)=$$GET1^DIQ(90355,1,402)
IF $LENGTH(SIG(1))
QUIT
+25 SET SIG(1)=$PIECE(^PSDRUG(DRUG,0),U,4)_" MAXIMUM DOSES PER DAY"
IF SIG(1)
QUIT
+26 SET SIG(1)="ASK PHYSICIAN FOR DOSE INSTRUCTIONS"
End DoDot:1
+27 SET SIGOK=1
+28 ;
SET NDC=$$NDCLKP(+DRUG)
+29 ;
CREATE ;creating a prescription record
+1 SET PSONEW("DFLG")=0
+2 SET PSOSITE=BOPSITE
+3 IF $DATA(^APSPCTRL(PSOSITE,0))
SET %APSITE=^(0)
+4 DO AUTO^PSONRXN
+5 SET PSOX=PSONEW("RX #")
+6 SET PSONEW("ISSUE DATE")=$PIECE(DT,".",1)
+7 SET PSONEW("DAYS SUPPLY")=7
+8 SET PSONEW("# OF REFILLS")=0
+9 SET BOPSTPDT=""
+10 SET BOPSTPDT=$$FMADD^XLFDT(DT,7)
+11 SET PSONEW("STOP DATE")=BOPSTPDT
+12 SET PSONEW("FILL DATE")=$PIECE(DT,".",1)
+13 SET PSONEW("CM")="N"
+14 SET PSONEW("PHARM")=PROV
+15 SET PSONEW("PROVIDER")=PROV
+16 SET PSONEW("CLINIC")=CLINIC
+17 SET PSODRUG("IEN")=DRUG
+18 SET PSONEW("QTY")=QTY
+19 SET PSODRUG("NDC")=NDC
+20 SET PSONEW("COST")=$$COST^APSQDAWP(NDC,DRUG)
+21 SET PSONEW("LAST DISPENSED DATE")=PSONEW("FILL DATE")
+22 SET PSODRUG("DEA")=$PIECE(^PSDRUG(DRUG,0),U,3)
+23 SET PSODRUG("OI")=+^PSDRUG(DRUG,2)
+24 SET PSONEW("ENT")=0
+25 SET PSOCOU=""
SET PSOCOUU=0
SET PSONOOR=""
+26 SET PSONEW("NDC")=NDC
+27 IF DFN=""
SET DFN=$PIECE(NODE0,"^",5)
+28 SET (PSODFN,BOPDFN)=DFN
+29 SET PSONEW("PATIENT STATUS")=1
+30 ; field 100
SET PSONEW("STATUS")=1
+31 SET PSONEW("MAIL/WINDOW")="W"
+32 SET PSONEW("CLERK CODE")=USER
+33 SET PSONEW("DISPENSED DATE")=$PIECE(DT,".",1)
+34 ; for nfile^pson52
SET PSONEW("RX #")=PSONEW("RX #")
+35 ;S PSONEW("STOP DATE")=PSOX("STOP DATE") ; for ps55
+36 ; for anq^pson52 to create verify 52.4 entry
SET PSORX("VERIFY")=1
+37 SET PSONEW("POE")=1
+38 ; file entry in file 52
DO EN^PSON52(.PSONEW)
+39 ; Returns RX IEN in PSONEW("IRXN")
+40 SET %APSITE=$GET(%APSITE)
+41 SET BOPPSRX=""
SET BOPPSRX=$ORDER(^PSRX("B",PSOX,BOPPSRX))
+42 SET $PIECE(^BOP(90355.44,BOPDAS,0),U,8)=BOPPSRX
+43 SET ^BOP(90355.44,"DRUG",DFN,DRUG,BOPPSRX)=DT
+44 ; Update the CLERK field of the RX VERIFY file (52.4) to reflect
+45 ; the dispensing person and not the user associated with the interface process.
+46 DO VERIFY(+$GET(PSONEW("IRXN")),USER)
+47 KILL PSOX,APSPDOC1,APSRX,PSODRUG
+48 QUIT
+49 ;
VERIFY(IEN,VAL) ;setting record for Rx Verify File
+1 NEW FDA,MSG,TIME
+2 IF '$DATA(^PS(52.4,IEN,0))
QUIT
+3 SET FDA(52.4,IEN_",",2)=VAL
+4 DO FILE^DIE(,"FDA","MSG")
+5 QUIT
+6 ;
MAIL ;mail alert for bad drug entry
+1 NEW XMDUZ,XMTEXT,XMY,XMSUB,XMZ,TEXT,BOPMGRP
+2 SET BOPMGRP=$$GET1^DIQ(90355,1,.06)
+3 IF BOPMGRP=""
Begin DoDot:1
+4 SET XMY(DUZ)=""
End DoDot:1
+5 IF '$TEST
Begin DoDot:1
+6 SET XMY("G."_BOPMGRP)=""
End DoDot:1
+7 SET XMDUZ=USER
+8 SET TEXT(1)="An error has occurred in the Automated Dispensing Interface."
+9 SET TEXT(2)="The drug that was selected is not in the Drug file (50)"
+10 SET TEXT(3)="for patient: "_$PIECE(^DPT(DFN,0),U)_"(Health Record #:"_HRN_")."
+11 SET TEXT(4)="Drug IEN is "_DRUG
+12 SET XMTEXT="TEXT("
SET XMSUB="BOP DRUG NOT ON FILE ERROR"
+13 DO ^XMD
+14 QUIT
+15 ; Return NDC value from the HL7 (Omnicell) or from Drug File (Pyxis)
NDCLKP(DRUG) ;EP
+1 ;N VEND
+2 ;S VEND=$$VENDTYP^BOPROC()
+3 ;I VEND="O" Q $P(NODE3,"|",8)
+4 ;I VEND="P"
+5 QUIT $PIECE($GET(^PSDRUG(+DRUG,2)),"^",4)
+6 ;Q ""