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

HLEME.m

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