EASCM ;ALB/PJH,JAM - PROCESS INCOME TEST (Z10) TRANSMISSIONS ;7/1/09 3:36pm
;;1.0;ENROLLMENT APPLICATION SYSTEM;**71,96,152,172**;15-MAR-01;Build 3
;
;CLONED FROM IVMCM (ESR EVENT DRIVER)
;
ORF ; Handler for ORF type HL7 messages received from HEC
;
; Make sure POSTMASTER DUZ instead of DUZ of Person who
; started Incoming Logical Link.
S DUZ=.5
N CNT,IVMRTN,SEGCNT
S IVMRTN="IVMCMX" ;USE "IVMCMX" BECAUSE "IVMCM" ALREADY USED
K ^TMP($J,IVMRTN),DIC
S (DGMSGF,DGMTMSG)=1 ; HL7 rtn. Don't need DG interative messages.
S HLECH=HL("ECH"),HLQ=HL("Q"),HLMID=HL("MID")
K %,%H,%I D NOW^%DTC S HLDT=%
F SEGCNT=1:1 X HLNEXT Q:HLQUIT'>0 D
. S CNT=0
. S ^TMP($J,IVMRTN,SEGCNT,CNT)=HLNODE
. F S CNT=$O(HLNODE(CNT)) Q:'CNT D
. . S ^TMP($J,IVMRTN,SEGCNT,CNT)=HLNODE(CNT)
S HLDA=HLMTIEN
;
N SEG,EVENT,MSGID
S:'$D(HLEVN) HLEVN=0
D NXTSEG^DGENUPL(HLDA,0,.SEG)
Q:(SEG("TYPE")'="MSH") ;would not have reached here if this happened!
S EVENT=$P(SEG(9),$E(HLECH),2)
;
; INITIALIZE HL7 VARIABLES
S HLEID="EAS ESR "_$P($$SITE^VASITE,"^",3)_" ORF-"_EVENT_" SERVER"
S HLEID=$O(^ORD(101,"B",HLEID,0))
D INIT^HLFNC2(HLEID,.HL)
S HLEIDS=$O(^ORD(101,HLEID,775,"B",0))
;
; Handle means test signature ORF (Z06) event
I EVENT="Z06" D ORF^IVMPREC7
;
; Handle income test ORF (Z10) event
I EVENT="Z10" D Z10^IVMCM
;
; Handle enrollment/elig. ORF (Z11) event
I EVENT="Z11" D
.S MSGID=SEG(10)
.D ORFZ11^DGENUPL(HLDA,MSGID)
;
K ^TMP($J,IVMRTN)
Q
; Code below this line is not used - left in place for reference only
; all Z10 processing performed within IVMCM
Z10 ; Entry point for receipt of ORF~Z10 transmission
; The Income Test (Z10) transmission has the following format:
;
; BHS ORF msgs do not include batch header or trailer.
; {MSH
; PID They will include the sequence: MSA
; ZIC QRD
; ZIR QRF
; {ZDP These segments will follow the MSH segment.
; ZIC
; ZIR
; }
; {ZDP} Inactive Dependent Spouse Entries
; {ZDP} Inactive Dependent Child Entries
; {ZMT
; }
; ZBT
; }
; BTS
;
S IVMORF=1 ; set ORF msg flag
S (HLEVN,IVMCT,IVMERROR,IVMCNTR)=0 ; init vars
;
ORU ; Entry point for receipt of ORU~Z10 trans (called by IVMPREC2)
S IVMTYPE=5,IVMZ10F=1
;
; - loop through the msg in (#772 file), and process (PROC) msgs
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
;
; - if ORF msg flag, update the Query Tran Log and send ACK
I $G(IVMORF) D
.I $G(DFN),$D(IVMMCI) D
..N IVMCR
..S IVMCR=$P("1^2^3^7^5^6^4","^",IVMTYPE) ;map reason to test type
..D FIND^IVMCQ2(DFN,IVMMCI,HLDT,$S($D(HLERR):5,1:IVMCR),1)
.;D ACK^IVMPREC:'$D(HLERR)
.;N HLRESLTA,HLP
.;D GENACK^HLMA1(HLEID,HLMTIEN,HLEIDS,"LM",1,.HLRESLTA,"",.HLP)
;
; - if tests are uploaded, generate notification msg
I $D(^TMP($J,"IVMBULL")) D ^IVMCMB
;
ENQ ;
K IVMDA,IVMORF,IVMSEG,IVMFLGC,IVMTYPE,IVMMTIEN,IVMMTDT,IVMDGBT,IVMMCI
K ^TMP($J,"IVMCM"),^("IVMBULL"),DGMSGF,DGADDF,IVMCPAY,IVMBULL,DFN
K DGMTMSG,IVMZ10F
Q
;
PROC ; Process each HL7 message from (#772) file
;
N IVMFUTR,TMSTAMP,SOURCE,NODE,HSDATE,IVMZ10,DGMTP,DGMTACT,DGMTI,DGMTA
S DGMTACT="ADD"
D PRIOR^DGMTEVT
S IVMZ10="UPLOAD IN PROGRESS"
S IVMFUTR=0 ;this flag will indicate whether or not a test with a future date is being uploaded
S IVMMTIEN=0
;
S MSGID=$P(IVMSEG,HLFS,10) ; msg control id for ACK's
; - check if DCD messaging is enabled
I '$$DCDON^IVMUPAR1() D PROB^IVMCMC("Facility has DCD messaging disabled") Q
;
; - check HL7 msg structure for errors
K HLERR,^TMP($J,"IVMCM")
; jam; EAS*1.0*172 - set IVMSSNFLAG=0 and quit processing if the flag is set upon return from ^IVMCMC
; (see ^IVMCMC for what sets this flag)
N IVMSSNFLAG
S IVMSSNFLAG=0
D ^IVMCMC I $D(HLERR) K:HLERR="" HLERR Q
I IVMSSNFLAG Q
;
; Determine type of test/transmission
S IVMTYPE=0
;
; - was a means test sent?
I $P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,2) S IVMTYPE=1 ; MT trans
;
; - if MT and CT transmitted, error - pt can't have both unless
; one is a deletion, but HEC not currently handling that situation
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
I $P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,2) S IVMTYPE=2 ; CT trans
;
; - if no MT or CT or LTC then Income Screening
I 'IVMTYPE,'$P($G(^TMP($J,"IVMCM","ZMT4")),HLFS,2) S IVMTYPE=3 ; IS trans
;
;send an eligibility query if no eligibility code
I '$$ELIG^IVMCUF1(DFN),'$$PENDING^DGENQRY(DFN) I $$SEND^DGENQRY1(DFN)
;
; obtain locks used to sychronize upload with local income test options
D GETLOCKS^IVMCUPL(DFN)
;
;
MT ; If transmission is a Means Test
N NODE0,RET,CODE,DATA,MTSIG,MTSIGDT
S HLQ=$G(HL("Q"))
S:HLQ="" HLQ=""""""
I IVMTYPE=1 D I $D(HLERR) G PROCQ
.S IVMMTDT=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,2))
.S TMSTAMP=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,25))
.S HSDATE=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,24))
.S SOURCE=$P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,22)
.S MTSIG=$P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,27)
.S MTSIGDT=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,15))
.S IVMLAST=$$LST^DGMTU(DFN,$E(IVMMTDT,1,3)_1231,1)
.; Check that test is for same year *152
.I $P(IVMLAST,U,2),$E($P(IVMLAST,U,2),1,3)'=$E(IVMMTDT,1,3) S IVMLAST="" ;*152
.Q:$$UPDMTSIG^IVMCMF(+IVMLAST,TMSTAMP,MTSIG,MTSIGDT)
.I $$Z06MT^EASPTRN1(+IVMLAST) Q
.I '$$ELIG^IVMUFNC5(DFN) S ERRMSG="Means Test upload not appropriate for current patient"
.I $$AGE^IVMUFNC5(DT)>$$INCY^IVMUFNC5(IVMMTDT) D
..N CATCZMT S CATCZMT=$G(^TMP($J,"IVMCM","ZMT1"))
..S CATC=$$CATC^IVMUFNC5(CATCZMT)
..I '+$G(CATC) S ERRMSG="Only Means Tests in current/previous income years are valid (not effective)"
.I $G(ERRMSG)'="" D PROB^IVMCMC(ERRMSG) K ERRMSG,CATC Q
.;
.; - perform edit checks and file MT
.D CHKDT
.;deletion indicator sent?
.I $P($G(^TMP($J,"IVMCM","ZMT1")),HLFS,3)=HLQ D Q
..D
...;if there is a future test for that income year, delete that
...N IEN,DATA,IVMPAT
...S IEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),1,.IVMPAT)
...I IEN S DATA(.06)="" I $$UPD^DGENDBS(301.5,IVMPAT,.DATA)
...I IEN,$D(^DGMT(408.31,IEN,0)) D
....S IVMMTIEN=IEN
....S IVMFUTR=1
...E D
....S IVMFUTR=0
..Q:('IVMMTIEN)
..S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
..I $$EN^IVMCMD(IVMMTIEN) D
...S RET=$$LST^DGMTU(DFN,DT,IVMTYPE)
...S CODE=$S(($E($P(RET,"^",2),1,3)=$E(DT,1,3)):$P(RET,"^",4),1:"")
...D ADD^IVMCMB(DFN,IVMTYPE,$S(IVMFUTR:"DELETE FUTR TEST",1:"DELETE PRMRY TEST"),+$G(NODE0),$$GETCODE^DGMTH($P(NODE0,"^",3)),CODE)
.;
.;check timestamp - if matches current primary test and hardship matches, then this is a duplicate and does not need to be uploaded
.I TMSTAMP D
..S NODE=""
..I IVMFUTR N IVMMTIEN S IVMMTIEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),1)
..Q:'IVMMTIEN
..S NODE=$G(^DGMT(408.31,IVMMTIEN,2))
.S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
.I TMSTAMP,TMSTAMP=$P(NODE,"^",2),IVMMTDT=$P(NODE0,"^"),SOURCE=$P(NODE,"^",5),(HSDATE=$P(NODE,"^")) Q
.;
.D DELTYPE^IVMCMD(DFN,IVMMTDT,2)
.D EN^IVMCM1
;
;
CT ; If transmission is a Copay Test
N NODE0,RET,CODE,DATA
I IVMTYPE=2 D I $D(HLERR) G PROCQ
.S IVMMTDT=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,2))
.S TMSTAMP=$$FMDATE^HLFNC($P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,25))
.S SOURCE=$P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,22)
.S IVMLAST=$$LST^DGMTU(DFN,$E(IVMMTDT,1,3)_1231,2)
.S IVMCPAY=$$RXST^IBARXEU(DFN)
.I $$AGE^IVMUFNC5(DT)>$$INCY^IVMUFNC5(IVMMTDT) D PROB^IVMCMC("Only Copay Tests in the current/previous income years are valid. (Not effective)") Q
.; - perform edit checks and file CT
.D CHKDT
.;deletion indicator sent?
.I $P($G(^TMP($J,"IVMCM","ZMT2")),HLFS,3)=HLQ D Q
..D
...;if there is a future test for that income year, delete that
...N IEN,DATA,IVMPAT
...S IEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),2,.IVMPAT)
...I IEN S DATA(.07)="" I $$UPD^DGENDBS(301.5,IVMPAT,.DATA)
...I IEN,$D(^DGMT(408.31,IEN,0)) D
....S IVMMTIEN=IEN
....S IVMFUTR=1
...E D
....S IVMFUTR=0
..Q:('IVMMTIEN)
..S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
..I $$EN^IVMCMD(IVMMTIEN) D
...S RET=$$LST^DGMTU(DFN,DT,IVMTYPE)
...S CODE=$S(($E($P(RET,"^",2),1,3)=$E(DT,1,3)):$P(RET,"^",4),1:"")
...D ADD^IVMCMB(DFN,IVMTYPE,$S(IVMFUTR:"DELETE FUTR TEST",1:"DELETE PRMRY TEST"),+$G(NODE0),$$GETCODE^DGMTH($P(NODE0,"^",3)),CODE)
.;
.;check timestamp - if matches current primary test, then this is a duplicate and does not need to be uploaded
.I TMSTAMP D
..S NODE=""
..I IVMFUTR N IVMMTIEN S IVMMTIEN=$$FUTURE(DFN,($E(IVMMTDT,1,3)-1),2)
..Q:'IVMMTIEN
..S NODE=$G(^DGMT(408.31,IVMMTIEN,2))
.S NODE0=$G(^DGMT(408.31,IVMMTIEN,0))
.I TMSTAMP,TMSTAMP=$P(NODE,"^",2),IVMMTDT=$P(NODE0,"^"),SOURCE=$P(NODE,"^",5) Q
.;
.D DELTYPE^IVMCMD(DFN,IVMMTDT,1)
.D EN^IVMCM1
;
IS ; - If transmission is income screening info only then do not process
; - outside of the scope of MTS
I IVMTYPE=3 S IVMMTDT=0
;
LTC ; If transmission contains a Long Term Care Test (TYPE 4 TEST)
I $P($G(^TMP($J,"IVMCM","ZMT4")),HLFS,2) D LTC^IVMCM1
;
PROCQ ;
; release locks used to sychronize upload with local income test options
D RELLOCKS^IVMCUPL(DFN)
Q
;
CHKDT ; check date of income test being uploaded
; Is it a future date? If so, set IVMFUTR=1
;
; IVMMTIEN is the IEN of current primary test for the year
;
I $E($P(IVMLAST,"^",2),1,3)=$E(IVMMTDT,1,3) S IVMMTIEN=+IVMLAST
I IVMMTDT>DT S IVMFUTR=1
Q
FUTURE(DFN,YEAR,TYPE,IVMPAT) ;
;Returns the ien of the future test, if there is one
;Inputs: DFN
; YEAR - income year
; TYPE - type of test
;Output:
; function value - ien of future means test, if there is one, "" otherwise
; IVMPAT - Pointer to the IVM Patient file for the income year if there is an entry (pass by reference)
;
N RET
S RET=""
S IVMPAT=$$FIND^IVMPLOG(DFN,YEAR)
I IVMPAT S RET=$P($G(^IVM(301.5,IVMPAT,0)),"^",$S(TYPE=1:6,1:7))
Q RET
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEASCM 10374 printed Oct 16, 2024@17:54:29 Page 2
EASCM ;ALB/PJH,JAM - PROCESS INCOME TEST (Z10) TRANSMISSIONS ;7/1/09 3:36pm
+1 ;;1.0;ENROLLMENT APPLICATION SYSTEM;**71,96,152,172**;15-MAR-01;Build 3
+2 ;
+3 ;CLONED FROM IVMCM (ESR EVENT DRIVER)
+4 ;
ORF ; Handler for ORF type HL7 messages received from HEC
+1 ;
+2 ; Make sure POSTMASTER DUZ instead of DUZ of Person who
+3 ; started Incoming Logical Link.
+4 SET DUZ=.5
+5 NEW CNT,IVMRTN,SEGCNT
+6 ;USE "IVMCMX" BECAUSE "IVMCM" ALREADY USED
SET IVMRTN="IVMCMX"
+7 KILL ^TMP($JOB,IVMRTN),DIC
+8 ; HL7 rtn. Don't need DG interative messages.
SET (DGMSGF,DGMTMSG)=1
+9 SET HLECH=HL("ECH")
SET HLQ=HL("Q")
SET HLMID=HL("MID")
+10 KILL %,%H,%I
DO NOW^%DTC
SET HLDT=%
+11 FOR SEGCNT=1:1
XECUTE HLNEXT
if HLQUIT'>0
QUIT
Begin DoDot:1
+12 SET CNT=0
+13 SET ^TMP($JOB,IVMRTN,SEGCNT,CNT)=HLNODE
+14 FOR
SET CNT=$ORDER(HLNODE(CNT))
if 'CNT
QUIT
Begin DoDot:2
+15 SET ^TMP($JOB,IVMRTN,SEGCNT,CNT)=HLNODE(CNT)
End DoDot:2
End DoDot:1
+16 SET HLDA=HLMTIEN
+17 ;
+18 NEW SEG,EVENT,MSGID
+19 if '$DATA(HLEVN)
SET HLEVN=0
+20 DO NXTSEG^DGENUPL(HLDA,0,.SEG)
+21 ;would not have reached here if this happened!
if (SEG("TYPE")'="MSH")
QUIT
+22 SET EVENT=$PIECE(SEG(9),$EXTRACT(HLECH),2)
+23 ;
+24 ; INITIALIZE HL7 VARIABLES
+25 SET HLEID="EAS ESR "_$PIECE($$SITE^VASITE,"^",3)_" ORF-"_EVENT_" SERVER"
+26 SET HLEID=$ORDER(^ORD(101,"B",HLEID,0))
+27 DO INIT^HLFNC2(HLEID,.HL)
+28 SET HLEIDS=$ORDER(^ORD(101,HLEID,775,"B",0))
+29 ;
+30 ; Handle means test signature ORF (Z06) event
+31 IF EVENT="Z06"
DO ORF^IVMPREC7
+32 ;
+33 ; Handle income test ORF (Z10) event
+34 IF EVENT="Z10"
DO Z10^IVMCM
+35 ;
+36 ; Handle enrollment/elig. ORF (Z11) event
+37 IF EVENT="Z11"
Begin DoDot:1
+38 SET MSGID=SEG(10)
+39 DO ORFZ11^DGENUPL(HLDA,MSGID)
End DoDot:1
+40 ;
+41 KILL ^TMP($JOB,IVMRTN)
+42 QUIT
+43 ; Code below this line is not used - left in place for reference only
+44 ; all Z10 processing performed within IVMCM
Z10 ; Entry point for receipt of ORF~Z10 transmission
+1 ; The Income Test (Z10) transmission has the following format:
+2 ;
+3 ; BHS ORF msgs do not include batch header or trailer.
+4 ; {MSH
+5 ; PID They will include the sequence: MSA
+6 ; ZIC QRD
+7 ; ZIR QRF
+8 ; {ZDP These segments will follow the MSH segment.
+9 ; ZIC
+10 ; ZIR
+11 ; }
+12 ; {ZDP} Inactive Dependent Spouse Entries
+13 ; {ZDP} Inactive Dependent Child Entries
+14 ; {ZMT
+15 ; }
+16 ; ZBT
+17 ; }
+18 ; BTS
+19 ;
+20 ; set ORF msg flag
SET IVMORF=1
+21 ; init vars
SET (HLEVN,IVMCT,IVMERROR,IVMCNTR)=0
+22 ;
ORU ; Entry point for receipt of ORU~Z10 trans (called by IVMPREC2)
+1 SET IVMTYPE=5
SET IVMZ10F=1
+2 ;
+3 ; - loop through the msg in (#772 file), and process (PROC) msgs
+4 SET IVMDA=0
FOR
SET IVMDA=$ORDER(^TMP($JOB,IVMRTN,IVMDA))
if 'IVMDA
QUIT
SET IVMSEG=$GET(^(IVMDA,0))
IF $EXTRACT(IVMSEG,1,3)="MSH"
DO PROC
if 'IVMDA
QUIT
+5 ;
+6 ; - if ORF msg flag, update the Query Tran Log and send ACK
+7 IF $GET(IVMORF)
Begin DoDot:1
+8 IF $GET(DFN)
IF $DATA(IVMMCI)
Begin DoDot:2
+9 NEW IVMCR
+10 ;map reason to test type
SET IVMCR=$PIECE("1^2^3^7^5^6^4","^",IVMTYPE)
+11 DO FIND^IVMCQ2(DFN,IVMMCI,HLDT,$SELECT($DATA(HLERR):5,1:IVMCR),1)
End DoDot:2
+12 ;D ACK^IVMPREC:'$D(HLERR)
+13 ;N HLRESLTA,HLP
+14 ;D GENACK^HLMA1(HLEID,HLMTIEN,HLEIDS,"LM",1,.HLRESLTA,"",.HLP)
End DoDot:1
+15 ;
+16 ; - if tests are uploaded, generate notification msg
+17 IF $DATA(^TMP($JOB,"IVMBULL"))
DO ^IVMCMB
+18 ;
ENQ ;
+1 KILL IVMDA,IVMORF,IVMSEG,IVMFLGC,IVMTYPE,IVMMTIEN,IVMMTDT,IVMDGBT,IVMMCI
+2 KILL ^TMP($JOB,"IVMCM"),^("IVMBULL"),DGMSGF,DGADDF,IVMCPAY,IVMBULL,DFN
+3 KILL DGMTMSG,IVMZ10F
+4 QUIT
+5 ;
PROC ; Process each HL7 message from (#772) file
+1 ;
+2 NEW IVMFUTR,TMSTAMP,SOURCE,NODE,HSDATE,IVMZ10,DGMTP,DGMTACT,DGMTI,DGMTA
+3 SET DGMTACT="ADD"
+4 DO PRIOR^DGMTEVT
+5 SET IVMZ10="UPLOAD IN PROGRESS"
+6 ;this flag will indicate whether or not a test with a future date is being uploaded
SET IVMFUTR=0
+7 SET IVMMTIEN=0
+8 ;
+9 ; msg control id for ACK's
SET MSGID=$PIECE(IVMSEG,HLFS,10)
+10 ; - check if DCD messaging is enabled
+11 IF '$$DCDON^IVMUPAR1()
DO PROB^IVMCMC("Facility has DCD messaging disabled")
QUIT
+12 ;
+13 ; - check HL7 msg structure for errors
+14 KILL HLERR,^TMP($JOB,"IVMCM")
+15 ; jam; EAS*1.0*172 - set IVMSSNFLAG=0 and quit processing if the flag is set upon return from ^IVMCMC
+16 ; (see ^IVMCMC for what sets this flag)
+17 NEW IVMSSNFLAG
+18 SET IVMSSNFLAG=0
+19 DO ^IVMCMC
IF $DATA(HLERR)
if HLERR=""
KILL HLERR
QUIT
+20 IF IVMSSNFLAG
QUIT
+21 ;
+22 ; Determine type of test/transmission
+23 SET IVMTYPE=0
+24 ;
+25 ; - was a means test sent?
+26 ; MT trans
IF $PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,2)
SET IVMTYPE=1
+27 ;
+28 ; - if MT and CT transmitted, error - pt can't have both unless
+29 ; one is a deletion, but HEC not currently handling that situation
+30 IF IVMTYPE
IF $PIECE($GET(^TMP($JOB,"IVMCM","ZMT2")),HLFS,2)
DO PROB^IVMCMC("Patient can not have both a Means Test and Copay Test")
QUIT
+31 ; CT trans
IF $PIECE($GET(^TMP($JOB,"IVMCM","ZMT2")),HLFS,2)
SET IVMTYPE=2
+32 ;
+33 ; - if no MT or CT or LTC then Income Screening
+34 ; IS trans
IF 'IVMTYPE
IF '$PIECE($GET(^TMP($JOB,"IVMCM","ZMT4")),HLFS,2)
SET IVMTYPE=3
+35 ;
+36 ;send an eligibility query if no eligibility code
+37 IF '$$ELIG^IVMCUF1(DFN)
IF '$$PENDING^DGENQRY(DFN)
IF $$SEND^DGENQRY1(DFN)
+38 ;
+39 ; obtain locks used to sychronize upload with local income test options
+40 DO GETLOCKS^IVMCUPL(DFN)
+41 ;
+42 ;
MT ; If transmission is a Means Test
+1 NEW NODE0,RET,CODE,DATA,MTSIG,MTSIGDT
+2 SET HLQ=$GET(HL("Q"))
+3 if HLQ=""
SET HLQ=""""""
+4 IF IVMTYPE=1
Begin DoDot:1
+5 SET IVMMTDT=$$FMDATE^HLFNC($PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,2))
+6 SET TMSTAMP=$$FMDATE^HLFNC($PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,25))
+7 SET HSDATE=$$FMDATE^HLFNC($PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,24))
+8 SET SOURCE=$PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,22)
+9 SET MTSIG=$PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,27)
+10 SET MTSIGDT=$$FMDATE^HLFNC($PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,15))
+11 SET IVMLAST=$$LST^DGMTU(DFN,$EXTRACT(IVMMTDT,1,3)_1231,1)
+12 ; Check that test is for same year *152
+13 ;*152
IF $PIECE(IVMLAST,U,2)
IF $EXTRACT($PIECE(IVMLAST,U,2),1,3)'=$EXTRACT(IVMMTDT,1,3)
SET IVMLAST=""
+14 if $$UPDMTSIG^IVMCMF(+IVMLAST,TMSTAMP,MTSIG,MTSIGDT)
QUIT
+15 IF $$Z06MT^EASPTRN1(+IVMLAST)
QUIT
+16 IF '$$ELIG^IVMUFNC5(DFN)
SET ERRMSG="Means Test upload not appropriate for current patient"
+17 IF $$AGE^IVMUFNC5(DT)>$$INCY^IVMUFNC5(IVMMTDT)
Begin DoDot:2
+18 NEW CATCZMT
SET CATCZMT=$GET(^TMP($JOB,"IVMCM","ZMT1"))
+19 SET CATC=$$CATC^IVMUFNC5(CATCZMT)
+20 IF '+$GET(CATC)
SET ERRMSG="Only Means Tests in current/previous income years are valid (not effective)"
End DoDot:2
+21 IF $GET(ERRMSG)'=""
DO PROB^IVMCMC(ERRMSG)
KILL ERRMSG,CATC
QUIT
+22 ;
+23 ; - perform edit checks and file MT
+24 DO CHKDT
+25 ;deletion indicator sent?
+26 IF $PIECE($GET(^TMP($JOB,"IVMCM","ZMT1")),HLFS,3)=HLQ
Begin DoDot:2
+27 Begin DoDot:3
+28 ;if there is a future test for that income year, delete that
+29 NEW IEN,DATA,IVMPAT
+30 SET IEN=$$FUTURE(DFN,($EXTRACT(IVMMTDT,1,3)-1),1,.IVMPAT)
+31 IF IEN
SET DATA(.06)=""
IF $$UPD^DGENDBS(301.5,IVMPAT,.DATA)
+32 IF IEN
IF $DATA(^DGMT(408.31,IEN,0))
Begin DoDot:4
+33 SET IVMMTIEN=IEN
+34 SET IVMFUTR=1
End DoDot:4
+35 IF '$TEST
Begin DoDot:4
+36 SET IVMFUTR=0
End DoDot:4
End DoDot:3
+37 if ('IVMMTIEN)
QUIT
+38 SET NODE0=$GET(^DGMT(408.31,IVMMTIEN,0))
+39 IF $$EN^IVMCMD(IVMMTIEN)
Begin DoDot:3
+40 SET RET=$$LST^DGMTU(DFN,DT,IVMTYPE)
+41 SET CODE=$SELECT(($EXTRACT($PIECE(RET,"^",2),1,3)=$EXTRACT(DT,1,3)):$PIECE(RET,"^",4),1:"")
+42 DO ADD^IVMCMB(DFN,IVMTYPE,$SELECT(IVMFUTR:"DELETE FUTR TEST",1:"DELETE PRMRY TEST"),+$GET(NODE0),$$GETCODE^DGMTH($PIECE(NODE0,"^",3)),CODE)
End DoDot:3
End DoDot:2
QUIT
+43 ;
+44 ;check timestamp - if matches current primary test and hardship matches, then this is a duplicate and does not need to be uploaded
+45 IF TMSTAMP
Begin DoDot:2
+46 SET NODE=""
+47 IF IVMFUTR
NEW IVMMTIEN
SET IVMMTIEN=$$FUTURE(DFN,($EXTRACT(IVMMTDT,1,3)-1),1)
+48 if 'IVMMTIEN
QUIT
+49 SET NODE=$GET(^DGMT(408.31,IVMMTIEN,2))
End DoDot:2
+50 SET NODE0=$GET(^DGMT(408.31,IVMMTIEN,0))
+51 IF TMSTAMP
IF TMSTAMP=$PIECE(NODE,"^",2)
IF IVMMTDT=$PIECE(NODE0,"^")
IF SOURCE=$PIECE(NODE,"^",5)
IF (HSDATE=$PIECE(NODE,"^"))
QUIT
+52 ;
+53 DO DELTYPE^IVMCMD(DFN,IVMMTDT,2)
+54 DO EN^IVMCM1
End DoDot:1
IF $DATA(HLERR)
GOTO PROCQ
+55 ;
+56 ;
CT ; If transmission is a Copay Test
+1 NEW NODE0,RET,CODE,DATA
+2 IF IVMTYPE=2
Begin DoDot:1
+3 SET IVMMTDT=$$FMDATE^HLFNC($PIECE($GET(^TMP($JOB,"IVMCM","ZMT2")),HLFS,2))
+4 SET TMSTAMP=$$FMDATE^HLFNC($PIECE($GET(^TMP($JOB,"IVMCM","ZMT2")),HLFS,25))
+5 SET SOURCE=$PIECE($GET(^TMP($JOB,"IVMCM","ZMT2")),HLFS,22)
+6 SET IVMLAST=$$LST^DGMTU(DFN,$EXTRACT(IVMMTDT,1,3)_1231,2)
+7 SET IVMCPAY=$$RXST^IBARXEU(DFN)
+8 IF $$AGE^IVMUFNC5(DT)>$$INCY^IVMUFNC5(IVMMTDT)
DO PROB^IVMCMC("Only Copay Tests in the current/previous income years are valid. (Not effective)")
QUIT
+9 ; - perform edit checks and file CT
+10 DO CHKDT
+11 ;deletion indicator sent?
+12 IF $PIECE($GET(^TMP($JOB,"IVMCM","ZMT2")),HLFS,3)=HLQ
Begin DoDot:2
+13 Begin DoDot:3
+14 ;if there is a future test for that income year, delete that
+15 NEW IEN,DATA,IVMPAT
+16 SET IEN=$$FUTURE(DFN,($EXTRACT(IVMMTDT,1,3)-1),2,.IVMPAT)
+17 IF IEN
SET DATA(.07)=""
IF $$UPD^DGENDBS(301.5,IVMPAT,.DATA)
+18 IF IEN
IF $DATA(^DGMT(408.31,IEN,0))
Begin DoDot:4
+19 SET IVMMTIEN=IEN
+20 SET IVMFUTR=1
End DoDot:4
+21 IF '$TEST
Begin DoDot:4
+22 SET IVMFUTR=0
End DoDot:4
End DoDot:3
+23 if ('IVMMTIEN)
QUIT
+24 SET NODE0=$GET(^DGMT(408.31,IVMMTIEN,0))
+25 IF $$EN^IVMCMD(IVMMTIEN)
Begin DoDot:3
+26 SET RET=$$LST^DGMTU(DFN,DT,IVMTYPE)
+27 SET CODE=$SELECT(($EXTRACT($PIECE(RET,"^",2),1,3)=$EXTRACT(DT,1,3)):$PIECE(RET,"^",4),1:"")
+28 DO ADD^IVMCMB(DFN,IVMTYPE,$SELECT(IVMFUTR:"DELETE FUTR TEST",1:"DELETE PRMRY TEST"),+$GET(NODE0),$$GETCODE^DGMTH($PIECE(NODE0,"^",3)),CODE)
End DoDot:3
End DoDot:2
QUIT
+29 ;
+30 ;check timestamp - if matches current primary test, then this is a duplicate and does not need to be uploaded
+31 IF TMSTAMP
Begin DoDot:2
+32 SET NODE=""
+33 IF IVMFUTR
NEW IVMMTIEN
SET IVMMTIEN=$$FUTURE(DFN,($EXTRACT(IVMMTDT,1,3)-1),2)
+34 if 'IVMMTIEN
QUIT
+35 SET NODE=$GET(^DGMT(408.31,IVMMTIEN,2))
End DoDot:2
+36 SET NODE0=$GET(^DGMT(408.31,IVMMTIEN,0))
+37 IF TMSTAMP
IF TMSTAMP=$PIECE(NODE,"^",2)
IF IVMMTDT=$PIECE(NODE0,"^")
IF SOURCE=$PIECE(NODE,"^",5)
QUIT
+38 ;
+39 DO DELTYPE^IVMCMD(DFN,IVMMTDT,1)
+40 DO EN^IVMCM1
End DoDot:1
IF $DATA(HLERR)
GOTO PROCQ
+41 ;
IS ; - If transmission is income screening info only then do not process
+1 ; - outside of the scope of MTS
+2 IF IVMTYPE=3
SET IVMMTDT=0
+3 ;
LTC ; If transmission contains a Long Term Care Test (TYPE 4 TEST)
+1 IF $PIECE($GET(^TMP($JOB,"IVMCM","ZMT4")),HLFS,2)
DO LTC^IVMCM1
+2 ;
PROCQ ;
+1 ; release locks used to sychronize upload with local income test options
+2 DO RELLOCKS^IVMCUPL(DFN)
+3 QUIT
+4 ;
CHKDT ; check date of income test being uploaded
+1 ; Is it a future date? If so, set IVMFUTR=1
+2 ;
+3 ; IVMMTIEN is the IEN of current primary test for the year
+4 ;
+5 IF $EXTRACT($PIECE(IVMLAST,"^",2),1,3)=$EXTRACT(IVMMTDT,1,3)
SET IVMMTIEN=+IVMLAST
+6 IF IVMMTDT>DT
SET IVMFUTR=1
+7 QUIT
FUTURE(DFN,YEAR,TYPE,IVMPAT) ;
+1 ;Returns the ien of the future test, if there is one
+2 ;Inputs: DFN
+3 ; YEAR - income year
+4 ; TYPE - type of test
+5 ;Output:
+6 ; function value - ien of future means test, if there is one, "" otherwise
+7 ; IVMPAT - Pointer to the IVM Patient file for the income year if there is an entry (pass by reference)
+8 ;
+9 NEW RET
+10 SET RET=""
+11 SET IVMPAT=$$FIND^IVMPLOG(DFN,YEAR)
+12 IF IVMPAT
SET RET=$PIECE($GET(^IVM(301.5,IVMPAT,0)),"^",$SELECT(TYPE=1:6,1:7))
+13 QUIT RET