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

LEXQDRG4.m

Go to the documentation of this file.
LEXQDRG4 ;ISL/KER - Query - DRG Calc. (DGPT - DX/SR/PR) ;05/23/2017
 ;;2.0;LEXICON UTILITY;**86,103**;Sep 23, 1996;Build 2
 ;               
 ; Global Variables
 ;    ^DGPT(              ICR     92
 ;               
 ; External References
 ;    $$GET1^DIQ          ICR   2056
 ;    $$CODEC^ICDEX       ICR   5747
 ;    $$DRG^ICDEX         ICR   5747
 ;    $$DRGD^ICDEX        ICR   5747
 ;    $$GETDATE^ICDEX     ICR   5747
 ;    $$ICDDX^ICDEX       ICR   5747
 ;    $$ICDOP^ICDEX       ICR   5747
 ;    $$VCC^ICDEX         ICR   5747
 ;    $$DT^XLFDT          ICR  10103
 ;    $$FMTE^XLFDT        ICR  10103
 ;    $$UP^XLFSTR         ICR  10104
 ;               
 ; Local Variables NEWed or KILLed Elsewhere
 ;          
 ;    ICDDX(1)    Array of ICD Principal Diagnosis
 ;    ICDDX(n)    Array of ICD Secondary Diagnosis
 ;    ICDPRC(n)   Array of ICD Procedures
 ;    ICDPOA(n)   Array of ICD-10 Present on Admission
 ;    ICDDATE     Date
 ; 
 ; PTF Diagnosis and Procedures
DX(X)  ;   LEXDX     Diagnosis String                    DX^DX^DX
 N LEX1,LEXDCH,LEXDT,LEXFL,LEXIEN,LEXIENS,LEXIPT,LEXIT,LEXPDX,LEXPRE,LEXPTF
 N LEXSDX,LEXTMP S LEXSDX="",LEXPTF=$G(X) Q:$G(LEXPTF)'>0 ""
 S LEXDCH=$$GET1^DIQ(45,(+($G(LEXPTF))_","),70,"I")
 ;     Diagnosis - after Oct 1, 1986
 I 'LEXDCH!(+LEXDCH>2861000) D
 . N LEXIT,LEXFL S LEXIT=0
 . F LEXFL=79.16,79.17,79.18,79.19,79.201,79.21,79.22,79.23,79.24 D  Q:LEXIT
 . . N LEXIPT,LEXDT,LEXTMP S LEXIPT=$$GET1^DIQ(45,(+($G(LEXPTF))_","),LEXFL,"I")
 . . S:LEXIPT'>0 LEXIT=1 Q:LEXIT  S LEXDT=$$GETDATE^ICDEX($G(LEXPTF))
 . . S LEXTMP=$$ICDDX^ICDEX(LEXIPT,LEXDT,,"I"),LEXIEN=+LEXTMP
 . . I +LEXTMP>0,$P(LEXTMP,"^",10) S LEXSDX=LEXSDX_"^"_+LEXTMP
 ;     Diagnosis - before Oct 1, 1986
 I +LEXDCH,+LEXDCH<2861000 D
 . N LEXDT F LEXDT=0:0 S LEXDT=$O(^DGPT(LEXPTF,"M","AM",LEXDT)) Q:LEXDT'>0  D
 . . N LEXTMP S LEX1=$O(^DGPT(LEXPTF,"M","AM",LEXDT,0))
 . . S LEXTMP="" F LEXFL=5:1:9 D
 . . . N LEXIEN,LEXIENS S LEXIENS=LEX1_","_LEXPTF_","
 . . . S LEXIEN=$$GET1^DIQ(45.02,LEXIENS,LEXFL,"I")
 . . . S:$$CODEC^ICDEX(80,LEXIEN)'["^" LEXTMP=LEXTMP_"^"_LEXIEN
 . . S LEXSDX=LEXTMP_$P(LEXSDX,"^",1,40)
 S LEXPDX=$$GET1^DIQ(45,(+($G(LEXPTF))_","),79,"I")
 S LEXPRE=$$GET1^DIQ(45,(+($G(LEXPTF))_","),80,"I")
 S LEXSDX=$S(LEXPDX:LEXPDX,1:LEXPRE)_LEXSDX
 S X=$G(LEXSDX) K LEXSDX
 Q X
SR(X) ;   LEXSR     Surgery String                      SR^SR^SR
 N LEXDCH,LEXI1,LEXI2,LEXIENS,LEXPTF,LEXSR,LEXSR1,LEXSRDT
 N LEXSRS,LEXTMP K LEXSR S LEXPTF=+($G(X)) q:$G(LEXPTF)'>0 ""
 Q:'$D(^DGPT(LEXPTF,"S")) ""  S LEXDCH=$$GET1^DIQ(45,(+($G(LEXPTF))_","),70,"I")
 F LEXI1=0:0 S LEXI1=$O(^DGPT(LEXPTF,"S",LEXI1)) Q:LEXI1'>0  D
 . N LEXSRS,LEXIENS S LEXIENS=LEXI1_","_LEXPTF_","
 . S LEXSRDT=$$GET1^DIQ(45.01,LEXIENS,.01,"I") I $L(LEXSRDT) D
 . . N LEXSR1 S LEXSRDT=$S('$D(LEXSR(LEXSRDT)):LEXSRDT,LEXSRDT[".":LEXSRDT_LEXI1_1,1:LEXSRDT_".0000"_LEXI1_1)
 . . S:$D(LEXSR(LEXSRDT)) LEXSRDT=$S(LEXSRDT[".":LEXSRDT_LEXI1_1,1:LEXSRDT_".0000"_LEXI1_1)
 . . S LEXSR(LEXSRDT)="" N LEXI2
 . . F LEXI2=8,9,10,11,12 S LEXSR1=$$GET1^DIQ(45.01,LEXIENS,LEXI2,"I") I LEXSR1]"" D
 . . . N LEXTMP S LEXTMP=$$ICDOP^ICDEX(LEXSR1,$P(LEXDCH,"."),,"I")
 . . . I +LEXTMP>0,$P(LEXTMP,"^",10) S LEXSR(LEXSRDT)=LEXSR(LEXSRDT)_LEXSR1_"^"
 I $D(LEXSR) S LEXSR="^" F LEXI1=0:0 S LEXI1=$O(LEXSR(LEXI1)) Q:LEXI1'>0  D
 . N LEXSR1,LEXSRS,LEXI2 S LEXSRS=LEXSR(LEXI1) F LEXI2=1:1:5 S LEXSR1=$P(LEXSRS,"^",LEXI2) Q:LEXSR1=""  D
 . . Q:$L(LEXSR)>240  S:LEXSR'[("^"_LEXSR1_"^") LEXSR=LEXSR_LEXSR1_"^"
 S X=$G(LEXSR) K LEXSR
 Q X
PR(X) ;   LEXPR     Procedures String                   PR^PR^PR
 N LEXDCH,LEXDT,LEXFL,LEXI1,LEXI2,LEXIEN,LEXIENS,LEXPR1,LEXPRDT,LEXPRS
 N LEXPTF,LEXTMP K LEXPR S LEXPTF=$G(X) Q:$G(LEXPTF)'>0 ""
 S LEXDCH=$$GET1^DIQ(45,(+($G(LEXPTF))_","),70,"I"),LEXPR=""
 I +LEXDCH,LEXDCH<2871000 D
 . N LEXFL F LEXFL=45.01,45.02,45.03,45.04,45.05 D
 . . N LEXPR1,LEXDT S LEXPR1=$$GET1^DIQ(45,(+($G(LEXPTF))_","),LEXFL,"I")
 . . S LEXDT=$$GETDATE^ICDEX($G(LEXPTF))
 . . S LEXTMP=$$ICDOP^ICDEX(LEXPR1,LEXDT,,"I")
 . . I +LEXTMP>0,$P(LEXTMP,"^",10) S LEXPR=LEXPR_LEXPR1_"^"
 I +LEXDCH'>0!(LEXDCH'<2871000) D
 . F LEXI1=0:0 S LEXI1=$O(^DGPT(LEXPTF,"P",LEXI1)) Q:LEXI1'>0  D
 . . N LEXPRDT,LEXIEN,LEXIENS,LEXFL
 . . S LEXIENS=LEXI1_","_LEXPTF_","
 . . S LEXPRDT=$$GET1^DIQ(45.05,LEXIENS,.01,"I") Q:'$L(LEXPRDT)
 . . S:$D(LEXPR(LEXPRDT)) LEXPRDT=$S(LEXPRDT[".":LEXPRDT_LEXI1_1,1:LEXPRDT_".0000"_LEXI1_1)
 . . S LEXPR(LEXPRDT)="" F LEXFL=4,5,6,7,8 D
 . . . N LEXIEN,LEXTMP S LEXIEN=$$GET1^DIQ(45.05,LEXIENS,LEXFL,"I")
 . . . Q:+LEXIEN'>0  S LEXTMP=$$ICDOP^ICDEX(LEXIEN,LEXDCH,,"I")
 . . . I +LEXTMP>0,$P(LEXTMP,"^",10) D
 . . . . S LEXPR(LEXPRDT)=LEXPR(LEXPRDT)_+LEXTMP_"^"
 . I $D(LEXPR) S LEXPR="^" F LEXI1=0:0 S LEXI1=$O(LEXPR(LEXI1)) Q:LEXI1'>0  D
 . . N LEXPRS,LEXPR1 S LEXPRS=LEXPR(LEXI1) F LEXI2=1:1:5 S LEXPR1=$P(LEXPRS,"^",LEXI2) Q:LEXPR1=""  D
 . . . Q:$L(LEXPR)>240  S:LEXPR'[("^"_LEXPR1_"^") LEXPR=LEXPR_LEXPR1_"^"
 S X=$G(LEXPR) K LEXPR
 Q X
 ;
ICDDXPR ;   Create ICDDX() and ICDPRC() arrays
 ;     ICDDX(n) Diagnosis Array                    (n)=IEN
 N LEXDT,LEXFLG,LEXGDAT,LEXI1,LEXI2,LEXI3,LEXPR1,LEXTMP K ICDDX,ICDPRC
 S LEXDT=$P($G(LEXGDAT),".",1)
 S:LEXDT'?7N LEXDT=$$DT^XLFDT I $D(LEXDX) D
 . N LEXI1 S LEXI1=0 F  S LEXI1=LEXI1+1 Q:$P(LEXDX,"^",LEXI1)=""  D
 . . N LEXTMP S LEXTMP=$$ICDDX^ICDEX(+$P(LEXDX,"^",LEXI1),$G(LEXDT),,"I")
 . . I +LEXTMP>0,($P(LEXTMP,"^",10)) S ICDDX(LEXI1)=$P(LEXDX,"^",LEXI1)
 ;     ICDPRC(n) Procedure Array                   (n)=IEN
 N LEXDX I $D(LEXPR) D
 . N LEXI1,LEXPR1
 . F LEXI1=2:1 S LEXPR1=$P(LEXPR,"^",LEXI1) Q:LEXPR1=""  D
 . . N LEXTMP S LEXTMP=$$ICDOP^ICDEX(LEXPR1,$G(LEXDT),,"I")
 . . I +LEXTMP>0,($P(LEXTMP,"^",10)) D
 . . . N LEXI3 S LEXI3=$O(ICDPRC(" "),-1)+1,ICDPRC(LEXI3)=LEXPR1
 I $D(LEXSR) D
 . N LEXI1,LEXPR1 F LEXI1=2:11 S LEXPR1=$P(LEXSR,"^",LEXI1) Q:LEXPR1=""  D
 . . N LEXFLG,LEXI2,LEXTMP S LEXFLG=0,LEXI2=0
 . . F  S LEXI2=$O(ICDPRC(LEXI2)) Q:'LEXI2  I LEXPR1=$G(ICDPRC(LEXI2)) S LEXFLG=1 Q
 . . Q:LEXFLG  S LEXTMP=$$ICDOP^ICDEX(LEXPR1,$G(LEXDT),,"I")
 . . I +LEXTMP>0,($P(LEXTMP,"^",10)) D
 . . . N LEXI3 S LEXI3=$O(ICDPRC(" "),-1)+1,ICDPRC(LEXI3)=LEXPR1
 Q
 ;
DCD ; Display Codes Used
 N LEXI,LEXC,LEXC2,LEXC3,LEXLEN,LEXT,LEXTX,LEXTD,LEXTI,LEXIEN,LEXCODE,LEXPOA,LEXCC,LEXEXT,LEXSTR,LEXSYS
 S LEXTD=$$DT^XLFDT,LEXSYS="10P" S:$G(ICDDATE)<$$IMPDATE^LEXU(30) LEXSYS="ICD"
 S LEXC2=16,LEXC3=25,LEXLEN=(79-LEXC3),LEXIEN=$G(ICDDX(1)) Q:+LEXIEN'>0
 S LEXCODE=$$CODEC^ICDEX(80,LEXIEN) Q:'$L(LEXCODE)
 S LEXPOA=$$POA(1),LEXCC=$$CC(1) S:LEXSYS="ICD" LEXPOA=""
 S LEXEXT="" S:$L(LEXCC) LEXEXT=LEXCC
 S:'$L(LEXCC)&($L(LEXPOA)) LEXEXT="POA: "_LEXPOA
 S:$L(LEXCC)&($L(LEXPOA)) LEXEXT=LEXEXT_", POA: "_LEXPOA
 S:$L(LEXEXT) LEXEXT=" ("_LEXEXT_")"
 W !!," Principal DX:"
 S LEXSTR=$P($$ICDDX^ICDEX(LEXIEN,LEXTD,,"I"),"^",4)_LEXEXT
 K LEXTX S LEXTX(1)=$$UP^XLFSTR(LEXSTR) D PR^LEXU(.LEXTX,LEXLEN)
 W ?LEXC2,LEXCODE,?LEXC3,$G(LEXTX(1)),! S LEXTI=1 F  S LEXTI=$O(LEXTX(LEXTI)) Q:+LEXTI'>0  D
 . N LEXS S LEXS=$$TM($G(LEXTX(LEXTI))) W:$L(LEXS) ?LEXC3,LEXS,!
 S (LEXC,LEXT)=0,LEXI=1 F  S LEXI=$O(ICDDX(LEXI)) Q:+LEXI'>0  D
 . N LEXIEN,LEXCODE,LEXPOA,LEXCC,LEXEXT,LEXSTR,LEXTX
 . S LEXIEN=$G(ICDDX(LEXI)) Q:+LEXIEN'>0
 . S LEXCODE=$$CODEC^ICDEX(80,LEXIEN) Q:'$L(LEXCODE)
 . S LEXPOA=$$POA(LEXI),LEXCC=$$CC(LEXI) S:LEXSYS="ICD" LEXPOA=""
 . S LEXEXT="" S:$L(LEXCC) LEXEXT=LEXCC
 . S:'$L(LEXCC)&($L(LEXPOA)) LEXEXT="POA: "_LEXPOA
 . S:$L(LEXCC)&($L(LEXPOA)) LEXEXT=LEXEXT_", POA: "_LEXPOA
 . S:$L(LEXEXT) LEXEXT=" ("_LEXEXT_")"
 . S LEXC=LEXC+1 W:LEXC=1 " Secondary DX:"
 . S LEXSTR=$P($$ICDDX^ICDEX(LEXIEN,LEXTD,,"I"),"^",4)_LEXEXT
 . K LEXTX S LEXTX(1)=$$UP^XLFSTR(LEXSTR) D PR^LEXU(.LEXTX,LEXLEN)
 . W ?LEXC2,LEXCODE,?LEXC3,$G(LEXTX(1)),! S LEXTI=1 F  S LEXTI=$O(LEXTX(LEXTI)) Q:+LEXTI'>0  D
 . . N LEXS S LEXS=$$TM($G(LEXTX(LEXTI))) W:$L(LEXS) ?LEXC3,LEXS,!
 S (LEXI,LEXC)=0 F  S LEXI=$O(ICDPRC(LEXI)) Q:+LEXI'>0  D
 . N LEXIEN,LEXCODE S LEXIEN=$G(ICDPRC(LEXI)),LEXCODE=$$CODEC^ICDEX(80.1,LEXIEN)
 . Q:'$L(LEXCODE)  S LEXC=LEXC+1 W:LEXC=1 " Procedures:"
 . K LEXTX S LEXTX(1)=$$UP^XLFSTR($P($$ICDOP^ICDEX(LEXIEN,LEXTD,,"I"),"^",5)) D PR^LEXU(.LEXTX,LEXLEN)
 . W ?LEXC2,LEXCODE,?LEXC3,$G(LEXTX(1)),! S LEXTI=1 F  S LEXTI=$O(LEXTX(LEXTI)) Q:+LEXTI'>0  D
 . . N LEXS S LEXS=$$TM($G(LEXTX(LEXTI))) W:$L(LEXS) ?LEXC3,LEXS,!
 Q
POA(X) ;   Present on Admission
 Q:+($G(X))'>0 ""  S X=$G(ICDPOA(+($G(X))))
 S X=$S(X="Y":"Yes",X="U":"Unknown",X="W":"Clinically Undetermined",1:"No")
 Q X
CC(X) ;   Complication/Comorbidity
 Q:+($G(X))'>0 ""  S X=$G(ICDDX(+($G(X)))) Q:+($G(X))'>0 ""
 S X=$$VCC^ICDEX(X,$G(ICDDATE))
 S X=$S(X=1:"CC",X=2:"Major CC",X=3:"MCC when patient is discharged alive",1:"")
 Q X
WRT(X,Y) ;   Write Output
 N LEXD,LEXDES,LEXDRG,LEXDT,LEXI,LEXN S LEXDRG=$G(X),LEXDT=$G(Y)
 S LEXD=$$DRG^ICDEX(+LEXDRG,LEXDT) D ATTR
 W !?10,"Effective Date: ","   ",$$FMTE^XLFDT($P(LEXDT,".",1),"5Z")
 W !," Diagnosis Related Group: ",$J(LEXDRG,6),?41,"Avg len of stay: ",$J($P(LEXD,"^",8),6)
 W !?18,"Weight: ",$J($P(LEXD,"^",2),6),?41,"Local Breakeven: ",$J($P(LEXD,"^",12),6)
 W !?13," Low day(s): ",$J($P(LEXD,"^",3),6),?40,"Local low day(s): ",$J($P(LEXD,"^",9),6)
 W !?14," High days: ",$J($P(LEXD,"^",4),6),?41,"Local High days: ",$J($P(LEXD,"^",10),6)
 N LEXN,LEXDES,LEXI S LEXN=$$DRGDES^ICDEX(LEXDRG,LEXDT,.LEXDES,(78-12)) S LEXI=0
 W !!," DRG: ",$G(BOLD),LEXDRG,$G(NORM)," - "
 F  S LEXI=$O(LEXDES(LEXI)) Q:'+LEXI  Q:LEXDES(LEXI)=" "  W ?12,LEXDES(LEXI),!
 D KATTR
 Q
TM(X,Y) ;   Trim Y
 N ICDDATE,ICDPOA S Y=$G(Y) S:'$L(Y) Y=" " F  Q:$E(X,1)'=Y  S X=$E(X,2,$L(X))
 F  Q:$E(X,$L(X))'=Y  S X=$E(X,1,($L(X)-1))
 Q X
ATTR ;   Screen Attributes
 N X,IOINHI,IOINORM S X="IOINHI;IOINORM" D ENDR^%ZISS S BOLD=$G(IOINHI),NORM=$G(IOINORM)
 Q
KATTR ;   Kill Screen Attributes
 D KILL^%ZISS K IOINHI,IOINORM,BOLD,NORM
 Q