ETSLNCIX ;O-OIFO/FM23 - ETS LOINC Set/Kill Index Utilities ;01/31/2017
 ;;1.0;Enterprise Terminology Service;**1**;Mar 20, 2017;Build 7
 ;;Per VA Directive 6402, this routine should not be modified.
 ;
 Q
 ;
SETLNC(ETSTEXT,ETSIEN) ; Set Long Common Name (129.1, #83) word index node D
 ;Standard Indexing input checks
 Q:'$D(ETSTEXT)!('$D(ETSIEN))
 ;
 ;New and initialize variables
 N ETSWORD,ETSLP,ETSLN
 ;
 ;Format the text string for parsing and indexing
 S ETSTEXT=$$PREPTEXT(ETSTEXT)
 S ETSLN=$L(ETSTEXT," ")
 ;
 ;Parse and index the text string
 F ETSLP=1:1:ETSLN D
 . S ETSWORD=$P(ETSTEXT," ",ETSLP)
 . Q:ETSWORD=""
 . S:'$D(^ETSLNC(129.1,"D",ETSWORD,ETSIEN)) ^ETSLNC(129.1,"D",ETSWORD,ETSIEN)=""
 ;
 ;Exit the indexing
 Q
 ;
KILLLNC(ETSTEXT,ETSIEN) ; Set Long Common Name (129.1, #83) word index node AWRD
 ;Standard Indexing input checks
 Q:'$D(ETSTEXT)!('$D(ETSIEN))
 ;
 ;New and initialize variables
 N ETSWORD,ETSLP,ETSLN
 ;
 ;Format the text string for parsing and indexing
 S ETSTEXT=$$PREPTEXT(ETSTEXT)
 S ETSLN=$L(ETSTEXT," ")
 ;
 ;Parse and remove the string from the index
 F ETSLP=1:1:ETSLN D
 . S ETSWORD=$P(ETSTEXT," ",ETSLP)
 . Q:ETSWORD=""
 . K:$D(^ETSLNC(129.1,"D",ETSWORD,ETSIEN)) ^ETSLNC(129.1,"D",ETSWORD,ETSIEN)
 ;
 Q
 ;
PREPTEXT(ETSTEXT) ;Prepare the Text for Indexing by
 ;  - excluding certain words (a, the, in, etc.)
 ;  - stop indexing when the [ or words IN, BY, or ON are reached
 ;  - strip terms that are punctuation only
 ;
 N ETSCT,ETSLP,ETSTERM,ETSNTEXT,ETSRM,ETSFLG,ETSWORD
 ;
 ;Note: ETSTEXT already validated as existing before 
 ;      coming to PREPTEXT
 ;
 ;Upper case the text string to check
 S ETSTEXT=$$UP^XLFSTR(ETSTEXT)
 ;
 S ETSCT=$L(ETSTEXT," ")
 ;
 ; Identify terms to remove
 S ETSFLG=0
 F ETSLP=1:1:ETSCT D  Q:ETSFLG
 . S ETSTERM=$P(ETSTEXT," ",ETSLP)
 . Q:ETSTERM=""
 . ;flag punctuation remove all punctuation
 . I ETSTERM?1.P S ETSRM(ETSLP)="" Q
 . ;flag excluded terms for removal
 . I $$EXCLUDED(ETSTERM) S ETSRM(ETSLP)="" Q
 . ;if term a stop term, set stop flag, reset text string and exit
 . I $E(ETSTERM,1)="[" S ETSFLG=1,ETSTEXT=$P(ETSTEXT," ",1,ETSLP-1) Q
 . I ETSTERM="BY" S ETSFLG=1,ETSTEXT=$P(ETSTEXT," ",1,ETSLP-1) Q
 . I ETSTERM="IN" S ETSFLG=1,ETSTEXT=$P(ETSTEXT," ",1,ETSLP-1) Q
 . I ETSTERM="ON" S ETSFLG=1,ETSTEXT=$P(ETSTEXT," ",1,ETSLP-1)
 ;
 ; Create text string with terms removed
 S ETSNTEXT=""
 ;
 ; Reset the Text Length Counter
 S ETSCT=$L(ETSTEXT," ")
 F ETSLP=1:1:ETSCT D
 . ;Add term to new string if not identified for removal
 . Q:$D(ETSRM(ETSLP))
 . S ETSWORD=$P(ETSTEXT," ",ETSLP)
 . Q:ETSWORD=""
 . S ETSNTEXT=ETSNTEXT_ETSWORD
 . ;Add space if not the last term in the text string
 . I ETSLP'=ETSCT S ETSNTEXT=ETSNTEXT_" "
 ;
 ; clean up string if last term was ignored or NULL
 S:$P(ETSNTEXT," ",$L(ETSNTEXT," "))="" ETSNTEXT=$P(ETSNTEXT," ",1,$L(ETSNTEXT," ")-1)
 ;
 ; Exit with new string
 Q ETSNTEXT
 ;
EXCLUDED(ETSTERM) ;Exclude certain terms
 ;
 ;If in Excluded Words - LOINC dictionary (129.4)
 ; then return true
 Q:$D(^ETSLNC(129.14,"B",ETSTERM)) 1
 ;
 ;else return false
 Q 0
 ;
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HETSLNCIX   3186     printed  Sep 23, 2025@19:30:13                                                                                                                                                                                                    Page 2
ETSLNCIX  ;O-OIFO/FM23 - ETS LOINC Set/Kill Index Utilities ;01/31/2017
 +1       ;;1.0;Enterprise Terminology Service;**1**;Mar 20, 2017;Build 7
 +2       ;;Per VA Directive 6402, this routine should not be modified.
 +3       ;
 +4        QUIT 
 +5       ;
SETLNC(ETSTEXT,ETSIEN) ; Set Long Common Name (129.1, #83) word index node D
 +1       ;Standard Indexing input checks
 +2        if '$DATA(ETSTEXT)!('$DATA(ETSIEN))
               QUIT 
 +3       ;
 +4       ;New and initialize variables
 +5        NEW ETSWORD,ETSLP,ETSLN
 +6       ;
 +7       ;Format the text string for parsing and indexing
 +8        SET ETSTEXT=$$PREPTEXT(ETSTEXT)
 +9        SET ETSLN=$LENGTH(ETSTEXT," ")
 +10      ;
 +11      ;Parse and index the text string
 +12       FOR ETSLP=1:1:ETSLN
               Begin DoDot:1
 +13               SET ETSWORD=$PIECE(ETSTEXT," ",ETSLP)
 +14               if ETSWORD=""
                       QUIT 
 +15               if '$DATA(^ETSLNC(129.1,"D",ETSWORD,ETSIEN))
                       SET ^ETSLNC(129.1,"D",ETSWORD,ETSIEN)=""
               End DoDot:1
 +16      ;
 +17      ;Exit the indexing
 +18       QUIT 
 +19      ;
KILLLNC(ETSTEXT,ETSIEN) ; Set Long Common Name (129.1, #83) word index node AWRD
 +1       ;Standard Indexing input checks
 +2        if '$DATA(ETSTEXT)!('$DATA(ETSIEN))
               QUIT 
 +3       ;
 +4       ;New and initialize variables
 +5        NEW ETSWORD,ETSLP,ETSLN
 +6       ;
 +7       ;Format the text string for parsing and indexing
 +8        SET ETSTEXT=$$PREPTEXT(ETSTEXT)
 +9        SET ETSLN=$LENGTH(ETSTEXT," ")
 +10      ;
 +11      ;Parse and remove the string from the index
 +12       FOR ETSLP=1:1:ETSLN
               Begin DoDot:1
 +13               SET ETSWORD=$PIECE(ETSTEXT," ",ETSLP)
 +14               if ETSWORD=""
                       QUIT 
 +15               if $DATA(^ETSLNC(129.1,"D",ETSWORD,ETSIEN))
                       KILL ^ETSLNC(129.1,"D",ETSWORD,ETSIEN)
               End DoDot:1
 +16      ;
 +17       QUIT 
 +18      ;
PREPTEXT(ETSTEXT) ;Prepare the Text for Indexing by
 +1       ;  - excluding certain words (a, the, in, etc.)
 +2       ;  - stop indexing when the [ or words IN, BY, or ON are reached
 +3       ;  - strip terms that are punctuation only
 +4       ;
 +5        NEW ETSCT,ETSLP,ETSTERM,ETSNTEXT,ETSRM,ETSFLG,ETSWORD
 +6       ;
 +7       ;Note: ETSTEXT already validated as existing before 
 +8       ;      coming to PREPTEXT
 +9       ;
 +10      ;Upper case the text string to check
 +11       SET ETSTEXT=$$UP^XLFSTR(ETSTEXT)
 +12      ;
 +13       SET ETSCT=$LENGTH(ETSTEXT," ")
 +14      ;
 +15      ; Identify terms to remove
 +16       SET ETSFLG=0
 +17       FOR ETSLP=1:1:ETSCT
               Begin DoDot:1
 +18               SET ETSTERM=$PIECE(ETSTEXT," ",ETSLP)
 +19               if ETSTERM=""
                       QUIT 
 +20      ;flag punctuation remove all punctuation
 +21               IF ETSTERM?1.P
                       SET ETSRM(ETSLP)=""
                       QUIT 
 +22      ;flag excluded terms for removal
 +23               IF $$EXCLUDED(ETSTERM)
                       SET ETSRM(ETSLP)=""
                       QUIT 
 +24      ;if term a stop term, set stop flag, reset text string and exit
 +25               IF $EXTRACT(ETSTERM,1)="["
                       SET ETSFLG=1
                       SET ETSTEXT=$PIECE(ETSTEXT," ",1,ETSLP-1)
                       QUIT 
 +26               IF ETSTERM="BY"
                       SET ETSFLG=1
                       SET ETSTEXT=$PIECE(ETSTEXT," ",1,ETSLP-1)
                       QUIT 
 +27               IF ETSTERM="IN"
                       SET ETSFLG=1
                       SET ETSTEXT=$PIECE(ETSTEXT," ",1,ETSLP-1)
                       QUIT 
 +28               IF ETSTERM="ON"
                       SET ETSFLG=1
                       SET ETSTEXT=$PIECE(ETSTEXT," ",1,ETSLP-1)
               End DoDot:1
               if ETSFLG
                   QUIT 
 +29      ;
 +30      ; Create text string with terms removed
 +31       SET ETSNTEXT=""
 +32      ;
 +33      ; Reset the Text Length Counter
 +34       SET ETSCT=$LENGTH(ETSTEXT," ")
 +35       FOR ETSLP=1:1:ETSCT
               Begin DoDot:1
 +36      ;Add term to new string if not identified for removal
 +37               if $DATA(ETSRM(ETSLP))
                       QUIT 
 +38               SET ETSWORD=$PIECE(ETSTEXT," ",ETSLP)
 +39               if ETSWORD=""
                       QUIT 
 +40               SET ETSNTEXT=ETSNTEXT_ETSWORD
 +41      ;Add space if not the last term in the text string
 +42               IF ETSLP'=ETSCT
                       SET ETSNTEXT=ETSNTEXT_" "
               End DoDot:1
 +43      ;
 +44      ; clean up string if last term was ignored or NULL
 +45       if $PIECE(ETSNTEXT," ",$LENGTH(ETSNTEXT," "))=""
               SET ETSNTEXT=$PIECE(ETSNTEXT," ",1,$LENGTH(ETSNTEXT," ")-1)
 +46      ;
 +47      ; Exit with new string
 +48       QUIT ETSNTEXT
 +49      ;
EXCLUDED(ETSTERM) ;Exclude certain terms
 +1       ;
 +2       ;If in Excluded Words - LOINC dictionary (129.4)
 +3       ; then return true
 +4        if $DATA(^ETSLNC(129.14,"B",ETSTERM))
               QUIT 1
 +5       ;
 +6       ;else return false
 +7        QUIT 0
 +8       ;