HLEME1 ;ALB/CJM-HL7 - APIs for Monitor Events (continued) ;02/04/2004
;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
;
NEWINDEX(EVENT,APPNAME,PARMARY) ;
;Description: This allows an application to build is own private index on its own events, which it can use to determine whether or not the event has been logged.
;
;Input:
; EVENT - ien of an event
; APPNAME - application name, including namespace. This is used as part of the lookup index. The application is responsible for insuring there will be no coflict with other applications logging its own events.
; PARMARY - **pass by reference** an array of parameters with which to build the index. The format is: PARMARY(1)=<first parameter>, PARMARY(2)=<second parameter> If PARRMARY(i)=null, the parameter will be translated to a single space.
;Output:
; function returns 1 on success, 0 otherwise
;
Q:'$G(EVENT) 0
Q:'$D(^HLEV(776.4,EVENT,0)) 0
Q:'$D(PARMARY) 0
Q:'$L($G(APPNAME)) 0
N INDEX,I
S INDEX="^HLEV(776.4,""AH"",APPNAME,"
S I=0
F S I=$O(PARMARY(I)) Q:'I S INDEX=INDEX_""""_$S($L(PARMARY(I)):PARMARY(I),1:" ")_""","
S INDEX=$E(INDEX,1,$L(INDEX)-1)_")"
S @INDEX=EVENT
S ^HLEV(776.4,"AH KILL",EVENT,""""_APPNAME_""","_$P(INDEX,"^HLEV(776.4,""AH"",APPNAME,",2))=""
Q 1
;
LOGGED(APPNAME,PARMARY) ;
;Description: This allows an application to determine whether or not an
;event has already been logged, based on a private index the application
;built by calling $$NEWINDEX^HLEME1()
;
;Input:
; APPNAME - application name, including namespace. This is used as part of the lookup index. The application is responsible for insuring there will be no coflict with other applications logging its own events.
; PARMARY **pass by reference** an array of parameters with which the index was built. The format is: PARMARY(1)=<first parameter>, PARMARY(2)=<second parameter> If PARRMARY(i)=null, the parameter will be translated to a single space.
;Output:
; function returns TWO values in the format <value 1>^<value 2>
; <value 1> is 1 one if that subscript in the AH index exists, 0 otherwise
; <value 2> is the event ien if found - which should be the case if all the subscripts are supplied that were passed to $$NEWINDEX
;
Q:'$D(PARMARY) "0^"
Q:'$L($G(APPNAME)) "0^"
N INDEX,I,EVENT,VALUE1,VALUE2
S VALUE1=0,VALUE2=""
S INDEX="^HLEV(776.4,""AH"",APPNAME,"
S I=0
F S I=$O(PARMARY(I)) Q:'I S INDEX=INDEX_""""_$S($L(PARMARY(I)):PARMARY(I),1:" ")_""","
S INDEX=$E(INDEX,1,$L(INDEX)-1)_")"
S VALUE1=$S($D(@INDEX):1,1:0)
S VALUE2=$G(@INDEX)
Q VALUE1_"^"_VALUE2
;
;
ADD(SITE,TYPE,TIME) ;
;Description - Checks for an existing event and determines if it can be added to, based on whether or not its period is expired. If it can be added, its count is incremented and its ien returned as the function value, otherwise, 0 is returned
;
Q:'$G(SITE) 0
Q:'$G(TYPE) 0
Q:'$G(TIME) 0
N EVENT,LAST,COUNT,HOURS
S EVENT=0
;
S HOURS=$$HOURS^HLEMT(TYPE)
Q:'HOURS 0
S LAST=$O(^HLEV(776.4,"AE",SITE,TYPE,TIME+.00000001),-1)
I LAST,TIME<$$FMADD^XLFDT(LAST,,HOURS) D
.S EVENT=$O(^HLEV(776.4,"AE",SITE,TYPE,LAST,0))
.I EVENT,$$INC^HLEME(EVENT,1)
Q EVENT
;
STORE(EVENT,ERROR) ;
;Desc: stores the event.Creates a new record if EVENT("IEN") isn't valued, otherwise overlays the existing record.
;Input:
; EVENT - an array containing the EVENT **pass by reference**
;Output:
; function value - 0 on failure, event ien on success
; EVENT() - if successful, the EVENT array is refreshed
; ERROR() - an array of error messages **pass by reference,optional**
;
Q:'$D(EVENT) 0
;
N DATA,I,SUB,SUCCESS,NODE
K ERROR
S I=0
F SUB="DT/TM","TYPE","SITE","ID","ACTION STATUS","REVIEW STATUS","DT/TM REVIEWED","REVIEWER","DT/TM ACTION","MSG ID","COUNT","URGENT","MSG TYPE","MSG EVENT","MSG LINK","APPLICATION","DT/TM CREATED" D
.S I=I+.01 S:$D(EVENT(SUB)) DATA(I)=$G(EVENT(SUB))
I $G(EVENT("IEN")) D
.;record already exists, overlay it
.S SUCCESS=$S($$UPD^HLEMU(776.4,EVENT("IEN"),.DATA,.ERROR):EVENT("IEN"),1:0)
.D:SUCCESS
..;Kill the multiples to insure full overlay (re-write later)
..K ^HLEV(776.4,EVENT("IEN"),3)
..K ^HLEV(776.4,EVENT("IEN"),1)
E D
.;record needs to be created
.S SUCCESS=$$ADD^HLEMU(776.4,,.DATA,.ERROR)
.S:SUCCESS EVENT("IEN")=SUCCESS
Q:'SUCCESS 0
;
;store the list of mail messages
K DATA,DA
S DA(1)=EVENT("IEN")
S I=0 F S I=$O(EVENT("MAIL",I)) Q:'I S DATA(.01)=I I '$$ADD^HLEMU(776.4,.DA,.DATA,.ERROR) Q
I SUCCESS,$$GET^HLEME(SUCCESS,.EVENT)
Q SUCCESS
;
LOCK(EVENT) ;
;Locks the event record (EVENT=Event ien), returns 1 on success, 0 on
;failure
Q:'$G(EVENT) 0
L +^HLEM(776.4,EVENT):3
Q $T
;
UNLOCK(EVENT) ;
;Unlocks the event record (EVENT=Event ien)
Q:'$G(EVENT)
L -^HLEM(776.4,EVENT)
Q
HLEME1 ;ALB/CJM-HL7 - APIs for Monitor Events (continued) ;02/04/2004
+1 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
+2 ;
NEWINDEX(EVENT,APPNAME,PARMARY) ;
+1 ;Description: This allows an application to build is own private index on its own events, which it can use to determine whether or not the event has been logged.
+2 ;
+3 ;Input:
+4 ; EVENT - ien of an event
+5 ; APPNAME - application name, including namespace. This is used as part of the lookup index. The application is responsible for insuring there will be no coflict with other applications logging its own events.
+6 ; PARMARY - **pass by reference** an array of parameters with which to build the index. The format is: PARMARY(1)=<first parameter>, PARMARY(2)=<second parameter> If PARRMARY(i)=null, the parameter will be translated to a single space.
+7 ;Output:
+8 ; function returns 1 on success, 0 otherwise
+9 ;
+10 IF '$GET(EVENT)
QUIT 0
+11 IF '$DATA(^HLEV(776.4,EVENT,0))
QUIT 0
+12 IF '$DATA(PARMARY)
QUIT 0
+13 IF '$LENGTH($GET(APPNAME))
QUIT 0
+14 NEW INDEX,I
+15 SET INDEX="^HLEV(776.4,""AH"",APPNAME,"
+16 SET I=0
+17 FOR
SET I=$ORDER(PARMARY(I))
IF 'I
QUIT
SET INDEX=INDEX_""""_$SELECT($LENGTH(PARMARY(I)):PARMARY(I),1:" ")_""","
+18 SET INDEX=$EXTRACT(INDEX,1,$LENGTH(INDEX)-1)_")"
+19 SET @INDEX=EVENT
+20 SET ^HLEV(776.4,"AH KILL",EVENT,""""_APPNAME_""","_$PIECE(INDEX,"^HLEV(776.4,""AH"",APPNAME,",2))=""
+21 QUIT 1
+22 ;
LOGGED(APPNAME,PARMARY) ;
+1 ;Description: This allows an application to determine whether or not an
+2 ;event has already been logged, based on a private index the application
+3 ;built by calling $$NEWINDEX^HLEME1()
+4 ;
+5 ;Input:
+6 ; APPNAME - application name, including namespace. This is used as part of the lookup index. The application is responsible for insuring there will be no coflict with other applications logging its own events.
+7 ; PARMARY **pass by reference** an array of parameters with which the index was built. The format is: PARMARY(1)=<first parameter>, PARMARY(2)=<second parameter> If PARRMARY(i)=null, the parameter will be translated to a single space.
+8 ;Output:
+9 ; function returns TWO values in the format <value 1>^<value 2>
+10 ; <value 1> is 1 one if that subscript in the AH index exists, 0 otherwise
+11 ; <value 2> is the event ien if found - which should be the case if all the subscripts are supplied that were passed to $$NEWINDEX
+12 ;
+13 IF '$DATA(PARMARY)
QUIT "0^"
+14 IF '$LENGTH($GET(APPNAME))
QUIT "0^"
+15 NEW INDEX,I,EVENT,VALUE1,VALUE2
+16 SET VALUE1=0
SET VALUE2=""
+17 SET INDEX="^HLEV(776.4,""AH"",APPNAME,"
+18 SET I=0
+19 FOR
SET I=$ORDER(PARMARY(I))
IF 'I
QUIT
SET INDEX=INDEX_""""_$SELECT($LENGTH(PARMARY(I)):PARMARY(I),1:" ")_""","
+20 SET INDEX=$EXTRACT(INDEX,1,$LENGTH(INDEX)-1)_")"
+21 SET VALUE1=$SELECT($DATA(@INDEX):1,1:0)
+22 SET VALUE2=$GET(@INDEX)
+23 QUIT VALUE1_"^"_VALUE2
+24 ;
+25 ;
ADD(SITE,TYPE,TIME) ;
+1 ;Description - Checks for an existing event and determines if it can be added to, based on whether or not its period is expired. If it can be added, its count is incremented and its ien returned as the function value, otherwise, 0 is returned
+2 ;
+3 IF '$GET(SITE)
QUIT 0
+4 IF '$GET(TYPE)
QUIT 0
+5 IF '$GET(TIME)
QUIT 0
+6 NEW EVENT,LAST,COUNT,HOURS
+7 SET EVENT=0
+8 ;
+9 SET HOURS=$$HOURS^HLEMT(TYPE)
+10 IF 'HOURS
QUIT 0
+11 SET LAST=$ORDER(^HLEV(776.4,"AE",SITE,TYPE,TIME+.00000001),-1)
+12 IF LAST
IF TIME<$$FMADD^XLFDT(LAST,,HOURS)
Begin DoDot:1
+13 SET EVENT=$ORDER(^HLEV(776.4,"AE",SITE,TYPE,LAST,0))
+14 IF EVENT
IF $$INC^HLEME(EVENT,1)
End DoDot:1
+15 QUIT EVENT
+16 ;
STORE(EVENT,ERROR) ;
+1 ;Desc: stores the event.Creates a new record if EVENT("IEN") isn't valued, otherwise overlays the existing record.
+2 ;Input:
+3 ; EVENT - an array containing the EVENT **pass by reference**
+4 ;Output:
+5 ; function value - 0 on failure, event ien on success
+6 ; EVENT() - if successful, the EVENT array is refreshed
+7 ; ERROR() - an array of error messages **pass by reference,optional**
+8 ;
+9 IF '$DATA(EVENT)
QUIT 0
+10 ;
+11 NEW DATA,I,SUB,SUCCESS,NODE
+12 KILL ERROR
+13 SET I=0
+14 FOR SUB="DT/TM","TYPE","SITE","ID","ACTION STATUS","REVIEW STATUS","DT/TM REVIEWED","REVIEWER","DT/TM ACTION","MSG ID","COUNT","URGENT","MSG TYPE","MSG EVENT","MSG LINK","APPLICATION","DT/TM CREATED"
Begin DoDot:1
+15 SET I=I+.01
IF $DATA(EVENT(SUB))
SET DATA(I)=$GET(EVENT(SUB))
End DoDot:1
+16 IF $GET(EVENT("IEN"))
Begin DoDot:1
+17 ;record already exists, overlay it
+18 SET SUCCESS=$SELECT($$UPD^HLEMU(776.4,EVENT("IEN"),.DATA,.ERROR):EVENT("IEN"),1:0)
+19 IF SUCCESS
Begin DoDot:2
+20 ;Kill the multiples to insure full overlay (re-write later)
+21 KILL ^HLEV(776.4,EVENT("IEN"),3)
+22 KILL ^HLEV(776.4,EVENT("IEN"),1)
End DoDot:2
End DoDot:1
+23 IF '$TEST
Begin DoDot:1
+24 ;record needs to be created
+25 SET SUCCESS=$$ADD^HLEMU(776.4,,.DATA,.ERROR)
+26 IF SUCCESS
SET EVENT("IEN")=SUCCESS
End DoDot:1
+27 IF 'SUCCESS
QUIT 0
+28 ;
+29 ;store the list of mail messages
+30 KILL DATA,DA
+31 SET DA(1)=EVENT("IEN")
+32 SET I=0
FOR
SET I=$ORDER(EVENT("MAIL",I))
IF 'I
QUIT
SET DATA(.01)=I
IF '$$ADD^HLEMU(776.4,.DA,.DATA,.ERROR)
QUIT
+33 IF SUCCESS
IF $$GET^HLEME(SUCCESS,.EVENT)
+34 QUIT SUCCESS
+35 ;
LOCK(EVENT) ;
+1 ;Locks the event record (EVENT=Event ien), returns 1 on success, 0 on
+2 ;failure
+3 IF '$GET(EVENT)
QUIT 0
+4 LOCK +^HLEM(776.4,EVENT):3
+5 QUIT $TEST
+6 ;
UNLOCK(EVENT) ;
+1 ;Unlocks the event record (EVENT=Event ien)
+2 IF '$GET(EVENT)
QUIT
+3 LOCK -^HLEM(776.4,EVENT)
+4 QUIT