source: Scheduling/trunk/m/BSDX08.m@ 1510

Last change on this file since 1510 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: 8.6 KB
RevLine 
[1479]1BSDX08 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 7/9/12 4:22pm
[1481]2 ;;1.7T2;BSDX;;Jul 11, 2012;Build 18
[1076]3 ;
4 ; Original by HMW. New Written by Sam Habiel. Licensed under LGPL.
5 ;
6 ; Change History
7 ; 3101022 UJO/SMH v1.42
[1461]8 ; - Transaction work. As of v 1.7, all work here has been superceded
9 ; - Refactoring of AVUPDT - never tested though.
[1076]10 ; - Refactored all of APPDEL.
11 ;
[1080]12 ; 3111125 UJO/SMH v1.5
13 ; - Added ability to remove checked in appointments. Added a couple
14 ; of units tests for that under UT2.
15 ;
[1461]16 ; 3120625 VEN/SMH v1.7
17 ; - Transactions removed. Code refactored to work w/o txns.
[1467]18 ; - Moved AVUPDT to AVUPDTCN in BSDXAPI1. BSDXAPI takes care of calling
19 ; that.
[1461]20 ;
[1076]21 ; Error Reference:
22 ; -1~BSDX08: Appt record is locked. Please contact technical support.
23 ; -2~BSDX08: Invalid Appointment ID
[1007]24 ; -3~BSDX08: Invalid Appointment ID
[1076]25 ; -4~BSDX08: Cancelled appointment does not have a Resouce ID
26 ; -5~BSDX08: Resouce ID does not exist in BSDX RESOURCE
27 ; -6~BSDX08: Invalid Hosp Location stored in Database
28 ; -7~BSDX08: Patient does not have an appointment in PIMS Clinic
29 ; -8^BSDX08: Unable to find associated PIMS appointment for this patient
30 ; -9^BSDX08: BSDXAPI returned an error: (error)
[1461]31 ; -10^BSDX08: $$BSDXCAN failed (Fileman filing error)
[1076]32 ; -100~BSDX08 Error: (Mumps Error)
[614]33 ;
34APPDELD(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP
35 ;Entry point for debugging
[1452]36 ;D DEBUG^%Serenji("APPDEL^BSDX08(.BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT)")
[614]37 Q
38 ;
[1479]39APPDEL(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ; Private EP
[1007]40 ;Called by RPC: BSDX CANCEL APPOINTMENT
41 ;Cancels existing appointment in BSDX APPOINTMENT and 44/2 subfiles
[1080]42 ;Input Parameters:
[1007]43 ; - BSDXAPTID is entry number in BSDX APPOINTMENT file
44 ; - BSDXTYP is C for clinic-cancelled and PC for patient cancelled
45 ; - BSDXCR is pointer to CANCELLATION REASON File (409.2)
46 ; - BSDXNOT is user note
[614]47 ;
[1080]48 ; Returns error code in recordset field ERRORID. Empty string is success.
49 ; Returns Global Array. Must use this type in RPC.
[614]50 ;
[1080]51 ; Return Array: set Return and clear array
[1007]52 S BSDXY=$NA(^BSDXTMP($J))
[1080]53 K ^BSDXTMP($J)
[1007]54 ;
[1080]55 ; Set min DUZ vars if they don't exist
56 D ^XBKVAR
[1007]57 ;
[1080]58 ; $ET
59 N $ET S $ET="G ETRAP^BSDX08"
60 ;
61 ; Counter
[1007]62 N BSDXI S BSDXI=0
[1454]63 ;
[1080]64 ; Header Node
[1041]65 S ^BSDXTMP($J,BSDXI)="T00100ERRORID"_$C(30)
[1007]66 ;
[1080]67 ; Turn off SDAM APPT PROTOCOL BSDX Entries
[614]68 N BSDXNOEV
69 S BSDXNOEV=1 ;Don't execute BSDX CANCEL APPOINTMENT protocol
70 ;
[1080]71 ;;;test for error inside transaction. See if %ZTER works
[1461]72 I $G(BSDXDIE1) N X S X=1/0
[1080]73 ;
74 ; Check appointment ID and whether it exists
75 I '+BSDXAPTID D ERR(BSDXI,"-2~BSDX08: Invalid Appointment ID") Q
[1007]76 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(BSDXI,"-3~BSDX08: Invalid Appointment ID") Q
[1455]77 ;
[1479]78 ; Lock BSDX node, only to synchronize access to the globals.
79 ; It's not expected that the error will ever happen as no filing
80 ; is supposed to take 5 seconds.
81 L +^BSDXAPPT(BSDXAPTID):5 E D ERR(BSDXI,"-1~BSDX08: Appt record is locked. Please contact technical support.") Q
82 ;
[1007]83 ; Start Processing:
[1455]84 ; First, get data
[1007]85 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) ; BSDX Appt Node
86 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; Patient ID
87 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Time
[614]88 ;
[1455]89 ; Check the resource ID and whether it exists
[1007]90 N BSDXSC1 S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID
[1461]91 ; If the resource id doesn't exist...
[1007]92 I BSDXSC1="" D ERR(BSDXI,"-4~BSDX08: Cancelled appointment does not have a Resouce ID") QUIT
[1080]93 I '$D(^BSDXRES(BSDXSC1,0)) D ERR(BSDXI,"-5~BSDX08: Resouce ID does not exist in BSDX RESOURCE") QUIT
[1455]94 ;
[1460]95 ;
[1461]96 ; Check if PIMS will let us cancel the appointment using $$CANCELCK^BSDXAPI
[1007]97 ; Get zero node of resouce
[1455]98 N BSDXNOD S BSDXNOD=^BSDXRES(BSDXSC1,0)
[1080]99 ; Get Hosp location
[1007]100 N BSDXLOC S BSDXLOC=$P(BSDXNOD,U,4)
[1461]101 ; Error indicator
[1080]102 N BSDXERR S BSDXERR=0
[1461]103 ;
104 N BSDXC ; Array to pass to BSDXAPI
105 ;
106 I BSDXLOC D
[1455]107 . S BSDXC("PAT")=BSDXPATID
108 . S BSDXC("CLN")=BSDXLOC
109 . S BSDXC("TYP")=BSDXTYP
110 . S BSDXC("ADT")=BSDXSTART
111 . S BSDXC("CDT")=$$NOW^XLFDT()
112 . S BSDXC("NOT")=BSDXNOT
113 . S:'+$G(BSDXCR) BSDXCR=11 ;Other
114 . S BSDXC("CR")=BSDXCR
115 . S BSDXC("USR")=DUZ
116 . ;
117 . S BSDXERR=$$CANCELCK^BSDXAPI(.BSDXC) ; 0 or 1^error message
[1461]118 ; If error, quit. No need to rollback as no changes took place.
119 I BSDXERR D ERR(BSDXI,"-9~BSDX08: BSDXAPI reports that "_$P(BSDXERR,U,2)) QUIT
120 ;
121 I $G(BSDXDIE2) N X S X=1/0
122 ;
123 ; Now cancel the appointment for real
124 ; BSDXAPPT First; no need for rollback if error occured.
125 N BSDXERR S BSDXERR=$$BSDXCAN(BSDXAPTID) ; Add a cancellation date in BSDX APPOINTMENT
[1479]126 I BSDXERR D ERR(BSDXI,"-10~BSDX08: $$BSDXCAN failed (Fileman filing error): "_$P(BSDXERR,U,2)) QUIT
[1461]127 ;
128 ; Then PIMS:
129 ; cancel appt in "S" nodes in file 2 and 44, then update Legacy PIMS Availability
130 ; If error happens, must rollback ^BSDXAPPT
[1479]131 I BSDXLOC S BSDXERR=$$CANCEL^BSDXAPI(.BSDXC) ; Cancel through BSDXAPI
132 ; Rollback BSDXAPPT if error occurs
133 I BSDXERR D ERR(BSDXI,"-9^BSDX08: BSDXAPI returned an error: "_$P(BSDXERR,U,2)),ROLLBACK(BSDXAPTID) QUIT
[614]134 ;
[1007]135 L -^BSDXAPPT(BSDXAPTID)
[614]136 S BSDXI=BSDXI+1
137 S ^BSDXTMP($J,BSDXI)=""_$C(30)
138 S BSDXI=BSDXI+1
139 S ^BSDXTMP($J,BSDXI)=$C(31)
140 Q
141 ;
[1461]142BSDXCAN(BSDXAPTID) ; $$; Private; Cancel BSDX APPOINTMENT entry
143 ; Input: Appt IEN in ^BSDXAPPT
144 ; Output: 0 for success and 1^Msg for failure
145 N BSDXDATE,BSDXIENS,BSDXFDA,BSDXMSG
146 S BSDXDATE=$$NOW^XLFDT()
[614]147 S BSDXIENS=BSDXAPTID_","
148 S BSDXFDA(9002018.4,BSDXIENS,.12)=BSDXDATE
149 D FILE^DIE("","BSDXFDA","BSDXMSG")
[1461]150 I $D(BSDXMSG) Q 1_U_BSDXMSG("DIERR",1,"TEXT",1)
151 QUIT 0
[614]152 ;
[1472]153ROLLBACK(BSDXAPTID) ; Proc; Private; Rollback cancellation
[1461]154 ; Input same as $$BSDXCAN
155 N BSDXIENS S BSDXIENS=BSDXAPTID_","
156 N BSDXFDA S BSDXFDA(9002018.4,BSDXIENS,.12)="@"
157 N BSDXMSG
158 D FILE^DIE("","BSDXFDA","BSDXMSG")
159 ;I $D(BSDXMSG) ; Not sure what to do. We are already handling an error.
160 QUIT
161 ;
[614]162CANEVT(BSDXPAT,BSDXSTART,BSDXSC) ;EP Called by BSDX CANCEL APPOINTMENT event
163 ;when appointments cancelled via PIMS interface.
164 ;Propagates cancellation to BSDXAPPT and raises refresh event to running GUI clients
165 N BSDXFOUND,BSDXRES
166 Q:+$G(BSDXNOEV)
167 Q:'+$G(BSDXSC)
168 S BSDXFOUND=0
169 I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0)) S BSDXFOUND=$$CANEVT1(BSDXRES,BSDXSTART,BSDXPAT)
170 I BSDXFOUND D CANEVT3(BSDXRES) Q
171 I $D(^BXDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0)) S BSDXFOUND=$$CANEVT1(BSDXRES,BSDXSTART,BSDXPAT)
172 I BSDXFOUND D CANEVT3(BSDXRES)
173 Q
174 ;
175CANEVT1(BSDXRES,BSDXSTART,BSDXPAT) ;
176 ;Get appointment id in BSDXAPT
177 ;If found, call BSDXCAN(BSDXAPPT) and return 1
178 ;else return 0
179 N BSDXFOUND,BSDXAPPT
180 S BSDXFOUND=0
181 Q:'+BSDXRES BSDXFOUND
182 Q:'$D(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART)) BSDXFOUND
183 S BSDXAPPT=0 F S BSDXAPPT=$O(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART,BSDXAPPT)) Q:'+BSDXAPPT D Q:BSDXFOUND
[1455]184 . N BSDXNOD
[614]185 . S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""
186 . I $P(BSDXNOD,U,5)=BSDXPAT,$P(BSDXNOD,U,12)="" S BSDXFOUND=1 Q
[1479]187 I BSDXFOUND,+$G(BSDXAPPT) N % S %=$$BSDXCAN(BSDXAPPT) I % D ^%ZTER
[614]188 Q BSDXFOUND
189 ;
190CANEVT3(BSDXRES) ;
191 ;Call RaiseEvent to notify GUI clients
192 ;
193 N BSDXRESN
194 S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
195 Q:BSDXRESN=""
196 S BSDXRESN=$P(BSDXRESN,"^")
197 ;D EVENT^BSDX23("SCHEDULE-"_BSDXRESN,"","","")
198 D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
199 Q
200 ;
201ERR(BSDXI,BSDXERR) ;Error processing
[1479]202 ; Unlock first
203 L:$D(BSDXAPTID) -^BSDXAPPT(BSDXAPTID)
[1467]204 ; If last line is $C(31), we are done. No more errors to send to client.
205 I ^BSDXTMP($J,$O(^BSDXTMP($J," "),-1))=$C(31) QUIT
[614]206 S BSDXI=BSDXI+1
207 S BSDXERR=$TR(BSDXERR,"^","~")
208 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30)
209 S BSDXI=BSDXI+1
210 S ^BSDXTMP($J,BSDXI)=$C(31)
[1007]211 QUIT
[614]212 ;
213ETRAP ;EP Error trap entry
[1007]214 N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
[1080]215 D ^%ZTER
[1479]216 ;
[1461]217 ; Roll back BSDXAPPT;
[1467]218 ; NB: What if a Mumps error happens inside fileman in BSDXAPI?
219 ; I have decided the M errors are out of scope for me to handle.
[1461]220 D:$G(BSDXAPTID) ROLLBACK(BSDXAPTID)
[1479]221 ;
[1007]222 ; Log error message and send to client
[1080]223 I '$D(BSDXI) N BSDXI S BSDXI=0
[1007]224 D ERR(BSDXI,"-100~BSDX08 Error: "_$G(%ZTERZE))
[1461]225 Q:$Q 1_U_"-100~Mumps Error" Q
[1080]226 ;
227 ;;;NB: This is code that is unused in both original and port.
228 ; ; If not appt in the "S" node is found in ^SC then check associated RPMS Clinic Multiple
229 ; I BSDXSCIEN="" D I 'BSDXZ Q ;Q:BSDXZ
[1007]230 ; . S BSDXERR="BSDX08: Unable to find associated RPMS appointment for this patient. "
231 ; . S BSDXZ=1
[1080]232 ; . ; Check if there are associated RPMS clinics. (not currently used) Does the multiple exist? No, then quit
[1007]233 ; . I '$D(^BSDXRES(BSDXSC1,20)) S BSDXZ=0 QUIT
[1080]234 ; . ; Loop through the multiple. Get Location and then the ^SC "S" node IEN.
[1007]235 ; . N BSDX1 S BSDX1=0
236 ; . F S BSDX1=$O(^BSDXRES(BSDXSC1,20,BSDX1)) Q:'+BSDX1 Q:BSDXZ=0 D
237 ; . . Q:'$D(^BSDXRES(BSDXSC1,20,BSDX1,0))
238 ; . . S BSDXLOC=$P(^BSDXRES(BSDXSC1,20,BSDX1,0),U)
[1080]239 ; . . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) I +BSDXSCIEN S BSDXZ=0 Q
Note: See TracBrowser for help on using the repository browser.