LEXQCM2 ;ISL/KER - Query - CPT Modifiers - Save ;04/21/2014
;;2.0;LEXICON UTILITY;**62,80**;Sep 23, 1996;Build 10
;
; Global Variables
; ^DIC(81.3, ICR 4492
; ^TMP("LEXQCM" SACC 2.3.2.5.1
; ^TMP("LEXQCMO" SACC 2.3.2.5.1
;
; External References
; $$DT^XLFDT ICR 10103
; $$UP^XLFSTR ICR 10104
;
; Variables NEWed or KILLed Elsewhere
; LEXIEN Modifier IEN
; LEXELDT External Last Date
; LEXLEN Offset Length
; LEXINC Include Modifier Ranges flag
; LEXINCI Include Inactive Modifier Ranges flag
; LEXINCF Include Future Modifier Ranges flag
; LEXGET Array of Non-Versioned Data
; LEXST CPT Status and Effective Dates
; LEXSD Versioned Short Description
; LEXLD Versioned Long Description
; LEXRAN Number of Ranges/Comment
; ^TMP("LEXQCM",$J,"RANGES",#) List of Ranges
;
EN ; Main Entry Point
;
K ^TMP("LEXQCMO",$J) Q:'$L($G(LEXELDT))
I +($G(LEXST))<0 D FUT D:$D(^TMP("LEXQCMO",$J)) DSP^LEXQO("LEXQCMO") Q
D FUL D:$D(^TMP("LEXQCMO",$J)) DSP^LEXQO("LEXQCMO")
Q
FUT ; Future Activation
N LEX1,LEX2,LEX3,LEXEFF,LEXI,LEXL,LEXNAM,LEXSO,LEXSTA S LEXI=+($G(LEXIEN)) Q:+LEXI'>0 Q:'$D(^DIC(81.3,+LEXI,0)) S LEXL=+($G(LEXLEN)) Q:+LEXL'>0
S:LEXL>62 LEXL=62 S LEXSO=$G(LEXGET(81.3,(+LEXI_","),.01,"E")) Q:'$L(LEXSO) S LEXNAM=$G(LEXGET(81.3,(+LEXI_","),"B")) Q:'$L(LEXNAM)
S LEXSTA=$G(LEXST),LEXEFF=$P(LEXSTA,"^",5),LEXSTA=$P(LEXSTA,"^",4) Q:'$L(LEXSTA) Q:'$L(LEXEFF) S (LEX1,LEX2,LEX3)=""
D BOD(LEXELDT),COD(LEXSO,LEXNAM,+($G(LEXL))),STA(.LEXST,+($G(LEXL)))
Q
BOD(X) ; Based on Date
N LEXBOD S LEXBOD=$G(X) Q:'$L(LEXBOD) Q:LEXBOD'["/" S X="Display based on date: "_LEXBOD D BL,TL(X)
Q
COD(X,Y,LEXLEN) ; Code Line
N LEXC,LEXN,LEXT S LEXC=$G(X),LEXN=$G(Y) S LEXT="Code: "_LEXC,LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXN D BL,TL(LEXT)
Q
STA(X,LEXLEN) ; Status Line
N LEX,LEXC,LEXI,LEXN,LEXX,LEXE,LEXS,LEXT,LEXW,LEXEFF,LEXSTA S LEXX=$G(X),LEXEFF=$P(LEXX,"^",5),LEXSTA=$P(LEXX,"^",4),LEXEFF=$TR(LEXEFF,"()","")
S LEXW=$P(LEXX,"^",6),LEXT=" Status: ",LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT))),LEXT=LEXT_LEXSTA
S LEXT=LEXT_$J(" ",(35-$L(LEXT)))
S:LEXEFF'["future" LEXT=LEXT_"Effective: "
S LEXT=LEXT_$$UP^XLFSTR($E(LEXEFF,1))_$E(LEXEFF,2,$L(LEXEFF)) D BL,TL(LEXT)
I $L(LEXW) D
. N LEX,LEXT,LEXC,LEXI,LEXN S LEX(1)=LEXW D PR^LEXQM(.LEX,(+($G(LEXLEN))-7)) Q:+($O(LEX(" "),-1))'>0
. S LEXT=$J(" ",((79-+($G(LEXLEN)))))
. S (LEXC,LEXI)=0 F S LEXI=$O(LEX(LEXI)) Q:+LEXI'>0 D
. . N LEXN S LEXN=$$TM^LEXQM($G(LEX(LEXI))) S:$L(LEXN) LEXC=LEXC+1 D:LEXC=1 BL D TL((LEXT_LEXN))
Q
;
FUL ; Full Display
N LEXFUL,LEX,LEXL S LEXL=+($G(LEXLEN)) S:LEXL>62 LEXL=62
S LEXFUL="" D FUT
D SD(.LEXSD,+($G(LEXL))),LD(.LEXLD,+($G(LEXL))),WN(.LEXWN,+($G(LEXL)))
D:+($G(LEXRAN))>0&($L($P($G(LEXRAN),"^",2)))&($O(^TMP("LEXQCM",$J,"RANGES",0))>0) RAN(.LEXRAN,+($G(LEXL)))
Q
SD(X,LEXLEN) ; Short Description
N LEXI,LEXH,LEXE,LEXN,LEXT Q:'$D(X(1)) S LEXN=$G(X(1)),LEXT=" Short Name: ",LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXN D BL,TL(LEXT)
S LEXE=$G(X(0)),LEXT=" "_LEXE,LEXN=$G(X(2)),LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXN D TL(LEXT)
Q
LD(X,LEXLEN) ; Long Description
N LEXI,LEXH,LEXE,LEXN,LEXT Q:'$D(X(1)) S LEXN=$G(X(1)),LEXT=" Description: ",LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXN D BL,TL(LEXT)
S LEXE=$G(X(0)),LEXT=" "_LEXE,LEXN=$G(X(2)),LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXN D TL(LEXT)
S LEXT=$J(" ",((79-+($G(LEXLEN))))) S LEXI=2 F S LEXI=$O(X(LEXI)) Q:+LEXI'>0 S LEXN=LEXT_$G(X(LEXI)) D TL(LEXN)
Q
WN(X,LEXLEN) ; Warning
N LEXI,LEXH,LEXE,LEXN,LEXT,LEXC Q:'$D(X(1)) S LEXC=0,LEXN=$G(X(1)),LEXT="",LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXN D BL,TL(LEXT)
S LEXT=$J(" ",((79-+($G(LEXLEN))))),LEXI=1 F S LEXI=$O(X(LEXI)) Q:+LEXI'>0 S LEXN=LEXT_$G(X(LEXI)) D TL(LEXN)
Q
RAN(X,LEXLEN) ; Code Ranges
N LEXC,LEXH,LEXI,LEXN,LEXS,LEXT S LEXH=$G(X),LEXN=+LEXH,LEXH=$P(LEXH,"^",2) Q:+LEXN'>0 Q:'$L(LEXH)
S LEXT=" Code Ranges: ",LEXT=LEXT_$J(" ",((79-+($G(LEXLEN)))-$L(LEXT)))_LEXH,LEXN=$J(" ",((79-+($G(LEXLEN))))) D BL,TL(LEXT)
S (LEXC,LEXI)=0 F S LEXI=$O(^TMP("LEXQCM",$J,"RANGES",LEXI)) Q:+LEXI'>0 D
. S LEXC=LEXC+1 D:LEXC=1 BL S LEXT=$G(^TMP("LEXQCM",$J,"RANGES",LEXI)) Q:'$L(LEXT) D TL((LEXN_LEXT))
Q
CCR(X,LEXVDT,LEX,LEXLEN,LEXINCI,LEXINCF) ; CPT Code Ranges
;
; LEX=# of Ranges
; ^TMP("LEXQCM",$J,"RANGES",#)=Begin_End_Act_Inact
;
K ^TMP("LEXQCM",$J,"RAN"),^TMP("LEXQCM",$J,"RANGES")
N LEXC,LEXEVDT,LEXFD,LEXFN,LEXH1,LEXH2,LEXH3,LEXIEN,LEXL,LEXN,LEXP,LEXR0,LEXRA,LEXRA1,LEXRA2,LEXRB,LEXRDA,LEXRDI,LEXRE,LEXRI,LEXRI1,LEXRI2,LEXRN,LEXRT,LEXRX,LEXT
S LEXIEN=$G(X) Q:+LEXIEN'>0 Q:'$D(^DIC(81.3,+LEXIEN,0)) Q:$O(^DIC(81.3,+LEXIEN,10,0))'>0 S LEXVDT=+($G(LEXVDT)) S:LEXVDT'?7N LEXVDT=$$DT^XLFDT S LEXEVDT=$$SD^LEXQM(LEXVDT),LEXLEN=+($G(LEXLEN))
S:+LEXLEN'>0 LEXLEN=62 Q:'$L(LEXEVDT) S LEXINCI=+($G(LEXINCI)),LEXINCF=+($G(LEXINCF)) S (LEXFD,LEXRX)=0 F S LEXRX=$O(^DIC(81.3,+LEXIEN,10,LEXRX)) Q:+LEXRX'>0 D
. S LEXR0=$G(^DIC(81.3,+LEXIEN,10,LEXRX,0)),LEXRB=$P(LEXR0,"^",1) Q:$L(LEXRB)'=5 S LEXRE=$P(LEXR0,"^",2) S:$L(LEXRB)&('$L(LEXRE)) LEXRE=LEXRB Q:$L(LEXRE)'=5
. S LEXRA=$P(LEXR0,"^",3) Q:LEXRA'?7N S LEXRI=$P(LEXR0,"^",4) Q:+LEXRA>0&(LEXVDT<+($G(LEXRA)))&(+($G(LEXINCF))'>0) Q:+LEXRI>0&(LEXVDT>+($G(LEXRI)))&(+($G(LEXINCI))'>0)
. S LEXRN=$$NUM(LEXRB),LEXRT=LEXRB_"^"_LEXRE_"^"_LEXRA_"^"_LEXRI,LEXRA1=$S(LEXVDT<LEXRA:"<",1:" "),LEXRA2=$S(LEXVDT<LEXRA:">",1:" ")
. S LEXRI1=$S(LEXVDT<LEXRI:"<",1:" "),LEXRI2=$S(LEXVDT<LEXRI:">",1:" ") S:LEXRA1["<"!(LEXRA2[">")!(LEXRI1["<")!(LEXRI2[">") LEXFD=1
. S LEXRDA=$S($L(LEXRA):(LEXRA1_$$SD^LEXQM(LEXRA)_LEXRA2),1:""),LEXRDI=$S($L(LEXRI):(LEXRI1_$$SD^LEXQM(LEXRI)_LEXRI2),1:"")
. S ^TMP("LEXQCM",$J,"RAN",LEXRN,LEXRT)=LEXRB_" "_LEXRE_" "_LEXRDA_" "_LEXRDI
S LEXH1="CPT Code Range Effective Dates",LEXH2="Begin End Active Inactive",LEXH3="----- ----- ---------- ----------"
K LEX S (LEX,LEXL,LEXC,LEXRN)=0 S LEXFN="" S:+($G(LEXFD))>0 LEXFN=" Future dates indicated as '<mm/dd/yyyy>'"
S LEXC=0 F S LEXRN=$O(^TMP("LEXQCM",$J,"RAN",LEXRN)) Q:+LEXRN'>0 S LEXRT="" F S LEXRT=$O(^TMP("LEXQCM",$J,"RAN",LEXRN,LEXRT)) Q:'$L(LEXRT) D
. S LEXT=$G(^TMP("LEXQCM",$J,"RAN",LEXRN,LEXRT)) Q:'$L(LEXT) S LEXC=LEXC+1 I LEXC=1 D
. . S LEXN=$O(^TMP("LEXQCM",$J,"RANGES"," "),-1)+1,^TMP("LEXQCM",$J,"RANGES",LEXN)=LEXH1 S LEXN=$O(^TMP("LEXQCM",$J,"RANGES"," "),-1)+1,^TMP("LEXQCM",$J,"RANGES",LEXN)=LEXH2
. . S LEXN=$O(^TMP("LEXQCM",$J,"RANGES"," "),-1)+1,^TMP("LEXQCM",$J,"RANGES",LEXN)=LEXH3 S ^TMP("LEXQCM",$J,"RANGES",0)=LEXN
. S LEX=+($G(LEX))+1 S LEXN=$O(^TMP("LEXQCM",$J,"RANGES"," "),-1)+1,^TMP("LEXQCM",$J,"RANGES",LEXN)=LEXT,^TMP("LEXQCM",$J,"RANGES",0)=LEXN
I $L(LEXFN) D
. S LEXN=$O(^TMP("LEXQCM",$J,"RANGES"," "),-1)+1,^TMP("LEXQCM",$J,"RANGES",LEXN)=" ",^TMP("LEXQCM",$J,"RANGES",0)=LEXN
. S LEXN=$O(^TMP("LEXQCM",$J,"RANGES"," "),-1)+1,^TMP("LEXQCM",$J,"RANGES",LEXN)=LEXFN,^TMP("LEXQCM",$J,"RANGES",0)=LEXN
K ^TMP("LEXQCM",$J,"RAN") S LEXT="" I +LEX>0 D
. N LEXP,LEXT S LEXP=$S(+LEX>1:"s",1:""),LEXT="" S:+($G(LEXINCI))>0&(+($G(LEXINCF))>0) LEXT=+LEX_" Current and future Active or Inactive range"_LEXP_" found"
. S:+($G(LEXINCI))>0&(+($G(LEXINCF))'>0) LEXT=+LEX_" Currently Active or Inactive range"_LEXP_" found" S:+($G(LEXINCI))'>0&(+($G(LEXINCF))>0) LEXT=+LEX_" Current and future Active range"_LEXP_" found"
. S:+($G(LEXINCI))'>0&(+($G(LEXINCF))'>0) LEXT=+LEX_" Currently Active range"_LEXP_" found" S:$L(LEXT) LEX=LEX_"^"_LEXT
Q
;
; Miscellaneous
BL ; Blank Line
D TL(" ") Q
TL(X) ; Text Line
I $D(LEXTEST) W !,$G(X) Q
N LEXI S LEXI=+($O(^TMP("LEXQCMO",$J," "),-1))+1 S ^TMP("LEXQCMO",$J,LEXI)=$G(X),^TMP("LEXQCMO",$J,0)=LEXI
Q
NUM(X) ; Convert Code to Numeric
Q $S(X?1.N:+X,X?4N1A:$A($E(X,5))*10_$E(X,1,4),1:$A(X)_$E(X,2,5))
CLR ; Clear
N LEXELDT,LEXGET,LEXLD,LEXRAN,LEXSD,LEXST,LEXTEST,LEXWN
Q
LEXQCM2 ;ISL/KER - Query - CPT Modifiers - Save ;04/21/2014
+1 ;;2.0;LEXICON UTILITY;**62,80**;Sep 23, 1996;Build 10
+2 ;
+3 ; Global Variables
+4 ; ^DIC(81.3, ICR 4492
+5 ; ^TMP("LEXQCM" SACC 2.3.2.5.1
+6 ; ^TMP("LEXQCMO" SACC 2.3.2.5.1
+7 ;
+8 ; External References
+9 ; $$DT^XLFDT ICR 10103
+10 ; $$UP^XLFSTR ICR 10104
+11 ;
+12 ; Variables NEWed or KILLed Elsewhere
+13 ; LEXIEN Modifier IEN
+14 ; LEXELDT External Last Date
+15 ; LEXLEN Offset Length
+16 ; LEXINC Include Modifier Ranges flag
+17 ; LEXINCI Include Inactive Modifier Ranges flag
+18 ; LEXINCF Include Future Modifier Ranges flag
+19 ; LEXGET Array of Non-Versioned Data
+20 ; LEXST CPT Status and Effective Dates
+21 ; LEXSD Versioned Short Description
+22 ; LEXLD Versioned Long Description
+23 ; LEXRAN Number of Ranges/Comment
+24 ; ^TMP("LEXQCM",$J,"RANGES",#) List of Ranges
+25 ;
EN ; Main Entry Point
+1 ;
+2 KILL ^TMP("LEXQCMO",$JOB)
IF '$LENGTH($GET(LEXELDT))
QUIT
+3 IF +($GET(LEXST))<0
DO FUT
IF $DATA(^TMP("LEXQCMO",$JOB))
DO DSP^LEXQO("LEXQCMO")
QUIT
+4 DO FUL
IF $DATA(^TMP("LEXQCMO",$JOB))
DO DSP^LEXQO("LEXQCMO")
+5 QUIT
FUT ; Future Activation
+1 NEW LEX1,LEX2,LEX3,LEXEFF,LEXI,LEXL,LEXNAM,LEXSO,LEXSTA
SET LEXI=+($GET(LEXIEN))
IF +LEXI'>0
QUIT
IF '$DATA(^DIC(81.3,+LEXI,0))
QUIT
SET LEXL=+($GET(LEXLEN))
IF +LEXL'>0
QUIT
+2 IF LEXL>62
SET LEXL=62
SET LEXSO=$GET(LEXGET(81.3,(+LEXI_","),.01,"E"))
IF '$LENGTH(LEXSO)
QUIT
SET LEXNAM=$GET(LEXGET(81.3,(+LEXI_","),"B"))
IF '$LENGTH(LEXNAM)
QUIT
+3 SET LEXSTA=$GET(LEXST)
SET LEXEFF=$PIECE(LEXSTA,"^",5)
SET LEXSTA=$PIECE(LEXSTA,"^",4)
IF '$LENGTH(LEXSTA)
QUIT
IF '$LENGTH(LEXEFF)
QUIT
SET (LEX1,LEX2,LEX3)=""
+4 DO BOD(LEXELDT)
DO COD(LEXSO,LEXNAM,+($GET(LEXL)))
DO STA(.LEXST,+($GET(LEXL)))
+5 QUIT
BOD(X) ; Based on Date
+1 NEW LEXBOD
SET LEXBOD=$GET(X)
IF '$LENGTH(LEXBOD)
QUIT
IF LEXBOD'["/"
QUIT
SET X="Display based on date: "_LEXBOD
DO BL
DO TL(X)
+2 QUIT
COD(X,Y,LEXLEN) ; Code Line
+1 NEW LEXC,LEXN,LEXT
SET LEXC=$GET(X)
SET LEXN=$GET(Y)
SET LEXT="Code: "_LEXC
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXN
DO BL
DO TL(LEXT)
+2 QUIT
STA(X,LEXLEN) ; Status Line
+1 NEW LEX,LEXC,LEXI,LEXN,LEXX,LEXE,LEXS,LEXT,LEXW,LEXEFF,LEXSTA
SET LEXX=$GET(X)
SET LEXEFF=$PIECE(LEXX,"^",5)
SET LEXSTA=$PIECE(LEXX,"^",4)
SET LEXEFF=$TRANSLATE(LEXEFF,"()","")
+2 SET LEXW=$PIECE(LEXX,"^",6)
SET LEXT=" Status: "
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))
SET LEXT=LEXT_LEXSTA
+3 SET LEXT=LEXT_$JUSTIFY(" ",(35-$LENGTH(LEXT)))
+4 IF LEXEFF'["future"
SET LEXT=LEXT_"Effective: "
+5 SET LEXT=LEXT_$$UP^XLFSTR($EXTRACT(LEXEFF,1))_$EXTRACT(LEXEFF,2,$LENGTH(LEXEFF))
DO BL
DO TL(LEXT)
+6 IF $LENGTH(LEXW)
Begin DoDot:1
+7 NEW LEX,LEXT,LEXC,LEXI,LEXN
SET LEX(1)=LEXW
DO PR^LEXQM(.LEX,(+($GET(LEXLEN))-7))
IF +($ORDER(LEX(" "),-1))'>0
QUIT
+8 SET LEXT=$JUSTIFY(" ",((79-+($GET(LEXLEN)))))
+9 SET (LEXC,LEXI)=0
FOR
SET LEXI=$ORDER(LEX(LEXI))
IF +LEXI'>0
QUIT
Begin DoDot:2
+10 NEW LEXN
SET LEXN=$$TM^LEXQM($GET(LEX(LEXI)))
IF $LENGTH(LEXN)
SET LEXC=LEXC+1
IF LEXC=1
DO BL
DO TL((LEXT_LEXN))
End DoDot:2
End DoDot:1
+11 QUIT
+12 ;
FUL ; Full Display
+1 NEW LEXFUL,LEX,LEXL
SET LEXL=+($GET(LEXLEN))
IF LEXL>62
SET LEXL=62
+2 SET LEXFUL=""
DO FUT
+3 DO SD(.LEXSD,+($GET(LEXL)))
DO LD(.LEXLD,+($GET(LEXL)))
DO WN(.LEXWN,+($GET(LEXL)))
+4 IF +($GET(LEXRAN))>0&($LENGTH($PIECE($GET(LEXRAN),"^",2)))&($ORDER(^TMP("LEXQCM",$JOB,"RANGES",0))>0)
DO RAN(.LEXRAN,+($GET(LEXL)))
+5 QUIT
SD(X,LEXLEN) ; Short Description
+1 NEW LEXI,LEXH,LEXE,LEXN,LEXT
IF '$DATA(X(1))
QUIT
SET LEXN=$GET(X(1))
SET LEXT=" Short Name: "
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXN
DO BL
DO TL(LEXT)
+2 SET LEXE=$GET(X(0))
SET LEXT=" "_LEXE
SET LEXN=$GET(X(2))
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXN
DO TL(LEXT)
+3 QUIT
LD(X,LEXLEN) ; Long Description
+1 NEW LEXI,LEXH,LEXE,LEXN,LEXT
IF '$DATA(X(1))
QUIT
SET LEXN=$GET(X(1))
SET LEXT=" Description: "
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXN
DO BL
DO TL(LEXT)
+2 SET LEXE=$GET(X(0))
SET LEXT=" "_LEXE
SET LEXN=$GET(X(2))
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXN
DO TL(LEXT)
+3 SET LEXT=$JUSTIFY(" ",((79-+($GET(LEXLEN)))))
SET LEXI=2
FOR
SET LEXI=$ORDER(X(LEXI))
IF +LEXI'>0
QUIT
SET LEXN=LEXT_$GET(X(LEXI))
DO TL(LEXN)
+4 QUIT
WN(X,LEXLEN) ; Warning
+1 NEW LEXI,LEXH,LEXE,LEXN,LEXT,LEXC
IF '$DATA(X(1))
QUIT
SET LEXC=0
SET LEXN=$GET(X(1))
SET LEXT=""
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXN
DO BL
DO TL(LEXT)
+2 SET LEXT=$JUSTIFY(" ",((79-+($GET(LEXLEN)))))
SET LEXI=1
FOR
SET LEXI=$ORDER(X(LEXI))
IF +LEXI'>0
QUIT
SET LEXN=LEXT_$GET(X(LEXI))
DO TL(LEXN)
+3 QUIT
RAN(X,LEXLEN) ; Code Ranges
+1 NEW LEXC,LEXH,LEXI,LEXN,LEXS,LEXT
SET LEXH=$GET(X)
SET LEXN=+LEXH
SET LEXH=$PIECE(LEXH,"^",2)
IF +LEXN'>0
QUIT
IF '$LENGTH(LEXH)
QUIT
+2 SET LEXT=" Code Ranges: "
SET LEXT=LEXT_$JUSTIFY(" ",((79-+($GET(LEXLEN)))-$LENGTH(LEXT)))_LEXH
SET LEXN=$JUSTIFY(" ",((79-+($GET(LEXLEN)))))
DO BL
DO TL(LEXT)
+3 SET (LEXC,LEXI)=0
FOR
SET LEXI=$ORDER(^TMP("LEXQCM",$JOB,"RANGES",LEXI))
IF +LEXI'>0
QUIT
Begin DoDot:1
+4 SET LEXC=LEXC+1
IF LEXC=1
DO BL
SET LEXT=$GET(^TMP("LEXQCM",$JOB,"RANGES",LEXI))
IF '$LENGTH(LEXT)
QUIT
DO TL((LEXN_LEXT))
End DoDot:1
+5 QUIT
CCR(X,LEXVDT,LEX,LEXLEN,LEXINCI,LEXINCF) ; CPT Code Ranges
+1 ;
+2 ; LEX=# of Ranges
+3 ; ^TMP("LEXQCM",$J,"RANGES",#)=Begin_End_Act_Inact
+4 ;
+5 KILL ^TMP("LEXQCM",$JOB,"RAN"),^TMP("LEXQCM",$JOB,"RANGES")
+6 NEW LEXC,LEXEVDT,LEXFD,LEXFN,LEXH1,LEXH2,LEXH3,LEXIEN,LEXL,LEXN,LEXP,LEXR0,LEXRA,LEXRA1,LEXRA2,LEXRB,LEXRDA,LEXRDI,LEXRE,LEXRI,LEXRI1,LEXRI2,LEXRN,LEXRT,LEXRX,LEXT
+7 SET LEXIEN=$GET(X)
IF +LEXIEN'>0
QUIT
IF '$DATA(^DIC(81.3,+LEXIEN,0))
QUIT
IF $ORDER(^DIC(81.3,+LEXIEN,10,0))'>0
QUIT
SET LEXVDT=+($GET(LEXVDT))
IF LEXVDT'?7N
SET LEXVDT=$$DT^XLFDT
SET LEXEVDT=$$SD^LEXQM(LEXVDT)
SET LEXLEN=+($GET(LEXLEN))
+8 IF +LEXLEN'>0
SET LEXLEN=62
IF '$LENGTH(LEXEVDT)
QUIT
SET LEXINCI=+($GET(LEXINCI))
SET LEXINCF=+($GET(LEXINCF))
SET (LEXFD,LEXRX)=0
FOR
SET LEXRX=$ORDER(^DIC(81.3,+LEXIEN,10,LEXRX))
IF +LEXRX'>0
QUIT
Begin DoDot:1
+9 SET LEXR0=$GET(^DIC(81.3,+LEXIEN,10,LEXRX,0))
SET LEXRB=$PIECE(LEXR0,"^",1)
IF $LENGTH(LEXRB)'=5
QUIT
SET LEXRE=$PIECE(LEXR0,"^",2)
IF $LENGTH(LEXRB)&('$LENGTH(LEXRE))
SET LEXRE=LEXRB
IF $LENGTH(LEXRE)'=5
QUIT
+10 SET LEXRA=$PIECE(LEXR0,"^",3)
IF LEXRA'?7N
QUIT
SET LEXRI=$PIECE(LEXR0,"^",4)
IF +LEXRA>0&(LEXVDT<+($GET(LEXRA)))&(+($GET(LEXINCF))'>0)
QUIT
IF +LEXRI>0&(LEXVDT>+($GET(LEXRI)))&(+($GET(LEXINCI))'>0)
QUIT
+11 SET LEXRN=$$NUM(LEXRB)
SET LEXRT=LEXRB_"^"_LEXRE_"^"_LEXRA_"^"_LEXRI
SET LEXRA1=$SELECT(LEXVDT<LEXRA:"<",1:" ")
SET LEXRA2=$SELECT(LEXVDT<LEXRA:">",1:" ")
+12 SET LEXRI1=$SELECT(LEXVDT<LEXRI:"<",1:" ")
SET LEXRI2=$SELECT(LEXVDT<LEXRI:">",1:" ")
IF LEXRA1["<"!(LEXRA2[">")!(LEXRI1["<")!(LEXRI2[">")
SET LEXFD=1
+13 SET LEXRDA=$SELECT($LENGTH(LEXRA):(LEXRA1_$$SD^LEXQM(LEXRA)_LEXRA2),1:"")
SET LEXRDI=$SELECT($LENGTH(LEXRI):(LEXRI1_$$SD^LEXQM(LEXRI)_LEXRI2),1:"")
+14 SET ^TMP("LEXQCM",$JOB,"RAN",LEXRN,LEXRT)=LEXRB_" "_LEXRE_" "_LEXRDA_" "_LEXRDI
End DoDot:1
+15 SET LEXH1="CPT Code Range Effective Dates"
SET LEXH2="Begin End Active Inactive"
SET LEXH3="----- ----- ---------- ----------"
+16 KILL LEX
SET (LEX,LEXL,LEXC,LEXRN)=0
SET LEXFN=""
IF +($GET(LEXFD))>0
SET LEXFN=" Future dates indicated as '<mm/dd/yyyy>'"
+17 SET LEXC=0
FOR
SET LEXRN=$ORDER(^TMP("LEXQCM",$JOB,"RAN",LEXRN))
IF +LEXRN'>0
QUIT
SET LEXRT=""
FOR
SET LEXRT=$ORDER(^TMP("LEXQCM",$JOB,"RAN",LEXRN,LEXRT))
IF '$LENGTH(LEXRT)
QUIT
Begin DoDot:1
+18 SET LEXT=$GET(^TMP("LEXQCM",$JOB,"RAN",LEXRN,LEXRT))
IF '$LENGTH(LEXT)
QUIT
SET LEXC=LEXC+1
IF LEXC=1
Begin DoDot:2
+19 SET LEXN=$ORDER(^TMP("LEXQCM",$JOB,"RANGES"," "),-1)+1
SET ^TMP("LEXQCM",$JOB,"RANGES",LEXN)=LEXH1
SET LEXN=$ORDER(^TMP("LEXQCM",$JOB,"RANGES"," "),-1)+1
SET ^TMP("LEXQCM",$JOB,"RANGES",LEXN)=LEXH2
+20 SET LEXN=$ORDER(^TMP("LEXQCM",$JOB,"RANGES"," "),-1)+1
SET ^TMP("LEXQCM",$JOB,"RANGES",LEXN)=LEXH3
SET ^TMP("LEXQCM",$JOB,"RANGES",0)=LEXN
End DoDot:2
+21 SET LEX=+($GET(LEX))+1
SET LEXN=$ORDER(^TMP("LEXQCM",$JOB,"RANGES"," "),-1)+1
SET ^TMP("LEXQCM",$JOB,"RANGES",LEXN)=LEXT
SET ^TMP("LEXQCM",$JOB,"RANGES",0)=LEXN
End DoDot:1
+22 IF $LENGTH(LEXFN)
Begin DoDot:1
+23 SET LEXN=$ORDER(^TMP("LEXQCM",$JOB,"RANGES"," "),-1)+1
SET ^TMP("LEXQCM",$JOB,"RANGES",LEXN)=" "
SET ^TMP("LEXQCM",$JOB,"RANGES",0)=LEXN
+24 SET LEXN=$ORDER(^TMP("LEXQCM",$JOB,"RANGES"," "),-1)+1
SET ^TMP("LEXQCM",$JOB,"RANGES",LEXN)=LEXFN
SET ^TMP("LEXQCM",$JOB,"RANGES",0)=LEXN
End DoDot:1
+25 KILL ^TMP("LEXQCM",$JOB,"RAN")
SET LEXT=""
IF +LEX>0
Begin DoDot:1
+26 NEW LEXP,LEXT
SET LEXP=$SELECT(+LEX>1:"s",1:"")
SET LEXT=""
IF +($GET(LEXINCI))>0&(+($GET(LEXINCF))>0)
SET LEXT=+LEX_" Current and future Active or Inactive range"_LEXP_" found"
+27 IF +($GET(LEXINCI))>0&(+($GET(LEXINCF))'>0)
SET LEXT=+LEX_" Currently Active or Inactive range"_LEXP_" found"
IF +($GET(LEXINCI))'>0&(+($GET(LEXINCF))>0)
SET LEXT=+LEX_" Current and future Active range"_LEXP_" found"
+28 IF +($GET(LEXINCI))'>0&(+($GET(LEXINCF))'>0)
SET LEXT=+LEX_" Currently Active range"_LEXP_" found"
IF $LENGTH(LEXT)
SET LEX=LEX_"^"_LEXT
End DoDot:1
+29 QUIT
+30 ;
+31 ; Miscellaneous
BL ; Blank Line
+1 DO TL(" ")
QUIT
TL(X) ; Text Line
+1 IF $DATA(LEXTEST)
WRITE !,$GET(X)
QUIT
+2 NEW LEXI
SET LEXI=+($ORDER(^TMP("LEXQCMO",$JOB," "),-1))+1
SET ^TMP("LEXQCMO",$JOB,LEXI)=$GET(X)
SET ^TMP("LEXQCMO",$JOB,0)=LEXI
+3 QUIT
NUM(X) ; Convert Code to Numeric
+1 QUIT $SELECT(X?1.N:+X,X?4N1A:$ASCII($EXTRACT(X,5))*10_$EXTRACT(X,1,4),1:$ASCII(X)_$EXTRACT(X,2,5))
CLR ; Clear
+1 NEW LEXELDT,LEXGET,LEXLD,LEXRAN,LEXSD,LEXST,LEXTEST,LEXWN
+2 QUIT