HLOCLNT2 ;ALB/CJM- Performs message updates for the client - 10/4/94 1pm ;09/13/2006
;;1.6;HEALTH LEVEL SEVEN;**126,130,131,133**;Oct 13, 1995;Build 13
;Per VHA Directive 2004-038, this routine should not be modified.
;
GETWORK(WORK) ;
;
N OLD,DOLLARJ,SUCCESS,NOW
S SUCCESS=0
S NOW=$$NOW^XLFDT
S (OLD,DOLLARJ)=$G(WORK("DOLLARJ"))
F S DOLLARJ=$O(^HLTMP("CLIENT UPDATES",DOLLARJ)) Q:DOLLARJ="" D Q:SUCCESS
.L +^HLTMP("CLIENT UPDATES",DOLLARJ):0
.Q:'$T
.N TIME S TIME=$O(^HLTMP("CLIENT UPDATES",DOLLARJ,""))
.I $$FMDIFF^XLFDT(NOW,TIME,2)<2 L -^HLTMP("CLIENT UPDATES",DOLLARJ) Q
.S SUCCESS=1
;
I OLD'="",'SUCCESS F S DOLLARJ=$O(^HLTMP("CLIENT UPDATES",DOLLARJ)) Q:DOLLARJ="" Q:DOLLARJ>OLD D Q:SUCCESS
.L +^HLTMP("CLIENT UPDATES",DOLLARJ):0
.Q:'$T
.N TIME S TIME=$O(^HLTMP("CLIENT UPDATES",DOLLARJ,""))
.I $$FMDIFF^XLFDT(NOW,TIME,2)<2 L -^HLTMP("CLIENT UPDATES",DOLLARJ) Q
.S SUCCESS=1
S WORK("DOLLARJ")=DOLLARJ,WORK("NOW")=NOW
Q $S($L(WORK("DOLLARJ")):1,1:0)
;
DOWORK(WORK) ;
;
N DOLLARJ,TIME,IEN,PARMS,SYSTEM
S TIME=""
S DOLLARJ=WORK("DOLLARJ")
D SYSPARMS^HLOSITE(.SYSTEM)
F S TIME=$O(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME)) Q:TIME="" Q:$$FMDIFF^XLFDT(WORK("NOW"),TIME,2)<2 D
.S IEN=0
.F S IEN=$O(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN)) Q:'IEN D
..N NODE
..S NODE=$G(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN))
..S PARMS("LINK")=$P(NODE,"^")
..S PARMS("QUEUE")=$P(NODE,"^",2)
..S PARMS("STATUS")=$P(NODE,"^",3)
..S PARMS("PURGE TYPE")=$P(NODE,"^",4)
..S PARMS("ACK TO IEN")=+$P($P(NODE,"^",4),"-",2)
..S PARMS("ACCEPT ACK")=$P(NODE,"^",5)
..S PARMS("RECEIVING APP")=$P(NODE,"^",6)
..S:PARMS("RECEIVING APP")="" PARMS("RECEIVING APP")="UNKNOWN RECEIVING APPLICATION"
..S PARMS("MSA")=$G(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN,"MSA"))
..S PARMS("ACTION")=$G(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN,"ACTION"))
..D UPDATE(IEN,TIME,.PARMS)
..K ^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN)
L -^HLTMP("CLIENT UPDATES",DOLLARJ)
Q
;
UPDATE(MSGIEN,TIME,PARMS) ;
S:PARMS("STATUS")]"" $P(^HLB(MSGIEN,0),"^",20)=PARMS("STATUS")
S:PARMS("STATUS")="SE" ^HLB("ERRORS","SE",PARMS("RECEIVING APP"),TIME,MSGIEN)=""
S:PARMS("STATUS")="AE" ^HLB("ERRORS","AE",PARMS("RECEIVING APP"),TIME,MSGIEN_"^")=""
S:PARMS("ACCEPT ACK") $P(^HLB(MSGIEN,0),"^",17)=PARMS("ACCEPT ACK")
S $P(^HLB(MSGIEN,0),"^",16)=TIME
S:PARMS("MSA")]"" ^HLB(MSGIEN,4)=TIME_"^"_PARMS("MSA")
I PARMS("PURGE TYPE"),PARMS("ACTION")="" D
.;don't set purge if going on the infiler - let infiler do it
.N PTIME
.S:(PARMS("PURGE TYPE")=2) PTIME=$$FMADD^XLFDT(TIME,SYSTEM("ERROR PURGE")) ;error purge is in days
.S:(PARMS("PURGE TYPE")'=2) PTIME=$$FMADD^XLFDT(TIME,,SYSTEM("NORMAL PURGE")) ;normal purge is in hours
.S $P(^HLB(MSGIEN,0),"^",9)=PTIME,^HLB("AD","OUT",PTIME,MSGIEN)=""
.I PARMS("ACK TO IEN"),$D(^HLB(PARMS("ACK TO IEN"),0)) S $P(^HLB(PARMS("ACK TO IEN"),0),"^",9)=PTIME,^HLB("AD","OUT",PTIME,PARMS("ACK TO IEN"))=""
D:PARMS("ACTION")]""
.N PURGE
.S PURGE=$S(PARMS("PURGE TYPE"):1,1:0)
.S:PARMS("ACK TO IEN") PURGE("ACKTOIEN")=PARMS("ACK TO IEN")
.D INQUE^HLOQUE(PARMS("LINK"),PARMS("QUEUE"),MSGIEN,PARMS("ACTION"),.PURGE)
Q
;
GETMSG(IEN,MSG) ;
;
;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
;Input:
; IEN - the ien of the message in file 778
;Output:
; Function returns 1 on success, 0 on failure
; MSG (pass by reference, required) These are the subscripts returned:
; "ACCEPT ACK RESPONSE" - if the sending app requested notification of the accept ack, this is the routine to perform
; "ACKTOIEN" - if this is an app ack to a message not in a batch, this is the ien of the original message
; "BATCH" = 1 if this is a batch message, 0 if not
; "CURRENT MESSAGE" - defined only for batch messages - a counterused during building and parsing messages to indicate the current message. It will be set to 0 initially.
; "BODY" - ptr to file 778 which contains the body of the message.
; "LINE COUNT" - a counter used during writing of the
; messages to indicate the current line. For
; batch messages where each message within the batch is stored
; separately, this field indicates the position within the current
; individual message
; "HDR" at these lower subscripts:
; 1 - components 1-6
; 2 - components 7-end
; "ACCEPT ACK TYPE" = "AL" or "NE"
; "APP ACK TYPE" = "AL" or "NE"
; "MESSAGE CONTROL ID" - defined if NOT batch
; "BATCH CONTROL ID" - defined if batch
;
; "ID" - message id from the header
; "IEN" - ien, file 778
;
K MSG
Q:'$G(IEN) 0
N NODE,FS,CS,REP,SUBCOMP,ESCAPE
S MSG("IEN")=IEN
S NODE=$G(^HLB(IEN,0))
S MSG("BODY")=$P(NODE,"^",2)
S MSG("ID")=$P(NODE,"^")
Q:'MSG("BODY") 0
S MSG("STATUS","ACCEPTED")=$P(NODE,"^",17)
S MSG("DT/TM")=$P(NODE,"^",16)
S MSG("STATUS","QUEUE")=$P(NODE,"^",6)
I MSG("STATUS","QUEUE")="" S MSG("STATUS","QUEUE")="DEFAULT"
S MSG("ACCEPT ACK RESPONSE")=$P(NODE,"^",12,13)
I MSG("ACCEPT ACK RESPONSE")="^" S MSG("ACCEPT ACK RESPONSE")=""
;
S MSG("BATCH")=+$P($G(^HLA(MSG("BODY"),0)),"^",2)
I MSG("BATCH") D
.S MSG("BATCH","CURRENT MESSAGE")=0
E D
.N ACKTO
.S ACKTO=$P(NODE,"^",3)
.I ACKTO]"" S ACKTO=$$ACKTOIEN^HLOMSG1(MSG("ID"),ACKTO)
.I ACKTO,+ACKTO=ACKTO S MSG("ACK TO IEN")=ACKTO
S MSG("LINE COUNT")=0
S MSG("HDR",1)=$G(^HLB(IEN,1))
S MSG("HDR",2)=$G(^HLB(IEN,2))
S FS=$E(MSG("HDR",1),4)
S CS=$E(MSG("HDR",1),5)
S REP=$E(MSG("HDR",1),6)
S ESCAPE=$E(MSG("HDR",1),7)
S SUBCOMP=$E(MSG("HDR",1),8)
S MSG("HDR","FIELD SEPARATOR")=FS
S MSG("HDR","SENDING APPLICATION")=$$DESCAPE^HLOPRS1($P($P(MSG("HDR",1),FS,3),CS),FS,CS,SUBCOMP,REP,ESCAPE)
S MSG("HDR","RECEIVING APPLICATION")=$$DESCAPE^HLOPRS1($P($P(MSG("HDR",1),FS,5),CS),FS,CS,SUBCOMP,REP,ESCAPE)
I 'MSG("BATCH") D
.S MSG("HDR","MESSAGE TYPE")=$P($P(MSG("HDR",2),FS,4),CS)
.S MSG("HDR","EVENT")=$P($P(MSG("HDR",2),FS,4),CS,2)
.S MSG("HDR","ACCEPT ACK TYPE")=$E($P(MSG("HDR",2),FS,10),1,2)
.S MSG("HDR","APP ACK TYPE")=$E($P(MSG("HDR",2),FS,11),1,2)
.S MSG("HDR","MESSAGE CONTROL ID")=MSG("ID")
E D
.S MSG("HDR","BATCH CONTROL ID")=MSG("ID")
.S MSG("HDR","ACCEPT ACK TYPE")=$E($P($P(MSG("HDR",2),FS,4),"ACCEPT ACK TYPE=",2),1,2)
.S MSG("HDR","APP ACK TYPE")=$E($P($P(MSG("HDR",2),FS,4),"APP ACK TYPE=",2),1,2)
Q 1
HLOCLNT2 ;ALB/CJM- Performs message updates for the client - 10/4/94 1pm ;09/13/2006
+1 ;;1.6;HEALTH LEVEL SEVEN;**126,130,131,133**;Oct 13, 1995;Build 13
+2 ;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
GETWORK(WORK) ;
+1 ;
+2 NEW OLD,DOLLARJ,SUCCESS,NOW
+3 SET SUCCESS=0
+4 SET NOW=$$NOW^XLFDT
+5 SET (OLD,DOLLARJ)=$GET(WORK("DOLLARJ"))
+6 FOR
SET DOLLARJ=$ORDER(^HLTMP("CLIENT UPDATES",DOLLARJ))
IF DOLLARJ=""
QUIT
Begin DoDot:1
+7 LOCK +^HLTMP("CLIENT UPDATES",DOLLARJ):0
+8 IF '$TEST
QUIT
+9 NEW TIME
SET TIME=$ORDER(^HLTMP("CLIENT UPDATES",DOLLARJ,""))
+10 IF $$FMDIFF^XLFDT(NOW,TIME,2)<2
LOCK -^HLTMP("CLIENT UPDATES",DOLLARJ)
QUIT
+11 SET SUCCESS=1
End DoDot:1
IF SUCCESS
QUIT
+12 ;
+13 IF OLD'=""
IF 'SUCCESS
FOR
SET DOLLARJ=$ORDER(^HLTMP("CLIENT UPDATES",DOLLARJ))
IF DOLLARJ=""
QUIT
IF DOLLARJ>OLD
QUIT
Begin DoDot:1
+14 LOCK +^HLTMP("CLIENT UPDATES",DOLLARJ):0
+15 IF '$TEST
QUIT
+16 NEW TIME
SET TIME=$ORDER(^HLTMP("CLIENT UPDATES",DOLLARJ,""))
+17 IF $$FMDIFF^XLFDT(NOW,TIME,2)<2
LOCK -^HLTMP("CLIENT UPDATES",DOLLARJ)
QUIT
+18 SET SUCCESS=1
End DoDot:1
IF SUCCESS
QUIT
+19 SET WORK("DOLLARJ")=DOLLARJ
SET WORK("NOW")=NOW
+20 QUIT $SELECT($LENGTH(WORK("DOLLARJ")):1,1:0)
+21 ;
DOWORK(WORK) ;
+1 ;
+2 NEW DOLLARJ,TIME,IEN,PARMS,SYSTEM
+3 SET TIME=""
+4 SET DOLLARJ=WORK("DOLLARJ")
+5 DO SYSPARMS^HLOSITE(.SYSTEM)
+6 FOR
SET TIME=$ORDER(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME))
IF TIME=""
QUIT
IF $$FMDIFF^XLFDT(WORK("NOW"),TIME,2)<2
QUIT
Begin DoDot:1
+7 SET IEN=0
+8 FOR
SET IEN=$ORDER(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN))
IF 'IEN
QUIT
Begin DoDot:2
+9 NEW NODE
+10 SET NODE=$GET(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN))
+11 SET PARMS("LINK")=$PIECE(NODE,"^")
+12 SET PARMS("QUEUE")=$PIECE(NODE,"^",2)
+13 SET PARMS("STATUS")=$PIECE(NODE,"^",3)
+14 SET PARMS("PURGE TYPE")=$PIECE(NODE,"^",4)
+15 SET PARMS("ACK TO IEN")=+$PIECE($PIECE(NODE,"^",4),"-",2)
+16 SET PARMS("ACCEPT ACK")=$PIECE(NODE,"^",5)
+17 SET PARMS("RECEIVING APP")=$PIECE(NODE,"^",6)
+18 IF PARMS("RECEIVING APP")=""
SET PARMS("RECEIVING APP")="UNKNOWN RECEIVING APPLICATION"
+19 SET PARMS("MSA")=$GET(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN,"MSA"))
+20 SET PARMS("ACTION")=$GET(^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN,"ACTION"))
+21 DO UPDATE(IEN,TIME,.PARMS)
+22 KILL ^HLTMP("CLIENT UPDATES",DOLLARJ,TIME,IEN)
End DoDot:2
End DoDot:1
+23 LOCK -^HLTMP("CLIENT UPDATES",DOLLARJ)
+24 QUIT
+25 ;
UPDATE(MSGIEN,TIME,PARMS) ;
+1 IF PARMS("STATUS")]""
SET $PIECE(^HLB(MSGIEN,0),"^",20)=PARMS("STATUS")
+2 IF PARMS("STATUS")="SE"
SET ^HLB("ERRORS","SE",PARMS("RECEIVING APP"),TIME,MSGIEN)=""
+3 IF PARMS("STATUS")="AE"
SET ^HLB("ERRORS","AE",PARMS("RECEIVING APP"),TIME,MSGIEN_"^")=""
+4 IF PARMS("ACCEPT ACK")
SET $PIECE(^HLB(MSGIEN,0),"^",17)=PARMS("ACCEPT ACK")
+5 SET $PIECE(^HLB(MSGIEN,0),"^",16)=TIME
+6 IF PARMS("MSA")]""
SET ^HLB(MSGIEN,4)=TIME_"^"_PARMS("MSA")
+7 IF PARMS("PURGE TYPE")
IF PARMS("ACTION")=""
Begin DoDot:1
+8 ;don't set purge if going on the infiler - let infiler do it
+9 NEW PTIME
+10 ;error purge is in days
IF (PARMS("PURGE TYPE")=2)
SET PTIME=$$FMADD^XLFDT(TIME,SYSTEM("ERROR PURGE"))
+11 ;normal purge is in hours
IF (PARMS("PURGE TYPE")'=2)
SET PTIME=$$FMADD^XLFDT(TIME,,SYSTEM("NORMAL PURGE"))
+12 SET $PIECE(^HLB(MSGIEN,0),"^",9)=PTIME
SET ^HLB("AD","OUT",PTIME,MSGIEN)=""
+13 IF PARMS("ACK TO IEN")
IF $DATA(^HLB(PARMS("ACK TO IEN"),0))
SET $PIECE(^HLB(PARMS("ACK TO IEN"),0),"^",9)=PTIME
SET ^HLB("AD","OUT",PTIME,PARMS("ACK TO IEN"))=""
End DoDot:1
+14 IF PARMS("ACTION")]""
Begin DoDot:1
+15 NEW PURGE
+16 SET PURGE=$SELECT(PARMS("PURGE TYPE"):1,1:0)
+17 IF PARMS("ACK TO IEN")
SET PURGE("ACKTOIEN")=PARMS("ACK TO IEN")
+18 DO INQUE^HLOQUE(PARMS("LINK"),PARMS("QUEUE"),MSGIEN,PARMS("ACTION"),.PURGE)
End DoDot:1
+19 QUIT
+20 ;
GETMSG(IEN,MSG) ;
+1 ;
+2 ;Description: given the message ien=MSGIEN (required), it returns the MSG array containing information about the message, defined below.
+3 ;Input:
+4 ; IEN - the ien of the message in file 778
+5 ;Output:
+6 ; Function returns 1 on success, 0 on failure
+7 ; MSG (pass by reference, required) These are the subscripts returned:
+8 ; "ACCEPT ACK RESPONSE" - if the sending app requested notification of the accept ack, this is the routine to perform
+9 ; "ACKTOIEN" - if this is an app ack to a message not in a batch, this is the ien of the original message
+10 ; "BATCH" = 1 if this is a batch message, 0 if not
+11 ; "CURRENT MESSAGE" - defined only for batch messages - a counterused during building and parsing messages to indicate the current message. It will be set to 0 initially.
+12 ; "BODY" - ptr to file 778 which contains the body of the message.
+13 ; "LINE COUNT" - a counter used during writing of the
+14 ; messages to indicate the current line. For
+15 ; batch messages where each message within the batch is stored
+16 ; separately, this field indicates the position within the current
+17 ; individual message
+18 ; "HDR" at these lower subscripts:
+19 ; 1 - components 1-6
+20 ; 2 - components 7-end
+21 ; "ACCEPT ACK TYPE" = "AL" or "NE"
+22 ; "APP ACK TYPE" = "AL" or "NE"
+23 ; "MESSAGE CONTROL ID" - defined if NOT batch
+24 ; "BATCH CONTROL ID" - defined if batch
+25 ;
+26 ; "ID" - message id from the header
+27 ; "IEN" - ien, file 778
+28 ;
+29 KILL MSG
+30 IF '$GET(IEN)
QUIT 0
+31 NEW NODE,FS,CS,REP,SUBCOMP,ESCAPE
+32 SET MSG("IEN")=IEN
+33 SET NODE=$GET(^HLB(IEN,0))
+34 SET MSG("BODY")=$PIECE(NODE,"^",2)
+35 SET MSG("ID")=$PIECE(NODE,"^")
+36 IF 'MSG("BODY")
QUIT 0
+37 SET MSG("STATUS","ACCEPTED")=$PIECE(NODE,"^",17)
+38 SET MSG("DT/TM")=$PIECE(NODE,"^",16)
+39 SET MSG("STATUS","QUEUE")=$PIECE(NODE,"^",6)
+40 IF MSG("STATUS","QUEUE")=""
SET MSG("STATUS","QUEUE")="DEFAULT"
+41 SET MSG("ACCEPT ACK RESPONSE")=$PIECE(NODE,"^",12,13)
+42 IF MSG("ACCEPT ACK RESPONSE")="^"
SET MSG("ACCEPT ACK RESPONSE")=""
+43 ;
+44 SET MSG("BATCH")=+$PIECE($GET(^HLA(MSG("BODY"),0)),"^",2)
+45 IF MSG("BATCH")
Begin DoDot:1
+46 SET MSG("BATCH","CURRENT MESSAGE")=0
End DoDot:1
+47 IF '$TEST
Begin DoDot:1
+48 NEW ACKTO
+49 SET ACKTO=$PIECE(NODE,"^",3)
+50 IF ACKTO]""
SET ACKTO=$$ACKTOIEN^HLOMSG1(MSG("ID"),ACKTO)
+51 IF ACKTO
IF +ACKTO=ACKTO
SET MSG("ACK TO IEN")=ACKTO
End DoDot:1
+52 SET MSG("LINE COUNT")=0
+53 SET MSG("HDR",1)=$GET(^HLB(IEN,1))
+54 SET MSG("HDR",2)=$GET(^HLB(IEN,2))
+55 SET FS=$EXTRACT(MSG("HDR",1),4)
+56 SET CS=$EXTRACT(MSG("HDR",1),5)
+57 SET REP=$EXTRACT(MSG("HDR",1),6)
+58 SET ESCAPE=$EXTRACT(MSG("HDR",1),7)
+59 SET SUBCOMP=$EXTRACT(MSG("HDR",1),8)
+60 SET MSG("HDR","FIELD SEPARATOR")=FS
+61 SET MSG("HDR","SENDING APPLICATION")=$$DESCAPE^HLOPRS1($PIECE($PIECE(MSG("HDR",1),FS,3),CS),FS,CS,SUBCOMP,REP,ESCAPE)
+62 SET MSG("HDR","RECEIVING APPLICATION")=$$DESCAPE^HLOPRS1($PIECE($PIECE(MSG("HDR",1),FS,5),CS),FS,CS,SUBCOMP,REP,ESCAPE)
+63 IF 'MSG("BATCH")
Begin DoDot:1
+64 SET MSG("HDR","MESSAGE TYPE")=$PIECE($PIECE(MSG("HDR",2),FS,4),CS)
+65 SET MSG("HDR","EVENT")=$PIECE($PIECE(MSG("HDR",2),FS,4),CS,2)
+66 SET MSG("HDR","ACCEPT ACK TYPE")=$EXTRACT($PIECE(MSG("HDR",2),FS,10),1,2)
+67 SET MSG("HDR","APP ACK TYPE")=$EXTRACT($PIECE(MSG("HDR",2),FS,11),1,2)
+68 SET MSG("HDR","MESSAGE CONTROL ID")=MSG("ID")
End DoDot:1
+69 IF '$TEST
Begin DoDot:1
+70 SET MSG("HDR","BATCH CONTROL ID")=MSG("ID")
+71 SET MSG("HDR","ACCEPT ACK TYPE")=$EXTRACT($PIECE($PIECE(MSG("HDR",2),FS,4),"ACCEPT ACK TYPE=",2),1,2)
+72 SET MSG("HDR","APP ACK TYPE")=$EXTRACT($PIECE($PIECE(MSG("HDR",2),FS,4),"APP ACK TYPE=",2),1,2)
End DoDot:1
+73 QUIT 1