source: WorldVistAEHR/trunk/r/INCOME_VERIFICATION_MATCH-IVM/IVMCM.m@ 1259

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

revised back to 6/30/08 version

File size: 9.2 KB
RevLine 
[623]1IVMCM ;ALB/SEK,KCL,RTK,AEG,BRM,AEG - PROCESS INCOME TEST (Z10) TRANSMISSIONS ; 04/23/03 1:43pm
2 ;;2.0;INCOME VERIFICATION MATCH;**12,17,28,41,44,53,34,49,59,55,63,77,74**;21-OCT-94
3 ;
4 ;
5ORF ; Handler for ORF type HL7 messages received from HEC
6 ;
7 ; Make sure POSTMASTER DUZ instead of DUZ of Person who
8 ; started Incoming Logical Link.
9 S DUZ=.5
10 N CNT,IVMRTN,SEGCNT
11 S IVMRTN="IVMCMX" ;USE "IVMCMX" BECAUSE "IVMCM" ALREADY USED
12 K ^TMP($J,IVMRTN),DIC
13 S (DGMSGF,DGMTMSG)=1 ; HL7 rtn. Don't need DG interative messages.
14 S HLECH=HL("ECH"),HLQ=HL("Q"),HLMID=HL("MID")
15 K %,%H,%I D NOW^%DTC S HLDT=%
16 F SEGCNT=1:1 X HLNEXT Q:HLQUIT'>0 D
17 . S CNT=0
18 . S ^TMP($J,IVMRTN,SEGCNT,CNT)=HLNODE
19 . F S CNT=$O(HLNODE(CNT)) Q:'CNT D
20 . . S ^TMP($J,IVMRTN,SEGCNT,CNT)=HLNODE(CNT)
21 S HLDA=HLMTIEN
22 ;
23 N SEG,EVENT,MSGID
24 S:'$D(HLEVN) HLEVN=0
25 D NXTSEG^DGENUPL(HLDA,0,.SEG)
26 Q:(SEG("TYPE")'="MSH") ;would not have reached here if this happened!
27 S EVENT=$P(SEG(9),$E(HLECH),2)
28 ;
29 ; INITIALIZE HL7 VARIABLES
30 S HLEID="VAMC "_$P($$SITE^VASITE,"^",3)_" ORF-"_EVENT_" SERVER"
31 S HLEID=$O(^ORD(101,"B",HLEID,0))
32 D INIT^HLFNC2(HLEID,.HL)
33 S HLEIDS=$O(^ORD(101,HLEID,775,"B",0))
34 ;
35 ; Handle means test signature ORF (Z06) event
36 I EVENT="Z06" D ORF^IVMPREC7
37 ;
38 ; Handle income test ORF (Z10) event
39 I EVENT="Z10" D Z10
40 ;
41 ; Handle enrollment/elig. ORF (Z11) event
42 I EVENT="Z11" D
43 .S MSGID=SEG(10)
44 .D ORFZ11^DGENUPL(HLDA,MSGID)
45 ;
46 K ^TMP($J,IVMRTN)
47 Q
48 ;
49 ;
50Z10 ; Entry point for receipt of ORF~Z10 transmission
51 ; The Income Test (Z10) transmission has the following format:
52 ;
53 ; BHS ORF msgs do not include batch header or trailer.
54 ; {MSH
55 ; PID They will include the sequence: MSA
56 ; ZIC QRD
57 ; ZIR QRF
58 ; {ZDP These segments will follow the MSH segment.
59 ; ZIC
60 ; ZIR
61 ; }
62 ; {ZMT
63 ; }
64 ; ZBT
65 ; }
66 ; BTS
67 ;
68 S IVMORF=1 ; set ORF msg flag
69 S (HLEVN,IVMCT,IVMERROR,IVMCNTR)=0 ; init vars
70 ;
71ORU ; Entry point for receipt of ORU~Z10 trans (called by IVMPREC2)
72 S IVMTYPE=5,IVMZ10F=1
73 ;
74 ; - loop through the msg in (#772 file), and process (PROC) msgs
75 S IVMDA=0 F S IVMDA=$O(^TMP($J,IVMRTN,IVMDA)) Q:'IVMDA S IVMSEG=$G(^(IVMDA,0)) I $E(IVMSEG,1,3)="MSH" D PROC Q:'IVMDA
76 ;
77 ; - if ORF msg flag, update the Query Tran Log and send ACK
78 I $G(IVMORF) D
79 .I $G(DFN),$D(IVMMCI) D
80 ..N IVMCR
81 ..S IVMCR=$P("1^2^3^7^5^6^4","^",IVMTYPE) ;map reason to test type
82 ..D FIND^IVMCQ2(DFN,IVMMCI,HLDT,$S($D(HLERR):5,1:IVMCR),1)
83 .;D ACK^IVMPREC:'$D(HLERR)
84 .;N HLRESLTA,HLP
85 .;D GENACK^HLMA1(HLEID,HLMTIEN,HLEIDS,"LM",1,.HLRESLTA,"",.HLP)
86 ;
87 ; - if tests are uploaded, generate notification msg
88 I $D(^TMP($J,"IVMBULL")) D ^IVMCMB
89 ;
90ENQ ;
91 K IVMDA,IVMORF,IVMSEG,IVMFLGC,IVMTYPE,IVMMTIEN,IVMMTDT,IVMDGBT,IVMMCI
92 K ^TMP($J,"IVMCM"),^("IVMBULL"),DGMSGF,DGADDF,IVMCPAY,IVMBULL,DFN
93 K DGMTMSG,IVMZ10F
94 Q
95 ;
96PROC ; Process each HL7 message from (#772) file
97 ;
98 N IVMFUTR,TMSTAMP,SOURCE,NODE,HSDATE,IVMZ10,DGMTP,DGMTACT,DGMTI,DGMTA
99 S DGMTACT="ADD"
100 D PRIOR^DGMTEVT
101 S IVMZ10="UPLOAD IN PROGRESS"
102 S IVMFUTR=0 ;this flag will indicate whether or not a test with a future date is being uploaded
103 S IVMMTIEN=0
104 ;
105 S MSGID=$P(IVMSEG,HLFS,10) ; msg control id for ACK's
106 ; - check if DCD messaging is enabled
107 I '$$DCDON^IVMUPAR1() D PROB^IVMCMC("Facility has DCD messaging disabled") Q
108 ;
109 ; - check HL7 msg structure for errors
110 K HLERR,^TMP($J,"IVMCM")
111 D ^IVMCMC I $D(HLERR) K:HLERR="" HLERR Q
112 ;
113 ; Determine type of test/transmission
114 S IVMTYPE=0
115 ;
116 ; - was a means test sent?
117 I $P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,2) S IVMTYPE=1 ; MT trans
118 ;
119 ; - if MT and CT transmitted, error - pt can't have both unless
120 ; one is a deletion, but HEC not currently handling that situation
121 I IVMTYPE,$P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,2) D PROB^IVMCMC("Patient can not have both a Means Test and Copay Test") Q
122 I $P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,2) S IVMTYPE=2 ; CT trans
123 ;
124 ; - if no MT or CT or LTC then Income Screening
125 I 'IVMTYPE,'$P($G(^TMP($J,"IVMCM","ZMT4")),HLFS,2) S IVMTYPE=3 ; IS trans
126 ;
127 ;send an eligibility query if no eligibility code
128 I '$$ELIG^IVMCUF1(DFN),'$$PENDING^DGENQRY(DFN) I $$SEND^DGENQRY1(DFN)
129 ;
130 ; obtain locks used to sychronize upload with local income test options
131 D GETLOCKS^IVMCUPL(DFN)
132 ;
133 ;
134MT ; If transmission is a Means Test
135 N NODE0,RET,CODE,DATA
136 S HLQ=$G(HL("Q"))
137 S:HLQ="" HLQ=""""""
138 I IVMTYPE=1 D I $D(HLERR) G PROCQ
139 .S IVMMTDT=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,2))
140 .S TMSTAMP=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,25))
141 .S HSDATE=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,24))
142 .S SOURCE=$P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,22)
143 .S IVMLAST=$$LST^DGMTU(DFN,$E(IVMMTDT,1,3)_1231,1)
144 .I $$Z06MT^EASPTRN1(+IVMLAST) Q
145 .I '$$ELIG^IVMUFNC5(DFN) S ERRMSG="Means Test upload not appropriate for current patient"
146 .I $$AGE^IVMUFNC5(DT)>$$INCY^IVMUFNC5(IVMMTDT) D
147 ..N CATCZMT S CATCZMT=$G(^TMP($J,"IVMCM","ZMT1"))
148 ..S CATC=$$CATC^IVMUFNC5(CATCZMT)
149 ..I '+$G(CATC) S ERRMSG="Only Means Tests in current/previous income years are valid (not effective)"
150 .I $G(ERRMSG)'="" D PROB^IVMCMC(ERRMSG) K ERRMSG,CATC Q
151 .;
152 .; - perform edit checks and file MT
153 .D CHKDT
154 .;deletion indicator sent?
155 .I $P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,3)=HLQ D Q
156 ..D
157 ...;if there is a future test for that income year, delete that
158 ...N IEN,DATA,IVMPAT
159 ...S IEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),1,.IVMPAT)
160 ...I IEN S DATA(.06)="" I $$UPD^DGENDBS(301.5,IVMPAT,.DATA)
161 ...I IEN,$D(^DGMT(408.31,IEN,0)) D
162 ....S IVMMTIEN=IEN
163 ....S IVMFUTR=1
164 ...E D
165 ....S IVMFUTR=0
166 ..Q:('IVMMTIEN)
167 ..S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
168 ..I $$EN^IVMCMD(IVMMTIEN) D
169 ...S RET=$$LST^DGMTU(DFN,DT,IVMTYPE)
170 ...S CODE=$S(($E($P(RET,"^",2),1,3)=$E(DT,1,3)):$P(RET,"^",4),1:"")
171 ...D ADD^IVMCMB(DFN,IVMTYPE,$S(IVMFUTR:"DELETE FUTR TEST",1:"DELETE PRMRY TEST"),+$G(NODE0),$$GETCODE^DGMTH($P(NODE0,"^",3)),CODE)
172 .;
173 .;check timestamp - if matches current primary test and hardship matches, then this is a duplicate and does not need to be uploaded
174 .I TMSTAMP D
175 ..S NODE=""
176 ..I IVMFUTR N IVMMTIEN S IVMMTIEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),1)
177 ..Q:'IVMMTIEN
178 ..S NODE=$G(^DGMT(408.31,IVMMTIEN,2))
179 .S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
180 .I TMSTAMP,TMSTAMP=$P(NODE,"^",2),IVMMTDT=$P(NODE0,"^"),SOURCE=$P(NODE,"^",5),(HSDATE=$P(NODE,"^")) Q
181 .;
182 .D DELTYPE^IVMCMD(DFN,IVMMTDT,2)
183 .D EN^IVMCM1
184 ;
185 ;
186CT ; If transmission is a Copay Test
187 N NODE0,RET,CODE,DATA
188 I IVMTYPE=2 D I $D(HLERR) G PROCQ
189 .S IVMMTDT=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,2))
190 .S TMSTAMP=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,25))
191 .S SOURCE=$P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,22)
192 .S IVMLAST=$$LST^DGMTU(DFN,$E(IVMMTDT,1,3)_1231,2)
193 .S IVMCPAY=$$RXST^IBARXEU(DFN)
194 .I $$AGE^IVMUFNC5(DT)>$$INCY^IVMUFNC5(IVMMTDT) D PROB^IVMCMC("Only Copay Tests in the current/previous income years are valid. (Not effective)") Q
195 .; - perform edit checks and file CT
196 .D CHKDT
197 .;deletion indicator sent?
198 .I $P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,3)=HLQ D Q
199 ..D
200 ...;if there is a future test for that income year, delete that
201 ...N IEN,DATA,IVMPAT
202 ...S IEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),2,.IVMPAT)
203 ...I IEN S DATA(.07)="" I $$UPD^DGENDBS(301.5,IVMPAT,.DATA)
204 ...I IEN,$D(^DGMT(408.31,IEN,0)) D
205 ....S IVMMTIEN=IEN
206 ....S IVMFUTR=1
207 ...E D
208 ....S IVMFUTR=0
209 ..Q:('IVMMTIEN)
210 ..S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
211 ..I $$EN^IVMCMD(IVMMTIEN) D
212 ...S RET=$$LST^DGMTU(DFN,DT,IVMTYPE)
213 ...S CODE=$S(($E($P(RET,"^",2),1,3)=$E(DT,1,3)):$P(RET,"^",4),1:"")
214 ...D ADD^IVMCMB(DFN,IVMTYPE,$S(IVMFUTR:"DELETE FUTR TEST",1:"DELETE PRMRY TEST"),+$G(NODE0),$$GETCODE^DGMTH($P(NODE0,"^",3)),CODE)
215 .;
216 .;check timestamp - if matches current primary test, then this is a duplicate and does not need to be uploaded
217 .I TMSTAMP D
218 ..S NODE=""
219 ..I IVMFUTR N IVMMTIEN S IVMMTIEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),2)
220 ..Q:'IVMMTIEN
221 ..S NODE=$G(^DGMT(408.31,IVMMTIEN,2))
222 .S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
223 .I TMSTAMP,TMSTAMP=$P(NODE,"^",2),IVMMTDT=$P(NODE0,"^"),SOURCE=$P(NODE,"^",5) Q
224 .;
225 .D DELTYPE^IVMCMD(DFN,IVMMTDT,1)
226 .D EN^IVMCM1
227 ;
228IS ; - If transmission is income screening info only then do not process
229 ; - outside of the scope of MTS
230 ;I IVMTYPE=3 S IVMMTDT=0 D EN^IVMCM1 I $D(HLERR) G PROCQ
231 I IVMTYPE=3 S IVMMTDT=0
232 ;
233LTC ; If transmission contains a Long Term Care Test (TYPE 4 TEST)
234 I $P($G(^TMP($J,"IVMCM","ZMT4")),HLFS,2) D LTC^IVMCM1
235 ;
236PROCQ ;
237 ; release locks used to sychronize upload with local income test options
238 D RELLOCKS^IVMCUPL(DFN)
239 Q
240 ;
241CHKDT ; check date of income test being uploaded
242 ; Is it a future date? If so, set IVMFUTR=1
243 ;
244 ; IVMMTIEN is the IEN of current primary test for the year
245 ;
246 I $E($P(IVMLAST,"^",2),1,3)=$E(IVMMTDT,1,3) S IVMMTIEN=+IVMLAST
247 I IVMMTDT>DT S IVMFUTR=1
248 Q
249FUTURE(DFN,YEAR,TYPE,IVMPAT) ;
250 ;Returns the ien of the future test, if there is one
251 ;Inputs: DFN
252 ; YEAR - income year
253 ; TYPE - type of test
254 ;Output:
255 ; function value - ien of future means test, if there is one, "" otherwise
256 ; IVMPAT - Pointer to the IVM Patient file for the income year if there is an entry (pass by reference)
257 ;
258 N RET
259 S RET=""
260 S IVMPAT=$$FIND^IVMPLOG(DFN,YEAR)
261 I IVMPAT S RET=$P($G(^IVM(301.5,IVMPAT,0)),"^",$S(TYPE=1:6,1:7))
262 Q RET
Note: See TracBrowser for help on using the repository browser.