Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: SDESPATRPC

SDESPATRPC.m

Go to the documentation of this file.
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