DVBAB51 ;ALB/VM - CAPRI INCOMPETENT PATIENT REPORT ; 3/21/12 3:21pm
 ;;2.7;AMIE;**35,149,179,185**;Apr 10, 1995;Build 18
 ;Per VHA Directive 2004-038, this routine should not be modified.
 ;
 ;Input: ZMSG      - Output Array for incompetent report (By Ref)
 ;       BDATE     - Beginning date for report (FM Format)
 ;       EDATE     - Ending date for report (FM Format)
 ;       DVBADLMTR - Indicates if report should be delimitted (Optional)
 ;                    CAPRI currently executes RPC by each day in 
 ;                    date range, so DVBADLMTR should equal the
 ;                    final EDATE in range so that XTMP global
 ;                    can be killed. 
 ;Output: ^TMP("DVBAR",$J) contains delimited/non-delimited incompetent report
STRT(ZMSG,BDATE,EDATE,DVBADLMTR) ;ENTER HERE
 
DVBAFNLDTE,MA1
 
DVBABCNT=0,RO="N",RONUM=0
 
DVBAFNLDTE=$S(+$G(DVBADLMTR):+$P(DVBADLMTR,"."),1:0)
 
DVBADLMTR=$S('+$G(DVBADLMTR):"",1:",")
 
^TMP($J),^TMP("DVBAR"TERM
SET 
Q:'$D(^DPT(DA,.29))  ICDAT=^(.29) Q:$P(ICDAT,U,12)'=1&(ICDAT']"")  INCMP="" S:$P(ICDAT,U)]""!($P(ICDAT,U,12)=1) INCMP=1 Q:INCMP'=1  ICDAT2=$P(ICDAT,U,2),ICDAT=$P(ICDAT,U)
 
S:ICDAT]"" ICDAT=$$FMTE^XLFDT(ICDAT,"5DZ")
 
S:ICDAT2]"" ICDAT2=$$FMTE^XLFDT(ICDAT2,"5DZ")
 
Q:'$D(^DPT(DA,0))  DFN=DA RCV^DVBAVDPT Q:CFLOC'=RONUM&(RO="Y")&(CFLOC'=0)&(CFLOC'=376)
 
MA1=$P(MA,".",1)
 
^TMP($J,MA1,XCN,CFLOC,MB,DA)=RCVAA_U_RCVPEN_U_CNUM_U_ICDAT_U_ICDAT2_U_INCMP
 
Q
 
;
PRINTB RCVAA=$P(DATA,U),RCVPEN=$P(DATA,U,2),CNUM=$P(DATA,U,3),ICDAT=$P(DATA,U,4),ICDAT2=$P(DATA,U,5),INCMP=$P(DATA,U,6),DFN=DA,QUIT1=1 ADM^DVBAVDPT
 
ADMDT=$$FMTE^XLFDT(ADMDT,"5DZ")
 
DCHGDT=$$FMTE^XLFDT(DCHGDT,"5DZ")
 
LADM=ADM,TDIS="UNKNOWN",TO="",DCHPTR=$P(^DGPM(LADM,0),U,17),TDIS=$S($D(^DGPM(+DCHPTR,0)):$P(^(0),U,18),1:""TDIS="" TDIS="Unknown discharge type"
 
S:'$D(^DG(405.2,+TDIS,0)) TDIS="Unknown discharge type" I $D(^(0)) TDIS=$S($P(^DG(405.2,+TDIS,0),U,1)]"":$P(^(0),U,1),1:"Unknown discharge type")
 
'$G(DVBADLMTR)="," S:(IOST?1"C-".E)!($D(DVBAON2)) ^TMP("DVBAR",$J,DVBABCNT)=" ",DVBABCNT=DVBABCNT+1
 
;***vm-out*W !!!,?(80-$L(HEAD)\2),HEAD,!,?(80-$L(HEAD1)\2),HEAD1,!!
 ;create delimited/non-delimited report
 
D:($G(DVBADLMTR)=","PRINTD
 
D:($G(DVBADLMTR)=""PRINTND
 
DVBAON2=""
 
Q
 
;
PRINTND ;create non-delimited incompetent report
 
^TMP("DVBAR",$J,DVBABCNT)="  Patient Name:    "_PNAM,DVBABCNT=DVBABCNT+1,^TMP("DVBAR",$J,DVBABCNT)=" ",DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="           Claim No:   "_CNUM,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="  Claim Folder Loc:    "_CFLOC,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="      Social Sec No:   "_SSN,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="     Admission Date:   "_ADMDT,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="Admitting Diagnosis:   "_DIAG,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="     Discharge Date:   "_DCHGDT,DVBABCNT=DVBABCNT+1
 
DCHGDT]"" ^TMP("DVBAR",$J,DVBABCNT)="  Type of Discharge:   "_TDIS_$S(TO]"":" TO "_$S($D(^DIC(4,+TO,0)):$P(^(0),U,1),1:""),1:""),DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="        Bed Service:   "_BEDSEC,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="          Recv A&A?:   "_$S(RCVAA=0:"NO",RCVAA=1:"YES",1:"Not specified"),DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="           Pension?:   "_$S(RCVPEN=0:"NO",RCVPEN=1:"YES",1:"Not specified"),DVBABCNT=DVBABCNT+1
 
;***vm-out*D ELIG^DVBAVDPT
ELIG ELIG=DVBAELIG,INCMP=""
 
^TMP("DVBAR",$J,DVBABCNT)="   Eligibility data:   "
 
ELIG]"" ELIG=ELIG_" ("_$S(DVBAELST="P":"Pend Ver",DVBAELST="R":"Pend Re-verif",DVBAELST="V":"Verified",1:"Not Verified")_")"
 
I $D(^DPT(DA,.29)) INCMP=$S($P(^(.29),U,12)=1:"Incompetent",1:"")
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_ELIG_$S(((ELIG]"")&(INCMP]"")):", ",1:"")_INCMP,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="  DATE RULED INCOMP:   "_$S($D(ICDAT)]"":ICDAT_" (VA)",1:"")_$S(ICDAT2]"":" - "_ICDAT2_" (CIVIL)",1:" "),DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)=" ",DVBABCNT=DVBABCNT+1
 
;***vm-out*I IOST?1"C-".E W *7,!,"Press RETURN to continue or ""^"" to stop    " R ANS:DTIME S:ANS=U!('$T) QUIT=1 I '$T S DVBAQUIT=1
 
Q
 
;
PRINTD ;create delimited incompetent report
 
D:('$D(^XTMP("DVBA_INCOMPETENT_RPT"_$J,0))) COLHDR
 
DEM^VADPT I $G(VADM(1))'="" SSN=$S(DVBADLMTR=",":$P($G(VADM(2)),U,2),1:$P($G(VADM(2)),U,1))
 
^TMP("DVBAR",$J,DVBABCNT)=""""_PNAM_""""_DVBADLMTR_$C(160)_CNUM_DVBADLMTR_CFLOC_DVBADLMTR_SSN_DVBADLMTR_ADMDT_DVBADLMTR_""""_DIAG_""""_DVBADLMTR_DCHGDT_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_$S((DCHGDT]""):TDIS_$S(TO]"":" TO "_$S($D(^DIC(4,+TO,0)):$P(^(0),U,1),1:""),1:""),1:"")_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_""""_BEDSEC_""""_DVBADLMTR_""_$S(RCVAA=0:"NO",RCVAA=1:"YES",1:"Not specified")_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_$S(RCVPEN=0:"NO",RCVPEN=1:"YES",1:"Not specified")_DVBADLMTR
 
;
 
ELIG=DVBAELIG,INCMP=""
 
ELIG]"" ELIG=ELIG_" ("_$S(DVBAELST="P":"Pend Ver",DVBAELST="R":"Pend Re-verif",DVBAELST="V":"Verified",1:"Not Verified")_")"
 
I $D(^DPT(DA,.29)) INCMP=$S($P(^(.29),U,12)=1:"Incompetent",1:"")
 
;
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_""""_ELIG_$S(ELIG]"":", ",1:"")_INCMP_""""_DVBADLMTR_$S($D(ICDAT)]"":ICDAT_" (VA)",1:"")_$S(ICDAT2]"":" - "_ICDAT2_" (CIVIL)",1:"")
 
DVBABCNT=DVBABCNT+1
 
Q
 
;
PRINT IO QUIT=""
 
MA="" H=0:0 MA=$O(^TMP($J,MA)) Q:MA=""!(QUIT=1)  XCN="" M=0:0 XCN=$O(^TMP($J,MA,XCN)) Q:XCN=""!(QUIT=1)  CFLOC="" J=0:0 CFLOC=$O(^TMP($J,MA,XCN,CFLOC)) Q:CFLOC=""!(QUIT=1)  PRINT1
 
Q
PRINT1 ADM="" K=0:0 ADM=$O(^TMP($J,MA,XCN,CFLOC,ADM)) Q:ADM=""!(QUIT=1)  DA="" L=0:0 DA=$O(^TMP($J,MA,XCN,CFLOC,ADM,DA)) Q:DA=""!(QUIT=1)  DATA=^(DAPRINTB
 
Q
 
;
TERM ;D HOME^%ZIS K NOASK
 
NOASK
 
;
SETUP ;W @IOF,!,"VARO INCOMPETENCY REPORT" D NOPARM^DVBAUTL2 
NOPARM ;check for AMIE parameter setup
 
'$D(^DVB(396.1,1,0)) ^TMP("DVBAR",$J,DVBABCNT)="No site parameters have been set up in file 396.1.",DVBABCNT=DVBABCNT+1,^TMP("DVBAR",$J,DVBABCNT)="You must do this before running any reports." DVBAQUIT=1 3
 
G:$D(DVBAQUITKILL^DVBAUTIL DTAR=^DVB(396.1,1,0),FDT(0)=$$FMTE^XLFDT(DT,"5DZ")
 
HEAD="INCOMPETENCY REPORT",HEAD1="FOR "_$P(DTAR,U,1)_" ON "_FDT(0)
 
;***vm-out*W !,HEAD1
EN1 ;***vm-out*W !!,"Please enter dates for search, oldest date first, most recent date last.",!!,"Last report was run on " S Y=$P(DTAR,U,5) X ^DD("DD") W Y,!!
 ;***vm-out*D DATE^DVBAUTIL G:X=""!(Y<0) KILL
 
%ZIS="Q" ^%ZIS %ZIS G:POP KILL^DVBAUTIL
 
;
QUEUE ;***vm-out*I $D(IO("Q")) S ZTRTN="DEQUE^DVBACMRP",ZTIO=ION,NOASK=1,ZTDESC="AMIE INCOMPETENT VET REPORT" F I="FDT(0)","HEAD","HEAD1","BDATE","EDATE","TYPE","RO","RONUM","NOASK" S ZTSAVE(I)=""
 ;***vm-out*I $D(IO("Q")) D ^%ZTLOAD W:$D(ZTSK) !!,"Request queued.",!! G KILL
 ;
GO MA=BDATE J=0:0 MA=$O(^DGPM("AMV1",MA)) Q:$P(MA,".")>EDATE!(MA="")  DA=0:0 DA=$O(^DGPM("AMV1",MA,DA)) Q:DA=""  MB=0:0 MB=$O(^DGPM("AMV1",MA,DA,MB)) Q:MB=""  SET '$D(NOASK"."
 
'$D(^TMP($J)) ^TMP("DVBAR",$J,DVBABCNT)="No data found for parameters entered." KILL
 
I $D(^TMP($J)) PRINT K:(DVBAFNLDTE=$P(EDATE,".")) ^XTMP("DVBA_INCOMPETENT_RPT"_$J,0) I $D(DVBAQUITDVBAON2 KILL^DVBAUTIL
 
;
KILL K:(DVBAFNLDTE=$P(EDATE,".")) ^XTMP("DVBA_INCOMPETENT_RPT"_$J,0)
 
ZMSG=$NA(^TMP("DVBAR",$J))
 
^%ZISC X=5 DVBAON2 D:$D(ZTQUEUEDKILL^%ZTLOAD FINAL^DVBAUTIL
 
Q
 
;
DEQUE ^TMP($JGO
 
;
COLHDR ;Column header for delimited report
 
^TMP("DVBAR",$J,DVBABCNT)=HEAD,DVBABCNT=DVBABCNT+1,^TMP("DVBAR",$J,DVBABCNT)=HEAD1,DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="Patient Name"_DVBADLMTR_"Claim No"_DVBADLMTR_"Claim Folder Loc"_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_"Social Sec No"_DVBADLMTR_"Admission Date"_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_"Admitting Diagnosis"_DVBADLMTR_"Discharge Date"_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_"Type of Discharge"_DVBADLMTR_"Bed Service"_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_"Recv A&A?"_DVBADLMTR_"Pension?"_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_"Eligibility Data"_DVBADLMTR_"Date Ruled Incomp"_$C(13)
 
DVBABCNT=DVBABCNT+1
 
^XTMP("DVBA_INCOMPETENT_RPT"_$J,0)=DT_U_DT
 
Q