source: Scheduling/trunk/m/BSDXAPI.m@ 1690

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

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

File size: 17.6 KB
RevLine 
[1625]1BSDXAPI ; IHS/LJF,HMW,MAW & VEN/SMH - SCHEDULING APIs ; 7/10/12 5:58pm
2 ;;1.7;BSDX;;Jun 01, 2013;Build 24
[1161]3 ; Licensed under LGPL
4 ;
[1625]5 ; Orignal routine is BSDAPI by IHS/LJF, HMW, and MAW
6 ; mods (many) by WV/SMH
7 ; Move to BSDX namespace as BSDXAPI from BSDAPI by WV/SMH
8 ; Change history is located in BSDXAPI1 (to save space).
[968]9 ;
10MAKE1(DFN,CLIN,TYP,DATE,LEN,INFO) ; Simplified PEP w/ parameters for $$MAKE - making appointment
11 ; Call like this for DFN 23435 having an appointment at Hospital Location 33
12 ; have 3 (scheduled) or 4 (walkin) appt at Dec 20, 2009 @ 10:11:59 for 30 minutes appt
13 ; for Baby foxes hallucinations.
14 ; S RESULT=$$MAKE1^BSDXAPI(23435,33,(3 or 4),3091220.221159,30,"I see Baby foxes")
[1625]15 N BSDR
[968]16 S BSDR("PAT")=DFN ;DFN
17 S BSDR("CLN")=CLIN ;Hosp Loc IEN
18 S BSDR("TYP")=TYP ;3 sched or 4 walkin
19 S BSDR("ADT")=DATE ;Appointment date in FM format
20 S BSDR("LEN")=LEN ;Appt len upto 240 (min)
[1035]21 S BSDR("OI")=INFO ;Reason for appt - up to 150 char
[968]22 S BSDR("USR")=DUZ ;Person who made appt - current user
23 Q $$MAKE(.BSDR)
24 ;
25MAKE(BSDR) ;PEP; call to store appt made
26 ;
27 ; Make call using: S ERR=$$MAKE^BSDXAPI(.ARRAY)
28 ;
29 ; Input Array -
30 ; BSDR("PAT") = ien of patient in file 2
31 ; BSDR("CLN") = ien of clinic in file 44
32 ; BSDR("TYP") = 3 for scheduled appts, 4 for walkins
33 ; BSDR("ADT") = appointment date and time
[1081]34 ; BSDR("LEN") = appointment length in minutes (*1.42 limit removed)
[968]35 ; BSDR("OI") = reason for appt - up to 150 characters
36 ; BSDR("USR") = user who made appt
37 ;
38 ;Output: error status and message
39 ; = 0 or null: everything okay
40 ; = 1^message: error and reason
41 ;
[1625]42 N BSDXMKCK S BSDXMKCK=$$MAKECK(.BSDR) ; Check if we can make appointment
43 I BSDXMKCK Q BSDXMKCK ; If we can't, quit with the reason why.
[968]44 ;
[1625]45 ;Otherwise, we continue
[968]46 ;
[1625]47 N BSDXFDA,BSDXIENS,BSDXMSG ; FILE/UPDATE^DIE variables
[1451]48 ;
[968]49 I $D(^DPT(BSDR("PAT"),"S",BSDR("ADT"),0)),$P(^(0),U,2)["C" D
50 . ; "un-cancel" existing appt in file 2
51 . S BSDXIENS=BSDR("ADT")_","_BSDR("PAT")_","
52 . S BSDXFDA(2.98,BSDXIENS,".01")=BSDR("CLN")
53 . S BSDXFDA(2.98,BSDXIENS,"3")=""
54 . S BSDXFDA(2.98,BSDXIENS,"9")=BSDR("TYP")
55 . S BSDXFDA(2.98,BSDXIENS,"9.5")=9
56 . S BSDXFDA(2.98,BSDXIENS,"14")=""
57 . S BSDXFDA(2.98,BSDXIENS,"15")=""
58 . S BSDXFDA(2.98,BSDXIENS,"16")=""
[1625]59 . S BSDXFDA(2.98,BSDXIENS,"17")="@" ; v 1.7; cancellation remarks were left over
[968]60 . S BSDXFDA(2.98,BSDXIENS,"19")=""
61 . S BSDXFDA(2.98,BSDXIENS,"20")=$$NOW^XLFDT
62 . D FILE^DIE("","BSDXFDA","BSDXMSG")
[1625]63 Q:$D(BSDXMSG) 1_U_"Fileman edit to DPT error: Patient="_BSDR("PAT")_" Appt="_BSDR("ADT")_" Error="_BSDXMSG("DIERR",1,"TEXT",1)
64 ;
65 Q:$G(BSDXSIMERR2) 1_U_$NA(BSDXSIMERR2) ; Unit Test line
66 ;
67 E D ; File new appointment/edit existing appointment in file 2
[968]68 . S BSDXIENS="?+2,"_BSDR("PAT")_","
69 . S BSDXIENS(2)=BSDR("ADT")
70 . S BSDXFDA(2.98,BSDXIENS,.01)=BSDR("CLN")
71 . S BSDXFDA(2.98,BSDXIENS,"9")=BSDR("TYP")
72 . S BSDXFDA(2.98,BSDXIENS,"9.5")=9
73 . S BSDXFDA(2.98,BSDXIENS,"20")=$$NOW^XLFDT
[1625]74 . D UPDATE^DIE("","BSDXFDA","BSDXIENS","BSDXMSG")
75 Q:$D(BSDXMSG) 1_U_"FileMan add to DPT error: Patient="_BSDR("PAT")_" Appt="_BSDR("ADT")_" Error="_BSDXMSG("DIERR",1,"TEXT",1)
76 ;
77 Q:$G(BSDXSIMERR3) 1_U_$NA(BSDXSIMERR3) ; Unit Test line
78 ;
79 ; add appt to file 44. This adds it to the FIRST subfile (Appointment)
80 N DIC,DA,Y,X,DD,DO,DLAYGO,DINUM
[968]81 I '$D(^SC(BSDR("CLN"),"S",0)) S ^SC(BSDR("CLN"),"S",0)="^44.001DA^^"
82 I '$D(^SC(BSDR("CLN"),"S",BSDR("ADT"),0)) D I Y<1 Q 1_U_"Error adding date to file 44: Clinic="_BSDR("CLN")_" Date="_BSDR("ADT")
83 . S DIC="^SC("_BSDR("CLN")_",""S"",",DA(1)=BSDR("CLN"),(X,DINUM)=BSDR("ADT")
84 . S DIC("P")="44.001DA",DIC(0)="L",DLAYGO=44.001
85 . S Y=1 I '$D(@(DIC_X_")")) D FILE^DICN
86 ;
[1625]87 Q:$G(BSDXSIMERR4) 1_U_$NA(BSDXSIMERR4) ; Unit Test line
88 ;
89 ; add appt for file 44, second subfile (Appointment/Patient)
[968]90 ; Sep 28 2010: Changed old style API to new style API. Keep for reference //smh
91 ;K DIC,DA,X,Y,DLAYGO,DD,DO,DINUM
92 ;S DIC="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
93 ;S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),X=BSDR("PAT")
94 ;S DIC("DR")="1///"_BSDR("LEN")_";3///"_$E($G(BSDR("OI")),1,150)_";7///`"_BSDR("USR")_";8///"_$P($$NOW^XLFDT,".")
95 ;S DIC("P")="44.003PA",DIC(0)="L",DLAYGO=44.003
96 ;D FILE^DICN
97 ;
98 N BSDXIENS S BSDXIENS="?+1,"_BSDR("ADT")_","_BSDR("CLN")_","
99 N BSDXFDA
100 S BSDXFDA(44.003,BSDXIENS,.01)=BSDR("PAT")
101 S BSDXFDA(44.003,BSDXIENS,1)=BSDR("LEN")
102 S BSDXFDA(44.003,BSDXIENS,3)=$E($G(BSDR("OI")),1,150)
103 S BSDXFDA(44.003,BSDXIENS,7)=BSDR("USR")
104 S BSDXFDA(44.003,BSDXIENS,8)=$P($$NOW^XLFDT,".")
105 N BSDXERR
106 D UPDATE^DIE("","BSDXFDA","","BSDXERR")
107 ;
108 I $D(BSDXERR) Q 1_U_"Error adding appt to file 44: Clinic="_BSDR("CLN")_" Date="_BSDR("ADT")_" Patient="_BSDR("PAT")_" Error: "_BSDXERR("DIERR",1,"TEXT",1)
109 ;
[1625]110 ;Q:$G(BSDXSIMERR5) 1_U_$NA(BSDXSIMERR5) ; Unit Test line
111 S:$G(BSDXSIMERR5) X=1/0
112 ;
113 ; Update the Availablilities ; Doesn't fail. Global reads and sets.
114 D AVUPDTMK^BSDXAPI1(BSDR("CLN"),BSDR("ADT"),BSDR("LEN"),BSDR("PAT"))
115 ;
[968]116 ; call event driver
117 NEW DFN,SDT,SDCL,SDDA,SDMODE
118 S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2
119 S SDDA=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
120 D MAKE^SDAMEVT(DFN,SDT,SDCL,SDDA,SDMODE)
121 Q 0
122 ;
[1625]123MAKECK(BSDR) ; $$ - Is it okay to make an appointment? ; PEP
124 ; Input: Same as $$MAKE
125 ; Output: 1^error or 0 for success
126 ; NB: This subroutine saves no data. Only checks whether it's okay.
127 ;
128 I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
129 I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
130 I ($G(BSDR("TYP"))<3)!($G(BSDR("TYP"))>4) Q 1_U_"Appt Type error: "_$G(BSDR("TYP"))
131 I $G(BSDR("ADT")) S BSDR("ADT")=+$E(BSDR("ADT"),1,12) ;remove seconds
132 I $G(BSDR("ADT"))'?7N.1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
133 ;
134 ; Appt Length check removed in v 1.5
135 ;
136 I '$D(^VA(200,+$G(BSDR("USR")),0)) Q 1_U_"User Who Made Appt Error: "_$G(BSDR("USR"))
137 ; More verbose error message in v1.5
138 ; Following block to give an error message to user if there is already an appointment for patient. More verbose than others.
139 N BSDXERR ; place to store error message
140 I $D(^DPT(BSDR("PAT"),"S",BSDR("ADT"),0)),$P(^(0),U,2)'["C" DO QUIT BSDXERR ; If there's an appt in the "S" node of file 2 and it's not cancelled
141 . S BSDXERR=1_U_"Patient "_$P(^DPT(BSDR("PAT"),0),U)_" ("_BSDR("PAT")_") "
142 . S BSDXERR=BSDXERR_"already has appt at "_$$FMTE^XLFDT(BSDR("ADT"))
143 . N BSDXSCIEN S BSDXSCIEN=$P(^DPT(BSDR("PAT"),"S",BSDR("ADT"),0),U) ; Clinic IEN in ^SC (0 piece of 0 node of "S" multiple in file 2)
144 . N BSDXSCNAM S BSDXSCNAM=$P(^SC(BSDXSCIEN,0),U) ; PIMS Name of Clinic
145 . S BSDXERR=BSDXERR_$C(13,10)_"PIMS clinic: "_BSDXSCNAM ; tell the user of the PIMS clinic
146 . I $D(^BSDXRES("ALOC",BSDXSCIEN)) DO ; if the Clinic is linked to a BSDX Resource (we find out using the index ALOC in the BSDX RESOURCE file)
147 . . N BSDXRESIEN S BSDXRESIEN=$O(^BSDXRES("ALOC",BSDXSCIEN,""))
148 . . QUIT:'BSDXRESIEN ; Safeguard if index is corrupt
149 . . N BSDXRESNAM S BSDXRESNAM=$P(^BSDXRES(BSDXRESIEN,0),U)
150 . . S BSDXERR=BSDXERR_$C(13,10)_"Scheduling GUI clinic: "_BSDXRESNAM ; tell the user of the BSDX clinic
151 Q 0
152 ;
153UNMAKE(BSDR) ; Reverse Make - Private $$
154 ; Only used in Emergiencies where Fileman data filing fails.
155 ; If previous data exists, which caused an error, it's destroyed.
156 ; NB: ^DIK stops for nobody
157 ; NB: If Patient Appointment previously existed as cancelled, it's removed.
158 ; How can I tell if one previously existed when data is in an intermediate
159 ; State? Can I restore it if the other file failed? Restoration can cause
160 ; another error. If I restore the global, there will be cross-references
161 ; missing (ASDCN specifically).
162 ;
163 ; Input: Same array as $$MAKE
164 ; Output: Always 0
165 NEW DIK,DA
166 S DIK="^DPT("_BSDR("PAT")_",""S"","
167 S DA(1)=BSDR("PAT"),DA=BSDR("ADT")
168 D ^DIK
169 ;
170 N IEN S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
171 I 'IEN QUIT 0
172 ;
173 NEW DIK,DA
174 S DIK="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
175 S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
176 D ^DIK
177 QUIT 0
178 ;
[968]179CHECKIN1(DFN,CLIN,APDATE) ; Simplified PEP w/ parameters for $$CHECKIN - Checking in
180 ; Call like this for DFN 23435 checking in now at Hospital Location 33
181 ; for appt at Dec 20, 2009 @ 10:11:59
182 ; S RESULT=$$CHECKIN1^BSDXAPI(23435,33,3091220.221159)
[1625]183 N BSDR
[968]184 S BSDR("PAT")=DFN ;DFN
185 S BSDR("CLN")=CLIN ;Hosp Loc IEN
186 S BSDR("ADT")=APDATE ;Appt Date
187 S BSDR("CDT")=$$NOW^XLFDT ;Check-in date defaults to now
188 S BSDR("USR")=DUZ ;Check-in user defaults to current
189 Q $$CHECKIN(.BSDR)
190 ;
191CHECKIN(BSDR) ;EP; call to add checkin info to appt; IHS/ITSC/LJF 12/23/2004 PATCH 1002
192 ;
193 ; Make call by using: S ERR=$$CHECKIN^BSDXAPI(.ARRAY)
194 ;
195 ; Input array -
196 ; BSDR("PAT") = ien of patient in file 2
197 ; BSDR("CLN") = ien of clinic in file 44
198 ; BSDR("ADT") = appt date/time
199 ; BSDR("CDT") = checkin date/time
200 ; BSDR("USR") = checkin user
201 ;
202 ; Output value -
203 ; = 0 means everything worked
204 ; = 1^message means error with reason message
205 ;
[1625]206 I $G(BSDXDIE2) N X S X=1/0
[968]207 ;
[1625]208 N BSDXERR S BSDXERR=$$CHECKICK(.BSDR)
209 I BSDXERR Q BSDXERR
210 ;
[968]211 ; find ien for appt in file 44
212 NEW IEN,DIE,DA,DR
213 S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
214 ;
215 ; remember before status
[1625]216 ; Failure analysis: Only ^TMP global is set here.
217 NEW SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL,SDMODE
[968]218 S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2,SDDA=IEN
219 S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
220 D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
221 ;
[1625]222 ; set checkin; Old Code -- keep for ref VEN/SMH 3 Jul 2012
223 ; S DIE="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
224 ; S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
225 ; S DR="309///"_BSDR("CDT")_";302///`"_BSDR("USR")_";305///"_$$NOW^XLFDT
226 ; D ^DIE
[968]227 ;
[1625]228 I $D(BSDXSIMERR3) Q 1_U_"Simulated Error"
229 ;
230 ; Failure analysis: If this fails, no other changes were made in this routine
231 N BSDXIENS S BSDXIENS=IEN_","_BSDR("ADT")_","_BSDR("CLN")_","
232 N BSDXFDA
233 S BSDXFDA(44.003,BSDXIENS,309)=BSDR("CDT")
234 S BSDXFDA(44.003,BSDXIENS,302)=BSDR("USR")
235 S BSDXFDA(44.003,BSDXIENS,305)=$$NOW^XLFDT()
236 N BSDXERR
237 D UPDATE^DIE("","BSDXFDA","BSDXERR")
238 ;
239 I $D(BSDXERR) Q 1_U_"Error checking in appointment to file 44. Error: "_BSDXERR("DIERR",1,"TEXT",1)
240 ;
[968]241 ; set after status
242 S SDDA=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
243 S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
244 D AFTER^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
245 ;
[1625]246 ; Point of no Return
[968]247 ; call event driver
248 D EVT^SDAMEVT(.SDATA,4,SDMODE,SDCIHDL)
249 Q 0
250 ;
[1625]251CHECKIC1(DFN,CLIN,APDATE) ; Simplified PEP w/ parameters for $$CHECKICK -
252 ; Check-in Check
253 ; Call like this for DFN 23435 checking in now at Hospital Location 33
254 ; for appt at Dec 20, 2009 @ 10:11:59
255 ; S RESULT=$$CHECKIC1^BSDXAPI(23435,33,3091220.221159)
256 N BSDR
257 S BSDR("PAT")=DFN ;DFN
258 S BSDR("CLN")=CLIN ;Hosp Loc IEN
259 S BSDR("ADT")=APDATE ;Appt Date
260 S BSDR("CDT")=$$NOW^XLFDT ;Check-in date defaults to now
261 S BSDR("USR")=DUZ ;Check-in user defaults to current
262 Q $$CHECKICK(.BSDR)
263 ;
264CHECKICK(BSDR) ; $$ PEP; - Is it okay to check-in patient?
265 ; Input: Same as $$CHECKIN
266 ; Output: 0 if okay or 1^message if error
267 ;
268 I $G(BSDXSIMERR2) Q 1_U_"Simulated Error"
269 ;
270 I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
271 I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
272 I $G(BSDR("ADT")) S BSDR("ADT")=+$E(BSDR("ADT"),1,12) ;remove seconds
273 I $G(BSDR("ADT"))'?7N.1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
274 I $G(BSDR("CDT")) S BSDR("CDT")=+$E(BSDR("CDT"),1,12) ;remove seconds
275 I $G(BSDR("CDT"))'?7N.1".".4N Q 1_U_"Checkin Date/Time error: "_$G(BSDR("CDT"))
276 I '$D(^VA(200,+$G(BSDR("USR")),0)) Q 1_U_"User Who Made Appt Error: "_$G(BSDR("USR"))
277 ;
278 ; find ien for appt in file 44
279 N IEN S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
280 I 'IEN Q 1_U_"Error trying to find appointment for checkin: Patient="_BSDR("PAT")_" Clinic="_BSDR("CLN")_" Appt="_BSDR("ADT")
281 Q 0
282 ;
[968]283CANCEL1(DFN,CLIN,TYP,APDATE,REASON,INFO) ; PEP w/ parameters for $$CANCEL - cancelling appointment
284 ; Call like this for DFN 23435 cancelling an appointment at Hospital Location 33,
285 ; cancellation initiated by patient ("PC" rather than clinic "C"),
286 ; cancelling appt at Dec 20, 2009 @ 10:11:59 because of reason 1 in file 409.2 IEN (weather)
287 ; because foxes come out during bad weather.
288 ; S RESULT=$$CANCEL1^BSDXAPI(23435,33,"PC",3091220.221159,1,"Afraid of foxes")
[1625]289 N BSDR
[968]290 S BSDR("PAT")=DFN
291 S BSDR("CLN")=CLIN
292 S BSDR("TYP")=TYP
293 S BSDR("ADT")=APDATE
294 S BSDR("CDT")=$$NOW^XLFDT
295 S BSDR("USR")=DUZ
296 S BSDR("CR")=REASON
297 S BSDR("NOT")=INFO
298 Q $$CANCEL(.BSDR)
299 ;
300CANCEL(BSDR) ;PEP; called to cancel appt
301 ;
302 ; Make call using: S ERR=$$CANCEL^BSDXAPI(.ARRAY)
303 ;
304 ; Input Array -
305 ; BSDR("PAT") = ien of patient in file 2
306 ; BSDR("CLN") = ien of clinic in file 44
307 ; BSDR("TYP") = C for canceled by clinic; PC for patient canceled
308 ; BSDR("ADT") = appointment date and time
309 ; BSDR("CDT") = cancel date and time
310 ; BSDR("USR") = user who canceled appt
311 ; BSDR("CR") = cancel reason - pointer to file 409.2
312 ; BSDR("NOT") = cancel remarks - optional notes to 160 characters
313 ;
314 ;Output: error status and message
315 ; = 0 or null: everything okay
316 ; = 1^message: error and reason
317 ;
[1625]318 ; Okay to Cancel? Call Cancel Check.
319 N BSDXCANCK S BSDXCANCK=$$CANCELCK(.BSDR)
320 I BSDXCANCK Q BSDXCANCK
[968]321 ;
[1080]322 ; BSDX 1.5 3110125
323 ; UJO/SMH - Add ability to remove check-in if the patient is checked in
[1625]324 ; VEN/SMH on 3120625/v1.7 - PIMS doesn't care if patient is already checked in
325 ; Lets you remove appointment anyways! Not like RPMS.
326 ; Plus... deleting checkin affects S node on 44, which is DELETED anyways!
[968]327 ;
328 ; remember before status
[1625]329 NEW SDATA,DFN,SDT,SDCL,SDDA,SDCPHDL,SDMODE
330 NEW IEN S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
[968]331 S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2,SDDA=IEN
332 S SDCPHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
333 D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCPHDL)
[1625]334 ; NB: Here only ^TMP globals are set with before values.
[968]335 ;
336 ; get user who made appt and date appt made from ^SC
337 ; because data in ^SC will be deleted
[1625]338 ; Appointment Length: ditto
[968]339 NEW USER,DATE
340 S USER=$P($G(^SC(SDCL,"S",SDT,1,IEN,0)),U,6)
341 S DATE=$P($G(^SC(SDCL,"S",SDT,1,IEN,0)),U,7)
[1625]342 N BSDXLEN S BSDXLEN=$$APPLEN(DFN,SDCL,SDT) ; appt length
[968]343 ;
[1625]344 ; update file 2 info --old code; keep for reference
345 ;NEW DIE,DA,DR
346 ;S DIE="^DPT("_DFN_",""S"",",DA(1)=DFN,DA=SDT
347 ;S DR="3///"_BSDR("TYP")_";14///`"_BSDR("USR")_";15///"_BSDR("CDT")_";16///`"_BSDR("CR")_";19///`"_USER_";20///"_DATE
348 ;S:$G(BSDR("NOT"))]"" DR=DR_";17///"_$E(BSDR("NOT"),1,160)
349 ;D ^DIE
350 N BSDXIENS S BSDXIENS=SDT_","_DFN_","
351 N BSDXFDA
352 S BSDXFDA(2.98,BSDXIENS,3)=BSDR("TYP")
353 S BSDXFDA(2.98,BSDXIENS,14)=BSDR("USR")
354 S BSDXFDA(2.98,BSDXIENS,15)=BSDR("CDT")
355 S BSDXFDA(2.98,BSDXIENS,16)=BSDR("CR")
356 S BSDXFDA(2.98,BSDXIENS,19)=USER
357 S BSDXFDA(2.98,BSDXIENS,20)=DATE
358 S:$G(BSDR("NOT"))]"" BSDXFDA(2.98,BSDXIENS,17)=$E(BSDR("NOT"),1,160)
359 N BSDXERR
360 D FILE^DIE("","BSDXFDA","BSDXERR")
361 I $D(BSDXERR) Q 1_U_"Cannot cancel appointment in File 2"
362 ; Failure point 1: If we fail here, nothing has happened yet.
[968]363 ;
[1625]364 ; delete data in ^SC -- this does not (typically) fail. Fileman won't stop
[968]365 NEW DIK,DA
366 S DIK="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
367 S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
368 D ^DIK
[1625]369 ; Failure point 2: not expected to happen here
[968]370 ;
[1625]371 ; Update PIMS availability -- this doesn't fail. Global gets/sets only.
372 D AVUPDTCN^BSDXAPI1(SDCL,SDT,BSDXLEN)
373 ;
374 ; call event driver -- point of no return
[968]375 D CANCEL^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDMODE,SDCPHDL)
[1625]376 ;
[968]377 Q 0
378 ;
[1625]379CANCELCK(BSDR) ; $$ PEP; Okay to Cancel Appointment?
380 ; Input: .BSDR array as documented in $$CANCEL
381 ; Output: 0 or 1^Error message
382 I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
383 I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
384 I ($G(BSDR("TYP"))'="C"),($G(BSDR("TYP"))'="PC") Q 1_U_"Cancel Status error: "_$G(BSDR("TYP"))
385 I $G(BSDR("ADT")) S BSDR("ADT")=+$E(BSDR("ADT"),1,12) ;remove seconds
386 I $G(BSDR("ADT"))'?7N.1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
387 I $G(BSDR("CDT")) S BSDR("CDT")=+$E(BSDR("CDT"),1,12) ;remove seconds
388 I $G(BSDR("CDT"))'?7N.1".".4N Q 1_U_"Cancel Date/Time error: "_$G(BSDR("CDT"))
389 I '$D(^VA(200,+$G(BSDR("USR")),0)) Q 1_U_"User Who Canceled Appt Error: "_$G(BSDR("USR"))
390 I '$D(^SD(409.2,+$G(BSDR("CR")))) Q 1_U_"Cancel Reason error: "_$G(BSDR("CR"))
391 ;
392 NEW IEN S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
393 I 'IEN Q 1_U_"Error trying to find appointment for cancel: Patient="_BSDR("PAT")_" Clinic="_BSDR("CLN")_" Appt="_BSDR("ADT")
394 ;
395 ; Check-out check. New in v1.7
396 I $$CO(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"),IEN) Q 1_U_"Cannot delete. Appointment has already been checked-out!"
397 Q 0
398 ;
[968]399CI(PAT,CLINIC,DATE,SDIEN) ;PEP; -- returns 1 if appt already checked-in
400 NEW X
401 S X=$G(SDIEN) ;ien sent in call
402 I 'X S X=$$SCIEN(PAT,CLINIC,DATE) I 'X Q 0
403 S X=$P($G(^SC(CLINIC,"S",DATE,1,X,"C")),U)
404 Q $S(X:1,1:0)
405 ;
[1625]406CO(PAT,CLINIC,DATE,SDIEN) ;PEP; -- returns 1 if appt already checked-out
407 NEW X
408 S X=$G(SDIEN) ;ien sent in call
409 I 'X S X=$$SCIEN(PAT,CLINIC,DATE) I 'X Q 0
410 S X=$P($G(^SC(CLINIC,"S",DATE,1,X,"C")),U,3)
411 Q $S(X:1,1:0)
[1472]412 ;
[968]413SCIEN(PAT,CLINIC,DATE) ;PEP; returns ien for appt in ^SC
414 NEW X,IEN
415 S X=0 F S X=$O(^SC(CLINIC,"S",DATE,1,X)) Q:'X Q:$G(IEN) D
[1006]416 . Q:$P($G(^SC(CLINIC,"S",DATE,1,X,0)),U,9)["C" ;cancelled
[968]417 . I +$G(^SC(CLINIC,"S",DATE,1,X,0))=PAT S IEN=X
418 Q $G(IEN)
419 ;
[1625]420APPLEN(PAT,CLINIC,DATE) ; $$ PEP; returns an appointment's length
421 ; Get either the appointment length or zero
422 N SCIEN S SCIEN=$$SCIEN(PAT,CLINIC,DATE)
423 Q:SCIEN $P(^SC(CLINIC,"S",DATE,1,SCIEN,0),U,2)
424 Q 0
[968]425APPTYP(PAT,DATE) ;PEP; -- returns type of appt (scheduled or walk-in)
426 NEW X S X=$P($G(^DPT(PAT,"S",DATE,0)),U,7)
427 Q $S(X=3:"SCHED",X=4:"WALK-IN",1:"??")
428 ;
Note: See TracBrowser for help on using the repository browser.