| 1 | HLEME ;ALB/CJM-HL7 - APIs for Monitor Events ;02/04/2004 | 
|---|
| 2 | ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995 | 
|---|
| 3 | ; | 
|---|
| 4 | GET(IEN,EVENT) ; | 
|---|
| 5 | ;Desc: given the ien, it returns an array containing the event.  Does NOT include the NOTES field or the Application Data | 
|---|
| 6 | ;Input: | 
|---|
| 7 | ;  IEN - ien of event | 
|---|
| 8 | ;Output: | 
|---|
| 9 | ;  function returns 0 on failure, 1 on success | 
|---|
| 10 | ;  EVENT(   ***pass by reference*** | 
|---|
| 11 | ;  "ACTION STATUS" | 
|---|
| 12 | ;  "APPLICATION" - the sending application, only if the event is related to an HL7 message | 
|---|
| 13 | ;  "COUNT" - the number of discrete events included in this event - for conglomerated events | 
|---|
| 14 | ;  "DT/TM" - date/time of the event | 
|---|
| 15 | ;  "DT/TM ACTION" - for automated action | 
|---|
| 16 | ;  "DT/TM CREATED" - time stamp for this event | 
|---|
| 17 | ;  "DT/TM REVIEWED" - | 
|---|
| 18 | ;  "ID" - unique identifier | 
|---|
| 19 | ;  "IEN" -the ien | 
|---|
| 20 | ;  "MAIL",<msg ien>)=<msg ien> - list of Mailman messages | 
|---|
| 21 | ;  "MSGID ID" - mssage id of message causing this event (if any) | 
|---|
| 22 | ;  "MSG TYPE" - HL7 message type code | 
|---|
| 23 | ;  "MSG EVENT" - HL7 event type code | 
|---|
| 24 | ;  "MSG LINK" - name of the HL Logical Link (NODE) on which the mssg was sent | 
|---|
| 25 | ;  "REVIEWER" - ien in New Person file | 
|---|
| 26 | ;  "REVIEW STATUS" | 
|---|
| 27 | ;  "SITE" - site of occurence, a pointer to the Institution file | 
|---|
| 28 | ;  "TYPE" - the type of event, an ien of a HL7 Monitor Event Type | 
|---|
| 29 | ;  "URGENT" - flag for urgency | 
|---|
| 30 | ; | 
|---|
| 31 | ; | 
|---|
| 32 | Q:'$G(IEN) 0 | 
|---|
| 33 | N NODE,I,LABEL | 
|---|
| 34 | K EVENT | 
|---|
| 35 | S EVENT("IEN")=IEN | 
|---|
| 36 | S NODE=$G(^HLEV(776.4,IEN,0)) | 
|---|
| 37 | Q:'$L(NODE) 0 | 
|---|
| 38 | S EVENT("DT/TM")=$P(NODE,"^") | 
|---|
| 39 | S EVENT("TYPE")=$P(NODE,"^",2) | 
|---|
| 40 | S EVENT("SITE")=$P(NODE,"^",3) | 
|---|
| 41 | S EVENT("ID")=$P(NODE,"^",4) | 
|---|
| 42 | S EVENT("ACTION STATUS")=$P(NODE,"^",5) | 
|---|
| 43 | S EVENT("REVIEW STATUS")=$P(NODE,"^",6) | 
|---|
| 44 | S EVENT("DT/TM REVIEWED")=$P(NODE,"^",7) | 
|---|
| 45 | S EVENT("REVIEWER")=$P(NODE,"^",8) | 
|---|
| 46 | S EVENT("DT/TM ACTION")=$P(NODE,"^",9) | 
|---|
| 47 | S EVENT("MSG ID")=$P(NODE,"^",10) | 
|---|
| 48 | S EVENT("MSG TYPE")=$P(NODE,"^",13) | 
|---|
| 49 | S EVENT("MSG EVENT")=$P(NODE,"^",14) | 
|---|
| 50 | S EVENT("MSG LINK")=$P(NODE,"^",15) | 
|---|
| 51 | S EVENT("DT/TM CREATED")=$P(NODE,"^",17) | 
|---|
| 52 | S EVENT("APPLICATION")=$P(NODE,"^",16) | 
|---|
| 53 | S EVENT("COUNT")=$P(NODE,"^",11) | 
|---|
| 54 | S EVENT("URGENT")=$P(NODE,"^",12) | 
|---|
| 55 | S I=0 F  S I=$O(^HLEV(776.4,IEN,2,I)) Q:'I  S NODE=+$G(^HLEV(776.4,IEN,2,I,0)) I NODE S EVENT("MAIL",NODE)=NODE | 
|---|
| 56 | Q 1 | 
|---|
| 57 | ; | 
|---|
| 58 | STOREVAR(EVENT,APPDATA,VAR) ; | 
|---|
| 59 | ;Desc:  Allows an app. to store its own application-specific data. | 
|---|
| 60 | ;Input: | 
|---|
| 61 | ;   EVENT - ien of event | 
|---|
| 62 | ;   APPDATA - variable or array to store **for arrays, pass by reference** | 
|---|
| 63 | ;   VAR - **optional** - variable name, may inlucde subscripts.Required if the application needs to store multiple variables or arrays. VAR="APPDATA"is the default | 
|---|
| 64 | ;Output: | 
|---|
| 65 | ;  function reuturns 1 on success,0 on failure | 
|---|
| 66 | ;Ex 1 | 
|---|
| 67 | ;  An app. needs to store a single set of data with the | 
|---|
| 68 | ;  event.  It could set the data into an array call | 
|---|
| 69 | ;  $$STOREVAR(EVENT,.MYARRAY) To get back the | 
|---|
| 70 | ;       data it would call $$GETVAR(EVENT,.MYARRAY).  (any variable name could have been used instead of MYARRAY. | 
|---|
| 71 | ;Ex 2 | 
|---|
| 72 | ;  An application needs to store multiple sets of data with the | 
|---|
| 73 | ;  the event. It could accomplish that by setting the data into | 
|---|
| 74 | ;  multiple arrays, say DATA1,DATA2,DATA3,... and calling | 
|---|
| 75 | ;  $$STOREVAR(EVENT,.DATA1,"DATA1"), then $$STOREVAR(EVENT,.DATA2,"DATA2"),etc. | 
|---|
| 76 | ;  To get back the named datasets the application would call | 
|---|
| 77 | ;  $$GETVAR(EVENT,.DATA1,"DATA1"), $$GETVAR(EVENT,.DATA2,"DATA2"), | 
|---|
| 78 | ;  etc. | 
|---|
| 79 | ; | 
|---|
| 80 | Q:'$G(EVENT) 0 | 
|---|
| 81 | Q:'$D(^HLEV(776.4,EVENT,0)) 0 | 
|---|
| 82 | Q:'$D(APPDATA) 0 | 
|---|
| 83 | ; | 
|---|
| 84 | N I,LABEL | 
|---|
| 85 | S I=+$O(^HLEV(776.4,EVENT,3,999999999),-1) | 
|---|
| 86 | I $L($G(VAR)) N @VAR D | 
|---|
| 87 | .S LABEL=VAR | 
|---|
| 88 | .M @VAR=APPDATA | 
|---|
| 89 | E  D | 
|---|
| 90 | .S LABEL="APPDATA" | 
|---|
| 91 | ; | 
|---|
| 92 | ;check if the root has data, if so, store it | 
|---|
| 93 | I $D(@LABEL)'[0 D | 
|---|
| 94 | .N OLDIEN | 
|---|
| 95 | .S OLDIEN=$O(^HLEV(776.4,EVENT,3,"B",LABEL,0)) | 
|---|
| 96 | .I OLDIEN D | 
|---|
| 97 | ..K ^HLEV(776.4,EVENT,"B",LABEL,OLDIEN),^HLEV(776.4,EVENT,3,OLDIEN) | 
|---|
| 98 | .E  D | 
|---|
| 99 | ..S I=I+1 | 
|---|
| 100 | .S ^HLEV(776.4,EVENT,3,I,0)=LABEL,^HLEV(776.4,EVENT,3,I,2)=@LABEL,^HLEV(776.4,EVENT,3,"B",LABEL,I)=0 | 
|---|
| 101 | ; | 
|---|
| 102 | ;now store everything that comes below it | 
|---|
| 103 | F  S LABEL=$Q(@LABEL) Q:LABEL=""  D | 
|---|
| 104 | .;can't go over a total lenth of 230 | 
|---|
| 105 | .Q:'$L(LABEL)>230 | 
|---|
| 106 | .S I=I+1 S ^HLEV(776.4,EVENT,3,I,0)=LABEL,^HLEV(776.4,EVENT,3,I,2)=@LABEL,^HLEV(776.4,EVENT,3,"B",LABEL,I)=0 | 
|---|
| 107 | ; | 
|---|
| 108 | ;write the 0-node | 
|---|
| 109 | S ^HLEV(776.4,EVENT,3,0)="^776.43^"_I_"^"_I | 
|---|
| 110 | ; | 
|---|
| 111 | Q 1 | 
|---|
| 112 | ; | 
|---|
| 113 | GETVAR(EVENT,APPDATA,VAR) ; | 
|---|
| 114 | ;Desc: Used to retrieve application-specific data that was stored along with the event. | 
|---|
| 115 | ;Input: | 
|---|
| 116 | ;   EVENT - ien of the event | 
|---|
| 117 | ;   VAR - name of the variable or array to fetch.  If not passed, "APPDATA" is assumed, which is also the default when calling $$STOREVAR() | 
|---|
| 118 | ;Output | 
|---|
| 119 | ;  function value - 1 on success, 0 on failure | 
|---|
| 120 | ;  APPDATA() - used to return the requested data **pass by reference** | 
|---|
| 121 | ; | 
|---|
| 122 | Q:'$G(EVENT) 0 | 
|---|
| 123 | Q:'$L($G(^HLEV(776.4,EVENT,0))) 0 | 
|---|
| 124 | ; | 
|---|
| 125 | N INDEX,I,LABEL,VAR2 | 
|---|
| 126 | K APPDATA | 
|---|
| 127 | S INDEX="^HLEV(776.4,EVENT,3)" | 
|---|
| 128 | S:'$L($G(VAR)) VAR="APPDATA" | 
|---|
| 129 | S VAR2=$O(@INDEX@("B",VAR),-1) | 
|---|
| 130 | F  S VAR2=$O(@INDEX@("B",VAR2)) Q:'$L(VAR2)  Q:(VAR2'[VAR)  S I=0 F  S I=$O(@INDEX@("B",VAR2,I)) Q:'I  S LABEL=$G(@INDEX@(I,0)) S:LABEL[VAR @LABEL=$G(@INDEX@(I,2)) | 
|---|
| 131 | ; | 
|---|
| 132 | M APPDATA=@VAR | 
|---|
| 133 | Q 1 | 
|---|
| 134 | ; | 
|---|
| 135 | EVENT(CODE,PACKAGE,HL7MSGID,SITE,WHEN,ERROR) ; | 
|---|
| 136 | ;Desc: API for applications to notify HL7 Event Monitor of their events | 
|---|
| 137 | ;Input: | 
|---|
| 138 | ;  CODE - the code (.01 field) for the HL7 Monitor Event Type | 
|---|
| 139 | ;  PACKAGE - the name of the package that created the HL7 Monitor Event Type, used to find the event type ien. | 
|---|
| 140 | ;  HL7MSGID - **optional** - if the event pertains to a specific message, this should be passed | 
|---|
| 141 | ;  SITE - **optional** - the station number, including any suffix, where the event occured. Will assume the local site if not passed in. | 
|---|
| 142 | ;  WHEN - **optional** - FM date/time of when the event occurred. Will assume now if not passed in. | 
|---|
| 143 | ;Output: | 
|---|
| 144 | ;  function value -  ien of the event (file 776.4) on success, 0 on failure | 
|---|
| 145 | ;  ERROR - **optional, pass by reference** - array of error messages | 
|---|
| 146 | ; | 
|---|
| 147 | N EVENT,TYPE,MSGIEN,NOW | 
|---|
| 148 | S EVENT("TYPE")=$$FIND^HLEMT(.CODE,.PACKAGE) | 
|---|
| 149 | I 'EVENT("TYPE") S ERROR(1)="UNKNOWN EVENT TYPE" Q 0 | 
|---|
| 150 | I '$L($G(SITE)) D | 
|---|
| 151 | .S EVENT("SITE")=+$P($$SITE^VASITE(),"^") | 
|---|
| 152 | E  D | 
|---|
| 153 | .S EVENT("SITE")=$$LKUP^XUAF4(SITE) | 
|---|
| 154 | I 'EVENT("SITE") S ERROR(1)="UNKNOWN SITE" Q 0 | 
|---|
| 155 | S NOW=$$NOW^XLFDT | 
|---|
| 156 | S EVENT("DT/TM")=$S('$G(WHEN):NOW,1:WHEN) | 
|---|
| 157 | S EVENT("DT/TM CREATED")=NOW | 
|---|
| 158 | ; | 
|---|
| 159 | ;get the event type array | 
|---|
| 160 | I '$$GET^HLEMT(EVENT("TYPE"),.TYPE) S ERROR(1)="UNKNOWN EVENT TYPE" Q 0 | 
|---|
| 161 | ; | 
|---|
| 162 | ;is this event type active? | 
|---|
| 163 | I 'TYPE("ACTIVE") S ERROR(1)="INACTIVE EVENT TYPE" Q 0 | 
|---|
| 164 | ; | 
|---|
| 165 | ;check if this is a conglomerated event that can be added to an existing event | 
|---|
| 166 | I TYPE("CONGLOMERATE") D | 
|---|
| 167 | .L +^HLEV(776.4,"AE",EVENT("SITE"),EVENT("TYPE")):2 | 
|---|
| 168 | .S EVENT("IEN")=$$ADD^HLEME1(EVENT("SITE"),EVENT("TYPE"),EVENT("DT/TM")) | 
|---|
| 169 | ; | 
|---|
| 170 | I '$G(EVENT("IEN")) D | 
|---|
| 171 | .; | 
|---|
| 172 | .;otherwise, create and store a new event | 
|---|
| 173 | .S EVENT("ACTION STATUS")=$S($L(TYPE("ACTION")):1,1:0) | 
|---|
| 174 | .S EVENT("REVIEW STATUS")=TYPE("REVIEW") | 
|---|
| 175 | .S EVENT("MSG ID")=$G(HL7MSGID) | 
|---|
| 176 | .S MSGIEN=$$MSGIEN^HLEMU($G(HL7MSGID)) | 
|---|
| 177 | .I MSGIEN D | 
|---|
| 178 | ..S EVENT("MSG TYPE")=$$MSGTYPE^HLEMU(MSGIEN) | 
|---|
| 179 | ..S EVENT("MSG EVENT")=$$HL7EVENT^HLEMU(MSGIEN) | 
|---|
| 180 | ..S EVENT("MSG LINK")=$P($$LINK^HLEMU(MSGIEN),"^",2) | 
|---|
| 181 | ..S EVENT("APPLICATION")=$$APP^HLEMU(MSGIEN) | 
|---|
| 182 | .E  D | 
|---|
| 183 | ..S EVENT("MSG TYPE")="" | 
|---|
| 184 | ..S EVENT("MSG EVENT")="" | 
|---|
| 185 | ..S EVENT("MSG LINK")="" | 
|---|
| 186 | ..S EVENT("APPLICATION")="" | 
|---|
| 187 | .S EVENT("COUNT")=1 | 
|---|
| 188 | .S EVENT("URGENT")=TYPE("URGENT") | 
|---|
| 189 | .S EVENT("IEN")=$$STORE^HLEME1(.EVENT,.ERROR) | 
|---|
| 190 | .I EVENT("IEN"),$O(TYPE("DOMAIN",0)) S ^HLEV(776.4,"AK",NOW,EVENT("IEN"))="" | 
|---|
| 191 | I TYPE("CONGLOMERATE") L -^HLEV(776.4,"AE",EVENT("SITE"),EVENT("TYPE")) | 
|---|
| 192 | Q EVENT("IEN") | 
|---|
| 193 | ; | 
|---|
| 194 | COUNT(EVENT) ; | 
|---|
| 195 | ;given the event ien, returns the value of the COUNT field | 
|---|
| 196 | Q:'$G(EVENT) 0 | 
|---|
| 197 | Q $P($G(^HLEV(776.4,EVENT,0)),"^",11) | 
|---|
| 198 | INC(EVENTIEN,NUMBER) ; | 
|---|
| 199 | ;Desc: given the ien of a conglomerated event, it will increment the count by the given amount and return the new count.  Returns "" on failure. | 
|---|
| 200 | ; | 
|---|
| 201 | Q:'$G(EVENTIEN) "" | 
|---|
| 202 | Q:'$G(NUMBER) "" | 
|---|
| 203 | N COUNT,EVENT | 
|---|
| 204 | L +^HLEV(776.4,EVENTIEN,0):1 | 
|---|
| 205 | Q:'$$GET(EVENTIEN,.EVENT) "" | 
|---|
| 206 | S COUNT=EVENT("COUNT") | 
|---|
| 207 | S $P(^HLEV(776.4,EVENTIEN,0),"^",11)=COUNT+NUMBER | 
|---|
| 208 | D ADDSTAT^HLEMDD(EVENT("DT/TM"),,EVENT("SITE"),EVENT("TYPE"),EVENT("REVIEW STATUS"),NUMBER) | 
|---|
| 209 | L -^HLEV(776.4,EVENTIEN,0) | 
|---|
| 210 | Q (COUNT+NUMBER) | 
|---|
| 211 | ; | 
|---|
| 212 | RSTATUS(EVENT) ; | 
|---|
| 213 | ;given the event ien, returns the value of the REVIEW STATUS field | 
|---|
| 214 | Q:'$G(EVENT) "" | 
|---|
| 215 | Q $P($G(^HLEV(776.4,EVENT,0)),"^",6) | 
|---|
| 216 | ; | 
|---|
| 217 | ADDNOTE(EVENT,NOTE) ; | 
|---|
| 218 | ;Description:  adds a note to the NOTE field of the event | 
|---|
| 219 | ;Input: | 
|---|
| 220 | ;  EVENT - ien of the event | 
|---|
| 221 | ;  NOTE - either: | 
|---|
| 222 | ;         1) A single line to add to the NOTES OR | 
|---|
| 223 | ;    2) An array of lines to add. All descendant nodes will be added. | 
|---|
| 224 | ;Ouput: | 
|---|
| 225 | ;   function value - 1 on success, 0 on failure | 
|---|
| 226 | ; | 
|---|
| 227 | Q:'$G(EVENT) 0 | 
|---|
| 228 | Q:'$L($G(^HLEV(776.4,EVENT,0))) 0 | 
|---|
| 229 | Q:'$D(NOTE) 0 | 
|---|
| 230 | ; | 
|---|
| 231 | N LABEL,I | 
|---|
| 232 | S I=$O(^HLEV(776.4,EVENT,1,9999999),-1)+1 | 
|---|
| 233 | I $L($G(NOTE)) S ^HLEV(776.4,EVENT,1,I,0)=NOTE,I=I+1 | 
|---|
| 234 | S LABEL="NOTE" | 
|---|
| 235 | F  S LABEL=$Q(@LABEL) Q:LABEL=""  S ^HLEV(776.4,EVENT,1,I,0)=@LABEL,I=I+1 | 
|---|
| 236 | S ^HLEV(776.4,EVENT,1,0)="^776.41^"_(I-1)_"^"_(I-1)_"^"_DT | 
|---|
| 237 | Q 1 | 
|---|
| 238 | ; | 
|---|
| 239 | GETNOTES(EVENT,ARRAY) ; | 
|---|
| 240 | ;Description - given an event, returns the note field into an array, local or global | 
|---|
| 241 | ;Input: ARRAY - the name of the array to store the notes, referenced by indirection | 
|---|
| 242 | ;Output: | 
|---|
| 243 | ;  function returns 1 on success, 0 on failure | 
|---|
| 244 | ;  @ARRAY will contain the NOTES, wich is a WP field | 
|---|
| 245 | ; | 
|---|
| 246 | Q:'$L('$G(ARRAY)) 0 | 
|---|
| 247 | Q:'$G(EVENT) 0 | 
|---|
| 248 | K @ARRAY | 
|---|
| 249 | M @ARRAY=^HLEV(776.4,EVENT,1) | 
|---|
| 250 | Q 1 | 
|---|