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

RORUPP02.m

Go to the documentation of this file.
  1. RORUPP02 ;HCIOFO/SG - PATIENT EVENTS (EVENTS) ; 1/20/06 1:55pm
  1. ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
  1. ;
  1. Q
  1. ;
  1. ;***** ADDS THE EVENT REFERENCE
  1. ;
  1. ; PATIEN Patient IEN
  1. ;
  1. ; AREA Data area of the event (see the DATA AREA field
  1. ; of the file #798.3 for details)
  1. ;
  1. ; [DATE] Date/Time associated with the event (the current
  1. ; date/time is used by default).
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. ADD(PATIEN,AREA,DATE) ;
  1. N IEN,IENS,RORFDA,RORIEN,RORMSG
  1. S:$G(DATE)'>0 DATE=$$NOW^XLFDT
  1. ;--- Do not record more than one reference per associated date.
  1. ; Maybe in the future all references will be recorded but we
  1. ; need only daily precision at the moment. If the reference
  1. ; exists already, update it with the earlier associated date
  1. ;--- and the latter timestamp if necessary.
  1. S IEN=$O(^RORDATA(798.3,+PATIEN,2,"AD",AREA,DATE\1,""))
  1. I IEN K DIERR D Q $S('$G(DIERR):0,1:-9)
  1. . N BUF,NOW
  1. . S IENS=IEN_","_(+PATIEN)_",",NOW=$$NOW^XLFDT
  1. . S BUF=$G(^RORDATA(798.3,+PATIEN,2,IEN,0))
  1. . S:NOW>$P(BUF,"^") RORFDA(798.32,IENS,.01)=NOW
  1. . S:DATE<$P(BUF,"^",3) RORFDA(798.32,IENS,2)=DATE
  1. . D:$D(RORFDA)>1 FILE^DIE(,"RORFDA","RORMSG")
  1. ;--- Create the new event reference
  1. S (RORFDA(798.3,"?+1,",.01),RORIEN(1))=+PATIEN
  1. S IENS="+2,?+1,"
  1. S RORFDA(798.32,IENS,.01)=$$NOW^XLFDT
  1. S RORFDA(798.32,IENS,1)=AREA
  1. S RORFDA(798.32,IENS,2)=DATE
  1. D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
  1. Q $S('$G(DIERR):0,1:-9)
  1. ;
  1. ;***** CHECKS THE EVENTS
  1. ;
  1. ; PATIEN Patient IEN
  1. ;
  1. ; AREA Data area of the event (see the DATA AREA field
  1. ; of the file #798.3 for details)
  1. ;
  1. ; .SDT Reference to a local variable containing the start
  1. ; date. The date can be modified by the function and
  1. ; returned via this parameter.
  1. ;
  1. ; .EDT Reference to a local variable containing the end
  1. ; date. The date can be modified by the function and
  1. ; returned via this parameter.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 No events (skip)
  1. ; 1 Events have been found (proceed)
  1. ; 2 The same as 1 + dates (SDT & EDT) have been modified
  1. ;
  1. GET(PATIEN,AREA,SDT,EDT) ;
  1. N ED,FDTC,FEVT,IEN,NEWEDT,NEWSDT,ROOT,TMP
  1. S ROOT=$NA(^RORDATA(798.3,+PATIEN,2))
  1. S NEWSDT=999999999,NEWEDT=0,(FDTC,FEVT)=0
  1. ;--- If the data search time frame is too wide and some of the
  1. ; event references have been purged already then the time
  1. ; frame cannot be shrinked according to the references and the
  1. ;--- patient cannot be skipped if there are no references at all.
  1. S:SDT<$G(RORUPD("EETS")) NEWSDT=SDT,NEWEDT=EDT,FEVT=1
  1. ;--- Browse through the event references
  1. S ED=$O(@ROOT@("AT",AREA,SDT),-1)
  1. F S ED=$O(@ROOT@("AT",AREA,ED)) Q:(ED="")!(ED'<EDT) D
  1. . S IEN=""
  1. . F S IEN=$O(@ROOT@("AT",AREA,ED,IEN)) Q:IEN="" D
  1. . . S TMP=$P($G(@ROOT@(IEN,0)),"^",3),FEVT=1
  1. . . Q:TMP'>0
  1. . . S:TMP<NEWSDT NEWSDT=TMP,FDTC=1
  1. . . S:TMP>NEWEDT NEWEDT=TMP,FDTC=1
  1. Q:'FEVT 0
  1. I FDTC S SDT=NEWSDT,EDT=NEWEDT Q 2
  1. Q 1
  1. ;
  1. ;***** PURGES THE OLD EVENT REFERENCES
  1. ;
  1. ; DATE Keep the references starting from this date
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. PURGE(DATE) ;
  1. N CNT,DA,DIK,IEN,IEN1,IENS,RC,REINDEX,ROOT,RORFDA,RORMSG
  1. S ROOT=$$ROOT^DILFD(798.3,,1)
  1. S DATE=DATE\1,(CNT,RC)=0
  1. F S DATE=$O(@ROOT@("AT",DATE),-1) Q:DATE="" D Q:RC<0
  1. . S IEN=""
  1. . F S IEN=$O(@ROOT@("AT",DATE,IEN)) Q:IEN="" D Q:RC<0
  1. . . S IEN1="",REINDEX=0
  1. . . F S IEN1=$O(@ROOT@("AT",DATE,IEN,IEN1)) Q:IEN1="" D Q:RC<0
  1. . . . ;---Check if the corresponding record exists
  1. . . . I '$D(@ROOT@(IEN,2,IEN1,0)) D Q
  1. . . . . ;--- Delete the "stray" entry from the cross-reference
  1. . . . . K @ROOT@("AT",DATE,IEN,IEN1)
  1. . . . ;--- Delete the record
  1. . . . S IENS=IEN1_","_IEN_","
  1. . . . S RORFDA(798.32,IENS,.01)="@"
  1. . . . D FILE^DIE(,"RORFDA","RORMSG")
  1. . . . I $G(DIERR) D Q
  1. . . . . S RC=$$DBS^RORERR("RORMSG",-9,,,798.32,IENS)
  1. . . . S CNT=CNT+1
  1. . . ;--- Re-index the main record if necessary
  1. . . I REINDEX K DA S DIK=$$OREF^DILF(ROOT),DA=IEN D IX^DIK
  1. D:CNT>0 LOG^RORLOG(2,CNT_" events were purged from the file #798.3")
  1. Q $S(RC<0:RC,1:0)