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

LEXLK2.m

Go to the documentation of this file.
LEXLK2 ;ISL/KER - Look Up - Expression Attributes ;05/23/2017
 ;;2.0;LEXICON UTILITY;**6,19,80,103**;Sep 23, 1996;Build 2
 ;               
 ; Global Variables
 ;    ^LEX(757.13)        N/A
 ;               
 ; External References
 ;    ^DIR                ICR  10026
 ;               
GET(Y) ; Build list in array LEX
 N LEXSPC,LEXSPCR,LEXSTR,LEXDIS,LEXMC,LEXMCE,LEXEXP,LEXAI
 S $E(LEXSPC,42)=" " S LEXMC=+($G(^LEX(757.01,+($G(Y)),1))),LEXMCE=+($G(Y)),LEXMEX=+($G(^LEX(757,+LEXMC,0)))
 K LEX
 ; PCH 6  add MD and CLC
 D MC,SY,FS,LV,MD,DEF,STY,CLC,SRC,SUB
 K LEXC,LEXCODE,LEXCT,LEXDEF,LEXDIS,LEXEXP,LEXF
 K LEXFORM,LEXMC,LEXMCE,LEXNOM,LEXSCP,LEXSO,LEXSPC,LEXSPCR
 K LEXSR,LEXSRC,LEXSTR
 Q
MC ;    Major Concept
 N LEXMEX,LEXA,LEXI S LEXMC=+($G(^LEX(757.01,+($G(Y)),1))),LEXMCE=+($G(Y)),LEXMEX=+($G(^LEX(757,+LEXMC,0)))
 S LEXAI(+LEXMEX)="" D BL,BL S LEXSTR="TERMS:" D TL,BL S LEXA(1)=$G(^LEX(757.01,LEXMEX,0)) D PR^LEXU(.LEXA,64)
 S LEXSTR="  Concept:" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(1)) D TL
 S LEXI=1 F  S LEXI=$O(LEXA(LEXI)) Q:+LEXI'>0  D
 . S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(LEXI)) D TL
 S LEXDIS=$$T(+LEXMEX) S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_LEXDIS D TL
 Q
SY ;    Synonyms
 N LEXEXP S LEXEXP=0 F  S LEXEXP=$O(^LEX(757.01,"AMC",+LEXMC,LEXEXP)) Q:+LEXEXP=0  D
 . I $P(^LEX(757.01,LEXEXP,1),U,2)=2 D
 . . N LEXA,LEXSTR,LEXI S LEXAI(+LEXEXP)="" S LEXA(1)=$G(^LEX(757.01,LEXEXP,0)) D PR^LEXU(.LEXA,64) D BL
 . . S LEXSTR="  Synonym:" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(1)) D TL
 . . S LEXI=1 F  S LEXI=$O(LEXA(LEXI)) Q:+LEXI'>0  D
 . . . S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(LEXI)) D TL
 . . S LEXDIS=$$T(+LEXEXP) S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_LEXDIS D TL
 Q
LV ;    Lexical Variants
 N LEXEXP S LEXEXP=0 F  S LEXEXP=$O(^LEX(757.01,"AMC",+LEXMC,LEXEXP)) Q:+LEXEXP=0  D
 . I $P(^LEX(757.01,LEXEXP,1),U,2)=3 D
 . . N LEXA,LEXSTR,LEXI S LEXAI(+LEXEXP)="" S LEXA(1)=$G(^LEX(757.01,LEXEXP,0)) D PR^LEXU(.LEXA,64) D BL
 . . S LEXSTR="  Variant:" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(1)) D TL
 . . S LEXI=1 F  S LEXI=$O(LEXA(LEXI)) Q:+LEXI'>0  D
 . . . S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(LEXI)) D TL
 . . S LEXDIS=$$T(+LEXEXP) S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_LEXDIS D TL
 Q
FS ;    Fully Specified
 N LEXEXP S LEXEXP=0 F  S LEXEXP=$O(^LEX(757.01,"AMC",+LEXMC,LEXEXP)) Q:+LEXEXP=0  D
 . I $P(^LEX(757.01,LEXEXP,1),U,2)=8 D
 . . N LEXA,LEXSTR,LEXI S LEXAI(+LEXEXP)="" S LEXA(1)=$G(^LEX(757.01,LEXEXP,0)) D PR^LEXU(.LEXA,64) D BL
 . . S LEXSTR="  Specified:" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(1)) D TL
 . . S LEXI=1 F  S LEXI=$O(LEXA(LEXI)) Q:+LEXI'>0  D
 . . . S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXA(LEXI)) D TL
 . . S LEXDIS=$$T(+LEXEXP) S LEXSTR="" S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_LEXDIS D TL
 Q
MD ;    Modifiers/Descendants    PCH 6  added
 Q:'$D(^LEX(757.01,"APAR",LEXMCE))
 D BL
 N LEXCHD,LEXORD,LEXSTR,LEXNO,LEXE,LEXCT,LEXTY,LEXL
 S (LEXCHD,LEXCT)=0
 S LEXSTR="  Modified/Descendant Terms" D TL,BL
 F  S LEXCHD=$O(^LEX(757.01,"APAR",LEXMCE,LEXCHD)) Q:+LEXCHD=0  D
 . S LEXE=$P($G(^LEX(757.01,LEXCHD,0)),"^") Q:'$L(LEXE)
 . S LEXTY=+$P($G(^LEX(757.01,LEXCHD,1)),"^",2) Q:LEXTY=0
 . S LEXCT=LEXCT+1
 . S LEXORD=+$P($G(^LEX(757.01,LEXCHD,1)),"^",10)
 . S LEXNO=$S(LEXORD>0:LEXORD,1:(9999+LEXCT))
 . S LEXL(LEXTY,LEXNO)=LEXE
 S LEXTY=0 F  S LEXTY=$O(LEXL(LEXTY)) Q:+LEXTY=0  D
 . S LEXNO=0 F  S LEXNO=$O(LEXL(LEXTY,LEXNO)) Q:+LEXNO=0  D
 . . S LEXSTR="            "_LEXL(LEXTY,LEXNO) D TL
 Q
DEF ;    Definition
 D BL
 I $D(^LEX(757.01,+Y,3)) D  D BL
 . S LEXSTR="DEFINITION:" D TL,BL
 . N LEXDEF S LEXDEF=0
 . F  S LEXDEF=$O(^LEX(757.01,+Y,3,LEXDEF)) Q:+LEXDEF=0  D
 . . S LEXSTR="  "_^LEX(757.01,+Y,3,LEXDEF,0) D TL
 Q
STY ;    Semantic Classes/Types
 S LEXSTR="SEMANTICS:" D TL,BL
 S LEXSTR="  CLASS                                 TYPE" D TL
 N LEXC,LEXT,LEXCT,LEXTT S LEXC="",LEXT=0
 F  S LEXC=$O(^LEX(757.1,"AMCC",LEXMC,LEXC)) Q:LEXC=""  D
 . S LEXCT=$E($P(^LEX(757.11,+$O(^LEX(757.11,"B",LEXC,0)),0),U,2),1,38)
 . S LEXSTR="  "_LEXCT,LEXT=0 F  S LEXT=$O(^LEX(757.1,"AMCC",LEXMC,LEXC,LEXT)) Q:+LEXT=0  D
 . . S LEXTT=$E($P(^LEX(757.12,+$P(^LEX(757.1,LEXT,0),U,3),0),U,2),1,38)
 . . S LEXSPCR=$E(LEXSPC,1,(40-$L(LEXSTR)))
 . . S LEXSTR=LEXSTR_LEXSPCR_LEXTT D TL S LEXSTR=""
 Q
CLC ;    Clinical Class   PCH 6  added
 N LEXCL,LEXGP,LEXSTR,LEXFM,LEXIND,LEXP,LEXMEM,LEXT,LEXTC
 S LEXCL=+$P($G(^LEX(757.01,+Y,1)),"^",11)
 S:LEXCL=0 LEXCL=+$P($G(^LEX(757.01,LEXMCE,1)),"^",11)
 Q:LEXCL=0  Q:'$D(^LEX(757.13,LEXCL,0))
 S LEXGP=$G(^LEX(757.13,LEXCL,5)) Q:'$L(LEXGP)
 D BL S LEXSTR="SOURCE CATEGORY:  "_LEXGP D TL,BL
 S LEXFM=$P($G(^LEX(757.13,LEXCL,3)),"^") Q:'$L(LEXFM)
 S LEXIND="  "
 F LEXP=1:1:$L(LEXFM,"~") D
 . S LEXMEM=+$P(LEXFM,"~",LEXP) Q:LEXMEM=0  Q:'$D(^LEX(757.13,LEXMEM,0))
 . S LEXT=$P($G(^LEX(757.13,LEXMEM,0)),"^") Q:LEXT=""
 . S LEXTC=$P($G(^LEX(757.13,LEXMEM,0)),"^",2)
 . S LEXIND=LEXIND_"  "
 . S LEXSTR=LEXIND_LEXT D TL
 Q
SRC ;    Classification Systems/Codes
 N LEXSR,LEXSO,LEXSPC
 K LEXSRC
 S LEXSO=0
 F  S LEXSO=$O(^LEX(757.02,"AMC",LEXMC,LEXSO)) Q:+LEXSO=0  D
 . Q:$P(^LEX(757.02,LEXSO,0),"^",6)=1
 . S LEXNOM=$P(^LEX(757.03,+$P(^LEX(757.02,LEXSO,0),U,3),0),U,2)
 . S LEXSR=$P(^LEX(757.03,+$P(^LEX(757.02,LEXSO,0),U,3),0),U,3)
 . S:LEXSR[" Edition" LEXSR=$P(LEXSR," Edition",1)_" Ed"_$P(LEXSR," Edition",2,299)
 . S $P(LEXSPC," ",16)=" ",LEXSPC=$E(LEXSPC,1,$L(LEXSPC)-$L(LEXNOM))
 . S LEXSR=LEXNOM_LEXSPC_LEXSR
 . S LEXCODE=$P(^LEX(757.02,LEXSO,0),U,2)
 . S LEXSRC(LEXSR,LEXCODE)=""
 I $D(LEXSRC) D  K LEXSRC
 . D BL S LEXSTR="CLASSIFICATION SYSTEMS/CODES:" D TL,BL
 . S LEXSR="" F  S LEXSR=$O(LEXSRC(LEXSR)) Q:LEXSR=""  D
 . . D BL S LEXSTR="  "_LEXSR D TL
 . . S (LEXSTR,LEXCODE)=""
 . . F  S LEXCODE=$O(LEXSRC(LEXSR,LEXCODE)) Q:LEXCODE=""  D
 . . . S LEXSTR=LEXSTR_"/"_LEXCODE
 . . S:$E(LEXSTR)="/" LEXSTR=$E(LEXSTR,2,$L(LEXSTR))
 . . S LEXSTR="                  "_LEXSTR
 . . D:$L(LEXSTR)>18 TL
 Q
SUB ;
 Q:$O(LEXAI(0))'>0
 N LEXEIEN,LEXAS S LEXEIEN=0 F  S LEXEIEN=$O(LEXAI(LEXEIEN)) Q:+LEXEIEN'>0  D
 . N LEXSIEN S LEXSIEN=0 F  S LEXSIEN=$O(^LEX(757.21,"B",+LEXEIEN,LEXSIEN)) Q:+LEXSIEN'>0  D
 . . N LEXSUB,LEXSUN S LEXSUB=$P($G(^LEX(757.21,+LEXSIEN,0)),"^",2),LEXSUN=$$MIX^LEXXM($P($G(^LEXT(757.2,+LEXSUB,0)),"^",1))
 . . S LEXAS(+LEXSUB)=LEXSUN
 I +($O(LEXAS(0)))>0 D
 . N LEXSTR,LEXS S LEXSTR="SUBSETS:" D BL S LEXS=0 F  S LEXS=$O(LEXAS(LEXS)) Q:+LEXS'>0  D
 . . S LEXSTR=LEXSTR_$J(" ",(14-$L(LEXSTR)))_$G(LEXAS(+LEXS)) D TL S LEXSTR=""
 D BL
 Q
T(X) ; Get Term Type
 N LEXSCP,LEXF,LEXFL,LEXTY,LEXTN
 S LEXF="",LEXFORM="",LEXEXP=+X,X=""
 S LEXTY=$P(^LEX(757.01,LEXEXP,1),U,2)
 S LEXTN=$S(LEXTY=1:"Concept",LEXTY=8:"Fully Specified Name",1:"Synonym")
 S LEXFL=$P(^LEX(757.01,LEXEXP,1),U,5)
 S LEXSCP=$P(^LEX(757.01,LEXEXP,1),U,3)
 S LEXSCP=$S(LEXSCP="D":"Directly Linked to Concept",LEXSCP="I":"Indirectly Linked (via Synonym)",LEXSCP="B":"Broader View of Concept",LEXSCP="N":"Narrower View of Concept",LEXSCP="O":"Other View of Concept",1:"")
 S LEXSCP="",LEXF=$P(^LEX(757.01,LEXEXP,1),U,4) S:+LEXF=0 LEXF=""
 S:+LEXF>0 LEXF=$P($G(^LEX(757.014,+LEXF,0)),U,2)
 S X=LEXSCP_"/"_LEXF S:$P(X,"/",2)="" X=$P(X,"/",1)
 S:$E(X)="/" X=$E(X,2,$L(X))
 S:LEXTY>1&(LEXFL>0)&($l(LEXTN)) X="Retired "_LEXTN
 K LEXSCP,LEXF
 Q X
TM(X,Y) ;   Trim Character
 S X=$G(X) Q:X="" X  S Y=$G(Y) S:'$L(Y) Y=" "
 F  Q:$E(X,1)'=Y  S X=$E(X,2,$L(X))
 F  Q:$E(X,$L(X))'=Y  S X=$E(X,1,($L(X)-1))
 Q X
TL ; Create a Text Line
 Q:'$L($G(LEXSTR))
 N LEXC
 S LEXC=+$G(LEX(0)),LEXC=LEXC+1
 S LEX(LEXC)=LEXSTR
 S LEX(0)=LEXC
 Q
BL ; Create a Blank Line
 N LEXC
 S LEXC=+$G(LEX(0)),LEXC=LEXC+1
 S LEX(LEXC)="",LEX(0)=LEXC
 Q
LIST ; List the contents of the LEX array
 Q:'$G(LEX(0))  N LEXLC,LEXLN,LEXCONT,LEXCL,LEXE,LEXB
 S (LEXLN,LEXLC)=0,LEXCONT=""
 F  Q:LEXLN=LEX(0)!(LEXCONT["^")  D  Q:LEXLN=LEX(0)!(LEXCONT["^")
 . S LEXB=LEXLN+1,LEXE=LEXB+(IOSL-3)
 . F LEXCL=LEXB:1:LEXE D
 . . I $D(LEX(LEXCL)) W !,LEX(LEXCL) S LEXLN=LEXCL,LEXLC=LEXLC+1
 . I LEXLN'=LEX(0) D CONT Q
 W ! S LEXLC=LEXLC+1 I LEXLC=(IOSL-3) D CONT
 K LEXLC,LEXLN,LEXCONT,LEXCL,LEXE,LEXB
 Q
 ; Device
DEV ;   Select a device
 N %ZIS,LEXE,LEXCF,LEXCONT,LEXDNC,LEXEOP,LEXI,LEXLC,ZTDESC,ZTDTH,ZTIO,ZTQUEUED,ZTREQ,ZTRTN,ZTSAVE,ZTSK
 S %ZIS("A")="Device:  ",ZTRTN="DSPI^LEXLK2",ZTDESC="Display Lexicon Entry"
 S ZTIO=ION,ZTDTH=$H,%ZIS="Q",ZTSAVE("LEX(")="" W ! D ^%ZIS I POP S LEXEXIT=1 Q
 S ZTIO=ION I $D(IO("Q")) D QUE,^%ZISC,HOME^%ZIS Q
 D NOQUE Q
NOQUE ;   Do not que task
 W:$L($G(IOF)) @IOF W:IOST["P-" !,"< Not queued, printing code lookup >",! U:IOST["P-" IO D @ZTRTN,^%ZISC,HOME^%ZIS Q
QUE ;   Task queued to print user defaults
 K IO("Q") D ^%ZTLOAD W !,$S($D(ZTSK):"Request Queued",1:"Request Cancelled"),! H 2 Q
 Q
 ;            
DSPI ; Display
 Q:'$D(LEX)  N LEXEXIT,LEXI,LEXIS S (LEXI,LEXEXIT)=0
 W:'$D(ZTQUEUED)&($G(IOST)'["P-")&($L($G(IOF))) @IOF W:$O(LEX(0))'>0 !,"Text not Found"
 U:IOST["P-" IO G:$O(LEX(0))'>0 DSPQ N LEXCONT,LEXI,LEXLC,LEXEOP,LEXCF
 S LEXCONT="",(LEXCF,LEXIS,LEXLC,LEXI)=0,LEXEOP=+($G(IOSL))
 S:LEXEOP=0 LEXEOP=24 F  S LEXI=$O(LEX(LEXI)) Q:+LEXI=0!(LEXCONT["^")  Q:+($G(LEXEXIT))>0  D  Q:+($G(LEXEXIT))>0
 . I '$L($$TM($G(LEX(LEXI)))),'$L($$TM($G(LEX((LEXI+1))))) Q
 . S:$G(LEX(LEXI))["TERMS:" LEXIS=1 Q:LEXIS'>0
 . W !,$G(LEX(LEXI)) S LEXCF=0 D LF Q:+($G(LEXEXIT))>0  Q:LEXCONT["^"
 S:$D(ZTQUEUED) ZTREQ="@" I +($G(LEXEXIT))>0 K LEX Q
 D:'LEXCF EOP  K LEX W ! W:$G(IOST)["P-"&($L($G(IOF))) @IOF
DSPQ ; Quit Display
 Q
LF ;   Line Feed
 S LEXLC=LEXLC+1 D:IOST["P-"&(LEXLC>(LEXEOP-5)) EOP D:IOST'["P-"&(LEXLC>(LEXEOP-4)) EOP
 Q
EOP ;   End of Page
 S LEXCF=1 S LEXLC=0 W:'$D(LEXCAP)&(IOST["P-")&($L($G(IOF))) @IOF Q:IOST["P-"  S LEXCONT=$$CONT2
 Q
CONT2(X) ;   Ask to Continue
 Q:$D(LEXCAP) ""  Q:+($G(LEXEXIT))>0 "^^"  N DIR,DIROUT,DIRUT,DUOUT,DTOUT,Y S DIR(0)="EAO",DIR("A")=" Enter RETURN to continue or '^' to exit: "
 S DIR("PRE")="S:X[""?"" X=""??"" S:X[""^"" X=""^""",(DIR("?"),DIR("??"))="^D CONTH^LEXLK2"
 W ! D ^DIR S:X["^^"!($D(DTOUT)) X="^^",LEXEXIT=1 Q:X["^^"!(+($G(LEXEXIT))>0) "^^"  Q:$D(DIROUT)!($D(DIRUT))!($D(DUOUT))!($D(DTOUT)) "^"
 Q:X["^^" "^^"  Q:X["^" "^"
 Q ""
CONTH ;      Ask to Continue Help
 W:'$D(LEXCAP) !,"     Enter either RETURN or '^'."
 Q
CONT ; Continue listing - Press <Return> to Continue
 W ! N DIR,DTOUT,DUOUT,DIRUT,DIROUT,X,Y S DIR(0)="E" D ^DIR
 S LEXLC=0,LEXCONT=X K DIR,DTOUT,DUOUT,DIRUT,DIROUT W !
 Q