-
Notifications
You must be signed in to change notification settings - Fork 1
/
ROOKDD.m
256 lines (256 loc) · 5.94 KB
/
ROOKDD.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
ROOKDD
Q
;
MKNEST(NEST,RESULT)
;
; SUBROUTINE DATA
;
N GLVN,TIMER,QRYTIME,DAT,NERES,NERET
S (RKRESULT,DAT(0))=1
S TIMER=$$BTIME^ROOK
;
; REQUIRE AN ACTIVE ROOK CONNECTION
;
I '$$CONNECTED^ROOK D
. D ERR^ROOK(13,.RESULT)
G:RKRESULT=0 ERMKNEST
S RKRESULT=1
;
; MAKE THE NEST IF THE NEST DOES NOT ALREADY EXIST
;
S NERET=$$NESTEXISTS(NEST,.NERES)
I NERES("RETURN")=0 D
. S GLVN="^"_NEST
. L (^ROOK("DD",NEST),@GLVN@("DATA"),@GLVN@("INDEX")):30
. I $TEST D
. . S ^ROOK("DD",NEST)=""
. . S @GLVN@("DATA")="",@GLVN@("INDEX")=""
. E D
. . D ERR^ROOK(20,.RESULT)
. I RKRESULT=1 D
. . L
. . S QTIME=$$ETIME^ROOK(TIMER)
. . D SUCCESS^ROOK(.RESULT,0,QTIME,1,.DAT)
. . I NEST'="INFOSCHEMA" D ADDSCHEMA^ROOKSCMA(NEST)
E D
. D ERR^ROOK(1,.RESULT)
ERMKNEST
Q RKRESULT
;
MKEGG(EGGDEF,RESULT)
;
; EGG ATTRIBUTES
;
N EGGNAME,EMBDEF,ENTNUM
;
; SUBROUTINE DATA
;
N TIMER,DATA
S DATA(0)=1,EGGNAME=""
;
; INITIALIZE QUERY TIMER
;
S TIMER=$$BTIME^ROOK
;
; REQUIRE AN ACTIVE ROOK CONNECTION AND SELECTED NEST
;
I '$$CONNECTED^ROOK D
. D ERR^ROOK(13,.RESULT)
G:RKRESULT=0 ERMKEGG
S RKRESULT=1
I $$USED^ROOK="" D
. D ERR^ROOK(10,.RESULT)
G:RKRESULT=0 ERMKEGG
S RKRESULT=1
;
; SET UP DATA STRUCTURES
;
S EGGNAME=$O(EGGDEF(EGGNAME))
S ENTNUM=EGGDEF(EGGNAME,"ENTRYNUMBER")
;
; FAIL IF EGG ALREADY EXISTS
;
N EGGEXRES,EGGEXRET
S EGGEXRET=$$EGGEXISTS^ROOKDD(EGGNAME,.EGGEXRET)
I EGGEXRET("RETURN")=1 D
. D ERR^ROOK(11,.RESULT)
G:RKRESULT=0 ERMKEGG
S RKRESULT=1
;
; CREATE THE DATA DICTIONARY ENTRY FOR THE EGG
;
L ^ROOK("DD",$$CURRENTNEST^ROOK,EGGNAME):30
I $TEST D
. S ^ROOK("DD",$$CURRENTNEST^ROOK,EGGNAME,"ENTRYNUMBER")=ENTNUM
E D
. D ERR^ROOK(20,.RESULT)
G:RKRESULT=0 ERMKEGG
L
S RKRESULT=1
;
; CREATE ANY DEFINED EMBRYOS
;
N EMBDEFS M EMBDEFS=EGGDEF(EGGNAME,"EMBRYOS")
N MKEMBRET,MKEMBRES
S MKEMBRET=$$MKEMBRYO(EGGNAME,.EMBDEFS,.MKEMBRES)
;
; PASS ANY ERRORS FROM $$MKEMBRYO THROUGH TO CALLER
;
I MKEMBRES("ERROR","CODE")>0 D
. D ERR^ROOK(MKEMBRES("ERROR","CODE"),.RESULT)
G:RKRESULT=0 ERMKEGG
S RKRESULT=1
;
; BUILD THE RETURN ARRAY AND QUIT
;
D SUCCESS^ROOK(.RESULT,1,$$ETIME^ROOK(TIMER),MKEMBRES("RECORDCOUNT")+1,.DATA)
ERMKEGG
Q RKRESULT
;
MKEMBRYO(EGGNAME,EMBDEF,RESULT)
;
; DATA ATTRIBUTES
;
N EMBNAME,TYPE,UNIQUE,REQ,PATTERN,IXF,OXF,PRIMARY,NEST,EMBCT,ERRCT,MAXLENGTH
S (EMBNAME,TYPE,PATTERN,IXF,OXF)=""
S (UNIQUE,REQ,PRIMARY,EMBCT,ERRCT)=0
S NEST=$$CURRENTNEST^ROOK
;
; SUBROUTINE DATA
;
N TIMER,DATA,EMBEXRES,EMBEXRET
S DATA(0)=1
;
; INITIALIZE QUERY TIMER
;
S TIMER=$$BTIME^ROOK
;
; REQUIRE CONNECTION TO ROOK
;
I '$$CONNECTED^ROOK D
. D ERR^ROOK(13,.RESULT)
G:RKRESULT=0 ERMKEMBRYO
S RKRESULT=1
;
; REQUIRE SELECTED NEST
; (SUCCESS HERE IMPLIES THAT THE NEST EXISTS)
;
I NEST="" D
. D ERR^ROOK(10,.RESULT)
G:RKRESULT=0 ERMKEMBRYO
S RKRESULT=1
;
; MAKE SURE EGG EXISTS
;
N EGGEXRES,EGGEXRET
S EGGEXRET=$$EGGEXISTS(EGGNAME,.EGGEXRES)
I EGGEXRES("RETURN")=0 D
. D ERR^ROOK(12,.RESULT)
G:RKRESULT=0 ERMKEMBRYO
S RKRESULT=1
;
; LOOP OVER THE EMBRYOS DEFINED IN THE EMBRYO DEFINITION
;
S EMBNAME=""
F S EMBNAME=$O(EMBDEF(EMBNAME)) Q:EMBNAME="" D
. ;
. ; ENSURE THE EMBRYO DOES NOT ALREADY EXIST
. ;
. K EMBEXRES
. S EMBEXRET=$$EMBRYOEXISTS(EGGNAME,EMBNAME,.EMBEXRES)
. I EMBEXRES("RETURN")=1 D
. . D ERR^ROOK(8,.RESULT)
. ;
. ; VALIDATE THE EMBRYO NAME
. ;
. I $$VALNAME^ROOK(EMBNAME)=0 D
. . D ERR^ROOK(15,.RESULT)
. ;
. ; PULL IN THE DATA
. ;
. S EMBCT=EMBCT+1
. S TYPE=$G(EMBDEF(EMBNAME,"TYPE"),"STRING")
. S UNIQUE=$G(EMBDEF(EMBNAME,"UNIQUE"),0)
. S REQ=$G(EMBDEF(EMBNAME,"REQUIRED"),0)
. S PATTERN=$G(EMBDEF(EMBNAME,"PATTERN"),"")
. S IXF=$G(EMBDEF(EMBNAME,"INPUTXFORM"),"")
. S OXF=$G(EMBDEF(EMBNAME,"OUTPUTXFORM"),"")
. S PRIMARY=$G(EMBDEF(EMBNAME,"PRIMARY"),0)
. S MAXLENGTH=$G(EMBDEF(EMBNAME,"MAXLENGTH"),"")
. ;
. ; IF PRIMARY IS SPECIFIED (1), UNIQUE AND REQUIRED
. ; MUST ALSO BE SPECIFIED
. ;
. I PRIMARY=1 D
. . I UNIQUE=0 D
. . . D ERR^ROOK(14,.RESULT)
. . . S ERRCT=$I(ERRCT)
. . I REQ=0 D
. . . D ERR^ROOK(14,.RESULT)
. . . S ERRCT=$I(ERRCT)
. Q:ERRCT>0
. S RKRESULT=1
. ;
. ; IF TYPE IS "STRING", "MAXLENGTH" MUST BE SPECIFIED
. ;
. I TYPE="STRING" D
. . I MAXLENGTH="" D ERR^ROOK(21,.RESULT) S ERRCT=$I(ERRCT)
. Q:ERRCT>0
. S RKRESULT=1
. ;
. ; ADD THE EMBRYO TO THE DATA DICTIONARY
. ;
. I RKRESULT=1 D
. . L ^ROOK("DD",NEST,EGGNAME,"EMBRYOS"):30
. . I $TEST D
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"TYPE")=TYPE
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"UNIQUE")=UNIQUE
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"REQUIRED")=REQ
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"PATTERN")=PATTERN
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"INPUTXFORM")=IXF
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"OUTPUTXFORM")=OXF
. . . S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"PRIMARY")=PRIMARY
. . . I TYPE="STRING" S ^ROOK("DD",NEST,EGGNAME,"EMBRYOS",EMBNAME,"MAXLENGTH")=MAXLENGTH
. . E D
. . . D ERR^ROOK(20,.RESULT)
. . L
I RKRESULT=1 D SUCCESS^ROOK(.RESULT,0,$$ETIME^ROOK(TIMER),EMBCT,.DATA)
ERMKEMBRYO
Q RKRESULT
;
NESTEXISTS(NEST,RESULT)
N ERRCT S ERRCT=0
N DATA S DATA(0)=1
I '$$CONNECTED^ROOK D
. D ERR^ROOK(13,.RESULT)
. S ERRCT=ERRCT+1
I $$USED^ROOK="" D
. D ERR^ROOK(10,.RESULT)
. S ERRCT=ERRCT+1
I ERRCT=0 D SUCCESS^ROOK(.RESULT,$D(^ROOK("DD",NEST)),0,0,.DATA)
Q RKRESULT
;
EGGEXISTS(EGG,RESULT)
N ERRCT S ERRCT=0
N DATA S DATA(0)=1
I '$$CONNECTED^ROOK D
. D ERR^ROOK(13,.RESULT)
. S ERRCT=ERRCT+1
I $$USED^ROOK="" D
. D ERR^ROOK(10,.RESULT)
. S ERRCT=ERRCT+1
I ERRCT=0 D SUCCESS^ROOK(.RESULT,$D(^ROOK("DD",$$CURRENTNEST^ROOK,EGG)),0,0,.DATA)
Q RKRESULT
;
EMBRYOEXISTS(EGGNAME,EMBRYO,RESULT)
N ERRCT S ERRCT=0
N DATA S DATA(0)=1
I '$$CONNECTED^ROOK D
. D ERR^ROOK(13,.RESULT)
. S ERRCT=ERRCT+1
I $$USED^ROOK="" D
. D ERR^ROOK(10,.RESULT)
. S ERRCT=ERRCT+1
I ERRCT=0 D SUCCESS^ROOK(.RESULT,$D(^ROOK("DD",$$CURRENTNEST^ROOK,"EMBRYOS",EMBRYO)),0,0,.DATA)
Q RKRESULT
;