SDD0 ;SF/GFT,ALB/BOK,JSH,LDB - REMAP A CLINIC ; 26 JAN 84 3:00 pm
;;5.3;Scheduling;**167,401,529,1015**;Aug 13, 1993;Build 21
SETX ;
N SDDIV
S SDDIV=$P($G(SD0),"^",15) Q:SDDIV=""
I '$D(VAUTD(SDDIV)),VAUTD=0 Q
Q:'$D(^SC(SC,"SL")) S SDSL=^("SL"),SL=+^("SL"),X=$P(SDSL,U,3),STARTDAY=$S($L(X):X,1:8),X=$P(SDSL,U,6),HSI=$S('X:4,X<3:8/X,1:2),SI=$S(X:X,1:4),SDSI=SI
S:SI=1 SI=4 S:SI=2 SI=4 S SDSOH=$S($P(SDSL,U,8)']"":0,1:1)
K SDIN,SDRE,SDRE1 N SDNODE I $D(^SC(SC,"I")) S SDIN=+^("I"),SDRE=+$P(^("I"),"^",2),Y=SDRE D DTS^SDUTL S SDRE1=Y
F DATE=$$FMADD^XLFDT(SDBD,-1):0 S X1=DATE,X2=1 N X D C^%DTC S DATE=X S SDNODE=$D(^SC(SC,"ST",DATE)) Q:DATE'>0!(DATE>SDED) I $S('$D(SDIN):1,'SDIN:1,SDIN>DATE:1,SDRE'>DATE&(SDRE):1,1:0) K SM,SDHOL D CHECK ;changed 1st part of For loop SD*529
Q
CHECK S X=DATE D DW^%DTC S DAY=$P("SUN^MON^TUES^WEDNES^THURS^FRI^SATUR",U,Y+1),DOW=Y
D APPT I $D(^SC(SC,"ST",DATE,1)),^(1)'[$E(DAY,1,2)&(^(1)["]") S MSG="Bogus clinic day"_$S(SDAPPT:"- Appts!",1:"") D PRNT
I $D(^SC(SC,"ST",DATE,1)),^(1)["CANCEL"!($E(^(1),$F(^(1),"["),999)?."X") S MSG="Cancelled" D PRNT Q
I $D(^HOLIDAY(DATE,0)),'SDSOH S SDHOL=1,X=$P(^(0),U,2) G HOLIDAY:'SDAPPT,Z:SDAPPT
K ^SC(SC,"ST",DATE) S SS=+$O(^SC(SC,"T"_DOW,DATE)),SB=STARTDAY-1/100,STR="{}&%?#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz"
I $D(^SC(SC,"OST",DATE,1)),^(1)]"" S (X,DR)=DATE D DOW^SDM0 S DOW=Y,SM=^SC(SC,"OST",DATE,1),SS=0 G:'SDAPPT OVR G I
G Z:'$D(^SC(SC,"T"_DOW,SS,1)) I ^(1)="" S MSG="no master pattern for this day" D:SDNODE PRNT Q
S DH=^(1),X=DATE G FIX ;NAKED REFERENCE ^SC(IFN,"T"_DOW,DATE,1)
HOLIDAY S ^SC(SC,"ST",DATE,1)=" "_$E(DATE,6,7)_" "_X,^(0)=DATE
Z S MSG=$S($D(SDHOL)&SDAPPT:"- Appts!",'SDSOH&$D(SDHOL):"- Inserted",1:"") I MSG]"" S MSG=X_MSG D PRNT
Q
END K %,%DT,DATE,DAY,DH,DOW,DR,DR1,HSI,I,P,POP,S,SB,SC,SDAPPT,SDAPPT1,SDBD,SDNM,SDED,SDHOL,SD0,SDIN,SDRE,SDRE1,SDSAVX,SDSL,SDSOH,SI,SM,SS,SD,SCI,SCC,ST,STARTDAY,STR,X,MSG,Y,YP,PG,DGVAR,DGPGM,VAUTD,VAUTC,SDU,BEGDATE,ENDDATE D CLOSE^DGUTQ Q
FIX ;DH=PATTERN X=DATE
D SM G:'SDAPPT OVR
I S I=DR#1-SB*100,I=I#1*SI\.6+(I\1*SI)*2,S=$E(SM,I,999),SM=$E(SM,1,I-1)
I $D(^SC(SC,"S",DR,"MES")) D CAN S X=SDSAVX K SDSAVX S DR=+$O(^SC(SC,"S",DR)) G:DR\1=X I G OVR
F Y=0:0 S Y=$O(^SC(SC,"S",DR,1,Y)) Q:Y'>0 I $P(^(Y,0),"^",9)'["C" S SDSL=$P(^(0),U,2)/SL*(SL\(60/SDSI))*HSI-HSI F I=0:HSI:SDSL S ST=$E(S,I+2) S:ST="" ST=" " S S=$E(S,1,I+2-1)_$E(STR,$F(STR,ST)-2)_$E(S,I+3,999)
S SM=SM_S,DR=$O(^SC(SC,"S",DR)) I DR\1=X G I
OVR I $L(SM)>SM S ^SC(SC,"ST",X,0)=X,^(1)=SM S:SS'>0 ^(9)=SC
G Z
SM S SM=$P("SU^MO^TU^WE^TH^FR^SA",U,DOW+1)_" "_$E(X,6,7)_$J("",SI+SI-6)_DH_$J("",64-$L(DH)) Q
APPT S DR=+$O(^SC(SC,"S",DATE)),SDAPPT=0 I DR>(DATE_.9) S DR=DATE Q
F DR1=DATE:0 S DR1=$O(^SC(SC,"S",DR1)) Q:DR1'>0!(DR1>(DATE+1))!(SDAPPT) S:$D(^(DR1,"MES")) SDAPPT=1 F SDAPPT1=0:0 S SDAPPT1=$O(^SC(SC,"S",DR1,1,SDAPPT1)) Q:SDAPPT1'>0 I $D(^(SDAPPT1,0)) S SDAPPT=$S($P(^(0),"^",9)="C":0,1:1)
Q
CAN S SDSAVX=X Q:'$D(^SC(SC,"SDCAN",DR,0)) S X=$E($P(DR,".",2)_"0000",1,4),I=SM_S D TT S ST=%,X=$P(^SC(SC,"SDCAN",DR,0),"^",2) D TT S I=I_$J("",%-$L(I)),Y=""
F X=0:2:% S S=$E(I,X+SI+SI),P=$S(X<ST:S_$E(I,X+1+SI+SI),X=%:$S(Y="[":Y,1:S)_$E(I,X+1+SI+SI),1:$S(Y="["&(X=ST):"]",1:"X")_"X"),Y=$S(S="]":"",S="[":S,1:Y),I=$E(I,1,X-1+SI+SI)_P_$E(I,X+2+SI+SI,999)
S SM=I Q
TT S %=$E(X,3,4),%=X\100-STARTDAY*SI+(%*SI\60)*2 Q
PRNT U IO S YP=YP+1 D:YP>(IOSL-4) ESC^SDD W !,$E(SDNM,1,25),?27,$E(DAY,1,3)_" " S Y=DATE D DT^DIO2 W ?45,MSG Q
ESC S SDU=0 I $E(IOST,1,2)="C-" W *7 R ESC:DTIME S:U=ESC SDU=1
SDD0 ;SF/GFT,ALB/BOK,JSH,LDB - REMAP A CLINIC ; 26 JAN 84 3:00 pm
+1 ;;5.3;Scheduling;**167,401,529,1015**;Aug 13, 1993;Build 21
SETX ;
+1 NEW SDDIV
+2 SET SDDIV=$PIECE($GET(SD0),"^",15)
IF SDDIV=""
QUIT
+3 IF '$DATA(VAUTD(SDDIV))
IF VAUTD=0
QUIT
+4 IF '$DATA(^SC(SC,"SL"))
QUIT
SET SDSL=^("SL")
SET SL=+^("SL")
SET X=$PIECE(SDSL,U,3)
SET STARTDAY=$SELECT($LENGTH(X):X,1:8)
SET X=$PIECE(SDSL,U,6)
SET HSI=$SELECT('X:4,X<3:8/X,1:2)
SET SI=$SELECT(X:X,1:4)
SET SDSI=SI
+5 IF SI=1
SET SI=4
IF SI=2
SET SI=4
SET SDSOH=$SELECT($PIECE(SDSL,U,8)']"":0,1:1)
+6 KILL SDIN,SDRE,SDRE1
NEW SDNODE
IF $DATA(^SC(SC,"I"))
SET SDIN=+^("I")
SET SDRE=+$PIECE(^("I"),"^",2)
SET Y=SDRE
DO DTS^SDUTL
SET SDRE1=Y
+7 ;changed 1st part of For loop SD*529
FOR DATE=$$FMADD^XLFDT(SDBD,-1):0
SET X1=DATE
SET X2=1
NEW X
DO C^%DTC
SET DATE=X
SET SDNODE=$DATA(^SC(SC,"ST",DATE))
IF DATE'>0!(DATE>SDED)
QUIT
IF $SELECT('$DATA(SDIN):1,'SDIN:1,SDIN>DATE:1,SDRE'>DATE&(SDRE):1,1:0)
KILL SM,SDHOL
DO CHECK
+8 QUIT
CHECK SET X=DATE
DO DW^%DTC
SET DAY=$PIECE("SUN^MON^TUES^WEDNES^THURS^FRI^SATUR",U,Y+1)
SET DOW=Y
+1 DO APPT
IF $DATA(^SC(SC,"ST",DATE,1))
IF ^(1)'[$EXTRACT(DAY,1,2)&(^(1)["]")
SET MSG="Bogus clinic day"_$SELECT(SDAPPT:"- Appts!",1:"")
DO PRNT
+2 IF $DATA(^SC(SC,"ST",DATE,1))
IF ^(1)["CANCEL"!($EXTRACT(^(1),$FIND(^(1),"["),999)?."X")
SET MSG="Cancelled"
DO PRNT
QUIT
+3 IF $DATA(^HOLIDAY(DATE,0))
IF 'SDSOH
SET SDHOL=1
SET X=$PIECE(^(0),U,2)
IF 'SDAPPT
GOTO HOLIDAY
IF SDAPPT
GOTO Z
+4 KILL ^SC(SC,"ST",DATE)
SET SS=+$ORDER(^SC(SC,"T"_DOW,DATE))
SET SB=STARTDAY-1/100
SET STR="{}&%?#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz"
+5 IF $DATA(^SC(SC,"OST",DATE,1))
IF ^(1)]""
SET (X,DR)=DATE
DO DOW^SDM0
SET DOW=Y
SET SM=^SC(SC,"OST",DATE,1)
SET SS=0
IF 'SDAPPT
GOTO OVR
GOTO I
+6 IF '$DATA(^SC(SC,"T"_DOW,SS,1))
GOTO Z
IF ^(1)=""
SET MSG="no master pattern for this day"
IF SDNODE
DO PRNT
QUIT
+7 ;NAKED REFERENCE ^SC(IFN,"T"_DOW,DATE,1)
SET DH=^(1)
SET X=DATE
GOTO FIX
HOLIDAY SET ^SC(SC,"ST",DATE,1)=" "_$EXTRACT(DATE,6,7)_" "_X
SET ^(0)=DATE
Z SET MSG=$SELECT($DATA(SDHOL)&SDAPPT:"- Appts!",'SDSOH&$DATA(SDHOL):"- Inserted",1:"")
IF MSG]""
SET MSG=X_MSG
DO PRNT
+1 QUIT
END KILL %,%DT,DATE,DAY,DH,DOW,DR,DR1,HSI,I,P,POP,S,SB,SC,SDAPPT,SDAPPT1,SDBD,SDNM,SDED,SDHOL,SD0,SDIN,SDRE,SDRE1,SDSAVX,SDSL,SDSOH,SI,SM,SS,SD,SCI,SCC,ST,STARTDAY,STR,X,MSG,Y,YP,PG,DGVAR,DGPGM,VAUTD,VAUTC,SDU,BEGDATE,ENDDATE
DO CLOSE^DGUTQ
QUIT
FIX ;DH=PATTERN X=DATE
+1 DO SM
IF 'SDAPPT
GOTO OVR
I SET I=DR#1-SB*100
SET I=I#1*SI\.6+(I\1*SI)*2
SET S=$EXTRACT(SM,I,999)
SET SM=$EXTRACT(SM,1,I-1)
+1 IF $DATA(^SC(SC,"S",DR,"MES"))
DO CAN
SET X=SDSAVX
KILL SDSAVX
SET DR=+$ORDER(^SC(SC,"S",DR))
IF DR\1=X
GOTO I
GOTO OVR
+2 FOR Y=0:0
SET Y=$ORDER(^SC(SC,"S",DR,1,Y))
IF Y'>0
QUIT
IF $PIECE(^(Y,0),"^",9)'["C"
SET SDSL=$PIECE(^(0),U,2)/SL*(SL\(60/SDSI))*HSI-HSI
FOR I=0:HSI:SDSL
SET ST=$EXTRACT(S,I+2)
IF ST=""
SET ST=" "
SET S=$EXTRACT(S,1,I+2-1)_$EXTRACT(STR,$FIND(STR,ST)-2)_$EXTRACT(S,I+3,999)
+3 SET SM=SM_S
SET DR=$ORDER(^SC(SC,"S",DR))
IF DR\1=X
GOTO I
OVR IF $LENGTH(SM)>SM
SET ^SC(SC,"ST",X,0)=X
SET ^(1)=SM
IF SS'>0
SET ^(9)=SC
+1 GOTO Z
SM SET SM=$PIECE("SU^MO^TU^WE^TH^FR^SA",U,DOW+1)_" "_$EXTRACT(X,6,7)_$JUSTIFY("",SI+SI-6)_DH_$JUSTIFY("",64-$LENGTH(DH))
QUIT
APPT SET DR=+$ORDER(^SC(SC,"S",DATE))
SET SDAPPT=0
IF DR>(DATE_.9)
SET DR=DATE
QUIT
+1 FOR DR1=DATE:0
SET DR1=$ORDER(^SC(SC,"S",DR1))
IF DR1'>0!(DR1>(DATE+1))!(SDAPPT)
QUIT
IF $DATA(^(DR1,"MES"))
SET SDAPPT=1
FOR SDAPPT1=0:0
SET SDAPPT1=$ORDER(^SC(SC,"S",DR1,1,SDAPPT1))
IF SDAPPT1'>0
QUIT
IF $DATA(^(SDAPPT1,0))
SET SDAPPT=$SELECT($PIECE(^(0),"^",9)="C":0,1:1)
+2 QUIT
CAN SET SDSAVX=X
IF '$DATA(^SC(SC,"SDCAN",DR,0))
QUIT
SET X=$EXTRACT($PIECE(DR,".",2)_"0000",1,4)
SET I=SM_S
DO TT
SET ST=%
SET X=$PIECE(^SC(SC,"SDCAN",DR,0),"^",2)
DO TT
SET I=I_$JUSTIFY("",%-$LENGTH(I))
SET Y=""
+1 FOR X=0:2:%
SET S=$EXTRACT(I,X+SI+SI)
SET P=$SELECT(X<ST:S_$EXTRACT(I,X+1+SI+SI),X=%:$SELECT(Y="[":Y,1:S)_$EXTRACT(I,X+1+SI+SI),1:$SELECT(Y="["&(X=ST):"]",1:"X")_"X")
SET Y=$SELECT(S="]":"",S="[":S,1:Y)
SET I=$EXTRACT(I,1,X-1+SI+SI)_P_$EXTRACT(I,X+2+SI+SI,999)
+2 SET SM=I
QUIT
TT SET %=$EXTRACT(X,3,4)
SET %=X\100-STARTDAY*SI+(%*SI\60)*2
QUIT
PRNT USE IO
SET YP=YP+1
IF YP>(IOSL-4)
DO ESC^SDD
WRITE !,$EXTRACT(SDNM,1,25),?27,$EXTRACT(DAY,1,3)_" "
SET Y=DATE
DO DT^DIO2
WRITE ?45,MSG
QUIT
ESC SET SDU=0
IF $EXTRACT(IOST,1,2)="C-"
WRITE *7
READ ESC:DTIME
IF U=ESC
SET SDU=1