source: FOIAVistA/trunk/r/INCOME_VERIFICATION_MATCH-IVM/IVMCQ2.m@ 1611

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

initial load of FOIAVistA 6/30/08 version

File size: 9.1 KB
Line 
1IVMCQ2 ;ALB/KCL - API FOR FINANCIAL QUERIES (continued) ; 27-APR-95
2 ;;2.0;INCOME VERIFICATION MATCH;**17**;21-OCT-94
3 ;
4 ;
5MONITOR ; Description: This entry point is used to monitor the IVM FINANCIAL
6 ; QUERY LOG file and check for query transmissions that have not been
7 ; responded to for more than 2 days. If a query is > 2 days old, the
8 ; corresponding entry in the IVM FINANCIAL QUERY LOG file will be
9 ; updated/closed and a new financial query may be sent.
10 ;
11 N IVMQLOG,QRYIEN,%
12 ;
13 ; roll through query log entries with 'open' status
14 S QRYIEN=0 F S QRYIEN=$O(^IVM(301.62,"AC",0,QRYIEN)) Q:'QRYIEN D
15 .;
16 .; obtain record from IVM FINANCIAL QUERY LOG
17 .Q:'$$GET(+QRYIEN,.IVMQLOG)
18 .;
19 .; quit if query msg not old enough
20 .Q:IVMQLOG("SENT")>$$FMADD^XLFDT(DT,-2)
21 .;
22 .; update/auto-close query in IVM FINANCIAL QUERY LOG file
23 .D NOW^%DTC,UPD(IVMQLOG("DFN"),+QRYIEN,%,6,2)
24 .;
25 .; quit if new query is not needed
26 .Q:'$$NEED^IVMCQ(IVMQLOG("DFN"))
27 .;
28 .; send new query
29 .I $$QUERY^IVMCQ1(IVMQLOG("DFN"),IVMQLOG("TRANBY"),IVMQLOG("NOTIFY"),IVMQLOG("OPTION"))
30 ;
31 Q
32 ;
33 ;
34FIND(DFN,IVMMSG,IVMRECD,IVMCR,IVMCS) ; Description: Used to find and update
35 ; entry in IVM FINANCIAL QUERY LOG file.
36 ;
37 ; Input:
38 ; DFN - ien of patient record in PATIENT file
39 ; IVMMSG - query message id
40 ; IVMRECD - date/time query response received
41 ; IVMCR - query closure reason code
42 ; IVMCS - query closure source (1|DCD -- 2|DHCP)
43 ;
44 ; Output: none
45 ;
46 I '$G(DFN)!'$G(IVMCR)!'$G(IVMCS) G FINDQ
47 N IVM,IVMD
48 S IVM=0 F S IVM=$O(^IVM(301.62,"B",DFN,IVM)) Q:'IVM D
49 .S IVMD=$G(^IVM(301.62,+IVM,0))
50 .Q:$P(IVMD,"^",5)'=$G(IVMMSG) ; message, query ID's not same
51 .D UPD(DFN,+IVM,$G(IVMRECD),IVMCR,IVMCS)
52FINDQ Q
53 ;
54 ;
55UPD(DFN,IVMDA,IVMRECD,IVMCR,IVMCS) ; Description: Used to update record found in IVM FINANCIAL QUERY LOG file.
56 ;
57 ; Input:
58 ; DFN - ien of patient record in PATIENT file
59 ; IVMMSG - query message id
60 ; IVMRECD - date/time query response received
61 ; IVMCR - query closure reason code
62 ; IVMCS - query closure source (1|DCD -- 2|DHCP)
63 ;
64 ; Output: none
65 ;
66 I '$G(DFN)!'$G(IVMDA)!'$G(IVMCR)!'$G(IVMCS) G FINDQ
67 N DA,DIE,DR,IVMCRP,IVMOPT
68 S IVMCRP=$O(^IVM(301.94,"AC",IVMCR,0)) S:'IVMCRP IVMCRP=IVMCR
69 S DIE="^IVM(301.62,",DA=IVMDA
70 S DR=".03////1"_$S($G(IVMRECD):";.06////"_IVMRECD,1:"")
71 S DR=DR_";1.01////"_IVMCRP_";1.02///NOW;1.03////"_IVMCS
72 D ^DIE
73 ;
74 ; determine if query reply requires user notification
75 I '$$NOTIFY(IVMDA)
76 ;
77UPDQ Q
78 ;
79 ;
80FINDMSG(MSGID) ;
81 ; Description: Used to find a record in the IVM FINANCIAL QUERY LOG
82 ; file, given the unique message id assigned to the query by the
83 ; HL7 package.
84 ;
85 ; Input:
86 ; MSGID - The unique id assigned to the query by the HL7 package and
87 ; stored in the IVM FINANCIAL QUERY LOG as the HL7 MESSAGE
88 ; CONTROL ID field.
89 ;
90 ; Output:
91 ; Function Value - If successful, returns the ien of the record in
92 ; the file, otherwise returns 0 on failure.
93 ;
94 Q:($G(MSGID)="") 0
95 Q +$O(^IVM(301.62,"C",MSGID,0))
96 ;
97 ;
98GET(IEN,IVMQRY) ;
99 ; Description: Used to obtain a record in the IVM FINANCIAL QUERY LOG
100 ; file. The values are returned in the IVMQRY() array.
101 ;
102 ; Input:
103 ; IEN - internal entry number of a record in the IVM FINANCIAL QUERY LOG file.
104 ;
105 ; Output:
106 ; Function Value - 1 on success, 0 on failure.
107 ; IVMQRY() array, pass by reference. Subscripts are:
108 ; "DFN" - PATIENT field
109 ; "SENT" - QUERY TRANS DT/TM field
110 ; "STATUS" - QUERY STATUS field
111 ; "TRANBY" - TRANSMITTED BY field
112 ; "MSGID" - HL7 MESSAGE CONTROL ID field
113 ; "RESPONSE" - QUERY RESPONSE REC'D DT/TM field
114 ; "OPTION" - DHCP OPTION field
115 ; "NOTIFY" - NOTIFY FLAG field
116 ; "CLOSURE RSN" - CLOSURE REASON field
117 ; "CLOSURE" - CLOSURE DT/TM field
118 ; "CLOSURE SRC" - CLOSURE SOURCE field
119 ;
120 N IVMNODE
121 K IVMQRY S IVMQRY=""
122 Q:'$G(IEN) 0
123 ;
124 S IVMNODE=$G(^IVM(301.62,IEN,0))
125 Q:IVMNODE="" 0
126 ;
127 S IVMQRY("DFN")=$P(IVMNODE,"^")
128 S IVMQRY("SENT")=$P(IVMNODE,"^",2)
129 S IVMQRY("STATUS")=$P(IVMNODE,"^",3)
130 S IVMQRY("TRANBY")=$P(IVMNODE,"^",4)
131 S IVMQRY("MSGID")=$P(IVMNODE,"^",5)
132 S IVMQRY("RESPONSE")=$P(IVMNODE,"^",6)
133 S IVMQRY("OPTION")=$P(IVMNODE,"^",7)
134 S IVMQRY("NOTIFY")=$P(IVMNODE,"^",8)
135 ;
136 S IVMNODE=$G(^IVM(301.62,IEN,1))
137 S IVMQRY("CLOSURE RSN")=$P(IVMNODE,"^")
138 S IVMQRY("CLOSURE")=$P(IVMNODE,"^",2)
139 S IVMQRY("CLOSURE SRC")=$P(IVMNODE,"^",3)
140 ;
141 Q 1
142 ;
143 ;
144DELETE(IEN) ;
145 ; Description: Delete record in the IVM FINANCIAL QUERY LOG file,
146 ; given the internal entry number (IEN).
147 ;
148 ; Input:
149 ; IEN - The internal entry number of the record.
150 ;
151 ; Output:
152 ; Function Value - 1 on success, 0 on failure.
153 ;
154 Q:'$G(IEN) 0
155 N DIK,DA
156 S DIK="^IVM(301.62,"
157 S DA=IEN
158 D ^DIK
159 Q 1
160 ;
161 ;
162LASTQRY(DFN) ; Description: Used to find the last financial query for a patient.
163 ;
164 ; Input:
165 ; DFN - ien of patient record in PATIENT file
166 ;
167 ; Output:
168 ; Function Value - If successful, returns the ien of the record in
169 ; the file, otherwise returns 0 on failure.
170 ;
171 Q:'$G(DFN) 0
172 N QRYDT
173 S QRYDT=$O(^IVM(301.62,"ADT1",DFN,9999999.999999),-1)
174 Q:'QRYDT 0
175 Q $O(^IVM(301.62,"ADT1",DFN,QRYDT,0))
176 ;
177 ;
178OPEN(DFN) ; Description: Used to determine if a patient has a financial query that is open (QUERY STATUS=TRANSMITTED).
179 ;
180 ; Input:
181 ; DFN - ien of patient record in PATIENT file
182 ;
183 ; Output:
184 ; Function Value - returns 1 if open query, otherwise returns 0.
185 ;
186 N IVMQRY,IVMIEN,OPEN
187 S OPEN=0
188 S IVMIEN=$$LASTQRY($G(DFN))
189 I IVMIEN,$$GET(IVMIEN,.IVMQRY) D
190 .I 'IVMQRY("STATUS") S OPEN=1
191 Q OPEN
192 ;
193SENT(DFN,IVMDT) ; Description: Used to determine if a query was sent for a patien on a specific date.
194 ;
195 ; Input:
196 ; DFN - IEN of patient record in PATIENT file
197 ; IVMDT - (optional) Date/Time - default TODAY
198 ;
199 ; Output:
200 ; Function Value: returns 1 if query sent on date, 0 otherwise.
201 ;
202 N IVMIDT,IVMIEN,IVMLDT,IVMQRY,SAMEDAY
203 ;
204 S SAMEDAY=0
205 I '$G(DFN) G SENTQ
206 S IVMIDT=$S($G(IVMDT)>0:IVMDT,1:DT) S:'$P(IVMIDT,".",2) IVMIDT=IVMIDT_.999999
207 S IVMIEN=$$LASTQRY(DFN)
208 I IVMIEN,$$GET(IVMIEN,.IVMQRY) D
209 .I $P(IVMIDT,".")=$P(IVMQRY("SENT"),".") S SAMEDAY=1
210 ;
211SENTQ Q SAMEDAY
212 ;
213 ;
214QRYQUE(DFN) ; Description: Queue off job to send a financial query to the
215 ; the HEC. This does first check to see if a query is needed.
216 ;
217 ; Input:
218 ; DFN - ien of patient record in PATIENT file
219 ;
220 ; Output: none
221 ;
222 N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
223 S ZTDESC="IVM Financial Query" ; task description
224 S ZTDTH=$H ; task start time
225 S ZTRTN="QUERY^IVMCQ2(DFN)" ; entry point of tasked routine
226 S ZTSAVE("DFN")="" ; input parameters
227 S ZTIO="" ; i/o device - (not needed)
228 D ^%ZTLOAD
229 Q
230 ;
231QRYQUE2(DFN,DUZ,NOTIFY,OPTION) ; Description: Queue off job to send a financial query to the
232 ; the HEC. This version does NOT first check to see if a query is
233 ; needed, but does check to see if a query is currently open.
234 ;
235 ; Input:
236 ; DFN - ien of patient record in PATIENT file
237 ; DUZ (optional)
238 ; NOTIFY - (optional) 1 if the user requested notification when reply received
239 ; OPTION - (optional) the option where the query was requested
240 ;
241 ; Output: none
242 ;
243 N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
244 S ZTDESC="IVM Financial Query" ; task description
245 S ZTDTH=$H ; task start time
246 S ZTRTN="QUERY2^IVMCQ1(DFN,$G(DUZ),$G(NOTIFY),$G(OPTION),,1)" ; entry point of tasked routine
247 S ZTSAVE("DFN")="",ZTSAVE("DUZ")="",ZTSAVE("NOTIFY")="",ZTSAVE("OPTION")=""
248 S ZTIO="" ; i/o device - (not needed)
249 D ^%ZTLOAD
250 Q
251 ;
252QUERY(DFN) ; Description: Determine if a financial query should be sent to the HEC.
253 ;
254 ; Input:
255 ; DFN - ien of patient record in PATIENT file
256 ;
257 ; Output: none
258 ;
259 ;
260 I '$G(DFN) Q
261 I '$$NEED^IVMCQ(DFN,0) Q
262 ;
263 ; send query for patient
264 I $$QUERY^IVMCQ1(DFN)
265 ;
266 Q
267 ;
268 ;
269NOTIFY(QRYIEN) ; Description: Send notification message of reply received for financial query.
270 ;
271 ; Input:
272 ; QRYIEN - ien of record in IVM FINANCIAL QUERY LOG file
273 ;
274 ; Output:
275 ; Function Value: 1 on success, 0 on failure
276 ;
277 N DIFROM,IVMTEXT,PATIENT,QARRAY,SUCCESS,XMDUZ,XMTEXT,XMSUB,XMY,XMZ
278 ;
279 S SUCCESS=0
280 ;
281 I '$G(QRYIEN) G MSGQ
282 ;
283 ; obtain record from IVM FINANCIAL QUERY LOG
284 I '$$GET(QRYIEN,.QARRAY) G MSGQ
285 ;
286 ; check NOTIFY FLAG
287 I '$G(QARRAY("NOTIFY")) G MSGQ
288 ;
289 ; obtain patient identifiers
290 I '$$GETPAT^IVMUFNC($G(QARRAY("DFN")),.PATIENT) G MSGQ
291 ;
292 ; build notification message
293 S XMDUZ="IVM PACKAGE"
294 S XMY(QARRAY("TRANBY")_"@"_$G(^XMB("NETNAME")))=""
295 S XMSUB="Financial Query Reply for: "_PATIENT("NAME")_" ("_PATIENT("SSN")_")"
296 S XMTEXT="IVMTEXT("
297 S IVMTEXT(1)="A reply to the financial query that you sent has been received."
298 S IVMTEXT(2)=" "
299 S IVMTEXT(3)=" Patient Name: "_PATIENT("NAME")
300 S IVMTEXT(4)=" Patient SSN: "_PATIENT("SSN")
301 S IVMTEXT(5)=" "
302 S IVMTEXT(6)=" Query Transmission Date/Time: "_$$EXTERNAL^DILFD(301.62,.02,"F",QARRAY("SENT"))
303 S IVMTEXT(7)=" Query Response Date/Time: "_$$EXTERNAL^DILFD(301.62,.06,"F",QARRAY("RESPONSE"))
304 S IVMTEXT(8)=" "
305 S IVMTEXT(9)=" Closure Reason: "_$$EXTERNAL^DILFD(301.62,1.01,"F",QARRAY("CLOSURE RSN"))
306 S IVMTEXT(10)=" Closure Source: "_$$EXTERNAL^DILFD(301.62,1.03,"F",QARRAY("CLOSURE SRC"))
307 ;
308 D ^XMD
309 ;
310 S SUCCESS=1
311 ;
312MSGQ Q SUCCESS
Note: See TracBrowser for help on using the repository browser.