-
Notifications
You must be signed in to change notification settings - Fork 1
/
ROOKVALI.m
64 lines (64 loc) · 1.21 KB
/
ROOKVALI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
ROOKVALI
Q
;
PATTERN(VALUE,PATTERN)
Q VALUE?@PATTERN
;
DATATYPE(TYPE)
N VALID S VALID=1
G:TYPE="STRING" DTEND
G:TYPE="NUMBER" DTEND
G:TYPE="HOROLOG" DTEND
G:TYPE="BOOLEAN" DTEND
S VALID=0
DTEND
Q VALID
;
BOOLEAN(VALUE)
N VALID S VALID=1
G:VALUE=1 BOOLEND
G:VALUE=0 BOOLEND
S VALID=0
BOOLEND
Q VALID
;
NUMBER(VALUE)
N VALID,CHAR S VALID=1,CHAR=""
N GOODCHAR S GOODCHAR="0123456789.-"
I $L(VALUE,".")>2 S VALID=0
I $L(VALUE,"-")>2 S VALID=0
I $L(VALUE,"-")=2 D
. I $E(VALUE,1,1)'="-" S VALID=0
. I $L(VALUE)=1 S VALID=0
G:VALID=0 NUMEND
N LENGTH S LENGTH=$L(VALUE)
F I=1:1:LENGTH D
. S CHAR=$E(VALUE,I,I)
. I '(GOODCHAR[CHAR) S VALID=0
NUMEND
Q VALID
;
STRING(VALUE)
N VALID S VALID=1
I $$NUMBER(VALUE) S VALID=0
I $$BOOLEAN(VALUE) S VALID=0
I $$HORO(VALUE) S VALID=0
STREND
Q VALID
;
HORO(VALUE)
N VALID S VALID=1
I $L(VALUE,",")'=2 S VALID=0
I $L(VALUE,",")=2 D
. I '$$NUMBER($P(VALUE,",",1)) S VALID=0
. I '$$NUMBER($P(VALUE,",",2)) S VALID=0
Q VALID
;
BYTYPE(DATATYPE,VALUE)
N VALID S VALID=1
I DATATYPE="STRING" S VALID=$$STRING(VALUE)
I DATATYPE="NUMBER" S VALID=$$NUMBER(VALUE)
I DATATYPE="HOROLOG" S VALID=$$HORO(VALUE)
I DATATYPE="BOOLEAN" S VALID=$$BOOLEAN(VALUE)
Q VALID
;