SDSCCHK ;ALB/JAM/RBS - Check Encounters for Inclusion in ASCD ; 4/30/07 4:46pm
;;5.3;Scheduling;**495,1015**;Aug 13, 1993;Build 21
;;MODIFIED FOR NATIONAL RELEASE from a Class III software product
;;known as Service Connected Automated Monitoring (SCAM).
;
Q
EN ; Entry point
N SDSCBDT,SDSCITE,SDSCDAY,ZTQUEUED,POP,ZTRTN,ZTDTH,ZTDESC,ZTSAVE
; Initialize system variables if not already set
D HOME^%ZIS
; Get start and end date for compile.
S (SDSCBDT,SDSCEDT,SDSCDAY)=""
S SDSCITE=$P($$SITE^VASITE(),U,1)
S SDSCDAY=$$GET^XPAR((+SDSCITE)_";DIC(4,","SDSC SITE PARAMETER")
; set default start date based on site parameter (30 days max)
I SDSCDAY="" S SDSCDAY=30
S SDSCBDT=$$FMADD^XLFDT(DT,-SDSCDAY),SDSCEDT=DT
D GETDATE1^SDSCOMP I SDSCTDT="" G EXIT
S DIR(0)="S^S:Summary Report;D:Detailed Report",DIR("B")="S"
D ^DIR K DIR
I $G(DTOUT)!($G(DUOUT)) G EXIT
S SDANS=Y
K %ZIS,IOP,IOC,ZTIO S %ZIS="MQ" D ^%ZIS G:POP EXIT
I $D(IO("Q")) D G EXIT
. S ZTRTN="PRT^SDSCCHK",ZTDTH=$H,ZTDESC="ASCD Compile Results Report"
. S ZTSAVE("SDANS")="",ZTSAVE("SDSCTDT")="",ZTSAVE("SDEDT")=""
. K IO("Q") D ^%ZTLOAD W !,"REQUEST QUEUED"
;
PRT ; Print results
N SDCT,SDDCT,SDOEDT,SDOE,P,L,SDTXT,TOTAL,SDOANS
K ^TMP("SDSCCHK",$J)
D ELIG^SDSCOMP
S SDOEDT=SDSCTDT,(SDCT,SDDCT)=0
F S SDOEDT=$O(^SCE("B",SDOEDT)) Q:(SDOEDT\1)>SDEDT Q:SDOEDT="" D
. S SDOE=0
. F S SDOE=$O(^SCE("B",SDOEDT,SDOE)) Q:'SDOE D FND
;
BEG ; Begin report
S (P,L,SDABRT,TOTAL,SDOANS)=0
S SDOANS=SDANS S:SDANS="D" SDANS="S"
D HDR
;
U IO
D G EXIT:$G(SDABRT)=1
. S SDTXT=""
. F S SDTXT=$O(^TMP("SDSCCHK",$J,"TOTAL",SDTXT)) Q:SDTXT="" D Q:$G(SDABRT)=1
.. W !,$J(^TMP("SDSCCHK",$J,"TOTAL",SDTXT),8),?10,SDTXT S L=L+1
.. F I=" TP "," MT " W:SDTXT[I " *"
.. S TOTAL=TOTAL+^TMP("SDSCCHK",$J,"TOTAL",SDTXT)
.. I L+3>IOSL D HDR Q:$G(SDABRT)=1
. W ! F I=1:1:79 W "-"
. W !,$J(TOTAL,8),?10,"TOTAL Encounters"
. W !!,"* Third Party=TP; Means Test=MT",!
;
I SDOANS="D" S SDANS="D" D HDR D G EXIT:$G(SDABRT)=1
. S SDTXT=""
. F S SDTXT=$O(^TMP("SDSCCHK",$J,"DX",SDTXT)) Q:'SDTXT D Q:$G(SDABRT)=1
.. S SDDATA=^TMP("SDSCCHK",$J,"DX",SDTXT)
.. W !,$P(SDDATA,U,1),?12,$P(SDDATA,U,2),?24,$E($P(SDDATA,U,3),1,19),?44,$E($P(SDDATA,U,4),1,16)
.. W ?62,$E($P(^TMP("SDSCCHK",$J,"DX",SDTXT),U,5),1,18),!,?10,$P($P(^TMP("SDSCCHK",$J,"DX",SDTXT),U,6),"(",1)
.. S L=L+2
.. I L+3>IOSL D HDR Q:$G(SDABRT)=1
D RPTEND^SDSCRPT1
EXIT ;
K SDABRT,SDANS,SDCLIN,SDEDT,SDFPTX,SDHDR,SDLIST,SDNWPV,SDOEX,SDPOV
K SDSCEDT,SDSCTDT,SDSCTXT,I,X,Y,QUE,POP,DFN,SDDATA
K ^TMP("SDSCCHK",$J),DTOUT,DUOUT
Q
;
FND ; Find errors with encounters
N SDOEDAT,SDCLIN,SDPAT,SDEC,DFN,SDCST,SDV0,SDPNAM,SDFILEOK
; If this encounter has already been compiled for review, quit.
I $D(^SDSC(409.48,SDOE,0)) Q
;
S SDOEDAT=$$GETOE^SDOE(SDOE) I SDOEDAT="" S SDSCTXT="No Encounter zero node" D STORE Q
; If child encounter, quit
I $P(SDOEDAT,U,6) Q
S SDCLIN=$P(SDOEDAT,U,4)
; Get patient. If no patient, quit.
S SDPAT=$P(SDOEDAT,U,2) I SDPAT="" S SDSCTXT="No Patient Pointer for this encounter" D STORE Q
N VADM S DFN=SDPAT D DEM^VADPT S SDPNAM=VADM(1)
; Get visit file entry. If no visit, quit.
S SDV0=$P(SDOEDAT,U,5) I SDV0="" S SDSCTXT="No Visit Pointer for this encounter" D STORE Q
; Get eligibility. If no eligibility, quit.
S SDEC=$P(SDOEDAT,U,13) I SDEC="" S SDSCTXT="Encounter eligibility is blank." D STORE Q
; If eligibility is not service connected, quit.
I '$D(SDLIST(SDEC)) S SDSCTXT="Eligibility is not service connected" D STORE Q
; Get clinic. If no clinic, quit.
I SDCLIN="" S SDSCTXT="No Clinic Pointer for this encounter" D STORE Q
; Get clinic stop code. If no clinic stop code, quit.
S SDCST=$P(SDOEDAT,U,3) I SDCST="" S SDSCTXT="Clinic "_$P(^SC(SDCLIN,0),U,1)_" has no defined clinic stop code" D STORE Q
; If clinic is non-count, quit.
I $$NCTCL^SDSCUTL(SDCLIN) S SDSCTXT="Clinic "_$P(^SC(SDCLIN,0),U,1)_" is non-count" D STORE Q
; If encounter is non-billable for first and third party, quit.
I $$NBFP(),$$NBTP() S SDSCTXT="Non-billable because "_SDFPTX D STORE Q
; Get and evaluate all ICD9 entries for the specified visit.
S SDFILEOK=$$SC^SDSCAPI(DFN,,SDOE)
;no ICDs were found for this encounter SDFILEOK=""
I SDFILEOK="" S SDSCTXT="No Diagnoses for this encounter" D STORED Q
;checks if ICD match found
I +SDFILEOK D Q
.I '$P(SDFILEOK,"^",4) S SDSCTXT="A diagnosis fully matched a rated disability condition" D STORED Q
.S SDSCTXT="A diagnosis partially matched a rated disability condition" D STORED
; ICDs that were found as non-service connected
S SDSCTXT="No Diagnoses identified as service connected" D STORED
Q
;
HDR ; Header
; Do not ask 'RETURN' before first page on CRT.
I $E(IOST,1,2)="C-",P N DIR S DIR(0)="E" D ^DIR I 'Y S SDABRT=1 Q
; Do not print a form feed before first page on printer. Top of form is set at end of previous report.
I $E(IOST,1,2)="C-"!P W @IOF
S P=P+1,L=5
S SDHDR="Compile Results Report"_" - "_$S(SDANS="S":"Summary",1:"Detail")
U IO
S SDNWPV=1
W SDHDR,?67,"PAGE: ",P
W !,?5,"For Encounters Dated ",$$FMTE^XLFDT(SDSCTDT,2)," THRU ",$$FMTE^XLFDT(SDEDT,2)
I SDANS="S" W !,?2,"# Enc",?10,"Reason"
I SDANS="D" D
. W !!,"Note: The Detail report will ONLY list additional encounter information ",!," for the Diagnosis code related Reasons.",!
. W !,"Enc #",?12,"Visit #",?24,"Clinic",?42,"Encounter Date/Time",?62,"Patient Name",!,?10,"Reason"
W ! F I=1:1:79 W "-"
Q
;
STORE ; Store the encounter for later use.
S SDCT=SDCT+1
I SDOEDAT="" S ^TMP("SDSCCHK",$J,SDCT)="Encounter IEN "_SDOE_" "_SDSCTXT Q
I SDPAT="" S ^TMP("SDSCCHK",$J,SDCT)="Encounter IEN "_SDOE_" "_SDSCTXT Q
S ^TMP("SDSCCHK",$J,SDCT)=$P(^SC(SDCLIN,0),U,1)_"^"_$$FMTE^XLFDT($P(SDOEDAT,U,1),"5Z")_"^"_SDPNAM_"^"_SDSCTXT
S ^TMP("SDSCCHK",$J,"TOTAL",SDSCTXT)=$G(^TMP("SDSCCHK",$J,"TOTAL",SDSCTXT))+1
Q
;
STORED ; Store the diagnosis encounter for detail
N DFN,SDPNAM
S SDDCT=SDDCT+1
S DFN=SDPAT D DEM^VADPT S SDPNAM=VADM(1) D KVA^VADPT
S ^TMP("SDSCCHK",$J,"DX",SDDCT)=SDOE_"^"_SDV0_"^"_$P(^SC(SDCLIN,0),U,1)_"^"_$$FMTE^XLFDT($P(SDOEDAT,U,1),"5Z")_"^"_SDPNAM_"^"_SDSCTXT
S ^TMP("SDSCCHK",$J,"TOTAL",SDSCTXT)=$G(^TMP("SDSCCHK",$J,"TOTAL",SDSCTXT))+1
Q
;
NBFP() ; Is first-party non-billable based on either clinic, stop code, or patient?
S SDFPTX="",SDFPTX=$P($$FIRST^IBRSUTL(SDOE),U,2) I SDFPTX'="" Q 1
Q 0
;
NBTP() ; Is third-party non-billable based on either clinic, stop code, or patient?
S SDFPTX="",SDFPTX=$P($$THIRD^IBRSUTL(SDOE),U,2) I SDFPTX'="" Q 1
I '+$$INSUR^IBBAPI(SDPAT,SDOEDT) S SDFPTX="patient is not insured" Q 1
Q 0
SDSCCHK ;ALB/JAM/RBS - Check Encounters for Inclusion in ASCD ; 4/30/07 4:46pm
+1 ;;5.3;Scheduling;**495,1015**;Aug 13, 1993;Build 21
+2 ;;MODIFIED FOR NATIONAL RELEASE from a Class III software product
+3 ;;known as Service Connected Automated Monitoring (SCAM).
+4 ;
+5 QUIT
EN ; Entry point
+1 NEW SDSCBDT,SDSCITE,SDSCDAY,ZTQUEUED,POP,ZTRTN,ZTDTH,ZTDESC,ZTSAVE
+2 ; Initialize system variables if not already set
+3 DO HOME^%ZIS
+4 ; Get start and end date for compile.
+5 SET (SDSCBDT,SDSCEDT,SDSCDAY)=""
+6 SET SDSCITE=$PIECE($$SITE^VASITE(),U,1)
+7 SET SDSCDAY=$$GET^XPAR((+SDSCITE)_";DIC(4,","SDSC SITE PARAMETER")
+8 ; set default start date based on site parameter (30 days max)
+9 IF SDSCDAY=""
SET SDSCDAY=30
+10 SET SDSCBDT=$$FMADD^XLFDT(DT,-SDSCDAY)
SET SDSCEDT=DT
+11 DO GETDATE1^SDSCOMP
IF SDSCTDT=""
GOTO EXIT
+12 SET DIR(0)="S^S:Summary Report;D:Detailed Report"
SET DIR("B")="S"
+13 DO ^DIR
KILL DIR
+14 IF $GET(DTOUT)!($GET(DUOUT))
GOTO EXIT
+15 SET SDANS=Y
+16 KILL %ZIS,IOP,IOC,ZTIO
SET %ZIS="MQ"
DO ^%ZIS
IF POP
GOTO EXIT
+17 IF $DATA(IO("Q"))
Begin DoDot:1
+18 SET ZTRTN="PRT^SDSCCHK"
SET ZTDTH=$HOROLOG
SET ZTDESC="ASCD Compile Results Report"
+19 SET ZTSAVE("SDANS")=""
SET ZTSAVE("SDSCTDT")=""
SET ZTSAVE("SDEDT")=""
+20 KILL IO("Q")
DO ^%ZTLOAD
WRITE !,"REQUEST QUEUED"
End DoDot:1
GOTO EXIT
+21 ;
PRT ; Print results
+1 NEW SDCT,SDDCT,SDOEDT,SDOE,P,L,SDTXT,TOTAL,SDOANS
+2 KILL ^TMP("SDSCCHK",$JOB)
+3 DO ELIG^SDSCOMP
+4 SET SDOEDT=SDSCTDT
SET (SDCT,SDDCT)=0
+5 FOR
SET SDOEDT=$ORDER(^SCE("B",SDOEDT))
IF (SDOEDT\1)>SDEDT
QUIT
IF SDOEDT=""
QUIT
Begin DoDot:1
+6 SET SDOE=0
+7 FOR
SET SDOE=$ORDER(^SCE("B",SDOEDT,SDOE))
IF 'SDOE
QUIT
DO FND
End DoDot:1
+8 ;
BEG ; Begin report
+1 SET (P,L,SDABRT,TOTAL,SDOANS)=0
+2 SET SDOANS=SDANS
IF SDANS="D"
SET SDANS="S"
+3 DO HDR
+4 ;
+5 USE IO
+6 Begin DoDot:1
+7 SET SDTXT=""
+8 FOR
SET SDTXT=$ORDER(^TMP("SDSCCHK",$JOB,"TOTAL",SDTXT))
IF SDTXT=""
QUIT
Begin DoDot:2
+9 WRITE !,$JUSTIFY(^TMP("SDSCCHK",$JOB,"TOTAL",SDTXT),8),?10,SDTXT
SET L=L+1
+10 FOR I=" TP "," MT "
IF SDTXT[I
WRITE " *"
+11 SET TOTAL=TOTAL+^TMP("SDSCCHK",$JOB,"TOTAL",SDTXT)
+12 IF L+3>IOSL
DO HDR
IF $GET(SDABRT)=1
QUIT
End DoDot:2
IF $GET(SDABRT)=1
QUIT
+13 WRITE !
FOR I=1:1:79
WRITE "-"
+14 WRITE !,$JUSTIFY(TOTAL,8),?10,"TOTAL Encounters"
+15 WRITE !!,"* Third Party=TP; Means Test=MT",!
End DoDot:1
IF $GET(SDABRT)=1
GOTO EXIT
+16 ;
+17 IF SDOANS="D"
SET SDANS="D"
DO HDR
Begin DoDot:1
+18 SET SDTXT=""
+19 FOR
SET SDTXT=$ORDER(^TMP("SDSCCHK",$JOB,"DX",SDTXT))
IF 'SDTXT
QUIT
Begin DoDot:2
+20 SET SDDATA=^TMP("SDSCCHK",$JOB,"DX",SDTXT)
+21 WRITE !,$PIECE(SDDATA,U,1),?12,$PIECE(SDDATA,U,2),?24,$EXTRACT($PIECE(SDDATA,U,3),1,19),?44,$EXTRACT($PIECE(SDDATA,U,4),1,16)
+22 WRITE ?62,$EXTRACT($PIECE(^TMP("SDSCCHK",$JOB,"DX",SDTXT),U,5),1,18),!,?10,$PIECE($PIECE(^TMP("SDSCCHK",$JOB,"DX",SDTXT),U,6),"(",1)
+23 SET L=L+2
+24 IF L+3>IOSL
DO HDR
IF $GET(SDABRT)=1
QUIT
End DoDot:2
IF $GET(SDABRT)=1
QUIT
End DoDot:1
IF $GET(SDABRT)=1
GOTO EXIT
+25 DO RPTEND^SDSCRPT1
EXIT ;
+1 KILL SDABRT,SDANS,SDCLIN,SDEDT,SDFPTX,SDHDR,SDLIST,SDNWPV,SDOEX,SDPOV
+2 KILL SDSCEDT,SDSCTDT,SDSCTXT,I,X,Y,QUE,POP,DFN,SDDATA
+3 KILL ^TMP("SDSCCHK",$JOB),DTOUT,DUOUT
+4 QUIT
+5 ;
FND ; Find errors with encounters
+1 NEW SDOEDAT,SDCLIN,SDPAT,SDEC,DFN,SDCST,SDV0,SDPNAM,SDFILEOK
+2 ; If this encounter has already been compiled for review, quit.
+3 IF $DATA(^SDSC(409.48,SDOE,0))
QUIT
+4 ;
+5 SET SDOEDAT=$$GETOE^SDOE(SDOE)
IF SDOEDAT=""
SET SDSCTXT="No Encounter zero node"
DO STORE
QUIT
+6 ; If child encounter, quit
+7 IF $PIECE(SDOEDAT,U,6)
QUIT
+8 SET SDCLIN=$PIECE(SDOEDAT,U,4)
+9 ; Get patient. If no patient, quit.
+10 SET SDPAT=$PIECE(SDOEDAT,U,2)
IF SDPAT=""
SET SDSCTXT="No Patient Pointer for this encounter"
DO STORE
QUIT
+11 NEW VADM
SET DFN=SDPAT
DO DEM^VADPT
SET SDPNAM=VADM(1)
+12 ; Get visit file entry. If no visit, quit.
+13 SET SDV0=$PIECE(SDOEDAT,U,5)
IF SDV0=""
SET SDSCTXT="No Visit Pointer for this encounter"
DO STORE
QUIT
+14 ; Get eligibility. If no eligibility, quit.
+15 SET SDEC=$PIECE(SDOEDAT,U,13)
IF SDEC=""
SET SDSCTXT="Encounter eligibility is blank."
DO STORE
QUIT
+16 ; If eligibility is not service connected, quit.
+17 IF '$DATA(SDLIST(SDEC))
SET SDSCTXT="Eligibility is not service connected"
DO STORE
QUIT
+18 ; Get clinic. If no clinic, quit.
+19 IF SDCLIN=""
SET SDSCTXT="No Clinic Pointer for this encounter"
DO STORE
QUIT
+20 ; Get clinic stop code. If no clinic stop code, quit.
+21 SET SDCST=$PIECE(SDOEDAT,U,3)
IF SDCST=""
SET SDSCTXT="Clinic "_$PIECE(^SC(SDCLIN,0),U,1)_" has no defined clinic stop code"
DO STORE
QUIT
+22 ; If clinic is non-count, quit.
+23 IF $$NCTCL^SDSCUTL(SDCLIN)
SET SDSCTXT="Clinic "_$PIECE(^SC(SDCLIN,0),U,1)_" is non-count"
DO STORE
QUIT
+24 ; If encounter is non-billable for first and third party, quit.
+25 IF $$NBFP()
IF $$NBTP()
SET SDSCTXT="Non-billable because "_SDFPTX
DO STORE
QUIT
+26 ; Get and evaluate all ICD9 entries for the specified visit.
+27 SET SDFILEOK=$$SC^SDSCAPI(DFN,,SDOE)
+28 ;no ICDs were found for this encounter SDFILEOK=""
+29 IF SDFILEOK=""
SET SDSCTXT="No Diagnoses for this encounter"
DO STORED
QUIT
+30 ;checks if ICD match found
+31 IF +SDFILEOK
Begin DoDot:1
+32 IF '$PIECE(SDFILEOK,"^",4)
SET SDSCTXT="A diagnosis fully matched a rated disability condition"
DO STORED
QUIT
+33 SET SDSCTXT="A diagnosis partially matched a rated disability condition"
DO STORED
End DoDot:1
QUIT
+34 ; ICDs that were found as non-service connected
+35 SET SDSCTXT="No Diagnoses identified as service connected"
DO STORED
+36 QUIT
+37 ;
HDR ; Header
+1 ; Do not ask 'RETURN' before first page on CRT.
+2 IF $EXTRACT(IOST,1,2)="C-"
IF P
NEW DIR
SET DIR(0)="E"
DO ^DIR
IF 'Y
SET SDABRT=1
QUIT
+3 ; Do not print a form feed before first page on printer. Top of form is set at end of previous report.
+4 IF $EXTRACT(IOST,1,2)="C-"!P
WRITE @IOF
+5 SET P=P+1
SET L=5
+6 SET SDHDR="Compile Results Report"_" - "_$SELECT(SDANS="S":"Summary",1:"Detail")
+7 USE IO
+8 SET SDNWPV=1
+9 WRITE SDHDR,?67,"PAGE: ",P
+10 WRITE !,?5,"For Encounters Dated ",$$FMTE^XLFDT(SDSCTDT,2)," THRU ",$$FMTE^XLFDT(SDEDT,2)
+11 IF SDANS="S"
WRITE !,?2,"# Enc",?10,"Reason"
+12 IF SDANS="D"
Begin DoDot:1
+13 WRITE !!,"Note: The Detail report will ONLY list additional encounter information ",!," for the Diagnosis code related Reasons.",!
+14 WRITE !,"Enc #",?12,"Visit #",?24,"Clinic",?42,"Encounter Date/Time",?62,"Patient Name",!,?10,"Reason"
End DoDot:1
+15 WRITE !
FOR I=1:1:79
WRITE "-"
+16 QUIT
+17 ;
STORE ; Store the encounter for later use.
+1 SET SDCT=SDCT+1
+2 IF SDOEDAT=""
SET ^TMP("SDSCCHK",$JOB,SDCT)="Encounter IEN "_SDOE_" "_SDSCTXT
QUIT
+3 IF SDPAT=""
SET ^TMP("SDSCCHK",$JOB,SDCT)="Encounter IEN "_SDOE_" "_SDSCTXT
QUIT
+4 SET ^TMP("SDSCCHK",$JOB,SDCT)=$PIECE(^SC(SDCLIN,0),U,1)_"^"_$$FMTE^XLFDT($PIECE(SDOEDAT,U,1),"5Z")_"^"_SDPNAM_"^"_SDSCTXT
+5 SET ^TMP("SDSCCHK",$JOB,"TOTAL",SDSCTXT)=$GET(^TMP("SDSCCHK",$JOB,"TOTAL",SDSCTXT))+1
+6 QUIT
+7 ;
STORED ; Store the diagnosis encounter for detail
+1 NEW DFN,SDPNAM
+2 SET SDDCT=SDDCT+1
+3 SET DFN=SDPAT
DO DEM^VADPT
SET SDPNAM=VADM(1)
DO KVA^VADPT
+4 SET ^TMP("SDSCCHK",$JOB,"DX",SDDCT)=SDOE_"^"_SDV0_"^"_$PIECE(^SC(SDCLIN,0),U,1)_"^"_$$FMTE^XLFDT($PIECE(SDOEDAT,U,1),"5Z")_"^"_SDPNAM_"^"_SDSCTXT
+5 SET ^TMP("SDSCCHK",$JOB,"TOTAL",SDSCTXT)=$GET(^TMP("SDSCCHK",$JOB,"TOTAL",SDSCTXT))+1
+6 QUIT
+7 ;
NBFP() ; Is first-party non-billable based on either clinic, stop code, or patient?
+1 SET SDFPTX=""
SET SDFPTX=$PIECE($$FIRST^IBRSUTL(SDOE),U,2)
IF SDFPTX'=""
QUIT 1
+2 QUIT 0
+3 ;
NBTP() ; Is third-party non-billable based on either clinic, stop code, or patient?
+1 SET SDFPTX=""
SET SDFPTX=$PIECE($$THIRD^IBRSUTL(SDOE),U,2)
IF SDFPTX'=""
QUIT 1
+2 IF '+$$INSUR^IBBAPI(SDPAT,SDOEDT)
SET SDFPTX="patient is not insured"
QUIT 1
+3 QUIT 0