AICDKWL1 ; IHS/OHPRD/ACC - PART 2 OF LOOKUP CONTROL PROGRAM FOR "AND"ING INVERTED SEARCH ;
;;4.0;AICD;;DEC 03, 2014;Build 7
NOTSHRT D ^AICDTOKN
D CHKREP
K AICDWORD,AICDDFN,AICDAWRD,AICDADFN,AICDNUSE S AICDNUSE=0
D PREPSCH^AICDKWL2
I AICDNWDS=0 W:AICDASK "Narrative contained no useable words.",! G:'AICDNUSE NOTSHRTX
I AICDNUSE,AICDNWDS W:AICDASK !,"The following word",$S(AICDNUSE=1:" was",1:"s were")," not used in this search:",! S AICDWD="" F AICDQ=0:0 S AICDWD=$O(AICDNUSE(AICDWD)) Q:AICDWD="" W:AICDASK ?5,AICDWD,!
NOTSHRTX K AICDNUSE
K ^UTILITY("AICDHITS",$J) S ^UTILITY("AICDHITS",$J)=0 D:AICDNWDS ^AICDKSCH
I ^UTILITY("AICDHITS",$J)=0 W:AICDASK "Search was unsuccessful.",! S Y=-1 G EXIT
G VERIFY
CHKREP ;
S AICDWORD="" F S AICDWORD=$O(AICDWT(AICDWORD)) Q:AICDWORD="" S AICDDFN=$O(^AICDKWLC(AICDKWCT,2,"B",AICDWORD,0)) D:AICDDFN CHKREP2
K AICDREP,AICDREPT
Q
CHKREP2 K AICDWT(AICDWORD)
S AICDREP=$P(^AICDKWLC(AICDKWCT,2,AICDDFN,0),U,2)
F D CHKREP3 Q:AICDREPT="" S AICDWT(AICDREPT)=""
Q
CHKREP3 F Q:$E(AICDREP)'=" " S AICDREP=$E(AICDREP,2,$L(AICDREP))
S AICDREPI=$F(AICDREP," ")
I AICDREPI S AICDREPT=$E(AICDREP,1,AICDREPI-2),AICDREP=$E(AICDREP,AICDREPI,$L(AICDREP))
E S AICDREPT=AICDREP,AICDREP=""
Q
VERIFY ;
S Y=-1
I ^UTILITY("AICDHITS",$J)=1 D ASKONE G VERIFY2
D:AICDASK ASKSEL:^UTILITY("AICDHITS",$J)>1
VERIFY2 I +Y>0,$D(^DD(+$P(@(AICDGBL_"0)"),U,2),0,"ACT")) X ^("ACT")
I +Y>0,$D(@(AICDREF1_(+Y)_",0)"))#2 S Y=+Y_U_$P(^(0),U,1)
EXIT ;
;IHS/BAO/TMD - 3/13/2005 - modified next line to not kill hits
;K ^UTILITY("AICDHITS",$J)
EXIT2 ;
K AICDWD,AICDNWDS,AICDKWCT,AICDI,AICDQ
K AICDREF,AICDREF0,AICDREF1,AICDREF2,AICDREF3,AICDREF4
K AICDGBL,AICDT,AICDL,AICDKSCH,AICDX,AICDASK
S X=AICDXSAV K AICDXSAV
Q
;
ASKONE ; ASK IF SINGLE HIT IS ACCEPTABLE
I $P(@(AICDKSCH("GBL")_"0)"),U,2)'["O" G ASKONEOK
G:'AICDASK ASKONEOK
W !
S AICDH=1,AICDMULT=0
D DSPLY
F AICDQ=0:0 R " OK? Y// ",X:$S($D(DTIME):DTIME,1:300),! S:'$T X="^" S X=$E(X_"Y") S:X?1L X=$C($A(X)-32) Q:"^YN"[X W $C(7)
K Y
I "^N"[X S Y=-1 G ASKONEX
ASKONEOK S Y=^UTILITY("AICDHITS",$J,1) I $D(DIC(0))#2,DIC(0)["Z" S AICDH=1,Y(0)=@AICDREF3 ;*4*
ASKONEX K AICDH,AICDMULT,AICDDESC,AICDF
Q
;
ASKSEL ; ASK FOR SELECTION AMONG HITS
W !!,"The following matches were found:",!!
S AICDMULT=1,AICDGRP=1
DSPGRP S AICDH2=$S((AICDGRP+4)'>^UTILITY("AICDHITS",$J):AICDGRP+4,1:^UTILITY("AICDHITS",$J))
F AICDH=AICDGRP:1:AICDH2 D DSPLY
W !
F AICDQ=0:0 W "Select 1-",^UTILITY("AICDHITS",$J),": " R X:$S($D(DTIME):DTIME,1:300),! S:'$T X="^" Q:X["^"!(X="")!(X="-") Q:X?1N.N&(X>0)&(X'>^UTILITY("AICDHITS",$J)) W $C(7)
I X="" S AICDGRP=$S((AICDGRP+5)'>^UTILITY("AICDHITS",$J):AICDGRP+5,1:1) G DSPGRP
I X="-" S AICDGRP=$S(AICDGRP'=1:AICDGRP-5,1:^UTILITY("AICDHITS",$J)-1\5*5+1) G DSPGRP
I X?1"^"1N.N S AICDI=($E(X,2,255)-1)\5*5+1 I AICDI'>^UTILITY("AICDHITS",$J) S AICDGRP=AICDI G DSPGRP
I X["^" S Y=-1
E S AICDH=X,Y=^UTILITY("AICDHITS",$J,AICDH) I $D(DIC(0))#2,DIC(0)["Z" S Y(0)=@AICDREF3
K AICDH,AICDMULT,AICDH2,AICDGRP,AICDDESC,AICDF
Q
;
DSPLY ; DISPLAY CODE AND TEXT
S AICDI=^UTILITY("AICDHITS",$J,AICDH)
S AICDREF0=AICDREF1_AICDI_",0)"
I $D(AICDKSCH("DSPLY")) D @AICDKSCH("DSPLY") Q
W:AICDMULT $J(AICDH,4),": "
W $P(@(AICDREF1_"AICDI,0)"),"^",1),!
S AICDDESC="<display protocol not provided>"
DSPDESC F %=0:0 Q:AICDDESC="" D GETFRAG W:AICDMULT ?7 W AICDF,!
W !
K AICDC,AICDF
Q
GETFRAG I $L(AICDDESC)<72 S AICDF=AICDDESC,AICDDESC="" Q
F AICDC=73:-1:1 Q:$E(AICDDESC,AICDC)=" "
S AICDF=$E(AICDDESC,1,AICDC-1),AICDDESC=$E(AICDDESC,AICDC+1,255)
Q
AICDKWL1 ; IHS/OHPRD/ACC - PART 2 OF LOOKUP CONTROL PROGRAM FOR "AND"ING INVERTED SEARCH ;
+1 ;;4.0;AICD;;DEC 03, 2014;Build 7
NOTSHRT DO ^AICDTOKN
+1 DO CHKREP
+2 KILL AICDWORD,AICDDFN,AICDAWRD,AICDADFN,AICDNUSE
SET AICDNUSE=0
+3 DO PREPSCH^AICDKWL2
+4 IF AICDNWDS=0
IF AICDASK
WRITE "Narrative contained no useable words.",!
IF 'AICDNUSE
GOTO NOTSHRTX
+5 IF AICDNUSE
IF AICDNWDS
IF AICDASK
WRITE !,"The following word",$SELECT(AICDNUSE=1:" was",1:"s were")," not used in this search:",!
SET AICDWD=""
FOR AICDQ=0:0
SET AICDWD=$ORDER(AICDNUSE(AICDWD))
IF AICDWD=""
QUIT
IF AICDASK
WRITE ?5,AICDWD,!
NOTSHRTX KILL AICDNUSE
+1 KILL ^UTILITY("AICDHITS",$JOB)
SET ^UTILITY("AICDHITS",$JOB)=0
IF AICDNWDS
DO ^AICDKSCH
+2 IF ^UTILITY("AICDHITS",$JOB)=0
IF AICDASK
WRITE "Search was unsuccessful.",!
SET Y=-1
GOTO EXIT
+3 GOTO VERIFY
CHKREP ;
+1 SET AICDWORD=""
FOR
SET AICDWORD=$ORDER(AICDWT(AICDWORD))
IF AICDWORD=""
QUIT
SET AICDDFN=$ORDER(^AICDKWLC(AICDKWCT,2,"B",AICDWORD,0))
IF AICDDFN
DO CHKREP2
+2 KILL AICDREP,AICDREPT
+3 QUIT
CHKREP2 KILL AICDWT(AICDWORD)
+1 SET AICDREP=$PIECE(^AICDKWLC(AICDKWCT,2,AICDDFN,0),U,2)
+2 FOR
DO CHKREP3
IF AICDREPT=""
QUIT
SET AICDWT(AICDREPT)=""
+3 QUIT
CHKREP3 FOR
IF $EXTRACT(AICDREP)'=" "
QUIT
SET AICDREP=$EXTRACT(AICDREP,2,$LENGTH(AICDREP))
+1 SET AICDREPI=$FIND(AICDREP," ")
+2 IF AICDREPI
SET AICDREPT=$EXTRACT(AICDREP,1,AICDREPI-2)
SET AICDREP=$EXTRACT(AICDREP,AICDREPI,$LENGTH(AICDREP))
+3 IF '$TEST
SET AICDREPT=AICDREP
SET AICDREP=""
+4 QUIT
VERIFY ;
+1 SET Y=-1
+2 IF ^UTILITY("AICDHITS",$JOB)=1
DO ASKONE
GOTO VERIFY2
+3 IF AICDASK
IF ^UTILITY("AICDHITS",$JOB)>1
DO ASKSEL
VERIFY2 IF +Y>0
IF $DATA(^DD(+$PIECE(@(AICDGBL_"0)"),U,2),0,"ACT"))
XECUTE ^("ACT")
+1 IF +Y>0
IF $DATA(@(AICDREF1_(+Y)_",0)"))#2
SET Y=+Y_U_$PIECE(^(0),U,1)
EXIT ;
+1 ;IHS/BAO/TMD - 3/13/2005 - modified next line to not kill hits
+2 ;K ^UTILITY("AICDHITS",$J)
EXIT2 ;
+1 KILL AICDWD,AICDNWDS,AICDKWCT,AICDI,AICDQ
+2 KILL AICDREF,AICDREF0,AICDREF1,AICDREF2,AICDREF3,AICDREF4
+3 KILL AICDGBL,AICDT,AICDL,AICDKSCH,AICDX,AICDASK
+4 SET X=AICDXSAV
KILL AICDXSAV
+5 QUIT
+6 ;
ASKONE ; ASK IF SINGLE HIT IS ACCEPTABLE
+1 IF $PIECE(@(AICDKSCH("GBL")_"0)"),U,2)'["O"
GOTO ASKONEOK
+2 IF 'AICDASK
GOTO ASKONEOK
+3 WRITE !
+4 SET AICDH=1
SET AICDMULT=0
+5 DO DSPLY
+6 FOR AICDQ=0:0
READ " OK? Y// ",X:$SELECT($DATA(DTIME):DTIME,1:300),!
IF '$TEST
SET X="^"
SET X=$EXTRACT(X_"Y")
IF X?1L
SET X=$CHAR($ASCII(X)-32)
IF "^YN"[X
QUIT
WRITE $CHAR(7)
+7 KILL Y
+8 IF "^N"[X
SET Y=-1
GOTO ASKONEX
ASKONEOK ;*4*
SET Y=^UTILITY("AICDHITS",$JOB,1)
IF $DATA(DIC(0))#2
IF DIC(0)["Z"
SET AICDH=1
SET Y(0)=@AICDREF3
ASKONEX KILL AICDH,AICDMULT,AICDDESC,AICDF
+1 QUIT
+2 ;
ASKSEL ; ASK FOR SELECTION AMONG HITS
+1 WRITE !!,"The following matches were found:",!!
+2 SET AICDMULT=1
SET AICDGRP=1
DSPGRP SET AICDH2=$SELECT((AICDGRP+4)'>^UTILITY("AICDHITS",$JOB):AICDGRP+4,1:^UTILITY("AICDHITS",$JOB))
+1 FOR AICDH=AICDGRP:1:AICDH2
DO DSPLY
+2 WRITE !
+3 FOR AICDQ=0:0
WRITE "Select 1-",^UTILITY("AICDHITS",$JOB),": "
READ X:$SELECT($DATA(DTIME):DTIME,1:300),!
IF '$TEST
SET X="^"
IF X["^"!(X="")!(X="-")
QUIT
IF X?1N.N&(X>0)&(X'>^UTILITY("AICDHITS",$JOB))
QUIT
WRITE $CHAR(7)
+4 IF X=""
SET AICDGRP=$SELECT((AICDGRP+5)'>^UTILITY("AICDHITS",$JOB):AICDGRP+5,1:1)
GOTO DSPGRP
+5 IF X="-"
SET AICDGRP=$SELECT(AICDGRP'=1:AICDGRP-5,1:^UTILITY("AICDHITS",$JOB)-1\5*5+1)
GOTO DSPGRP
+6 IF X?1"^"1N.N
SET AICDI=($EXTRACT(X,2,255)-1)\5*5+1
IF AICDI'>^UTILITY("AICDHITS",$JOB)
SET AICDGRP=AICDI
GOTO DSPGRP
+7 IF X["^"
SET Y=-1
+8 IF '$TEST
SET AICDH=X
SET Y=^UTILITY("AICDHITS",$JOB,AICDH)
IF $DATA(DIC(0))#2
IF DIC(0)["Z"
SET Y(0)=@AICDREF3
+9 KILL AICDH,AICDMULT,AICDH2,AICDGRP,AICDDESC,AICDF
+10 QUIT
+11 ;
DSPLY ; DISPLAY CODE AND TEXT
+1 SET AICDI=^UTILITY("AICDHITS",$JOB,AICDH)
+2 SET AICDREF0=AICDREF1_AICDI_",0)"
+3 IF $DATA(AICDKSCH("DSPLY"))
DO @AICDKSCH("DSPLY")
QUIT
+4 IF AICDMULT
WRITE $JUSTIFY(AICDH,4),": "
+5 WRITE $PIECE(@(AICDREF1_"AICDI,0)"),"^",1),!
+6 SET AICDDESC="<display protocol not provided>"
DSPDESC FOR %=0:0
IF AICDDESC=""
QUIT
DO GETFRAG
IF AICDMULT
WRITE ?7
WRITE AICDF,!
+1 WRITE !
+2 KILL AICDC,AICDF
+3 QUIT
GETFRAG IF $LENGTH(AICDDESC)<72
SET AICDF=AICDDESC
SET AICDDESC=""
QUIT
+1 FOR AICDC=73:-1:1
IF $EXTRACT(AICDDESC,AICDC)=" "
QUIT
+2 SET AICDF=$EXTRACT(AICDDESC,1,AICDC-1)
SET AICDDESC=$EXTRACT(AICDDESC,AICDC+1,255)
+3 QUIT