ICDEXC ;SLC/KER - ICD Extractor - Code APIs ;12/19/2014
;;18.0;DRG Grouper;**57,67**;Oct 20, 2000;Build 1
;
; Global Variables
; None
;
; External References
; $$DT^XLFDT ICR 10103
; $$UP^XLFSTR ICR 10104
;
ICDDX(CODE,CDT,SYS,FMT,LOC) ; Return ICD Dx Code Info
;
; Input:
;
; CODE Code/IEN (required)
; CDT Date (default = TODAY)
; SYS Coding System (taken from file 80.4)
; 1 = ICD-9 Diagnosis
; 30 = ICD-10 Diagnosis
; FMT Format
; E = External (default)
; I = Internal Entry Number
; LOC Use Local codes
; 1 = Yes
; 0 = No (default)
;
; Output:
;
; Returns an 22 piece string delimited by ^
;
; 1 IEN of code in ^ICD9(
; 2 ICD-9 Dx Code (#.01)
; 3 Identifier (#1.2)
; 4 Versioned Dx (67 multiple)
; 5 Unacceptable as Principal Dx (#1.3)
; 6 Major Dx Cat (72 multiple)
; 7 MDC13 (#1.4)
; 8 Compl/Comorb (103 multiple)
; 9 ICD Expanded (#1.7)
; 10 Status (66 multiple)
; 11 Sex (10 multiple)
; 12 Inactive Date (66 multiple)
; 13 MDC24 (#1.5)
; 14 MDC25 (#1.6)
; 15 Age Low (11 multiple)
; 16 Age High (12 multiple)
; 17 Activation Date (66 multiple)
; 18 Message
; 19 Complication/Comorbidity (103 multiple)
; 20 Coding System (#1.1)
; 21 Primary CC Flag (103 multiple)
; 22 PDX Exclusion Code (#1.11)
;
; or
;
; -1^Error Description
;
N IEN,NODE,OUT,SAI,ROOT,SNAM,ICDY,UPC S FMT=$G(FMT) S:'$L(FMT) FMT="E"
S ROOT=$$ROOT^ICDEX(80),CODE=$G(CODE) Q:'$L(CODE) "-1^No Code Selected"
Q:FMT="I"&(CODE'?1N.N) "-1^Code not in correct format"
I FMT="I",CODE?1N.N S IEN=CODE,CODE=$P($G(^ICD9(IEN,0)),"^",1)
Q:'$L(CODE) "-1^No Code Selected" S SYS=$$SYS^ICDEX(+($G(SYS)))
S UPC=$$UP^XLFSTR(CODE) S:+SYS'>0 SYS=$$SYS^ICDEX($G(UPC)) I +SYS'>0 D
. N FILE S FILE=$$CODEFI^ICDEX(UPC),SYS=$P($$CODECS^ICDEX(UPC,FILE),"^",1)
Q:+SYS>0&('$D(@(ROOT_"""ABA"","_+SYS_")"))) "-1^Invalid Coding System"
S SNAM=$$SNAM^ICDEX(+SYS),LOC=+($G(LOC))
S IEN=$S(+SYS>0:$$CODEABA(CODE,ROOT,SYS),1:$$CODEBA(CODE,ROOT))
S:+IEN'>0 IEN=$S(+SYS>0:$$CODEABA(UPC,ROOT,SYS),1:$$CODEBA(UPC,ROOT))
S:+IEN'>0&($G(LOC)>0)&($D(^ICD9("AVA",(CODE_" ")))) IEN=$O(^ICD9("AVA",(CODE_" "),0))
Q:'$G(LOC)&($D(^ICD9("AVA",(CODE_" ")))) ("-1^VA Local Code ("_CODE_")")
Q:IEN<1&(+SYS>0)&($L(SNAM))&('$D(^ICD9("AVA",(CODE_" ")))) ("-1^Invalid Code (not found in the "_SNAM_" system)")
Q:IEN<1 "-1^Invalid Code" Q:'$D(^ICD9(IEN,0)) "-1^Invalid Code (not found)"
S ICDY=$P($G(^ICD9(IEN,1)),"^",1) Q:+ICDY'>0 "-1^Invalid Coding System"
S CDT=$P($G(CDT),".",1) S:'$L($G(CDT)) CDT=$$DT^XLFDT
S CDT=$$DTBR^ICDEX($G(CDT),,ICDY) Q:CDT'?7N "-1^No Date Provided"
S NODE=$P($G(^ICD9(IEN,0)),"^",1) Q:'$L(NODE) "-1^Code not found"
Q:'$G(LOC)&($L(NODE))&($P(^ICD9(IEN,1),U,7)) ("-1^VA Local Code ("_NODE_")")
S OUT=IEN_"^"_NODE,SAI=$$SAI^ICDEX(80,IEN,CDT)
S NODE=$G(^ICD9(IEN,1)) Q:'$L(NODE) "-1^Data not found"
S $P(OUT,"^",3)=$$IDSTR^ICDEX(80,IEN)
S $P(OUT,"^",4)=$$VSTD^ICDEX(IEN,CDT)
S $P(OUT,"^",5)=$P(NODE,"^",3)
S $P(OUT,"^",6)=$$VMDC^ICDEX(IEN,CDT)
S $P(OUT,"^",7)=$P(NODE,"^",4)
S $P(OUT,"^",8)=$$VCC^ICDEX(IEN,CDT)
S:$P(NODE,"^",7)>0 $P(OUT,"^",9)=$P(NODE,"^",7)
S $P(OUT,"^",10)=$S(+$P($G(SAI),"^",1)>0:1,1:0)
S $P(OUT,"^",11)=$$VSEX^ICDEX(80,IEN,CDT)
S $P(OUT,"^",12)=$S($P($G(SAI),"^",3)?7N:$P($G(SAI),"^",3),1:"")
S $P(OUT,"^",13)=$P(NODE,"^",5)
S $P(OUT,"^",14)=$P(NODE,"^",6)
S $P(OUT,"^",15)=$$VAGEL^ICDEX(IEN,CDT)
S $P(OUT,"^",16)=$$VAGEH^ICDEX(IEN,CDT)
S $P(OUT,"^",17)=$S($P($G(SAI),"^",2)?7N:$P($G(SAI),"^",2),1:"")
S $P(OUT,"^",18)=$$MSG^ICDEX(CDT)
S $P(OUT,"^",19)=$$VCC^ICDEX(IEN,CDT)
S:+($G(^ICD9(+IEN,1)))>0 $P(OUT,"^",20)=+($G(^ICD9(+IEN,1)))
S $P(OUT,"^",21)=$$VCCP^ICDEX(IEN,CDT)
S $P(OUT,"^",22)=$$PDXE^ICDEX(IEN)
Q OUT
;
ICDOP(CODE,CDT,SYS,FMT,LOC) ; Return ICD Operation/Procedure Code Info
;
; Input:
;
; CODE Code/IEN (required)
; CDT Date (default = TODAY)
; SYS Coding System (taken from file 757.03)
; 2 = ICD-9 Procedure
; 31 = ICD-10 Procedure
; FMT Format
; E = External (default)
; I = Internal Entry Number
; LOC Use Local codes
; 1 = Yes
; 0 = No (default)
;
; Output:
;
; Returns an 14 piece string delimited by ^
;
; 1 IEN of code in ^ICD0(
; 2 ICD procedure code (#.01)
; 3 Identifier (#1.2)
; 4 MDC24 (#1.5)
; 5 Versioned Oper/Proc (67 multiple)
; 6 <null>
; 7 <null>
; 8 <null>
; 9 ICD Expanded (#1.7)
; 10 Status (66 multiple)
; 11 Use with Sex (10 multiple)
; 12 Inactive Date (66 multiple)
; 13 Activation Date (66 multiple)
; 14 Message
; 15 Coding System (#1.1)
;
; or
;
; -1^Error Description
;
N IEN,NODE,OUT,ROOT,SNAM,SAI,ICDY S FMT=$G(FMT) S:'$L(FMT) FMT="E"
S ROOT=$$ROOT^ICDEX(80.1),CODE=$G(CODE) Q:'$L(CODE) "-1^No Code Selected"
Q:FMT="I"&(CODE'?1N.N) "-1^Code not in correct format"
I FMT="I",CODE?1N.N S IEN=CODE,CODE=$P($G(^ICD0(+IEN,0)),"^",1),FMT="E"
Q:'$L(CODE) "-1^No Code Selected"
S SYS=$$SYS^ICDEX(+($G(SYS))),LOC=+($G(LOC)) I +SYS'>0 D
. N FILE S FILE=$$CODEFI^ICDEX(CODE),SYS=$P($$CODECS^ICDEX(CODE,FILE),"^",1)
Q:+SYS>0&('$D(@(ROOT_"""ABA"","_+SYS_")"))) "-1^Invalid Coding System"
S SNAM=$$SNAM^ICDEX(+SYS),IEN=$S(+SYS>0:$$CODEABA(CODE,ROOT,SYS),1:$$CODEBA(CODE,ROOT))
S:+IEN'>0&(+($G(LOC))>0)&($D(^ICD0("AVA",(CODE_" ")))) IEN=$O(^ICD0("AVA",(CODE_" "),0))
Q:'$G(LOC)&($D(^ICD0("AVA",(CODE_" ")))) ("-1^VA Local Code ("_CODE_")")
Q:IEN<1&(+SYS>0)&($L(SNAM)) ("-1^Invalid Code (not found in the "_SNAM_" system)")
Q:IEN<1 "-1^Invalid Code" Q:'$D(^ICD0(IEN,0)) "-1^Invalid Code (not found)"
S ICDY=$P($G(^ICD0(IEN,1)),"^",1) Q:+ICDY'>0 "-1^Invalid Coding System"
S CDT=$P($G(CDT),".",1) S:'$L($G(CDT)) CDT=$$DT^XLFDT
S CDT=$$DTBR^ICDEX($G(CDT),,ICDY) Q:CDT'?7N "-1^No Date Provided"
S NODE=$P($G(^ICD0(+IEN,0)),"^",1) Q:'$L(NODE) "-1^Code not found"
Q:'$G(LOC)&($P(^ICD0(IEN,1),U,7)) ("-1^VA Local Code Selected ("_NODE_")")
S OUT=IEN_"^"_NODE,SAI=$$SAI^ICDEX(80.1,IEN,CDT)
S NODE=$G(^ICD0(IEN,1)) Q:'$L(NODE) "-1^Data not found"
S $P(OUT,"^",3)=$$IDSTR^ICDEX(80.1,IEN)
S $P(OUT,"^",4)=$P(NODE,"^",5)
S $P(OUT,"^",5)=$$VSTP^ICDEX(IEN,CDT)
S:$P(NODE,"^",7)>0 $P(OUT,"^",9)=$P(NODE,"^",7)
S $P(OUT,"^",10)=$S(+$P($G(SAI),"^",1)>0:1,1:0)
S $P(OUT,"^",11)=$$VSEX^ICDEX(80.1,IEN,CDT)
S $P(OUT,"^",12)=$S($P($G(SAI),"^",3)?7N:$P($G(SAI),"^",3),1:"")
S $P(OUT,"^",13)=$S($P($G(SAI),"^",2)?7N:$P($G(SAI),"^",2),1:"")
S $P(OUT,"^",14)=$$MSG^ICDEX(CDT)
S:+($G(^ICD0(+IEN,1)))>0 $P(OUT,"^",15)=+($G(^ICD0(+IEN,1)))
Q OUT
ICDD(CODE,ARY,CDT,SYS,LEN) ; Returns ICD description in array
;
; Input:
;
; CODE Code, external format (required)
; ARY Array Name passed by reference (required)
; CDT Date (optional, default = TODAY)
; SYS Coding System (optional)
; LEN Sting Length (optional, > 27, default 245)
;
; Output:
;
; # Number of lines in array
;
; ARY(1) - Versioned Description (68 multiple)
;
; If there is a warning message (ICD-9 only):
;
; ARY(n+1) - blank
; ARY(n+2) - warning message: CODE TEXT MAY BE INACCURATE
;
; or
;
; -1^Error Description
;
;
N ARR,END,I,N,ROOT,SNAM,VAR,IEN,ICDY
Q:'$L($G(CODE)) "-1^Missing required input parameter CODE"
S SYS=$$SYS^ICDEX(+($G(SYS))) I +SYS'>0 D
. N FILE S FILE=$$CODEFI^ICDEX(CODE),SYS=$P($$CODECS^ICDEX(CODE,FILE),"^",1)
S ROOT=$$ROOT^ICDEX(+SYS)
Q:"^ICD9(^ICD0(^"'[("^"_$E(ROOT,2,$L(ROOT))_"^")!('$L(ROOT)) "-1^Invalid Coding System"
Q:+SYS>0&('$D(@(ROOT_"""ABA"","_+SYS_")"))) "-1^Invalid Coding System"
S SNAM=$$SNAM^ICDEX(+SYS),IEN=$S(+SYS>0:$$CODEABA(CODE,ROOT,SYS),1:$$CODEBA(CODE,ROOT))
Q:+IEN<1!('$L(ROOT)) "-1^Invalid Code" Q:'$D(@(ROOT_IEN_",0)")) "-1^Code not found"
S LEN=+($G(LEN)) S:LEN'>0 LEN=245 S:LEN<28 LEN=245 K ARY
S ICDY=$P($G(@(ROOT_+IEN_",1)")),"^",1)
Q:+ICDY'>0 "-1^Invalid Coding System"
S I=0,N=0
S CDT=$P($G(CDT),".",1) S:'$L($G(CDT)) CDT=$$DT^XLFDT
S CDT=$$DTBR^ICDEX($G(CDT),,ICDY) Q:CDT'?7N "-1^No Date Provided"
S ARY(1)=$$VLT^ICDEX(ROOT,IEN,CDT)
I LEN>27,LEN<245 D PAR^ICDEX(.ARY,LEN)
S N=$O(ARY(" "),-1) I +ICDY<3 D
. N MSG S MSG=$$MSG^ICDEX(CDT) Q:'$L(MSG) S ARY(N+1)=" ",ARY(N+2)=MSG
S N=+($O(ARY(" "),-1))
Q N
CODEN(CODE,FILE) ; Return IEN of ICD code
;
; Input:
;
; CODE ICD code (required)
; FILE File Number to search for code
; 80 = ICD Dx file
; 80.1 = ICD Oper/Proc file
;
; Output:
;
; IEN~Global Root or -1~error message
;
N ROOT,IEN,ERR,EIEN,ICDU S ERR=""
Q:$G(CODE)="" "-1~Missing required input parameter CODE"
S CODE=$TR(CODE," ",""),ICDU=$$UP^XLFSTR(CODE)
S:"^80^80.1^"'[("^"_$G(FILE)_"^") FILE=$$CODEFI^ICDEX(CODE)
S ROOT=$$ROOT^ICDEX($G(FILE)) Q:'$L(ROOT) "-1~Invalid File"
S IEN=$$CODEBA(CODE,ROOT) S:+IEN'>0 ERR="-1~Invalid or Code not found"
I $D(ICDVP),CODE?1N.N,+ERR<0,$L(ROOT) S:$D(@(ROOT_+CODE_",0)")) IEN=+CODE,ERR="" N ICDVP
I +IEN>0,$D(@(ROOT_"""AEXC"","""_ICDU_" "","_+IEN_")")) D
. S ERR="-1~IEN "_+IEN_" is excluded from lookup"
Q:+ERR<0 ERR Q (IEN_"~"_ROOT)
CODE(FILE,IEN) ; Replaces Direct Global Read of Code
;
; Input:
;
; IEN Internal Entry Number (required)
; FILE File Number 80 or 80.1 (required)
;
; Output:
;
; $$CODE An ICD Diagnosis or Procedure code
;
; or -1 ^ message on error
;
; Retire IA 280, 365, 582, 5388, 5404
;
N ICDC,ICDF,ICDI,ICDR,ICDE S ICDI=$G(IEN) Q:+ICDI'>0 "-1^Invalid IEN"
S ICDF=$G(FILE) Q:"^80^80.1^"'[("^"_ICDF_"^") "-1^Invalid File"
S ICDR=$$ROOT^ICDEX(ICDF) Q:'$L(ICDR) "-1^Invalid File Root"
Q:'$D(@(ICDR_+ICDI_")")) "-1^Invalid IEN for File"
S ICDC=$P($G(@(ICDR_+ICDI_",0)")),"^",1)
Q $S($L(ICDC):ICDC,1:"-1^Code Not Found")
CODEBA(CODE,ROOT) ; Return IEN based on Code and Root
;
; Input:
;
; CODE ICD Code, either ICD-9 or ICD-10 (required)
; ROOT File Root or Number (required)
; ^ICD9( or 80
; ^ICD0( or 80.1
;
; Output:
;
; IEN IEN for CODE in ROOT or -1 if not found
;
Q:'$L($G(CODE)) -1 S:$TR($G(ROOT),".","")?1N.N ROOT=$$ROOT^ICDEX(ROOT) Q:'$L($G(ROOT)) -1
N IEN,OUT,FILE,TMP,ICDU,VIEN,EIEN S IEN=0,OUT="",FILE=$$FILE^ICDEX(ROOT) Q:+FILE'>0 -1
S ICDU=$$UP^XLFSTR(CODE) S EIEN=$O(@(ROOT_"""AEXC"","""_ICDU_" "",0)"))
S VIEN=$O(@(ROOT_"""AVA"","""_ICDU_" "",0)"))
I +IEN'>0,CODE?1N.N,$L(ROOT) D
. I $D(ICDVP) S:$D(@(ROOT_+CODE_",0)")) (IEN,OUT)=+CODE N ICDVP
I IEN'>0 S OUT="",IEN=0 F TMP=CODE,ICDU D
. S IEN=0 F S IEN=$O(@(ROOT_"""BA"","""_TMP_" "","_IEN_")")) Q:+IEN'>0 Q:+OUT>0 D
. . N EXC S EXC=$$EXC^ICDEX(FILE,IEN) S:+EXC'>0 OUT=IEN
S IEN=+($G(OUT))
I +IEN>0,$D(@(ROOT_"""AEXC"","""_ICDU_" "","_+IEN_")")) Q ("-1^IEN "_+EIEN_" is excluded from lookup")
I +IEN'>0,+EIEN>0 Q ("-1^Code "_ICDU_", IEN "_+EIEN_" is excluded from lookup")
I +IEN'>0,+VIEN>0 Q ("-1^Code "_ICDU_", IEN "_+VIEN_" is a VA local code, not used")
Q $S('IEN:-1,1:IEN)
CODEABA(CODE,ROOT,SYS) ; Return IEN based on Code, Root and Coding System
;
; Input:
;
; CODE ICD Code, either ICD-9 or ICD-10 (required)
; ROOT File Root or Number (Optional if SYS is supplied)
; ^ICD9( or 80
; ^ICD0( or 80.1
; SYS Coding System (required)
; 1 = ICD-9 Diagnosis
; 2 = ICD-9 Procedure
; 30 = ICD-10 Diagnosis
; 31 = ICD-10 Procedure
;
; Output:
;
; IEN IEN for CODE in ROOT for SYS
; or
; -1 ^ error message if not found
;
N IEN,ICDF,ICDR,ICDI,ICDS,ICDU,ICDE,ICDV S CODE=$TR($G(CODE)," ","")
Q:'$L(CODE) "-1^Code missing" Q:CODE["""" "-1^Invalid code"
S (ICDS,SYS)=+($G(SYS)),ICDU=$$UP^XLFSTR(CODE)
I ICDS'>0 D
. N ICDF S ICDF=$$CODEFI^ICDEX(CODE),(ICDS,SYS)=$P($$CODECS^ICDEX(CODE,ICDF),"^",1)
Q:+ICDS'>0 "-1^Invalid coding system"
S ICDR="" S ICDR=$$ROOT^ICDEX($G(ROOT))
S:'$L(ICDR) ICDR=$$ROOT^ICDEX(+($G(SYS)))
S:'$L(ICDR) ICDR=$$ROOT^ICDEX(+($G(ICDS)))
Q:'$L(ICDR) "-1^Invalid file/root"
S ICDE=$O(@(ICDR_"""AEXC"","""_ICDU_" "",0)"))
S ICDV=$O(@(ICDR_"""AVA"","""_ICDU_" "",0)"))
S:+($G(IEN))'>0 IEN=$O(@(ICDR_"""ABA"","_+ICDS_","""_CODE_" "","" "")"),-1)
S:+($G(IEN))'>0 IEN=$O(@(ICDR_"""ABA"","_+ICDS_","""_ICDU_" "","" "")"),-1)
I IEN'>0,+ICDE>0 Q ("-1^IEN "_+ICDE_" is excluded from lookup")
I IEN'>0,+ICDV>0 Q ("-1^CODE "_ICDU_", IEN "_+ICDE_" is a VA local code, not used")
Q $S('IEN:"-1^IEN/Code not found",1:IEN)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HICDEXC 13441 printed Dec 13, 2024@01:50:32 Page 2
ICDEXC ;SLC/KER - ICD Extractor - Code APIs ;12/19/2014
+1 ;;18.0;DRG Grouper;**57,67**;Oct 20, 2000;Build 1
+2 ;
+3 ; Global Variables
+4 ; None
+5 ;
+6 ; External References
+7 ; $$DT^XLFDT ICR 10103
+8 ; $$UP^XLFSTR ICR 10104
+9 ;
ICDDX(CODE,CDT,SYS,FMT,LOC) ; Return ICD Dx Code Info
+1 ;
+2 ; Input:
+3 ;
+4 ; CODE Code/IEN (required)
+5 ; CDT Date (default = TODAY)
+6 ; SYS Coding System (taken from file 80.4)
+7 ; 1 = ICD-9 Diagnosis
+8 ; 30 = ICD-10 Diagnosis
+9 ; FMT Format
+10 ; E = External (default)
+11 ; I = Internal Entry Number
+12 ; LOC Use Local codes
+13 ; 1 = Yes
+14 ; 0 = No (default)
+15 ;
+16 ; Output:
+17 ;
+18 ; Returns an 22 piece string delimited by ^
+19 ;
+20 ; 1 IEN of code in ^ICD9(
+21 ; 2 ICD-9 Dx Code (#.01)
+22 ; 3 Identifier (#1.2)
+23 ; 4 Versioned Dx (67 multiple)
+24 ; 5 Unacceptable as Principal Dx (#1.3)
+25 ; 6 Major Dx Cat (72 multiple)
+26 ; 7 MDC13 (#1.4)
+27 ; 8 Compl/Comorb (103 multiple)
+28 ; 9 ICD Expanded (#1.7)
+29 ; 10 Status (66 multiple)
+30 ; 11 Sex (10 multiple)
+31 ; 12 Inactive Date (66 multiple)
+32 ; 13 MDC24 (#1.5)
+33 ; 14 MDC25 (#1.6)
+34 ; 15 Age Low (11 multiple)
+35 ; 16 Age High (12 multiple)
+36 ; 17 Activation Date (66 multiple)
+37 ; 18 Message
+38 ; 19 Complication/Comorbidity (103 multiple)
+39 ; 20 Coding System (#1.1)
+40 ; 21 Primary CC Flag (103 multiple)
+41 ; 22 PDX Exclusion Code (#1.11)
+42 ;
+43 ; or
+44 ;
+45 ; -1^Error Description
+46 ;
+47 NEW IEN,NODE,OUT,SAI,ROOT,SNAM,ICDY,UPC
SET FMT=$GET(FMT)
if '$LENGTH(FMT)
SET FMT="E"
+48 SET ROOT=$$ROOT^ICDEX(80)
SET CODE=$GET(CODE)
if '$LENGTH(CODE)
QUIT "-1^No Code Selected"
+49 if FMT="I"&(CODE'?1N.N)
QUIT "-1^Code not in correct format"
+50 IF FMT="I"
IF CODE?1N.N
SET IEN=CODE
SET CODE=$PIECE($GET(^ICD9(IEN,0)),"^",1)
+51 if '$LENGTH(CODE)
QUIT "-1^No Code Selected"
SET SYS=$$SYS^ICDEX(+($GET(SYS)))
+52 SET UPC=$$UP^XLFSTR(CODE)
if +SYS'>0
SET SYS=$$SYS^ICDEX($GET(UPC))
IF +SYS'>0
Begin DoDot:1
+53 NEW FILE
SET FILE=$$CODEFI^ICDEX(UPC)
SET SYS=$PIECE($$CODECS^ICDEX(UPC,FILE),"^",1)
End DoDot:1
+54 if +SYS>0&('$DATA(@(ROOT_"""ABA"","_+SYS_")")))
QUIT "-1^Invalid Coding System"
+55 SET SNAM=$$SNAM^ICDEX(+SYS)
SET LOC=+($GET(LOC))
+56 SET IEN=$SELECT(+SYS>0:$$CODEABA(CODE,ROOT,SYS),1:$$CODEBA(CODE,ROOT))
+57 if +IEN'>0
SET IEN=$SELECT(+SYS>0:$$CODEABA(UPC,ROOT,SYS),1:$$CODEBA(UPC,ROOT))
+58 if +IEN'>0&($GET(LOC)>0)&($DATA(^ICD9("AVA",(CODE_" "))))
SET IEN=$ORDER(^ICD9("AVA",(CODE_" "),0))
+59 if '$GET(LOC)&($DATA(^ICD9("AVA",(CODE_" "))))
QUIT ("-1^VA Local Code ("_CODE_")")
+60 if IEN<1&(+SYS>0)&($LENGTH(SNAM))&('$DATA(^ICD9("AVA",(CODE_" "))))
QUIT ("-1^Invalid Code (not found in the "_SNAM_" system)")
+61 if IEN<1
QUIT "-1^Invalid Code"
if '$DATA(^ICD9(IEN,0))
QUIT "-1^Invalid Code (not found)"
+62 SET ICDY=$PIECE($GET(^ICD9(IEN,1)),"^",1)
if +ICDY'>0
QUIT "-1^Invalid Coding System"
+63 SET CDT=$PIECE($GET(CDT),".",1)
if '$LENGTH($GET(CDT))
SET CDT=$$DT^XLFDT
+64 SET CDT=$$DTBR^ICDEX($GET(CDT),,ICDY)
if CDT'?7N
QUIT "-1^No Date Provided"
+65 SET NODE=$PIECE($GET(^ICD9(IEN,0)),"^",1)
if '$LENGTH(NODE)
QUIT "-1^Code not found"
+66 if '$GET(LOC)&($LENGTH(NODE))&($PIECE(^ICD9(IEN,1),U,7))
QUIT ("-1^VA Local Code ("_NODE_")")
+67 SET OUT=IEN_"^"_NODE
SET SAI=$$SAI^ICDEX(80,IEN,CDT)
+68 SET NODE=$GET(^ICD9(IEN,1))
if '$LENGTH(NODE)
QUIT "-1^Data not found"
+69 SET $PIECE(OUT,"^",3)=$$IDSTR^ICDEX(80,IEN)
+70 SET $PIECE(OUT,"^",4)=$$VSTD^ICDEX(IEN,CDT)
+71 SET $PIECE(OUT,"^",5)=$PIECE(NODE,"^",3)
+72 SET $PIECE(OUT,"^",6)=$$VMDC^ICDEX(IEN,CDT)
+73 SET $PIECE(OUT,"^",7)=$PIECE(NODE,"^",4)
+74 SET $PIECE(OUT,"^",8)=$$VCC^ICDEX(IEN,CDT)
+75 if $PIECE(NODE,"^",7)>0
SET $PIECE(OUT,"^",9)=$PIECE(NODE,"^",7)
+76 SET $PIECE(OUT,"^",10)=$SELECT(+$PIECE($GET(SAI),"^",1)>0:1,1:0)
+77 SET $PIECE(OUT,"^",11)=$$VSEX^ICDEX(80,IEN,CDT)
+78 SET $PIECE(OUT,"^",12)=$SELECT($PIECE($GET(SAI),"^",3)?7N:$PIECE($GET(SAI),"^",3),1:"")
+79 SET $PIECE(OUT,"^",13)=$PIECE(NODE,"^",5)
+80 SET $PIECE(OUT,"^",14)=$PIECE(NODE,"^",6)
+81 SET $PIECE(OUT,"^",15)=$$VAGEL^ICDEX(IEN,CDT)
+82 SET $PIECE(OUT,"^",16)=$$VAGEH^ICDEX(IEN,CDT)
+83 SET $PIECE(OUT,"^",17)=$SELECT($PIECE($GET(SAI),"^",2)?7N:$PIECE($GET(SAI),"^",2),1:"")
+84 SET $PIECE(OUT,"^",18)=$$MSG^ICDEX(CDT)
+85 SET $PIECE(OUT,"^",19)=$$VCC^ICDEX(IEN,CDT)
+86 if +($GET(^ICD9(+IEN,1)))>0
SET $PIECE(OUT,"^",20)=+($GET(^ICD9(+IEN,1)))
+87 SET $PIECE(OUT,"^",21)=$$VCCP^ICDEX(IEN,CDT)
+88 SET $PIECE(OUT,"^",22)=$$PDXE^ICDEX(IEN)
+89 QUIT OUT
+90 ;
ICDOP(CODE,CDT,SYS,FMT,LOC) ; Return ICD Operation/Procedure Code Info
+1 ;
+2 ; Input:
+3 ;
+4 ; CODE Code/IEN (required)
+5 ; CDT Date (default = TODAY)
+6 ; SYS Coding System (taken from file 757.03)
+7 ; 2 = ICD-9 Procedure
+8 ; 31 = ICD-10 Procedure
+9 ; FMT Format
+10 ; E = External (default)
+11 ; I = Internal Entry Number
+12 ; LOC Use Local codes
+13 ; 1 = Yes
+14 ; 0 = No (default)
+15 ;
+16 ; Output:
+17 ;
+18 ; Returns an 14 piece string delimited by ^
+19 ;
+20 ; 1 IEN of code in ^ICD0(
+21 ; 2 ICD procedure code (#.01)
+22 ; 3 Identifier (#1.2)
+23 ; 4 MDC24 (#1.5)
+24 ; 5 Versioned Oper/Proc (67 multiple)
+25 ; 6 <null>
+26 ; 7 <null>
+27 ; 8 <null>
+28 ; 9 ICD Expanded (#1.7)
+29 ; 10 Status (66 multiple)
+30 ; 11 Use with Sex (10 multiple)
+31 ; 12 Inactive Date (66 multiple)
+32 ; 13 Activation Date (66 multiple)
+33 ; 14 Message
+34 ; 15 Coding System (#1.1)
+35 ;
+36 ; or
+37 ;
+38 ; -1^Error Description
+39 ;
+40 NEW IEN,NODE,OUT,ROOT,SNAM,SAI,ICDY
SET FMT=$GET(FMT)
if '$LENGTH(FMT)
SET FMT="E"
+41 SET ROOT=$$ROOT^ICDEX(80.1)
SET CODE=$GET(CODE)
if '$LENGTH(CODE)
QUIT "-1^No Code Selected"
+42 if FMT="I"&(CODE'?1N.N)
QUIT "-1^Code not in correct format"
+43 IF FMT="I"
IF CODE?1N.N
SET IEN=CODE
SET CODE=$PIECE($GET(^ICD0(+IEN,0)),"^",1)
SET FMT="E"
+44 if '$LENGTH(CODE)
QUIT "-1^No Code Selected"
+45 SET SYS=$$SYS^ICDEX(+($GET(SYS)))
SET LOC=+($GET(LOC))
IF +SYS'>0
Begin DoDot:1
+46 NEW FILE
SET FILE=$$CODEFI^ICDEX(CODE)
SET SYS=$PIECE($$CODECS^ICDEX(CODE,FILE),"^",1)
End DoDot:1
+47 if +SYS>0&('$DATA(@(ROOT_"""ABA"","_+SYS_")")))
QUIT "-1^Invalid Coding System"
+48 SET SNAM=$$SNAM^ICDEX(+SYS)
SET IEN=$SELECT(+SYS>0:$$CODEABA(CODE,ROOT,SYS),1:$$CODEBA(CODE,ROOT))
+49 if +IEN'>0&(+($GET(LOC))>0)&($DATA(^ICD0("AVA",(CODE_" "))))
SET IEN=$ORDER(^ICD0("AVA",(CODE_" "),0))
+50 if '$GET(LOC)&($DATA(^ICD0("AVA",(CODE_" "))))
QUIT ("-1^VA Local Code ("_CODE_")")
+51 if IEN<1&(+SYS>0)&($LENGTH(SNAM))
QUIT ("-1^Invalid Code (not found in the "_SNAM_" system)")
+52 if IEN<1
QUIT "-1^Invalid Code"
if '$DATA(^ICD0(IEN,0))
QUIT "-1^Invalid Code (not found)"
+53 SET ICDY=$PIECE($GET(^ICD0(IEN,1)),"^",1)
if +ICDY'>0
QUIT "-1^Invalid Coding System"
+54 SET CDT=$PIECE($GET(CDT),".",1)
if '$LENGTH($GET(CDT))
SET CDT=$$DT^XLFDT
+55 SET CDT=$$DTBR^ICDEX($GET(CDT),,ICDY)
if CDT'?7N
QUIT "-1^No Date Provided"
+56 SET NODE=$PIECE($GET(^ICD0(+IEN,0)),"^",1)
if '$LENGTH(NODE)
QUIT "-1^Code not found"
+57 if '$GET(LOC)&($PIECE(^ICD0(IEN,1),U,7))
QUIT ("-1^VA Local Code Selected ("_NODE_")")
+58 SET OUT=IEN_"^"_NODE
SET SAI=$$SAI^ICDEX(80.1,IEN,CDT)
+59 SET NODE=$GET(^ICD0(IEN,1))
if '$LENGTH(NODE)
QUIT "-1^Data not found"
+60 SET $PIECE(OUT,"^",3)=$$IDSTR^ICDEX(80.1,IEN)
+61 SET $PIECE(OUT,"^",4)=$PIECE(NODE,"^",5)
+62 SET $PIECE(OUT,"^",5)=$$VSTP^ICDEX(IEN,CDT)
+63 if $PIECE(NODE,"^",7)>0
SET $PIECE(OUT,"^",9)=$PIECE(NODE,"^",7)
+64 SET $PIECE(OUT,"^",10)=$SELECT(+$PIECE($GET(SAI),"^",1)>0:1,1:0)
+65 SET $PIECE(OUT,"^",11)=$$VSEX^ICDEX(80.1,IEN,CDT)
+66 SET $PIECE(OUT,"^",12)=$SELECT($PIECE($GET(SAI),"^",3)?7N:$PIECE($GET(SAI),"^",3),1:"")
+67 SET $PIECE(OUT,"^",13)=$SELECT($PIECE($GET(SAI),"^",2)?7N:$PIECE($GET(SAI),"^",2),1:"")
+68 SET $PIECE(OUT,"^",14)=$$MSG^ICDEX(CDT)
+69 if +($GET(^ICD0(+IEN,1)))>0
SET $PIECE(OUT,"^",15)=+($GET(^ICD0(+IEN,1)))
+70 QUIT OUT
ICDD(CODE,ARY,CDT,SYS,LEN) ; Returns ICD description in array
+1 ;
+2 ; Input:
+3 ;
+4 ; CODE Code, external format (required)
+5 ; ARY Array Name passed by reference (required)
+6 ; CDT Date (optional, default = TODAY)
+7 ; SYS Coding System (optional)
+8 ; LEN Sting Length (optional, > 27, default 245)
+9 ;
+10 ; Output:
+11 ;
+12 ; # Number of lines in array
+13 ;
+14 ; ARY(1) - Versioned Description (68 multiple)
+15 ;
+16 ; If there is a warning message (ICD-9 only):
+17 ;
+18 ; ARY(n+1) - blank
+19 ; ARY(n+2) - warning message: CODE TEXT MAY BE INACCURATE
+20 ;
+21 ; or
+22 ;
+23 ; -1^Error Description
+24 ;
+25 ;
+26 NEW ARR,END,I,N,ROOT,SNAM,VAR,IEN,ICDY
+27 if '$LENGTH($GET(CODE))
QUIT "-1^Missing required input parameter CODE"
+28 SET SYS=$$SYS^ICDEX(+($GET(SYS)))
IF +SYS'>0
Begin DoDot:1
+29 NEW FILE
SET FILE=$$CODEFI^ICDEX(CODE)
SET SYS=$PIECE($$CODECS^ICDEX(CODE,FILE),"^",1)
End DoDot:1
+30 SET ROOT=$$ROOT^ICDEX(+SYS)
+31 if "^ICD9(^ICD0(^"'[("^"_$EXTRACT(ROOT,2,$LENGTH(ROOT))_"^")!('$LENGTH(ROOT))
QUIT "-1^Invalid Coding System"
+32 if +SYS>0&('$DATA(@(ROOT_"""ABA"","_+SYS_")")))
QUIT "-1^Invalid Coding System"
+33 SET SNAM=$$SNAM^ICDEX(+SYS)
SET IEN=$SELECT(+SYS>0:$$CODEABA(CODE,ROOT,SYS),1:$$CODEBA(CODE,ROOT))
+34 if +IEN<1!('$LENGTH(ROOT))
QUIT "-1^Invalid Code"
if '$DATA(@(ROOT_IEN_",0)"))
QUIT "-1^Code not found"
+35 SET LEN=+($GET(LEN))
if LEN'>0
SET LEN=245
if LEN<28
SET LEN=245
KILL ARY
+36 SET ICDY=$PIECE($GET(@(ROOT_+IEN_",1)")),"^",1)
+37 if +ICDY'>0
QUIT "-1^Invalid Coding System"
+38 SET I=0
SET N=0
+39 SET CDT=$PIECE($GET(CDT),".",1)
if '$LENGTH($GET(CDT))
SET CDT=$$DT^XLFDT
+40 SET CDT=$$DTBR^ICDEX($GET(CDT),,ICDY)
if CDT'?7N
QUIT "-1^No Date Provided"
+41 SET ARY(1)=$$VLT^ICDEX(ROOT,IEN,CDT)
+42 IF LEN>27
IF LEN<245
DO PAR^ICDEX(.ARY,LEN)
+43 SET N=$ORDER(ARY(" "),-1)
IF +ICDY<3
Begin DoDot:1
+44 NEW MSG
SET MSG=$$MSG^ICDEX(CDT)
if '$LENGTH(MSG)
QUIT
SET ARY(N+1)=" "
SET ARY(N+2)=MSG
End DoDot:1
+45 SET N=+($ORDER(ARY(" "),-1))
+46 QUIT N
CODEN(CODE,FILE) ; Return IEN of ICD code
+1 ;
+2 ; Input:
+3 ;
+4 ; CODE ICD code (required)
+5 ; FILE File Number to search for code
+6 ; 80 = ICD Dx file
+7 ; 80.1 = ICD Oper/Proc file
+8 ;
+9 ; Output:
+10 ;
+11 ; IEN~Global Root or -1~error message
+12 ;
+13 NEW ROOT,IEN,ERR,EIEN,ICDU
SET ERR=""
+14 if $GET(CODE)=""
QUIT "-1~Missing required input parameter CODE"
+15 SET CODE=$TRANSLATE(CODE," ","")
SET ICDU=$$UP^XLFSTR(CODE)
+16 if "^80^80.1^"'[("^"_$GET(FILE)_"^")
SET FILE=$$CODEFI^ICDEX(CODE)
+17 SET ROOT=$$ROOT^ICDEX($GET(FILE))
if '$LENGTH(ROOT)
QUIT "-1~Invalid File"
+18 SET IEN=$$CODEBA(CODE,ROOT)
if +IEN'>0
SET ERR="-1~Invalid or Code not found"
+19 IF $DATA(ICDVP)
IF CODE?1N.N
IF +ERR<0
IF $LENGTH(ROOT)
if $DATA(@(ROOT_+CODE_",0)"))
SET IEN=+CODE
SET ERR=""
NEW ICDVP
+20 IF +IEN>0
IF $DATA(@(ROOT_"""AEXC"","""_ICDU_" "","_+IEN_")"))
Begin DoDot:1
+21 SET ERR="-1~IEN "_+IEN_" is excluded from lookup"
End DoDot:1
+22 if +ERR<0
QUIT ERR
QUIT (IEN_"~"_ROOT)
CODE(FILE,IEN) ; Replaces Direct Global Read of Code
+1 ;
+2 ; Input:
+3 ;
+4 ; IEN Internal Entry Number (required)
+5 ; FILE File Number 80 or 80.1 (required)
+6 ;
+7 ; Output:
+8 ;
+9 ; $$CODE An ICD Diagnosis or Procedure code
+10 ;
+11 ; or -1 ^ message on error
+12 ;
+13 ; Retire IA 280, 365, 582, 5388, 5404
+14 ;
+15 NEW ICDC,ICDF,ICDI,ICDR,ICDE
SET ICDI=$GET(IEN)
if +ICDI'>0
QUIT "-1^Invalid IEN"
+16 SET ICDF=$GET(FILE)
if "^80^80.1^"'[("^"_ICDF_"^")
QUIT "-1^Invalid File"
+17 SET ICDR=$$ROOT^ICDEX(ICDF)
if '$LENGTH(ICDR)
QUIT "-1^Invalid File Root"
+18 if '$DATA(@(ICDR_+ICDI_")"))
QUIT "-1^Invalid IEN for File"
+19 SET ICDC=$PIECE($GET(@(ICDR_+ICDI_",0)")),"^",1)
+20 QUIT $SELECT($LENGTH(ICDC):ICDC,1:"-1^Code Not Found")
CODEBA(CODE,ROOT) ; Return IEN based on Code and Root
+1 ;
+2 ; Input:
+3 ;
+4 ; CODE ICD Code, either ICD-9 or ICD-10 (required)
+5 ; ROOT File Root or Number (required)
+6 ; ^ICD9( or 80
+7 ; ^ICD0( or 80.1
+8 ;
+9 ; Output:
+10 ;
+11 ; IEN IEN for CODE in ROOT or -1 if not found
+12 ;
+13 if '$LENGTH($GET(CODE))
QUIT -1
if $TRANSLATE($GET(ROOT),".","")?1N.N
SET ROOT=$$ROOT^ICDEX(ROOT)
if '$LENGTH($GET(ROOT))
QUIT -1
+14 NEW IEN,OUT,FILE,TMP,ICDU,VIEN,EIEN
SET IEN=0
SET OUT=""
SET FILE=$$FILE^ICDEX(ROOT)
if +FILE'>0
QUIT -1
+15 SET ICDU=$$UP^XLFSTR(CODE)
SET EIEN=$ORDER(@(ROOT_"""AEXC"","""_ICDU_" "",0)"))
+16 SET VIEN=$ORDER(@(ROOT_"""AVA"","""_ICDU_" "",0)"))
+17 IF +IEN'>0
IF CODE?1N.N
IF $LENGTH(ROOT)
Begin DoDot:1
+18 IF $DATA(ICDVP)
if $DATA(@(ROOT_+CODE_",0)"))
SET (IEN,OUT)=+CODE
NEW ICDVP
End DoDot:1
+19 IF IEN'>0
SET OUT=""
SET IEN=0
FOR TMP=CODE,ICDU
Begin DoDot:1
+20 SET IEN=0
FOR
SET IEN=$ORDER(@(ROOT_"""BA"","""_TMP_" "","_IEN_")"))
if +IEN'>0
QUIT
if +OUT>0
QUIT
Begin DoDot:2
+21 NEW EXC
SET EXC=$$EXC^ICDEX(FILE,IEN)
if +EXC'>0
SET OUT=IEN
End DoDot:2
End DoDot:1
+22 SET IEN=+($GET(OUT))
+23 IF +IEN>0
IF $DATA(@(ROOT_"""AEXC"","""_ICDU_" "","_+IEN_")"))
QUIT ("-1^IEN "_+EIEN_" is excluded from lookup")
+24 IF +IEN'>0
IF +EIEN>0
QUIT ("-1^Code "_ICDU_", IEN "_+EIEN_" is excluded from lookup")
+25 IF +IEN'>0
IF +VIEN>0
QUIT ("-1^Code "_ICDU_", IEN "_+VIEN_" is a VA local code, not used")
+26 QUIT $SELECT('IEN:-1,1:IEN)
CODEABA(CODE,ROOT,SYS) ; Return IEN based on Code, Root and Coding System
+1 ;
+2 ; Input:
+3 ;
+4 ; CODE ICD Code, either ICD-9 or ICD-10 (required)
+5 ; ROOT File Root or Number (Optional if SYS is supplied)
+6 ; ^ICD9( or 80
+7 ; ^ICD0( or 80.1
+8 ; SYS Coding System (required)
+9 ; 1 = ICD-9 Diagnosis
+10 ; 2 = ICD-9 Procedure
+11 ; 30 = ICD-10 Diagnosis
+12 ; 31 = ICD-10 Procedure
+13 ;
+14 ; Output:
+15 ;
+16 ; IEN IEN for CODE in ROOT for SYS
+17 ; or
+18 ; -1 ^ error message if not found
+19 ;
+20 NEW IEN,ICDF,ICDR,ICDI,ICDS,ICDU,ICDE,ICDV
SET CODE=$TRANSLATE($GET(CODE)," ","")
+21 if '$LENGTH(CODE)
QUIT "-1^Code missing"
if CODE[""""
QUIT "-1^Invalid code"
+22 SET (ICDS,SYS)=+($GET(SYS))
SET ICDU=$$UP^XLFSTR(CODE)
+23 IF ICDS'>0
Begin DoDot:1
+24 NEW ICDF
SET ICDF=$$CODEFI^ICDEX(CODE)
SET (ICDS,SYS)=$PIECE($$CODECS^ICDEX(CODE,ICDF),"^",1)
End DoDot:1
+25 if +ICDS'>0
QUIT "-1^Invalid coding system"
+26 SET ICDR=""
SET ICDR=$$ROOT^ICDEX($GET(ROOT))
+27 if '$LENGTH(ICDR)
SET ICDR=$$ROOT^ICDEX(+($GET(SYS)))
+28 if '$LENGTH(ICDR)
SET ICDR=$$ROOT^ICDEX(+($GET(ICDS)))
+29 if '$LENGTH(ICDR)
QUIT "-1^Invalid file/root"
+30 SET ICDE=$ORDER(@(ICDR_"""AEXC"","""_ICDU_" "",0)"))
+31 SET ICDV=$ORDER(@(ICDR_"""AVA"","""_ICDU_" "",0)"))
+32 if +($GET(IEN))'>0
SET IEN=$ORDER(@(ICDR_"""ABA"","_+ICDS_","""_CODE_" "","" "")"),-1)
+33 if +($GET(IEN))'>0
SET IEN=$ORDER(@(ICDR_"""ABA"","_+ICDS_","""_ICDU_" "","" "")"),-1)
+34 IF IEN'>0
IF +ICDE>0
QUIT ("-1^IEN "_+ICDE_" is excluded from lookup")
+35 IF IEN'>0
IF +ICDV>0
QUIT ("-1^CODE "_ICDU_", IEN "_+ICDE_" is a VA local code, not used")
+36 QUIT $SELECT('IEN:"-1^IEN/Code not found",1:IEN)