BTPWLOCK ;VNGT/HS/ALA-Locking Routine for CMET ; 31 Dec 2009 10:11 AM
;;1.0;CARE MANAGEMENT EVENT TRACKING;;Feb 07, 2011
;
LOCK(DATA,DFN,TYPE,CMIEN) ; EP - BTPW LOCK CMET RECORD
; Input
; DFN - Patient IEN
; TYPE - T=Tracked, Q=Queued
; CMIEN - Record IEN
; Output:
; DATA = name of global (passed by reference) in which the data is stored
;
; RESULT = 1 if the lock succeeded
; = 0 if the lock failed
; = -1 if problem identified with file 90507 (shouldn't happen)
; USER = DUZ of the last user to successfully lock this panel
; or
; BMXSEC - if M error encountered
;
NEW UID,X,II,MSG,VAL,RESULT
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BTPWLCK",UID))
K @DATA
;
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWLOCK D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
;
; Create header record
S II=0,@DATA@(II)="I00010RESULT^T00080MESSAGE"_$C(30)
;
S VAL=$$VAL(TYPE,CMIEN),MSG=$P(VAL,U,2),VAL=$P(VAL,U)
I VAL=-1 S RESULT=-1 D SET Q
;
NEW USER
; Attempt lock and set RESULT accordingly
S RESULT=1
I TYPE="T" L +^BTPWP(CMIEN):1 E S RESULT=0
I TYPE="Q" L +^BTPWQ(CMIEN):1 E S RESULT=0
;
; If lock is unsuccessful, get 'LAST LOCKED BY' from the panel.
I RESULT=0 D
. S USER=$G(^XTMP("BTPWLCK",TYPE,CMIEN))
. S NAME=$$GET1^DIQ(200,USER,.01,"E")
. I NAME="" S NAME="an unknown user"
. S MSG="This event is locked for editing by "_NAME_"."
; If lock is successful, update 'LAST LOCKED BY' in ^XTMP.
I RESULT=1 D
. S ^XTMP("BTPWLCK",0)=$$FMADD^XLFDT(DT,1)_U_$$DT^XLFDT()_U_"Maintain locked by information for current locks of CMET data"
. S ^XTMP("BTPWLCK",TYPE,CMIEN)=DUZ
;
D SET
Q
;
UNLOCK(DATA,DFN,TYPE,CMIEN) ; EP - BTPW UNLOCK CMET RECORD
; Input
; DFN - Patient IEN
; TYPE - T=Tracked, Q=Queued
; CMIEN - Record IEN
; Output:
; DATA = name of global (passed by reference) in which the data is stored
; RESULT = 1 (unlock will always succeed)
; RESULT = -1 if problem identified with file 90507 (shouldn't happen)
; or
; BMXSEC - if M error encountered
;
NEW UID,X,II,MSG,VAL
S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
S DATA=$NA(^TMP("BTPWLCK",UID))
K @DATA
;
NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BTPWLOCK D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
;
; Create header record
S II=0,@DATA@(II)="I00010RESULT^T00080MESSAGE"_$C(30)
NEW RESULT,USER
S VAL=$$VAL(TYPE,CMIEN),MSG=$P(VAL,U,2),VAL=$P(VAL,U)
I VAL=-1 S RESULT=-1 D SET Q
;
; Unlock and set RESULT
D UNL(TYPE,CMIEN)
S RESULT=1
D SET
Q
;
SET ; Report results
S II=II+1,@DATA@(II)=RESULT_"^"_$G(MSG)_$C(30)
S II=II+1,@DATA@(II)=$C(31)
Q
;
ERR ;
D ^%ZTER
NEW Y,ERRDTM
S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
S BMXSEC="Recording that an error occurred at "_ERRDTM
I $D(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
Q
;
VAL(TYPE,IEN) ;EP - Validate RECORD ien
I IEN="" Q "-1^Invalid CMET record selected"
I TYPE="" Q "-1^Invalid CMET event selected"
I TYPE="T",'$D(^BTPWP(IEN)) Q "-1^Tracked Event does not exist"
I TYPE="Q",'$D(^BTPWQ(IEN)) Q "-1^Queued Event does not exist"
Q 1
;
UNL(TYPE,CMIEN) ; EP
; Get 'LAST LOCKED BY'.
S USER=$G(^XTMP("BTPWLCK",TYPE,CMIEN))
;
; If 'LAST LOCKED BY' is this DUZ then delete the lock entry from ^XTMP.
I USER=DUZ K ^XTMP("BTPWLCK",TYPE,CMIEN)
I TYPE="T" L -^BTPWP(CMIEN)
I TYPE="Q" L -^BTPWQ(CMIEN)
Q
BTPWLOCK ;VNGT/HS/ALA-Locking Routine for CMET ; 31 Dec 2009 10:11 AM
+1 ;;1.0;CARE MANAGEMENT EVENT TRACKING;;Feb 07, 2011
+2 ;
LOCK(DATA,DFN,TYPE,CMIEN) ; EP - BTPW LOCK CMET RECORD
+1 ; Input
+2 ; DFN - Patient IEN
+3 ; TYPE - T=Tracked, Q=Queued
+4 ; CMIEN - Record IEN
+5 ; Output:
+6 ; DATA = name of global (passed by reference) in which the data is stored
+7 ;
+8 ; RESULT = 1 if the lock succeeded
+9 ; = 0 if the lock failed
+10 ; = -1 if problem identified with file 90507 (shouldn't happen)
+11 ; USER = DUZ of the last user to successfully lock this panel
+12 ; or
+13 ; BMXSEC - if M error encountered
+14 ;
+15 NEW UID,X,II,MSG,VAL,RESULT
+16 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+17 SET DATA=$NAME(^TMP("BTPWLCK",UID))
+18 KILL @DATA
+19 ;
+20 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BTPWLOCK D UNWIND^%ZTER"
+21 ;
+22 ; Create header record
+23 SET II=0
SET @DATA@(II)="I00010RESULT^T00080MESSAGE"_$CHAR(30)
+24 ;
+25 SET VAL=$$VAL(TYPE,CMIEN)
SET MSG=$PIECE(VAL,U,2)
SET VAL=$PIECE(VAL,U)
+26 IF VAL=-1
SET RESULT=-1
DO SET
QUIT
+27 ;
+28 NEW USER
+29 ; Attempt lock and set RESULT accordingly
+30 SET RESULT=1
+31 IF TYPE="T"
LOCK +^BTPWP(CMIEN):1
IF '$TEST
SET RESULT=0
+32 IF TYPE="Q"
LOCK +^BTPWQ(CMIEN):1
IF '$TEST
SET RESULT=0
+33 ;
+34 ; If lock is unsuccessful, get 'LAST LOCKED BY' from the panel.
+35 IF RESULT=0
Begin DoDot:1
+36 SET USER=$GET(^XTMP("BTPWLCK",TYPE,CMIEN))
+37 SET NAME=$$GET1^DIQ(200,USER,.01,"E")
+38 IF NAME=""
SET NAME="an unknown user"
+39 SET MSG="This event is locked for editing by "_NAME_"."
End DoDot:1
+40 ; If lock is successful, update 'LAST LOCKED BY' in ^XTMP.
+41 IF RESULT=1
Begin DoDot:1
+42 SET ^XTMP("BTPWLCK",0)=$$FMADD^XLFDT(DT,1)_U_$$DT^XLFDT()_U_"Maintain locked by information for current locks of CMET data"
+43 SET ^XTMP("BTPWLCK",TYPE,CMIEN)=DUZ
End DoDot:1
+44 ;
+45 DO SET
+46 QUIT
+47 ;
UNLOCK(DATA,DFN,TYPE,CMIEN) ; EP - BTPW UNLOCK CMET RECORD
+1 ; Input
+2 ; DFN - Patient IEN
+3 ; TYPE - T=Tracked, Q=Queued
+4 ; CMIEN - Record IEN
+5 ; Output:
+6 ; DATA = name of global (passed by reference) in which the data is stored
+7 ; RESULT = 1 (unlock will always succeed)
+8 ; RESULT = -1 if problem identified with file 90507 (shouldn't happen)
+9 ; or
+10 ; BMXSEC - if M error encountered
+11 ;
+12 NEW UID,X,II,MSG,VAL
+13 SET UID=$SELECT($GET(ZTSK):"Z"_ZTSK,1:$JOB)
+14 SET DATA=$NAME(^TMP("BTPWLCK",UID))
+15 KILL @DATA
+16 ;
+17 ; SAC 2006 2.2.3.3.2
NEW $ESTACK,$ETRAP
SET $ETRAP="D ERR^BTPWLOCK D UNWIND^%ZTER"
+18 ;
+19 ; Create header record
+20 SET II=0
SET @DATA@(II)="I00010RESULT^T00080MESSAGE"_$CHAR(30)
+21 NEW RESULT,USER
+22 SET VAL=$$VAL(TYPE,CMIEN)
SET MSG=$PIECE(VAL,U,2)
SET VAL=$PIECE(VAL,U)
+23 IF VAL=-1
SET RESULT=-1
DO SET
QUIT
+24 ;
+25 ; Unlock and set RESULT
+26 DO UNL(TYPE,CMIEN)
+27 SET RESULT=1
+28 DO SET
+29 QUIT
+30 ;
SET ; Report results
+1 SET II=II+1
SET @DATA@(II)=RESULT_"^"_$GET(MSG)_$CHAR(30)
+2 SET II=II+1
SET @DATA@(II)=$CHAR(31)
+3 QUIT
+4 ;
ERR ;
+1 DO ^%ZTER
+2 NEW Y,ERRDTM
+3 SET Y=$$NOW^XLFDT()
XECUTE ^DD("DD")
SET ERRDTM=Y
+4 SET BMXSEC="Recording that an error occurred at "_ERRDTM
+5 IF $DATA(II)
IF $DATA(DATA)
SET II=II+1
SET @DATA@(II)=$CHAR(31)
+6 QUIT
+7 ;
VAL(TYPE,IEN) ;EP - Validate RECORD ien
+1 IF IEN=""
QUIT "-1^Invalid CMET record selected"
+2 IF TYPE=""
QUIT "-1^Invalid CMET event selected"
+3 IF TYPE="T"
IF '$DATA(^BTPWP(IEN))
QUIT "-1^Tracked Event does not exist"
+4 IF TYPE="Q"
IF '$DATA(^BTPWQ(IEN))
QUIT "-1^Queued Event does not exist"
+5 QUIT 1
+6 ;
UNL(TYPE,CMIEN) ; EP
+1 ; Get 'LAST LOCKED BY'.
+2 SET USER=$GET(^XTMP("BTPWLCK",TYPE,CMIEN))
+3 ;
+4 ; If 'LAST LOCKED BY' is this DUZ then delete the lock entry from ^XTMP.
+5 IF USER=DUZ
KILL ^XTMP("BTPWLCK",TYPE,CMIEN)
+6 IF TYPE="T"
LOCK -^BTPWP(CMIEN)
+7 IF TYPE="Q"
LOCK -^BTPWQ(CMIEN)
+8 QUIT