XQ83D ;ISC-SF..SEA/JLI - MICRO SURGERY ON MENU TREES FOR ITEM DELETED FROM MENU ;04/16/2002  13:58
 ;;8.0;KERNEL;**157**;Jul 10, 1995
 I $D(^DIC(19,+XQOPM,0)),$D(^(10,"B",+XQOPI)) S XQB=$O(^(+XQOPI,0)) I $D(^DIC(19,+XQOPM,10,XQB,0)),+^(0)=+XQOPI Q  ;  item hasn't been removed, or was put back on
 D TABLE^XQ83A
 S A="P" F XQI=0:0 S A=$O(^XUTL("XQO",A)) Q:A'["P"  I $D(^(A,U,XQOPI)),$D(^(XQOPM)) S XQAKEY=$S(+$E(A,2,99)=+XQOPM:1,1:0) D A
 Q
XPAND ;
 F L=0:0 S L=$O(^DIC(19,XQNEW,10,L)) Q:L'>0  S T=+^(L,0) I $P(^DIC(19,T,0),U,3)="",'$D(^TMP($J,"ACT",T)) S K=K+1,^(T)="",^TMP($J,"NEW",K)=T
 Q
 ;
A ;
 S PATH=""
 F XQ83DI=0:0 S PATH=$O(^TMP($J,"PATH",PATH)) Q:PATH=""  S XQ83DN=$L(PATH,","),XQJ=$P(PATH,",",XQ83DN-1),XQVAL=^(PATH),XQSYN=^(PATH,"SYN"),XQUC=^("U") I $D(^XUTL("XQO",A,U,XQJ)) S XQPATH=","_$S(XQAKEY:"",1:XQOPM_",")_PATH D DA
 K XQB,XQFND,XQJ,XQSYN,XQPATH,XQ83DI,XQ83DN,PATH
 Q
 ;
DA ;
 F XQK=0:0 S XQK=$O(^XUTL("XQO",A,U,XQJ,0,XQK)) Q:XQK'>0  S XQB=$P(^(XQK),U) I ","_XQB[XQPATH S ^(0)=^XUTL("XQO",A,U,XQJ,0)-1 K:^(0)'>0 ^(0) K ^(0,XQK) I XQSYN'="" S XQ2=XQSYN,XQ1=XQJ_U_"0" D DELNAM
 S XQB=$P(^XUTL("XQO",A,U,XQJ),U,6) I ","_XQB[XQPATH D DA1 I XQSYN'="" S XQ2=XQSYN,XQ1=XQJ_U_"0" D DELNAM
 I '$D(^XUT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