ATSERCH4 ;TUCSON/DG;GETS STORED RESULTS FOR COMPARISON [ 10/25/91 1:31 PM ]
;;2.5;SEARCH TEMPLATE COMPARISON;;OCT 25, 1991
;
;
D ^ATSERCH3 ;GIVES USER CHANCE TO SAVE RESULTS IN A TEMPLATE
I ATSFLAG D EOJ Q
;IN CASE OF A LONG SEARCH WHERE USER MAY BE GONE AND A TIMEOUT
;KILLING THE MERGE RESULTS WOULD OCCUR
D ^ATSERCHD ;CALL TO SEE IF USER WANTS COMPARISON TO BE DONE
;VIA TASKMAN
I ATSTASK!(ATSFLAG) D EOJ Q
ZTM ;ENTRY POINT FOR TASKMAN
I $D(ZTQEUED) S ZTREQ="@" K ^UTILITY("ATSEARCH",$J)
W:'ATSTASK !!,"Please wait ..."
S ATSUB=1 D GET
S ATSUB=2 D GET
D MERGE
I ATSTASK,'$D(ATSETMP) D WRITE^ATSERCHG
I ATSRCSTR D SEARCH^ATSERCH3
D CHKMTCH^ATSERCHG
D EOJ
D:ATSTASK EOJ^ATSERCH
Q
;
GET ;GETS STORED RESULTS, PLACE IN ^UTILITY
S (ATSDFN,ATSEDOT,ATSEARCH(ATSUB,"COUNT"),ATSEARCH("MERGE COUNT"))=0
F L=0:0 S ATSDFN=$O(@(ATSEARCH(ATSUB,"SRCHRESLTREF")_ATSDFN_")")) Q:ATSDFN'=+ATSDFN D @$S($D(ATSEARCH(ATSUB,"PTEDTOFILE")):"GET3",1:"GET2")
Q
;
GET2 ;CONTINUATION OF FOR LOOP IN GET FOR A DATA FILE THAT IS NOT THE PTED
;TO FILE
S ATSENDPC=ATSEARCH(ATSUB,"DATAGLBLREF")_ATSDFN_","_ATSEARCH(ATSUB,"NODE")_")"
Q:'$D(@(ATSENDPC))&(ATSENLAG'=2)
I $D(@(ATSENDPC)) S ATSENDPC=$P(@(ATSENDPC),U,ATSEARCH(ATSUB,"PIECENUM")),ATSEFLY=""
Q:((ATSENDPC']"")!('$D(ATSEFLY)))&(ATSENLAG'=2)
S:((ATSENDPC']"")!('$D(ATSEFLY)))&(ATSENLAG=2) ATSENDPC="NULL"
S ^UTILITY("ATSEARCH",$J,ATSUB,ATSENDPC,ATSDFN)="",ATSEARCH(ATSUB,"COUNT")=ATSEARCH(ATSUB,"COUNT")+1
S ATSEDOT=ATSEDOT+1 W:'(ATSEDOT#20)&('ATSTASK) "."
Q
;
GET3 ;CONT. OF FOR LOOP IF FILE WITH SEARCH TEMPLATE LINKED TO
;IT ALSO THE POINTED TO FILE - FIELD IN FILE POINTED TO FILE MUST
;BE THE .01 FIELD OF THE FILE
S ^UTILITY("ATSEARCH",$J,ATSUB,ATSDFN,ATSDFN)="",ATSEARCH(ATSUB,"COUNT")=ATSEARCH(ATSUB,"COUNT")+1
S ATSEDOT=ATSEDOT+1 W:'(ATSEDOT#20)&('ATSTASK) "."
Q
;
MERGE ;FIRST TEMPLATE WITH LESSER COUNT, COMPARE TO TEMPLATE TWO
S (ATSPRIMY,ATSECDY)="^UTILITY(""ATSEARCH"",$J,"
I (ATSMTCH=1!(ATSMTCH="")),ATSEARCH(1,"COUNT")<ATSEARCH(2,"COUNT") S ATSPRIMY=ATSPRIMY_"1,",ATSECDY=ATSECDY_"2,"
E S:ATSMTCH=1!(ATSMTCH="") ATSPRIMY=ATSPRIMY_"2,",ATSECDY=ATSECDY_"1,"
I ATSMTCH'<2 S ATSPRIMY=$S(ATSMTCH=2:ATSPRIMY_"1,",1:ATSPRIMY_"2,"),ATSECDY=$S(ATSMTCH=2:ATSECDY_"2,",1:ATSECDY_"1,")
I $D(^UTILITY("ATSEARCH",$J,"MERGED")) D SETTEMP
K ^UTILITY("ATSEARCH",$J,"MERGED")
S ATSPTVAL=0 F L=0:0 S ATSPTVAL=$O(@(ATSPRIMY_""""_ATSPTVAL_""""_")")) Q:ATSPTVAL'=+ATSPTVAL&(ATSPTVAL'["NULL") D MERGE2
Q
;
MERGE2 ;CONT OF FOR LOOP
I @(ATSNOT_"$D(@(ATSECDY_""""""""_ATSPTVAL_""""""""_"")""))") D @$S(ATSEARCH("FILELINK")=ATSEARCH("PTRFILENUM"):"LINKPTR",1:"LINKSRCH")
Q
;
LINKPTR ;LINK COMMON POINTER VALUES OF FIELDS TO POINTER FILE
S ATSEARCH("MERGE COUNT")=ATSEARCH("MERGE COUNT")+1
S ^UTILITY("ATSEARCH",$J,"MERGED",3,ATSPTVAL)=""
Q
;
LINKSRCH ;COMMON POINTER VALUES OF FIELDS
;LINK ALL SEARCH RESULTS WITH COMMON POINTER VALUES TO SEARCH FILE
;REQUESTED BY USER VIA SEARCH FILE DFN
I '(ATSEARCH(1,"SRCHFILENUM")=ATSEARCH(2,"SRCHFILENUM")&(ATSNOT="")) S ATSDFN="" F L=0:0 S ATSDFN=$O(^UTILITY("ATSEARCH",$J,ATSX,ATSPTVAL,ATSDFN)) Q:ATSDFN'=+ATSDFN D CONT
E F ATSI=1:1:2 S ATSDFN=0 F ATSL=0:0 S ATSDFN=$O(^UTILITY("ATSEARCH",$J,ATSI,ATSPTVAL,ATSDFN)) Q:ATSDFN'=+ATSDFN D:'$D(^UTILITY("ATSEARCH",$J,"MERGED",3,ATSDFN)) CONT
Q
;
CONT ;CONT OF LINKSRCH+3
S ^UTILITY("ATSEARCH",$J,"MERGED",3,ATSDFN)="",ATSEARCH("MERGE COUNT")=ATSEARCH("MERGE COUNT")+1
Q
;
SETTEMP ;SETS NODES WITH RESULTS OF LAST SEARCH COMPARE
K ^UTILITY("ATSEARCH",$J,"TMP")
S ATSTMPN=0 F ATSL=0:0 S ATSTMPN=$O(^UTILITY("ATSEARCH",$J,"MERGED",3,ATSTMPN)) Q:ATSTMPN'=+ATSTMPN S ^UTILITY("ATSEARCH",$J,"TMP",ATSTMPN)=""
Q
;
EOJ ;
K ATSECDY,ATSPTVAL,ATSDFN,ATSPRIMY,^UTILITY("ATSEARCH",$J,1),^(2),ATSUB,ATSEDOT,ATSENDPC,ATSENUL,ATSEFLY,ATSETMP,ATSTMPN,ATSL,ATSI
Q
;
ATSERCH4 ;TUCSON/DG;GETS STORED RESULTS FOR COMPARISON [ 10/25/91 1:31 PM ]
+1 ;;2.5;SEARCH TEMPLATE COMPARISON;;OCT 25, 1991
+2 ;
+3 ;
+4 ;GIVES USER CHANCE TO SAVE RESULTS IN A TEMPLATE
DO ^ATSERCH3
+5 IF ATSFLAG
DO EOJ
QUIT
+6 ;IN CASE OF A LONG SEARCH WHERE USER MAY BE GONE AND A TIMEOUT
+7 ;KILLING THE MERGE RESULTS WOULD OCCUR
+8 ;CALL TO SEE IF USER WANTS COMPARISON TO BE DONE
DO ^ATSERCHD
+9 ;VIA TASKMAN
+10 IF ATSTASK!(ATSFLAG)
DO EOJ
QUIT
ZTM ;ENTRY POINT FOR TASKMAN
+1 IF $DATA(ZTQEUED)
SET ZTREQ="@"
KILL ^UTILITY("ATSEARCH",$JOB)
+2 IF 'ATSTASK
WRITE !!,"Please wait ..."
+3 SET ATSUB=1
DO GET
+4 SET ATSUB=2
DO GET
+5 DO MERGE
+6 IF ATSTASK
IF '$DATA(ATSETMP)
DO WRITE^ATSERCHG
+7 IF ATSRCSTR
DO SEARCH^ATSERCH3
+8 DO CHKMTCH^ATSERCHG
+9 DO EOJ
+10 IF ATSTASK
DO EOJ^ATSERCH
+11 QUIT
+12 ;
GET ;GETS STORED RESULTS, PLACE IN ^UTILITY
+1 SET (ATSDFN,ATSEDOT,ATSEARCH(ATSUB,"COUNT"),ATSEARCH("MERGE COUNT"))=0
+2 FOR L=0:0
SET ATSDFN=$ORDER(@(ATSEARCH(ATSUB,"SRCHRESLTREF")_ATSDFN_")"))
IF ATSDFN'=+ATSDFN
QUIT
DO @$SELECT($DATA(ATSEARCH(ATSUB,"PTEDTOFILE")):"GET3",1:"GET2")
+3 QUIT
+4 ;
GET2 ;CONTINUATION OF FOR LOOP IN GET FOR A DATA FILE THAT IS NOT THE PTED
+1 ;TO FILE
+2 SET ATSENDPC=ATSEARCH(ATSUB,"DATAGLBLREF")_ATSDFN_","_ATSEARCH(ATSUB,"NODE")_")"
+3 IF '$DATA(@(ATSENDPC))&(ATSENLAG'=2)
QUIT
+4 IF $DATA(@(ATSENDPC))
SET ATSENDPC=$PIECE(@(ATSENDPC),U,ATSEARCH(ATSUB,"PIECENUM"))
SET ATSEFLY=""
+5 IF ((ATSENDPC']"")!('$DATA(ATSEFLY)))&(ATSENLAG'=2)
QUIT
+6 IF ((ATSENDPC']"")!('$DATA(ATSEFLY)))&(ATSENLAG=2)
SET ATSENDPC="NULL"
+7 SET ^UTILITY("ATSEARCH",$JOB,ATSUB,ATSENDPC,ATSDFN)=""
SET ATSEARCH(ATSUB,"COUNT")=ATSEARCH(ATSUB,"COUNT")+1
+8 SET ATSEDOT=ATSEDOT+1
IF '(ATSEDOT#20)&('ATSTASK)
WRITE "."
+9 QUIT
+10 ;
GET3 ;CONT. OF FOR LOOP IF FILE WITH SEARCH TEMPLATE LINKED TO
+1 ;IT ALSO THE POINTED TO FILE - FIELD IN FILE POINTED TO FILE MUST
+2 ;BE THE .01 FIELD OF THE FILE
+3 SET ^UTILITY("ATSEARCH",$JOB,ATSUB,ATSDFN,ATSDFN)=""
SET ATSEARCH(ATSUB,"COUNT")=ATSEARCH(ATSUB,"COUNT")+1
+4 SET ATSEDOT=ATSEDOT+1
IF '(ATSEDOT#20)&('ATSTASK)
WRITE "."
+5 QUIT
+6 ;
MERGE ;FIRST TEMPLATE WITH LESSER COUNT, COMPARE TO TEMPLATE TWO
+1 SET (ATSPRIMY,ATSECDY)="^UTILITY(""ATSEARCH"",$J,"
+2 IF (ATSMTCH=1!(ATSMTCH=""))
IF ATSEARCH(1,"COUNT")<ATSEARCH(2,"COUNT")
SET ATSPRIMY=ATSPRIMY_"1,"
SET ATSECDY=ATSECDY_"2,"
+3 IF '$TEST
IF ATSMTCH=1!(ATSMTCH="")
SET ATSPRIMY=ATSPRIMY_"2,"
SET ATSECDY=ATSECDY_"1,"
+4 IF ATSMTCH'<2
SET ATSPRIMY=$SELECT(ATSMTCH=2:ATSPRIMY_"1,",1:ATSPRIMY_"2,")
SET ATSECDY=$SELECT(ATSMTCH=2:ATSECDY_"2,",1:ATSECDY_"1,")
+5 IF $DATA(^UTILITY("ATSEARCH",$JOB,"MERGED"))
DO SETTEMP
+6 KILL ^UTILITY("ATSEARCH",$JOB,"MERGED")
+7 SET ATSPTVAL=0
FOR L=0:0
SET ATSPTVAL=$ORDER(@(ATSPRIMY_""""_ATSPTVAL_""""_")"))
IF ATSPTVAL'=+ATSPTVAL&(ATSPTVAL'["NULL")
QUIT
DO MERGE2
+8 QUIT
+9 ;
MERGE2 ;CONT OF FOR LOOP
+1 IF @(ATSNOT_"$D(@(ATSECDY_""""""""_ATSPTVAL_""""""""_"")""))")
DO @$SELECT(ATSEARCH("FILELINK")=ATSEARCH("PTRFILENUM"):"LINKPTR",1:"LINKSRCH")
+2 QUIT
+3 ;
LINKPTR ;LINK COMMON POINTER VALUES OF FIELDS TO POINTER FILE
+1 SET ATSEARCH("MERGE COUNT")=ATSEARCH("MERGE COUNT")+1
+2 SET ^UTILITY("ATSEARCH",$JOB,"MERGED",3,ATSPTVAL)=""
+3 QUIT
+4 ;
LINKSRCH ;COMMON POINTER VALUES OF FIELDS
+1 ;LINK ALL SEARCH RESULTS WITH COMMON POINTER VALUES TO SEARCH FILE
+2 ;REQUESTED BY USER VIA SEARCH FILE DFN
+3 IF '(ATSEARCH(1,"SRCHFILENUM")=ATSEARCH(2,"SRCHFILENUM")&(ATSNOT=""))
SET ATSDFN=""
FOR L=0:0
SET ATSDFN=$ORDER(^UTILITY("ATSEARCH",$JOB,ATSX,ATSPTVAL,ATSDFN))
IF ATSDFN'=+ATSDFN
QUIT
DO CONT
+4 IF '$TEST
FOR ATSI=1:1:2
SET ATSDFN=0
FOR ATSL=0:0
SET ATSDFN=$ORDER(^UTILITY("ATSEARCH",$JOB,ATSI,ATSPTVAL,ATSDFN))
IF ATSDFN'=+ATSDFN
QUIT
IF '$DATA(^UTILITY("ATSEARCH",$JOB,"MERGED",3,ATSDFN))
DO CONT
+5 QUIT
+6 ;
CONT ;CONT OF LINKSRCH+3
+1 SET ^UTILITY("ATSEARCH",$JOB,"MERGED",3,ATSDFN)=""
SET ATSEARCH("MERGE COUNT")=ATSEARCH("MERGE COUNT")+1
+2 QUIT
+3 ;
SETTEMP ;SETS NODES WITH RESULTS OF LAST SEARCH COMPARE
+1 KILL ^UTILITY("ATSEARCH",$JOB,"TMP")
+2 SET ATSTMPN=0
FOR ATSL=0:0
SET ATSTMPN=$ORDER(^UTILITY("ATSEARCH",$JOB,"MERGED",3,ATSTMPN))
IF ATSTMPN'=+ATSTMPN
QUIT
SET ^UTILITY("ATSEARCH",$JOB,"TMP",ATSTMPN)=""
+3 QUIT
+4 ;
EOJ ;
+1 KILL ATSECDY,ATSPTVAL,ATSDFN,ATSPRIMY,^UTILITY("ATSEARCH",$JOB,1),^(2),ATSUB,ATSEDOT,ATSENDPC,ATSENUL,ATSEFLY,ATSETMP,ATSTMPN,ATSL,ATSI
+2 QUIT
+3 ;