source: Scheduling/trunk/m/BSDX25.m@ 1799

Last change on this file since 1799 was 1625, checked in by Tariq Hamkari, 12 years ago

Ayman Ghaith : adding the correct routines which not has the transactions.

File size: 10.1 KB
Line 
1BSDX25 ; VEN/SMH - WINDOWS SCHEDULING RPCS ; 7/9/12 5:00pm
2 ;;1.7;BSDX;;Jun 01, 2013;Build 24
3 ; Licensed under LGPL
4 ;
5 ; Change Log:
6 ; 3110106: SMH -> Changed Check-in EP - Removed unused paramters. Will change C#
7 ; 3120630: VEN/SMH -> Extensive Refactoring to remove transactions.
8 ; -> Functionality still the same.
9 ; -> Unit Tests in UT25^BSDXUT2
10 ;
11 ;
12CHECKIND(BSDXY,BSDXAPPTID,BSDXCDT,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG) ;EP
13 ;Entry point for debugging
14 ;
15 ;I +$G(^BSDXDBUG("BREAK","CHECKIN")),+$G(^BSDXDBUG("BREAK"))=DUZ D DEBUG^%Serenji("CHECKIN^BSDX25(.BSDXY,BSDXAPPTID,BSDXCDT,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG)",$P(^BSDXDBUG("BREAK"),U,2))
16 Q
17 ;
18CHECKIN(BSDXY,BSDXAPPTID,BSDXCDT) ;Private EP Check in appointment
19 ; Old additional vars: ,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG)
20 ; Called by RPC: BSDX CHECKIN APPOINTMENT
21 ;
22 ; Private to GUI; use BSDXAPI for general API to checkin patients
23 ; Parameters:
24 ; BSDXY: Global Out
25 ; BSDXAPPTID: Appointment ID in ^BSDXAPPT
26 ; BSDXCDT: Checkin Date --> Changed
27 ; BSDXCC: Clinic Stop IEN (not used)
28 ; BSDXPRV: Provider IEN (not used)
29 ; BSDXROU: Print Routing Slip? (not used)
30 ; BSDXVCL: PCC+ Clinic IEN (not used)
31 ; BSDXVFM: PCC+ Form IEN (not used)
32 ; BSDXOG: PCC+ Outguide (true or false) (not used)
33 ;
34 ; Output:
35 ; ADO.net table with 1 column ErrorID, 1 row result
36 ; - 0 if all okay
37 ; - Another number or text if not
38 ;
39 ; Error reference:
40 ; -1 -> Invalid Appointment ID
41 ; -2 -> Invalid Check-in Date
42 ; -3 -> Cannot check-in due to Fileman Filer failure
43 ; -4 -> Cannot lock ^BSDXAPPT(APPTID)
44 ; -10 -> BSDXAPI error
45 ; -100 -> Mumps Error
46 ;
47 ; Turn off SDAM Appointment Events BSDX Protocol Processing
48 N BSDXNOEV
49 S BSDXNOEV=1 ;Don't execute protocol
50 ;
51 ; Set min DUZ vars
52 D ^XBKVAR
53 ;
54 ; $ET
55 N $ET S $ET="G ERROR^BSDX25"
56 ;
57 ; Test for error trap for Unit Tests
58 I $G(BSDXDIE) N X S X=1/0
59 ;
60 N BSDXI S BSDXI=0
61 ;
62 S BSDXY=$NAME(^BSDXTMP($J))
63 K @BSDXY
64 ;
65 S ^BSDXTMP($J,0)="T00020ERRORID"_$C(30)
66 ;
67 I '+BSDXAPPTID D ERR("-1~Invalid Appointment ID") QUIT
68 I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-1~Invalid Appointment ID") QUIT
69 ;
70 ; Lock BSDX node, only to synchronize access to the globals.
71 ; It's not expected that the error will ever happen as no filing
72 ; is supposed to take 5 seconds.
73 L +^BSDXAPPT(BSDXAPPTID):5 E D ERR("-4~Appt record is locked. Please contact technical support.") QUIT
74 ;
75 ; Remove Date formatting v.1.5. Client will send date as FM Date.
76 ;S:BSDXCDT["@0000" BSDXCDT=$P(BSDXCDT,"@")
77 ;S %DT="T",X=BSDXCDT D ^%DT S BSDXCDT=Y
78 S BSDXCDT=+BSDXCDT ; Strip off zeros if C# sends them
79 I BSDXCDT'>2000000 D ERR("-2~Invalid Check-in Date") QUIT
80 I BSDXCDT>$$NOW^XLFDT S BSDXCDT=$$NOW^XLFDT
81 ;
82 ; Some data
83 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPPTID,0) ; Appointment Node
84 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN
85 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Appointment Start Time
86 ;
87 ; Get Hospital Location IEN from BSDXAPPT to BSDXRES (RESOUCE:HOSPITAL LOCATION)
88 N BSDXSC1 S BSDXSC1=$$GET1^DIQ(9002018.4,BSDXAPPTID_",",".07:.04","I")
89 I BSDXSC1,'$D(^SC(BSDXSC1,0)) S BSDXSC1="" ; Null it off if it doesn't exist
90 ;
91 ; Check if we can check-in using BSDXAPI
92 N BSDXERR S BSDXERR=0
93 I BSDXSC1 S BSDXERR=$$CHECKIC1^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART)
94 I BSDXERR D ERR(-10_"~"_$P(BSDXERR,U,2)) QUIT
95 ;
96 ; Checkin BSDX APPOINTMENT entry
97 ; Failure Analysis: If we fail here, no changes were made.
98 N BSDXERR S BSDXERR=$$BSDXCHK(BSDXAPPTID,BSDXCDT)
99 I BSDXERR D ERR("-3~Fileman Filer failed to check-in appt") QUIT
100 ;
101 ; File check-in using BSDXAPI
102 ; Failure Analysis: If we fail here, we need to roll back first check-in.
103 N BSDXERR S BSDXERR=0
104 I BSDXSC1 S BSDXERR=$$CHECKIN1^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART)
105 I BSDXERR D QUIT
106 . N % S %=$$BSDXCHK(BSDXAPPTID,"@") ; No Error checking to prevent loop.
107 . D ERR(-10_"~"_$P(BSDXERR,U,2)) ; Send error message to client
108 ;
109 L -^BSDXAPPT(BSDXAPPTID)
110 S BSDXI=BSDXI+1
111 S ^BSDXTMP($J,BSDXI)="0"_$C(30)
112 S BSDXI=BSDXI+1
113 S ^BSDXTMP($J,BSDXI)=$C(31)
114 Q
115 ;
116BSDXCHK(BSDXAPPTID,BSDXCDT) ; $$ Private Entry Point. File or delete check-in to
117 ; BSDX Appointment
118 ; Input: BSDXAPPTID -> Appointment ID
119 ; BSDXCDT -> Check-in date, or "@" to remove check-in.
120 ;
121 ; Output: 1^Error for error
122 ; 0 for success
123 ;
124 Q:$G(BSDXSIMERR1) 1_U_"Simulated Error 1"
125 ;
126 N BSDXIENS,BSDXMSG,BSDXFDA ; Filer variables
127 S BSDXIENS=BSDXAPPTID_","
128 S BSDXFDA(9002018.4,BSDXIENS,.03)=BSDXCDT
129 D FILE^DIE("","BSDXFDA","BSDXMSG")
130 Q:$D(BSDXMSG) 1_U_BSDXMSG("DIERR",1,"TEXT",1)
131 Q 0
132 ;
133RMCI(BSDXY,BSDXAPPTID) ; Private EP - Remove Check-in from BSDX APPT and 2/44
134 ; Called by RPC BSDX REMOVE CHECK-IN
135 ;
136 ; Parameters to pass:
137 ; APPTID: IEN in file BSDX APPOINTMENT
138 ;
139 ; Return in global array:
140 ; Record set with Column ERRORID; value of 0 AOK; other value
141 ; --> means that something went wrong
142 ;
143 ; Error Reference:
144 ; -1~Invalid Appointment ID (not passed)
145 ; -2~Invalid Appointment ID (Doesn't exist in ^BSDXAPPT)
146 ; -3~DB has corruption. Call Tech Support. (Resource ID doesn't exist in BSDXAPPT)
147 ; -4~DB has corruption. Call Tech Support. (Resource ID in BSDXAPPT doesnt exist in BSDXRES)
148 ; -5~BSDXAPI Error. Message depends on error.
149 ; -6~Data Filing Error in BSDXCHK
150 ; -7~Lock not acquired
151 ; -100~Mumps Error
152 ;
153 N BSDXNOEV S BSDXNOEV=1 ;Don't execute protocol
154 ;
155 N $ET S $ET="G ERROR^BSDX25" ; Error Trap
156 ;
157 ; Set return variable and kill contents
158 S BSDXY=$NAME(^BSDXTMP($J))
159 K @BSDXY
160 ;
161 N BSDXI S BSDXI=0 ; Initialize Counter
162 ;
163 S ^BSDXTMP($J,BSDXI)="T00020ERRORID"_$C(30) ; Header of ADO recordset
164 ;
165 ;;;test
166 I $G(BSDXDIE) N X S X=8/0
167 ;
168 ; Check for Appointment ID (passed and exists in file)
169 I '+$G(BSDXAPPTID) D ERR("-1~Invalid Appointment ID") QUIT
170 I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-2~Invalid Appointment ID") QUIT
171 ;
172 ; Lock
173 ; Timeout not expected to happen except in error conditions.
174 L +^BSDXAPPT(BSDXAPPTID):5 E D ERR("-7~Appt record is locked. Please contact technical support.") QUIT
175 ;
176 ; Get appointment Data
177 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPPTID,0)
178 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN
179 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Date
180 N BSDXRESID S BSDXRESID=$P(BSDXNOD,U,7) ; Resource ID
181 ;
182 ; If the resource doesn't exist, error out. DB is corrupt.
183 I 'BSDXRESID D ERR("-3~DB has corruption. Call Tech Support.") QUIT
184 I '$D(^BSDXRES(BSDXRESID,0)) D ERR("-4~DB has corruption. Call Tech Support.") QUIT
185 ;
186 ; Get HL Data
187 N BSDXNOD S BSDXNOD=^BSDXRES(BSDXRESID,0) ; Resource 0 node
188 N BSDXSC1 S BSDXSC1=$P(BSDXNOD,U,4) ;HOSPITAL LOCATION IEN
189 I BSDXSC1,'$D(^SC(BSDXSC1,0)) S BSDXSC1="" ; Zero out if HL doesn't exist
190 ;
191 ; Is it okay to remove check-in from PIMS?
192 N BSDXERR S BSDXERR=0 ; Scratch variable
193 ; $$RMCICK = Remove Check-in Check
194 I BSDXSC1 S BSDXERR=$$RMCICK^BSDXAPI1(BSDXPATID,BSDXSC1,BSDXSTART)
195 I BSDXERR D ERR("-5~"_$P(BSDXERR,U,2)) QUIT
196 ;
197 ; For possible rollback, get old check-in date (internal value)
198 N BSDXCDT S BSDXCDT=$$GET1^DIQ(9002018.4,BSDXAPPTID_",",.03,"I")
199 ;
200 ; Remove checkin from BSDX APPOINTMENT entry
201 ; No need to rollback here on failure.
202 N BSDXERR S BSDXERR=$$BSDXCHK(BSDXAPPTID,"@")
203 I BSDXERR D ERR("-6~Cannot file data in $$BSDXCHK") QUIT
204 ;
205 ; Now, remove checkin from PIMS files 2/44
206 ; Restore BSDXCDT into ^BSDXAPPT if we fail.
207 N BSDXERR S BSDXERR=0 ; Scratch variable to hold error message
208 I BSDXSC1 S BSDXERR=$$RMCI^BSDXAPI1(BSDXPATID,BSDXSC1,BSDXSTART)
209 I BSDXERR D QUIT
210 . N % S %=$$BSDXCHK(BSDXAPPTID,BSDXCDT) ; No error checking here.
211 . D ERR("-5~"_$P(BSDXERR,U,2)) ; Send error message to client
212 ;
213 ; Unlock
214 L -^BSDXAPPT(BSDXAPPTID)
215 ;
216 ; Return ADO recordset
217 S BSDXI=BSDXI+1
218 S ^BSDXTMP($J,BSDXI)="0"_$C(30)
219 S BSDXI=BSDXI+1
220 S ^BSDXTMP($J,BSDXI)=$C(31)
221 Q
222 ;
223CHKEVT(BSDXPAT,BSDXSTART,BSDXSC) ;EP Called by BSDX CHECKIN APPOINTMENT event
224 ;when appointments CHECKIN via PIMS interface.
225 ;Propagates CHECKIN to BSDXAPPT and raises refresh event to running GUI clients
226 ;
227 Q:+$G(BSDXNOEV)
228 Q:'+$G(BSDXSC)
229 N BSDXSTAT,BSDXFOUND,BSDXRES
230 S BSDXSTAT=""
231 S:$G(SDATA("AFTER","STATUS"))["CHECKED IN" BSDXSTAT=$P(SDATA("AFTER","STATUS"),"^",4)
232 S BSDXFOUND=0
233 I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0)) S BSDXFOUND=$$CHKEVT1(BSDXRES,BSDXSTART,BSDXPAT,BSDXSTAT)
234 I BSDXFOUND D CHKEVT3(BSDXRES) Q
235 I $D(^BXDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0)) S BSDXFOUND=$$CHKEVT1(BSDXRES,BSDXSTART,BSDXPAT,BSDXSTAT)
236 I BSDXFOUND D CHKEVT3(BSDXRES)
237 Q
238 ;
239CHKEVT1(BSDXRES,BSDXSTART,BSDXPAT,BSDXSTAT) ;
240 ;Get appointment id in BSDXAPT
241 ;If found, call BSDXNOS(BSDXAPPT) and return 1
242 ;else return 0
243 N BSDXFOUND,BSDXAPPT
244 S BSDXFOUND=0
245 Q:'+$G(BSDXRES) BSDXFOUND
246 Q:'$D(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART)) BSDXFOUND
247 S BSDXAPPT=0 F S BSDXAPPT=$O(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART,BSDXAPPT)) Q:'+BSDXAPPT D Q:BSDXFOUND
248 . N BSDXNOD S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""
249 . I $P(BSDXNOD,U,5)=BSDXPAT,$P(BSDXNOD,U,12)="" S BSDXFOUND=1 Q
250 I BSDXFOUND,+$G(BSDXAPPT) D
251 . N BSDXERR S BSDXERR=$$BSDXCHK(BSDXAPPT,BSDXSTAT)
252 . I BSDXERR D ^%ZTER ; VEN/SMH - This is silent. This is a last resort
253 Q BSDXFOUND
254 ;
255CHKEVT3(BSDXRES) ;
256 ;Call RaiseEvent to notify GUI clients
257 ;
258 N BSDXRESN
259 S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
260 Q:BSDXRESN=""
261 S BSDXRESN=$P(BSDXRESN,"^")
262 D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
263 Q
264 ;
265ERROR ;
266 S $ETRAP="D ^%ZTER HALT" ; Emergency Error Trap for the wise
267 D ^%ZTER
268 ; VEN/SMH: NB: I make a conscious decision not to roll back anything
269 ; here in the error trap. Once the error is fixed, users can
270 ; undo or redo the check-in.
271 ; Individual portions of this routine may choose to do rolling back
272 ; of their own (e.g. a failed call to BSDXAPI causes rollback to occur
273 ; in CHECKIN and RMCI)
274 ;
275 ; Log error message and send to client
276 D ERR("-100~Mumps Error")
277 Q:$Q "-100^Mumps Error" Q
278 ;
279ERR(BSDXERR) ;Error processing
280 ; Unlock first
281 L:$D(BSDXAPPTID) -^BSDXAPPT(BSDXAPPTID)
282 ; If last line is $C(31), we are done. No more errors to send to client.
283 I ^BSDXTMP($J,$O(^BSDXTMP($J," "),-1))=$C(31) QUIT
284 S BSDXERR=$G(BSDXERR)
285 S BSDXERR=$P(BSDXERR,"~")_"~"_$TEXT(+0)_":"_$P(BSDXERR,"~",2) ; Append Routine Name
286 S BSDXI=$G(BSDXI)+1
287 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30)
288 S BSDXI=BSDXI+1
289 S ^BSDXTMP($J,BSDXI)=$C(31)
290 QUIT
Note: See TracBrowser for help on using the repository browser.