source: FOIAVistA/trunk/r/FEE_BASIS-FB/FBFHLX.m@ 1582

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

initial load of FOIAVistA 6/30/08 version

File size: 7.3 KB
Line 
1FBFHLX ;WOIFO/SAB-TRANSMIT HL7 MESSAGES TO FPPS ;10/8/2003
2 ;;3.5;FEE BASIS;**61**;JULY 18, 2003
3 ;;Per VHA Directive 10-93-142, this routine should not be modified.
4 Q
5 ;
6EN ; Entry Point
7 ; may be called by scheduled option as non-interactive task
8 ; may be called by user menu option as interactive task
9 ;
10 N FBMODE,FBQUIT
11 S FBQUIT=0
12 ;
13 ; Determine Mode - (A)LL PENDING or BY SELECTED (I)NVOICE
14 I $E(IOST,1,2)'="C-" S FBMODE="A" ; non-interactive is always ALL
15 I $E(IOST,1,2)="C-" D
16 . ; ask mode
17 . W !,"This option transmits HL7 messages to FPPS for EDI invoices."
18 . S DIR(0)="S^I:By Specified Invoice;A:All Pending Invoices"
19 . S DIR("A")="Select Transmission Option"
20 . S DIR("?",1)="Enter I to transmit a single invoice or A to transmit"
21 . S DIR("?",2)="all pending invoices. If I is entered then you will be"
22 . S DIR("?",3)="asked to select the invoice."
23 . S DIR("?",4)=""
24 . S DIR("?")="Enter a code from the list."
25 . D ^DIR K DIR I $D(DIRUT) S FBQUIT=1 Q
26 . S FBMODE=Y
27 . ; confirm all
28 . I FBMODE="A" D
29 . . S DIR(0)="Y",DIR("A")="Transmit all pending invoices now"
30 . . D ^DIR K DIR I 'Y!$D(DIRUT) S FBQUIT=1 Q
31 Q:FBQUIT
32 ;
33 I FBMODE="A" D ALL
34 I FBMODE="I" D BYINV
35 ;
36 Q
37 ;
38ALL ; Transmit All Pending Invoices (interactive and non-interactive)
39 ; input
40 ; FBQUIT - boolean value (0 or 1), true if process should stop
41 ; output
42 ; FBQUIT - may change value
43 ;
44 N FBCNT,FBERR,FBHL,FBQDA,FBSTA,FBTTYP,FBXL,FBXMIT,HLFS,HLECH
45 ;
46 ; init
47 S FBXL=20 ; last line used for message text (save 20 lines for header)
48 S FBCNT("PENDT")=0 ; count of pending invoices that were transmitted
49 S FBCNT("PENDE")=0 ; count of pending invoices that had exception
50 ;
51 ; save time that process started
52 S FBXMIT("START")=$$NOW^XLFDT()
53 I $E(IOST,1,2)="C-" W !!,"Starting Process..."
54 ;
55 ; initialize HL variables
56 D INIT^HLFNC2("FB FEE TO FPPS EVENT",.FBHL)
57 I $G(FBHL) D
58 . S FBQUIT=1
59 . D PTXT^FBFHLX1(.FBXL,"Error: Unable to initialize HL variables.")
60 . D PTXT^FBFHLX1(.FBXL,FBHL)
61 E D
62 . S HLFS=FBHL("FS")
63 . S HLECH=FBHL("ECH")
64 ;
65 ; check for transmitted invoices w/o commit ACK
66 S FBXMIT("ACK")=$$NOW^XLFDT()
67 I 'FBQUIT,$E(IOST,1,2)="C-" W !!,"Checking for acknowledgements..."
68 I 'FBQUIT D CHKACK^FBFHLX1
69 ;
70 S FBXMIT("SEND")=$$NOW^XLFDT()
71 I 'FBQUIT,$E(IOST,1,2)="C-" W !!,"Transmitting Pending Invoices..."
72 ; loop thru pending invoices and transmit
73 S FBQDA=0 F S FBQDA=$O(^FBHL(163.5,"AC",0,FBQDA)) Q:'FBQDA!FBQUIT D
74 . ; check for taskman quit request
75 . I $D(ZTQUEUED),$$S^%ZTLOAD S ZTSTOP=1,FBQUIT=1 Q
76 . ; try to transmit invoice
77 . D INVOICE
78 . ; update counters based on result
79 . I FBERR S FBCNT("PENDE")=FBCNT("PENDE")+1
80 . E S FBCNT("PENDT")=FBCNT("PENDT")+1
81 ;
82 ; save time that process ended
83 S FBXMIT("END")=$$NOW^XLFDT()
84 I $E(IOST,1,2)="C-" W !!,"Process complete. Sending Summary Message to G.FEE..."
85 ;
86 ; build and send summary mail message to G.FEE
87 D SUMMSG^FBFHLX1
88 ;
89 ; clean-up
90 K ^TMP($J,"FBE"),^TMP($J,"FBNA"),^TMP($J,"FBW"),^TMP($J,"FBX")
91 ;
92 Q
93 ;
94BYINV ; Transmit Selected Invoices (interactive)
95 ;
96 N FBAAIN,FBERR,FBHL,FBQDA,FBSTA,FBTTYP,FBX,HLFS,HLECH
97 ;
98 ; initialize HL variables
99 D INIT^HLFNC2("FB FEE TO FPPS EVENT",.FBHL)
100 I $G(FBHL) D Q
101 . W !,$C(7),"ERROR: Couldn't initialize HL variables!"
102 . W !,FBHL
103 S HLFS=FBHL("FS")
104 S HLECH=FBHL("ECH")
105 ;
106 ; select invoice
107 F Q:FBQUIT D
108 . S DIC="^FBHL(163.5,",DIC(0)="AEQM"
109 . D ^DIC I Y'>0 S FBQUIT=1 Q
110 . S FBQDA=+Y
111 . ;
112 . ; get invoice number and switch to last entry for invoice
113 . S FBAAIN=$P($G(^FBHL(163.5,FBQDA,0)),U)
114 . S FBQDA=$$LAST^FBFHLU(FBAAIN)
115 . I 'FBQDA W !,"Error, invalid data for invoice ",FBAAIN," in file 163.5" Q
116 . S FBQY=$G(^FBHL(163.5,FBQDA,0))
117 . ;
118 . ; confirm
119 . S FBX=$S($P(FBQY,U,3)=0:"",1:"re-")
120 . S DIR(0)="Y"
121 . S DIR("A")="Do you want to "_FBX_"transmit invoice "_FBAAIN
122 . D ^DIR K DIR S:$D(DIRUT) FBQUIT=1 I 'Y Q
123 . ;
124 . ; if re-transmit then create a new pending entry for invoice
125 . I FBX="re-" D
126 . . D FILEQUE^FBFHLL(FBAAIN,$P(FBQY,U,2))
127 . . S FBQDA=$$LAST^FBFHLU(FBAAIN)
128 . . I FBQDA S FBQY=$G(^FBHL(163.5,FBQDA,0))
129 . . E S FBQY=""
130 . ;
131 . ; check that pending entry was added
132 . I FBX="re-",$P(FBQY,U,3)'=0 D Q
133 . . W !,"Error adding entry to file 163.5. Can't re-transmit invoice."
134 . ;
135 . ; transmit specified invoice
136 . D INVOICE
137 . ;
138 . ; report success or failure of transmit
139 . I FBERR=0 W !,"Invoice has been transmitted to the HL7 package.",!!
140 . I FBERR=1 D
141 . . N FBL
142 . . W $C(7),!,"Problems prevented transmission of the invoice."
143 . . S FBL=0 F S FBL=$O(^TMP($J,"FBE",FBAAIN,FBL)) Q:'FBL D
144 . . . W !," ",$G(^TMP($J,"FBE",FBAAIN,FBL))
145 . . W !
146 . ;
147 . ; clean up after transmit
148 . K ^TMP($J,"FBE",FBAAIN)
149 . K ^TMP($J,"FBW",FBAAIN)
150 ;
151 Q
152 ;
153INVOICE ; transmit invoice
154 ; input
155 ; FBQDA - ien of entry in file 163.5 to transmit, required
156 ; output
157 ; FBERR - error flag (0 or 1), true if error prevented transmit
158 ; FBSTA - station number in transmitted message (may be null if err)
159 ; FBTTYP - transaction type in transmitted message (may be null)
160 ; ^TMP($J,"FBE",invoice number,#) - any exceptions
161 ; ^TMP($J,"FBW",invoice number,#) - any warnings
162 ;
163 ; N FBAAIN,FBD,FBFILE,FBRESULT,FBQY
164 ;
165 ; initialize
166 S FBERR=0
167 S FBSTA=""
168 S FBTTYP=""
169 ;
170 ; check for required input
171 I '$G(FBQDA) S FBERR=1 Q
172 ;
173 ; lock record
174 L +^FBHL(163.5,FBQDA):10
175 I '$T D Q
176 . S FBERR=1
177 . S FBAAIN=+$P($G(^FBHL(163.5,FBQDA,0)),U)
178 . I FBAAIN D POST^FBFHLU(FBAAIN,"E","Couldn't Lock Entry "_FBQDA_" in File 163.5.")
179 ;
180 ; get invoice number and file number
181 I 'FBERR D
182 . N FBQY
183 . S FBQY=$G(^FBHL(163.5,FBQDA,0))
184 . S FBAAIN=+$P(FBQY,U)
185 . I 'FBAAIN D
186 . . S FBERR=1
187 . . D POST^FBFHLU(0,"E","Couldn't determine invoice # for entry "_FBQDA_" in file 163.5.")
188 . Q:FBERR
189 . S FBFILE=$P(FBQY,U,2)
190 . I "^3^5^9^"'[(U_FBFILE_U) D
191 . . S FBERR=1
192 . . D POST^FBFHLU(FBAAIN,"E","Invalid File # for entry "_FBQDA_" in file 163.5.")
193 ;
194 ; gather invoice data
195 I 'FBERR D @("EN^FBFHLD"_FBFILE) I $D(^TMP($J,"FBE",FBAAIN)) S FBERR=1
196 S FBTTYP=$P($G(FBD(0,"INV")),U,2)
197 S FBSTA=$P($G(FBD(0,"INV")),U,3)
198 ;
199 ; build HL segments
200 I 'FBERR D EN^FBFHLS I $D(^TMP($J,"FBE",FBAAIN)) S FBERR=1
201 ;
202 ; generate HL message
203 I 'FBERR D
204 . K FBRESULT
205 . D GENERATE^HLMA("FB FEE TO FPPS EVENT","GM",1,.FBRESULT)
206 . I +$P(FBRESULT,U,2) D
207 . . S FBERR=1
208 . . D POST^FBFHLU(FBAAIN,"E","HL ERR:"_$P(FBRESULT,U,3))
209 ;
210 ; update file 163.5
211 I 'FBERR D
212 . N FBFDA
213 . S FBFDA(163.5,FBQDA_",",2)="1" ; set status = transmitted
214 . S FBFDA(163.5,FBQDA_",",3)=$P(FBRESULT,U) ; message ID
215 . S FBFDA(163.5,FBQDA_",",4)=$$NOW^XLFDT() ; message date/time
216 . S FBFDA(163.5,FBQDA_",",5)=FBTTYP ; transaction type
217 . S FBFDA(163.5,FBQDA_",",6)=FBSTA ; station number
218 . I $D(FBFDA) D FILE^DIE("","FBFDA")
219 . ;
220 . ; store HL segments in word-processing field
221 . D MOVEHL
222 . D WP^DIE(163.5,FBQDA_",",7,"","^TMP($J,""FBHLSEG"")")
223 . K ^TMP($J,"FBHLSEG")
224 ;
225 ; unlock record
226 L -^FBHL(163.5,FBQDA)
227 ;
228 ; clean-up
229 K ^TMP("HLS",$J)
230 Q
231 ;
232MOVEHL ; Copy HL segment data into word-processing style array
233 ; input
234 ; ^TMP("HLS",$J, array
235 ; output
236 ; ^TMP($J,"HLSEG",#)=line of text
237 ; there will be a blank line after each segment
238 ;
239 N FBI,FBII,FBL
240 K ^TMP($J,"FBHLSEG")
241 S FBL=0
242 S FBI=0 F S FBI=$O(^TMP("HLS",$J,FBI)) Q:'FBI D
243 . S FBL=FBL+1,^TMP($J,"FBHLSEG",FBL)=$G(^TMP("HLS",$J,FBI))
244 . S FBII=0 F S FBII=$O(^TMP("HLS",$J,FBI,FBII)) Q:'FBII D
245 . . S FBL=FBL+1,^TMP($J,"FBHLSEG",FBL)=$G(^TMP("HLS",$J,FBI,FBII))
246 . S FBL=FBL+1,^TMP($J,"FBHLSEG",FBL)=""
247 Q
248 ;
249 ;FBFHLX
Note: See TracBrowser for help on using the repository browser.