DVBAB54 ;ALB/VM - CAPRI ADMISSION REPORT ; 3/5/12 11:31am
 ;;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 SC Veteran Admission report (By Ref)
 ;       BDATE     - Beginning date for eport (FM Format)
 ;       EDATE     - Ending date for report (FM Format)
 ;       DVBADLMTR - Indicates if report should be delimited (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 SC Veteran Admission report 
STRT(ZMSG,BDATE,EDATE,DVBADLMTR)  ;ENTER HERE
 
DVBAFNLDTE,MA1,DVBATMP
 
DVBABCNT=0,RO="N",RONUM=0
 
DVBAFNLDTE=$S(+$G(DVBADLMTR):+$P(DVBADLMTR,"."),1:0)
 
DVBADLMTR=$S('+$G(DVBADLMTR):"",1:"^")
 
^TMP($JTERM
SET 
Q:'$D(^DPT(DA,0))  DFN=DA,DVBASC="" SC^DVBAVDPT Q:DVBASC'="Y"  Q:CFLOC'=RONUM&(RO="Y")&(CFLOC'=0)&(CFLOC'=376)  MA1=$P(MA,".",1),^TMP($J,MA1,XCN,CFLOC,MB,DA)=MA
 
Q
 
;
PRINTB ADMDT=$P(DATA,U),DFN=DA ADM^DVBAVDPT
 
;W:(IOST?1"C-".E)!($D(DVBAON2)) @IOF
 ;W !!!,?(80-$L(HEAD)\2),HEAD,!,?(80-$L(HEAD1)\2),HEAD1,!!
 
S:ADMDT]"" ADMDT=$E(ADMDT,4,5)_"/"_$E(ADMDT,6,7)_"/"_$E(ADMDT,2,3) S:DCHGDT]"" DCHGDT=$E(DCHGDT,4,5)_"/"_$E(DCHGDT,6,7)_"/"_$E(DCHGDT,2,3)
 
;create delimited/non-delimited report
 
D:($G(DVBADLMTR)'=""PRINTD
 
D:($G(DVBADLMTR)=""PRINTND
 
DVBAON2=""
 
Q
 
;
PRINTND ;create non-delimited admission report
 
^TMP("DVBAR",$J,DVBABCNT)="",DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="",DVBABCNT=DVBABCNT+1
 
^TMP("DVBAR",$J,DVBABCNT)="          Patient Name:   "_PNAM,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
 
^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
 
;D ELIG^DVBAVDPT
ELIG 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)="      Eligibility data:   "_ELIG_$S(((ELIG]"")&(INCMP]"")):", ",1:""),DVBABCNT=DVBABCNT+1
 
I $X>60 ^TMP("DVBAR",$J,DVBABCNT)=INCMP,DVBABCNT=DVBABCNT+1
 
;Q
 ;***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 admission report
 
ELIG,INCMP,X,X1,X2,X3
 
D:('$D(^XTMP("DVBA_SCADMSSN_RPT"_$J,0))) COLHDR
 
^TMP("DVBAR",$J,DVBABCNT)=PNAM_DVBADLMTR_CNUM_DVBADLMTR_CFLOC_DVBADLMTR_SSN_DVBADLMTR_ADMDT_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_DIAG_DVBADLMTR_DCHGDT_DVBADLMTR_BEDSEC_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=^TMP("DVBAR",$J,DVBABCNT)_$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]"")&(INCMP]"")):", ",1:"")_INCMP
 
;
 
DVBATMP=^TMP("DVBAR",$J,DVBABCNT)
 
X=$P(DVBATMP,DVBADLMTR,4)
 
I $L(X)'>9 X=""""_$E("000000000",1,9-$L(X))_X_"""",X1=$E(X,1,4),X2=$E(X,5,6),X3=$E(X,7,11),X=X1_"-"_X2_"-"_X3
 
I $E(X,10,10)'?.X=""""_$E("0000000000",1,10-$L(X))_X_"""",X1=$E(X,1,4),X2=$E(X,5,6),X3=$E(X,7,12),X=X1_"-"_X2_"-"_X3
 
S $P(DVBATMP,DVBADLMTR,4)=X
 
X=$P(DVBATMP,DVBADLMTR,2)
 
X=$C(160)_X
 
S $P(DVBATMP,DVBADLMTR,2)=X
 
I=1:1:$L(DVBATMP,DVBADLMTRI $P(DVBATMP,DVBADLMTR,I)["," S $P(DVBATMP,DVBADLMTR,I)=""""_$P(DVBATMP,DVBADLMTR,I)_""""
 
DVBATMP=$TR(DVBATMP,DVBADLMTR,",")
 
^TMP("DVBAR",$J,DVBABCNT)=DVBATMP
 
;
 
DVBABCNT=DVBABCNT+1
 
Q
 
;
PRINT MA QUIT=""
 
MA="" G=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
 ;
 ;W @IOF,!,"VARO SERVICE-CONNECTED ADMISSION REPORT" D NOPARM^DVBAUTL2 G:$D(DVBAQUIT) KILL^DVBAUTIL
 
DTAR=^DVB(396.1,1,0),FDT(0)=$E(DT,4,5)_"-"_$E(DT,6,7)_"-"_$E(DT,2,3)
 
HEAD="SERVICE-CONNECTED ADMISSION REPORT",HEAD1="FOR "_$P(DTAR,U,1)_" ON "_FDT(0)
 
;W !,HEAD1
 ;W !!,"Please enter dates for search, oldest date first, most recent date last.",!!,"Last report was run on " S Y=$P(DTAR,U,8) X ^DD("DD") W Y,!!
 ;D DATE^DVBAUTIL
 ;G:X=""!(Y<0) KILL
 ;S %ZIS="Q" D ^%ZIS K %ZIS G:POP KILL^DVBAUTIL
 ;
 ;I $D(IO("Q")) S ZTRTN="DEQUE^DVBASCRP",ZTIO=ION,NOASK=1,ZTDESC="AMIE SC ADMISSION REPORT" F I="FDT(0)","HEAD","HEAD1","BDATE","EDATE","TYPE","RO","RONUM","NOASK" S ZTSAVE(I)=""
 ;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 W:'$D(NOASK"."
 
'$D(^TMP($J)) ^TMP("DVBAR",$J,DVBABCNT)="No data found for parameters entered." KILL
 
PRINT K:(DVBAFNLDTE=$P(EDATE,".")) ^XTMP("DVBA_SCADMSSN_RPT"_$J,0)
 
I $D(DVBAQUITDVBAON2 D:$D(ZTQUEUEDKILL^%ZTLOAD KILL^DVBAUTIL
 
;
KILL K:(DVBAFNLDTE=$P(EDATE,".")) ^XTMP("DVBA_SCADMSSN_RPT"_$J,0)
 
ZMSG=$NA(^TMP("DVBAR",$J))
 
D:$D(ZTQUEUEDKILL^%ZTLOAD ^%ZISC X=8 DVBAON2 FINAL^DVBAUTIL
 
;
DEQUE ^TMP($JGO
 
;
COLHDR ;Column header for delimited report
 
DVBADLMTR
 
DVBADLMTR=","
 
^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))_"Bed Service"_DVBADLMTR_"Recv A&A?"_DVBADLMTR
 
^TMP("DVBAR",$J,DVBABCNT)=(^TMP("DVBAR",$J,DVBABCNT))_"Pension?"_DVBADLMTR_"Eligibility Data"
 
DVBABCNT=DVBABCNT+1
 
;set global entry so header is only created once for job ($J)
 
^XTMP("DVBA_SCADMSSN_RPT"_$J,0)=DT_U_DT
 
Q