PXLOCK ;SLC/PKR - PCE Locking/Unlocking utility; 09/28/2017
;;1.0;PCE PATIENT CARE ENCOUNTER;**211**;AUG 12, 1996;Build 454
;
;====================
FINDLOCK(VISITIEN,ERROR) ;Try to determine who has the lock on the
;encounter.
N MSG,SUB,USER,USERNAME
S SUB="PXLOCK:"_VISITIEN
S SUB=$O(^XTMP(SUB))
I SUB="" Q
S USER=$P(SUB,":",3),USERNAME=$$GET1^DIQ(200,USER_",",.01,"","","MSG")
I USERNAME="" S USERNAME="UNKNOWN (DUZ="_USER_")"
S ERROR("LOCK")="User "_USERNAME_" is editing this encounter."
Q
;
;====================
LOCK(VISITIEN,USER,NUMTRIES,ERROR,SOURCE) ;Lock the encounter.
I $G(VISITIEN)="" S ERROR("LOCK")="Could not get lock, Visit not specified." Q 0
I $G(USER)="" S ERROR("LOCK")="Could not get lock, User not specified." Q 0
N IND,LOCK,NOW,SUB
S SUB="PXLOCK:"_VISITIEN_":"_USER_":"_$J
;See if the encounter is already locked.
I $D(^XTMP(SUB,0)) Q 1
S (IND,LOCK)=0
F Q:(LOCK)!(IND=NUMTRIES) D
. L +^PXLOCK(VISITIEN):DILOCKTM
. I $T S LOCK=1 Q
. S IND=IND+1
I LOCK=0 D FINDLOCK(VISITIEN,.ERROR) Q 0
S NOW=$$NOW^XLFDT
S ^XTMP(SUB,0)=$$FMADD^XLFDT(NOW,1,0,0,0)_U_NOW_U_"PCE LOCKING"
I $G(SOURCE)'="" S ^XTMP(SUB,"SOURCE")=SOURCE
Q 1
;
;====================
PXCEAE(VISITIEN,USER,NUMTRIES) ;Locking for PXCEAE.
N DONE,ERROR,INPUT,LOCK,START
S LOCK=$$LOCK(VISITIEN,USER,NUMTRIES,.ERROR,"PXCEAE")
I LOCK=1 Q 1
W !,"Cannot open this encounter.",!,ERROR("LOCK")
S DONE=0
W !,"Waiting for file access, press ENTER to cancel..."
S START=$$NOW^XLFDT
F Q:DONE D
. S LOCK=$$LOCK(VISITIEN,USER,NUMTRIES,.ERROR,"PXCEAE")
. I LOCK=1 S DONE=1 Q
. R INPUT:0
. I $T S DONE=1 Q
. I $$FMDIFF^XLFDT($$NOW^XLFDT,START,2)>DTIME D
.. S DONE=1
.. W !,"The maximum wait time has been exceeded."
.. H 2
Q LOCK
;
;====================
UNLOCK(VISITIEN,USER,SOURCE) ;Unlock the encounter.
N SUB
S SUB="PXLOCK:"_VISITIEN_":"_USER_":"_$J
;If a SOURCE has been stored and it does not match the input
;SOURCE do not unlock.
I $G(^XTMP(SUB,"SOURCE"))'="",$G(SOURCE)'=^XTMP(SUB,"SOURCE") Q
L -^PXLOCK(VISITIEN):DILOCKTM
I $T K ^XTMP(SUB)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPXLOCK 2145 printed Nov 22, 2024@17:39:37 Page 2
PXLOCK ;SLC/PKR - PCE Locking/Unlocking utility; 09/28/2017
+1 ;;1.0;PCE PATIENT CARE ENCOUNTER;**211**;AUG 12, 1996;Build 454
+2 ;
+3 ;====================
FINDLOCK(VISITIEN,ERROR) ;Try to determine who has the lock on the
+1 ;encounter.
+2 NEW MSG,SUB,USER,USERNAME
+3 SET SUB="PXLOCK:"_VISITIEN
+4 SET SUB=$ORDER(^XTMP(SUB))
+5 IF SUB=""
QUIT
+6 SET USER=$PIECE(SUB,":",3)
SET USERNAME=$$GET1^DIQ(200,USER_",",.01,"","","MSG")
+7 IF USERNAME=""
SET USERNAME="UNKNOWN (DUZ="_USER_")"
+8 SET ERROR("LOCK")="User "_USERNAME_" is editing this encounter."
+9 QUIT
+10 ;
+11 ;====================
LOCK(VISITIEN,USER,NUMTRIES,ERROR,SOURCE) ;Lock the encounter.
+1 IF $GET(VISITIEN)=""
SET ERROR("LOCK")="Could not get lock, Visit not specified."
QUIT 0
+2 IF $GET(USER)=""
SET ERROR("LOCK")="Could not get lock, User not specified."
QUIT 0
+3 NEW IND,LOCK,NOW,SUB
+4 SET SUB="PXLOCK:"_VISITIEN_":"_USER_":"_$JOB
+5 ;See if the encounter is already locked.
+6 IF $DATA(^XTMP(SUB,0))
QUIT 1
+7 SET (IND,LOCK)=0
+8 FOR
if (LOCK)!(IND=NUMTRIES)
QUIT
Begin DoDot:1
+9 LOCK +^PXLOCK(VISITIEN):DILOCKTM
+10 IF $TEST
SET LOCK=1
QUIT
+11 SET IND=IND+1
End DoDot:1
+12 IF LOCK=0
DO FINDLOCK(VISITIEN,.ERROR)
QUIT 0
+13 SET NOW=$$NOW^XLFDT
+14 SET ^XTMP(SUB,0)=$$FMADD^XLFDT(NOW,1,0,0,0)_U_NOW_U_"PCE LOCKING"
+15 IF $GET(SOURCE)'=""
SET ^XTMP(SUB,"SOURCE")=SOURCE
+16 QUIT 1
+17 ;
+18 ;====================
PXCEAE(VISITIEN,USER,NUMTRIES) ;Locking for PXCEAE.
+1 NEW DONE,ERROR,INPUT,LOCK,START
+2 SET LOCK=$$LOCK(VISITIEN,USER,NUMTRIES,.ERROR,"PXCEAE")
+3 IF LOCK=1
QUIT 1
+4 WRITE !,"Cannot open this encounter.",!,ERROR("LOCK")
+5 SET DONE=0
+6 WRITE !,"Waiting for file access, press ENTER to cancel..."
+7 SET START=$$NOW^XLFDT
+8 FOR
if DONE
QUIT
Begin DoDot:1
+9 SET LOCK=$$LOCK(VISITIEN,USER,NUMTRIES,.ERROR,"PXCEAE")
+10 IF LOCK=1
SET DONE=1
QUIT
+11 READ INPUT:0
+12 IF $TEST
SET DONE=1
QUIT
+13 IF $$FMDIFF^XLFDT($$NOW^XLFDT,START,2)>DTIME
Begin DoDot:2
+14 SET DONE=1
+15 WRITE !,"The maximum wait time has been exceeded."
+16 HANG 2
End DoDot:2
End DoDot:1
+17 QUIT LOCK
+18 ;
+19 ;====================
UNLOCK(VISITIEN,USER,SOURCE) ;Unlock the encounter.
+1 NEW SUB
+2 SET SUB="PXLOCK:"_VISITIEN_":"_USER_":"_$JOB
+3 ;If a SOURCE has been stored and it does not match the input
+4 ;SOURCE do not unlock.
+5 IF $GET(^XTMP(SUB,"SOURCE"))'=""
IF $GET(SOURCE)'=^XTMP(SUB,"SOURCE")
QUIT
+6 LOCK -^PXLOCK(VISITIEN):DILOCKTM
+7 IF $TEST
KILL ^XTMP(SUB)
+8 QUIT
+9 ;