source: WorldVistAEHR/trunk/r/INCOME_VERIFICATION_MATCH-IVM/IVMCQ1.m@ 1073

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

initial load of WorldVistAEHR

File size: 5.5 KB
Line 
1IVMCQ1 ;ALB/KCL - API FOR FINANCIAL QUERIES (continued) ; 7/6/01 1:10pm
2 ;;2.0;INCOME VERIFICATION MATCH;**17,23,34,63**;21-OCT-94
3 ;
4QUERY(DFN,USER,NOTIFY,OPTION,ERROR,RECENT) ; Build/send HL7 financial query for a patient.
5 ;
6 ; Input:
7 ; DFN - ien of patient record in PATIENT file (required)
8 ; USER - user initiating the query. Pointer to NEW USER
9 ; file. (optional)
10 ; NOTIFY - flag to determine if user should be notified when a
11 ; query reply is received. (optional)
12 ; OPTION - option query is initiated from. Ien of record in
13 ; OPTION file. (optional)
14 ; RECENT - a flag, if set to 1, a check will be done to determine
15 ; if a query is currently open OR recently sent(optional)
16 ;
17 ; Output:
18 ; Function Value: 1 on success, 0 on failure
19 ; ERROR - if failure, returns error msg (pass by reference)
20 ;
21 N DATA,DG,DGENDA
22 N HLDA,HLDAN,HLDAP,HLDT,HLDT1,HLECH,HLERR,HLEVN,HLFS,HLMID,HLMTN,HLNDAP,HLNDAP0,HLPID,HLQ,HLSDT,HLVER
23 N IVMCID,IVMIEN,IVMPAT,IVMQRY,SUCCESS,XMTEXT
24 N HL,HLEID
25 ;
26 S SUCCESS=0
27 ;
28 ; check if DCD messaging is active
29 I '$$DCDON^IVMUPAR1() S ERROR="MESSAGING IS DISABLED." G Q2
30 I $G(IVMZ10)="UPLOAD IN PROGRESS" S ERROR="FINANCIAL UPLOAD IS IN PROGRESS" G Q2
31 ;
32 ; for synchronization and to avoid multiple queries on the same day
33 ; for the same patient, LOCK the IVM FINANCIAL QUERY LOG file before
34 ; doing two query checks...
35 L +^IVM(301.62,"ADT1",DFN):15
36 I '$T S ERROR="UNABLE TO SEND A QUERY AT THIS TIME" G Q2
37 ;
38 ; if RECENT flag, quit if query is currently open OR just sent
39 I $G(RECENT)=1,$$RECENT(DFN) S ERROR="A FINANCIAL QUERY IS CURRENTLY OPEN OR JUST SENT" G Q2
40 ;
41 ; regardless of RECENT flag, check to see if a query has already been
42 ; sent out for this patient today...
43 I $$SENT^IVMCQ2(DFN) S ERROR="A FINANCIAL QUERY HAS ALREADY BEEN SENT FOR THIS PATIENT TODAY" G Q2
44 ;
45 ; no query RECENT or SENT today. set a stub record in 301.62 and
46 ; release the lock. the stub will contain the patient DFN and
47 ; today's date so that the "ADT1" x-ref is set and subsequent checks
48 ; both in DG and IVM processes will find a query sent today...
49 S DATA(.01)=DFN
50 S DATA(.02)=$$NOW^XLFDT
51 S IVMIEN=$$ADD^DGENDBS(301.62,,.DATA)
52 L -^IVM(301.62,"ADT1",DFN)
53 K DATA
54 K ^TMP("HLS",$J) ;IVM*2*63
55 ;
56 ; init HL7 variables
57 S HLMTN="QRY"
58 S HLDAP="IVM"
59 S HLEID="VAMC "_$P($$SITE^VASITE,"^",3)_" QRY-Z10 SERVER"
60 S HLEID=$O(^ORD(101,"B",HLEID,0))
61 D INIT^HLFNC2(HLEID,.HL)
62 I $G(HL)]"" S HLERR=$P(HL,"^",2)
63 S HLEVN=0 ; init msg event counter
64 S HLSDT=$$NOW^XLFDT
65 I $D(HLERR) S ERROR="HL7 INITIALIZATION ERROR - "_HLERR G QUERYQ
66 ;
67 ; get patient identifiers
68 I '$$GETPAT^IVMUFNC(DFN,.IVMPAT) S ERROR="PATIENT NOT FOUND" G QUERYQ
69 I (IVMPAT("DOB")="") S ERROR="PATIENT DATE OF BIRTH IS REQUIRED" G QUERYQ
70 I (IVMPAT("SSN")="") S ERROR="PATIENT SSN IS REQUIRED" G QUERYQ
71 I (IVMPAT("SEX")="") S ERROR="PATIENT SEX IS REQUIRED" G QUERYQ
72 I "MF"'[IVMPAT("SEX") S ERROR="PATIENT SEX IS NOT VALID" G QUERYQ
73 ;
74 ; build HL7 financial query (QRY) message components...
75 D QRD
76 D QRF
77 ;
78 ; send the message...
79 S HLARYTYP="GM"
80 S HLFORMAT=1
81 D GENERATE^HLMA(HLEID,HLARYTYP,HLFORMAT,.HLRESLT)
82 I $P($G(HLRESLT),"^",2)]"" S HLERR=$P(HLRESLT,"^",3)
83 I $D(HLERR) S ERROR="HL7 TRANSMISSION ERROR - "_HLERR G QUERYQ
84 ;
85 ;S IVMCID=$G(MID)
86 S IVMCID=+HLRESLT
87 ;
88 ; update our record in the LOG file...
89 S DATA(.03)=0
90 S DATA(.04)=$G(USER)
91 S DATA(.05)=IVMCID
92 S DATA(.06)=""
93 S DATA(.07)=$G(OPTION)
94 S DATA(.08)=$S($G(NOTIFY):1,1:0)
95 S DGENDA=IVMIEN
96 I '$$UPD^DGENDBS(301.62,.DGENDA,.DATA) S ERROR="UPDATE OF RECORD "_IVMIEN_" IN 301.62 FAILED!" G QUERYQ
97 ;
98 S SUCCESS=1
99 ;
100QUERYQ ; exit and clean-up
101 D KILL^HLTRANS
102 K ^TMP("HLS",$J) ;IVM*2*63 - K ^TMP("HLS",$J,HLSDT)
103Q2 ;
104 L -^IVM(301.62,"ADT1",DFN)
105 Q SUCCESS
106 ;
107QUERY2(DFN,USER,NOTIFY,OPTION,ERROR,RECENT) ; Build/send HL7 financial query for a patient.
108 ;
109 ; Same input/output parameters as described in module QUERY above.
110 ;
111 I $$QUERY($G(DFN),$G(USER),$G(NOTIFY),$G(OPTION),.ERROR,$G(RECENT))
112 Q
113 ;
114QRD ; Build (HL7) QRD segment for patient
115 ;
116 N IVMQRD
117 ; date/time query generated...
118 S $P(IVMQRD,HLFS,1)=$$HLDATE^HLFNC(HLSDT)
119 ; query format code (record-oriented format)...
120 S $P(IVMQRD,HLFS,2)="R"
121 ; query priority (immediate)...
122 S $P(IVMQRD,HLFS,3)="I"
123 ; query ID (patient's DFN)...
124 S $P(IVMQRD,HLFS,4)=DFN
125 ; quantity-limited request (1 record)...
126 S $P(IVMQRD,HLFS,7)="1~RD"
127 ; "who" subject filter (=SSN)...
128 S $P(IVMQRD,HLFS,8)=IVMPAT("SSN")
129 ; "what" subject filter (=financial)...
130 S $P(IVMQRD,HLFS,9)="FIN"
131 ; what department data code (=income year)...
132 S $P(IVMQRD,HLFS,10)=$$HLDATE^HLFNC($$LYR^DGMTSCU1(DT))
133 ; query results level (full results)...
134 S $P(IVMQRD,HLFS,12)="T"
135 S ^TMP("HLS",$J,1)="QRD"_HLFS_IVMQRD
136 Q
137 ;
138 ;
139QRF ; Build HL7 (QRF) segment for patient
140 ;
141 N IVMQRF
142 ; "where" subject filter (=IVM)...
143 S $P(IVMQRF,HLFS,1)="IVM"
144 ; what user qualifier (DOB)...
145 S $P(IVMQRF,HLFS,4)=$$HLDATE^HLFNC(IVMPAT("DOB"))
146 ; other subject query filter (SEX)...
147 S $P(IVMQRF,HLFS,5)=IVMPAT("SEX")
148 S ^TMP("HLS",$J,2)="QRF"_HLFS_IVMQRF
149 Q
150 ;
151RECENT(DFN) ; Determine if a patient has a financial query that is open OR recently responded to (last 2 minutes)
152 ;
153 ; Input: DFN - ien of patient record in PATIENT file
154 ; Output: returns 1 if open query, otherwise returns 0.
155 ;
156 N IVMQRY,IVMIEN,RECENT
157 S RECENT=0
158 S IVMIEN=$$LASTQRY^IVMCQ2($G(DFN))
159 I IVMIEN,$$GET^IVMCQ2(IVMIEN,.IVMQRY) D
160 .I 'IVMQRY("STATUS") S RECENT=1 Q
161 .I (($$NOW^XLFDT-IVMQRY("RESPONSE"))<.0003) S RECENT=1
162 Q RECENT
Note: See TracBrowser for help on using the repository browser.