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

PXCOMPACTEVAL.m

Go to the documentation of this file.
PXCOMPACTEVAL ;ALB/BPA,CMC - COMPACT Act evaluation / protocol entry routine;12/26/2023@10:58am
 ;;1.0;PCE PATIENT CARE ENCOUNTER;**240**;Aug 12, 1996;Build 55
 ; *240* COMPACT Act evaluation / protocol entry routine
 ; Reference to $$ELIG^DGCOMPACTELIG in ICR #7462
 Q
 ;
EVAL ; load an TMP global with foreground $J value to simulate a pre-existing TMP global from protocol
 N PURGEDT,XTMPSUB,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
 S XTMPSUB="PXCMP"_$J_$$NOW^XLFDT
 S PURGEDT=DT_".1159"
 S XTMPSUB(0)=PURGEDT_U_DT_U_"COMPACT Act auto adjudication"
 M ^XTMP(XTMPSUB,0)=^TMP("PXKCO",$J)
 S ZTRTN="EVALQUE^PXCOMPACTEVAL"
 S ZTDESC="COMPACT Act auto adjudication",ZTIO="",ZTDTH=$H
 S ZTSAVE("XTMPSUB")=""
 D ^%ZTLOAD
 Q
 ;
EVALQUE ; RUNS IN BACKGROUND
 N CPTBEFOR,CPTBEFORVAL,CPTCODE,CPTVAL,DFN,DXCOD1,DXCOD2,DXCOD3,DXCOD4,HFCHECK,HFBEFOR,HFBEFORVAL
 N HFCODE,HFVAL,POVBEFOR,POVBEFORVAL,POVCODE,POVVAL,PXADMIN,PXCOD1,PXCOD2,PXEOCNUM,PXEOCSEQ,PXFOLLOW
 N PXNEWEOC,PXOPNCLOSE,PXHFFOLLOW,PXHFINITIAL,PXHFNONACUTE,PXVCPTIEN,PXVHFIEN,PXVPOVIEN,PXSTDT,PXVSTIEN
 N PXUPDATEVST,PXUPDTEOC
 S (CPTBEFOR,CPTBEFORVAL,CPTCODE,CPTVAL,DFN,DXCOD1,DXCOD2,DXCOD3,DXCOD4,HFCHECK,HFBEFOR,HFBEFORVAL)=""
 S (HFCODE,HFVAL,POVBEFOR,POVBEFORVAL,POVCODE,POVVAL,PXADMIN,PXCOD1,PXCOD2,PXVCPTIEN,PXVHFIEN,PXVPOVIEN)=""
 S (PXSTDT,PXVSTIEN)=""
 S (PXHFINITIAL,PXHFFOLLOW,PXHFNONACUTE)=0
 S (PXFOLLOW,PXNEWEOC,PXOPNCLOSE,PXUPDATEVST,PXUPDTEOC)=0
 ;
 ; Set the VISIT IEN value
 S PXVSTIEN=$O(^XTMP(XTMPSUB,0,""))
 ; Get the DFN and start date
 I PXVSTIEN'="" D 
 . S DFN=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"VST",PXVSTIEN,0,"AFTER"),"^",5)
 . S PXSTDT=$P($P(^XTMP(XTMPSUB,0,PXVSTIEN,"VST",PXVSTIEN,0,"AFTER"),"^"),".")
 ;
 I DFN="" K ^XTMP(XTMPSUB) Q
 ; Check for an open EoC
 S PXOPNCLOSE=$$ASC^PXCOMPACT(DFN)
 ;
 ; Check for existing episode of care number and current episode of care sequence number
 S PXEOCNUM=$$GETEOC^PXCOMPACT(DFN),PXEOCSEQ=$$GETEOCSEQ^PXCOMPACT(DFN)
 ;
 ; Gather rules engine Health Factor code
 S PXHFINITIAL=$O(^AUTTHF("B","VA-COMPACT ACT SUICIDE TX ENCOUNTER INITIAL",""))
 S PXHFFOLLOW=$O(^AUTTHF("B","VA-COMPACT ACT SUICIDE TX ENCOUNTER FOLLOW UP",""))
 S PXHFNONACUTE=$O(^AUTTHF("B","VA-COMPACT ACT SUICIDE RISK NONACUTE",""))
 ;
 ; Add calls here to validate DX codes for rules engine
 S DXCOD1=$P($$CODEN^ICDEX("T14.91XA",80),"~",1)
 S DXCOD2=$P($$CODEN^ICDEX("R45.851",80),"~",1)
 S DXCOD3=$P($$CODEN^ICDEX("T14.91XD",80),"~",1) ;Added for follow up
 S DXCOD4=$P($$CODEN^ICDEX("T14.91XS",80),"~",1) ;Added for follow up
 ; Add calls here to validate PX codes for rules engine
 S PXCOD1=$P($$STATCHK^ICPTAPIU(90839,1),"^",2)
 S PXCOD2=$P($$STATCHK^ICPTAPIU("T2034",1),"^",2)
 ;
 ; Set up the default start date to now if PXSTDT is not set
 I PXSTDT="" S PXSTDT=DT
 ; 
 ; Gather Procedure Codes
 F  S PXVCPTIEN=$O(^XTMP(XTMPSUB,0,PXVSTIEN,"CPT",PXVCPTIEN)) Q:PXVCPTIEN=""  D
 . I $D(^XTMP(XTMPSUB,0,PXVSTIEN,"CPT",PXVCPTIEN,0,"AFTER")) D 
 . . S CPTVAL=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"CPT",PXVCPTIEN,0,"AFTER"),"^") I CPTVAL'="" S CPTCODE(CPTVAL)=""
 . . S CPTBEFORVAL=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"CPT",PXVCPTIEN,0,"BEFORE"),"^")
 . ; Evaluate the before value to see if if differs from the after value
 . I CPTBEFORVAL'="",CPTBEFORVAL'=$G(CPTVAL) S CPTBEFOR(CPTBEFORVAL)=PXVCPTIEN_"^"_CPTVAL,PXUPDATEVST=1
 ;
 ; Gather Diagnosis Codes
 F  S PXVPOVIEN=$O(^XTMP(XTMPSUB,0,PXVSTIEN,"POV",PXVPOVIEN)) Q:PXVPOVIEN=""  D
 . I $D(^XTMP(XTMPSUB,0,PXVSTIEN,"POV",PXVPOVIEN,0,"AFTER")) D
 . . S POVVAL=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"POV",PXVPOVIEN,0,"AFTER"),"^") I POVVAL'="" S POVCODE(POVVAL)=""
 . . S POVBEFORVAL=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"POV",PXVPOVIEN,0,"BEFORE"),"^")
 . ; Evaluate the before value to see if if differs from the after value
 . I POVBEFORVAL'="",POVBEFORVAL'=$G(POVVAL) S POVBEFOR(POVBEFORVAL)=PXVPOVIEN_"^"_POVVAL,PXUPDATEVST=1
 ;
 ; Gather Health Factor information
 F  S PXVHFIEN=$O(^XTMP(XTMPSUB,0,PXVSTIEN,"HF",PXVHFIEN)) Q:PXVHFIEN=""  D
 . I $D(^XTMP(XTMPSUB,0,PXVSTIEN,"HF",PXVHFIEN,0,"AFTER")) D
 . . S HFVAL=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"HF",PXVHFIEN,0,"AFTER"),"^") I HFVAL'="" S HFCODE(HFVAL)=""
 . I $D(^XTMP(XTMPSUB,0,PXVSTIEN,"HF",PXVHFIEN,0,"BEFORE")),$P(^XTMP(XTMPSUB,0,PXVSTIEN,"HF",PXVHFIEN,0,"BEFORE"),"^")'=$G(HFVAL) D
 . . S HFCHECK=$P(^XTMP(XTMPSUB,0,PXVSTIEN,"HF",PXVHFIEN,0,"BEFORE"),"^")
 . . I PXHFINITIAL>0,(HFCHECK=PXHFINITIAL) S HFBEFOR(HFCHECK)=PXVHFIEN_"^"_HFVAL,PXUPDATEVST=1
 . . I PXHFFOLLOW>0,(HFCHECK=PXHFFOLLOW) S HFBEFOR(HFCHECK)=PXVHFIEN_"^"_HFVAL,PXUPDATEVST=1
 ;
 K ^XTMP(XTMPSUB)
 ; Check to see if the non acute health factor has been selected
 I PXOPNCLOSE="Y",PXHFNONACUTE>0,$D(HFCODE(PXHFNONACUTE)) D
 . D VISIT^PXCOMPACT(PXVSTIEN,"O",PXEOCNUM,DFN)
 . D SETENDDT^PXCOMPACT(DFN,PXSTDT,"PR")
 ;
 ; Gather health factor and compare to see if it contains VA-COMPACT ACT SUICIDE TX ENCOUNTER INITIAL
 ; Current auto adjudication rules : 
 ;      Health Factor VA-COMPACT ACT SUICIDE TX ENCOUNTER INITIAL
 ;      OR DX code T14.91XA
 ;      OR Procedure code 90839 + DX code R45.851
 ;      OR Procedure code T2034 <-- default code from CRD
 ;
 I PXNEWEOC=0,PXOPNCLOSE="N" D
 . I PXHFINITIAL>0,$D(HFCODE(PXHFINITIAL)) S PXNEWEOC=1 Q  ;Health Factor VA-COMPACT ACT SUICIDE TX ENCOUNTER INITIAL
 . I PXNEWEOC=0,$D(POVCODE(DXCOD1)) S PXNEWEOC=1 Q  ;T14.91XA
 . I PXNEWEOC=0,$D(POVCODE(DXCOD2)),$D(CPTCODE(PXCOD1)) S PXNEWEOC=1 Q  ;R45.851 + 90839
 . I PXNEWEOC=0,$D(CPTCODE(PXCOD2)) S PXNEWEOC=1 Q  ;T2034
 I PXNEWEOC=1 D
 . ; Check administrative eligibility for COMPACT Act
 . S PXADMIN=$$ELIG^DGCOMPACTELIG(DFN,"PXCOMPACTEVAL")
 . I PXADMIN'="NOT ELIGIBLE" D NEWEOC^PXCOMPACT(DFN,PXVSTIEN,"O",PXSTDT,"A")
 ;
 ; If the follow up flag is not set and the episode of care is still open (not closed by non-acute health factor)
 I PXFOLLOW=0,$$ASC^PXCOMPACT(DFN)="Y" D
 . I PXHFINITIAL>0,$D(HFCODE(PXHFINITIAL)) S PXFOLLOW=1 Q  ;Health Factor VA-COMPACT ACT SUICIDE TX ENCOUNTER INITIAL
 . I PXFOLLOW=0,PXHFFOLLOW>0,$D(HFCODE(PXHFFOLLOW)) S PXFOLLOW=1 Q  ;VA-COMPACT ACT SUICIDE TX ENCOUNTER FOLLOW UP
 . I PXFOLLOW=0,$D(POVCODE(DXCOD3)) S PXFOLLOW=1 Q  ;T14.91XD
 . I PXFOLLOW=0,$D(POVCODE(DXCOD4)) S PXFOLLOW=1 Q  ;T14.91XS
 . I PXFOLLOW=0,$D(POVCODE(DXCOD1)) S PXFOLLOW=1 Q  ;T14.91XA
 . I PXFOLLOW=0,$D(POVCODE(DXCOD2)),$D(CPTCODE(PXCOD1)) S PXFOLLOW=1 Q  ;R45.851 + 90839
 . I PXFOLLOW=0,$D(CPTCODE(PXCOD2)) S PXFOLLOW=1 Q  ;T2034
 I PXFOLLOW=1 D 
 . ; Check administrative eligibility for COMPACT Act
 . S PXADMIN=$$ELIG^DGCOMPACTELIG(DFN,"PXCOMPACTEVAL")
 . I PXADMIN'="NOT ELIGIBLE" D VISIT^PXCOMPACT(PXVSTIEN,"O",PXEOCNUM,DFN)
 ;
 ; If there is an EoC entry, the new EoC logic did not trigger, the follow up EoC logic did not trigger
 ; and either a procedure code, diagnosis code or health factor has changed, check further
 I $D(^PXCOMP(818,"B",DFN)),PXNEWEOC=0,PXFOLLOW=0,PXUPDATEVST=1 D
 . S PXUPDTEOC=0
 . I $D(CPTBEFOR(PXCOD1))!$D(CPTBEFOR(PXCOD2)) S PXUPDTEOC=1
 . I $D(POVBEFOR(DXCOD1))!$D(POVBEFOR(DXCOD2))!$D(POVBEFOR(DXCOD3))!$D(POVBEFOR(DXCOD4)) S PXUPDTEOC=1
 . I $D(HFBEFOR(PXHFINITIAL))!$D(HFBEFOR(PXHFFOLLOW)) S PXUPDTEOC=1
 . I PXUPDTEOC=1 D CHNGEVAL(DFN,PXVSTIEN)
 ;
 I $D(ZTQUEUED) S ZTREQ="@"   ;SAC convention to keep taskman log clean.
 K ZTQUEUED,ZTREQ
 Q
 ;
CHNGEVAL(DFN,PXVSTIEN) ;
 N PXEOCNUM,PXEOCSEQ,PXPONTRSEQ,PXVSTLST,PXVSTFLG
 S (PXEOCNUM,PXEOCSEQ,PXPONTRSEQ,PXVSTLST,PXVSTFLG)=""
 ;
 S PXEOCNUM=$$GETEOC^PXCOMPACT(DFN),PXEOCSEQ=$$GETEOCSEQ^PXCOMPACT(DFN)
 S PXPONTRSEQ=$$GETPOINTRSEQ^PXCOMPACT(DFN,PXVSTIEN,"O")
 I PXPONTRSEQ="" Q  ; This visit is not part of the current episode of care
 ;
 ; If it is the first sequence and there is no inpatient benefit end date, end the episode of care
 ; and mark the episode as entered in error (E)
 I PXPONTRSEQ=1,$P(^PXCOMP(818,PXEOCNUM,10,PXEOCSEQ,0),"^",4)="" D
 . D SETENDDT^PXCOMPACT(DFN,DT,"PR")
 . S $P(^PXCOMP(818,PXEOCNUM,10,PXEOCSEQ,0),"^",6)="E"
 . ; Loop through the visit pointers to set the treatment for flags to no
 . S PXVSTLST=$P(^PXCOMP(818,PXEOCNUM,10,PXEOCSEQ,41,0),"^",3)
 . F PXVSTFLG=1:1:PXVSTLST D
 . . S PXVSTIEN=$P(^PXCOMP(818,PXEOCNUM,10,PXEOCSEQ,41,PXVSTFLG,0),"^")
 . . ; Mark the visit treatment for flag(s) to NULL
 . . I PXVSTIEN'="" D SETVSTFLG^PXCOMPACT(DFN,PXVSTIEN,"")
 E  D
 . ; Mark the visit treatment for flag to NULL
 . D SETVSTFLG^PXCOMPACT(DFN,PXVSTIEN,"")
 Q