SDESPATRPC ;ALB/TAW,RJT,ANU,MGD,DJS,RRM - PATIENT RPCS ;Aug 11, 2022
;;5.3;Scheduling;**792,804,805,807,809,814,816,820,823,824**;Aug 13, 1993;Build 3
;
; Reference to ^IBA(355.33 in ICR #6891
; Reference to $$GETS^DIQ,$$GET1^DIQ in ICR #2056
; Reference to #354 in ICR #5296
;
Q
;
INSURINDICATORS(RETURN,DFNS) ;
Q:$D(DFNS)=0
N INDICATORS,SDINDEX,HASDFNERRORS,PTDFN,SDINDEX,SDCNT
S SDINDEX="",SDCNT=0
F S SDINDEX=$O(DFNS(SDINDEX)) Q:(SDINDEX="")!(SDCNT>100) D
.S SDCNT=SDCNT+1
.S PTDFN=DFNS(SDINDEX)
.S INDICATORS("NeedInsuranceVerification",SDINDEX,"DFN")=PTDFN
.S INDICATORS("NeedInsuranceVerification",SDINDEX,"ICN")=$$GETPATICN^SDESINPUTVALUTL(PTDFN)
.I $G(SDCNT)>100 D
..S INDICATORS("NeedInsuranceVerification",SDINDEX,"Errors")="Max number of records allowed is 100"
.Q:SDCNT>100
.N DFNERRORS
.S HASDFNERRORS=$$VALIDATEDFN(.DFNERRORS,PTDFN)
.I $G(HASDFNERRORS) D
..S INDICATORS("NeedInsuranceVerification",SDINDEX,"Errors")="DFN Error"
..S INDICATORS("NeedInsuranceVerification",SDINDEX,"YesNo")=""
.I '$G(HASDFNERRORS) D
..N FLG
..D NEEDVERIFY(.FLG,PTDFN,180,90)
..S INDICATORS("NeedInsuranceVerification",SDINDEX,"YesNo")=FLG
D BUILDJSON(.RETURN,.INDICATORS)
Q
;
VALIDATEDFN(ERRORS,PDFN) ;
N ERRORFLAG
I $G(PDFN)="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,1)
I $G(PDFN)'="",'$D(^DPT(PDFN,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,2)
Q $D(ERRORFLAG)
;
BUILDJSON(JSONRETURN,INPUT) ;
N JSONERROR
S JSONERROR=""
D ENCODE^XLFJSON("INPUT","JSONRETURN","JSONERROR")
Q
;
INSURVERIFYREQ(RETURN,DFN,SDEAS) ;
N POP,SDPAT,FLG
S (FLG,POP)=0
S DFN=$G(DFN)
I DFN="" S POP=1 D ERRLOG^SDESJSON(.SDPAT,1)
I DFN'="",'$D(^DPT(DFN,0)) S POP=1 D ERRLOG^SDESJSON(.SDPAT,2)
S SDEAS=$G(SDEAS,"")
I $L(SDEAS) S SDEAS=$$EASVALIDATE^SDESUTIL(SDEAS)
I $G(SDEAS)=-1 S POP=1 D ERRLOG^SDESJSON(.SDPAT,142)
I '$G(POP) D NEEDVERIFY(.FLG,DFN,180,90) S SDPAT("NeedInsuranceVerification","YesNo")=FLG
D BUILDER
Q
NEEDVERIFY(NEEDVERIFY,DFN,LASTVERFWINDOW,NOCOVWINDOW) ;
; LASTVERFWINDOW - How many days in the past to look for a Last Verified Date
; NOCOVWINDOW - How many days in the past to look for a No Coverage Date
;
; Return
; 1 = Verification needed (Default)
; 0 = Has active insurance or verification started
N IENS,SDMSG,PATDATA,BILLPATDATA,NOCOVDT,COVBYHI,SUBIEN,XDT,TMPDT,INDEXEND,IBAIEN,IBADATA
N FEDONLY,FEDPOLICY
S NEEDVERIFY=1
;
;SD*5.3*816
;
S IBAIEN=""
S FEDONLY="Y"
F S IBAIEN=$O(^IBA(355.33,"C",DFN,IBAIEN)) Q:IBAIEN=""!(FEDONLY="N") D
.S FEDPOLICY=""
.S FEDPOLICY=$$GET1^DIQ(355.33,IBAIEN,20.01,"E")
.S FEDPOLICY=$G(FEDPOLICY,"")
.S FEDPOLICY=$$UP^XLFSTR(FEDPOLICY)
.Q:((FEDPOLICY["MEDICAID")!(FEDPOLICY["MEDICARE")!(FEDPOLICY["TRICARE")!(FEDPOLICY["CHAMPVA"))
.S FEDONLY="N"
;
S SUBIEN=0
F S SUBIEN=$O(^DPT(DFN,.312,SUBIEN)) Q:SUBIEN=""!('SUBIEN)!(FEDONLY="N") D
.S IENS=SUBIEN_","_DFN_","
.K PATDATA
.D GETS^DIQ(2.312,IENS,".01;3","IE","PATDATA","SDMSG")
.;Check the Insurance Expiration Data is active
.S TMPDT=PATDATA(2.312,IENS,3,"I")
.S TMPDT=$G(TMPDT)
.I +TMPDT,(+TMPDT'>DT) Q ;term date of today is inactive coverage
.S FEDPOLICY=""
.S FEDPOLICY=PATDATA(2.312,IENS,.01,"E")
.S FEDPOLICY=$G(FEDPOLICY,"")
.S FEDPOLICY=$$UP^XLFSTR(FEDPOLICY)
.Q:((FEDPOLICY["MEDICAID")!(FEDPOLICY["MEDICARE")!(FEDPOLICY["TRICARE")!(FEDPOLICY["CHAMPVA"))
.S FEDONLY="N"
;
I $G(FEDONLY)="Y" S LASTVERFWINDOW=365
;
;Check the Insurance Verification Processor file
; The assumption is that once verification is complete all
; references to the patient are removed.
S IBAIEN=""
S INDEXEND=$$FMADD^XLFDT(DT,-LASTVERFWINDOW)
F S IBAIEN=$O(^IBA(355.33,"C",DFN,IBAIEN)) Q:IBAIEN="" D
. K IBADATA
. Q:$$GET1^DIQ(355.33,IBAIEN,.01,"I")<INDEXEND
. I $$GET1^DIQ(355.33,IBAIEN,.04,"I")="E" S NEEDVERIFY=0 ;Entered - verification has started
I $G(NEEDVERIFY)=0 Q ;Verification not needed
;
;Check the Insurance Types (sub file .321) of the Patient File (#2)
S SUBIEN=0
F S SUBIEN=$O(^DPT(DFN,.312,SUBIEN)) Q:SUBIEN=""!(NEEDVERIFY=0)!('SUBIEN) D
.S IENS=SUBIEN_","_DFN_","
.K PATDATA
.D GETS^DIQ(2.312,IENS,"1.03;3","I","PATDATA","SDMSG")
.;Check the Insurance Expiration Data is active
.S TMPDT=PATDATA(2.312,IENS,3,"I")
.S TMPDT=$G(TMPDT)
.I +TMPDT,(+TMPDT'>DT) Q ;term date of today is inactive coverage
.;Check the Date Last Verified
.S TMPDT=$P(PATDATA(2.312,IENS,1.03,"I"),".")
.S TMPDT=$G(TMPDT)
.I TMPDT D
..S XDT=$$FMADD^XLFDT(DT,-LASTVERFWINDOW)
..S XDT=$G(XDT)
..I XDT<TMPDT S NEEDVERIFY=0
I $G(NEEDVERIFY)=0 Q ;Verification not needed
;
;If no insurance or unknown on file then check the Covered by Health Insurance date
D GETS^DIQ(2,DFN,".3192","I","PATDATA","SDMSG")
S COVBYHI=PATDATA(2,DFN_",",.3192,"I")
S COVBYHI=$G(COVBYHI)
I COVBYHI="N"!(COVBYHI="U") D
.D GETS^DIQ(354,DFN,"60","I","BILLPATDATA","SDMSG")
.S NOCOVDT=$G(BILLPATDATA(354,DFN_",",60,"I"))
.S NOCOVDT=$G(NOCOVDT)
.I NOCOVDT D
..S XDT=$$FMADD^XLFDT(DT,-NOCOVWINDOW)
..I $G(XDT)<NOCOVDT S NEEDVERIFY=0
Q
;
BUILDER ;Convert data to JSON
N JSONERR
S JSONERR=""
D ENCODE^SDESJSON(.SDPAT,.RETURN,.JSONERR)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESPATRPC 5256 printed Oct 16, 2024@18:57:55 Page 2
SDESPATRPC ;ALB/TAW,RJT,ANU,MGD,DJS,RRM - PATIENT RPCS ;Aug 11, 2022
+1 ;;5.3;Scheduling;**792,804,805,807,809,814,816,820,823,824**;Aug 13, 1993;Build 3
+2 ;
+3 ; Reference to ^IBA(355.33 in ICR #6891
+4 ; Reference to $$GETS^DIQ,$$GET1^DIQ in ICR #2056
+5 ; Reference to #354 in ICR #5296
+6 ;
+7 QUIT
+8 ;
INSURINDICATORS(RETURN,DFNS) ;
+1 if $DATA(DFNS)=0
QUIT
+2 NEW INDICATORS,SDINDEX,HASDFNERRORS,PTDFN,SDINDEX,SDCNT
+3 SET SDINDEX=""
SET SDCNT=0
+4 FOR
SET SDINDEX=$ORDER(DFNS(SDINDEX))
if (SDINDEX="")!(SDCNT>100)
QUIT
Begin DoDot:1
+5 SET SDCNT=SDCNT+1
+6 SET PTDFN=DFNS(SDINDEX)
+7 SET INDICATORS("NeedInsuranceVerification",SDINDEX,"DFN")=PTDFN
+8 SET INDICATORS("NeedInsuranceVerification",SDINDEX,"ICN")=$$GETPATICN^SDESINPUTVALUTL(PTDFN)
+9 IF $GET(SDCNT)>100
Begin DoDot:2
+10 SET INDICATORS("NeedInsuranceVerification",SDINDEX,"Errors")="Max number of records allowed is 100"
End DoDot:2
+11 if SDCNT>100
QUIT
+12 NEW DFNERRORS
+13 SET HASDFNERRORS=$$VALIDATEDFN(.DFNERRORS,PTDFN)
+14 IF $GET(HASDFNERRORS)
Begin DoDot:2
+15 SET INDICATORS("NeedInsuranceVerification",SDINDEX,"Errors")="DFN Error"
+16 SET INDICATORS("NeedInsuranceVerification",SDINDEX,"YesNo")=""
End DoDot:2
+17 IF '$GET(HASDFNERRORS)
Begin DoDot:2
+18 NEW FLG
+19 DO NEEDVERIFY(.FLG,PTDFN,180,90)
+20 SET INDICATORS("NeedInsuranceVerification",SDINDEX,"YesNo")=FLG
End DoDot:2
End DoDot:1
+21 DO BUILDJSON(.RETURN,.INDICATORS)
+22 QUIT
+23 ;
VALIDATEDFN(ERRORS,PDFN) ;
+1 NEW ERRORFLAG
+2 IF $GET(PDFN)=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,1)
+3 IF $GET(PDFN)'=""
IF '$DATA(^DPT(PDFN,0))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,2)
+4 QUIT $DATA(ERRORFLAG)
+5 ;
BUILDJSON(JSONRETURN,INPUT) ;
+1 NEW JSONERROR
+2 SET JSONERROR=""
+3 DO ENCODE^XLFJSON("INPUT","JSONRETURN","JSONERROR")
+4 QUIT
+5 ;
INSURVERIFYREQ(RETURN,DFN,SDEAS) ;
+1 NEW POP,SDPAT,FLG
+2 SET (FLG,POP)=0
+3 SET DFN=$GET(DFN)
+4 IF DFN=""
SET POP=1
DO ERRLOG^SDESJSON(.SDPAT,1)
+5 IF DFN'=""
IF '$DATA(^DPT(DFN,0))
SET POP=1
DO ERRLOG^SDESJSON(.SDPAT,2)
+6 SET SDEAS=$GET(SDEAS,"")
+7 IF $LENGTH(SDEAS)
SET SDEAS=$$EASVALIDATE^SDESUTIL(SDEAS)
+8 IF $GET(SDEAS)=-1
SET POP=1
DO ERRLOG^SDESJSON(.SDPAT,142)
+9 IF '$GET(POP)
DO NEEDVERIFY(.FLG,DFN,180,90)
SET SDPAT("NeedInsuranceVerification","YesNo")=FLG
+10 DO BUILDER
+11 QUIT
NEEDVERIFY(NEEDVERIFY,DFN,LASTVERFWINDOW,NOCOVWINDOW) ;
+1 ; LASTVERFWINDOW - How many days in the past to look for a Last Verified Date
+2 ; NOCOVWINDOW - How many days in the past to look for a No Coverage Date
+3 ;
+4 ; Return
+5 ; 1 = Verification needed (Default)
+6 ; 0 = Has active insurance or verification started
+7 NEW IENS,SDMSG,PATDATA,BILLPATDATA,NOCOVDT,COVBYHI,SUBIEN,XDT,TMPDT,INDEXEND,IBAIEN,IBADATA
+8 NEW FEDONLY,FEDPOLICY
+9 SET NEEDVERIFY=1
+10 ;
+11 ;SD*5.3*816
+12 ;
+13 SET IBAIEN=""
+14 SET FEDONLY="Y"
+15 FOR
SET IBAIEN=$ORDER(^IBA(355.33,"C",DFN,IBAIEN))
if IBAIEN=""!(FEDONLY="N")
QUIT
Begin DoDot:1
+16 SET FEDPOLICY=""
+17 SET FEDPOLICY=$$GET1^DIQ(355.33,IBAIEN,20.01,"E")
+18 SET FEDPOLICY=$GET(FEDPOLICY,"")
+19 SET FEDPOLICY=$$UP^XLFSTR(FEDPOLICY)
+20 if ((FEDPOLICY["MEDICAID")!(FEDPOLICY["MEDICARE")!(FEDPOLICY["TRICARE")!(FEDPOLICY["CHAMPVA"))
QUIT
+21 SET FEDONLY="N"
End DoDot:1
+22 ;
+23 SET SUBIEN=0
+24 FOR
SET SUBIEN=$ORDER(^DPT(DFN,.312,SUBIEN))
if SUBIEN=""!('SUBIEN)!(FEDONLY="N")
QUIT
Begin DoDot:1
+25 SET IENS=SUBIEN_","_DFN_","
+26 KILL PATDATA
+27 DO GETS^DIQ(2.312,IENS,".01;3","IE","PATDATA","SDMSG")
+28 ;Check the Insurance Expiration Data is active
+29 SET TMPDT=PATDATA(2.312,IENS,3,"I")
+30 SET TMPDT=$GET(TMPDT)
+31 ;term date of today is inactive coverage
IF +TMPDT
IF (+TMPDT'>DT)
QUIT
+32 SET FEDPOLICY=""
+33 SET FEDPOLICY=PATDATA(2.312,IENS,.01,"E")
+34 SET FEDPOLICY=$GET(FEDPOLICY,"")
+35 SET FEDPOLICY=$$UP^XLFSTR(FEDPOLICY)
+36 if ((FEDPOLICY["MEDICAID")!(FEDPOLICY["MEDICARE")!(FEDPOLICY["TRICARE")!(FEDPOLICY["CHAMPVA"))
QUIT
+37 SET FEDONLY="N"
End DoDot:1
+38 ;
+39 IF $GET(FEDONLY)="Y"
SET LASTVERFWINDOW=365
+40 ;
+41 ;Check the Insurance Verification Processor file
+42 ; The assumption is that once verification is complete all
+43 ; references to the patient are removed.
+44 SET IBAIEN=""
+45 SET INDEXEND=$$FMADD^XLFDT(DT,-LASTVERFWINDOW)
+46 FOR
SET IBAIEN=$ORDER(^IBA(355.33,"C",DFN,IBAIEN))
if IBAIEN=""
QUIT
Begin DoDot:1
+47 KILL IBADATA
+48 if $$GET1^DIQ(355.33,IBAIEN,.01,"I")<INDEXEND
QUIT
+49 ;Entered - verification has started
IF $$GET1^DIQ(355.33,IBAIEN,.04,"I")="E"
SET NEEDVERIFY=0
End DoDot:1
+50 ;Verification not needed
IF $GET(NEEDVERIFY)=0
QUIT
+51 ;
+52 ;Check the Insurance Types (sub file .321) of the Patient File (#2)
+53 SET SUBIEN=0
+54 FOR
SET SUBIEN=$ORDER(^DPT(DFN,.312,SUBIEN))
if SUBIEN=""!(NEEDVERIFY=0)!('SUBIEN)
QUIT
Begin DoDot:1
+55 SET IENS=SUBIEN_","_DFN_","
+56 KILL PATDATA
+57 DO GETS^DIQ(2.312,IENS,"1.03;3","I","PATDATA","SDMSG")
+58 ;Check the Insurance Expiration Data is active
+59 SET TMPDT=PATDATA(2.312,IENS,3,"I")
+60 SET TMPDT=$GET(TMPDT)
+61 ;term date of today is inactive coverage
IF +TMPDT
IF (+TMPDT'>DT)
QUIT
+62 ;Check the Date Last Verified
+63 SET TMPDT=$PIECE(PATDATA(2.312,IENS,1.03,"I"),".")
+64 SET TMPDT=$GET(TMPDT)
+65 IF TMPDT
Begin DoDot:2
+66 SET XDT=$$FMADD^XLFDT(DT,-LASTVERFWINDOW)
+67 SET XDT=$GET(XDT)
+68 IF XDT<TMPDT
SET NEEDVERIFY=0
End DoDot:2
End DoDot:1
+69 ;Verification not needed
IF $GET(NEEDVERIFY)=0
QUIT
+70 ;
+71 ;If no insurance or unknown on file then check the Covered by Health Insurance date
+72 DO GETS^DIQ(2,DFN,".3192","I","PATDATA","SDMSG")
+73 SET COVBYHI=PATDATA(2,DFN_",",.3192,"I")
+74 SET COVBYHI=$GET(COVBYHI)
+75 IF COVBYHI="N"!(COVBYHI="U")
Begin DoDot:1
+76 DO GETS^DIQ(354,DFN,"60","I","BILLPATDATA","SDMSG")
+77 SET NOCOVDT=$GET(BILLPATDATA(354,DFN_",",60,"I"))
+78 SET NOCOVDT=$GET(NOCOVDT)
+79 IF NOCOVDT
Begin DoDot:2
+80 SET XDT=$$FMADD^XLFDT(DT,-NOCOVWINDOW)
+81 IF $GET(XDT)<NOCOVDT
SET NEEDVERIFY=0
End DoDot:2
End DoDot:1
+82 QUIT
+83 ;
BUILDER ;Convert data to JSON
+1 NEW JSONERR
+2 SET JSONERR=""
+3 DO ENCODE^SDESJSON(.SDPAT,.RETURN,.JSONERR)
+4 QUIT