LEXABC2 ;ISL/KER - Look-up by Code (part 2) ;04/21/2014
;;2.0;LEXICON UTILITY;**4,80**;Sep 23, 1996;Build 10
;
; Global Variables
; ^TMP("LEXFND" SACC 2.3.2.5.1
; ^TMP("LEXL" SACC 2.3.2.5.1
; ^TMP("LEXSCH" SACC 2.3.2.5.1
;
; External References
; None
;
REO ; Reorder list
Q:'$D(^TMP("LEXL",$J)) N LEXS,LEXT,LEXP,LEXE,LEXEX,LEXFT,LEXM,LEXX S LEXS="" F S LEXS=$O(^TMP("LEXL",$J,LEXS)) Q:LEXS="" S LEXT=0 F S LEXT=$O(^TMP("LEXL",$J,LEXS,LEXT)) Q:+LEXT=0 D
. S LEXP=0 F S LEXP=$O(^TMP("LEXL",$J,LEXS,LEXT,LEXP)) Q:+LEXP=0 S LEXE=0 F S LEXE=$O(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE)) Q:+LEXE=0 D
. . Q:LEXP=3
. . I LEXP=1 D MC Q
. . I LEXP=4,$G(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE))["ICD" D SP Q
. . D OT
Q
MC ; Major concept
S LEXM=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",1),LEXFT="A"
S ^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXFT,LEXE)=^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE)
K ^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE)
Q
SP ; Joint term/code
N LEXS2,LEXT2,LEXP2,LEXF2,LEXE2,LEXEX,LEXFT,LEXM,LEXF
N LEXX,LEXTM,LEXTE,LEXHM,LEXHE,LEXHD,LEXOK
S LEXOK=0,LEXS2="" F S LEXS2=$O(^TMP("LEXL",$J,LEXS2)) Q:LEXS2=""!(LEXOK) S LEXT2=0 F S LEXT2=$O(^TMP("LEXL",$J,LEXS2,LEXT2)) Q:+LEXT2=0!(LEXOK) D
. S LEXP2=0 F S LEXP2=$O(^TMP("LEXL",$J,LEXS2,LEXT2,LEXP2)) Q:+LEXP2=0!(LEXOK) S LEXF=99999999999 F S LEXF=$O(^TMP("LEXL",$J,LEXS2,LEXT2,LEXP2,LEXF)) Q:LEXF=""!(LEXOK) D
. . S LEXE2=0 F S LEXE2=$O(^TMP("LEXL",$J,LEXS2,LEXT2,LEXP2,LEXF,LEXE2)) Q:+LEXE2=0!(LEXOK) D
. . . S LEXTM=$P(^TMP("LEXL",$J,LEXS2,LEXT2,LEXP2,LEXF,LEXE2),"^",1)
. . . S LEXTE=$P(^TMP("LEXL",$J,LEXS2,LEXT2,LEXP2,LEXF,LEXE2),"^",2)
. . . S LEXHM=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",1)
. . . S LEXHE=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",2)
. . . S LEXHD=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",4)
. . . I LEXTM=LEXHM,LEXTE=LEXHE S $P(^TMP("LEXL",$J,LEXS2,LEXT2,LEXP2,LEXF,LEXE2),"^",4)=LEXHD K ^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE) S LEXOK=1 Q
I 'LEXOK D OT
Q
OT ; Other than Major Concept
S:LEXP>1 LEXX=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",1)
S LEXFT=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",5)
; Primary --> <major concept>=<primary concept>
I +($G(LEXM))=+($G(LEXX)) D Q
. S:LEXFT="" LEXFT="B"
. S:$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",6)="Other: " $P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",6)="Synonym: ",LEXFT="B"
. S ^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXFT,LEXE)=^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE) K ^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE)
Q:+($G(LEXM))=+($G(LEXX))
; Other --> <major concept>'=<primary concept>
S LEXFT="F"
S $P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",7)=$P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",6)
S $P(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE),"^",6)="Other: "
S ^TMP("LEXL",$J,LEXS,LEXT,3,LEXFT,LEXE)=^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE)
K ^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXE)
Q
SCH(LEXX) ; $Orderable variable
S LEXX=$E(LEXX,1,($L(LEXX)-1))_$C($A($E(LEXX,$L(LEXX)))-1)_"~" Q LEXX
ADD ; Add codes expressions to the selection list
;
; Use local array LEXL
;
; S ^TMP("LEXL",$J,<Code>,<Type>,<Preference>,<Form>,<IEN>)=
; <IEN 757>^<IEN 757.01>^<Description>^<Display>^<Form Type>^<Form>
;
N LEXS,LEXT,LEXP,LEXFT,LEXSIEN,LEXPM,LEXEXA
S LEXS="" F S LEXS=$O(^TMP("LEXL",$J,LEXS)) Q:LEXS="" D
. S LEXT=0 F S LEXT=$O(^TMP("LEXL",$J,LEXS,LEXT)) Q:+LEXT=0 D
. . S (LEXP,LEXPM)=0 F S LEXP=$O(^TMP("LEXL",$J,LEXS,LEXT,LEXP)) Q:+LEXP=0 D
. . . S LEXFT="" F S LEXFT=$O(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXFT)) Q:LEXFT="" D
. . . . S LEXSIEN=0 F S LEXSIEN=$O(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXFT,LEXSIEN)) Q:+LEXSIEN=0 D SAVE
Q
SAVE ; Save in ^TMP
N LEXMI,LEXEI,LEXDF,LEXDS,LEXFM,LEXTP,LEXPX,LEXSX,LEXFQ,LEXSTR,LEXTMP
S LEXSTR="",LEXTMP=$G(^TMP("LEXL",$J,LEXS,LEXT,LEXP,LEXFT,LEXSIEN)),LEXMI=$P(LEXTMP,"^",1),LEXEI=$P(LEXTMP,"^",2),LEXDF=$P(LEXTMP,"^",3)
S LEXDS=$P(LEXTMP,"^",4),LEXFM=$P(LEXTMP,"^",4),LEXTP=$P(LEXTMP,"^",6),(LEXSX,LEXPX)="" S:LEXP=1 LEXPM=LEXMI
; Remove the following line of code if Mental Health either begins to use ICD-10 or DSM-V
Q:$D(LEXEXA(+LEXEI)) S LEXEXA(+LEXEI)=""
; Prefix
I LEXP>1 S LEXPX=LEXTP S:LEXPX["Concept" LEXPX="Synonym: " S:LEXPX="" LEXPX="Other: "
; Suffix
I LEXP>1 S LEXSX="" S:LEXPX["Other:" LEXSX="classified as" S:LEXPX="" LEXSX="classified as",LEXPX="Other: "
; Display
S:$L(LEXSX)&($G(LEXSO2)["+") LEXDS=LEXSX_" "_LEXDS S:$L(LEXDS) LEXDS="("_LEXDS_")"
; String
S LEXSTR=$$TERM(LEXEI) S:$L(LEXDF) LEXSTR=LEXSTR_" "_LEXDF S:$L(LEXDS) LEXSTR=LEXSTR_" "_LEXDS S:$L(LEXPX) LEXSTR=LEXPX_LEXSTR S:LEXP>1 LEXSTR=" "_LEXSTR
; ^TMP("LEXFND",$J,FQ,IEN)
S LEXFQ=$G(^TMP("LEXFND",$J,0)) S:+LEXFQ=0 LEXFQ=-999999 S LEXFQ=LEXFQ+1
S:'$D(^TMP("LEXFND",$J,-LEXFQ,LEXEI)) ^TMP("LEXSCH",$J,"NUM",0)=$G(^TMP("LEXSCH",$J,"NUM",0))+1
S ^TMP("LEXFND",$J,LEXFQ,LEXEI)=LEXSTR,^TMP("LEXFND",$J,0)=LEXFQ,LEX=$G(^TMP("LEXSCH",$J,"NUM",0))
Q
TERM(LEXX) ; Get expression
Q $G(^LEX(757.01,+($G(LEXX)),0))
LEXABC2 ;ISL/KER - Look-up by Code (part 2) ;04/21/2014
+1 ;;2.0;LEXICON UTILITY;**4,80**;Sep 23, 1996;Build 10
+2 ;
+3 ; Global Variables
+4 ; ^TMP("LEXFND" SACC 2.3.2.5.1
+5 ; ^TMP("LEXL" SACC 2.3.2.5.1
+6 ; ^TMP("LEXSCH" SACC 2.3.2.5.1
+7 ;
+8 ; External References
+9 ; None
+10 ;
REO ; Reorder list
+1 IF '$DATA(^TMP("LEXL",$JOB))
QUIT
NEW LEXS,LEXT,LEXP,LEXE,LEXEX,LEXFT,LEXM,LEXX
SET LEXS=""
FOR
SET LEXS=$ORDER(^TMP("LEXL",$JOB,LEXS))
IF LEXS=""
QUIT
SET LEXT=0
FOR
SET LEXT=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT))
IF +LEXT=0
QUIT
Begin DoDot:1
+2 SET LEXP=0
FOR
SET LEXP=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP))
IF +LEXP=0
QUIT
SET LEXE=0
FOR
SET LEXE=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE))
IF +LEXE=0
QUIT
Begin DoDot:2
+3 IF LEXP=3
QUIT
+4 IF LEXP=1
DO MC
QUIT
+5 IF LEXP=4
IF $GET(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE))["ICD"
DO SP
QUIT
+6 DO OT
End DoDot:2
End DoDot:1
+7 QUIT
MC ; Major concept
+1 SET LEXM=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",1)
SET LEXFT="A"
+2 SET ^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXFT,LEXE)=^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
+3 KILL ^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
+4 QUIT
SP ; Joint term/code
+1 NEW LEXS2,LEXT2,LEXP2,LEXF2,LEXE2,LEXEX,LEXFT,LEXM,LEXF
+2 NEW LEXX,LEXTM,LEXTE,LEXHM,LEXHE,LEXHD,LEXOK
+3 SET LEXOK=0
SET LEXS2=""
FOR
SET LEXS2=$ORDER(^TMP("LEXL",$JOB,LEXS2))
IF LEXS2=""!(LEXOK)
QUIT
SET LEXT2=0
FOR
SET LEXT2=$ORDER(^TMP("LEXL",$JOB,LEXS2,LEXT2))
IF +LEXT2=0!(LEXOK)
QUIT
Begin DoDot:1
+4 SET LEXP2=0
FOR
SET LEXP2=$ORDER(^TMP("LEXL",$JOB,LEXS2,LEXT2,LEXP2))
IF +LEXP2=0!(LEXOK)
QUIT
SET LEXF=99999999999
FOR
SET LEXF=$ORDER(^TMP("LEXL",$JOB,LEXS2,LEXT2,LEXP2,LEXF))
IF LEXF=""!(LEXOK)
QUIT
Begin DoDot:2
+5 SET LEXE2=0
FOR
SET LEXE2=$ORDER(^TMP("LEXL",$JOB,LEXS2,LEXT2,LEXP2,LEXF,LEXE2))
IF +LEXE2=0!(LEXOK)
QUIT
Begin DoDot:3
+6 SET LEXTM=$PIECE(^TMP("LEXL",$JOB,LEXS2,LEXT2,LEXP2,LEXF,LEXE2),"^",1)
+7 SET LEXTE=$PIECE(^TMP("LEXL",$JOB,LEXS2,LEXT2,LEXP2,LEXF,LEXE2),"^",2)
+8 SET LEXHM=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",1)
+9 SET LEXHE=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",2)
+10 SET LEXHD=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",4)
+11 IF LEXTM=LEXHM
IF LEXTE=LEXHE
SET $PIECE(^TMP("LEXL",$JOB,LEXS2,LEXT2,LEXP2,LEXF,LEXE2),"^",4)=LEXHD
KILL ^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
SET LEXOK=1
QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+12 IF 'LEXOK
DO OT
+13 QUIT
OT ; Other than Major Concept
+1 IF LEXP>1
SET LEXX=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",1)
+2 SET LEXFT=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",5)
+3 ; Primary --> <major concept>=<primary concept>
+4 IF +($GET(LEXM))=+($GET(LEXX))
Begin DoDot:1
+5 IF LEXFT=""
SET LEXFT="B"
+6 IF $PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",6)="Other
SET $PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",6)="Synonym: "
SET LEXFT="B"
+7 SET ^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXFT,LEXE)=^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
KILL ^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
End DoDot:1
QUIT
+8 IF +($GET(LEXM))=+($GET(LEXX))
QUIT
+9 ; Other --> <major concept>'=<primary concept>
+10 SET LEXFT="F"
+11 SET $PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",7)=$PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",6)
+12 SET $PIECE(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE),"^",6)="Other: "
+13 SET ^TMP("LEXL",$JOB,LEXS,LEXT,3,LEXFT,LEXE)=^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
+14 KILL ^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXE)
+15 QUIT
SCH(LEXX) ; $Orderable variable
+1 SET LEXX=$EXTRACT(LEXX,1,($LENGTH(LEXX)-1))_$CHAR($ASCII($EXTRACT(LEXX,$LENGTH(LEXX)))-1)_"~"
QUIT LEXX
ADD ; Add codes expressions to the selection list
+1 ;
+2 ; Use local array LEXL
+3 ;
+4 ; S ^TMP("LEXL",$J,<Code>,<Type>,<Preference>,<Form>,<IEN>)=
+5 ; <IEN 757>^<IEN 757.01>^<Description>^<Display>^<Form Type>^<Form>
+6 ;
+7 NEW LEXS,LEXT,LEXP,LEXFT,LEXSIEN,LEXPM,LEXEXA
+8 SET LEXS=""
FOR
SET LEXS=$ORDER(^TMP("LEXL",$JOB,LEXS))
IF LEXS=""
QUIT
Begin DoDot:1
+9 SET LEXT=0
FOR
SET LEXT=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT))
IF +LEXT=0
QUIT
Begin DoDot:2
+10 SET (LEXP,LEXPM)=0
FOR
SET LEXP=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP))
IF +LEXP=0
QUIT
Begin DoDot:3
+11 SET LEXFT=""
FOR
SET LEXFT=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXFT))
IF LEXFT=""
QUIT
Begin DoDot:4
+12 SET LEXSIEN=0
FOR
SET LEXSIEN=$ORDER(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXFT,LEXSIEN))
IF +LEXSIEN=0
QUIT
DO SAVE
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+13 QUIT
SAVE ; Save in ^TMP
+1 NEW LEXMI,LEXEI,LEXDF,LEXDS,LEXFM,LEXTP,LEXPX,LEXSX,LEXFQ,LEXSTR,LEXTMP
+2 SET LEXSTR=""
SET LEXTMP=$GET(^TMP("LEXL",$JOB,LEXS,LEXT,LEXP,LEXFT,LEXSIEN))
SET LEXMI=$PIECE(LEXTMP,"^",1)
SET LEXEI=$PIECE(LEXTMP,"^",2)
SET LEXDF=$PIECE(LEXTMP,"^",3)
+3 SET LEXDS=$PIECE(LEXTMP,"^",4)
SET LEXFM=$PIECE(LEXTMP,"^",4)
SET LEXTP=$PIECE(LEXTMP,"^",6)
SET (LEXSX,LEXPX)=""
IF LEXP=1
SET LEXPM=LEXMI
+4 ; Remove the following line of code if Mental Health either begins to use ICD-10 or DSM-V
+5 IF $DATA(LEXEXA(+LEXEI))
QUIT
SET LEXEXA(+LEXEI)=""
+6 ; Prefix
+7 IF LEXP>1
SET LEXPX=LEXTP
IF LEXPX["Concept"
SET LEXPX="Synonym: "
IF LEXPX=""
SET LEXPX="Other: "
+8 ; Suffix
+9 IF LEXP>1
SET LEXSX=""
IF LEXPX["Other
SET LEXSX="classified as"
IF LEXPX=""
SET LEXSX="classified as"
SET LEXPX="Other: "
+10 ; Display
+11 IF $LENGTH(LEXSX)&($GET(LEXSO2)["+")
SET LEXDS=LEXSX_" "_LEXDS
IF $LENGTH(LEXDS)
SET LEXDS="("_LEXDS_")"
+12 ; String
+13 SET LEXSTR=$$TERM(LEXEI)
IF $LENGTH(LEXDF)
SET LEXSTR=LEXSTR_" "_LEXDF
IF $LENGTH(LEXDS)
SET LEXSTR=LEXSTR_" "_LEXDS
IF $LENGTH(LEXPX)
SET LEXSTR=LEXPX_LEXSTR
IF LEXP>1
SET LEXSTR=" "_LEXSTR
+14 ; ^TMP("LEXFND",$J,FQ,IEN)
+15 SET LEXFQ=$GET(^TMP("LEXFND",$JOB,0))
IF +LEXFQ=0
SET LEXFQ=-999999
SET LEXFQ=LEXFQ+1
+16 IF '$DATA(^TMP("LEXFND",$JOB,-LEXFQ,LEXEI))
SET ^TMP("LEXSCH",$JOB,"NUM",0)=$GET(^TMP("LEXSCH",$JOB,"NUM",0))+1
+17 SET ^TMP("LEXFND",$JOB,LEXFQ,LEXEI)=LEXSTR
SET ^TMP("LEXFND",$JOB,0)=LEXFQ
SET LEX=$GET(^TMP("LEXSCH",$JOB,"NUM",0))
+18 QUIT
TERM(LEXX) ; Get expression
+1 QUIT $GET(^LEX(757.01,+($GET(LEXX)),0))