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

EDPBLK.m

Go to the documentation of this file.
  1. EDPBLK ;SLC/KCM - Handle locking for configuration ;2/28/12 08:33am
  1. ;;2.0;EMERGENCY DEPARTMENT;;May 2, 2012;Build 103
  1. ;
  1. READL(AREA,PART,TOKEN) ; lock for reading
  1. N DAY,SEQ
  1. S DAY=$$INITLOCK
  1. L +^XTMP("EDP-LOCK-"_DAY,AREA,PART):10 E Q ""
  1. S SEQ=+$G(^XTMP("EDP-LOCK-"_DAY,AREA,PART,"READ"))+1
  1. S ^XTMP("EDP-LOCK-"_DAY,AREA,PART,"READ")=SEQ
  1. S TOKEN=DAY_"-"_SEQ
  1. Q
  1. READU(AREA,PART,TOKEN) ; unlock for reading
  1. Q:$G(TOKEN)=""
  1. L -^XTMP("EDP-LOCK-"_$P(TOKEN,"-"),AREA,PART)
  1. Q
  1. INITLOCK() ; returns lock table id, initializing new table if necessary
  1. S DAY=+$H
  1. I '$D(^XTMP("EDP-LOCK-"_DAY,0)) D
  1. . S ^XTMP("EDP-LOCK-"_DAY,0)=$$FMADD^XLFDT(DT,2)_U_DT_U_"ED Locks"
  1. . N X S X=DAY-3 ; delete any older than 3 days
  1. . F S X=$O(^XTMP("EDP-LOCK-"_X),-1) Q:$E(X,1,8)'="EDP-LOCK" D
  1. . . S X=$P(X,"-",3)
  1. . . K ^XTMP("EDP-LOCK-"_X)
  1. Q DAY
  1. ;
  1. SAVEL(AREA,PART,TOKEN,ERR) ; lock for saving configuration
  1. ; ERR is return, empty if successful, message if lock fails
  1. ; TOKEN is returned with save token, contains read token initially
  1. S ERR=""
  1. I '$L(TOKEN) S ERR="Unable to update with empty token" Q
  1. ;
  1. ; extract from token the time of the GET
  1. N GDAY,GSEQ
  1. S GDAY=$P(TOKEN,"-"),GSEQ=$P(TOKEN,"-",2)
  1. ;
  1. ; lock out all reads during the update
  1. N DAY
  1. S DAY=$$INITLOCK
  1. L +^XTMP("EDP-LOCK-"_DAY,AREA,PART):10 E S ERR="Unable to obtain lock" Q
  1. ;
  1. ; look backwards for interfering updates since GET
  1. N COLLIDE,SEQ,X,Y
  1. S COLLIDE="",X="EDP-LOCK-?"
  1. F S X=$O(^XTMP(X),-1) Q:$E(X,1,8)'="EDP-LOCK" Q:$P(X,"-",3)<GDAY D
  1. . S Y=$O(^XTMP(X,AREA,PART,"SAVE"," "),-1) Q:'Y ; no puts
  1. . I (GDAY=$P(X,"-",3)),(Y<GSEQ) Q ; put earlier than get token
  1. . S COLLIDE=^XTMP(X,AREA,PART,"SAVE",Y)
  1. ;
  1. I COLLIDE D
  1. . L -^XTMP("EDP-LOCK-"_DAY,AREA,PART)
  1. . I COLLIDE=TOKEN S ERR="These changes have already been saved." Q
  1. . S ERR="Only one person should edit the configuration at a time. "
  1. . S ERR=ERR_"The configuration has been modified since you began. "
  1. . S ERR=ERR_"You will need to re-enter the changes you have made."
  1. E D
  1. . S SEQ=+$G(^XTMP("EDP-LOCK-"_DAY,AREA,PART,"READ"))+1
  1. . S ^XTMP("EDP-LOCK-"_DAY,AREA,PART,"READ")=SEQ
  1. . S ^XTMP("EDP-LOCK-"_DAY,AREA,PART,"SAVE",SEQ)=TOKEN
  1. . S TOKEN=DAY_"-"_SEQ
  1. ;
  1. ; return & do the actual update now, unlocking afterwards
  1. Q
  1. SAVEU(AREA,PART,TOKEN) ; Unlock for saving
  1. L -^XTMP("EDP-LOCK-"_$P(TOKEN,"-"),AREA,PART)
  1. Q