DIBT1 ;SFISC/GFT,TKW-STORE A SORT TEMPLATE ;8/2/94 15:57
;;22.0;VA FileMan;;Mar 30, 1999
;Per VHA Directive 10-93-142, this routine should not be modified.
S1 K DIR S DIR(0)="O",DIR("A")="STORE IN 'SORT' TEMPLATE",DIR("?")="^D H1^DIBT1"
D SAV Q:$D(DIRUT) D DIC Q
;
S2 K DIR S DIR(0)="O",DIR("A")="STORE THESE ENTRY ID'S IN TEMPLATE",DIR("?")="^D H2^DIBT1"
D SAV Q:$D(DIRUT) D MRG Q
;
S3 K DIR S DIR(0)="O",DIR("A")="STORE RESULTS OF SEARCH IN TEMPLATE",DIR("?")="^D H3^DIBT1"
S:$D(DIAR) DIR(0)=""
D SAV Q:$D(DIRUT) D MRG Q
;
SAV S DIR(0)="F"_DIR(0)_"^1,30"
D ^DIR K DIR Q:$D(DIRUT)
I $E(X)="[" S X=$P($E(X,2,99),"]",1)
Q
H1 N A,B S A="sort criteria",B="SORT" D H,DIC Q
H2 N A,B S A="list of entries",B="SEARCH/SORT" D H,MRG Q
H3 N A,B S A="list of entries from the search",B="SEARCH/SORT"
W:$D(DIAR) !!,"You must store the results in a template.",!,"Otherwise you will have to rerun this search to archive the entries."
D H,MRG Q
H W !!,"If you wish to save this "_A_" for later re-use",!,"enter the name of a "_B_" TEMPLATE here (1-30 characters)." Q
MRG ;
S DIBT1=1
DIC K DIC S DIC="^DIBT(",DLAYGO=0,DIC(0)="QELSZ",DIOVRD=1,DIC("S")="I "_$S($D(DIAR)&('$D(DIARI)):"",1:"'")_"$P(^(0),U,8)"
S DIC("S")=DIC("S")_",$P(^(0),U,4)=DK,$P(^(0),U,5)=DUZ!'$P(^(0),U,5)!$D(DIEDT)",D="F"_DK
D IX^DIC S DIBTY=Y K DIC,DLAYGO,DIEDT,DIOVRD G QDIC:Y'>0
N X,DIBTSEC S DIBTSEC="" I $O(^DIBT(+Y,0))]"" S DIBTSEC=Y(0) D ALR
I $D(DIRUT)!(Y'>0) G QDIC
D NOW^%DTC
S ^DIBT("F"_DK,$P(Y,U,2),+Y)=1,^DIBT(+Y,0)=$P(Y,U,2)_U_+$J(%,0,4)_U_$S(DIBTSEC]"":$P(DIBTSEC,U,3),1:DUZ(0))_U_DK_U_DUZ_U_$S(DIBTSEC]"":$P(DIBTSEC,U,6),1:DUZ(0)) I $D(DIAR),'$D(DIARI) S $P(^(0),U,8)=1
K DIBTSEC N DIE,DA,DI,DK,DR,Y S DIE="^DIBT(",DA=+DIBTY,DR=10,DIOVRD=1 D ^DIE K DUOUT,DIROUT,DIRUT
QDIC K DIBT1,DIBTY,DIOVRD,%,%X,%Y Q
ALR W !,$C(7) I $D(DIBT),+Y=DIBT W "NO!! YOU ARE USING THAT TEMPLATE FOR YOUR LIST OF ENTRIES!" S Y=-1 Q
I $D(DISV),+Y=DISV W "NO!! YOU ARE GOING TO STORE SEARCH RESULTS IN THAT TEMPLATE!" S Y=-1 Q
N DIR S DIR(0)="Y",DIR("B")="NO",DIR("A")="DATA ALREADY STORED THERE....OK TO PURGE" D ^DIR Q:$D(DIRUT)
I Y=1 S %Y="" D S Y=DIBTY Q
.F S %Y=$O(^DIBT(+DIBTY,%Y)) Q:%Y="" I %Y'="%D",%Y'="ROU",%Y'="ROUOLD",%Y'="DIPT" K ^DIBT(+DIBTY,%Y)
.Q
S %Y=-1 I $O(^DIBT(+DIBTY,1,0))'>0!'$D(DIBT1) S Y=-1 Q
F %=0:0 S %=$O(^(%)),%Y=%Y+1 Q:%'>0
K DIR S DIR(0)="Y",DIR("B")="NO",DIR("A",1)="WANT TO MERGE THESE ENTRIES",DIR("A")="WITH THE "_%Y_" ALREADY IN '"_$P(DIBTY,U,2)_"' TEMPLATE"
D ^DIR S Y=$S(Y=0:-1,1:DIBTY) W ! Q
DIBT1 ;SFISC/GFT,TKW-STORE A SORT TEMPLATE ;8/2/94 15:57
+1 ;;22.0;VA FileMan;;Mar 30, 1999
+2 ;Per VHA Directive 10-93-142, this routine should not be modified.
S1 KILL DIR
SET DIR(0)="O"
SET DIR("A")="STORE IN 'SORT' TEMPLATE"
SET DIR("?")="^D H1^DIBT1"
+1 DO SAV
IF $DATA(DIRUT)
QUIT
DO DIC
QUIT
+2 ;
S2 KILL DIR
SET DIR(0)="O"
SET DIR("A")="STORE THESE ENTRY ID'S IN TEMPLATE"
SET DIR("?")="^D H2^DIBT1"
+1 DO SAV
IF $DATA(DIRUT)
QUIT
DO MRG
QUIT
+2 ;
S3 KILL DIR
SET DIR(0)="O"
SET DIR("A")="STORE RESULTS OF SEARCH IN TEMPLATE"
SET DIR("?")="^D H3^DIBT1"
+1 IF $DATA(DIAR)
SET DIR(0)=""
+2 DO SAV
IF $DATA(DIRUT)
QUIT
DO MRG
QUIT
+3 ;
SAV SET DIR(0)="F"_DIR(0)_"^1,30"
+1 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
QUIT
+2 IF $EXTRACT(X)="["
SET X=$PIECE($EXTRACT(X,2,99),"]",1)
+3 QUIT
H1 NEW A,B
SET A="sort criteria"
SET B="SORT"
DO H
DO DIC
QUIT
H2 NEW A,B
SET A="list of entries"
SET B="SEARCH/SORT"
DO H
DO MRG
QUIT
H3 NEW A,B
SET A="list of entries from the search"
SET B="SEARCH/SORT"
+1 IF $DATA(DIAR)
WRITE !!,"You must store the results in a template.",!,"Otherwise you will have to rerun this search to archive the entries."
+2 DO H
DO MRG
QUIT
H WRITE !!,"If you wish to save this "_A_" for later re-use",!,"enter the name of a "_B_" TEMPLATE here (1-30 characters)."
QUIT
MRG ;
+1 SET DIBT1=1
DIC KILL DIC
SET DIC="^DIBT("
SET DLAYGO=0
SET DIC(0)="QELSZ"
SET DIOVRD=1
SET DIC("S")="I "_$SELECT($DATA(DIAR)&('$DATA(DIARI)):"",1:"'")_"$P(^(0),U,8)"
+1 SET DIC("S")=DIC("S")_",$P(^(0),U,4)=DK,$P(^(0),U,5)=DUZ!'$P(^(0),U,5)!$D(DIEDT)"
SET D="F"_DK
+2 DO IX^DIC
SET DIBTY=Y
KILL DIC,DLAYGO,DIEDT,DIOVRD
IF Y'>0
GOTO QDIC
+3 NEW X,DIBTSEC
SET DIBTSEC=""
IF $ORDER(^DIBT(+Y,0))]""
SET DIBTSEC=Y(0)
DO ALR
+4 IF $DATA(DIRUT)!(Y'>0)
GOTO QDIC
+5 DO NOW^%DTC
+6 SET ^DIBT("F"_DK,$PIECE(Y,U,2),+Y)=1
SET ^DIBT(+Y,0)=$PIECE(Y,U,2)_U_+$JUSTIFY(%,0,4)_U_$SELECT(DIBTSEC]"":$PIECE(DIBTSEC,U,3),1:DUZ(0))_U_DK_U_DUZ_U_$SELECT(DIBTSEC]"":$PIECE(DIBTSEC,U,6),1:DUZ(0))
IF $DATA(DIAR)
IF '$DATA(DIARI)
SET $PIECE(^(0),U,8)=1
+7 KILL DIBTSEC
NEW DIE,DA,DI,DK,DR,Y
SET DIE="^DIBT("
SET DA=+DIBTY
SET DR=10
SET DIOVRD=1
DO ^DIE
KILL DUOUT,DIROUT,DIRUT
QDIC KILL DIBT1,DIBTY,DIOVRD,%,%X,%Y
QUIT
ALR WRITE !,$CHAR(7)
IF $DATA(DIBT)
IF +Y=DIBT
WRITE "NO!! YOU ARE USING THAT TEMPLATE FOR YOUR LIST OF ENTRIES!"
SET Y=-1
QUIT
+1 IF $DATA(DISV)
IF +Y=DISV
WRITE "NO!! YOU ARE GOING TO STORE SEARCH RESULTS IN THAT TEMPLATE!"
SET Y=-1
QUIT
+2 NEW DIR
SET DIR(0)="Y"
SET DIR("B")="NO"
SET DIR("A")="DATA ALREADY STORED THERE....OK TO PURGE"
DO ^DIR
IF $DATA(DIRUT)
QUIT
+3 IF Y=1
SET %Y=""
Begin DoDot:1
+4 FOR
SET %Y=$ORDER(^DIBT(+DIBTY,%Y))
IF %Y=""
QUIT
IF %Y'="%D"
IF %Y'="ROU"
IF %Y'="ROUOLD"
IF %Y'="DIPT"
KILL ^DIBT(+DIBTY,%Y)
+5 QUIT
End DoDot:1
SET Y=DIBTY
QUIT
+6 SET %Y=-1
IF $ORDER(^DIBT(+DIBTY,1,0))'>0!'$DATA(DIBT1)
SET Y=-1
QUIT
+7 FOR %=0:0
SET %=$ORDER(^(%))
SET %Y=%Y+1
IF %'>0
QUIT
+8 KILL DIR
SET DIR(0)="Y"
SET DIR("B")="NO"
SET DIR("A",1)="WANT TO MERGE THESE ENTRIES"
SET DIR("A")="WITH THE "_%Y_" ALREADY IN '"_$PIECE(DIBTY,U,2)_"' TEMPLATE"
+9 DO ^DIR
SET Y=$SELECT(Y=0:-1,1:DIBTY)
WRITE !
QUIT