Changeset 1563 for Scheduling/trunk/m/BSDX25.m
- Timestamp:
- Oct 8, 2012, 6:59:10 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/m/BSDX25.m
r1481 r1563 1 BSDX25 ; V EN/SMH - WINDOWS SCHEDULING RPCS ; 7/9/12 5:00pm2 ;;1. 7T2;BSDX;;Jul 11, 2012;Build 181 BSDX25 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 4/28/11 10:24am 2 ;;1.6;BSDX;;Aug 31, 2011;Build 25 3 3 ; Licensed under LGPL 4 4 ; 5 5 ; Change Log: 6 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 ; 12 CHECKIND(BSDXY,BSDXAPPTID,BSDXCDT,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG) ;EP 7 ; 8 ; 9 UT ; Unit Tests 10 ; Make appointment, checkin, then uncheckin 11 N ZZZ 12 N APPTTIME S APPTTIME=$E($$NOW^XLFDT(),1,12) 13 D APPADD^BSDX07(.ZZZ,APPTTIME,APPTTIME+.0001,3,"Dr Office",30,"Sam's Note",1) 14 N APPTID S APPTID=+^BSDXTMP($J,1) 15 N HL S HL=$$GET1^DIQ(9002018.4,APPTID,".07:.04","I") 16 D CHECKIN^BSDX25(.ZZZ,APPTID,$$NOW^XLFDT()) 17 IF '$P(^BSDXAPPT(APPTID,0),U,3) WRITE "ERROR IN CHECKIN 1",! 18 IF '+$G(^SC(HL,"S",APPTTIME,1,1,"C")) WRITE "ERROR IN CHECKIN 2",! 19 D RMCI^BSDX25(.ZZZ,APPTID) 20 IF $P(^BSDXAPPT(APPTID,0),U,3) WRITE "ERROR IN UNCHECKIN 1",! 21 IF $G(^SC(HL,"S",APPTTIME,1,1,"C")) WRITE "ERROR IN UNCHECKIN 2",! 22 D RMCI^BSDX25(.ZZZ,APPTID) ; again, test sanity in repeat 23 IF $P(^BSDXAPPT(APPTID,0),U,3) WRITE "ERROR IN UNCHECKIN 1",! 24 IF $G(^SC(HL,"S",APPTTIME,1,1,"C")) WRITE "ERROR IN UNCHECKIN 2",! 25 ; now test various error conditions 26 ; Test Error 1 27 D RMCI^BSDX25(.ZZZ,) 28 IF +^BSDXTMP($J,1)'=-1 WRITE "ERROR IN ETest 1",! 29 ; Test Error 2 30 D RMCI^BSDX25(.ZZZ,234987234398) 31 IF +^BSDXTMP($J,1)'=-2 WRITE "ERROR IN Etest 2",! 32 ; Tests for 3 to 5 difficult to produce 33 ; Error tests follow: Mumps error test; Transaction restartability 34 N bsdxdie S bsdxdie=1 35 D RMCI^BSDX25(.ZZZ,APPTID) 36 IF +^BSDXTMP($J,1)'=-20 WRITE "ERROR IN Etest 3",! 37 K bsdxdie 38 N bsdxrestart S bsdxrestart=1 39 D RMCI^BSDX25(.ZZZ,APPTID) 40 IF +^BSDXTMP($J,1)'=0 WRITE "Error in Etest 4",! 41 QUIT 42 CHECKIND(BSDXY,BSDXAPTID,BSDXCDT,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG) ;EP 13 43 ;Entry point for debugging 14 44 ; 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 ; 18 CHECKIN(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 ; 45 ;I +$G(^BSDXDBUG("BREAK","CHECKIN")),+$G(^BSDXDBUG("BREAK"))=DUZ D DEBUG^%Serenji("CHECKIN^BSDX25(.BSDXY,BSDXAPTID,BSDXCDT,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG)",$P(^BSDXDBUG("BREAK"),U,2)) 46 Q 47 ; 48 CHECKIN(BSDXY,BSDXAPTID,BSDXCDT) ; ,BSDXCC,BSDXPRV,BSDXROU,BSDXVCL,BSDXVFM,BSDXOG) ;EP Check in appointment 22 49 ; Private to GUI; use BSDXAPI for general API to checkin patients 23 50 ; Parameters: 24 51 ; BSDXY: Global Out 25 ; BSDXAP PTID: Appointment ID in ^BSDXAPPT52 ; BSDXAPTID: Appointment ID in ^BSDXAPPT 26 53 ; BSDXCDT: Checkin Date --> Changed 27 54 ; BSDXCC: Clinic Stop IEN (not used) … … 30 57 ; BSDXVCL: PCC+ Clinic IEN (not used) 31 58 ; BSDXVFM: PCC+ Form IEN (not used) 32 ; BSDXOG: PCC+ Outguide (true or false) (not used)59 ; BSDXOG: PCC+ Outguide (true or false) 33 60 ; 34 61 ; Output: … … 36 63 ; - 0 if all okay 37 64 ; - 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 65 66 N BSDXNOD,BSDXPATID,BSDXSTART,DIK,DA,BSDXID,BSDXI,BSDXZ,BSDXIENS,BSDXVEN 48 67 N BSDXNOEV 49 68 S BSDXNOEV=1 ;Don't execute protocol 50 69 ; 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 ; 70 D ^XBKVAR S X="ERROR^BSDX25",@^%ZOSF("TRAP") 71 S BSDXI=0 72 K ^BSDXTMP($J) 73 S BSDXY="^BSDXTMP("_$J_")" 65 74 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 I '+BSDXAPTID D ERR("BSDX25: Invalid Appointment ID") Q 76 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR("BSDX08: Invalid Appointment ID") Q 75 77 ; Remove Date formatting v.1.5. Client will send date as FM Date. 76 78 ;S:BSDXCDT["@0000" BSDXCDT=$P(BSDXCDT,"@") 77 79 ;S %DT="T",X=BSDXCDT D ^%DT S BSDXCDT=Y 78 S BSDXCDT=+BSDXCDT ; Strip off zeros if C# sends them79 I BSDXCDT '>2000000 D ERR("-2~Invalid Check-in Date") QUIT80 S BSDXCDT=+BSDXCDT ; Strip off zeros if C# sends them 81 I BSDXCDT=-1 D ERR(70) Q 80 82 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) 83 ;Checkin BSDX APPOINTMENT entry 84 D BSDXCHK(BSDXAPTID,BSDXCDT) 85 S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) 86 S BSDXPATID=$P(BSDXNOD,U,5) 87 S BSDXSTART=$P(BSDXNOD,U) 88 ; 89 S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID 90 I BSDXSC1]"",$D(^BSDXRES(BSDXSC1,0)) D I +$G(BSDXZ) D ERR($P(BSDXZ,U,2)) Q 91 . S BSDXNOD=^BSDXRES(BSDXSC1,0) 92 . S BSDXSC1=$P(BSDXNOD,U,4) ;HOSPITAL LOCATION 93 . I BSDXSC1]"",$D(^SC(BSDXSC1,0)) D APCHK(.BSDXZ,BSDXSC1,BSDXPATID,BSDXCDT,BSDXSTART) 94 ; 110 95 S BSDXI=BSDXI+1 111 96 S ^BSDXTMP($J,BSDXI)="0"_$C(30) … … 114 99 Q 115 100 ; 116 BSDXCHK(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_"," 101 BSDXCHK(BSDXAPTID,BSDXCDT) ; 102 ; 103 S BSDXIENS=BSDXAPTID_"," 128 104 S BSDXFDA(9002018.4,BSDXIENS,.03)=BSDXCDT 129 105 D FILE^DIE("","BSDXFDA","BSDXMSG") 130 Q:$D(BSDXMSG) 1_U_BSDXMSG("DIERR",1,"TEXT",1) 131 Q 0 132 ; 133 RMCI(BSDXY,BSDXAPPTID) ; Private EP - Remove Check-in from BSDX APPT and 2/44 134 ; Called by RPC BSDX REMOVE CHECK-IN 106 Q 107 ; 108 APCHK(BSDXZ,BSDXSC1,BSDXDFN,BSDXCDT,BSDXSTART) ; 109 ;Checkin appointment for patient BSDXDFN in clinic BSDXSC1 110 ;at time BSDXSTART 111 S BSDXZ=$$CHECKIN1^BSDXAPI(BSDXDFN,BSDXSC1,BSDXSTART) 112 Q 113 ; 114 RMCI(BSDXY,BSDXAPPTID) ; EP - Remove Check-in from BSDX APPT and 2/44 115 ; Called by RPC [Fill in later] 135 116 ; 136 117 ; Parameters to pass: … … 147 128 ; -4~DB has corruption. Call Tech Support. (Resource ID in BSDXAPPT doesnt exist in BSDXRES) 148 129 ; -5~BSDXAPI Error. Message depends on error. 149 ; -6~Data Filing Error in BSDXCHK 150 ; -7~Lock not acquired 151 ; -100~Mumps Error 130 ; -20~Mumps Error 152 131 ; 153 132 N BSDXNOEV S BSDXNOEV=1 ;Don't execute protocol … … 163 142 S ^BSDXTMP($J,BSDXI)="T00020ERRORID"_$C(30) ; Header of ADO recordset 164 143 ; 144 TSTART (BSDXI):SERIAL ; Perform Autolocking 145 ; 165 146 ;;;test 166 I $G(BSDXDIE) N X S X=8/0 147 I $g(bsdxdie) S X=8/0 148 ;;; 149 I $g(bsdxrestart) k bsdxrestart TRESTART 150 ;;;test 167 151 ; 168 152 ; Check for Appointment ID (passed and exists in file) … … 170 154 I '$D(^BSDXAPPT(BSDXAPPTID,0)) D ERR("-2~Invalid Appointment ID") QUIT 171 155 ; 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 156 ; Remove checkin from BSDX APPOINTMENT entry 157 D BSDXCHK(BSDXAPPTID,"@") 158 ; 159 ; Now, remove checkin from PIMS files 2/44 177 160 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPPTID,0) 178 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) 179 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) 180 N BSDX RESID S BSDXRESID=$P(BSDXNOD,U,7) ; Resource ID161 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN 162 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Date 163 N BSDXSC1 S BSDXSC1=$P(BSDXNOD,U,7) ; Resource ID 181 164 ; 182 165 ; 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) 166 I 'BSDXSC1 D ERR("-3~DB has corruption. Call Tech Support.") QUIT 167 I '$D(^BSDXRES(BSDXSC1,0)) D ERR("-4~DB has corruption. Call Tech Support.") QUIT 168 ; 169 N BSDXNOD S BSDXNOD=^BSDXRES(BSDXSC1,0) ; Resource 0 node 170 S BSDXSC1=$P(BSDXNOD,U,4) ;HOSPITAL LOCATION 171 ; 172 N BSDXZ ; Scratch variable to hold error message 173 I BSDXSC1]"",$D(^SC(BSDXSC1,0)) S BSDXZ=$$RMCI^BSDXAPI(BSDXPATID,BSDXSC1,BSDXSTART) 174 I +$G(BSDXZ) D ERR("-5~"_$P(BSDXZ,U,2)) QUIT 175 ; 176 TCOMMIT ; Save Data into Globals 215 177 ; 216 178 ; Return ADO recordset … … 246 208 Q:'$D(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART)) BSDXFOUND 247 209 S BSDXAPPT=0 F S BSDXAPPT=$O(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART,BSDXAPPT)) Q:'+BSDXAPPT D Q:BSDXFOUND 248 . N BSDXNODS BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""210 . S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD="" 249 211 . 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 212 I BSDXFOUND,+$G(BSDXAPPT) D BSDXCHK(BSDXAPPT,BSDXSTAT) 253 213 Q BSDXFOUND 254 214 ; … … 265 225 ERROR ; 266 226 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 227 ; Rollback, otherwise ^XTER will be empty from future rollback 228 I $TL>0 TROLLBACK 229 D ^%ZTER 230 S $EC="" ; Clear Error 231 ; Log error message and send to client 232 D ERR("-20~Mumps Error") 233 Q 278 234 ; 279 235 ERR(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 236 I $TLEVEL>0 TROLLBACK 284 237 S BSDXERR=$G(BSDXERR) 285 238 S BSDXERR=$P(BSDXERR,"~")_"~"_$TEXT(+0)_":"_$P(BSDXERR,"~",2) ; Append Routine Name
Note:
See TracChangeset
for help on using the changeset viewer.