source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLDIE.m@ 949

Last change on this file since 949 was 623, checked in by George Lilly, 15 years ago

revised back to 6/30/08 version

File size: 8.1 KB
Line 
1HLDIE ;CIOFO-O/LJA - Direct 772 & 773 Sets ; 11/18/2003 11:17
2 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13,1995
3 ;
4 ; Rules: if any of these rules is broken, FILE^DIE is called instead
5 ;
6 ; * Can't edit files other than 772,773
7 ; * Don't pass IENS value with multiples IENs. You can only
8 ; edit one IEN at a time!
9 ; * Only flag "S" is honored. Flag "K" is ignored. Other
10 ; flags result in FILE^DIE being called.
11 ; * Can't edit ^HLMA(IEN,90) data.
12 ; * Can't edit ^HLMA(IEN,91) data.
13 ; * Can't edit ^HL(772,IEN,"IN") data (field #200, MESSAGE TEXT)
14 ; * No checking of data performed! (Data format MUST be OK.)
15 ; * No locking of records in files 772 or 773. (Locks on queues.)
16 ;
17FILE(FLAGS,ROOT,ERR,SUB,RTN) ; FILE^DIE functional equivalent...
18 ; This call has similar parameters to FILE^DIE, but changes data
19 ; using hard sets. The first two parameters of this API are the
20 ; same as FILE^DIE. So, if any file other than 772 or 773 is being
21 ; edited, this API just passes on the FLAGS,ROOT,ERR parameters to
22 ; FILE^DIE and quits. If file 772 or 773 is being edited, the hard
23 ; set code in HLDIE772 and HLDIE773 is called.
24 ;
25 N DEBUG,FILE,HLEDITOR,LERR,IEN,X,XECMCODE
26 ;
27 S DT=$$NOW^XLFDT\1
28 ;
29 D BEGIN ; Debug call at beginning or process
30 ;
31 ; Check FILE, IEN, FIELDs passed, etc...
32 I '$$CHECKS D QUIT ;->
33 .
34 . S HLEDITOR="FILE^DIE"
35 .
36 . ; Call FILEMAN...
37 . D FILE^DIE($G(FLAGS),$G(ROOT),$G(ERR))
38 .
39 . ; Debug call made even with Fileman...
40 . D END
41 ;
42 S HLEDITOR="FILE^HLDIE"
43 ;
44 ; If this point is reached, file 772 or 773 is being edited, data
45 ; in ROOT() has been checked, and data is being hard set...
46 ;
47 ;
48 ; Make sure ERR is defined...
49 I $G(ERR)']"" N HLERR S ERR="HLERR"
50 ;
51 ; All editing occurs in this call...
52 D EDITALL(.ROOT,FILE,IEN)
53 ;
54 ; Store debug data if XTMP debug string set...
55 D END
56 ;
57 ;check if ROOT needs to be retained
58 I FLAGS'["S" K @ROOT,FLAGS
59 ;
60 Q
61 ;
62EDITALL(ROOT,FILE,IEN) ; Edit 772 or 773 by direct sets...
63 ;
64 ; FILE,IEN -- optional (parsed from ROOT())
65 ;
66 N ERRNO,FIELD,GBL,NODE,ROUTINE,TAG,VALUE,XRF
67 ;
68 S GBL=$$GBL(FILE,+IEN)
69 ;
70 ;check if .01="@" for deletion of record...
71 I $G(@ROOT@(FILE,IEN,.01))="@" D Q
72 .I FILE=773 D DEL773^HLUOPT3(+IEN) Q
73 .I FILE=772 D DEL772^HLUOPT3(+IEN)
74 ;
75 ; If no data in record passed in, log an error and quit...
76 I '$D(@GBL) D Q ; Remember. GBL contains IEN...
77 . S ERRNO=$$ERRNO(601,"The entry does not exist.",FILE,2)
78 . S @ERR@("DIERR",+ERRNO,"PARAM","IENS")=IEN_$S(IEN'[",":",",1:"")
79 ;
80 ;
81 ; What routine holds the file-specific field/xref set code?
82 S ROUTINE=$S(FILE=772:"HLDIE772",FILE=773:"HLDIE773",1:"")
83 ;
84 ; Load NODEs...
85 D GETNODES(FILE,+IEN,.NODE)
86 ;
87 ; When a field is edited, the NODE(1) is changed
88 ;
89 ; Edit NODE(1), adding new values, and set XRF(XREF) nodes...
90 S FIELD=0
91 F S FIELD=$O(@ROOT@(FILE,IEN,FIELD)) Q:FIELD'>0 D
92 . ; VALUE = value passed in by process that is to be stored in file
93 . S VALUE=$G(@ROOT@(FILE,IEN,FIELD))
94 .
95 . ; If field should be deleted, VALUE will equal @...
96 . I VALUE="@" S VALUE=""
97 .
98 . ; Get and check tag...
99 . S TAG="F"_(FILE-770)_$TR(FIELD,".","")_U_ROUTINE
100 . S TAG(1)=$T(@TAG) I TAG(1)']"" D QUIT ;->
101 . . S ERRNO=$$ERRNO(501,"No set logic for file #"_FILE_"'s field# "_FIELD,FILE,3)
102 . . S @ERR@("DIERR",+ERRNO,"PARAM",1)=FIELD
103 . . S @ERR@("DIERR",+ERRNO,"PARAM","FIELD")=FIELD
104 .
105 . ; Call the subroutine below that is for the specific field...
106 . ; (No editing of xrefs or global data occurs in these calls.)
107 . D @("F"_(FILE-770)_$TR(FIELD,".","")_U_ROUTINE)
108 ;
109 ; If no data actually changed, quit...
110 QUIT:'$D(NODE("CHG")) ;->
111 ;
112 ; Store changes in the global now...
113 D STORE(FILE,IEN,.NODE)
114 ;
115 ; Set xrefs to correspond to the just-stored data...
116 S XRF=""
117 F S XRF=$O(XRF(XRF)) Q:XRF']"" D
118 . D @("XRF"_XRF_U_ROUTINE)
119 ;
120 Q
121 ;
122GETNODES(FILE,IEN,NODE) ; Load pre-change data for each node in
123 ; NODE(node,0), and load node to be changed in NODE(node,1).
124 ; GBL -- req
125 F NODE=0,1,2,"P","S" D
126 . ; After setting, NODE(NODE,0) will equal each other.
127 . ; However, after each edited field is processed, the pieces of
128 . ; data in NODE(NODE,1) will be changed. The pre and post nodes
129 . ; then are of comparison value.
130 . S NODE(NODE,0)=$G(@GBL@(NODE)) ; Pre-change node
131 . S NODE(NODE,1)=NODE(NODE,0) ; Node that is changed
132 Q
133 ;
134STORE(FILE,IEN,NODE) ; Store changes in file...
135 N DATA,ND
136 ;
137 ; Loop thru change nodes, get changed data, and store it...
138 S ND=""
139 F S ND=$O(NODE("CHG",ND)) Q:ND']"" D
140 . S DATA=$G(NODE(ND,1))
141 . ; Even if no data no node, store it. (Will be removed by purge.)
142 . I FILE=772 S ^HL(772,+IEN,ND)=DATA
143 . I FILE=773 S ^HLMA(+IEN,ND)=DATA
144 ;
145 QUIT
146 ;
147GBL(FILE,IEN) QUIT $S(FILE=772:"^HL(772,"_+IEN_")",1:"^HLMA("_+IEN_")")
148 ;
149CHKFLD(FILE,FIELD) ; Does passed-in field exist?
150 ; Returns -- @ERR@(...) ->
151 ;
152 ; Quit if field exists...
153 QUIT:$D(^DD(+FILE,+FIELD)) 1 ;->
154 ;
155 ; Field doesn't exist. Log error...
156 S ERRNO=$$ERRNO(501,"File #"_FILE_" does not contain a field "_FIELD_".",FILE,3)
157 S @ERR@("DIERR",+ERRNO,"PARAM",1)=FIELD
158 S @ERR@("DIERR",+ERRNO,"PARAM","FIELD")=FIELD
159 ;
160 Q ""
161 ;
162ERRNO(NUM,TXT,FILE,PNO) ; Return next ERROR number and create general data...
163 N NO
164 S NO=$G(@ERR@("DIERR"))+1,@ERR@("DIERR")=+NO_U_+NO
165 S @ERR@("DIERR",NO)=NUM
166 S @ERR@("DIERR",NO,"PARAM",0)=PNO
167 S @ERR@("DIERR",NO,"PARAM","FILE")=FILE
168 S @ERR@("DIERR",NO,"TEXT",1)=TXT
169 S @ERR@("DIERR","E",NUM,NO)=""
170 Q NO
171 ;
172GENLERR(ETXT) ; Store GENERAL (and fatal) error...
173 ; ERR -- req
174 N NO
175 S NO=$G(@ERR@("DIERR"))+1,@ERR@("DIERR")=+NO_U_+NO
176 S @ERR@("DIERR",NO)=999_U_ETXT ; Made up error number
177 Q
178 ;
179CHECKS() ; Check ROOT() for file and validity of data...
180 ; FLAGS, ROOT() -- req --> FILE,IEN
181 N I,OK,FIELD
182 ;
183 ;check the file & ien
184 S FILE=$O(@ROOT@(0))
185 I FILE'=772,FILE'=773 D QUIT "" ;->
186 . S IEN=$S(FILE:$O(@ROOT@(FILE,0)),1:0) ; Set for debugging
187 ;
188 ; ;shouldn't be more than 1 file!
189 QUIT:$O(@ROOT@(FILE)) "" ;->
190 ;
191 ;check the ien structure, and that only ien passed...
192 S IEN=$O(@ROOT@(FILE,0))
193 ; Structure check...
194 QUIT:$P(IEN,",")'=+IEN_"," "" ;->
195 ; Is it numeric?
196 QUIT:'(+IEN) "" ;->
197 ; Has more than one IEN been passed?
198 QUIT:($O(@ROOT@(FILE,IEN))'="") "" ;->
199 ;
200 ;check the flags. Only K and S flags allowed...
201 I $L(FLAGS) D QUIT:'OK "" ;->
202 . S OK=1
203 . F I=0:1:$L(FLAGS) I $E(FLAGS,I)'="K",$E(FLAGS,I)'="S" S OK=0
204 ;
205 ; Check for existence of FIELD in FILE's DD & if an excluded field.
206 ; (See rules for fields which cannot be updated by FILE^HLDIE.)
207 S FIELD=0,OK=1
208 F S FIELD=$O(@ROOT@(FILE,IEN,FIELD)) Q:FIELD="" D Q:'OK
209 . I '$$CHKFLD(FILE,FIELD) S OK=0 Q
210 . I FILE=773,FIELD\1=90 S OK=0 Q
211 . I FILE=773,FIELD\1=91 S OK=0 Q
212 . I FILE=772,FIELD=200 S OK=0 Q
213 ;
214 ; If not OK to use FILE^HLDIE, skip any further testing...
215 QUIT:'OK "" ;->
216 ;
217 ; *** WARNING ***
218 ; The following check **MUST** be removed after FILE^HLDIE is working.
219 ;
220 ; Final check for whether FILE^HLDIE should be used...
221 I $G(^XTMP("HLDIE-DEBUG","CALL"))]"" QUIT "" ;->
222 ; If this node exists and follows null, FILE^DIE will be used.
223 ; Otherwise, execution defaults to using FILE^HLDIE.
224 ;
225 Q OK
226 ;
227BEGIN ; Always call here before any ^HLDIE or ^DIE calls...
228 D DEBUG(1)
229 Q
230 ;
231END ; Always call here after all ^HLDIE or ^DIE actions...
232 D DEBUG(2)
233 Q
234 ;
235DEBUG(LOC) ; Debug presets and setup...
236 ; Most variables created here should be left around. These variables
237 ; are newed above.
238 N STORE
239 ;
240 S RTN=$G(RTN),SUB=$G(SUB)
241 ;
242 ; First-time (beginning) call setups...
243 I LOC=1 D
244 . S RTN=$S(RTN]"":RTN,1:"HLDIE")_"~"_$S(RTN="HLDIE":"FILE",1:SUB)
245 . S DEBUG=$G(^XTMP("HLDIE-DEBUG","STATUS"))
246 . S XECMCODE=$P(DEBUG,U,3)
247 ; DEBUG is always called at beginning (LOC=1) and end (LOC=2) or
248 ; FILE^HLDIE. So, set up variables only once, at beginning...
249 ;
250 ; Setup that is individual to each (1 or 2) call...
251 S STORE=$P(DEBUG,U,LOC),STORE=$S(STORE=1:1,STORE=2:2,1:"")
252 ; Some, All, or no data stored?
253 ;
254 ; If no STORE instructions, and no M code to specify STORE, quit...
255 QUIT:'STORE&($G(XECMCODE)'=1) ;->
256 ;
257 ; Call DEBUG to STORE data...
258 D DEBUG^HLDIEDBG(RTN,LOC,STORE,XECMCODE)
259 ;
260 Q
261 ;
262EOR ;HLDIE - Direct 772 & 773 Sets ; 11/18/2003 11:17
Note: See TracBrowser for help on using the repository browser.