source: Scheduling/trunk/m/BSDX31.m@ 1672

Last change on this file since 1672 was 1625, checked in by Tariq Hamkari, 12 years ago

Ayman Ghaith : adding the correct routines which not has the transactions.

File size: 7.1 KB
RevLine 
[1625]1BSDX31 ; IHS/OIT/HMW - WINDOWS SCHEDULING RPCS ; 7/10/12 10:39am
2 ;;1.7;BSDX;;Jun 01, 2013;Build 24
3 ; Licensed under LGPL
4 ; Change Log:
5 ; v1.42 3101023 WV/SMH - Change transaction to restartable.
6 ; v1.42 3101206 UJO/SMH - Extensive refactoring
7 ; v1.7 3120626 VEN/SMH - Removed transactions; extensive refactoring
8 ; - Moved APTNS (whatever it was) to BSDXAPI1
9 ; as $$NOSHOW
10 ; - Made BSDXNOS extrinsic.
11 ; - Moved Unit Tests to BSDXUT1
12 ; - BSDXNOS deletes no-show rather than file 0 for
13 ; undoing a no show
14 ;
15 ; Error Reference:
16 ; -1: zero or null Appt ID
17 ; -2: Invalid APPT ID (doesn't exist in ^BSDXAPPT)
18 ; -3: No-show flag is invalid
19 ; -4: Filing of No-show in ^BSDXAPPT failed
20 ; -5: Filing of No-show in ^DPT failed (BSDXAPI error)
21 ; -6: Invalid Resource ID
22 ; -7: Lock not acquired on ^BSDXAPPT(BSDXAPTID)
23 ; -100: M Error
24 ;
25 ;
[1041]26NOSHOWD(BSDXY,BSDXAPTID,BSDXNS) ;EP
[1625]27 ;Entry point for debugging
28 ;
29 ; D DEBUG^%Serenji("NOSHOW^BSDX31(.BSDXY,BSDXAPTID,BSDXNS)")
30 Q
31 ;
[1041]32NOSHOW(BSDXY,BSDXAPTID,BSDXNS) ;EP - No show a patient
[1625]33 ; Called by RPC: BSDX NOSHOW
34 ; Sets appointment noshow flag in BSDX APPOINTMENT file and "S" node in File 2
35 ;
36 ; Parameters:
37 ; BSDXY: Global Return
38 ; BSDXAPTID is entry number in BSDX APPOINTMENT file
39 ; BSDXNS = 1: NOSHOW, 0: CANCEL NOSHO
40 ;
41 ; Returns ADO.net record set with fields
42 ; - ERRORID; ERRORTEXT
43 ; ERRORID of 1 is okay
44 ; Anything else is an error.
45 ;
46 ; Return Array; set and clear
47 S BSDXY=$NA(^BSDXTMP($J))
48 K ^BSDXTMP($J)
49 ;
50 ; $ET
51 N $ET S $ET="G ETRAP^BSDX31"
52 ;
53 ; Basline vars
54 D ^XBKVAR ; Set up baseline variables (DUZ, DUZ(2)) if they don't exist
55 ;
56 ; Counter
57 N BSDXI S BSDXI=0
58 ;
59 ; Header Node
60 S ^BSDXTMP($J,BSDXI)="I00100ERRORID^T00030ERRORTEXT"_$C(30)
61 ;
62 ;;;test for error. See if %ZTER works
63 I $G(BSDXDIE) N X S X=1/0
64 ;;;TEST
65 ;
66 ; Turn off SDAM APPT PROTOCOL BSDX Entries
67 N BSDXNOEV S BSDXNOEV=1 ;Don't execute protocol
68 ;
69 ; Appointment ID check
70 I '+BSDXAPTID D ERR(-1,"BSDX31: Invalid Appointment ID") Q
71 I '$D(^BSDXAPPT(BSDXAPTID,0)) D ERR(-2,"BSDX31: Invalid Appointment ID") Q
72 ;
73 ; Lock BSDX node, only to synchronize access to the globals.
74 ; It's not expected that the error will ever happen as no filing
75 ; is supposed to take 5 seconds.
76 L +^BSDXAPPT(BSDXAPTID):5 E D ERR(-7,"BSDX31: Appt record is locked. Please contact technical support.") Q
77 ;
78 ; Noshow value check - Must be 1 or 0
79 S BSDXNS=+BSDXNS
80 I BSDXNS'=1&(BSDXNS'=0) D ERR(-3,"BSDX31: Invalid No Show value") Q
81 ;
82 ; Get Some data
83 N BSDXNOD S BSDXNOD=^BSDXAPPT(BSDXAPTID,0) ; Node
84 N BSDXPATID S BSDXPATID=$P(BSDXNOD,U,5) ; DFN
85 N BSDXSTART S BSDXSTART=$P(BSDXNOD,U) ; Start Date/Time
86 N BSDXRES S BSDXRES=$P(BSDXNOD,U,7) ; Resource ID
87 ;
88 ; Check if Resource ID is missing or invalid
89 I BSDXRES="" D ERR(-6,"BSDX31: Invalid Resource") QUIT
90 I '$D(^BSDXRES(BSDXRES,0)) D ERR(-6,"BSDX31: Invalid Resource") QUIT
91 ;
92 ; Get the Hospital Location
93 N BSDXRESNOD S BSDXRESNOD=^BSDXRES(BSDXRES,0)
94 N BSDXLOC S BSDXLOC=$P(BSDXRESNOD,U,4) ;HOSPITAL LOCATION
95 I BSDXLOC,'$D(^SC(BSDXLOC,0)) S BSDXLOC="" ; Unlink it if it doesn't exist
96 ; I can go and then delete it from ^BSDXRES like Mailman code which tries
97 ; to be too helpful... but I will postpone that until this is a need.
98 ;
99 ; Check if it's okay to no-show patient.
100 N BSDXERR S BSDXERR=0 ; Error variable
101 I BSDXLOC S BSDXERR=$$NOSHOWCK^BSDXAPI1(BSDXPATID,BSDXLOC,BSDXSTART,BSDXNS)
102 I BSDXERR D ERR(-5,"BSDX31: "_$P(BSDXERR,U,2)) QUIT
103 ;
104 ; Simulated Error
105 I $G(BSDXSIMERR1) D ERR(-4,"BSDX31: Simulated Error") QUIT
106 ; Edit BSDX APPOINTMENT entry No-show field
107 ; Failure Analysis: If we fail here, no rollback needed, as this is the 1st
108 ; call
109 N BSDXMSG S BSDXMSG=$$BSDXNOS(BSDXAPTID,BSDXNS)
110 I BSDXMSG D ERR(-4,"BSDX31: "_$P(BSDXMSG,U,2)) QUIT
111 ;
112 ; Edit File 2 "S" node entry
113 ; Failure Analysis: If we fail here, we need to rollback the BSDX
114 ; Apptointment Entry
115 N BSDXERR S BSDXERR=0 ; Error variable
116 ; If HL exist, (resource is linked to PIMS), file no show in File 2
117 I BSDXLOC S BSDXERR=$$NOSHOW^BSDXAPI1(BSDXPATID,BSDXLOC,BSDXSTART,BSDXNS)
118 I BSDXERR D QUIT
119 . D ERR(-5,"BSDX31: "_$P(BSDXERR,U,2))
120 . N % S %=$$BSDXNOS(BSDXAPTID,'BSDXNS) ; no error checking for filer
121 ;
122 ; Unlock
123 L -^BSDXAPPT(BSDXAPTID)
124 ;
125 ; Return data in ADO.net table
126 S BSDXI=BSDXI+1
127 S ^BSDXTMP($J,BSDXI)="1^"_$C(30) ; 1 means everything okay
128 S BSDXI=BSDXI+1
129 S ^BSDXTMP($J,BSDXI)=$C(31)
130 QUIT
131 ;
132BSDXNOS(BSDXAPTID,BSDXNS) ; $$ Private; File/unfile noshow in ^BSDXAPPT
133 ; in v1.7 I delete the no-show value rather than file zero
134 N BSDXFDA,BSDXIENS,BSDXMSG
135 N BSDXVALUE ; What to file: 1 or delete it.
136 I BSDXNS S BSDXVALUE=1
137 E S BSDXVALUE="@"
138 S BSDXIENS=BSDXAPTID_","
139 S BSDXFDA(9002018.4,BSDXIENS,.1)=BSDXVALUE ;NOSHOW 1 or 0
140 D FILE^DIE("","BSDXFDA","BSDXMSG")
141 QUIT:$D(BSDXMSG) -1_U_BSDXMSG("DIERR",1,"TEXT",1)
142 QUIT 0
143 ;
[1041]144NOSEVT(BSDXPAT,BSDXSTART,BSDXSC) ;EP Called by BSDX NOSHOW APPOINTMENT event
[1625]145 ;when appointments NOSHOW via PIMS interface.
146 ;Propagates NOSHOW to BSDXAPPT and raises refresh event to running GUI clients
147 ;
148 Q:+$G(BSDXNOEV)
149 Q:'+$G(BSDXSC)
150 Q:$G(SDATA("AFTER","STATUS"))["AUTO RE-BOOK"
151 N BSDXSTAT,BSDXFOUND,BSDXRES
152 S BSDXSTAT=1
153 S:$G(SDATA("BEFORE","STATUS"))["NO-SHOW" BSDXSTAT=0
154 S BSDXFOUND=0
155 I $D(^BSDXRES("ALOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ALOC",BSDXSC,0)) S BSDXFOUND=$$NOSEVT1(BSDXRES,BSDXSTART,BSDXPAT,BSDXSTAT)
156 I BSDXFOUND D NOSEVT3(BSDXRES) Q
157 I $D(^BXDXRES("ASSOC",BSDXSC)) S BSDXRES=$O(^BSDXRES("ASSOC",BSDXSC,0)) S BSDXFOUND=$$NOSEVT1(BSDXRES,BSDXSTART,BSDXPAT,BSDXSTAT)
158 I BSDXFOUND D NOSEVT3(BSDXRES)
159 Q
160 ;
[1041]161NOSEVT1(BSDXRES,BSDXSTART,BSDXPAT,BSDXSTAT) ;
[1625]162 ;Get appointment id in BSDXAPT
163 ;If found, call BSDXNOS(BSDXAPPT) and return 1
164 ;else return 0
165 N BSDXFOUND,BSDXAPPT,BSDXNOD
166 S BSDXFOUND=0
167 Q:'+$G(BSDXRES) BSDXFOUND
168 Q:'$D(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART)) BSDXFOUND
169 S BSDXAPPT=0 F S BSDXAPPT=$O(^BSDXAPPT("ARSRC",BSDXRES,BSDXSTART,BSDXAPPT)) Q:'+BSDXAPPT D Q:BSDXFOUND
170 . S BSDXNOD=$G(^BSDXAPPT(BSDXAPPT,0)) Q:BSDXNOD=""
171 . I $P(BSDXNOD,U,5)=BSDXPAT,$P(BSDXNOD,U,12)="" S BSDXFOUND=1 Q
172 I BSDXFOUND,+$G(BSDXAPPT) N BSDXMSG S BSDXMSG=$$BSDXNOS(BSDXAPPT,BSDXSTAT)
173 I BSDXMSG D ^%ZTER ; Last ditch error handling. This is supposed to be silently called from the protocol file.
174 Q BSDXFOUND
175 ;
[1041]176NOSEVT3(BSDXRES) ;
[1625]177 ;Call RaiseEvent to notify GUI clients
178 ;
179 N BSDXRESN
180 S BSDXRESN=$G(^BSDXRES(BSDXRES,0))
181 Q:BSDXRESN=""
182 S BSDXRESN=$P(BSDXRESN,"^")
183 D EVENT^BMXMEVN("BSDX SCHEDULE",BSDXRESN)
184 Q
185 ;
186 ;
[1041]187ERR(BSDXERID,ERRTXT) ;Error processing
[1625]188 ; Unlock first
189 L:$D(BSDXAPTID) -^BSDXAPPT(BSDXAPTID)
190 ; If last line is $C(31), we are done. No more errors to send to client.
191 I ^BSDXTMP($J,$O(^BSDXTMP($J," "),-1))=$C(31) QUIT
192 S BSDXI=BSDXI+1
193 S ERRTXT=$TR(ERRTXT,"^","~")
194 S ^BSDXTMP($J,BSDXI)=BSDXERID_"^"_ERRTXT_$C(30)
195 S BSDXI=BSDXI+1
196 S ^BSDXTMP($J,BSDXI)=$C(31)
197 QUIT
198 ;
[1041]199ETRAP ;EP Error trap entry
[1625]200 N $ET S $ET="D ^%ZTER HALT" ; Emergency Error Trap
201 D ^%ZTER
202 ;
203 ; Send to client
204 I '$D(BSDXI) N BSDXI S BSDXI=0
205 D ERR(-100,"BSDX31 Error: "_$G(%ZTERZE))
206 Q:$Q 100_U_"Mumps Error" Q
207 ;
[1041]208IMHERE(BSDXRES) ;EP
[1625]209 ;Entry point for BSDX IM HERE remote procedure
210 S BSDXRES=1
211 Q
212 ;
Note: See TracBrowser for help on using the repository browser.