source: WorldVistAEHR/trunk/r/MY_HEALTHEVET-MHV/MHV7TB.m@ 1154

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

initial load of WorldVistAEHR

File size: 3.7 KB
Line 
1MHV7TB ;WAS/GPM - HL7 BOLUS TRANSMITTER ; [12/31/07 6:15pm]
2 ;;1.0;My HealtheVet;**2**;Aug 23, 2005;Build 22
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5 Q
6 ;
7BOLUS(MSGROOT,XMT,HL) ; Build and Transmit large messages in Bolus mode
8 ; Walks message in MSGROOT and transmits multiple response messages
9 ; based on the desired message size in XMT("MAX SIZE").
10 ; Always creates at least one message with at least one record.
11 ; Messages may exceed the maximum size by the size of the last record
12 ; added to the message.
13 ;
14 ; Algorithm:
15 ; Copy original message to temporary storage
16 ; Extract header segments common to all mesages (MSA,QPD,QRD,QAK,etc)
17 ; Determine QAK segment postion if exists
18 ; For each message in the bolus response
19 ; merge in the common header segments
20 ; add segments by walking the original message
21 ; if reach end of orginal message or exceed maximum size
22 ; if QAK exists update with hit counts
23 ; transmit message
24 ;
25 ; Integration Agreements:
26 ; 2164 : GENERATE^HLMA
27 ;
28 ; Input:
29 ; MSGROOT - Global root of message array
30 ; XMT - Transmission parameters
31 ; XMT("PROTOCOL") - Protocol for deferred transmissions
32 ; XMT("BUILDER") - Name/tag of message builder routine
33 ; XMT("MAX SIZE") - Maximum message size
34 ; XMT("BREAK SEGMENT") - Segment that marks new record
35 ; HL - HL7 package array variable
36 ;
37 ; Output: HL7 Messages Transmitted
38 ;
39 N ORGROOT,ORGCNT,MSGHEAD,HEADSIZE,HEADCNT,QAKPOS,QAKSEG,MSGSIZE,MSGCNT,MAXSIZE,HIT,HITTOT,HITREM,CNT,SEG,SEGTYPE,BREAKPT,FS,END,XMIT,HLRSLT,HLP
40 ;
41 D LOG^MHVUL2("TRANSMIT "_$P(XMT("BUILDER"),"^")_" BOLUS","BEGIN","S","DEBUG")
42 ;
43 S ORGROOT="^TMP(""MHV7 BOLUS ROOT"",$J)"
44 M @ORGROOT=@MSGROOT
45 K @MSGROOT
46 S BREAKPT=XMT("BREAK SEGMENT")
47 S MAXSIZE=XMT("MAX SIZE")
48 S QAKPOS=0,QAKSEG=""
49 S HEADCNT=0,HEADSIZE=0,ORGCNT=0
50 S FS=HL("FS") ;field separator
51 ;
52 ; Pull out header segments (MSA,QAK,QPD,QRD,etc)
53 ;-----------------------------------------
54 F D Q:SEG=""!(SEGTYPE=BREAKPT)
55 . S ORGCNT=ORGCNT+1
56 . S SEG=$G(@ORGROOT@(ORGCNT))
57 . Q:SEG=""
58 . S SEGTYPE=$E(SEG,1,3)
59 . Q:SEGTYPE=BREAKPT
60 . S MSGHEAD(ORGCNT)=SEG
61 . S HEADSIZE=HEADSIZE+$L(SEG)
62 . S HEADCNT=HEADCNT+1
63 . I SEGTYPE="QAK" D
64 . . S QAKPOS=ORGCNT
65 . . S QAKSEG=SEG
66 . . S HITTOT=$P(QAKSEG,FS,5)
67 . . S HITREM=HITTOT
68 . . Q
69 . Q
70 ;
71 ; Create and send message bolus messages
72 ;-----------------------------------------
73 S END=0
74 F MSGCNT=1:1 D Q:END
75 . ; Merge in header segments
76 . M @MSGROOT=MSGHEAD
77 . S MSGSIZE=HEADSIZE
78 . S CNT=HEADCNT
79 . S HIT=0,XMIT=0
80 . ; Merge segments into message
81 . F D Q:XMIT!END
82 . . K SEG S SEG=""
83 . . I '$D(@ORGROOT@(ORGCNT)) S END=1 Q
84 . . M SEG=@ORGROOT@(ORGCNT)
85 . . S SEGTYPE=$E(SEG,1,3)
86 . . S MSGSIZE=MSGSIZE+$$SIZE(SEG)
87 . . I SEGTYPE=BREAKPT,MSGSIZE>MAXSIZE,HIT>0 S XMIT=1 Q
88 . . I SEGTYPE=BREAKPT S HIT=HIT+1
89 . . S CNT=CNT+1
90 . . M @MSGROOT@(CNT)=SEG
91 . . S ORGCNT=ORGCNT+1
92 . . Q
93 . ; Update QAK
94 . I QAKPOS D ;Update QAK
95 . . S $P(QAKSEG,FS,6)=HIT ;Hits this payload
96 . . S HITREM=HITREM-HIT
97 . . S $P(QAKSEG,FS,7)=HITREM ;Hits remaining
98 . . S @MSGROOT@(QAKPOS)=QAKSEG
99 . . Q
100 . D LOG^MHVUL2("BOLUS MESSAGE:"_MSGCNT,HIT_" HITS","S","DEBUG")
101 . D LOG^MHVUL2("MESSAGE "_MSGCNT,MSGROOT,"I","DEBUG")
102 . ; Transmit message
103 . D GENERATE^HLMA(XMT("PROTOCOL"),"GM",1,.HLRSLT,"",.HLP)
104 . K @MSGROOT
105 . D LOG^MHVUL2("TRANSMIT MESSAGE:"_MSGCNT,.HLRSLT,"M","DEBUG")
106 . Q
107 ;
108 K @ORGROOT
109 D LOG^MHVUL2("TRANSMIT "_$P(XMT("BUILDER"),"^")_" BOLUS","END","S","DEBUG")
110 Q
111 ;
112SIZE(SEG) ; Calculate the size of a segment
113 N LEN,I
114 S LEN=$L(SEG)
115 S I="" F S I=$O(SEG(I)) Q:I="" S LEN=LEN+$L(SEG(I))
116 Q LEN
117 ;
Note: See TracBrowser for help on using the repository browser.