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

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

Moved Unit Tests and UT Set-up to BSDXUT, started refactoring BSDX08.

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