LEXXM ;ISL/KER - Convert Text to Mix Case ;04/21/2014
;;2.0;General Lexicon Utilities;**80**;Sep 23, 1996;Build 10
;
; Global Variables
; ^UTILITY($J ICR 10011
;
; External References
; ^DIWP ICR 10011
; $$CODEN^ICDCODE ICR 3990
; $$ICDDX^ICDCODE ICR 3990
; $$ICDOP^ICDCODE ICR 3990
; ICDD^ICDCODE ICR 3990
; $$CPT^ICPTCOD ICR 1995
; CPTD^ICPTCOD ICR 1995
; $$MOD^ICPTMOD ICR 1996
; MODD^ICPTMOD ICR 1996
; $$DT^XLFDT ICR 10103
;
Q
;
; TXT General Text
; Input X Text
; L Text Length (>19 & <80) (default $L(X))
; Output Y() Mix case diagnosis
;
; LEX Lexicon Text
; Input X Lexicon IEN
; L Text Length (>19 & <80) (default $L(X))
; Output Y() Mix case diagnosis
;
; For the Entry Points ICDDX1, ICDDX2, ICDOP1, ICDOP2, ICPT1,
; ICPT2, MOD1, and MOD2 use:
;
; Input X File IEN
; V Version date (default = TODAY)
; L Text Length (>19 & <80) (default $L(X))
; Output Y() Mix case text
;
MIX(X) ; Mix Case any length
N Y S X=$G(X) D FULL(X) S X=Y
Q X
TXT(X,L) ; Convert Text to Mixed Case
N LOW,LEN K LOW,Y S Y(1)=$$CASE($G(X)),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN D FMT
Q
FULL(X) ; Convert Text to Mixed Case
N LOW,LEN K LOW,Y S Y=$E($$CASE($G(X)),1,240)
Q
LEX(X,L) ; Convert Expression to Mixed Case
K Y N I,IEN,VDT,LEN,LOW K LOW,Y S IEN=+($G(X)),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN Q:+IEN'>0 Q:'$D(^LEX(757.01,+IEN,0))
S Y(1)=$$EXP(X) D FMT
Q
ICDDX1(X,V,L) ; Convert ICD Diagnosis to Mixed Case
N CODE,IEN,VDT,LEN,ICDDX,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S IEN=$P($$CODEN^ICDCODE(IEN,80),"~",1),X="",ICDDX=$P($$ICDDX^ICDCODE(+IEN,VDT,,0),"^",4) Q:'$L(ICDDX) S Y(1)=$$CASE(ICDDX) D FMT
Q
ICDDX2(X,V,L) ; Convert ICD Diagnosis Description to Mixed Case
N CODE,I,IEN,VDT,LEN,ND,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S IEN=$P($$CODEN^ICDCODE(IEN,80),"~",1),CODE=$P($$ICDDX^ICDCODE(+IEN,,0),"^",2) D ICDD^ICDCODE(CODE,"ND",VDT)
K Y S I=0 F S I=$O(ND(I)) Q:+I'>0 Q:$$TRIM($G(ND(I)))="" S:I>1 LOW=1 S Y(I)=$$CASE($G(ND(I))) K LOW
D FMT
Q
ICDOP1(X,V,L) ; Convert ICD Procedure to Mixed Case
N CODE,IEN,VDT,LEN,ICDOP,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S IEN=$P($$CODEN^ICDCODE(IEN,80.1),"~",1),X="",ICDOP=$P($$ICDOP^ICDCODE(+IEN,VDT,,0),"^",5) Q:'$L(ICDOP) S Y(1)=$$CASE(ICDOP) D FMT
Q
ICDOP2(X,V,L) ; Convert ICD Procedure Description to Mixed Case
N CODE,I,IEN,VDT,LEN,ND,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S IEN=$P($$CODEN^ICDCODE(IEN,80.1),"~",1),CODE=$P($$ICDOP^ICDCODE(+IEN,VDT,,0),"^",2) D ICDD^ICDCODE(CODE,"ND",VDT)
K Y S I=0 F S I=$O(ND(I)) Q:+I'>0 Q:$$TRIM($G(ND(I)))="" S:I>1 LOW=1 S Y(I)=$$CASE($G(ND(I))) K LOW
D FMT
Q
ICPT1(X,V,L) ; Convert CPT Procedure to Mixed Case
N CODE,IEN,VDT,LEN,ICPT,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S X="",ICPT=$$CPT^ICPTCOD(+IEN,VDT),IEN=+ICPT,CODE=$P(ICPT,"^",2),ICPT=$P(ICPT,"^",3) Q:'$L(ICPT) S Y(1)=$$CASE(ICPT) D FMT
Q
ICPT2(X,V,L) ; Convert CPT Procedure Description to Mixed Case
N CODE,I,IEN,VDT,LEN,ND,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S CODE=$P($$CPT^ICPTCOD(+IEN,VDT),"^",2) D CPTD^ICPTCOD(CODE,"ND",,VDT)
K Y S I=0 F S I=$O(ND(I)) Q:+I'>0 Q:$$TRIM($G(ND(I)))="" S:I>1 LOW=1 S Y(I)=$$CASE($G(ND(I))) K LOW
D FMT
Q
MOD1(X,V,L) ; Convert CPT Modifier to Mixed Case
N CODE,IEN,VDT,LEN,MOD,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L))
K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S X="",MOD=$$MOD^ICPTMOD(IEN,"I",VDT,1) S MOD=$P(MOD,"^",3) Q:'$L(MOD) S Y(1)=$$CASE(MOD) D FMT
Q
MOD2(X,V,L) ; Convert CPT Modifier Description to Mixed Case
N CODE,I,IEN,VDT,LEN,ND,LOW K LOW,Y S (CODE,IEN)=$G(X),VDT=$G(V),LEN=+($G(L)) K:$G(LEN)'>19 LEN K:$G(LEN)'<80 LEN S:VDT'?7N VDT=$$DT^XLFDT
S CODE=$P($$MOD^ICPTMOD(+IEN,"I",VDT,1),"^",2) D MODD^ICPTMOD(CODE,"ND",,VDT)
K Y S I=0 F S I=$O(ND(I)) Q:+I'>0 Q:$$TRIM($G(ND(I)))="" S:I>1 LOW=1 S Y(I)=$$CASE($G(ND(I))) K LOW
D FMT
Q
;
EXP(X) ; Get Case for Expression X = IEN in 757.01
N IEN,IEN,TXT,IN S IEN=$G(X),(TXT,IN)=$G(^LEX(757.01,+IEN,0)) Q:'$L(TXT) K PAR S (TXT,X)=$$CASE(TXT) S:'$L(X) X=IN
Q X
CASE(X) ; Get Case for String X = String of Text
K PAR N C,CHR,CT,LEXIN,LEXCTL,LEXCHR,I,L,PH,REM,STO,STR,TRL,TXT,W,WD,UIN,OIN,LEXPRE,LEXORG,LEXNXT,LEXUSE
S OIN=$$TRIM($G(X)) S (UIN,STR)=$$UP(OIN) Q:'$L(STR) X S STR=$$SW1(STR),L=$L(STR),PAR(0)=0,(LEXIN,PAR("T",1))=STR
S TRL="" F Q:$E(STR,$L(STR))'?1P S TRL=$E(STR,$L(STR))_TRL,STR=$E(STR,1,($L(STR)-1))
S PAR("TRL")=$G(TRL) S I=0 F Q:I>L Q:'$L(STR) D Q:'$L(STR)
. S I=I+1 I I=$L(STR) D Q
. . S CT=$O(PAR(" "),-1)+1 S (STO,PAR(CT))=STR,PAR(0)=CT,STR=""
. . S PH=$G(PAR((CT-1),"C"))_$G(PAR(CT))_$G(PAR(CT,"C")),PAR(CT,"A")=PH
. . S LEXIN=$G(PAR("T",1)),LEXCTL=$G(PAR(CT,"A")),LEXCHR=$G(PAR(CT,"C"))
. . F W=1:1:$L(STO," ") D
. . . N NWD S WD=$P(STO," ",W),LEXORG=$G(PAR(CT,"W",(+($G(W))-1))),LEXPRE=$$UP(LEXORG)
. . . S LEXNXT="",NWD=$$GETC(WD),PAR(CT,"W",W)=NWD
. S C=$E(STR,I)
. I C?1P&(C'=" ") D
. . S:C="(" C=" (" S:C="[" C=" [" S:C="&" C=" &"
. . N REM,STO S CT=$O(PAR(" "),-1)+1,(STO,PAR(CT))=$E(STR,1,(I-1)),PAR(0)=CT
. . S PH=$G(PAR(CT-1,"C"))_$G(PAR(CT))_$G(PAR(CT,"C")),PAR(CT,"A")=PH
. . S LEXIN=$G(PAR("T",1)),LEXCTL=$G(PAR(CT,"A")),LEXCHR=C
. . F W=1:1:$L(STO," ") D
. . . N NWD S WD=$P(STO," ",W),LEXPRE=$$UP($G(PAR(CT,"W",(+($G(W))-1))))
. . . S NWD=$$GETC(WD),PAR(CT,"W",W)=NWD
. . S (REM,STR)=$E(STR,I+1,$L(STR)),I=0
. . F Q:$E(STR,1)'=" " S C=C_" " S (REM,STR)=$E(STR,2,$L(STR))
. . S PAR(CT,"C")=C
S TXT="",CT=0 F S CT=$O(PAR(CT)) Q:+CT'>0 D
. N STR,TR S STR="",TR=$G(PAR(CT,"C")),W=0 F S W=$O(PAR(CT,"W",W)) Q:+W'>0 S STR=STR_" "_$G(PAR(CT,"W",W))
. S STR=$$TRIM(STR)_TR,PAR(CT,"B")=STR
. S TXT=TXT_STR K PAR(CT)
S TXT=TXT_$G(PAR("TRL")),X=$$SW3(TXT) K PAR F CHR="-","+" D
. I UIN[(" "_CHR),X[CHR,X'[(" "_CHR) D
. . N TXT S TXT=$P(X,CHR,1) F I=2:1 Q:'$L($P(X,CHR,I)) S TXT=TXT_(" "_CHR)_$P(X,CHR,I)
. . S X=TXT
S X=$$FN(X),X=$$DBL(X) F CHR="~","!","@","#","$","^","&","*","_","-","+","=","|","\",";",":",",","." S X=$$TM(X,CHR)
Q X
GETC(X) ; Set to Mixed/lower/UPPER case
N LEXTAG,LEXRTN,LEXLEN,Y Q:$L($G(X))'>0 X S X=$$UP($G(X)),Y="",LEXLEN=$L(X) S:LEXLEN>12 LEXLEN=12
S LEXUSE=$$UP($$USE),LEXNXT=$$TP($$TM($P($G(UIN),LEXUSE,2,299)))
S LEXTAG="T"_$L(X),LEXRTN="LEXXM"_$L(X)
S:$L($G(X))>9 LEXTAG="TM" S:$L($G(X))>5 LEXRTN="LEXXM6" S LEXRTN=LEXTAG_"^"_LEXRTN D @LEXRTN I $L(Y) S X=$$SW2(Y) Q X
S X=$$MX(X)
Q X
;
SW1(X) ; Switch Text (before setting case)
S X=$$SW1^LEXXMM($G(X)) Q X
SW2(X) ; Switch Text (after setting case)
S X=$$SW2^LEXXMM($G(X)) Q X
SW3(X) ; Switch Text (after assembling string)
S X=$$SW3^LEXXMM($G(X)) Q X
EW(X) ; Display Word Usage
D EW^LEXXMM($G(X)) Q
;
USE(X) ; Used
N STR,SEG,CUR S STR="",SEG=0 F S SEG=$O(PAR(SEG)) Q:+SEG'>0 D
. N WC S WC=0 F S WC=$O(PAR(SEG,"W",WC)) Q:+WC'>0 D
. . N WD S WD=$$UP($G(PAR(SEG,"W",WC)))
. . S:$E(STR,$L(STR))?1A!($E(STR,$L(STR))?1N) STR=$G(STR)_" "_WD
. . S:$E(STR,$L(STR))'?1A&($E(STR,$L(STR))'?1N) STR=$G(STR)_WD
. S:$L($G(PAR(SEG,"C"))) STR=STR_$G(PAR(SEG,"C"))
S CUR=$G(WD) I $L(CUR) D
. S:$E(STR,$L(STR))?1A!($E(STR,$L(STR))?1N) STR=$G(STR)_" "_CUR
. S:$E(STR,$L(STR))'?1A&($E(STR,$L(STR))'?1N) STR=$G(STR)_CUR
S X=$$TM(STR)
Q X
;WD="COMPLICATED"
Q X
FMT ; Format Line Length - needs Y() and LEN
Q:$O(Y(0))'>0 Q:+($G(LEN))'>0 Q:+($G(LEN))'>19 Q:+($G(LEN))>79 N I,J,X,D,DIW,DIWF,DIWL,DIWI,DIWR,DIWT,DIWTC,DIWX,DN,Z,L
K ^UTILITY($J,"W") S DIWL=0,DIWF="C"_+($G(LEN)) F J=0:0 S J=$O(Y(J)) Q:'J S X=Y(J) D ^DIWP
K Y F J=0:0 S J=$O(^UTILITY($J,"W",0,J)) Q:'J S Y(J)=$$TRIM($G(^UTILITY($J,"W",0,J,0)))
K ^UTILITY($J,"W")
Q
FN(X) ; Footnote Removed
S X=$G(X) Q:X'[")" X N ORG,FIR,LAS,TRM,L,NUM,OUT,REP,WTH S (OUT,ORG)=X,L=$L(X,")"),FIR=$P(X,")",1,(L-1))_")",LAS=$P(X,")",L),TRM=$$TRIM(LAS),X=ORG I TRM=LAS,$E(LAS,1)?1N,+LAS=LAS S OUT=FIR
F NUM=1:1:9 S REP=")"_NUM_" ",WTH=") " I OUT[REP S OUT=$$SWAP^LEXXMM(OUT,REP,WTH)
S X=OUT
Q X
LO(X) ; Lower Case
Q $TR(X,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
UP(X) ; Upper Case
Q $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
MX(X) ; Mixed Case
Q $TR($E(X,1),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")_$TR($E(X,2,$L(X)),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
LD(X) ; Leading Character
Q $TR($E(X,1),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")_$E(X,2,$L(X))
TRIM(X) ; Trim Spaces
S X=$G(X) F Q:$E(X,1)'=" " S X=$E(X,2,$L(X))
F Q:$E(X,$L(X))'=" " S X=$E(X,1,($L(X)-1))
Q X
TP(X) ; Trim Punctuation
S X=$G(X) Q:'$L(X) X F Q:$E(X,1)'?1P S X=$E(X,2,$L(X))
F Q:$E(X,$L(X))'?1P S X=$E(X,1,($L(X)-1))
Q X
TM(X,Y) ; Trim Character Y - Default " "
S X=$G(X),Y=$G(Y) Q:$L(Y)&(X'[Y) X 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
DBL(X) ; Double Spaces
S X=$G(X) F Q:X'[" " S X=$P(X," ",1)_" "_$P(X," ",2,299)
S X=$$TRIM(X)
Q X
LEXXM ;ISL/KER - Convert Text to Mix Case ;04/21/2014
+1 ;;2.0;General Lexicon Utilities;**80**;Sep 23, 1996;Build 10
+2 ;
+3 ; Global Variables
+4 ; ^UTILITY($J ICR 10011
+5 ;
+6 ; External References
+7 ; ^DIWP ICR 10011
+8 ; $$CODEN^ICDCODE ICR 3990
+9 ; $$ICDDX^ICDCODE ICR 3990
+10 ; $$ICDOP^ICDCODE ICR 3990
+11 ; ICDD^ICDCODE ICR 3990
+12 ; $$CPT^ICPTCOD ICR 1995
+13 ; CPTD^ICPTCOD ICR 1995
+14 ; $$MOD^ICPTMOD ICR 1996
+15 ; MODD^ICPTMOD ICR 1996
+16 ; $$DT^XLFDT ICR 10103
+17 ;
+18 QUIT
+19 ;
+20 ; TXT General Text
+21 ; Input X Text
+22 ; L Text Length (>19 & <80) (default $L(X))
+23 ; Output Y() Mix case diagnosis
+24 ;
+25 ; LEX Lexicon Text
+26 ; Input X Lexicon IEN
+27 ; L Text Length (>19 & <80) (default $L(X))
+28 ; Output Y() Mix case diagnosis
+29 ;
+30 ; For the Entry Points ICDDX1, ICDDX2, ICDOP1, ICDOP2, ICPT1,
+31 ; ICPT2, MOD1, and MOD2 use:
+32 ;
+33 ; Input X File IEN
+34 ; V Version date (default = TODAY)
+35 ; L Text Length (>19 & <80) (default $L(X))
+36 ; Output Y() Mix case text
+37 ;
MIX(X) ; Mix Case any length
+1 NEW Y
SET X=$GET(X)
DO FULL(X)
SET X=Y
+2 QUIT X
TXT(X,L) ; Convert Text to Mixed Case
+1 NEW LOW,LEN
KILL LOW,Y
SET Y(1)=$$CASE($GET(X))
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
DO FMT
+2 QUIT
FULL(X) ; Convert Text to Mixed Case
+1 NEW LOW,LEN
KILL LOW,Y
SET Y=$EXTRACT($$CASE($GET(X)),1,240)
+2 QUIT
LEX(X,L) ; Convert Expression to Mixed Case
+1 KILL Y
NEW I,IEN,VDT,LEN,LOW
KILL LOW,Y
SET IEN=+($GET(X))
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF +IEN'>0
QUIT
IF '$DATA(^LEX(757.01,+IEN,0))
QUIT
+2 SET Y(1)=$$EXP(X)
DO FMT
+3 QUIT
ICDDX1(X,V,L) ; Convert ICD Diagnosis to Mixed Case
+1 NEW CODE,IEN,VDT,LEN,ICDDX,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET IEN=$PIECE($$CODEN^ICDCODE(IEN,80),"~",1)
SET X=""
SET ICDDX=$PIECE($$ICDDX^ICDCODE(+IEN,VDT,,0),"^",4)
IF '$LENGTH(ICDDX)
QUIT
SET Y(1)=$$CASE(ICDDX)
DO FMT
+3 QUIT
ICDDX2(X,V,L) ; Convert ICD Diagnosis Description to Mixed Case
+1 NEW CODE,I,IEN,VDT,LEN,ND,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET IEN=$PIECE($$CODEN^ICDCODE(IEN,80),"~",1)
SET CODE=$PIECE($$ICDDX^ICDCODE(+IEN,,0),"^",2)
DO ICDD^ICDCODE(CODE,"ND",VDT)
+3 KILL Y
SET I=0
FOR
SET I=$ORDER(ND(I))
IF +I'>0
QUIT
IF $$TRIM($GET(ND(I)))=""
QUIT
IF I>1
SET LOW=1
SET Y(I)=$$CASE($GET(ND(I)))
KILL LOW
+4 DO FMT
+5 QUIT
ICDOP1(X,V,L) ; Convert ICD Procedure to Mixed Case
+1 NEW CODE,IEN,VDT,LEN,ICDOP,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET IEN=$PIECE($$CODEN^ICDCODE(IEN,80.1),"~",1)
SET X=""
SET ICDOP=$PIECE($$ICDOP^ICDCODE(+IEN,VDT,,0),"^",5)
IF '$LENGTH(ICDOP)
QUIT
SET Y(1)=$$CASE(ICDOP)
DO FMT
+3 QUIT
ICDOP2(X,V,L) ; Convert ICD Procedure Description to Mixed Case
+1 NEW CODE,I,IEN,VDT,LEN,ND,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET IEN=$PIECE($$CODEN^ICDCODE(IEN,80.1),"~",1)
SET CODE=$PIECE($$ICDOP^ICDCODE(+IEN,VDT,,0),"^",2)
DO ICDD^ICDCODE(CODE,"ND",VDT)
+3 KILL Y
SET I=0
FOR
SET I=$ORDER(ND(I))
IF +I'>0
QUIT
IF $$TRIM($GET(ND(I)))=""
QUIT
IF I>1
SET LOW=1
SET Y(I)=$$CASE($GET(ND(I)))
KILL LOW
+4 DO FMT
+5 QUIT
ICPT1(X,V,L) ; Convert CPT Procedure to Mixed Case
+1 NEW CODE,IEN,VDT,LEN,ICPT,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET X=""
SET ICPT=$$CPT^ICPTCOD(+IEN,VDT)
SET IEN=+ICPT
SET CODE=$PIECE(ICPT,"^",2)
SET ICPT=$PIECE(ICPT,"^",3)
IF '$LENGTH(ICPT)
QUIT
SET Y(1)=$$CASE(ICPT)
DO FMT
+3 QUIT
ICPT2(X,V,L) ; Convert CPT Procedure Description to Mixed Case
+1 NEW CODE,I,IEN,VDT,LEN,ND,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET CODE=$PIECE($$CPT^ICPTCOD(+IEN,VDT),"^",2)
DO CPTD^ICPTCOD(CODE,"ND",,VDT)
+3 KILL Y
SET I=0
FOR
SET I=$ORDER(ND(I))
IF +I'>0
QUIT
IF $$TRIM($GET(ND(I)))=""
QUIT
IF I>1
SET LOW=1
SET Y(I)=$$CASE($GET(ND(I)))
KILL LOW
+4 DO FMT
+5 QUIT
MOD1(X,V,L) ; Convert CPT Modifier to Mixed Case
+1 NEW CODE,IEN,VDT,LEN,MOD,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
+2 IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+3 SET X=""
SET MOD=$$MOD^ICPTMOD(IEN,"I",VDT,1)
SET MOD=$PIECE(MOD,"^",3)
IF '$LENGTH(MOD)
QUIT
SET Y(1)=$$CASE(MOD)
DO FMT
+4 QUIT
MOD2(X,V,L) ; Convert CPT Modifier Description to Mixed Case
+1 NEW CODE,I,IEN,VDT,LEN,ND,LOW
KILL LOW,Y
SET (CODE,IEN)=$GET(X)
SET VDT=$GET(V)
SET LEN=+($GET(L))
IF $GET(LEN)'>19
KILL LEN
IF $GET(LEN)'<80
KILL LEN
IF VDT'?7N
SET VDT=$$DT^XLFDT
+2 SET CODE=$PIECE($$MOD^ICPTMOD(+IEN,"I",VDT,1),"^",2)
DO MODD^ICPTMOD(CODE,"ND",,VDT)
+3 KILL Y
SET I=0
FOR
SET I=$ORDER(ND(I))
IF +I'>0
QUIT
IF $$TRIM($GET(ND(I)))=""
QUIT
IF I>1
SET LOW=1
SET Y(I)=$$CASE($GET(ND(I)))
KILL LOW
+4 DO FMT
+5 QUIT
+6 ;
EXP(X) ; Get Case for Expression X = IEN in 757.01
+1 NEW IEN,IEN,TXT,IN
SET IEN=$GET(X)
SET (TXT,IN)=$GET(^LEX(757.01,+IEN,0))
IF '$LENGTH(TXT)
QUIT
KILL PAR
SET (TXT,X)=$$CASE(TXT)
IF '$LENGTH(X)
SET X=IN
+2 QUIT X
CASE(X) ; Get Case for String X = String of Text
+1 KILL PAR
NEW C,CHR,CT,LEXIN,LEXCTL,LEXCHR,I,L,PH,REM,STO,STR,TRL,TXT,W,WD,UIN,OIN,LEXPRE,LEXORG,LEXNXT,LEXUSE
+2 SET OIN=$$TRIM($GET(X))
SET (UIN,STR)=$$UP(OIN)
IF '$LENGTH(STR)
QUIT X
SET STR=$$SW1(STR)
SET L=$LENGTH(STR)
SET PAR(0)=0
SET (LEXIN,PAR("T",1))=STR
+3 SET TRL=""
FOR
IF $EXTRACT(STR,$LENGTH(STR))'?1P
QUIT
SET TRL=$EXTRACT(STR,$LENGTH(STR))_TRL
SET STR=$EXTRACT(STR,1,($LENGTH(STR)-1))
+4 SET PAR("TRL")=$GET(TRL)
SET I=0
FOR
IF I>L
QUIT
IF '$LENGTH(STR)
QUIT
Begin DoDot:1
+5 SET I=I+1
IF I=$LENGTH(STR)
Begin DoDot:2
+6 SET CT=$ORDER(PAR(" "),-1)+1
SET (STO,PAR(CT))=STR
SET PAR(0)=CT
SET STR=""
+7 SET PH=$GET(PAR((CT-1),"C"))_$GET(PAR(CT))_$GET(PAR(CT,"C"))
SET PAR(CT,"A")=PH
+8 SET LEXIN=$GET(PAR("T",1))
SET LEXCTL=$GET(PAR(CT,"A"))
SET LEXCHR=$GET(PAR(CT,"C"))
+9 FOR W=1:1:$LENGTH(STO," ")
Begin DoDot:3
+10 NEW NWD
SET WD=$PIECE(STO," ",W)
SET LEXORG=$GET(PAR(CT,"W",(+($GET(W))-1)))
SET LEXPRE=$$UP(LEXORG)
+11 SET LEXNXT=""
SET NWD=$$GETC(WD)
SET PAR(CT,"W",W)=NWD
End DoDot:3
End DoDot:2
QUIT
+12 SET C=$EXTRACT(STR,I)
+13 IF C?1P&(C'=" ")
Begin DoDot:2
+14 IF C="("
SET C=" ("
IF C="["
SET C=" ["
IF C="&"
SET C=" &"
+15 NEW REM,STO
SET CT=$ORDER(PAR(" "),-1)+1
SET (STO,PAR(CT))=$EXTRACT(STR,1,(I-1))
SET PAR(0)=CT
+16 SET PH=$GET(PAR(CT-1,"C"))_$GET(PAR(CT))_$GET(PAR(CT,"C"))
SET PAR(CT,"A")=PH
+17 SET LEXIN=$GET(PAR("T",1))
SET LEXCTL=$GET(PAR(CT,"A"))
SET LEXCHR=C
+18 FOR W=1:1:$LENGTH(STO," ")
Begin DoDot:3
+19 NEW NWD
SET WD=$PIECE(STO," ",W)
SET LEXPRE=$$UP($GET(PAR(CT,"W",(+($GET(W))-1))))
+20 SET NWD=$$GETC(WD)
SET PAR(CT,"W",W)=NWD
End DoDot:3
+21 SET (REM,STR)=$EXTRACT(STR,I+1,$LENGTH(STR))
SET I=0
+22 FOR
IF $EXTRACT(STR,1)'=" "
QUIT
SET C=C_" "
SET (REM,STR)=$EXTRACT(STR,2,$LENGTH(STR))
+23 SET PAR(CT,"C")=C
End DoDot:2
End DoDot:1
IF '$LENGTH(STR)
QUIT
+24 SET TXT=""
SET CT=0
FOR
SET CT=$ORDER(PAR(CT))
IF +CT'>0
QUIT
Begin DoDot:1
+25 NEW STR,TR
SET STR=""
SET TR=$GET(PAR(CT,"C"))
SET W=0
FOR
SET W=$ORDER(PAR(CT,"W",W))
IF +W'>0
QUIT
SET STR=STR_" "_$GET(PAR(CT,"W",W))
+26 SET STR=$$TRIM(STR)_TR
SET PAR(CT,"B")=STR
+27 SET TXT=TXT_STR
KILL PAR(CT)
End DoDot:1
+28 SET TXT=TXT_$GET(PAR("TRL"))
SET X=$$SW3(TXT)
KILL PAR
FOR CHR="-","+"
Begin DoDot:1
+29 IF UIN[(" "_CHR)
IF X[CHR
IF X'[(" "_CHR)
Begin DoDot:2
+30 NEW TXT
SET TXT=$PIECE(X,CHR,1)
FOR I=2:1
IF '$LENGTH($PIECE(X,CHR,I))
QUIT
SET TXT=TXT_(" "_CHR)_$PIECE(X,CHR,I)
+31 SET X=TXT
End DoDot:2
End DoDot:1
+32 SET X=$$FN(X)
SET X=$$DBL(X)
FOR CHR="~","!","@","#","$","^","&","*","_","-","+","=","|","\",";",":",",","."
SET X=$$TM(X,CHR)
+33 QUIT X
GETC(X) ; Set to Mixed/lower/UPPER case
+1 NEW LEXTAG,LEXRTN,LEXLEN,Y
IF $LENGTH($GET(X))'>0
QUIT X
SET X=$$UP($GET(X))
SET Y=""
SET LEXLEN=$LENGTH(X)
IF LEXLEN>12
SET LEXLEN=12
+2 SET LEXUSE=$$UP($$USE)
SET LEXNXT=$$TP($$TM($PIECE($GET(UIN),LEXUSE,2,299)))
+3 SET LEXTAG="T"_$LENGTH(X)
SET LEXRTN="LEXXM"_$LENGTH(X)
+4 IF $LENGTH($GET(X))>9
SET LEXTAG="TM"
IF $LENGTH($GET(X))>5
SET LEXRTN="LEXXM6"
SET LEXRTN=LEXTAG_"^"_LEXRTN
DO @LEXRTN
IF $LENGTH(Y)
SET X=$$SW2(Y)
QUIT X
+5 SET X=$$MX(X)
+6 QUIT X
+7 ;
SW1(X) ; Switch Text (before setting case)
+1 SET X=$$SW1^LEXXMM($GET(X))
QUIT X
SW2(X) ; Switch Text (after setting case)
+1 SET X=$$SW2^LEXXMM($GET(X))
QUIT X
SW3(X) ; Switch Text (after assembling string)
+1 SET X=$$SW3^LEXXMM($GET(X))
QUIT X
EW(X) ; Display Word Usage
+1 DO EW^LEXXMM($GET(X))
QUIT
+2 ;
USE(X) ; Used
+1 NEW STR,SEG,CUR
SET STR=""
SET SEG=0
FOR
SET SEG=$ORDER(PAR(SEG))
IF +SEG'>0
QUIT
Begin DoDot:1
+2 NEW WC
SET WC=0
FOR
SET WC=$ORDER(PAR(SEG,"W",WC))
IF +WC'>0
QUIT
Begin DoDot:2
+3 NEW WD
SET WD=$$UP($GET(PAR(SEG,"W",WC)))
+4 IF $EXTRACT(STR,$LENGTH(STR))?1A!($EXTRACT(STR,$LENGTH(STR))?1N)
SET STR=$GET(STR)_" "_WD
+5 IF $EXTRACT(STR,$LENGTH(STR))'?1A&($EXTRACT(STR,$LENGTH(STR))'?1N)
SET STR=$GET(STR)_WD
End DoDot:2
+6 IF $LENGTH($GET(PAR(SEG,"C")))
SET STR=STR_$GET(PAR(SEG,"C"))
End DoDot:1
+7 SET CUR=$GET(WD)
IF $LENGTH(CUR)
Begin DoDot:1
+8 IF $EXTRACT(STR,$LENGTH(STR))?1A!($EXTRACT(STR,$LENGTH(STR))?1N)
SET STR=$GET(STR)_" "_CUR
+9 IF $EXTRACT(STR,$LENGTH(STR))'?1A&($EXTRACT(STR,$LENGTH(STR))'?1N)
SET STR=$GET(STR)_CUR
End DoDot:1
+10 SET X=$$TM(STR)
+11 QUIT X
+12 ;WD="COMPLICATED"
+13 QUIT X
FMT ; Format Line Length - needs Y() and LEN
+1 IF $ORDER(Y(0))'>0
QUIT
IF +($GET(LEN))'>0
QUIT
IF +($GET(LEN))'>19
QUIT
IF +($GET(LEN))>79
QUIT
NEW I,J,X,D,DIW,DIWF,DIWL,DIWI,DIWR,DIWT,DIWTC,DIWX,DN,Z,L
+2 KILL ^UTILITY($JOB,"W")
SET DIWL=0
SET DIWF="C"_+($GET(LEN))
FOR J=0:0
SET J=$ORDER(Y(J))
IF 'J
QUIT
SET X=Y(J)
DO ^DIWP
+3 KILL Y
FOR J=0:0
SET J=$ORDER(^UTILITY($JOB,"W",0,J))
IF 'J
QUIT
SET Y(J)=$$TRIM($GET(^UTILITY($JOB,"W",0,J,0)))
+4 KILL ^UTILITY($JOB,"W")
+5 QUIT
FN(X) ; Footnote Removed
+1 SET X=$GET(X)
IF X'[")"
QUIT X
NEW ORG,FIR,LAS,TRM,L,NUM,OUT,REP,WTH
SET (OUT,ORG)=X
SET L=$LENGTH(X,")")
SET FIR=$PIECE(X,")",1,(L-1))_")"
SET LAS=$PIECE(X,")",L)
SET TRM=$$TRIM(LAS)
SET X=ORG
IF TRM=LAS
IF $EXTRACT(LAS,1)?1N
IF +LAS=LAS
SET OUT=FIR
+2 FOR NUM=1:1:9
SET REP=")"_NUM_" "
SET WTH=") "
IF OUT[REP
SET OUT=$$SWAP^LEXXMM(OUT,REP,WTH)
+3 SET X=OUT
+4 QUIT X
LO(X) ; Lower Case
+1 QUIT $TRANSLATE(X,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
UP(X) ; Upper Case
+1 QUIT $TRANSLATE(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
MX(X) ; Mixed Case
+1 QUIT $TRANSLATE($EXTRACT(X,1),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")_$TRANSLATE($EXTRACT(X,2,$LENGTH(X)),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")
LD(X) ; Leading Character
+1 QUIT $TRANSLATE($EXTRACT(X,1),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")_$EXTRACT(X,2,$LENGTH(X))
TRIM(X) ; Trim Spaces
+1 SET X=$GET(X)
FOR
IF $EXTRACT(X,1)'=" "
QUIT
SET X=$EXTRACT(X,2,$LENGTH(X))
+2 FOR
IF $EXTRACT(X,$LENGTH(X))'=" "
QUIT
SET X=$EXTRACT(X,1,($LENGTH(X)-1))
+3 QUIT X
TP(X) ; Trim Punctuation
+1 SET X=$GET(X)
IF '$LENGTH(X)
QUIT X
FOR
IF $EXTRACT(X,1)'?1P
QUIT
SET X=$EXTRACT(X,2,$LENGTH(X))
+2 FOR
IF $EXTRACT(X,$LENGTH(X))'?1P
QUIT
SET X=$EXTRACT(X,1,($LENGTH(X)-1))
+3 QUIT X
TM(X,Y) ; Trim Character Y - Default " "
+1 SET X=$GET(X)
SET Y=$GET(Y)
IF $LENGTH(Y)&(X'[Y)
QUIT X
SET X=$GET(X)
IF X=""
QUIT X
SET Y=$GET(Y)
IF '$LENGTH(Y)
SET Y=" "
FOR
IF $EXTRACT(X,1)'=Y
QUIT
SET X=$EXTRACT(X,2,$LENGTH(X))
+2 FOR
IF $EXTRACT(X,$LENGTH(X))'=Y
QUIT
SET X=$EXTRACT(X,1,($LENGTH(X)-1))
+3 QUIT X
DBL(X) ; Double Spaces
+1 SET X=$GET(X)
FOR
IF X'[" "
QUIT
SET X=$PIECE(X," ",1)_" "_$PIECE(X," ",2,299)
+2 SET X=$$TRIM(X)
+3 QUIT X