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

Last change on this file since 1466 was 1466, checked in by Sam Habiel, 12 years ago

Refactoring BSDX25 continued...

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