PSBVAR ;BIRMINGHAM/EFC-BCMA VARIANCE LOG FUNCTIONS ;Mar 2004
;;3.0;BAR CODE MED ADMIN;*31*;Mar 2004;Build 1
;Per VHA Directive 2004-038, this routine should not be modified.
;
; Reference/IA
; ^DPT/10035
; ^DIC(42/10039
;
EN ;
Q
;
CHKPRN(DFN,PSBMIN,PSBLOG) ;
Q:PSBMIN=""
Q:PSBMIN'>$$GET^XPAR("DIV","PSB ADMIN PRN EFFECT")
D ADD(.RESULTS,DFN,3,PSBMIN,"",PSBLOG)
Q
;
;CHECK^PSBVAR() calling point is used to create a new variance entry. Triggered by Order Administration Variance Field # 14 in the BCMA Medication Log File (#53.79).
;
CHECK(DFN,PSBMIN,PSBLOG) ;
Q:PSBMIN=""
N RESULTS
; Checks the timing from the Med Log Entry X-Ref
I PSBMIN<0 D:(PSBMIN*-1)>$$GET^XPAR("DIV","PSB ADMIN BEFORE") ADD(.RESULTS,DFN,2,PSBMIN,"",PSBLOG)
I PSBMIN>0 D:PSBMIN>$$GET^XPAR("DIV","PSB ADMIN AFTER") ADD(.RESULTS,DFN,2,PSBMIN,"",PSBLOG)
Q
;
ADD(RESULTS,DFN,PSBEVNT,PSBMIN,PSBDRUG,PSBLOG) ;
;
; DFN: Patient File (#2) Pointer
; PSBEVNT: Event Code (See DD for 53.78)
; PSBMIN: Minutes off of schedule (Optional)
; PSBDRUG: Drug File (#50) Pointer (Optional)
; PSBLOG: BCMA Med Log IEN (Optional)
;
;Do not create variance for med order with missing dose status.
I $G(PSBLOG),$P($G(^PSB(53.79,PSBLOG,0)),U,9)="M" Q
;
N PSBDT,PSBRB,PSBWRD,PSBXX
;
D EN^DDIOL("Filing Variance...")
D NOW^%DTC
L +(^PSB(53.78,0)):5 E S RESULTS(0)="-1^Variance Log Locked" Q
S PSBXX=$O(^PSB(53.78,"A"),-1)+1
S $P(^PSB(53.78,0),U,3)=PSBXX
S $P(^PSB(53.78,0),U,4)=$P(^PSB(53.78,0),U,4)+1
;
WARD ;Extract the ward and room/bed information.
;DFN is pre-defined.
S PSBRB=$P($G(^DPT(DFN,.101)),U)
S PSBRB=$S(PSBRB'="":PSBRB,1:"***")
S PSBWRD=$P($G(^DPT(DFN,.1)),U)
;Convert Ward Name to Ward IEN
I PSBWRD'="" D
. S PSBDT=%
. S PSBWRD=$$FIND1^DIC(42,"","X",PSBWRD,"","","ERR")
. S %=PSBDT ;reset after $$FIND1^DIC fileman call
S PSBWRD=$S($G(PSBWRD):PSBWRD,1:"***")
;
; Set Variance Entry
S ^PSB(53.78,PSBXX,0)=DFN_U_PSBRB_U_DUZ_U_%_U_PSBEVNT_U_$G(PSBMIN)_U_$G(PSBDRUG)_U_$G(PSBLOG)_U_PSBWRD
;
S ^PSB(53.78,"ADT",%,PSBXX)=""
S ^PSB(53.78,"B",DFN,PSBXX)=""
L -(^PSB(53.78,0))
S RESULTS(0)="1^Data Filed"
Q
;
; Unable to UPDATE^DIE WHILE IN UPDATE^DIE
W !,"Filing Variance..."
D EN^DDIOL("Filing Variance...")
N PSBVFDA,PSBVMSG,PSBVIEN
D VAL(.01,"`"_DFN) ; Patient Pointer
S Y=$G(^DPT(DFN,.1),"Unk Ward")_" "_$G(^DPT(DFN,.101),"Unk Bed")
D VAL(.02,Y) ; Patient Location
D VAL(.03,"`"_DUZ) ; New Person Pointer
D VAL(.04,"NOW") ; DT Entered
D VAL(.05,PSBEVNT) ; Event Code
D:$G(PSBMIN) VAL(.06,PSBMIN) ; Minutes Early/Late
D:$G(PSBDRUG) VAL(.07,"`"_PSBDRUG) ; Drug File Pointer
D:$G(PSBLOG) VAL(.08,"`"_PSBLOG)
; Call UPDATE^DIE and set Results(0)
D UPDATE^DIE("","PSBVFDA","PSBVIEN","PSBVMSG") ; PSBVFDA set into file 53.68, BCMA MEDICATION VARIANCE LOG at VAL+3
I $D(PSBVMSG) S RESULTS(0)="-1^"_PSBVMSG("DIERR",1)_": "_PSBVMSG("DIERR",1,"TEXT",1)
E S RESULTS(0)="1^Data Successfully Filed^"_PSBVIEN(1)
W !,RESULTS(0)
Q
;
VAL(PSBVFLD,PSBVVAL) ;
N PSBVRET
K ^TMP("DIERR",$J)
D VAL^DIE(53.78,"+1,",PSBVFLD,"F",PSBVVAL,.PSBVRET,"PSBVFDA")
I PSBVRET="^" F X=0:0 S X=$O(^TMP("DIERR",$J,X)) Q:'X S Y=^TMP("DIERR",$J,X)_": "_$G(^(X,"TEXT",1),"**"),RESULTS($O(RESULTS(""),-1)+1)="Data Validation Error: "_Y
K ^TMP("DIERR",$J)
Q
;
PSBVAR ;BIRMINGHAM/EFC-BCMA VARIANCE LOG FUNCTIONS ;Mar 2004
+1 ;;3.0;BAR CODE MED ADMIN;*31*;Mar 2004;Build 1
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 ; Reference/IA
+5 ; ^DPT/10035
+6 ; ^DIC(42/10039
+7 ;
EN ;
+1 QUIT
+2 ;
CHKPRN(DFN,PSBMIN,PSBLOG) ;
+1 IF PSBMIN=""
QUIT
+2 IF PSBMIN'>$$GET^XPAR("DIV","PSB ADMIN PRN EFFECT")
QUIT
+3 DO ADD(.RESULTS,DFN,3,PSBMIN,"",PSBLOG)
+4 QUIT
+5 ;
+6 ;CHECK^PSBVAR() calling point is used to create a new variance entry. Triggered by Order Administration Variance Field # 14 in the BCMA Medication Log File (#53.79).
+7 ;
CHECK(DFN,PSBMIN,PSBLOG) ;
+1 IF PSBMIN=""
QUIT
+2 NEW RESULTS
+3 ; Checks the timing from the Med Log Entry X-Ref
+4 IF PSBMIN<0
IF (PSBMIN*-1)>$$GET^XPAR("DIV","PSB ADMIN BEFORE")
DO ADD(.RESULTS,DFN,2,PSBMIN,"",PSBLOG)
+5 IF PSBMIN>0
IF PSBMIN>$$GET^XPAR("DIV","PSB ADMIN AFTER")
DO ADD(.RESULTS,DFN,2,PSBMIN,"",PSBLOG)
+6 QUIT
+7 ;
ADD(RESULTS,DFN,PSBEVNT,PSBMIN,PSBDRUG,PSBLOG) ;
+1 ;
+2 ; DFN: Patient File (#2) Pointer
+3 ; PSBEVNT: Event Code (See DD for 53.78)
+4 ; PSBMIN: Minutes off of schedule (Optional)
+5 ; PSBDRUG: Drug File (#50) Pointer (Optional)
+6 ; PSBLOG: BCMA Med Log IEN (Optional)
+7 ;
+8 ;Do not create variance for med order with missing dose status.
+9 IF $GET(PSBLOG)
IF $PIECE($GET(^PSB(53.79,PSBLOG,0)),U,9)="M"
QUIT
+10 ;
+11 NEW PSBDT,PSBRB,PSBWRD,PSBXX
+12 ;
+13 DO EN^DDIOL("Filing Variance...")
+14 DO NOW^%DTC
+15 LOCK +(^PSB(53.78,0)):5
IF '$TEST
SET RESULTS(0)="-1^Variance Log Locked"
QUIT
+16 SET PSBXX=$ORDER(^PSB(53.78,"A"),-1)+1
+17 SET $PIECE(^PSB(53.78,0),U,3)=PSBXX
+18 SET $PIECE(^PSB(53.78,0),U,4)=$PIECE(^PSB(53.78,0),U,4)+1
+19 ;
WARD ;Extract the ward and room/bed information.
+1 ;DFN is pre-defined.
+2 SET PSBRB=$PIECE($GET(^DPT(DFN,.101)),U)
+3 SET PSBRB=$SELECT(PSBRB'="":PSBRB,1:"***")
+4 SET PSBWRD=$PIECE($GET(^DPT(DFN,.1)),U)
+5 ;Convert Ward Name to Ward IEN
+6 IF PSBWRD'=""
Begin DoDot:1
+7 SET PSBDT=%
+8 SET PSBWRD=$$FIND1^DIC(42,"","X",PSBWRD,"","","ERR")
+9 ;reset after $$FIND1^DIC fileman call
SET %=PSBDT
End DoDot:1
+10 SET PSBWRD=$SELECT($GET(PSBWRD):PSBWRD,1:"***")
+11 ;
+12 ; Set Variance Entry
+13 SET ^PSB(53.78,PSBXX,0)=DFN_U_PSBRB_U_DUZ_U_%_U_PSBEVNT_U_$GET(PSBMIN)_U_$GET(PSBDRUG)_U_$GET(PSBLOG)_U_PSBWRD
+14 ;
+15 SET ^PSB(53.78,"ADT",%,PSBXX)=""
+16 SET ^PSB(53.78,"B",DFN,PSBXX)=""
+17 LOCK -(^PSB(53.78,0))
+18 SET RESULTS(0)="1^Data Filed"
+19 QUIT
+20 ;
+21 ; Unable to UPDATE^DIE WHILE IN UPDATE^DIE
+22 WRITE !,"Filing Variance..."
+23 DO EN^DDIOL("Filing Variance...")
+24 NEW PSBVFDA,PSBVMSG,PSBVIEN
+25 ; Patient Pointer
DO VAL(.01,"`"_DFN)
+26 SET Y=$GET(^DPT(DFN,.1),"Unk Ward")_" "_$GET(^DPT(DFN,.101),"Unk Bed")
+27 ; Patient Location
DO VAL(.02,Y)
+28 ; New Person Pointer
DO VAL(.03,"`"_DUZ)
+29 ; DT Entered
DO VAL(.04,"NOW")
+30 ; Event Code
DO VAL(.05,PSBEVNT)
+31 ; Minutes Early/Late
IF $GET(PSBMIN)
DO VAL(.06,PSBMIN)
+32 ; Drug File Pointer
IF $GET(PSBDRUG)
DO VAL(.07,"`"_PSBDRUG)
+33 IF $GET(PSBLOG)
DO VAL(.08,"`"_PSBLOG)
+34 ; Call UPDATE^DIE and set Results(0)
+35 ; PSBVFDA set into file 53.68, BCMA MEDICATION VARIANCE LOG at VAL+3
DO UPDATE^DIE("","PSBVFDA","PSBVIEN","PSBVMSG")
+36 IF $DATA(PSBVMSG)
SET RESULTS(0)="-1^"_PSBVMSG("DIERR",1)_": "_PSBVMSG("DIERR",1,"TEXT",1)
+37 IF '$TEST
SET RESULTS(0)="1^Data Successfully Filed^"_PSBVIEN(1)
+38 WRITE !,RESULTS(0)
+39 QUIT
+40 ;
VAL(PSBVFLD,PSBVVAL) ;
+1 NEW PSBVRET
+2 KILL ^TMP("DIERR",$JOB)
+3 DO VAL^DIE(53.78,"+1,",PSBVFLD,"F",PSBVVAL,.PSBVRET,"PSBVFDA")
+4 IF PSBVRET="^"
FOR X=0:0
SET X=$ORDER(^TMP("DIERR",$JOB,X))
IF 'X
QUIT
SET Y=^TMP("DIERR",$JOB,X)_": "_$GET(^(X,"TEXT",1),"**")
SET RESULTS($ORDER(RESULTS(""),-1)+1)="Data Validation Error: "_Y
+5 KILL ^TMP("DIERR",$JOB)
+6 QUIT
+7 ;