OOPSUTL3 ;HINES/WAA-Utilities Routines ;3/24/98
;;2.0;ASISTS;;Jun 03, 2002
;;
CHECK(IEN,FORM) ; Checks to see if there was data enter for a form
N ANS,I,LIST,FIELD
S ANS=0
I FORM="CA1" S LIST="130,176,138,139,140,175,146,148,150,156,157,158,159,160,161,162,163"
; Patch 8 - removed field 250 from list below
I FORM="CA2" S LIST="230,237,242,243,244,245,246,247,248,249,251,252,258"
F I=1:1 S FIELD=$P(LIST,",",I) Q:FIELD="" D Q:ANS
.I $$GET1^DIQ(2260,IEN,FIELD,"I")'="" S ANS=1
.Q
Q ANS
PSDTCHK(DATE,NOYR,FLD) ;
; this functionality returns a valid date (the one passed in) if
; the current date (DT) minus the date passed in (DATE) is less than
; the value in NOYR. Specific checking also occurs if date pasted in
; is the DOB (field 6).
;
; Note: DT must be defined to run
; Input: DATE = external value of the date entered by user
; NOYR = # of years in past to check date entered in against
; FLD = field number of the field
; Output: VAL = DATE passed in if valid (true)
; "" if not valid
N VAL
S VAL=DATE
I '$G(IEN) S IEN=$G(DA)
I DATE>0,(($E(DT,1,3)-$E(DATE,1,3))>NOYR) S VAL="" D
. W !!?5,$$GET1^DID(2260,FLD,"","LABEL")_" cannot be more than "_NOYR_" years in the past.",!
I VAL,IEN,FLD=6,$$GET1^DIQ(2260,IEN,4,"I") D
. I DATE>$$GET1^DIQ(2260,IEN,4,"I") S VAL="" W !!?5,"DOB cannot be after "_$$GET1^DID(2260,4,"","LABEL"),!
Q VAL
NMCHK(NA) ; Checks format for name fields
;
; Input - NA = value entered (X) for name
; Output - VALID = 1 if format valid
; 0 if format not valid
;
N VALID,LN
S VALID=1
I (NA?1P.E)!(NA'?1U.ANP)!(NA'[",") S VALID=0
I $TR(NA,"~`!@#$%^&*()_+=|}{[]\:;'?><./","")'=NA S VALID=0
S LN=$P(NA,",") I (LN[" ")!($L(LN)=0) S VALID=0
I $P(NA,",",2)="" S VALID=0
Q VALID
NMERR ; Error message to print if error on name check and doing input
W !,"Enter the person's name, using the format LASTNAME,FIRSTNAME."
W !,"Suffixes such as Sr, Jr, III can only be entered as a FIRSTNAME."
W !,"There must be a LAST NAME and FIRST NAME separated by a comma."
W !,"Spaces in the last name are not allowed and the only "
W !,"punctuation allowed is a hyphen (-) or comma (,).",!
Q
WIT() ; Check if Witness name exists that other witness fields have data
;
N ARR,I,J,LAST,STR,VALID,WIT,VCHAR
S VALID=1,VCHAR=1
S WIT=$O(^OOPS(2260,IEN,"CA1W",0))
I '$G(WIT) Q VALID
S LAST=$P($G(^OOPS(2260,IEN,"CA1W",0)),U,3)
F I=WIT:1:LAST I $G(^OOPS(2260,IEN,"CA1W",I,0))'="" D
. S STR=^OOPS(2260,IEN,"CA1W",I,0)
. F J=2:1:6 I $P($G(STR),U,J)="" S VALID=0,ARR($P(STR,U,1),J)=""
. F J=2:1:3 I $P($G(STR),U,J)'=$TR($P($G(STR),U,J),"~`@#$%^*_|\}{[]><","") S VCHAR=0
. I $P($G(STR),U,6) D
.. I ($$GET1^DIQ(2260,IEN,4,"I")\1)>$P(STR,U,6) S VALID=0
I 'VALID,$D(ARR) D
. W !," Witness Data is incomplete for the following Witnesses, enter missing data."
. S I="" F S I=$O(ARR(I)) Q:I="" W !?7,I," is missing the" D
.. S J="" F S J=$O(ARR(I,J)) Q:J="" W !?9,$$GET1^DID(2260.0125,J-1,"","LABEL")
I 'VALID D
. I $P(STR,U,6) W !," Date of Witness Signature cannot be prior to DATE/TIME OF OCCURRENCE."
I 'VCHAR W !," Address or City contains invalid characters:",!?7,"(~,`,@,#,$,%,*,_,|,\,},{,[,],>,or <). Please Edit"
Q VALID_U_VCHAR
REG(IEN,FIELD) ; Regular work schedule
N DIR,Y
N ANS,ANSS,LINE
S (ANSS,ANS)=""
I FIELD=140 S ANSS=$P($G(^OOPS(2260,IEN,"CA1F")),U,11)
I FIELD=244 S ANSS=$P($G(^OOPS(2260,IEN,"CA2I")),U,8)
I ANSS'="" D
.W !," YOU LAST SELECTED: "
.N I,DAY
.F I=1:1 S DAY=$P(ANSS,",",I) Q:DAY="" D
.. I DAY=1 W !," 1) SUNDAY"
.. I DAY=2 W !," 2) MONDAY"
.. I DAY=3 W !," 3) TUESDAY"
.. I DAY=4 W !," 4) WEDNESDAY"
.. I DAY=5 W !," 5) THURSDAY"
.. I DAY=6 W !," 6) FRIDAY"
.. I DAY=7 W !," 7) SATURDAY"
..Q
.W !
.Q
W !
S LINE=" "_$S(FIELD=140:"20",FIELD=244:"22",1:"")_". REGULAR WORK SCHEDULE:"
W !,LINE
W !," 1) SUNDAY"
W !," 2) MONDAY"
W !," 3) TUESDAY"
W !," 4) WEDNESDAY"
W !," 5) THURSDAY"
W !," 6) FRIDAY"
W !," 7) SATURDAY"
W !
S DIR(0)="LAO^1:7"
S DIR("A")="SELECT THE DAYS OF THE WEEK: "
S DIR("?")="This response must be a list or range, e.g., 1,3,5 or 2-4,8."
S DIR("?",1)="ENTER THE NUMBER OF THE DAY/S OF THE WEEK WORKED"
S DIR("?",2)=" 1-3,6,7 WOULD BE: "
S DIR("?",3)=" SUNDAY THRU TUESDAY, FRIDAY AND SATURDAY."
D ^DIR
I $D(Y(0)) D
.S ANS=Y
.I FIELD=140 S $P(^OOPS(2260,IEN,"CA1F"),U,11)=ANS
.I FIELD=244 S $P(^OOPS(2260,IEN,"CA2I"),U,8)=ANS
.Q
Q
TI ;TIME INPUT TRANS FORM
S X=$TR(X,"adimnop","ADIMNOP")
I X?1"12".A S X=$S(X="12M":"MID",X="12N":"NOON",1:X)
I X?1.A S X=$S(X["MID":2400,X["NOON":1200,1:"")
S:$E(X,$L(X))="M" X=$E(X,1,$L(X)-1) S X1=$E(X,$L(X)) I X1?1U,"AP"'[X1 G ERR
S X1=$P(X,":",2) I X1'="",X1'?2N1.2U G ERR
I X'?4N,$S($L(+X)<3:+X,1:+X\100)>12 G ERR
S X=$P(X,":",1)_$P(X,":",2),X1=X
G:X?4N A I X'?1.4N1.2U G ERR
S:X<13 X=X*100 I X1["A" G:X>1259 ERR S X=$S(X=1200:2400,X>1159:X-1200,1:X)
E I X<1200,X1["P"!(X<600) S X=X+1200 I X<1300 G ERR
A I X>2400!('X&(X'="0000"))!(X#100>59) G ERR
S X1=+X I 'X1!(X1=1200)!(X1=2400) S X=$S(X1=1200:"NOON",1:"MID") G DNE
S X1=$S(X1>1259:X1-1200,1:X1),X1=$E("000",0,4-$L(X1))_X1_$S(X=2400:"A",X>1159:"P",1:"A")
I "00^15^30^45"'[$E(X1,3,4) G ERR
S X=$E(X1,1,2)_":"_$E(X1,3,5)
DNE K X1 Q
ERR K X,X1 Q
CNV ; Convert Start/Stop to minutes
; X=start_"^"_stop Output: Y=start(min)_"^"_stop(min)
S CNX=X,X=$P(CNX,"^",1),Y=0 D MIL S Y=Y\100*60+(Y#100),$P(CNX,"^",1)=Y
S X=$P(CNX,"^",2),Y=1 D MIL S Y=Y\100*60+(Y#100)
S Y=$P(CNX,"^",1)_"^"_Y K CNX Q
MIL ; Convert from AM/PM to 2400
; X=time Y: 0=Mid=0,1=Mid=2400 Output: Y=time in 2400
I X="MID"!(X="NOON") S Y=$S(X="NOON":1200,Y:2400,1:0) Q
S Y=$P(X,":",1)_$P(X,":",2),Y=+Y Q:X["A"
S:Y<1200 Y=Y+1200 Q
HLP ; Time Help
W !?5,"Time may be entered as 8A or 8a, 8:00A, 8:15A, 8:15AM or military"
W !?5,"time: 0800, 1300; or MID or 12M for midnight; NOON or 12N for noon."
W !?5,"Time must be in quarter hours; e.g., 8A or 8:15A or 8:30A or 8:45A.",!
Q
DC(OPDT) ; Convert Date to YYYYMMDD
;
; Input: OPDT = Date to be converted
; Output: COPDT = Converted Date
S COPDT=""
S:OPDT]"" COPDT=OPDT+17000000\1
Q COPDT
HM(TIME) ;Convert Regular Hrs. From Time and Regular Hrs To Time
; to HHMM (HOUR AND MINUTE)
;
; Input: TIME = Time converted to military time(21:00P), Noon and Mid
; Output: OTIME= Formatted time in HHMM
;
S OTIME=$S(TIME="MID":2400,TIME="NOON":1200,1:TIME)
I $E(TIME,$L(TIME))="A" S OTIME=$TR($E(TIME,1,5),":")
I $E(TIME,$L(TIME))="P" D
. S OTIME=$TR($E(TIME,1,5),":")
. I OTIME<1200 S OTIME=OTIME+1200
Q OTIME
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HOOPSUTL3 7022 printed Oct 16, 2024@17:40:38 Page 2
OOPSUTL3 ;HINES/WAA-Utilities Routines ;3/24/98
+1 ;;2.0;ASISTS;;Jun 03, 2002
+2 ;;
CHECK(IEN,FORM) ; Checks to see if there was data enter for a form
+1 NEW ANS,I,LIST,FIELD
+2 SET ANS=0
+3 IF FORM="CA1"
SET LIST="130,176,138,139,140,175,146,148,150,156,157,158,159,160,161,162,163"
+4 ; Patch 8 - removed field 250 from list below
+5 IF FORM="CA2"
SET LIST="230,237,242,243,244,245,246,247,248,249,251,252,258"
+6 FOR I=1:1
SET FIELD=$PIECE(LIST,",",I)
if FIELD=""
QUIT
Begin DoDot:1
+7 IF $$GET1^DIQ(2260,IEN,FIELD,"I")'=""
SET ANS=1
+8 QUIT
End DoDot:1
if ANS
QUIT
+9 QUIT ANS
PSDTCHK(DATE,NOYR,FLD) ;
+1 ; this functionality returns a valid date (the one passed in) if
+2 ; the current date (DT) minus the date passed in (DATE) is less than
+3 ; the value in NOYR. Specific checking also occurs if date pasted in
+4 ; is the DOB (field 6).
+5 ;
+6 ; Note: DT must be defined to run
+7 ; Input: DATE = external value of the date entered by user
+8 ; NOYR = # of years in past to check date entered in against
+9 ; FLD = field number of the field
+10 ; Output: VAL = DATE passed in if valid (true)
+11 ; "" if not valid
+12 NEW VAL
+13 SET VAL=DATE
+14 IF '$GET(IEN)
SET IEN=$GET(DA)
+15 IF DATE>0
IF (($EXTRACT(DT,1,3)-$EXTRACT(DATE,1,3))>NOYR)
SET VAL=""
Begin DoDot:1
+16 WRITE !!?5,$$GET1^DID(2260,FLD,"","LABEL")_" cannot be more than "_NOYR_" years in the past.",!
End DoDot:1
+17 IF VAL
IF IEN
IF FLD=6
IF $$GET1^DIQ(2260,IEN,4,"I")
Begin DoDot:1
+18 IF DATE>$$GET1^DIQ(2260,IEN,4,"I")
SET VAL=""
WRITE !!?5,"DOB cannot be after "_$$GET1^DID(2260,4,"","LABEL"),!
End DoDot:1
+19 QUIT VAL
NMCHK(NA) ; Checks format for name fields
+1 ;
+2 ; Input - NA = value entered (X) for name
+3 ; Output - VALID = 1 if format valid
+4 ; 0 if format not valid
+5 ;
+6 NEW VALID,LN
+7 SET VALID=1
+8 IF (NA?1P.E)!(NA'?1U.ANP)!(NA'[",")
SET VALID=0
+9 IF $TRANSLATE(NA,"~`!@#$%^&*()_+=|}{[]\:;'?><./","")'=NA
SET VALID=0
+10 SET LN=$PIECE(NA,",")
IF (LN[" ")!($LENGTH(LN)=0)
SET VALID=0
+11 IF $PIECE(NA,",",2)=""
SET VALID=0
+12 QUIT VALID
NMERR ; Error message to print if error on name check and doing input
+1 WRITE !,"Enter the person's name, using the format LASTNAME,FIRSTNAME."
+2 WRITE !,"Suffixes such as Sr, Jr, III can only be entered as a FIRSTNAME."
+3 WRITE !,"There must be a LAST NAME and FIRST NAME separated by a comma."
+4 WRITE !,"Spaces in the last name are not allowed and the only "
+5 WRITE !,"punctuation allowed is a hyphen (-) or comma (,).",!
+6 QUIT
WIT() ; Check if Witness name exists that other witness fields have data
+1 ;
+2 NEW ARR,I,J,LAST,STR,VALID,WIT,VCHAR
+3 SET VALID=1
SET VCHAR=1
+4 SET WIT=$ORDER(^OOPS(2260,IEN,"CA1W",0))
+5 IF '$GET(WIT)
QUIT VALID
+6 SET LAST=$PIECE($GET(^OOPS(2260,IEN,"CA1W",0)),U,3)
+7 FOR I=WIT:1:LAST
IF $GET(^OOPS(2260,IEN,"CA1W",I,0))'=""
Begin DoDot:1
+8 SET STR=^OOPS(2260,IEN,"CA1W",I,0)
+9 FOR J=2:1:6
IF $PIECE($GET(STR),U,J)=""
SET VALID=0
SET ARR($PIECE(STR,U,1),J)=""
+10 FOR J=2:1:3
IF $PIECE($GET(STR),U,J)'=$TRANSLATE($PIECE($GET(STR),U,J),"~`@#$%^*_|\}{[]><","")
SET VCHAR=0
+11 IF $PIECE($GET(STR),U,6)
Begin DoDot:2
+12 IF ($$GET1^DIQ(2260,IEN,4,"I")\1)>$PIECE(STR,U,6)
SET VALID=0
End DoDot:2
End DoDot:1
+13 IF 'VALID
IF $DATA(ARR)
Begin DoDot:1
+14 WRITE !," Witness Data is incomplete for the following Witnesses, enter missing data."
+15 SET I=""
FOR
SET I=$ORDER(ARR(I))
if I=""
QUIT
WRITE !?7,I," is missing the"
Begin DoDot:2
+16 SET J=""
FOR
SET J=$ORDER(ARR(I,J))
if J=""
QUIT
WRITE !?9,$$GET1^DID(2260.0125,J-1,"","LABEL")
End DoDot:2
End DoDot:1
+17 IF 'VALID
Begin DoDot:1
+18 IF $PIECE(STR,U,6)
WRITE !," Date of Witness Signature cannot be prior to DATE/TIME OF OCCURRENCE."
End DoDot:1
+19 IF 'VCHAR
WRITE !," Address or City contains invalid characters:",!?7,"(~,`,@,#,$,%,*,_,|,\,},{,[,],>,or <). Please Edit"
+20 QUIT VALID_U_VCHAR
REG(IEN,FIELD) ; Regular work schedule
+1 NEW DIR,Y
+2 NEW ANS,ANSS,LINE
+3 SET (ANSS,ANS)=""
+4 IF FIELD=140
SET ANSS=$PIECE($GET(^OOPS(2260,IEN,"CA1F")),U,11)
+5 IF FIELD=244
SET ANSS=$PIECE($GET(^OOPS(2260,IEN,"CA2I")),U,8)
+6 IF ANSS'=""
Begin DoDot:1
+7 WRITE !," YOU LAST SELECTED: "
+8 NEW I,DAY
+9 FOR I=1:1
SET DAY=$PIECE(ANSS,",",I)
if DAY=""
QUIT
Begin DoDot:2
+10 IF DAY=1
WRITE !," 1) SUNDAY"
+11 IF DAY=2
WRITE !," 2) MONDAY"
+12 IF DAY=3
WRITE !," 3) TUESDAY"
+13 IF DAY=4
WRITE !," 4) WEDNESDAY"
+14 IF DAY=5
WRITE !," 5) THURSDAY"
+15 IF DAY=6
WRITE !," 6) FRIDAY"
+16 IF DAY=7
WRITE !," 7) SATURDAY"
+17 QUIT
End DoDot:2
+18 WRITE !
+19 QUIT
End DoDot:1
+20 WRITE !
+21 SET LINE=" "_$SELECT(FIELD=140:"20",FIELD=244:"22",1:"")_". REGULAR WORK SCHEDULE:"
+22 WRITE !,LINE
+23 WRITE !," 1) SUNDAY"
+24 WRITE !," 2) MONDAY"
+25 WRITE !," 3) TUESDAY"
+26 WRITE !," 4) WEDNESDAY"
+27 WRITE !," 5) THURSDAY"
+28 WRITE !," 6) FRIDAY"
+29 WRITE !," 7) SATURDAY"
+30 WRITE !
+31 SET DIR(0)="LAO^1:7"
+32 SET DIR("A")="SELECT THE DAYS OF THE WEEK: "
+33 SET DIR("?")="This response must be a list or range, e.g., 1,3,5 or 2-4,8."
+34 SET DIR("?",1)="ENTER THE NUMBER OF THE DAY/S OF THE WEEK WORKED"
+35 SET DIR("?",2)=" 1-3,6,7 WOULD BE: "
+36 SET DIR("?",3)=" SUNDAY THRU TUESDAY, FRIDAY AND SATURDAY."
+37 DO ^DIR
+38 IF $DATA(Y(0))
Begin DoDot:1
+39 SET ANS=Y
+40 IF FIELD=140
SET $PIECE(^OOPS(2260,IEN,"CA1F"),U,11)=ANS
+41 IF FIELD=244
SET $PIECE(^OOPS(2260,IEN,"CA2I"),U,8)=ANS
+42 QUIT
End DoDot:1
+43 QUIT
TI ;TIME INPUT TRANS FORM
+1 SET X=$TRANSLATE(X,"adimnop","ADIMNOP")
+2 IF X?1"12".A
SET X=$SELECT(X="12M":"MID",X="12N":"NOON",1:X)
+3 IF X?1.A
SET X=$SELECT(X["MID":2400,X["NOON":1200,1:"")
+4 if $EXTRACT(X,$LENGTH(X))="M"
SET X=$EXTRACT(X,1,$LENGTH(X)-1)
SET X1=$EXTRACT(X,$LENGTH(X))
IF X1?1U
IF "AP"'[X1
GOTO ERR
+5 SET X1=$PIECE(X,":",2)
IF X1'=""
IF X1'?2N1.2U
GOTO ERR
+6 IF X'?4N
IF $SELECT($LENGTH(+X)<3:+X,1:+X\100)>12
GOTO ERR
+7 SET X=$PIECE(X,":",1)_$PIECE(X,":",2)
SET X1=X
+8 if X?4N
GOTO A
IF X'?1.4N1.2U
GOTO ERR
+9 if X<13
SET X=X*100
IF X1["A"
if X>1259
GOTO ERR
SET X=$SELECT(X=1200:2400,X>1159:X-1200,1:X)
+10 IF '$TEST
IF X<1200
IF X1["P"!(X<600)
SET X=X+1200
IF X<1300
GOTO ERR
A IF X>2400!('X&(X'="0000"))!(X#100>59)
GOTO ERR
+1 SET X1=+X
IF 'X1!(X1=1200)!(X1=2400)
SET X=$SELECT(X1=1200:"NOON",1:"MID")
GOTO DNE
+2 SET X1=$SELECT(X1>1259:X1-1200,1:X1)
SET X1=$EXTRACT("000",0,4-$LENGTH(X1))_X1_$SELECT(X=2400:"A",X>1159:"P",1:"A")
+3 IF "00^15^30^45"'[$EXTRACT(X1,3,4)
GOTO ERR
+4 SET X=$EXTRACT(X1,1,2)_":"_$EXTRACT(X1,3,5)
DNE KILL X1
QUIT
ERR KILL X,X1
QUIT
CNV ; Convert Start/Stop to minutes
+1 ; X=start_"^"_stop Output: Y=start(min)_"^"_stop(min)
+2 SET CNX=X
SET X=$PIECE(CNX,"^",1)
SET Y=0
DO MIL
SET Y=Y\100*60+(Y#100)
SET $PIECE(CNX,"^",1)=Y
+3 SET X=$PIECE(CNX,"^",2)
SET Y=1
DO MIL
SET Y=Y\100*60+(Y#100)
+4 SET Y=$PIECE(CNX,"^",1)_"^"_Y
KILL CNX
QUIT
MIL ; Convert from AM/PM to 2400
+1 ; X=time Y: 0=Mid=0,1=Mid=2400 Output: Y=time in 2400
+2 IF X="MID"!(X="NOON")
SET Y=$SELECT(X="NOON":1200,Y:2400,1:0)
QUIT
+3 SET Y=$PIECE(X,":",1)_$PIECE(X,":",2)
SET Y=+Y
if X["A"
QUIT
+4 if Y<1200
SET Y=Y+1200
QUIT
HLP ; Time Help
+1 WRITE !?5,"Time may be entered as 8A or 8a, 8:00A, 8:15A, 8:15AM or military"
+2 WRITE !?5,"time: 0800, 1300; or MID or 12M for midnight; NOON or 12N for noon."
+3 WRITE !?5,"Time must be in quarter hours; e.g., 8A or 8:15A or 8:30A or 8:45A.",!
+4 QUIT
DC(OPDT) ; Convert Date to YYYYMMDD
+1 ;
+2 ; Input: OPDT = Date to be converted
+3 ; Output: COPDT = Converted Date
+4 SET COPDT=""
+5 if OPDT]""
SET COPDT=OPDT+17000000\1
+6 QUIT COPDT
HM(TIME) ;Convert Regular Hrs. From Time and Regular Hrs To Time
+1 ; to HHMM (HOUR AND MINUTE)
+2 ;
+3 ; Input: TIME = Time converted to military time(21:00P), Noon and Mid
+4 ; Output: OTIME= Formatted time in HHMM
+5 ;
+6 SET OTIME=$SELECT(TIME="MID":2400,TIME="NOON":1200,1:TIME)
+7 IF $EXTRACT(TIME,$LENGTH(TIME))="A"
SET OTIME=$TRANSLATE($EXTRACT(TIME,1,5),":")
+8 IF $EXTRACT(TIME,$LENGTH(TIME))="P"
Begin DoDot:1
+9 SET OTIME=$TRANSLATE($EXTRACT(TIME,1,5),":")
+10 IF OTIME<1200
SET OTIME=OTIME+1200
End DoDot:1
+11 QUIT OTIME