source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLEME1.m@ 1582

Last change on this file since 1582 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 4.7 KB
Line 
1HLEME1 ;ALB/CJM-HL7 - APIs for Monitor Events (continued) ;02/04/2004
2 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
3 ;
4NEWINDEX(EVENT,APPNAME,PARMARY) ;
5 ;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.
6 ;
7 ;Input:
8 ; EVENT - ien of an event
9 ; 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.
10 ; 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.
11 ;Output:
12 ; function returns 1 on success, 0 otherwise
13 ;
14 Q:'$G(EVENT) 0
15 Q:'$D(^HLEV(776.4,EVENT,0)) 0
16 Q:'$D(PARMARY) 0
17 Q:'$L($G(APPNAME)) 0
18 N INDEX,I
19 S INDEX="^HLEV(776.4,""AH"",APPNAME,"
20 S I=0
21 F S I=$O(PARMARY(I)) Q:'I S INDEX=INDEX_""""_$S($L(PARMARY(I)):PARMARY(I),1:" ")_""","
22 S INDEX=$E(INDEX,1,$L(INDEX)-1)_")"
23 S @INDEX=EVENT
24 S ^HLEV(776.4,"AH KILL",EVENT,""""_APPNAME_""","_$P(INDEX,"^HLEV(776.4,""AH"",APPNAME,",2))=""
25 Q 1
26 ;
27LOGGED(APPNAME,PARMARY) ;
28 ;Description: This allows an application to determine whether or not an
29 ;event has already been logged, based on a private index the application
30 ;built by calling $$NEWINDEX^HLEME1()
31 ;
32 ;Input:
33 ; 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.
34 ; 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.
35 ;Output:
36 ; function returns TWO values in the format <value 1>^<value 2>
37 ; <value 1> is 1 one if that subscript in the AH index exists, 0 otherwise
38 ; <value 2> is the event ien if found - which should be the case if all the subscripts are supplied that were passed to $$NEWINDEX
39 ;
40 Q:'$D(PARMARY) "0^"
41 Q:'$L($G(APPNAME)) "0^"
42 N INDEX,I,EVENT,VALUE1,VALUE2
43 S VALUE1=0,VALUE2=""
44 S INDEX="^HLEV(776.4,""AH"",APPNAME,"
45 S I=0
46 F S I=$O(PARMARY(I)) Q:'I S INDEX=INDEX_""""_$S($L(PARMARY(I)):PARMARY(I),1:" ")_""","
47 S INDEX=$E(INDEX,1,$L(INDEX)-1)_")"
48 S VALUE1=$S($D(@INDEX):1,1:0)
49 S VALUE2=$G(@INDEX)
50 Q VALUE1_"^"_VALUE2
51 ;
52 ;
53ADD(SITE,TYPE,TIME) ;
54 ;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
55 ;
56 Q:'$G(SITE) 0
57 Q:'$G(TYPE) 0
58 Q:'$G(TIME) 0
59 N EVENT,LAST,COUNT,HOURS
60 S EVENT=0
61 ;
62 S HOURS=$$HOURS^HLEMT(TYPE)
63 Q:'HOURS 0
64 S LAST=$O(^HLEV(776.4,"AE",SITE,TYPE,TIME+.00000001),-1)
65 I LAST,TIME<$$FMADD^XLFDT(LAST,,HOURS) D
66 .S EVENT=$O(^HLEV(776.4,"AE",SITE,TYPE,LAST,0))
67 .I EVENT,$$INC^HLEME(EVENT,1)
68 Q EVENT
69 ;
70STORE(EVENT,ERROR) ;
71 ;Desc: stores the event.Creates a new record if EVENT("IEN") isn't valued, otherwise overlays the existing record.
72 ;Input:
73 ; EVENT - an array containing the EVENT **pass by reference**
74 ;Output:
75 ; function value - 0 on failure, event ien on success
76 ; EVENT() - if successful, the EVENT array is refreshed
77 ; ERROR() - an array of error messages **pass by reference,optional**
78 ;
79 Q:'$D(EVENT) 0
80 ;
81 N DATA,I,SUB,SUCCESS,NODE
82 K ERROR
83 S I=0
84 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
85 .S I=I+.01 S:$D(EVENT(SUB)) DATA(I)=$G(EVENT(SUB))
86 I $G(EVENT("IEN")) D
87 .;record already exists, overlay it
88 .S SUCCESS=$S($$UPD^HLEMU(776.4,EVENT("IEN"),.DATA,.ERROR):EVENT("IEN"),1:0)
89 .D:SUCCESS
90 ..;Kill the multiples to insure full overlay (re-write later)
91 ..K ^HLEV(776.4,EVENT("IEN"),3)
92 ..K ^HLEV(776.4,EVENT("IEN"),1)
93 E D
94 .;record needs to be created
95 .S SUCCESS=$$ADD^HLEMU(776.4,,.DATA,.ERROR)
96 .S:SUCCESS EVENT("IEN")=SUCCESS
97 Q:'SUCCESS 0
98 ;
99 ;store the list of mail messages
100 K DATA,DA
101 S DA(1)=EVENT("IEN")
102 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
103 I SUCCESS,$$GET^HLEME(SUCCESS,.EVENT)
104 Q SUCCESS
105 ;
106LOCK(EVENT) ;
107 ;Locks the event record (EVENT=Event ien), returns 1 on success, 0 on
108 ;failure
109 Q:'$G(EVENT) 0
110 L +^HLEM(776.4,EVENT):3
111 Q $T
112 ;
113UNLOCK(EVENT) ;
114 ;Unlocks the event record (EVENT=Event ien)
115 Q:'$G(EVENT)
116 L -^HLEM(776.4,EVENT)
117 Q
Note: See TracBrowser for help on using the repository browser.