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

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

Updated routine version numbers to 1.7T2.
Changes the Writes in the post-init to MESXPDUTL in BSDX2E.
Changed the check for BMX to be for BMX 4 rather than BMX 2.

File size: 10.1 KB
RevLine 
[1479]1BSDX25 ; VEN/SMH - WINDOWS SCHEDULING RPCS ; 7/9/12 5:00pm
[1481]2 ;;1.7T2;BSDX;;Jul 11, 2012;Build 18
[1161]3 ; Licensed under LGPL
[614]4 ;
[1114]5 ; Change Log:
6 ; 3110106: SMH -> Changed Check-in EP - Removed unused paramters. Will change C#
[1467]7 ; 3120630: VEN/SMH -> Extensive Refactoring to remove transactions.
8 ; -> Functionality still the same.
9 ; -> Unit Tests in UT25^BSDXUT2
[614]10 ;
[1114]11 ;
[1464]12CHECKIND(BSDXY,BSDXAPPTID,BSDXCDT,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG) ;EP
[614]13 ;Entry point for debugging
14 ;
[1464]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))
[614]16 Q
17 ;
[1472]18CHECKIN(BSDXY,BSDXAPPTID,BSDXCDT) ;Private EP Check in appointment
[1463]19 ; Old additional vars: ,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG)
[1464]20 ; Called by RPC: BSDX CHECKIN APPOINTMENT
21 ;
[1064]22 ; Private to GUI; use BSDXAPI for general API to checkin patients
[1114]23 ; Parameters:
24 ; BSDXY: Global Out
[1464]25 ; BSDXAPPTID: Appointment ID in ^BSDXAPPT
[1114]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)
[1464]32 ; BSDXOG: PCC+ Outguide (true or false) (not used)
[1114]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
[1463]38 ;
[1466]39 ; Error reference:
40 ; -1 -> Invalid Appointment ID
41 ; -2 -> Invalid Check-in Date
42 ; -3 -> Cannot check-in due to Fileman Filer failure
[1479]43 ; -4 -> Cannot lock ^BSDXAPPT(APPTID)
[1466]44 ; -10 -> BSDXAPI error
45 ; -100 -> Mumps Error
46 ;
[1463]47 ; Turn off SDAM Appointment Events BSDX Protocol Processing
[614]48 N BSDXNOEV
49 S BSDXNOEV=1 ;Don't execute protocol
50 ;
[1463]51 ; Set min DUZ vars
[1464]52 D ^XBKVAR
[1463]53 ;
54 ; $ET
55 N $ET S $ET="G ERROR^BSDX25"
56 ;
[1466]57 ; Test for error trap for Unit Tests
58 I $G(BSDXDIE) N X S X=1/0
59 ;
[1463]60 N BSDXI S BSDXI=0
[1464]61 ;
62 S BSDXY=$NAME(^BSDXTMP($J))
63 K @BSDXY
64 ;
[614]65 S ^BSDXTMP($J,0)="T00020ERRORID"_$C(30)
[1464]66 ;
[1466]67 I '+BSDXAPPTID D ERR("-1~Invalid Appointment ID") QUIT
68 I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-1~Invalid Appointment ID") QUIT
[1464]69 ;
[1479]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 ;
[1064]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
[1463]78 S BSDXCDT=+BSDXCDT ; Strip off zeros if C# sends them
[1466]79 I BSDXCDT'>2000000 D ERR("-2~Invalid Check-in Date") QUIT
[614]80 I BSDXCDT>$$NOW^XLFDT S BSDXCDT=$$NOW^XLFDT
[1464]81 ;
[1466]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
[614]86 ;
[1464]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 ;
[1466]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 ;
[1464]101 ; File check-in using BSDXAPI
[1466]102 ; Failure Analysis: If we fail here, we need to roll back first check-in.
[1464]103 N BSDXERR S BSDXERR=0
104 I BSDXSC1 S BSDXERR=$$CHECKIN1^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART)
[1466]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
[1464]108 ;
[1479]109 L -^BSDXAPPT(BSDXAPPTID)
[614]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 ;
[1464]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.
[614]120 ;
[1464]121 ; Output: 1^Error for error
122 ; 0 for success
123 ;
[1466]124 Q:$G(BSDXSIMERR1) 1_U_"Simulated Error 1"
125 ;
[1464]126 N BSDXIENS,BSDXMSG,BSDXFDA ; Filer variables
127 S BSDXIENS=BSDXAPPTID_","
[614]128 S BSDXFDA(9002018.4,BSDXIENS,.03)=BSDXCDT
129 D FILE^DIE("","BSDXFDA","BSDXMSG")
[1464]130 Q:$D(BSDXMSG) 1_U_BSDXMSG("DIERR",1,"TEXT",1)
131 Q 0
[614]132 ;
[1479]133RMCI(BSDXY,BSDXAPPTID) ; Private EP - Remove Check-in from BSDX APPT and 2/44
[1464]134 ; Called by RPC BSDX REMOVE CHECK-IN
[1113]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
[1114]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.
[1464]149 ; -6~Data Filing Error in BSDXCHK
150 ; -7~Lock not acquired
[1463]151 ; -100~Mumps Error
[1114]152 ;
[1113]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
[1115]158 S BSDXY=$NAME(^BSDXTMP($J))
[1113]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 ;
[1114]165 ;;;test
[1464]166 I $G(BSDXDIE) N X S X=8/0
[1114]167 ;
[1113]168 ; Check for Appointment ID (passed and exists in file)
[1114]169 I '+$G(BSDXAPPTID) D ERR("-1~Invalid Appointment ID") QUIT
170 I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-2~Invalid Appointment ID") QUIT
[1113]171 ;
[1479]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 ;
[1467]176 ; Get appointment Data
[1114]177 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPPTID,0)
[1463]178 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN
179 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Date
[1467]180 N BSDXRESID S BSDXRESID=$P(BSDXNOD,U,7) ; Resource ID
[1113]181 ;
182 ; If the resource doesn't exist, error out. DB is corrupt.
[1467]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
[1113]185 ;
[1467]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
[1113]190 ;
[1467]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
[1479]212 ;
213 ; Unlock
214 L -^BSDXAPPT(BSDXAPPTID)
215 ;
[1113]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 ;
[614]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
[1464]248 . N BSDXNOD S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""
[614]249 . I $P(BSDXNOD,U,5)=BSDXPAT,$P(BSDXNOD,U,12)="" S BSDXFOUND=1 Q
[1464]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
[614]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 ;
[1114]266 S $ETRAP="D ^%ZTER HALT" ; Emergency Error Trap for the wise
[1463]267 D ^%ZTER
[1466]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
[1467]273 ; in CHECKIN and RMCI)
[1466]274 ;
[1463]275 ; Log error message and send to client
276 D ERR("-100~Mumps Error")
[1466]277 Q:$Q "-100^Mumps Error" Q
[614]278 ;
[1113]279ERR(BSDXERR) ;Error processing
[1479]280 ; Unlock first
281 L:$D(BSDXAPPTID) -^BSDXAPPT(BSDXAPPTID)
[1466]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
[1114]284 S BSDXERR=$G(BSDXERR)
285 S BSDXERR=$P(BSDXERR,"~")_"~"_$TEXT(+0)_":"_$P(BSDXERR,"~",2) ; Append Routine Name
286 S BSDXI=$G(BSDXI)+1
[614]287 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30)
288 S BSDXI=BSDXI+1
289 S ^BSDXTMP($J,BSDXI)=$C(31)
[1113]290 QUIT
Note: See TracBrowser for help on using the repository browser.