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

LEXQDRG3.m

Go to the documentation of this file.
  1. LEXQDRG3 ;ISL/KER - Query - DRG Calc. (DGPT) ;12/19/2014
  1. ;;2.0;LEXICON UTILITY;**86**;Sep 23, 1996;Build 1
  1. ;
  1. ; Global Variables
  1. ; ^XTMP(ID) SACC 2.3.2.5.2
  1. ;
  1. ; External References
  1. ; ^DIC ICR 10006
  1. ; $$FIND1^DIC ICR 2051
  1. ; $$GET1^DIQ ICR 2056
  1. ; ^DIR ICR 10026
  1. ; ^ICDDRG ICR 371
  1. ; $$DT^XLFDT ICR 10103
  1. ; $$FMADD^XLFDT ICR 10103
  1. ; $$FMTE^XLFDT ICR 10103
  1. ; $$UP^XLFSTR ICR 10104
  1. ;
  1. ; ICDDATE Date
  1. ; ICDEXP Patient died during episode of care 1/0
  1. ; ICDTRS Was patient transferred to acute care 1/0
  1. ; ICDDMS Patient discharged against medical advice 1/0
  1. ; SEX Patient's Sex (pre-surgical M/F
  1. ; AGE Patient's Age Numeric
  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. ;
  1. EN ; Main Entry Point
  1. N AGE,DFN,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,ICDDATE,ICDDMS,ICDDRG,ICDDX,ICDEXP
  1. N ICDPRC,ICDTRS,LEX1,LEXB,LEXC,LEXCODE,LEXD,LEXDCH,LEXDES,LEXDFN,LEXDOB
  1. N LEXDRG,LEXDT,LEXDX,LEXLEXP,LEXF,LEXFL,LEXFLG,LEXGDAT,LEXI,LEXI1,LEXI2,LEXI3
  1. N LEXID,LEXIEN,LEXIENS,LEXIPT,LEXIT,LEXMN,LEXMNE,LEXMX,LEXMXE,LEXN,LEXNAM
  1. N LEXOK,LEXOUT,LEXPDX,LEXPR,LEXPR1,LEXPRDT,LEXPRE,LEXPRS,LEXPTF,LEXSCC
  1. N LEXSDX,LEXSR,LEXSR1,LEXSRDT,LEXSRS,LEXT,LEXTD,LEXTMP,LEXVAP,SEX,X,Y
  1. S LEXVAP=$$VAP I +LEXVAP'>0,$L($P(LEXVAP,"^",2)) W !!," ",$P(LEXVAP,"^",2) Q
  1. I +LEXVAP'>0 W !!," Patient not selected" Q
  1. S X=$P($$EFF,".",1) I X'?7N,$L($P(X,"^",2)) W !!," ",$P(X,"^",2) Q
  1. I X'?7N W !!," 'Effective date' missing or invalid" Q
  1. S (LEXGDAT,ICDDATE)=X,LEXVAP=+($G(LEXVAP)) S LEXOK=$$GETPAT(LEXVAP)
  1. I LEXOK'>0,$L($P(LEXOK,"^",2)) W !!," ",$P(LEXOK,"^",2) Q
  1. I LEXOK'>0 W !!," 'Patient treatment information' missing or invalid" Q
  1. D ^ICDDRG I +($G(ICDDRG))>0 W:$L($G(IOF)) @IOF D DCD^LEXQDRG4,WRT^LEXQDRG4(ICDDRG,ICDDATE)
  1. Q
  1. EFF(X) ; Effective date
  1. N DIR,DIROUT,DIRUT,DTOUT,DUOUT,LEXB,LEXF,LEXID,LEXMN,LEXMNE,LEXMX,LEXMXE,LEXN,Y,LEXIMP
  1. S LEXIMP=$$IMPDATE^LEXU(30),LEXN=$$DT^XLFDT,LEXF=$$FMADD^XLFDT(LEXN,60),LEXID="LEXQDRG "_$G(DUZ)_" DATE"
  1. S LEXB=$P($G(^XTMP(LEXID,"PRE")),".",1) S:LEXB?7N DIR("B")=$$UP^XLFSTR($$FMTE^XLFDT(LEXB,"1D"))
  1. S LEXMN=2781001,LEXMX=DT S:LEXMX'>LEXIMP LEXMX=LEXIMP S LEXMX=$$FMADD^XLFDT(LEXMX,730)
  1. S LEXMNE=$$FMTE^XLFDT(+($G(LEXMN)),"1D"),LEXMXE=$$FMTE^XLFDT(+($G(LEXMX)),"1D")
  1. S LEXMNE=$$UP^XLFSTR(LEXMNE),LEXMXE=$$UP^XLFSTR(LEXMXE) S DIR(0)="DAO^"_LEXMN_":"_LEXMX
  1. S DIR("?")="^D EFH1^LEXQDRG3" S DIR("??")="^D EFH2^LEXQDRG3"
  1. S DIR("A")=" Enter the diagnosis effective date: "
  1. W:+($G(LEXHAS))'>0&('$D(DFN)) ! D ^DIR Q:$D(DTOUT) "0^'Effective date' selection timed-out"
  1. I $D(DIROUT)!($D(DIRUT))!($D(DUOUT)) D Q X
  1. . S X="0^'Effective date' selection aborted"
  1. S Y=$P(Y,".",1) Q:Y'?7N "0^Missing or invalid 'effective date'"
  1. I Y?7N S ^XTMP(LEXID,0)=LEXF_"^"_LEXN_"^Previous",^XTMP(LEXID,"PRE")=Y N DFN
  1. S X=Y Q:X?7N X
  1. Q "0^Invalid 'effective date'"
  1. EFH1 ; Effective Date Help #1
  1. W !," Enter the effective date of the patient's diagnosis"
  1. I $L($G(LEXMXE)),$L($G(LEXMNE)) D
  1. . W !!," Select a date from ",LEXMNE," to ",LEXMXE
  1. Q
  1. EFH2 ; Effective Date Help #2
  1. D EFH1 W !
  1. W !," JAN 20 2012 or 20 JAN 12 or 1/20/12 or 012012"
  1. W !," T (for TODAY), T+1 (for TOMORROW), T+2, etc."
  1. W !," T-1 (for YESTERDAY), T-3W (for 3 WEEKS AGO), etc."
  1. W !," If the year is omitted, the computer uses CURRENT"
  1. W !," YEAR. Two digit year assumes no more than 20 "
  1. W !," years in the future, or 80 years in the past."
  1. W:$L($G(DIR("B"))) !," Press return to accept the default date."
  1. W !," Enter ""^"" to abort."
  1. Q
  1. PAT(X) ; Patient
  1. N DIR,DIROUT,DIRUT,DTOUT,DUOUT,LEXB,LEXF,LEXID,LEXN,Y
  1. S LEXN=$$DT^XLFDT,LEXF=$$FMADD^XLFDT(LEXN,60),LEXID="LEXQDRG "_$G(DUZ)_" PAT"
  1. S LEXB=$G(^XTMP(LEXID,"PRE")),LEXB=$S(LEXB="1":"YES",1:"NO") S:$L(LEXB) DIR("B")=LEXB
  1. S DIR(0)="YAO",DIR("A")=" Calculate DRGs for a Registered Patient? (Y/N) "
  1. S DIR("?")="Enter 'Yes' if the patient has been previously registered, enter 'No' for other patient."
  1. S DIR("PRE")="S:X[""?"" X=""?""" D ^DIR
  1. Q:$D(DTOUT) "0^'Calculate DRGs for a Registered Patient' selection timed-out"
  1. I $D(DIROUT)!($D(DIRUT))!($D(DUOUT))!("^1^0^"'[("^"_Y_"^")) D Q X
  1. . S X="0^'Calculate DRGs for a Registered Patient' selection aborted"
  1. I "^1^0^"[("^"_Y_"^") S ^XTMP(LEXID,0)=LEXF_"^"_LEXN_"^Previous",^XTMP(LEXID,"PRE")=Y
  1. S X=Y
  1. Q X
  1. VAP(X) ; VA Patient File #2
  1. N DIC,DTOUT,DUOUT,LEXB,LEXDFN,LEXLEXP,LEXF,LEXID,LEXN,LEXNAM,LEXSCC,Y
  1. S LEXN=$$DT^XLFDT,LEXF=$$FMADD^XLFDT(LEXN,60),LEXID="LEXQDRG "_$G(DUZ)_" VAP"
  1. S LEXB=$G(^XTMP(LEXID,"PRE")),LEXB=$$GET1^DIQ(2,(+LEXB_","),.01)
  1. S DIC="^DPT(",DIC(0)="AEQMZ",DIC("A")=" Select VA Patient: ",DIC("S")="I +($$VAS^LEXQDRG3)>0"
  1. D ^DIC Q:$D(DTOUT) "0^'VA Patient' selection timed-out"
  1. I $D(DUOUT) S X="0^'VA Patient' selection aborted" Q X
  1. I +Y'>0 S X="0^'VA Patient' not selected" Q X
  1. S X=Y I +Y>0 S DFN=+Y,^XTMP(LEXID,0)=LEXF_"^"_LEXN_"^Previous",^XTMP(LEXID,"PRE")=+Y
  1. Q X
  1. VAS(X) ; VA Patient File #2 Screen (live/service connected)
  1. N LEXDFN,LEXNAM,LEXLEXP,LEXSCC S LEXDFN=+($G(Y)) Q:LEXDFN'>0 0
  1. S LEXNAM=$$GET1^DIQ(2,(+($G(Y))_","),.01) Q:'$L(LEXNAM) 0
  1. S LEXLEXP=$$GET1^DIQ(2,(+($G(Y))_","),.351,"I") Q:+LEXLEXP>0 0
  1. S LEXSCC=$$GET1^DIQ(2,(+($G(Y))_","),.301,"I") Q:$E(LEXSCC,1)'="Y" 0
  1. Q 1
  1. ;
  1. GETPAT(X) ; Get Patient Values
  1. N LEXDCH,LEXDFN,LEXDOB,LEXNAM,LEXOUT,LEXPTF
  1. K AGE,ICDDMS,ICDDX,ICDEXP,ICDPRC,ICDTRS,SEX
  1. S LEXOUT=1,LEXDFN=+($G(X))
  1. Q:$G(LEXDFN)'>0 "0^Patient (DFN) undefined"
  1. S LEXNAM=$$GET1^DIQ(2,(+($G(LEXDFN))_","),.01)
  1. Q:'$L(LEXNAM) "0^Patient (DFN) not found"
  1. S LEXPTF=$$FIND1^DIC(45,,"B",LEXNAM,"B")
  1. Q:LEXPTF'>0 "0^Patient Treatment Record not found"
  1. ; ICDEXP Did patient die during care 1/0
  1. S ICDEXP=$$GET1^DIQ(45,(+($G(LEXPTF))_","),72,"I"),ICDEXP=$S(ICDEXP>5:1,1:0)
  1. ; ICDDSM Discharged against medical advice 1/0
  1. S ICDDMS=$$GET1^DIQ(45,(+($G(LEXPTF))_","),72,"I"),ICDEXP=$S(ICDDMS=4:1,1:0)
  1. ; ICDTRS Transfer to acute care facility 1/0
  1. S ICDTRS=$$GET1^DIQ(45,(+($G(LEXPTF))_","),76.2),ICDTRS=$S(ICDEXP:1,1:0)
  1. ; SEX Sex M/F
  1. S SEX=$$GET1^DIQ(2,(+($G(LEXDFN))_","),.02,"I")
  1. ; AGE Age Numeric
  1. S LEXDCH=$$GET1^DIQ(45,(+($G(LEXPTF))_","),70,"I")
  1. S LEXDOB=$$GET1^DIQ(2,(+($G(LEXDFN))_","),.03,"I")
  1. S AGE=$S(LEXDCH:LEXDCH,1:DT)-LEXDOB\10000
  1. K LEXDX S LEXDX=$$DX^LEXQDRG4(LEXPTF)
  1. K LEXSR S LEXSR=$$SR^LEXQDRG4(LEXPTF)
  1. K LEXPR S LEXPR=$$PR^LEXQDRG4(LEXPTF)
  1. D ICDDXPR^LEXQDRG4
  1. S LEXOUT=1 S:"^1^0^"'[("^"_ICDEXP_"^") LEXOUT=-1
  1. S:"^1^0^"'[("^"_ICDTRS_"^") LEXOUT=-2
  1. S:"^1^0^"'[("^"_ICDDMS_"^") LEXOUT=-3
  1. S:"^M^F^"'[("^"_SEX_"^") LEXOUT=-4
  1. S:AGE'?1N.N LEXOUT=-5
  1. S:$O(ICDDX(0))'>0 LEXOUT=-6
  1. K:LEXOUT'>0 AGE,SEX,ICDDMS,ICDDX,ICDEXP,ICDPRC,ICDTRS
  1. S X=LEXOUT S:X'>0 X="0^Error extracting patient treatment information"
  1. Q X