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

Last change on this file since 1007 was 1006, checked in by Sam Habiel, 14 years ago

Changed "C" to ["C" in SCIEN

File size: 11.6 KB
Line 
1BSDXAPI ; IHS/ANMC/LJF - SCHEDULING APIs ; 11/2/10 4:36pm
2 ;;1.42;BSDX;;Sep 29, 2010;Build 7
3 ;Orignal routine is BSDAPI by IHS/LJF, HMW, and MAW
4 ;local mods (many) by WV/SMH
5 ;Move to BSDX namespace as BSDXAPI from BSDAPI by WV/SMH
6 ; Change History:
7 ; - Fixed errors having to do uncanceling patient appointments if it was a patient cancelled appointment.
8 ; - Use new style Fileman API for storing appointments in file 44 in $$MAKE due to problems with legacy API.
9 ; 2010-11-12:
10 ; - Changed ="C" to ["C" in SCIEN. Cancelled appointments can be "PC" as well.
11 ;
12MAKE1(DFN,CLIN,TYP,DATE,LEN,INFO) ; Simplified PEP w/ parameters for $$MAKE - making appointment
13 ; Call like this for DFN 23435 having an appointment at Hospital Location 33
14 ; have 3 (scheduled) or 4 (walkin) appt at Dec 20, 2009 @ 10:11:59 for 30 minutes appt
15 ; for Baby foxes hallucinations.
16 ; S RESULT=$$MAKE1^BSDXAPI(23435,33,(3 or 4),3091220.221159,30,"I see Baby foxes")
17 S BSDR("PAT")=DFN ;DFN
18 S BSDR("CLN")=CLIN ;Hosp Loc IEN
19 S BSDR("TYP")=TYP ;3 sched or 4 walkin
20 S BSDR("ADT")=DATE ;Appointment date in FM format
21 S BSDR("LEN")=LEN ;Appt len upto 240 (min)
22 S BSDR("INFO")=INFO ;Reason for appt - up to 150 char
23 S BSDR("USR")=DUZ ;Person who made appt - current user
24 Q $$MAKE(.BSDR)
25 ;
26MAKE(BSDR) ;PEP; call to store appt made
27 ;
28 ; Make call using: S ERR=$$MAKE^BSDXAPI(.ARRAY)
29 ;
30 ; Input Array -
31 ; BSDR("PAT") = ien of patient in file 2
32 ; BSDR("CLN") = ien of clinic in file 44
33 ; BSDR("TYP") = 3 for scheduled appts, 4 for walkins
34 ; BSDR("ADT") = appointment date and time
35 ; BSDR("LEN") = appointment length in minutes (5-120)
36 ; BSDR("OI") = reason for appt - up to 150 characters
37 ; BSDR("USR") = user who made appt
38 ;
39 ;Output: error status and message
40 ; = 0 or null: everything okay
41 ; = 1^message: error and reason
42 ;
43 I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
44 I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
45 I ($G(BSDR("TYP"))<3)!($G(BSDR("TYP"))>4) Q 1_U_"Appt Type error: "_$G(BSDR("TYP"))
46 I $G(BSDR("ADT")) S BSDR("ADT")=+$E(BSDR("ADT"),1,12) ;remove seconds
47 I $G(BSDR("ADT"))'?7N1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
48 ;
49 I ($G(BSDR("LEN"))<5)!($G(BSDR("LEN"))>240) Q 1_U_"Appt Length error: "_$G(BSDR("LEN"))
50 I '$D(^VA(200,+$G(BSDR("USR")),0)) Q 1_U_"User Who Made Appt Error: "_$G(BSDR("USR"))
51 I $D(^DPT(BSDR("PAT"),"S",BSDR("ADT"),0)),$P(^(0),U,2)'["C" Q 1_U_"Patient "_BSDR("PAT")_" already has appt at "_BSDR("ADT")
52 ;
53 NEW DIC,DA,Y,X,DD,DO,DLAYGO
54 ;
55 I $D(^DPT(BSDR("PAT"),"S",BSDR("ADT"),0)),$P(^(0),U,2)["C" D
56 . ; "un-cancel" existing appt in file 2
57 . N BSDXFDA,BSDXIENS,BSDXMSG
58 . S BSDXIENS=BSDR("ADT")_","_BSDR("PAT")_","
59 . S BSDXFDA(2.98,BSDXIENS,".01")=BSDR("CLN")
60 . S BSDXFDA(2.98,BSDXIENS,"3")=""
61 . S BSDXFDA(2.98,BSDXIENS,"9")=BSDR("TYP")
62 . S BSDXFDA(2.98,BSDXIENS,"9.5")=9
63 . S BSDXFDA(2.98,BSDXIENS,"14")=""
64 . S BSDXFDA(2.98,BSDXIENS,"15")=""
65 . S BSDXFDA(2.98,BSDXIENS,"16")=""
66 . S BSDXFDA(2.98,BSDXIENS,"19")=""
67 . S BSDXFDA(2.98,BSDXIENS,"20")=$$NOW^XLFDT
68 . D FILE^DIE("","BSDXFDA","BSDXMSG")
69 . N BSDXTEMP S BSDXTEMP=$G(BSDXMSG)
70 E D I $G(BSDXERR(1)) Q 1_U_"FileMan add to DPT error: Patient="_BSDR("PAT")_" Appt="_BSDR("ADT")
71 . N BSDXFDA,BSDXIENS,BSDXMSG
72 . S BSDXIENS="?+2,"_BSDR("PAT")_","
73 . S BSDXIENS(2)=BSDR("ADT")
74 . S BSDXFDA(2.98,BSDXIENS,.01)=BSDR("CLN")
75 . S BSDXFDA(2.98,BSDXIENS,"9")=BSDR("TYP")
76 . S BSDXFDA(2.98,BSDXIENS,"9.5")=9
77 . S BSDXFDA(2.98,BSDXIENS,"20")=$$NOW^XLFDT
78 . D UPDATE^DIE("","BSDXFDA","BSDXIENS","BSDXERR(1)")
79 ; add appt to file 44
80 K DIC,DA,X,Y,DLAYGO,DD,DO
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 ;
87 ; Sep 28 2010: Changed old style API to new style API. Keep for reference //smh
88 ;K DIC,DA,X,Y,DLAYGO,DD,DO,DINUM
89 ;S DIC="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
90 ;S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),X=BSDR("PAT")
91 ;S DIC("DR")="1///"_BSDR("LEN")_";3///"_$E($G(BSDR("OI")),1,150)_";7///`"_BSDR("USR")_";8///"_$P($$NOW^XLFDT,".")
92 ;S DIC("P")="44.003PA",DIC(0)="L",DLAYGO=44.003
93 ;D FILE^DICN
94 ;
95 N BSDXIENS S BSDXIENS="?+1,"_BSDR("ADT")_","_BSDR("CLN")_","
96 N BSDXFDA
97 S BSDXFDA(44.003,BSDXIENS,.01)=BSDR("PAT")
98 S BSDXFDA(44.003,BSDXIENS,1)=BSDR("LEN")
99 S BSDXFDA(44.003,BSDXIENS,3)=$E($G(BSDR("OI")),1,150)
100 S BSDXFDA(44.003,BSDXIENS,7)=BSDR("USR")
101 S BSDXFDA(44.003,BSDXIENS,8)=$P($$NOW^XLFDT,".")
102 N BSDXERR
103 D UPDATE^DIE("","BSDXFDA","","BSDXERR")
104 ;
105 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)
106 ;
107 ; call event driver
108 NEW DFN,SDT,SDCL,SDDA,SDMODE
109 S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2
110 S SDDA=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
111 D MAKE^SDAMEVT(DFN,SDT,SDCL,SDDA,SDMODE)
112 Q 0
113 ;
114CHECKIN1(DFN,CLIN,APDATE) ; Simplified PEP w/ parameters for $$CHECKIN - Checking in
115 ; Call like this for DFN 23435 checking in now at Hospital Location 33
116 ; for appt at Dec 20, 2009 @ 10:11:59
117 ; S RESULT=$$CHECKIN1^BSDXAPI(23435,33,3091220.221159)
118 S BSDR("PAT")=DFN ;DFN
119 S BSDR("CLN")=CLIN ;Hosp Loc IEN
120 S BSDR("ADT")=APDATE ;Appt Date
121 S BSDR("CDT")=$$NOW^XLFDT ;Check-in date defaults to now
122 S BSDR("USR")=DUZ ;Check-in user defaults to current
123 Q $$CHECKIN(.BSDR)
124 ;
125CHECKIN(BSDR) ;EP; call to add checkin info to appt; IHS/ITSC/LJF 12/23/2004 PATCH 1002
126 ;
127 ; Make call by using: S ERR=$$CHECKIN^BSDXAPI(.ARRAY)
128 ;
129 ; Input array -
130 ; BSDR("PAT") = ien of patient in file 2
131 ; BSDR("CLN") = ien of clinic in file 44
132 ; BSDR("ADT") = appt date/time
133 ; BSDR("CDT") = checkin date/time
134 ; BSDR("USR") = checkin user
135 ;
136 ; Output value -
137 ; = 0 means everything worked
138 ; = 1^message means error with reason message
139 ;
140 I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
141 I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
142 I $G(BSDR("ADT")) S BSDR("ADT")=+$E(BSDR("ADT"),1,12) ;remove seconds
143 I $G(BSDR("ADT"))'?7N1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
144 I $G(BSDR("CDT")) S BSDR("CDT")=+$E(BSDR("CDT"),1,12) ;remove seconds
145 I $G(BSDR("CDT"))'?7N1".".4N Q 1_U_"Checkin Date/Time error: "_$G(BSDR("CDT"))
146 I '$D(^VA(200,+$G(BSDR("USR")),0)) Q 1_U_"User Who Made Appt Error: "_$G(BSDR("USR"))
147 ;
148 ; find ien for appt in file 44
149 NEW IEN,DIE,DA,DR
150 S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
151 I 'IEN Q 1_U_"Error trying to find appointment for checkin: Patient="_BSDR("PAT")_" Clinic="_BSDR("CLN")_" Appt="_BSDR("ADT")
152 ;
153 ; remember before status
154 NEW SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL
155 S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2,SDDA=IEN
156 S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
157 D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
158 ;
159 ; set checkin
160 S DIE="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
161 S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
162 S DR="309///"_BSDR("CDT")_";302///`"_BSDR("USR")_";305///"_$$NOW^XLFDT
163 D ^DIE
164 ;
165 ; set after status
166 S SDDA=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
167 S SDCIHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
168 D AFTER^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCIHDL)
169 ;
170 ; call event driver
171 D EVT^SDAMEVT(.SDATA,4,SDMODE,SDCIHDL)
172 Q 0
173 ;
174CANCEL1(DFN,CLIN,TYP,APDATE,REASON,INFO) ; PEP w/ parameters for $$CANCEL - cancelling appointment
175 ; Call like this for DFN 23435 cancelling an appointment at Hospital Location 33,
176 ; cancellation initiated by patient ("PC" rather than clinic "C"),
177 ; cancelling appt at Dec 20, 2009 @ 10:11:59 because of reason 1 in file 409.2 IEN (weather)
178 ; because foxes come out during bad weather.
179 ; S RESULT=$$CANCEL1^BSDXAPI(23435,33,"PC",3091220.221159,1,"Afraid of foxes")
180 S BSDR("PAT")=DFN
181 S BSDR("CLN")=CLIN
182 S BSDR("TYP")=TYP
183 S BSDR("ADT")=APDATE
184 S BSDR("CDT")=$$NOW^XLFDT
185 S BSDR("USR")=DUZ
186 S BSDR("CR")=REASON
187 S BSDR("NOT")=INFO
188 Q $$CANCEL(.BSDR)
189 ;
190CANCEL(BSDR) ;PEP; called to cancel appt
191 ;
192 ; Make call using: S ERR=$$CANCEL^BSDXAPI(.ARRAY)
193 ;
194 ; Input Array -
195 ; BSDR("PAT") = ien of patient in file 2
196 ; BSDR("CLN") = ien of clinic in file 44
197 ; BSDR("TYP") = C for canceled by clinic; PC for patient canceled
198 ; BSDR("ADT") = appointment date and time
199 ; BSDR("CDT") = cancel date and time
200 ; BSDR("USR") = user who canceled appt
201 ; BSDR("CR") = cancel reason - pointer to file 409.2
202 ; BSDR("NOT") = cancel remarks - optional notes to 160 characters
203 ;
204 ;Output: error status and message
205 ; = 0 or null: everything okay
206 ; = 1^message: error and reason
207 ;
208 I '$D(^DPT(+$G(BSDR("PAT")),0)) Q 1_U_"Patient not on file: "_$G(BSDR("PAT"))
209 I '$D(^SC(+$G(BSDR("CLN")),0)) Q 1_U_"Clinic not on file: "_$G(BSDR("CLN"))
210 I ($G(BSDR("TYP"))'="C"),($G(BSDR("TYP"))'="PC") Q 1_U_"Cancel Status error: "_$G(BSDR("TYP"))
211 I $G(BSDR("ADT")) S BSDR("ADT")=+$E(BSDR("ADT"),1,12) ;remove seconds
212 I $G(BSDR("ADT"))'?7N1".".4N Q 1_U_"Appt Date/Time error: "_$G(BSDR("ADT"))
213 I $G(BSDR("CDT")) S BSDR("CDT")=+$E(BSDR("CDT"),1,12) ;remove seconds
214 I $G(BSDR("CDT"))'?7N1".".4N Q 1_U_"Cancel Date/Time error: "_$G(BSDR("CDT"))
215 I '$D(^VA(200,+$G(BSDR("USR")),0)) Q 1_U_"User Who Canceled Appt Error: "_$G(BSDR("USR"))
216 I '$D(^SD(409.2,+$G(BSDR("CR")))) Q 1_U_"Cancel Reason error: "_$G(BSDR("CR"))
217 ;
218 NEW IEN,DIE,DA,DR
219 S IEN=$$SCIEN(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"))
220 I 'IEN Q 1_U_"Error trying to find appointment for cancel: Patient="_BSDR("PAT")_" Clinic="_BSDR("CLN")_" Appt="_BSDR("ADT")
221 ;
222 I $$CI(BSDR("PAT"),BSDR("CLN"),BSDR("ADT"),IEN) Q 1_U_"Patient already checked in; cannot cancel until checkin deleted: Patient="_BSDR("PAT")_" Clinic="_BSDR("CLN")_" Appt="_BSDR("ADT")
223 ;
224 ; remember before status
225 NEW SDATA,DFN,SDT,SDCL,SDDA,SDCPHDL
226 S DFN=BSDR("PAT"),SDT=BSDR("ADT"),SDCL=BSDR("CLN"),SDMODE=2,SDDA=IEN
227 S SDCPHDL=$$HANDLE^SDAMEVT(1),SDATA=SDDA_U_DFN_U_SDT_U_SDCL
228 D BEFORE^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDCPHDL)
229 ;
230 ; get user who made appt and date appt made from ^SC
231 ; because data in ^SC will be deleted
232 NEW USER,DATE
233 S USER=$P($G(^SC(SDCL,"S",SDT,1,IEN,0)),U,6)
234 S DATE=$P($G(^SC(SDCL,"S",SDT,1,IEN,0)),U,7)
235 ;
236 ; update file 2 info
237 NEW DIE,DA,DR
238 S DIE="^DPT("_DFN_",""S"",",DA(1)=DFN,DA=SDT
239 S DR="3///"_BSDR("TYP")_";14///`"_BSDR("USR")_";15///"_BSDR("CDT")_";16///`"_BSDR("CR")_";19///`"_USER_";20///"_DATE
240 S:$G(BSDR("NOT"))]"" DR=DR_";17///"_$E(BSDR("NOT"),1,160)
241 D ^DIE
242 ;
243 ; delete data in ^SC
244 NEW DIK,DA
245 S DIK="^SC("_BSDR("CLN")_",""S"","_BSDR("ADT")_",1,"
246 S DA(2)=BSDR("CLN"),DA(1)=BSDR("ADT"),DA=IEN
247 D ^DIK
248 ;
249 ; call event driver
250 D CANCEL^SDAMEVT(.SDATA,DFN,SDT,SDCL,SDDA,SDMODE,SDCPHDL)
251 Q 0
252 ;
253CI(PAT,CLINIC,DATE,SDIEN) ;PEP; -- returns 1 if appt already checked-in
254 NEW X
255 S X=$G(SDIEN) ;ien sent in call
256 I 'X S X=$$SCIEN(PAT,CLINIC,DATE) I 'X Q 0
257 S X=$P($G(^SC(CLINIC,"S",DATE,1,X,"C")),U)
258 Q $S(X:1,1:0)
259 ;
260SCIEN(PAT,CLINIC,DATE) ;PEP; returns ien for appt in ^SC
261 NEW X,IEN
262 S X=0 F S X=$O(^SC(CLINIC,"S",DATE,1,X)) Q:'X Q:$G(IEN) D
263 . Q:$P($G(^SC(CLINIC,"S",DATE,1,X,0)),U,9)["C" ;cancelled
264 . I +$G(^SC(CLINIC,"S",DATE,1,X,0))=PAT S IEN=X
265 Q $G(IEN)
266 ;
267APPTYP(PAT,DATE) ;PEP; -- returns type of appt (scheduled or walk-in)
268 NEW X S X=$P($G(^DPT(PAT,"S",DATE,0)),U,7)
269 Q $S(X=3:"SCHED",X=4:"WALK-IN",1:"??")
270 ;
271CO(PAT,CLINIC,DATE,SDIEN) ;PEP; -- returns 1 if appt already checked-out
272 NEW X
273 S X=$G(SDIEN) ;ien sent in call
274 I 'X S X=$$SCIEN(PAT,CLINIC,DATE) I 'X Q 0
275 S X=$P($G(^SC(CLINIC,"S",DATE,1,X,"C")),U,3)
276 Q $S(X:1,1:0)
277 ;
Note: See TracBrowser for help on using the repository browser.