Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BQIDCLK

BQIDCLK.m

Go to the documentation of this file.
  1. BQIDCLK ;PRXM/HC/DB-Patient Diagnostic Tag Lock/Unlock Functions ; 18 Mar 2008 4:03 PM
  1. ;;2.1;ICARE MANAGEMENT SYSTEM;;Feb 07, 2011
  1. ;
  1. Q
  1. ;
  1. LOCK(DATA,DFN,DCAT) ; EP - BQI LOCK PATIENT BY DX TAG
  1. ; Description
  1. ; Attempt to lock a patient diagnostic tag record specified by DCAT for
  1. ; exclusive editing access.
  1. ; If successful, sets 'LAST LOCKED BY' with the current DUZ
  1. ; and returns a RESULT of 1 and the current DUZ.
  1. ; If unsuccessful, returns a RESULT of 0 and the DUZ from the
  1. ; 'LAST LOCKED BY' field.
  1. ; Input:
  1. ; DFN - Patient IEN
  1. ; DCAT - Diagnostic tag defined in ^BQI(90506.2
  1. ;
  1. ; Output:
  1. ; DATA = name of global (passed by reference) in which the data is stored
  1. ;
  1. ; RESULT = 1 if the lock succeeded
  1. ; = 0 if the lock failed
  1. ; = -1 if problem identified with DCAT (shouldn't happen)
  1. ; USER = DUZ of the last user to successfully lock this panel
  1. ; or
  1. ; BMXSEC - if M error encountered
  1. ;
  1. N UID,X,BQII,MSG,RESULT,DCATIEN
  1. S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
  1. S DATA=$NA(^TMP("BQIDCLK",UID))
  1. K ^TMP("BQIDCLK",UID)
  1. ;
  1. NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIDCLK D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
  1. ;
  1. ; Create header record
  1. S BQII=0,@DATA@(BQII)="I00010RESULT^T00080MESSAGE"_$C(30)
  1. ;
  1. S MSG=""
  1. ; If adding register information create temporary ien for locking
  1. S DCATIEN=$O(^BQI(90506.2,"B",DCAT,"")) I DCATIEN="" D INV Q
  1. ; Subdefinitions (risk factors that are not standalone) are not valid here
  1. I $$GET1^DIQ(90506.2,DCATIEN_",",.05,"I") D INV Q
  1. ;
  1. N USER
  1. ;
  1. ; Attempt lock and set RESULT accordingly
  1. S RESULT=1
  1. L +^BQIREG(DCAT,DFN):1 E S RESULT=0
  1. ;
  1. ; If lock is unsuccessful, get 'LAST LOCKED BY' from the panel.
  1. I RESULT=0 D
  1. . S USER=$G(^XTMP("BQIDCLK",DCAT,DFN))
  1. . S NAME=$$GET1^DIQ(200,USER,.01,"E")
  1. . I NAME="" S NAME="an unknown user"
  1. . S MSG="This record is currently being updated by "_NAME_"."
  1. ; If lock is successful, update 'LAST LOCKED BY' in ^XTMP.
  1. I RESULT=1 D
  1. . S ^XTMP("BQIDCLK",0)=$$FMADD^XLFDT(DT,1)_U_$$DT^XLFDT()_U_"Maintain locked by information for current locks of patient register data"
  1. . S ^XTMP("BQIDCLK",DCAT,DFN)=DUZ
  1. ;
  1. D UPD
  1. Q
  1. ;
  1. UNLOCK(DATA,DFN,DCAT) ; EP - BQI UNLOCK PATIENT BY DX TAG
  1. ; Description
  1. ; Unlock the patient diagnostic tag record specified by DCAT which was
  1. ; previously locked for exclusive editing access. If the
  1. ; entry in the 'LAST LOCKED BY' field is for this DUZ then
  1. ; delete it (so another user can't accidentally update it).
  1. ; Input:
  1. ; DFN - Patient IEN
  1. ; DCAT - Diagnostic tag defined in ^BQI(90506.2
  1. ; Output:
  1. ; DATA = name of global (passed by reference) in which the data is stored
  1. ;
  1. ; RESULT = 1 (unlock will always succeed)
  1. ; or
  1. ; BMXSEC - if M error encountered
  1. ;
  1. N UID,X,BQII,MSG,REGIEN,RDATA
  1. S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
  1. S DATA=$NA(^TMP("BQIDCLK",UID))
  1. K ^TMP("BQIDCLK",UID)
  1. ;
  1. NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIDCLK D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
  1. ;
  1. ; Create header record
  1. S BQII=0,@DATA@(BQII)="I00010RESULT^T00080MESSAGE"_$C(30)
  1. ;
  1. N RESULT,USER
  1. ;
  1. S MSG=""
  1. ; Get 'LAST LOCKED BY'.
  1. S USER=$G(^XTMP("BQIDCLK",DCAT,DFN))
  1. ;
  1. ; If 'LAST LOCKED BY' is this DUZ then delete the lock entry from ^XTMP.
  1. I USER=DUZ K ^XTMP("BQIDCLK",DCAT,DFN)
  1. ;
  1. ; Unlock and set RESULT
  1. S RESULT=1
  1. L -^BQIREG(DCAT,DFN)
  1. ;
  1. D UPD
  1. Q
  1. ;
  1. UPD ; Report results
  1. S BQII=BQII+1,@DATA@(BQII)=RESULT_"^"_MSG_$C(30)
  1. S BQII=BQII+1,@DATA@(BQII)=$C(31)
  1. Q
  1. ;
  1. INV ; Invalid dx tag passed - either a subdefinition or not in the file
  1. S MSG="Invalid diagnostic tag selected.",RESULT=-1
  1. D UPD
  1. Q
  1. ;
  1. ERR ;
  1. L
  1. I $G(DCAT)'="",$G(DFN)'="",$G(^XTMP("BQIDCLK",DCAT,DFN))=DUZ K ^XTMP("BQIDCLK",DCAT,DFN)
  1. D ^%ZTER
  1. N Y,ERRDTM
  1. S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
  1. S BMXSEC="Recording that an error occurred at "_ERRDTM
  1. Q