Changeset 1007
- Timestamp:
- Nov 18, 2010, 7:03:27 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/m/BSDX08.m
r968 r1007 1 BSDX08 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 9/15/10 8:21pm 2 ;;1.41;BSDX;;Sep 29, 2010 3 ; 1 BSDX08 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 11/16/10 7:12am 2 ;;1.42;BSDX;;Sep 29, 2010 3 ; 4 ; Original by HMW. New Written by Sam Habiel. Licensed under LGPL. 5 ; 6 ; Change History 7 ; 3101022 UJO/SMH v1.42 8 ; - Transaction now restartable. Thanks to 9 ; --> Zach Gonzalez and Rick Marshall for fix. 10 ; - Extra TROLLBACK in Lock Statement when lock fails. 11 ; --> Removed--Rollback is already in ERR tag. 12 ; - Added new statements to old SD code in AVUPDT to obviate 13 ; --> need to restore variables in transaction 14 ; - Refactored this chunk of code. Don't really know whether it 15 ; --> worked in the first place. Waiting for bug report to know. 16 ; - Refactored all of APPDEL. 17 ; 18 ; Error Reference: 19 ; -1~BSDX08: Appt record is locked. Please contact technical support. 20 ; -2~BSDX08: Invalid Appointment ID 21 ; -3~BSDX08: Invalid Appointment ID 22 ; -4~BSDX08: Cancelled appointment does not have a Resouce ID 23 ; -5~BSDX08: Resouce ID does not exist in BSDX RESOURCE 24 ; -6~BSDX08: Invalid Hosp Location stored in Database 25 ; -7~BSDX08: Patient does not have an appointment in PIMS Clinic 26 ; -8^BSDX08: Unable to find associated PIMS appointment for this patient 27 ; -9^BSDX08: BSDXAPI returned an error: (error) 28 ; -100~BSDX08 Error: (Mumps Error) 4 29 ; 5 30 APPDELD(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP 6 31 ;Entry point for debugging 7 ; 8 ;D DEBUG^%Serenji("APPDEL^BSDX08(.BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT)") 9 Q 10 ; 32 D DEBUG^%Serenji("APPDEL^BSDX08(.BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT)") 33 Q 34 ; 35 UT ; Unit Tests 36 ; Test 1: Make normal appointment and cancel it. See if every thing works 37 N ZZZ 38 D APPADD^BSDX07(.ZZZ,3110123.2,3110123.3,4,"Dr Office",10,"Sam's Note",1) 39 S APPID=+$P(^BSDXTMP($J,1),U) 40 D APPDEL^BSDX08(.ZZZ,APPID,"PC",1,"Sam's Cancel Note") 41 I $P(^BSDXAPPT(APPID,0),U,12)'>0 W "Error in Cancellation-1" 42 I $O(^SC(2,"S",3110123.2,1,0))]"" W "Error in Cancellation-2" 43 I $P(^DPT(4,"S",3110123.2,0),U,2)'="PC" W "Error in Cancellation-3" 44 I ^DPT(4,"S",3110123.2,"R")'="Sam's Cancel Note" W "Error in Cancellation-4" 45 ; 46 ; Test 2: Check for -1 47 ; Make appt 48 D APPADD^BSDX07(.ZZZ,3110125.2,3110125.3,4,"Dr Office",10,"Sam's Note",1) 49 ; Lock the node in another job 50 S APPID=+$P(^BSDXTMP($J,1),U) 51 ; W "Lock ^BSDXAPPT("_APPID_") in another session. You have 10 seconds." H 10 52 D APPDEL^BSDX08(.ZZZ,APPID,"PC",1,"Sam's Cancel Note") 53 ; 54 ; Test 3: Check for -100 55 S bsdxdie=1 56 D APPADD^BSDX07(.ZZZ,3110126.2,3110126.3,4,"Dr Office",10,"Sam's Note",1) 57 S APPID=+$P(^BSDXTMP($J,1),U) 58 D APPDEL^BSDX08(.ZZZ,APPID,"PC",1,"Reasons") 59 I $P(^BSDXTMP($J,1),"~")'=-100 W "Error in -100",! 60 K bsdxdie 61 ; 62 ; Test 4: Restartable transaction 63 S bsdxrestart=1 64 D APPADD^BSDX07(.ZZZ,3110128.2,3110128.3,4,"Dr Office",10,"Sam's Note",1) 65 S APPID=+$P(^BSDXTMP($J,1),U) 66 D APPDEL^BSDX08(.ZZZ,APPID,"PC",1,"Reasons") 67 I $P(^DPT(4,"S",3110128.2,0),U,2)'="PC" W "Error in Restartable Transaction",! 68 ; 69 ; Test 5: for invalid Appointment ID (-2 and -3) 70 D APPDEL^BSDX08(.ZZZ,0,"PC",1,"Reasons") 71 I $P(^BSDXTMP($J,1),"~")'=-2 W "Error in -2",! 72 D APPDEL^BSDX08(.ZZZ,999999,"PC",1,"Reasons") 73 I $P(^BSDXTMP($J,1),"~")'=-3 W "Error in -3",! 74 QUIT 75 ; Lock the node in another job for testing. 76 UTL(APPID) L +^BSDXAPPT(APPID) HANG 10 QUIT 77 ; 11 78 APPDEL(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP 12 ;Called by BSDX CANCEL APPOINTMENT 13 ;Cancels appointment 14 ;BSDXAPTID is entry number in BSDX APPOINTMENT file 15 ;BSDXTYP is C for clinic-cancelled and PC for patient cancelled 16 ;BSDXCR is pointer to CANCELLATION REASON File (409.2) 17 ;BSDXNOT is user note 18 ;Returns error code in recordset field ERRORID 19 ; 20 ; 21 N BSDXNOD,BSDXPATID,BSDXSTART,DIK,DA,BSDXID,BSDXI,BSDXZ,BSDXERR 22 N BSDXLOC,BSDXLEN,BSDXSCIEN 79 ;Called by RPC: BSDX CANCEL APPOINTMENT 80 ;Cancels existing appointment in BSDX APPOINTMENT and 44/2 subfiles 81 ;Input Parameters: 82 ; - BSDXAPTID is entry number in BSDX APPOINTMENT file 83 ; - BSDXTYP is C for clinic-cancelled and PC for patient cancelled 84 ; - BSDXCR is pointer to CANCELLATION REASON File (409.2) 85 ; - BSDXNOT is user note 86 ; 87 ; Returns error code in recordset field ERRORID. Zero is success. 88 ; Returns Global Array. Must use this type in RPC. 89 ; 90 ; Return Array: set Return and clear array 91 S BSDXY=$NA(^BSDXTMP($J)) 92 K ^BSDXTMP($J) 93 ; 94 ; Set min DUZ vars if they don't exist 95 D ^XBKVAR 96 ; 97 ; $ET 98 N $ET S $ET="G ETRAP^BSDX08" 99 ; 100 ; Counter 101 N BSDXI S BSDXI=0 102 ; Header Node 103 S ^BSDXTMP($J,BSDXI)="T00030ERRORID"_$C(30) 104 ; 105 ; Lock BSDX node, only to synchronize access to the globals. 106 ; It's not expected that the error will ever happen as no filing 107 ; is supposed to take 5 seconds. 108 L +^BSDXAPPT(BSDXAPTID):5 I '$T D ERR(BSDXI,"-1~BSDX08: Appt record is locked. Please contact technical support.") Q 109 ; 110 ;Restartable Transaction; restore paramters when starting. 111 ; (Params restored are what's passed here + BSDXI) 112 TSTART (BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT,BSDXI):T="BSDX CANCEL APPOINTEMENT^BSDX08" 113 ; 114 ; Turn off SDAM APPT PROTOCOL BSDX Entries 23 115 N BSDXNOEV 24 116 S BSDXNOEV=1 ;Don't execute BSDX CANCEL APPOINTMENT protocol 25 117 ; 26 D ^XBKVAR S X="ETRAP^BSDX08",@^%ZOSF("TRAP") 27 S BSDXI=0 28 K ^BSDXTMP($J) 29 S BSDXY="^BSDXTMP("_$J_")" 30 S ^BSDXTMP($J,BSDXI)="T00020ERRORID"_$C(30) 31 S BSDXI=BSDXI+1 32 TSTART 33 I '+BSDXAPTID D ERR(BSDXI,"BSDX08: Invalid Appointment ID") Q 34 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(BSDXI,"BSDX08: Invalid Appointment ID") Q 35 ; 36 ;Delete APPOINTMENT entries 37 S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) 38 S BSDXPATID=$P(BSDXNOD,U,5) 39 S BSDXSTART=$P(BSDXNOD,U) 40 ; 41 ;Lock BSDX node 42 L +^BSDXAPPT(BSDXPATID):5 I '$T D ERR(BSDXI+1,"Another user is working with this patient's record. Please try again later") TROLLBACK Q 43 ; 44 D BSDXCAN(BSDXAPTID) 45 ; 46 S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID 47 I BSDXSC1]"",$D(^BSDXRES(BSDXSC1,0)) D I +$G(BSDXZ) S BSDXERR=BSDXERR_$P(BSDXZ,U,2) D ERR(BSDXI,BSDXERR) Q 48 . S BSDXNOD=^BSDXRES(BSDXSC1,0) 49 . S BSDXLOC=$P(BSDXNOD,U,4) ;HOSPITAL LOCATION 50 . Q:'+BSDXLOC 51 . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) I BSDXSCIEN="" D I 'BSDXZ Q ;Q:BSDXZ 52 . . S BSDXERR="BSDX08: Unable to find associated RPMS appointment for this patient. " 53 . . S BSDXZ=1 54 . . I '$D(^BSDXRES(BSDXSC1,20)) S BSDXZ=0 Q 55 . . N BSDX1 56 . . S BSDX1=0 57 . . F S BSDX1=$O(^BSDXRES(BSDXSC1,20,BSDX1)) Q:'+BSDX1 Q:BSDXZ=0 D 58 . . . Q:'$D(^BSDXRES(BSDXSC1,20,BSDX1,0)) 59 . . . S BSDXLOC=$P(^BSDXRES(BSDXSC1,20,BSDX1,0),U) 60 . . . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) I +BSDXSCIEN S BSDXZ=0 Q 61 . S BSDXERR="BSDX08: CANCEL^BSDXAPI Returned " 62 . I BSDXLOC']"" S BSDXZ="0^Unable to find associated RPMS appointment for this patient." Q 63 . I '$D(^SC(BSDXLOC,0)) S BSDXZ="0^Unable to find associated RPMS appointment for this patient." Q 64 . S BSDXNOD=$G(^SC(BSDXLOC,"S",BSDXSTART,1,BSDXSCIEN,0)) 65 . I BSDXNOD="" S BSDXZ="0^Unable to find associated RPMS appointment for this patient." Q 66 . S BSDXLEN=$P(BSDXNOD,U,2) 67 . D APCAN(.BSDXZ,BSDXLOC,BSDXPATID,BSDXSTART) 68 . Q:+$G(BSDXZ) 118 ;;;test for error inside transaction. See if %ZTER works 119 I $G(bsdxdie) S X=1/0 120 ;;;test 121 ;;;test for TRESTART 122 I $G(bsdxrestart) K bsdxrestart TRESTART 123 ;;;test 124 ; 125 ; Check appointment ID and whether it exists 126 I '+BSDXAPTID D ERR(BSDXI,"-2~BSDX08: Invalid Appointment ID") Q 127 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(BSDXI,"-3~BSDX08: Invalid Appointment ID") Q 128 ; 129 ; Start Processing: 130 ; First, add cancellation date to appt entry in BSDX APPOINTMENT 131 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) ; BSDX Appt Node 132 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; Patient ID 133 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Time 134 D BSDXCAN(BSDXAPTID) ; Add a cancellation date in BSDX APPOINTMENT 135 ; 136 ; Second, cancel appt in "S" nodes in file 2 and 44, then update Legacy PIMS Availability 137 N BSDXSC1 S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID 138 ; If the resouce id doesn't exist... 139 I BSDXSC1="" D ERR(BSDXI,"-4~BSDX08: Cancelled appointment does not have a Resouce ID") QUIT 140 I '$D(^BSDXRES(BSDXSC1,0)) D ERR(BSDXI,"-5~BSDX08: Resouce ID does not exist in BSDX RESOURCE") QUIT 141 ; Get zero node of resouce 142 S BSDXNOD=^BSDXRES(BSDXSC1,0) 143 ; Get Hosp location 144 N BSDXLOC S BSDXLOC=$P(BSDXNOD,U,4) 145 ; Error indicator for Hosp Location filing for getting out of routine 146 N BSDXERR S BSDXERR=0 147 ; Only file in 2/44 if there is an associated hospital location 148 I BSDXLOC D QUIT:BSDXERR 149 . I '$D(^SC(BSDXLOC,0)) S BSDXERR=1 D ERR(BSDXI,"-6~BSDX08: Invalid Hosp Location stored in Database") QUIT 150 . ; Get the IEN of the appointment in the "S" node of ^SC 151 . N BSDXSCIEN 152 . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) 153 . I BSDXSCIEN="" S BSDXERR=1 D ERR(BSDXI,"-7~BSDX08: Patient does not have an appointment in PIMS Clinic") QUIT 154 . ; Get the appointment node 155 . S BSDXNOD=$G(^SC(BSDXLOC,"S",BSDXSTART,1,BSDXSCIEN,0)) 156 . I BSDXNOD="" S BSDXERR=1 D ERR(BSDXI,"-8^BSDX08: Unable to find associated PIMS appointment for this patient") QUIT 157 . N BSDXLEN S BSDXLEN=$P(BSDXNOD,U,2) 158 . ; Cancel through BSDXAPI 159 . N BSDXZ 160 . D APCAN(.BSDXZ,BSDXLOC,BSDXPATID,BSDXSTART) 161 . I +BSDXZ>0 S BSDXERR=1 D ERR(BSDXI,"-9^BSDX08: BSDXAPI returned an error: "_$P(BSDXZ,U,2)) QUIT 162 . ; Update Legacy PIMS clinic Availability 69 163 . D AVUPDT(BSDXLOC,BSDXSTART,BSDXLEN) 70 . ;L71 164 ; 72 165 TCOMMIT 73 L -^BSDXAPPT(BSDX PATID)166 L -^BSDXAPPT(BSDXAPTID) 74 167 S BSDXI=BSDXI+1 75 168 S ^BSDXTMP($J,BSDXI)=""_$C(30) … … 78 171 Q 79 172 ; 80 AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ;Update RPMS Clinic availability173 AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ;Update Legacy PIMS Clinic availability 81 174 ;See SDCNP0 82 S (SD,S)=BSDXSTART 175 N SD,S ; Start Date 176 S (SD,S)=BSDXSTART 177 N I ; Clinic IEN in 44 83 178 S I=BSDXSCD 179 ; if day has no schedule in legacy PIMS, forget about this update. 84 180 Q:'$D(^SC(I,"ST",SD\1,1)) 85 S SL=^SC(I,"SL"),X=$P(SL,U,3),STARTDAY=$S($L(X):X,1:8),SB=STARTDAY-1/100,X=$P(SL,U,6),HSI=$S(X:X,1:4),SI=$S(X="":4,X<3:4,X:X,1:4),STR="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz",SDDIF=$S(HSI<3:8/HSI,1:2) K Y 86 S SL=BSDXLEN 87 S S=^SC(I,"ST",SD\1,1),Y=SD#1-SB*100,ST=Y#1*SI\.6+(Y\1*SI),SS=SL*HSI/60 88 I Y'<1 F I=ST+ST:SDDIF S Y=$E(STR,$F(STR,$E(S,I+1))) Q:Y="" S S=$E(S,1,I)_Y_$E(S,I+2,999),SS=SS-1 Q:SS'>0 89 S ^SC(BSDXSCD,"ST",SD\1,1)=S 181 N SL ; Clinic characteristics node (length of appt, when appts start etc) 182 S SL=^SC(I,"SL") 183 N X ; Hour Clinic Display Begins 184 S X=$P(SL,U,3) 185 N STARTDAY ; When does the day start? 186 S STARTDAY=$S($L(X):X,1:8) ; If defined, use it; otherwise, 8am 187 N SB ; ?? Who knows? Day Start - 1 divided by 100. 188 S SB=STARTDAY-1/100 189 S X=$P(SL,U,6) ; Now X is Display increments per hour 190 N HSI ; Slots per hour, try 1 191 S HSI=$S(X:X,1:4) ; if defined, use it; otherwise, 4 192 N SI ; Slots per hour, try 2 193 S SI=$S(X="":4,X<3:4,X:X,1:4) ; If slots "", or less than 3, then 4 194 N STR ; ?? 195 S STR="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz" 196 N SDDIF ; Slots per hour diff?? 197 S SDDIF=$S(HSI<3:8/HSI,1:2) 198 S SL=BSDXLEN ; Dammit, reusing variable; SL now Appt Length from GUI 199 S S=^SC(I,"ST",SD\1,1) ; reusing var again; S now Day Pattern from PIMS 200 N Y ; Hours since start of Date 201 S Y=SD#1-SB*100 ;SD#1=FM Time portion; -SB minus start of day; conv to hrs 202 N ST ; ?? 203 ; Y#1 -> Minutes; *SI -> * Slots per hour; \.6 trunc min to hour 204 ; Y\1 -> Hours since start of day; * SI: * slots 205 S ST=Y#1*SI\.6+(Y\1*SI) 206 N SS ; how many slots are supposed to be taken by appointment 207 S SS=SL*HSI/60 ; (nb: try SL: 30 min; HSI: 4 slots) 208 N I 209 I Y'<1 D ; If Hours since start of Date is greater than 1 210 . ; loop through pattern. Tired of documenting. 211 . F I=ST+ST:SDDIF D Q:Y="" Q:SS'>0 212 . . S Y=$E(STR,$F(STR,$E(S,I+1))) Q:Y="" 213 . . S S=$E(S,1,I)_Y_$E(S,I+2,999) 214 . . S SS=SS-1 215 . . Q:SS'>0 216 S ^SC(BSDXSCD,"ST",SD\1,1)=S ; new pattern; global set 90 217 Q 91 218 ; … … 160 287 S BSDXI=BSDXI+1 161 288 S BSDXERR=$TR(BSDXERR,"^","~") 162 TROLLBACK289 I $TL>0 TROLLBACK 163 290 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30) 164 291 S BSDXI=BSDXI+1 165 292 S ^BSDXTMP($J,BSDXI)=$C(31) 166 L 167 Q 293 L -^BSDXAPPT(BSDXAPTID) 294 QUIT 168 295 ; 169 296 ETRAP ;EP Error trap entry 170 D ^%ZTER 171 I '$D(BSDXI) N BSDXI S BSDXI=999999 172 S BSDXI=BSDXI+1 173 D ERR(BSDXI,"BSDX08 Error: "_$G(%ZTERROR)) 174 Q 297 N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap 298 ; Rollback, otherwise ^XTER will be empty from future rollback 299 I $TL>0 TROLLBACK 300 D ^%ZTER 301 S $EC="" ; Clear Error 302 ; Log error message and send to client 303 I '$D(BSDXI) N BSDXI S BSDXI=0 304 D ERR(BSDXI,"-100~BSDX08 Error: "_$G(%ZTERZE)) 305 QUIT 306 ; 307 ;;;NB: This is code that is unused in both original and port. 308 ; ; If not appt in the "S" node is found in ^SC then check associated RPMS Clinic Multiple 309 ; I BSDXSCIEN="" D I 'BSDXZ Q ;Q:BSDXZ 310 ; . S BSDXERR="BSDX08: Unable to find associated RPMS appointment for this patient. " 311 ; . S BSDXZ=1 312 ; . ; Check if there are associated RPMS clinics. (not currently used) Does the multiple exist? No, then quit 313 ; . I '$D(^BSDXRES(BSDXSC1,20)) S BSDXZ=0 QUIT 314 ; . ; Loop through the multiple. Get Location and then the ^SC "S" node IEN. 315 ; . N BSDX1 S BSDX1=0 316 ; . F S BSDX1=$O(^BSDXRES(BSDXSC1,20,BSDX1)) Q:'+BSDX1 Q:BSDXZ=0 D 317 ; . . Q:'$D(^BSDXRES(BSDXSC1,20,BSDX1,0)) 318 ; . . S BSDXLOC=$P(^BSDXRES(BSDXSC1,20,BSDX1,0),U) 319 . ; . . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) I +BSDXSCIEN S BSDXZ=0 Q
Note:
See TracChangeset
for help on using the changeset viewer.