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

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

refactored BSDX26; still working on BSDX08

File size: 9.6 KB
Line 
1BSDX08 ; VW/UJO/SMH - WINDOWS SCHEDULING RPCS ; 6/25/12 6:17pm
2 ;;1.7T1;BSDX;;Aug 31, 2011;Build 18
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 ; 3111125 UJO/SMH v1.5
19 ; - Added ability to remove checked in appointments. Added a couple
20 ; of units tests for that under UT2.
21 ; - Minor reformatting because of how KIDS adds tabs.
22 ;
23 ; Error Reference:
24 ; -1~BSDX08: Appt record is locked. Please contact technical support.
25 ; -2~BSDX08: Invalid Appointment ID
26 ; -3~BSDX08: Invalid Appointment ID
27 ; -4~BSDX08: Cancelled appointment does not have a Resouce ID
28 ; -5~BSDX08: Resouce ID does not exist in BSDX RESOURCE
29 ; -6~BSDX08: Invalid Hosp Location stored in Database
30 ; -7~BSDX08: Patient does not have an appointment in PIMS Clinic
31 ; -8^BSDX08: Unable to find associated PIMS appointment for this patient
32 ; -9^BSDX08: BSDXAPI returned an error: (error)
33 ; -100~BSDX08 Error: (Mumps Error)
34 ;
35APPDELD(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP
36 ;Entry point for debugging
37 ;D DEBUG^%Serenji("APPDEL^BSDX08(.BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT)")
38 Q
39 ;
40APPDEL(BSDXY,BSDXAPTID,BSDXTYP,BSDXCR,BSDXNOT) ;EP
41 ;Called by RPC: BSDX CANCEL APPOINTMENT
42 ;Cancels existing appointment in BSDX APPOINTMENT and 44/2 subfiles
43 ;Input Parameters:
44 ; - BSDXAPTID is entry number in BSDX APPOINTMENT file
45 ; - BSDXTYP is C for clinic-cancelled and PC for patient cancelled
46 ; - BSDXCR is pointer to CANCELLATION REASON File (409.2)
47 ; - BSDXNOT is user note
48 ;
49 ; Returns error code in recordset field ERRORID. Empty string is success.
50 ; Returns Global Array. Must use this type in RPC.
51 ;
52 ; Return Array: set Return and clear array
53 S BSDXY=$NA(^BSDXTMP($J))
54 K ^BSDXTMP($J)
55 ;
56 ; Set min DUZ vars if they don't exist
57 D ^XBKVAR
58 ;
59 ; $ET
60 N $ET S $ET="G ETRAP^BSDX08"
61 ;
62 ; Counter
63 N BSDXI S BSDXI=0
64 ;
65 ; Header Node
66 S ^BSDXTMP($J,BSDXI)="T00100ERRORID"_$C(30)
67 ;
68 ; Lock BSDX node, only to synchronize access to the globals.
69 ; It's not expected that the error will ever happen as no filing
70 ; is supposed to take 5 seconds.
71 L +^BSDXAPPT(BSDXAPTID):5 I '$T D ERR(BSDXI,"-1~BSDX08: Appt record is locked. Please contact technical support.") Q
72 ;
73 ; Turn off SDAM APPT PROTOCOL BSDX Entries
74 N BSDXNOEV
75 S BSDXNOEV=1 ;Don't execute BSDX CANCEL APPOINTMENT protocol
76 ;
77 ;;;test for error inside transaction. See if %ZTER works
78 I $G(BSDXDIE) S X=1/0
79 ;
80 ; Check appointment ID and whether it exists
81 I '+BSDXAPTID D ERR(BSDXI,"-2~BSDX08: Invalid Appointment ID") Q
82 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(BSDXI,"-3~BSDX08: Invalid Appointment ID") Q
83 ;
84 ; Start Processing:
85 ; First, get data
86 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) ; BSDX Appt Node
87 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; Patient ID
88 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Time
89 ;
90 ; Check the resource ID and whether it exists
91 N BSDXSC1 S BSDXSC1=$P(BSDXNOD,U,7) ;RESOURCEID
92 ; If the resouce id doesn't exist...
93 I BSDXSC1="" D ERR(BSDXI,"-4~BSDX08: Cancelled appointment does not have a Resouce ID") QUIT
94 I '$D(^BSDXRES(BSDXSC1,0)) D ERR(BSDXI,"-5~BSDX08: Resouce ID does not exist in BSDX RESOURCE") QUIT
95 ;
96 ; BSDXAPPT First; todo: check for error
97 D BSDXCAN(BSDXAPTID) ; Add a cancellation date in BSDX APPOINTMENT
98 ;
99 ; Process PIMS issues second:
100 ; cancel appt in "S" nodes in file 2 and 44, then update Legacy PIMS Availability
101 ; Get zero node of resouce
102 N BSDXNOD S BSDXNOD=^BSDXRES(BSDXSC1,0)
103 ; Get Hosp location
104 N BSDXLOC S BSDXLOC=$P(BSDXNOD,U,4)
105 ; Error indicator for Hosp Location filing for getting out of routine
106 N BSDXERR S BSDXERR=0
107 ; For BSDXC
108 N BSDXC
109 ; Only file in 2/44 if there is an associated hospital location
110 I BSDXLOC D QUIT:BSDXERR
111 . S BSDXC("PAT")=BSDXPATID
112 . S BSDXC("CLN")=BSDXLOC
113 . S BSDXC("TYP")=BSDXTYP
114 . S BSDXC("ADT")=BSDXSTART
115 . S BSDXC("CDT")=$$NOW^XLFDT()
116 . S BSDXC("NOT")=BSDXNOT
117 . S:'+$G(BSDXCR) BSDXCR=11 ;Other
118 . S BSDXC("CR")=BSDXCR
119 . S BSDXC("USR")=DUZ
120 . ;
121 . S BSDXERR=$$CANCELCK^BSDXAPI(.BSDXC) ; 0 or 1^error message
122 . I BSDXERR D ERR(BSDXI,"-9^BSDX08: BSDXAPI returned an error: "_$P(BSDXERR,U,2)) QUIT
123 . ;
124 . N BSDXLEN S BSDXLEN=$$APPLEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART)
125 . ;
126 . ; Cancel through BSDXAPI
127 . S BSDXERR=$$CANCEL^BSDXAPI(.BSDXC)
128 . I BSDXERR=1 D ERR(BSDXI,"-9^BSDX08: BSDXAPI returned an error: "_$P(BSDXZ,U,2)) QUIT
129 . ; Update Legacy PIMS clinic Availability
130 . D AVUPDT(BSDXLOC,BSDXSTART,BSDXLEN)
131 ;
132 ;
133 L -^BSDXAPPT(BSDXAPTID)
134 S BSDXI=BSDXI+1
135 S ^BSDXTMP($J,BSDXI)=""_$C(30)
136 S BSDXI=BSDXI+1
137 S ^BSDXTMP($J,BSDXI)=$C(31)
138 Q
139 ;
140ROLLBACK(BSDXAPTID)
141AVUPDT(BSDXSCD,BSDXSTART,BSDXLEN) ;Update Legacy PIMS Clinic availability
142 ;See SDCNP0
143 N SD,S ; Start Date
144 S (SD,S)=BSDXSTART
145 N I ; Clinic IEN in 44
146 S I=BSDXSCD
147 ; if day has no schedule in legacy PIMS, forget about this update.
148 Q:'$D(^SC(I,"ST",SD\1,1))
149 N SL ; Clinic characteristics node (length of appt, when appts start etc)
150 S SL=^SC(I,"SL")
151 N X ; Hour Clinic Display Begins
152 S X=$P(SL,U,3)
153 N STARTDAY ; When does the day start?
154 S STARTDAY=$S($L(X):X,1:8) ; If defined, use it; otherwise, 8am
155 N SB ; ?? Who knows? Day Start - 1 divided by 100.
156 S SB=STARTDAY-1/100
157 S X=$P(SL,U,6) ; Now X is Display increments per hour
158 N HSI ; Slots per hour, try 1
159 S HSI=$S(X:X,1:4) ; if defined, use it; otherwise, 4
160 N SI ; Slots per hour, try 2
161 S SI=$S(X="":4,X<3:4,X:X,1:4) ; If slots "", or less than 3, then 4
162 N STR ; ??
163 S STR="#@!$* XXWVUTSRQPONMLKJIHGFEDCBA0123456789jklmnopqrstuvwxyz"
164 N SDDIF ; Slots per hour diff??
165 S SDDIF=$S(HSI<3:8/HSI,1:2)
166 S SL=BSDXLEN ; Dammit, reusing variable; SL now Appt Length from GUI
167 S S=^SC(I,"ST",SD\1,1) ; reusing var again; S now Day Pattern from PIMS
168 N Y ; Hours since start of Date
169 S Y=SD#1-SB*100 ;SD#1=FM Time portion; -SB minus start of day; conv to hrs
170 N ST ; ??
171 ; Y#1 -> Minutes; *SI -> * Slots per hour; \.6 trunc min to hour
172 ; Y\1 -> Hours since start of day; * SI: * slots
173 S ST=Y#1*SI\.6+(Y\1*SI)
174 N SS ; how many slots are supposed to be taken by appointment
175 S SS=SL*HSI/60 ; (nb: try SL: 30 min; HSI: 4 slots)
176 N I
177 I Y'<1 D ; If Hours since start of Date is greater than 1
178 . ; loop through pattern. Tired of documenting.
179 . F I=ST+ST:SDDIF D Q:Y="" Q:SS'>0
180 . . S Y=$E(STR,$F(STR,$E(S,I+1))) Q:Y=""
181 . . S S=$E(S,1,I)_Y_$E(S,I+2,999)
182 . . S SS=SS-1
183 . . Q:SS'>0
184 S ^SC(BSDXSCD,"ST",SD\1,1)=S ; new pattern; global set
185 Q
186 ;
187BSDXCAN(BSDXAPTID) ;
188 ;Cancel BSDX APPOINTMENT entry
189 N %DT,X,BSDXDATE,Y,BSDXIENS,BSDXFDA,BSDXMSG
190 S %DT="XT",X="NOW" D ^%DT ; X ^DD("DD")
191 S BSDXDATE=Y
192 S BSDXIENS=BSDXAPTID_","
193 S BSDXFDA(9002018.4,BSDXIENS,.12)=BSDXDATE
194 K BSDXMSG
195 D FILE^DIE("","BSDXFDA","BSDXMSG")
196 Q
197 ;
198CANEVT(BSDXPAT,BSDXSTART,BSDXSC) ;EP Called by BSDX CANCEL APPOINTMENT event
199 ;when appointments cancelled via PIMS interface.
200 ;Propagates cancellation to BSDXAPPT and raises refresh event to running GUI clients
201 N BSDXFOUND,BSDXRES
202 Q:+$G(BSDXNOEV)
203 Q:'+$G(BSDXSC)
204 S BSDXFOUND=0
205 I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0)) S BSDXFOUND=$$CANEVT1(BSDXRES,BSDXSTART,BSDXPAT)
206 I BSDXFOUND D CANEVT3(BSDXRES) Q
207 I $D(^BXDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0)) S BSDXFOUND=$$CANEVT1(BSDXRES,BSDXSTART,BSDXPAT)
208 I BSDXFOUND D CANEVT3(BSDXRES)
209 Q
210 ;
211CANEVT1(BSDXRES,BSDXSTART,BSDXPAT) ;
212 ;Get appointment id in BSDXAPT
213 ;If found, call BSDXCAN(BSDXAPPT) and return 1
214 ;else return 0
215 N BSDXFOUND,BSDXAPPT
216 S BSDXFOUND=0
217 Q:'+BSDXRES BSDXFOUND
218 Q:'$D(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART)) BSDXFOUND
219 S BSDXAPPT=0 F S BSDXAPPT=$O(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART,BSDXAPPT)) Q:'+BSDXAPPT D Q:BSDXFOUND
220 . N BSDXNOD
221 . S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""
222 . I $P(BSDXNOD,U,5)=BSDXPAT,$P(BSDXNOD,U,12)="" S BSDXFOUND=1 Q
223 I BSDXFOUND,+$G(BSDXAPPT) D BSDXCAN(BSDXAPPT)
224 Q BSDXFOUND
225 ;
226CANEVT3(BSDXRES) ;
227 ;Call RaiseEvent to notify GUI clients
228 ;
229 N BSDXRESN
230 S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
231 Q:BSDXRESN=""
232 S BSDXRESN=$P(BSDXRESN,"^")
233 ;D EVENT^BSDX23("SCHEDULE-"_BSDXRESN,"","","")
234 D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
235 Q
236 ;
237ERR(BSDXI,BSDXERR) ;Error processing
238 S BSDXI=BSDXI+1
239 S BSDXERR=$TR(BSDXERR,"^","~")
240 S ^BSDXTMP($J,BSDXI)=BSDXERR_$C(30)
241 S BSDXI=BSDXI+1
242 S ^BSDXTMP($J,BSDXI)=$C(31)
243 L -^BSDXAPPT(BSDXAPTID)
244 QUIT
245 ;
246ETRAP ;EP Error trap entry
247 N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
248 D ^%ZTER
249 S $EC="" ; Clear Error
250 ; Log error message and send to client
251 I '$D(BSDXI) N BSDXI S BSDXI=0
252 D ERR(BSDXI,"-100~BSDX08 Error: "_$G(%ZTERZE))
253 QUIT
254 ;
255 ;;;NB: This is code that is unused in both original and port.
256 ; ; If not appt in the "S" node is found in ^SC then check associated RPMS Clinic Multiple
257 ; I BSDXSCIEN="" D I 'BSDXZ Q ;Q:BSDXZ
258 ; . S BSDXERR="BSDX08: Unable to find associated RPMS appointment for this patient. "
259 ; . S BSDXZ=1
260 ; . ; Check if there are associated RPMS clinics. (not currently used) Does the multiple exist? No, then quit
261 ; . I '$D(^BSDXRES(BSDXSC1,20)) S BSDXZ=0 QUIT
262 ; . ; Loop through the multiple. Get Location and then the ^SC "S" node IEN.
263 ; . N BSDX1 S BSDX1=0
264 ; . F S BSDX1=$O(^BSDXRES(BSDXSC1,20,BSDX1)) Q:'+BSDX1 Q:BSDXZ=0 D
265 ; . . Q:'$D(^BSDXRES(BSDXSC1,20,BSDX1,0))
266 ; . . S BSDXLOC=$P(^BSDXRES(BSDXSC1,20,BSDX1,0),U)
267 ; . . S BSDXSCIEN=$$SCIEN^BSDXAPI(BSDXPATID,BSDXLOC,BSDXSTART) I +BSDXSCIEN S BSDXZ=0 Q
Note: See TracBrowser for help on using the repository browser.