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