PSSJSV ;BIR/CML3/WRT-SCHEDULE VALIDATION ;06/24/96
;;1.0;PHARMACY DATA MANAGEMENT;**20,38,56,59,110,121**;9/30/97;Build 1
;
; Reference to ^PS(51.15 is supported by DBIA #2132
; Reference to $$UP^XLFSTR(P1) is supported by DBIA #10104
;
EN ;
S X=PSJX,(PSJAT,PSJM,PSJTS,PSJY,PSJAX)="" I $S(X["""":1,$A(X)=45:1,X'?.ANP:1,$L(X," ")>2:1,$L(X)>70:1,$L(X)<1:1,X["P RN":1,1:X["PR N") K PSJX,X Q
I X["PRN"!(X="ON CALL")!(X="ONCALL")!(X="ON-CALL") G DONE
I X?1."?" D:'$D(PSJNE) ENSVH^PSSJSV0 Q
S X0=X,(XT,Y)="" I X,X'["X",(X?2.4N1"-".E!(X?2.4N)) D ENCHK S:$D(X) PSJAT=X G DONE
I X["@" D DW S:$D(X) PSJAT=$P(X,"@",2) G DONE
I $S($D(^PS(51.1,"AC",PSJPP,X)):1,1:$E($O(^(X)),1,$L(X))=X) D DIC G:$S(PSJY:PSJTS'="C",1:PSJM) DONE
I $S(X="NOW":1,X="ONCE":1,X="STAT":1,X="ONE TIME":1,X="ONETIME":1,X="1TIME":1,X="1-TIME":1,X="1 TIME":1,1:X="ONE-TIME") S PSJTS="O" W:'$D(PSJNE) " (ONCE ONLY)" G DONE
S:PSJTS="" PSJTS="C" I PSJAT="" W:'$D(PSJNE) " (Non standard schedule)" S X=PSJX
I $E(X,1,2)="AD" K X G DONE
I $E(X,1,3)="BID"!($E(X,1,3)="TID")!($E(X,1,3)="QID") S PSJM=1440\$F("BTQ",$E(X)) G DONE
S:$E(X)="Q" X=$E(X,2,99) S:'X X="1"_X S X1=+X,X=$P(X,+X,2),X2=0 S:X1<0 X1=-X1 S:$E(X)="X" X2=X1,X=$E(X,2,99) I 'X2,$E(X)="O" S X2=.5,X=$E(X,2,99)
S XT=$S(X["'":1,(X["D"&(X'["AD"))!(X["AM")!(X["PM")!(X["HS"&(X'["THS")):1440,X["H"&(X'["TH"):60,X["AC"!(X["PC"):480,X["W":10080,X["M":40320,1:-1) I XT<0,PSJAT="" K X G DONE
S X=PSJX I XT S:X2 XT=XT\X2 S:'X2 XT=XT*X1
S PSJM=XT
;
DONE ;
K:$D(X)[0 PSJX K D,DIC,Q,QX,SDW,SWD,X,X0,X1,X2,XT,Y,Z Q
;
ENCHK ; admin times
I $S($L($P(X,"-"))>4:1,$L(X)>119:1,$L(X)<2:1,X'>0:1,1:X'?.ANP) K X Q
S X(1)=$P(X,"-") I X(1)'?2N,X(1)'?4N K X Q
S X(1)=$L(X(1)) F X(2)=2:1:$L(X,"-") S X(3)=$P(X,"-",X(2)) I $S($L(X(3))'=X(1):1,X(3)>$S(X(1)=2:24,1:2400):1,1:X(3)'>$P(X,"-",X(2)-1)) K X Q
K:$D(X) X(1),X(2),X(3) Q
;
DIC ; 51.1 look-up
S DIC="^PS(51.1,",DIC(0)=$E("E",'$D(PSJNE))_"ISZ",DIC("W")="I '$D(PSJNE) D DICW^PSSJSV0",D="AP"_PSJPP
D IX^DIC K DIC Q:Y'>0 S PSJY=+Y,(PSJX,X,X0)=Y(0,0),PSJM=$P(Y(0),"^",3),PSJTS=$P(Y(0),"^",5),PSJAX=$P(Y(0),U,7) S:PSJTS="" PSJTS="C" Q:PSJTS="O"!(PSJTS["R") I $D(PSJW),$D(^PS(51.1,+Y,1,+PSJW,0)) S PSJAT=$P(^(0),"^",PSJTS="S"+2)
E S PSJAT=$P(Y(0),"^",PSJTS="S"*4+2)
Q:PSJTS'="S"
F Y=1:1:$L(PSJAT,"-") S Y(1)=$P(PSJAT,"-",Y),PSJAT(Y(1))="",Y(2)=$O(^PS(51.15,"ACP",PSJPP,Y(1),0)) I Y(2),$D(^PS(51.15,Y(2),0)) S PSJAT(Y(1))=$P(^(0),"^",3) I $D(PSJW),$D(^(1,PSJW,0)),$P(^(0),"^",2)]"" S PSJAT(Y(1))=$P(^(0),"^",2)
Q
;
DW ; week days
S SWD="SUNDAYS^MONDAYS^TUESDAYS^WEDNESDAYS^THURSDAYS^FRIDAYS^SATURDAYS",SDW=X,X=$P(X,"@",2) D ENCHK Q:'$D(X) S X=$P(SDW,"@"),X(1)="-" I X?.E1P.E,X'["-" F QX=1:1:$L(X) I $E(X,QX)?1P S X(1)=$E(X,QX) Q
F Q=1:1:$L(X,X(1)) K:SWD="" X Q:SWD="" S Z=$P(X,X(1),Q) D DWC Q:'$D(X)
K X(1) S:$D(X) X=SDW Q
DWC I $L(Z)<2 K X Q
F QX=1:1:$L(SWD,"^") S Y=$P(SWD,"^",QX) I $P(Y,Z)="" S SWD=$P(SWD,Y,2) S:$L(SWD) SWD=$E(SWD,2,50) Q
E K X
Q
;
ENSNV ; schedule name
I $S(X["""":1,$A(X)=45:1,X'?.ANP:1,$L(X)>20:1,$L(X)<2:1,1:X?1P.E) K X Q
I $S('$D(PSJPP):0,PSJPP="":1,PSJPP'?.ANP:1,1:'$$VERSION^XPDUTL(PSJPP)) K X
I $D(DA),$D(^PS(51.1,DA,0)),$P(^(0),"^",5)["D" S ZX=X D DNVX S:$D(X) X=ZX K Z1,Z2,Z3,Z4,ZX
Q
;
ENSHV ; shift in 51.1
I $S($L(X)>11:1,$L(X)<1:1,'$D(PSJPP):1,PSJPP="":1,PSJPP'?.ANP:1,1:'$$VERSION^XPDUTL(PSJPP)) K X Q
F X(1)=1:1:$L(X,"-") S X(2)=$P(X,"-",X(1)) I $S(X(2)="":1,X(2)'?.ANP:1,1:'$D(^PS(51.15,"ACP",PSJPP,X(2)))) K X Q
K X(1),X(2) Q
;
ENVSST ; shift start/stop times
I X'?2N1"-"2N,X'?4N1"-"4N K X Q
F X(1)=1,2 I $P(X,"-",X(1))>$S($L($P(X,"-",X(1)))<4:24,1:2400) K X Q
K X(1) Q
;
ENFQD ; frequency default
N X1,X2,Z S Z=$S($D(^PS(51.1,DA,0)):$P(^(0),"^"),1:""),X=""
S X=$P(Z,"^",3) I Z]"" Q
S Z=DA I $E(Z,1,2)="AD" Q
I $E(Z,1,3)="BID"!($E(Z,1,3)="TID")!($E(Z,1,3)="QID") S X=1440/$F("BTQ",$E(Z)) Q
E S:$E(Z)="Q" Z=$E(Z,2,99) S:'Z Z="1"_Z S X1=+Z,Z=$P(Z,+Z,2),X2=0 S:$E(Z)="X" X2=X1,Z=$E(Z,2,99) I 'X2,$E(Z)="O" S X2=.5,Z=$E(Z,2,99)
S X=$S(Z["'":1,(Z["D"&(Z'["AD"))!(Z["AM")!(Z["PM")!(Z["HS"&(Z'["THS")):1440,Z["H"&(Z'["TH"):60,Z["AC"!(Z["PC"):480,Z["W":10080,Z["M":40320,1:"") Q:'X S:X2 X=X\X2 S:'X2 X=X*X1 Q
;
ENDNV ; day of the week name
N Z1,Z2,Z3,Z4 S X=$S($D(^PS(51.1,DA,0)):$P(^(0),"^"),1:"") I X="" K X Q
;
DNVX S Z2=1,Z4="-" I X'["-",X?.E1P.E F Z1=1:1:$L(X) I $E(X,Z1)?1P S Z4=$E(X,Z1) Q
F Z1=1:1:$L(X,Z4) Q:'Z2 S Z2=0 I $L($P(X,Z4,Z1))>1 F Z3="MONDAYS","TUESDAYS","WEDNESDAYS","THURSDAYS","FRIDAYS","SATURDAYS","SUNDAYS" I $P(Z3,$P(X,Z4,Z1))="" S Z2=1 Q
K:'Z2 X S:Z2 X="D" Q
ENPSJ ;validate schedule names for PSJ package
N A,B,I
S X=$$UP^XLFSTR(X)
I $G(PSJPP)'="PSJ" Q
S A=$TR(X,".","") I A="OTHER" K X Q
F I=1:1:$L(A," ") S B=$P(A," ",I) I B="QD"!(B="QOD")!(B="HS")!(B="TIW") K X
Q
ENPSJT ; Validate one-time PRN conflict
N A,B
S A=$$GET1^DIQ(51.1,DA,.01),B=""
I A["PRN",X'="P" D
. S B="Conflict: Schedule Name contains PRN but selected Schedule "
. S B=B_"Type is not PRN."
. K X
I A'["PRN",X="P" D
. S B="Conflict: Schedule Name does not contain PRN but selected "
. S B=B_"Schedule Type is PRN."
. K X
I $L(B)>0 W !,B
Q
PSSJSV ;BIR/CML3/WRT-SCHEDULE VALIDATION ;06/24/96
+1 ;;1.0;PHARMACY DATA MANAGEMENT;**20,38,56,59,110,121**;9/30/97;Build 1
+2 ;
+3 ; Reference to ^PS(51.15 is supported by DBIA #2132
+4 ; Reference to $$UP^XLFSTR(P1) is supported by DBIA #10104
+5 ;
EN ;
+1 SET X=PSJX
SET (PSJAT,PSJM,PSJTS,PSJY,PSJAX)=""
IF $SELECT(X["""":1,$ASCII(X)=45:1,X'?.ANP:1,$LENGTH(X," ")>2:1,$LENGTH(X)>70:1,$LENGTH(X)<1:1,X["P RN":1,1:X["PR N")
KILL PSJX,X
QUIT
+2 IF X["PRN"!(X="ON CALL")!(X="ONCALL")!(X="ON-CALL")
GOTO DONE
+3 IF X?1."?"
IF '$DATA(PSJNE)
DO ENSVH^PSSJSV0
QUIT
+4 SET X0=X
SET (XT,Y)=""
IF X
IF X'["X"
IF (X?2.4N1"-".E!(X?2.4N))
DO ENCHK
IF $DATA(X)
SET PSJAT=X
GOTO DONE
+5 IF X["@"
DO DW
IF $DATA(X)
SET PSJAT=$PIECE(X,"@",2)
GOTO DONE
+6 IF $SELECT($DATA(^PS(51.1,"AC",PSJPP,X)):1,1:$EXTRACT($ORDER(^(X)),1,$LENGTH(X))=X)
DO DIC
IF $SELECT(PSJY
GOTO DONE
+7 IF $SELECT(X="NOW":1,X="ONCE":1,X="STAT":1,X="ONE TIME":1,X="ONETIME":1,X="1TIME":1,X="1-TIME":1,X="1 TIME":1,1:X="ONE-TIME")
SET PSJTS="O"
IF '$DATA(PSJNE)
WRITE " (ONCE ONLY)"
GOTO DONE
+8 IF PSJTS=""
SET PSJTS="C"
IF PSJAT=""
IF '$DATA(PSJNE)
WRITE " (Non standard schedule)"
SET X=PSJX
+9 IF $EXTRACT(X,1,2)="AD"
KILL X
GOTO DONE
+10 IF $EXTRACT(X,1,3)="BID"!($EXTRACT(X,1,3)="TID")!($EXTRACT(X,1,3)="QID")
SET PSJM=1440\$FIND("BTQ",$EXTRACT(X))
GOTO DONE
+11 IF $EXTRACT(X)="Q"
SET X=$EXTRACT(X,2,99)
IF 'X
SET X="1"_X
SET X1=+X
SET X=$PIECE(X,+X,2)
SET X2=0
IF X1<0
SET X1=-X1
IF $EXTRACT(X)="X"
SET X2=X1
SET X=$EXTRACT(X,2,99)
IF 'X2
IF $EXTRACT(X)="O"
SET X2=.5
SET X=$EXTRACT(X,2,99)
+12 SET XT=$SELECT(X["'":1,(X["D"&(X'["AD"))!(X["AM")!(X["PM")!(X["HS"&(X'["THS")):1440,X["H"&(X'["TH"):60,X["AC"!(X["PC"):480,X["W":10080,X["M":40320,1:-1)
IF XT<0
IF PSJAT=""
KILL X
GOTO DONE
+13 SET X=PSJX
IF XT
IF X2
SET XT=XT\X2
IF 'X2
SET XT=XT*X1
+14 SET PSJM=XT
+15 ;
DONE ;
+1 IF $DATA(X)[0
KILL PSJX
KILL D,DIC,Q,QX,SDW,SWD,X,X0,X1,X2,XT,Y,Z
QUIT
+2 ;
ENCHK ; admin times
+1 IF $SELECT($LENGTH($PIECE(X,"-"))>4:1,$LENGTH(X)>119:1,$LENGTH(X)<2:1,X'>0:1,1:X'?.ANP)
KILL X
QUIT
+2 SET X(1)=$PIECE(X,"-")
IF X(1)'?2N
IF X(1)'?4N
KILL X
QUIT
+3 SET X(1)=$LENGTH(X(1))
FOR X(2)=2:1:$LENGTH(X,"-")
SET X(3)=$PIECE(X,"-",X(2))
IF $SELECT($LENGTH(X(3))'=X(1):1,X(3)>$SELECT(X(1)=2:24,1:2400):1,1:X(3)'>$PIECE(X,"-",X(2)-1))
KILL X
QUIT
+4 IF $DATA(X)
KILL X(1),X(2),X(3)
QUIT
+5 ;
DIC ; 51.1 look-up
+1 SET DIC="^PS(51.1,"
SET DIC(0)=$EXTRACT("E",'$DATA(PSJNE))_"ISZ"
SET DIC("W")="I '$D(PSJNE) D DICW^PSSJSV0"
SET D="AP"_PSJPP
+2 DO IX^DIC
KILL DIC
IF Y'>0
QUIT
SET PSJY=+Y
SET (PSJX,X,X0)=Y(0,0)
SET PSJM=$PIECE(Y(0),"^",3)
SET PSJTS=$PIECE(Y(0),"^",5)
SET PSJAX=$PIECE(Y(0),U,7)
IF PSJTS=""
SET PSJTS="C"
IF PSJTS="O"!(PSJTS["R")
QUIT
IF $DATA(PSJW)
IF $DATA(^PS(51.1,+Y,1,+PSJW,0))
SET PSJAT=$PIECE(^(0),"^",PSJTS="S"+2)
+3 IF '$TEST
SET PSJAT=$PIECE(Y(0),"^",PSJTS="S"*4+2)
+4 IF PSJTS'="S"
QUIT
+5 FOR Y=1:1:$LENGTH(PSJAT,"-")
SET Y(1)=$PIECE(PSJAT,"-",Y)
SET PSJAT(Y(1))=""
SET Y(2)=$ORDER(^PS(51.15,"ACP",PSJPP,Y(1),0))
IF Y(2)
IF $DATA(^PS(51.15,Y(2),0))
SET PSJAT(Y(1))=$PIECE(^(0),"^",3)
IF $DATA(PSJW)
IF $DATA(^(1,PSJW,0))
IF $PIECE(^(0),"^",2)]""
SET PSJAT(Y(1))=$PIECE(^(0),"^",2)
+6 QUIT
+7 ;
DW ; week days
+1 SET SWD="SUNDAYS^MONDAYS^TUESDAYS^WEDNESDAYS^THURSDAYS^FRIDAYS^SATURDAYS"
SET SDW=X
SET X=$PIECE(X,"@",2)
DO ENCHK
IF '$DATA(X)
QUIT
SET X=$PIECE(SDW,"@")
SET X(1)="-"
IF X?.E1P.E
IF X'["-"
FOR QX=1:1:$LENGTH(X)
IF $EXTRACT(X,QX)?1P
SET X(1)=$EXTRACT(X,QX)
QUIT
+2 FOR Q=1:1:$LENGTH(X,X(1))
IF SWD=""
KILL X
IF SWD=""
QUIT
SET Z=$PIECE(X,X(1),Q)
DO DWC
IF '$DATA(X)
QUIT
+3 KILL X(1)
IF $DATA(X)
SET X=SDW
QUIT
DWC IF $LENGTH(Z)<2
KILL X
QUIT
+1 FOR QX=1:1:$LENGTH(SWD,"^")
SET Y=$PIECE(SWD,"^",QX)
IF $PIECE(Y,Z)=""
SET SWD=$PIECE(SWD,Y,2)
IF $LENGTH(SWD)
SET SWD=$EXTRACT(SWD,2,50)
QUIT
+2 IF '$TEST
KILL X
+3 QUIT
+4 ;
ENSNV ; schedule name
+1 IF $SELECT(X["""":1,$ASCII(X)=45:1,X'?.ANP:1,$LENGTH(X)>20:1,$LENGTH(X)<2:1,1:X?1P.E)
KILL X
QUIT
+2 IF $SELECT('$DATA(PSJPP):0,PSJPP="":1,PSJPP'?.ANP:1,1:'$$VERSION^XPDUTL(PSJPP))
KILL X
+3 IF $DATA(DA)
IF $DATA(^PS(51.1,DA,0))
IF $PIECE(^(0),"^",5)["D"
SET ZX=X
DO DNVX
IF $DATA(X)
SET X=ZX
KILL Z1,Z2,Z3,Z4,ZX
+4 QUIT
+5 ;
ENSHV ; shift in 51.1
+1 IF $SELECT($LENGTH(X)>11:1,$LENGTH(X)<1:1,'$DATA(PSJPP):1,PSJPP="":1,PSJPP'?.ANP:1,1:'$$VERSION^XPDUTL(PSJPP))
KILL X
QUIT
+2 FOR X(1)=1:1:$LENGTH(X,"-")
SET X(2)=$PIECE(X,"-",X(1))
IF $SELECT(X(2)="":1,X(2)'?.ANP:1,1:'$DATA(^PS(51.15,"ACP",PSJPP,X(2))))
KILL X
QUIT
+3 KILL X(1),X(2)
QUIT
+4 ;
ENVSST ; shift start/stop times
+1 IF X'?2N1"-"2N
IF X'?4N1"-"4N
KILL X
QUIT
+2 FOR X(1)=1,2
IF $PIECE(X,"-",X(1))>$SELECT($LENGTH($PIECE(X,"-",X(1)))<4:24,1:2400)
KILL X
QUIT
+3 KILL X(1)
QUIT
+4 ;
ENFQD ; frequency default
+1 NEW X1,X2,Z
SET Z=$SELECT($DATA(^PS(51.1,DA,0)):$PIECE(^(0),"^"),1:"")
SET X=""
+2 SET X=$PIECE(Z,"^",3)
IF Z]""
QUIT
+3 SET Z=DA
IF $EXTRACT(Z,1,2)="AD"
QUIT
+4 IF $EXTRACT(Z,1,3)="BID"!($EXTRACT(Z,1,3)="TID")!($EXTRACT(Z,1,3)="QID")
SET X=1440/$FIND("BTQ",$EXTRACT(Z))
QUIT
+5 IF '$TEST
IF $EXTRACT(Z)="Q"
SET Z=$EXTRACT(Z,2,99)
IF 'Z
SET Z="1"_Z
SET X1=+Z
SET Z=$PIECE(Z,+Z,2)
SET X2=0
IF $EXTRACT(Z)="X"
SET X2=X1
SET Z=$EXTRACT(Z,2,99)
IF 'X2
IF $EXTRACT(Z)="O"
SET X2=.5
SET Z=$EXTRACT(Z,2,99)
+6 SET X=$SELECT(Z["'":1,(Z["D"&(Z'["AD"))!(Z["AM")!(Z["PM")!(Z["HS"&(Z'["THS")):1440,Z["H"&(Z'["TH"):60,Z["AC"!(Z["PC"):480,Z["W":10080,Z["M":40320,1:"")
IF 'X
QUIT
IF X2
SET X=X\X2
IF 'X2
SET X=X*X1
QUIT
+7 ;
ENDNV ; day of the week name
+1 NEW Z1,Z2,Z3,Z4
SET X=$SELECT($DATA(^PS(51.1,DA,0)):$PIECE(^(0),"^"),1:"")
IF X=""
KILL X
QUIT
+2 ;
DNVX SET Z2=1
SET Z4="-"
IF X'["-"
IF X?.E1P.E
FOR Z1=1:1:$LENGTH(X)
IF $EXTRACT(X,Z1)?1P
SET Z4=$EXTRACT(X,Z1)
QUIT
+1 FOR Z1=1:1:$LENGTH(X,Z4)
IF 'Z2
QUIT
SET Z2=0
IF $LENGTH($PIECE(X,Z4,Z1))>1
FOR Z3="MONDAYS","TUESDAYS","WEDNESDAYS","THURSDAYS","FRIDAYS","SATURDAYS","SUNDAYS"
IF $PIECE(Z3,$PIECE(X,Z4,Z1))=""
SET Z2=1
QUIT
+2 IF 'Z2
KILL X
IF Z2
SET X="D"
QUIT
ENPSJ ;validate schedule names for PSJ package
+1 NEW A,B,I
+2 SET X=$$UP^XLFSTR(X)
+3 IF $GET(PSJPP)'="PSJ"
QUIT
+4 SET A=$TRANSLATE(X,".","")
IF A="OTHER"
KILL X
QUIT
+5 FOR I=1:1:$LENGTH(A," ")
SET B=$PIECE(A," ",I)
IF B="QD"!(B="QOD")!(B="HS")!(B="TIW")
KILL X
+6 QUIT
ENPSJT ; Validate one-time PRN conflict
+1 NEW A,B
+2 SET A=$$GET1^DIQ(51.1,DA,.01)
SET B=""
+3 IF A["PRN"
IF X'="P"
Begin DoDot:1
+4 SET B="Conflict: Schedule Name contains PRN but selected Schedule "
+5 SET B=B_"Type is not PRN."
+6 KILL X
End DoDot:1
+7 IF A'["PRN"
IF X="P"
Begin DoDot:1
+8 SET B="Conflict: Schedule Name does not contain PRN but selected "
+9 SET B=B_"Schedule Type is PRN."
+10 KILL X
End DoDot:1
+11 IF $LENGTH(B)>0
WRITE !,B
+12 QUIT