PRSALVU ; HISC/REL-Leave Length ;5/31/95 12:21
;;4.0;PAID;;Sep 21, 1995
S Z=$G(^PRST(458.1,DA,0)) I $E(ENT,1,2)["D" G D
I $P(Z,"^",7)="ML" G D
H ; Calculate Hours
S TYL="H",D1=$P(Z,"^",3) D PP^PRSAPPU
I D1=$P(Z,"^",5) G 1
; Calculate first day
D TC S X1=$G(^PRST(457.1,+TC,1))
S X2="MID" F K=1:3 Q:$P(X1,"^",K)="" S %=$P(X1,"^",K+2) I $S('%:1,1:$P($G(^PRST(457.2,%,0)),"^",2)="RG") S X2=$P(X1,"^",K+1)
S X=$P(Z,"^",4)_"^"_X2 D CNV^PRSATIM S TIM=$P(Y,"^",2)-$P(Y,"^",1)/60 S:TIM<0 TIM=0
D RG I TIM>RG S TIM=RG
E S X1=$P(X1,"^",3) I X1,TIM>4.75 S TIM=TIM-(X1/60)
; Calculate intermediate days
0 S DAY=DAY+1 S:DAY=15 DAY=1,PPI=$S('PPI:PPI,$D(^PRST(458,PPI+1)):PPI+1,1:"")
S X1=D1,X2=1 D C^%DTC S D1=X I X'<$P(Z,"^",5) G L
D TC,RG S TIM=TIM+RG G 0
L ; Calculate last day
D TC S X1=$G(^PRST(457.1,+TC,1))
S X2="MID" F K=1:3 Q:$P(X1,"^",K)="" S %=$P(X1,"^",K+2) I $S('%:1,1:$P($G(^PRST(457.2,%,0)),"^",2)="RG") S X2=$P(X1,"^",K) Q
S X=X2_"^"_$P(Z,"^",6) D CNV^PRSATIM S T1=$P(Y,"^",2)-$P(Y,"^",1)/60 S:T1<0 T1=0
D RG I T1>RG S T1=RG
E S X1=$P(X1,"^",3) I X1,T1>4.75 S T1=T1-(X1/60)
S TIM=TIM+T1 G S
1 ; One Day
S X=$P(Z,"^",4)_"^"_$P(Z,"^",6) D CNV^PRSATIM S TIM=$P(Y,"^",2)-$P(Y,"^",1)/60
D TC,RG I TIM>RG S TIM=RG G S
S X1=$P(X1,"^",3) I X1,TIM>4.75 S TIM=TIM-(X1/60)
G S
TC ; Get tour
I PPI S X1=$G(^PRST(458,PPI,"E",DFN,"D",DAY,0)),TC=$P(X1,"^",2)
E S PPI=$P(^PRST(458,0),"^",3),X1=$G(^PRST(458,PPI,"E",DFN,"D",DAY,0)),TC=$P(X1,"^",2) I $P(X1,"^",3),$P(X1,"^",4) S TC=$P(X1,"^",4)
Q
RG ; Get X1,RG
S X1=$G(^PRST(457.1,+TC,0)),RG=$P(X1,"^",6) Q:RG'="" I TC<5 S RG=0 Q
I $E(AC,2)=1,NH=48 S RG=12 Q
S RG=$S(NH>80:24,NH<80:NH\10,1:8) Q
D ; Calculate Days
S X2=$P(Z,"^",3),X1=$P(Z,"^",5) I 'X1!('X2) Q
D ^%DTC S TIM=X+1,TYL="D" G S
S ; Store length
S $P(^PRST(458.1,DA,0),"^",15,16)=TIM_"^"_TYL Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRSALVU 1872 printed Nov 22, 2024@17:33:44 Page 2
PRSALVU ; HISC/REL-Leave Length ;5/31/95 12:21
+1 ;;4.0;PAID;;Sep 21, 1995
+2 SET Z=$GET(^PRST(458.1,DA,0))
IF $EXTRACT(ENT,1,2)["D"
GOTO D
+3 IF $PIECE(Z,"^",7)="ML"
GOTO D
H ; Calculate Hours
+1 SET TYL="H"
SET D1=$PIECE(Z,"^",3)
DO PP^PRSAPPU
+2 IF D1=$PIECE(Z,"^",5)
GOTO 1
+3 ; Calculate first day
+4 DO TC
SET X1=$GET(^PRST(457.1,+TC,1))
+5 SET X2="MID"
FOR K=1:3
if $PIECE(X1,"^",K)=""
QUIT
SET %=$PIECE(X1,"^",K+2)
IF $SELECT('%:1,1:$PIECE($GET(^PRST(457.2,%,0)),"^",2)="RG")
SET X2=$PIECE(X1,"^",K+1)
+6 SET X=$PIECE(Z,"^",4)_"^"_X2
DO CNV^PRSATIM
SET TIM=$PIECE(Y,"^",2)-$PIECE(Y,"^",1)/60
if TIM<0
SET TIM=0
+7 DO RG
IF TIM>RG
SET TIM=RG
+8 IF '$TEST
SET X1=$PIECE(X1,"^",3)
IF X1
IF TIM>4.75
SET TIM=TIM-(X1/60)
+9 ; Calculate intermediate days
0 SET DAY=DAY+1
if DAY=15
SET DAY=1
SET PPI=$SELECT('PPI:PPI,$DATA(^PRST(458,PPI+1)):PPI+1,1:"")
+1 SET X1=D1
SET X2=1
DO C^%DTC
SET D1=X
IF X'<$PIECE(Z,"^",5)
GOTO L
+2 DO TC
DO RG
SET TIM=TIM+RG
GOTO 0
L ; Calculate last day
+1 DO TC
SET X1=$GET(^PRST(457.1,+TC,1))
+2 SET X2="MID"
FOR K=1:3
if $PIECE(X1,"^",K)=""
QUIT
SET %=$PIECE(X1,"^",K+2)
IF $SELECT('%:1,1:$PIECE($GET(^PRST(457.2,%,0)),"^",2)="RG")
SET X2=$PIECE(X1,"^",K)
QUIT
+3 SET X=X2_"^"_$PIECE(Z,"^",6)
DO CNV^PRSATIM
SET T1=$PIECE(Y,"^",2)-$PIECE(Y,"^",1)/60
if T1<0
SET T1=0
+4 DO RG
IF T1>RG
SET T1=RG
+5 IF '$TEST
SET X1=$PIECE(X1,"^",3)
IF X1
IF T1>4.75
SET T1=T1-(X1/60)
+6 SET TIM=TIM+T1
GOTO S
1 ; One Day
+1 SET X=$PIECE(Z,"^",4)_"^"_$PIECE(Z,"^",6)
DO CNV^PRSATIM
SET TIM=$PIECE(Y,"^",2)-$PIECE(Y,"^",1)/60
+2 DO TC
DO RG
IF TIM>RG
SET TIM=RG
GOTO S
+3 SET X1=$PIECE(X1,"^",3)
IF X1
IF TIM>4.75
SET TIM=TIM-(X1/60)
+4 GOTO S
TC ; Get tour
+1 IF PPI
SET X1=$GET(^PRST(458,PPI,"E",DFN,"D",DAY,0))
SET TC=$PIECE(X1,"^",2)
+2 IF '$TEST
SET PPI=$PIECE(^PRST(458,0),"^",3)
SET X1=$GET(^PRST(458,PPI,"E",DFN,"D",DAY,0))
SET TC=$PIECE(X1,"^",2)
IF $PIECE(X1,"^",3)
IF $PIECE(X1,"^",4)
SET TC=$PIECE(X1,"^",4)
+3 QUIT
RG ; Get X1,RG
+1 SET X1=$GET(^PRST(457.1,+TC,0))
SET RG=$PIECE(X1,"^",6)
if RG'=""
QUIT
IF TC<5
SET RG=0
QUIT
+2 IF $EXTRACT(AC,2)=1
IF NH=48
SET RG=12
QUIT
+3 SET RG=$SELECT(NH>80:24,NH<80:NH\10,1:8)
QUIT
D ; Calculate Days
+1 SET X2=$PIECE(Z,"^",3)
SET X1=$PIECE(Z,"^",5)
IF 'X1!('X2)
QUIT
+2 DO ^%DTC
SET TIM=X+1
SET TYL="D"
GOTO S
S ; Store length
+1 SET $PIECE(^PRST(458.1,DA,0),"^",15,16)=TIM_"^"_TYL
QUIT