- HLEME ;ALB/CJM-HL7 - APIs for Monitor Events ;02/04/2004
- ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
- ;
- GET(IEN,EVENT) ;
- ;Desc: given the ien, it returns an array containing the event. Does NOT include the NOTES field or the Application Data
- ;Input:
- ; IEN - ien of event
- ;Output:
- ; function returns 0 on failure, 1 on success
- ; EVENT( ***pass by reference***
- ; "ACTION STATUS"
- ; "APPLICATION" - the sending application, only if the event is related to an HL7 message
- ; "COUNT" - the number of discrete events included in this event - for conglomerated events
- ; "DT/TM" - date/time of the event
- ; "DT/TM ACTION" - for automated action
- ; "DT/TM CREATED" - time stamp for this event
- ; "DT/TM REVIEWED" -
- ; "ID" - unique identifier
- ; "IEN" -the ien
- ; "MAIL",<msg ien>)=<msg ien> - list of Mailman messages
- ; "MSGID ID" - mssage id of message causing this event (if any)
- ; "MSG TYPE" - HL7 message type code
- ; "MSG EVENT" - HL7 event type code
- ; "MSG LINK" - name of the HL Logical Link (NODE) on which the mssg was sent
- ; "REVIEWER" - ien in New Person file
- ; "REVIEW STATUS"
- ; "SITE" - site of occurence, a pointer to the Institution file
- ; "TYPE" - the type of event, an ien of a HL7 Monitor Event Type
- ; "URGENT" - flag for urgency
- ;
- ;
- Q:'$G(IEN) 0
- N NODE,I,LABEL
- K EVENT
- S EVENT("IEN")=IEN
- S NODE=$G(^HLEV(776.4,IEN,0))
- Q:'$L(NODE) 0
- S EVENT("DT/TM")=$P(NODE,"^")
- S EVENT("TYPE")=$P(NODE,"^",2)
- S EVENT("SITE")=$P(NODE,"^",3)
- S EVENT("ID")=$P(NODE,"^",4)
- S EVENT("ACTION STATUS")=$P(NODE,"^",5)
- S EVENT("REVIEW STATUS")=$P(NODE,"^",6)
- S EVENT("DT/TM REVIEWED")=$P(NODE,"^",7)
- S EVENT("REVIEWER")=$P(NODE,"^",8)
- S EVENT("DT/TM ACTION")=$P(NODE,"^",9)
- S EVENT("MSG ID")=$P(NODE,"^",10)
- S EVENT("MSG TYPE")=$P(NODE,"^",13)
- S EVENT("MSG EVENT")=$P(NODE,"^",14)
- S EVENT("MSG LINK")=$P(NODE,"^",15)
- S EVENT("DT/TM CREATED")=$P(NODE,"^",17)
- S EVENT("APPLICATION")=$P(NODE,"^",16)
- S EVENT("COUNT")=$P(NODE,"^",11)
- S EVENT("URGENT")=$P(NODE,"^",12)
- 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
- Q 1
- ;
- STOREVAR(EVENT,APPDATA,VAR) ;
- ;Desc: Allows an app. to store its own application-specific data.
- ;Input:
- ; EVENT - ien of event
- ; APPDATA - variable or array to store **for arrays, pass by reference**
- ; VAR - **optional** - variable name, may inlucde subscripts.Required if the application needs to store multiple variables or arrays. VAR="APPDATA"is the default
- ;Output:
- ; function reuturns 1 on success,0 on failure
- ;Ex 1
- ; An app. needs to store a single set of data with the
- ; event. It could set the data into an array call
- ; $$STOREVAR(EVENT,.MYARRAY) To get back the
- ; data it would call $$GETVAR(EVENT,.MYARRAY). (any variable name could have been used instead of MYARRAY.
- ;Ex 2
- ; An application needs to store multiple sets of data with the
- ; the event. It could accomplish that by setting the data into
- ; multiple arrays, say DATA1,DATA2,DATA3,... and calling
- ; $$STOREVAR(EVENT,.DATA1,"DATA1"), then $$STOREVAR(EVENT,.DATA2,"DATA2"),etc.
- ; To get back the named datasets the application would call
- ; $$GETVAR(EVENT,.DATA1,"DATA1"), $$GETVAR(EVENT,.DATA2,"DATA2"),
- ; etc.
- ;
- Q:'$G(EVENT) 0
- Q:'$D(^HLEV(776.4,EVENT,0)) 0
- Q:'$D(APPDATA) 0
- ;
- N I,LABEL
- S I=+$O(^HLEV(776.4,EVENT,3,999999999),-1)
- I $L($G(VAR)) N @VAR D
- .S LABEL=VAR
- .M @VAR=APPDATA
- E D
- .S LABEL="APPDATA"
- ;
- ;check if the root has data, if so, store it
- I $D(@LABEL)'[0 D
- .N OLDIEN
- .S OLDIEN=$O(^HLEV(776.4,EVENT,3,"B",LABEL,0))
- .I OLDIEN D
- ..K ^HLEV(776.4,EVENT,"B",LABEL,OLDIEN),^HLEV(776.4,EVENT,3,OLDIEN)
- .E D
- ..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
- ;
- ;now store everything that comes below it
- F S LABEL=$Q(@LABEL) Q:LABEL="" D
- .;can't go over a total lenth of 230
- .Q:'$L(LABEL)>230
- .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
- ;
- ;write the 0-node
- S ^HLEV(776.4,EVENT,3,0)="^776.43^"_I_"^"_I
- ;
- Q 1
- ;
- GETVAR(EVENT,APPDATA,VAR) ;
- ;Desc: Used to retrieve application-specific data that was stored along with the event.
- ;Input:
- ; EVENT - ien of the event
- ; VAR - name of the variable or array to fetch. If not passed, "APPDATA" is assumed, which is also the default when calling $$STOREVAR()
- ;Output
- ; function value - 1 on success, 0 on failure
- ; APPDATA() - used to return the requested data **pass by reference**
- ;
- Q:'$G(EVENT) 0
- Q:'$L($G(^HLEV(776.4,EVENT,0))) 0
- ;
- N INDEX,I,LABEL,VAR2
- K APPDATA
- S INDEX="^HLEV(776.4,EVENT,3)"
- S:'$L($G(VAR)) VAR="APPDATA"
- S VAR2=$O(@INDEX@("B",VAR),-1)
- 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))
- ;
- M APPDATA=@VAR
- Q 1
- ;
- EVENT(CODE,PACKAGE,HL7MSGID,SITE,WHEN,ERROR) ;
- ;Desc: API for applications to notify HL7 Event Monitor of their events
- ;Input:
- ; CODE - the code (.01 field) for the HL7 Monitor Event Type
- ; PACKAGE - the name of the package that created the HL7 Monitor Event Type, used to find the event type ien.
- ; HL7MSGID - **optional** - if the event pertains to a specific message, this should be passed
- ; SITE - **optional** - the station number, including any suffix, where the event occured. Will assume the local site if not passed in.
- ; WHEN - **optional** - FM date/time of when the event occurred. Will assume now if not passed in.
- ;Output:
- ; function value - ien of the event (file 776.4) on success, 0 on failure
- ; ERROR - **optional, pass by reference** - array of error messages
- ;
- N EVENT,TYPE,MSGIEN,NOW
- S EVENT("TYPE")=$$FIND^HLEMT(.CODE,.PACKAGE)
- I 'EVENT("TYPE") S ERROR(1)="UNKNOWN EVENT TYPE" Q 0
- I '$L($G(SITE)) D
- .S EVENT("SITE")=+$P($$SITE^VASITE(),"^")
- E D
- .S EVENT("SITE")=$$LKUP^XUAF4(SITE)
- I 'EVENT("SITE") S ERROR(1)="UNKNOWN SITE" Q 0
- S NOW=$$NOW^XLFDT
- S EVENT("DT/TM")=$S('$G(WHEN):NOW,1:WHEN)
- S EVENT("DT/TM CREATED")=NOW
- ;
- ;get the event type array
- I '$$GET^HLEMT(EVENT("TYPE"),.TYPE) S ERROR(1)="UNKNOWN EVENT TYPE" Q 0
- ;
- ;is this event type active?
- I 'TYPE("ACTIVE") S ERROR(1)="INACTIVE EVENT TYPE" Q 0
- ;
- ;check if this is a conglomerated event that can be added to an existing event
- I TYPE("CONGLOMERATE") D
- .L +^HLEV(776.4,"AE",EVENT("SITE"),EVENT("TYPE")):2
- .S EVENT("IEN")=$$ADD^HLEME1(EVENT("SITE"),EVENT("TYPE"),EVENT("DT/TM"))
- ;
- I '$G(EVENT("IEN")) D
- .;
- .;otherwise, create and store a new event
- .S EVENT("ACTION STATUS")=$S($L(TYPE("ACTION")):1,1:0)
- .S EVENT("REVIEW STATUS")=TYPE("REVIEW")
- .S EVENT("MSG ID")=$G(HL7MSGID)
- .S MSGIEN=$$MSGIEN^HLEMU($G(HL7MSGID))
- .I MSGIEN D
- ..S EVENT("MSG TYPE")=$$MSGTYPE^HLEMU(MSGIEN)
- ..S EVENT("MSG EVENT")=$$HL7EVENT^HLEMU(MSGIEN)
- ..S EVENT("MSG LINK")=$P($$LINK^HLEMU(MSGIEN),"^",2)
- ..S EVENT("APPLICATION")=$$APP^HLEMU(MSGIEN)
- .E D
- ..S EVENT("MSG TYPE")=""
- ..S EVENT("MSG EVENT")=""
- ..S EVENT("MSG LINK")=""
- ..S EVENT("APPLICATION")=""
- .S EVENT("COUNT")=1
- .S EVENT("URGENT")=TYPE("URGENT")
- .S EVENT("IEN")=$$STORE^HLEME1(.EVENT,.ERROR)
- .I EVENT("IEN"),$O(TYPE("DOMAIN",0)) S ^HLEV(776.4,"AK",NOW,EVENT("IEN"))=""
- I TYPE("CONGLOMERATE") L -^HLEV(776.4,"AE",EVENT("SITE"),EVENT("TYPE"))
- Q EVENT("IEN")
- ;
- COUNT(EVENT) ;
- ;given the event ien, returns the value of the COUNT field
- Q:'$G(EVENT) 0
- Q $P($G(^HLEV(776.4,EVENT,0)),"^",11)
- INC(EVENTIEN,NUMBER) ;
- ;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.
- ;
- Q:'$G(EVENTIEN) ""
- Q:'$G(NUMBER) ""
- N COUNT,EVENT
- L +^HLEV(776.4,EVENTIEN,0):1
- Q:'$$GET(EVENTIEN,.EVENT) ""
- S COUNT=EVENT("COUNT")
- S $P(^HLEV(776.4,EVENTIEN,0),"^",11)=COUNT+NUMBER
- D ADDSTAT^HLEMDD(EVENT("DT/TM"),,EVENT("SITE"),EVENT("TYPE"),EVENT("REVIEW STATUS"),NUMBER)
- L -^HLEV(776.4,EVENTIEN,0)
- Q (COUNT+NUMBER)
- ;
- RSTATUS(EVENT) ;
- ;given the event ien, returns the value of the REVIEW STATUS field
- Q:'$G(EVENT) ""
- Q $P($G(^HLEV(776.4,EVENT,0)),"^",6)
- ;
- ADDNOTE(EVENT,NOTE) ;
- ;Description: adds a note to the NOTE field of the event
- ;Input:
- ; EVENT - ien of the event
- ; NOTE - either:
- ; 1) A single line to add to the NOTES OR
- ; 2) An array of lines to add. All descendant nodes will be added.
- ;Ouput:
- ; function value - 1 on success, 0 on failure
- ;
- Q:'$G(EVENT) 0
- Q:'$L($G(^HLEV(776.4,EVENT,0))) 0
- Q:'$D(NOTE) 0
- ;
- N LABEL,I
- S I=$O(^HLEV(776.4,EVENT,1,9999999),-1)+1
- I $L($G(NOTE)) S ^HLEV(776.4,EVENT,1,I,0)=NOTE,I=I+1
- S LABEL="NOTE"
- F S LABEL=$Q(@LABEL) Q:LABEL="" S ^HLEV(776.4,EVENT,1,I,0)=@LABEL,I=I+1
- S ^HLEV(776.4,EVENT,1,0)="^776.41^"_(I-1)_"^"_(I-1)_"^"_DT
- Q 1
- ;
- GETNOTES(EVENT,ARRAY) ;
- ;Description - given an event, returns the note field into an array, local or global
- ;Input: ARRAY - the name of the array to store the notes, referenced by indirection
- ;Output:
- ; function returns 1 on success, 0 on failure
- ; @ARRAY will contain the NOTES, wich is a WP field
- ;
- Q:'$L('$G(ARRAY)) 0
- Q:'$G(EVENT) 0
- K @ARRAY
- M @ARRAY=^HLEV(776.4,EVENT,1)
- Q 1
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHLEME 9446 printed Feb 18, 2025@23:23:48 Page 2
- HLEME ;ALB/CJM-HL7 - APIs for Monitor Events ;02/04/2004
- +1 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
- +2 ;
- GET(IEN,EVENT) ;
- +1 ;Desc: given the ien, it returns an array containing the event. Does NOT include the NOTES field or the Application Data
- +2 ;Input:
- +3 ; IEN - ien of event
- +4 ;Output:
- +5 ; function returns 0 on failure, 1 on success
- +6 ; EVENT( ***pass by reference***
- +7 ; "ACTION STATUS"
- +8 ; "APPLICATION" - the sending application, only if the event is related to an HL7 message
- +9 ; "COUNT" - the number of discrete events included in this event - for conglomerated events
- +10 ; "DT/TM" - date/time of the event
- +11 ; "DT/TM ACTION" - for automated action
- +12 ; "DT/TM CREATED" - time stamp for this event
- +13 ; "DT/TM REVIEWED" -
- +14 ; "ID" - unique identifier
- +15 ; "IEN" -the ien
- +16 ; "MAIL",<msg ien>)=<msg ien> - list of Mailman messages
- +17 ; "MSGID ID" - mssage id of message causing this event (if any)
- +18 ; "MSG TYPE" - HL7 message type code
- +19 ; "MSG EVENT" - HL7 event type code
- +20 ; "MSG LINK" - name of the HL Logical Link (NODE) on which the mssg was sent
- +21 ; "REVIEWER" - ien in New Person file
- +22 ; "REVIEW STATUS"
- +23 ; "SITE" - site of occurence, a pointer to the Institution file
- +24 ; "TYPE" - the type of event, an ien of a HL7 Monitor Event Type
- +25 ; "URGENT" - flag for urgency
- +26 ;
- +27 ;
- +28 if '$GET(IEN)
- QUIT 0
- +29 NEW NODE,I,LABEL
- +30 KILL EVENT
- +31 SET EVENT("IEN")=IEN
- +32 SET NODE=$GET(^HLEV(776.4,IEN,0))
- +33 if '$LENGTH(NODE)
- QUIT 0
- +34 SET EVENT("DT/TM")=$PIECE(NODE,"^")
- +35 SET EVENT("TYPE")=$PIECE(NODE,"^",2)
- +36 SET EVENT("SITE")=$PIECE(NODE,"^",3)
- +37 SET EVENT("ID")=$PIECE(NODE,"^",4)
- +38 SET EVENT("ACTION STATUS")=$PIECE(NODE,"^",5)
- +39 SET EVENT("REVIEW STATUS")=$PIECE(NODE,"^",6)
- +40 SET EVENT("DT/TM REVIEWED")=$PIECE(NODE,"^",7)
- +41 SET EVENT("REVIEWER")=$PIECE(NODE,"^",8)
- +42 SET EVENT("DT/TM ACTION")=$PIECE(NODE,"^",9)
- +43 SET EVENT("MSG ID")=$PIECE(NODE,"^",10)
- +44 SET EVENT("MSG TYPE")=$PIECE(NODE,"^",13)
- +45 SET EVENT("MSG EVENT")=$PIECE(NODE,"^",14)
- +46 SET EVENT("MSG LINK")=$PIECE(NODE,"^",15)
- +47 SET EVENT("DT/TM CREATED")=$PIECE(NODE,"^",17)
- +48 SET EVENT("APPLICATION")=$PIECE(NODE,"^",16)
- +49 SET EVENT("COUNT")=$PIECE(NODE,"^",11)
- +50 SET EVENT("URGENT")=$PIECE(NODE,"^",12)
- +51 SET I=0
- FOR
- SET I=$ORDER(^HLEV(776.4,IEN,2,I))
- if 'I
- QUIT
- SET NODE=+$GET(^HLEV(776.4,IEN,2,I,0))
- IF NODE
- SET EVENT("MAIL",NODE)=NODE
- +52 QUIT 1
- +53 ;
- STOREVAR(EVENT,APPDATA,VAR) ;
- +1 ;Desc: Allows an app. to store its own application-specific data.
- +2 ;Input:
- +3 ; EVENT - ien of event
- +4 ; APPDATA - variable or array to store **for arrays, pass by reference**
- +5 ; VAR - **optional** - variable name, may inlucde subscripts.Required if the application needs to store multiple variables or arrays. VAR="APPDATA"is the default
- +6 ;Output:
- +7 ; function reuturns 1 on success,0 on failure
- +8 ;Ex 1
- +9 ; An app. needs to store a single set of data with the
- +10 ; event. It could set the data into an array call
- +11 ; $$STOREVAR(EVENT,.MYARRAY) To get back the
- +12 ; data it would call $$GETVAR(EVENT,.MYARRAY). (any variable name could have been used instead of MYARRAY.
- +13 ;Ex 2
- +14 ; An application needs to store multiple sets of data with the
- +15 ; the event. It could accomplish that by setting the data into
- +16 ; multiple arrays, say DATA1,DATA2,DATA3,... and calling
- +17 ; $$STOREVAR(EVENT,.DATA1,"DATA1"), then $$STOREVAR(EVENT,.DATA2,"DATA2"),etc.
- +18 ; To get back the named datasets the application would call
- +19 ; $$GETVAR(EVENT,.DATA1,"DATA1"), $$GETVAR(EVENT,.DATA2,"DATA2"),
- +20 ; etc.
- +21 ;
- +22 if '$GET(EVENT)
- QUIT 0
- +23 if '$DATA(^HLEV(776.4,EVENT,0))
- QUIT 0
- +24 if '$DATA(APPDATA)
- QUIT 0
- +25 ;
- +26 NEW I,LABEL
- +27 SET I=+$ORDER(^HLEV(776.4,EVENT,3,999999999),-1)
- +28 IF $LENGTH($GET(VAR))
- NEW @VAR
- Begin DoDot:1
- +29 SET LABEL=VAR
- +30 MERGE @VAR=APPDATA
- End DoDot:1
- +31 IF '$TEST
- Begin DoDot:1
- +32 SET LABEL="APPDATA"
- End DoDot:1
- +33 ;
- +34 ;check if the root has data, if so, store it
- +35 IF $DATA(@LABEL)'[0
- Begin DoDot:1
- +36 NEW OLDIEN
- +37 SET OLDIEN=$ORDER(^HLEV(776.4,EVENT,3,"B",LABEL,0))
- +38 IF OLDIEN
- Begin DoDot:2
- +39 KILL ^HLEV(776.4,EVENT,"B",LABEL,OLDIEN),^HLEV(776.4,EVENT,3,OLDIEN)
- End DoDot:2
- +40 IF '$TEST
- Begin DoDot:2
- +41 SET I=I+1
- End DoDot:2
- +42 SET ^HLEV(776.4,EVENT,3,I,0)=LABEL
- SET ^HLEV(776.4,EVENT,3,I,2)=@LABEL
- SET ^HLEV(776.4,EVENT,3,"B",LABEL,I)=0
- End DoDot:1
- +43 ;
- +44 ;now store everything that comes below it
- +45 FOR
- SET LABEL=$QUERY(@LABEL)
- if LABEL=""
- QUIT
- Begin DoDot:1
- +46 ;can't go over a total lenth of 230
- +47 if '$LENGTH(LABEL)>230
- QUIT
- +48 SET I=I+1
- SET ^HLEV(776.4,EVENT,3,I,0)=LABEL
- SET ^HLEV(776.4,EVENT,3,I,2)=@LABEL
- SET ^HLEV(776.4,EVENT,3,"B",LABEL,I)=0
- End DoDot:1
- +49 ;
- +50 ;write the 0-node
- +51 SET ^HLEV(776.4,EVENT,3,0)="^776.43^"_I_"^"_I
- +52 ;
- +53 QUIT 1
- +54 ;
- GETVAR(EVENT,APPDATA,VAR) ;
- +1 ;Desc: Used to retrieve application-specific data that was stored along with the event.
- +2 ;Input:
- +3 ; EVENT - ien of the event
- +4 ; VAR - name of the variable or array to fetch. If not passed, "APPDATA" is assumed, which is also the default when calling $$STOREVAR()
- +5 ;Output
- +6 ; function value - 1 on success, 0 on failure
- +7 ; APPDATA() - used to return the requested data **pass by reference**
- +8 ;
- +9 if '$GET(EVENT)
- QUIT 0
- +10 if '$LENGTH($GET(^HLEV(776.4,EVENT,0)))
- QUIT 0
- +11 ;
- +12 NEW INDEX,I,LABEL,VAR2
- +13 KILL APPDATA
- +14 SET INDEX="^HLEV(776.4,EVENT,3)"
- +15 if '$LENGTH($GET(VAR))
- SET VAR="APPDATA"
- +16 SET VAR2=$ORDER(@INDEX@("B",VAR),-1)
- +17 FOR
- SET VAR2=$ORDER(@INDEX@("B",VAR2))
- if '$LENGTH(VAR2)
- QUIT
- if (VAR2'[VAR)
- QUIT
- SET I=0
- FOR
- SET I=$ORDER(@INDEX@("B",VAR2,I))
- if 'I
- QUIT
- SET LABEL=$GET(@INDEX@(I,0))
- if LABEL[VAR
- SET @LABEL=$GET(@INDEX@(I,2))
- +18 ;
- +19 MERGE APPDATA=@VAR
- +20 QUIT 1
- +21 ;
- EVENT(CODE,PACKAGE,HL7MSGID,SITE,WHEN,ERROR) ;
- +1 ;Desc: API for applications to notify HL7 Event Monitor of their events
- +2 ;Input:
- +3 ; CODE - the code (.01 field) for the HL7 Monitor Event Type
- +4 ; PACKAGE - the name of the package that created the HL7 Monitor Event Type, used to find the event type ien.
- +5 ; HL7MSGID - **optional** - if the event pertains to a specific message, this should be passed
- +6 ; SITE - **optional** - the station number, including any suffix, where the event occured. Will assume the local site if not passed in.
- +7 ; WHEN - **optional** - FM date/time of when the event occurred. Will assume now if not passed in.
- +8 ;Output:
- +9 ; function value - ien of the event (file 776.4) on success, 0 on failure
- +10 ; ERROR - **optional, pass by reference** - array of error messages
- +11 ;
- +12 NEW EVENT,TYPE,MSGIEN,NOW
- +13 SET EVENT("TYPE")=$$FIND^HLEMT(.CODE,.PACKAGE)
- +14 IF 'EVENT("TYPE")
- SET ERROR(1)="UNKNOWN EVENT TYPE"
- QUIT 0
- +15 IF '$LENGTH($GET(SITE))
- Begin DoDot:1
- +16 SET EVENT("SITE")=+$PIECE($$SITE^VASITE(),"^")
- End DoDot:1
- +17 IF '$TEST
- Begin DoDot:1
- +18 SET EVENT("SITE")=$$LKUP^XUAF4(SITE)
- End DoDot:1
- +19 IF 'EVENT("SITE")
- SET ERROR(1)="UNKNOWN SITE"
- QUIT 0
- +20 SET NOW=$$NOW^XLFDT
- +21 SET EVENT("DT/TM")=$SELECT('$GET(WHEN):NOW,1:WHEN)
- +22 SET EVENT("DT/TM CREATED")=NOW
- +23 ;
- +24 ;get the event type array
- +25 IF '$$GET^HLEMT(EVENT("TYPE"),.TYPE)
- SET ERROR(1)="UNKNOWN EVENT TYPE"
- QUIT 0
- +26 ;
- +27 ;is this event type active?
- +28 IF 'TYPE("ACTIVE")
- SET ERROR(1)="INACTIVE EVENT TYPE"
- QUIT 0
- +29 ;
- +30 ;check if this is a conglomerated event that can be added to an existing event
- +31 IF TYPE("CONGLOMERATE")
- Begin DoDot:1
- +32 LOCK +^HLEV(776.4,"AE",EVENT("SITE"),EVENT("TYPE")):2
- +33 SET EVENT("IEN")=$$ADD^HLEME1(EVENT("SITE"),EVENT("TYPE"),EVENT("DT/TM"))
- End DoDot:1
- +34 ;
- +35 IF '$GET(EVENT("IEN"))
- Begin DoDot:1
- +36 ;
- +37 ;otherwise, create and store a new event
- +38 SET EVENT("ACTION STATUS")=$SELECT($LENGTH(TYPE("ACTION")):1,1:0)
- +39 SET EVENT("REVIEW STATUS")=TYPE("REVIEW")
- +40 SET EVENT("MSG ID")=$GET(HL7MSGID)
- +41 SET MSGIEN=$$MSGIEN^HLEMU($GET(HL7MSGID))
- +42 IF MSGIEN
- Begin DoDot:2
- +43 SET EVENT("MSG TYPE")=$$MSGTYPE^HLEMU(MSGIEN)
- +44 SET EVENT("MSG EVENT")=$$HL7EVENT^HLEMU(MSGIEN)
- +45 SET EVENT("MSG LINK")=$PIECE($$LINK^HLEMU(MSGIEN),"^",2)
- +46 SET EVENT("APPLICATION")=$$APP^HLEMU(MSGIEN)
- End DoDot:2
- +47 IF '$TEST
- Begin DoDot:2
- +48 SET EVENT("MSG TYPE")=""
- +49 SET EVENT("MSG EVENT")=""
- +50 SET EVENT("MSG LINK")=""
- +51 SET EVENT("APPLICATION")=""
- End DoDot:2
- +52 SET EVENT("COUNT")=1
- +53 SET EVENT("URGENT")=TYPE("URGENT")
- +54 SET EVENT("IEN")=$$STORE^HLEME1(.EVENT,.ERROR)
- +55 IF EVENT("IEN")
- IF $ORDER(TYPE("DOMAIN",0))
- SET ^HLEV(776.4,"AK",NOW,EVENT("IEN"))=""
- End DoDot:1
- +56 IF TYPE("CONGLOMERATE")
- LOCK -^HLEV(776.4,"AE",EVENT("SITE"),EVENT("TYPE"))
- +57 QUIT EVENT("IEN")
- +58 ;
- COUNT(EVENT) ;
- +1 ;given the event ien, returns the value of the COUNT field
- +2 if '$GET(EVENT)
- QUIT 0
- +3 QUIT $PIECE($GET(^HLEV(776.4,EVENT,0)),"^",11)
- INC(EVENTIEN,NUMBER) ;
- +1 ;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.
- +2 ;
- +3 if '$GET(EVENTIEN)
- QUIT ""
- +4 if '$GET(NUMBER)
- QUIT ""
- +5 NEW COUNT,EVENT
- +6 LOCK +^HLEV(776.4,EVENTIEN,0):1
- +7 if '$$GET(EVENTIEN,.EVENT)
- QUIT ""
- +8 SET COUNT=EVENT("COUNT")
- +9 SET $PIECE(^HLEV(776.4,EVENTIEN,0),"^",11)=COUNT+NUMBER
- +10 DO ADDSTAT^HLEMDD(EVENT("DT/TM"),,EVENT("SITE"),EVENT("TYPE"),EVENT("REVIEW STATUS"),NUMBER)
- +11 LOCK -^HLEV(776.4,EVENTIEN,0)
- +12 QUIT (COUNT+NUMBER)
- +13 ;
- RSTATUS(EVENT) ;
- +1 ;given the event ien, returns the value of the REVIEW STATUS field
- +2 if '$GET(EVENT)
- QUIT ""
- +3 QUIT $PIECE($GET(^HLEV(776.4,EVENT,0)),"^",6)
- +4 ;
- ADDNOTE(EVENT,NOTE) ;
- +1 ;Description: adds a note to the NOTE field of the event
- +2 ;Input:
- +3 ; EVENT - ien of the event
- +4 ; NOTE - either:
- +5 ; 1) A single line to add to the NOTES OR
- +6 ; 2) An array of lines to add. All descendant nodes will be added.
- +7 ;Ouput:
- +8 ; function value - 1 on success, 0 on failure
- +9 ;
- +10 if '$GET(EVENT)
- QUIT 0
- +11 if '$LENGTH($GET(^HLEV(776.4,EVENT,0)))
- QUIT 0
- +12 if '$DATA(NOTE)
- QUIT 0
- +13 ;
- +14 NEW LABEL,I
- +15 SET I=$ORDER(^HLEV(776.4,EVENT,1,9999999),-1)+1
- +16 IF $LENGTH($GET(NOTE))
- SET ^HLEV(776.4,EVENT,1,I,0)=NOTE
- SET I=I+1
- +17 SET LABEL="NOTE"
- +18 FOR
- SET LABEL=$QUERY(@LABEL)
- if LABEL=""
- QUIT
- SET ^HLEV(776.4,EVENT,1,I,0)=@LABEL
- SET I=I+1
- +19 SET ^HLEV(776.4,EVENT,1,0)="^776.41^"_(I-1)_"^"_(I-1)_"^"_DT
- +20 QUIT 1
- +21 ;
- GETNOTES(EVENT,ARRAY) ;
- +1 ;Description - given an event, returns the note field into an array, local or global
- +2 ;Input: ARRAY - the name of the array to store the notes, referenced by indirection
- +3 ;Output:
- +4 ; function returns 1 on success, 0 on failure
- +5 ; @ARRAY will contain the NOTES, wich is a WP field
- +6 ;
- +7 if '$LENGTH('$GET(ARRAY))
- QUIT 0
- +8 if '$GET(EVENT)
- QUIT 0
- +9 KILL @ARRAY
- +10 MERGE @ARRAY=^HLEV(776.4,EVENT,1)
- +11 QUIT 1