source: cprs/branches/tmg-cprs/m_files/TMGRPC5.m@ 1117

Last change on this file since 1117 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 13.0 KB
Line 
1TMGRPC5 ;TMG/kst/RPC Functions for Scheduling ;01/12/09
2 ;;1.0;TMG-LIB;**1**;01/12/09
3 ;
4 ;"TMG RPC FUNCTIONS for working with Scheduling GUI application
5 ;
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"01/12/09
9 ;"=======================================================================
10 ;" RPC -- Public Functions.
11 ;"=======================================================================
12 ;"MAKEAPPT(RESULT,PATIENT,APPT,CLINIC,MODE,INFO) -- MAKE AN APPOINTMENT
13 ;"APPTLIST(RESULT,STRTDATE,ENDDATE,FILTER,TMGMSG) --return a listing of appts
14 ;"GETAVAIL(RESULT,CLINIC,STRTDATE,ENDDATE) -- Return array with appt slot info
15 ;"SETAVAIL(RESULT,CLINIC,PATTERN,FLAGS) -- API to set availability for clinic
16 ;"CANCAPPT(RESULT,PATIENT,APPT,CLINIC,MODE,INFO)--CANCEL AN APPOINTMENT
17 ;"=======================================================================
18 ;"Dependencies:
19 ;" TMGSDAM2,TMGSDAG,TMGSDAVG,TMGSDAVS,TMGSDAU2
20 ;"=======================================================================
21 ;
22MAKEAPPT(RESULT,PATIENT,APPT,CLINIC,MODE,INFO) ;
23 ;"Purpose: MAKE AN APPOINTMENT
24 ;"INPUT: RESULTS -- PASS BY REFERENCE, an OUT PARAMETER (See values below)
25 ;" PATIENT -- Patient Name (must be unique) or IEN
26 ;" APPT -- Desired Appointment Date & Time -- External, or FM format
27 ;" CLINIC -- Name, or IEN, of Clinic for appt (file 44)
28 ;" MODE -- Mode. See STYPE in EN^TMGSDAM2() below for reference
29 ;" INFO -- PASS BY REFERENCE. See SDARRAY in EN^TMGSDAM2() below for reference
30 ;"Result: None
31 ;"Output: RESULTS variable filled as follows
32 ;" 1 = OK,APPOINTMENT SUCCESSFULLY MADE
33 ;" NEG NUMBER= ErrorNum^ErrorMessage. See also EN^TMGSDAM2() for values
34 ;
35 new UseStored set UseStored=0 ;"default
36 ;"set UseStored=1
37 if UseStored=0 do
38 . kill ^TMG("TMP","RPC","MAKEAPPT")
39 . merge ^TMG("TMP","RPC","MAKEAPPT","PATIENT")=PATIENT
40 . merge ^TMG("TMP","RPC","MAKEAPPT","APPT")=APPT
41 . merge ^TMG("TMP","RPC","MAKEAPPT","CLINIC")=CLINIC
42 . merge ^TMG("TMP","RPC","MAKEAPPT","MODE")=MODE
43 . merge ^TMG("TMP","RPC","MAKEAPPT","INFO")=INFO
44 else if UseStored=1 do
45 . merge PATIENT=^TMG("TMP","RPC","MAKEAPPT","PATIENT")
46 . merge APPT=^TMG("TMP","RPC","MAKEAPPT","APPT")
47 . merge CLINIC=^TMG("TMP","RPC","MAKEAPPT","CLINIC")
48 . merge MODE=^TMG("TMP","RPC","MAKEAPPT","MODE")
49 . merge INFO=^TMG("TMP","RPC","MAKEAPPT","INFO")
50 ;
51 KILL RESULT
52 NEW DFN,SC,APPTDATE
53 SET RESULT(0)=1 ;"Default to success.
54 SET DFN=$$GETDFN^TMGSDAU2(.PATIENT)
55 IF DFN<1 DO GOTO ENRDONE
56 . SET RESULT(0)="-1^Invalid Patient: "_$GET(PATIENT)
57 SET SC=$$GETCLIEN^TMGSDAU2(.CLINIC)
58 IF SC<1 DO GOTO ENRDONE
59 . SET RESULT(0)="-1^Can't find clinic: "_$GET(CLINIC)
60 SET APPTDATE=$$GETDATE^TMGSDAU2(.APPT)
61 IF APPTDATE<1 DO GOTO ENRDONE
62 . SET RESULT(0)="-1^Invalid appt Date: "_$GET(APPT)
63 ;
64 SET RESULT(0)=$$EN^TMGSDAM2(DFN,APPTDATE,SC,MODE,.INFO)
65 ;
66ENRDONE ;
67 QUIT
68 ;
69 ;
70APPTLIST(RESULT,STRTDATE,ENDDATE,FILTER)
71 ;"Purpose: To return a listing of appts, based on dates and filters). Provide a wrapper to $$SDAPI^SDAMA301
72 ;" that accepts data in external formats, and returns custom results in array.
73 ;"Input:RESULTS: PASS BY REFERENCE. An OUT PARAMATER. (See format below)
74 ;" STRTDATE -- Starting Date (in FMDate format, OR External format, e.g. Jan 1, 2005) (Time ignored)
75 ;" If value="I" or "" (i.e. 'indefinite'), then all dates up to End Date on returned
76 ;" ENDDATE -- OPTIONAL. Ending date (in FMDate, OR External format) (Time ignored)
77 ;" If not provided, then only dates for Starting date returned
78 ;" If value="I" (i.e. 'indefinite'), then all dates from Start Date on returned
79 ;" FILTER -- PASS BY REFERENCE. OPTIONAL. Format below. Any or all of the filters can be applied at once.
80 ;" See APPTLIST^TMGSDAG for reference
81 ;"Results: None
82 ;"Output: RESULT is filled with results. Format below:
83 ;" RESULT(0)=# of found matching appts, or 0 if none, or -1 if error.
84 ;" RESULT(Count)=-1^ErrCode^Message <-- (if any)
85 ;" RESULT(Count)=-1^ErrCode^Message
86 ;" RESULT(Count)=-1^ErrCode^Message
87 ;" RESULT(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
88 ;" RESULT(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
89 ;" RESULT(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
90 ;" NOTE: If there are no appts for time period, then one entry will be
91 ;" returned as follows. This value can be used as a place holder
92 ;" to show that a search has taken place
93 ;" RESULT(Count)="0;<NONE>^FMFormatApptDateTime"
94 ;
95 if 1=0 do
96 . kill ^TMG("TMP","RPC","APPTLIST")
97 . merge ^TMG("TMP","RPC","APPTLIST","FILTER")=FILTER
98 . merge ^TMG("TMP","RPC","APPTLIST","STRTDATE")=STRTDATE
99 . merge ^TMG("TMP","RPC","APPTLIST","ENDDATE")=ENDDATE
100 else if 0=1 do
101 . merge FILTER=^TMG("TMP","RPC","APPTLIST","FILTER")
102 . merge STRTDATE=^TMG("TMP","RPC","APPTLIST","STRTDATE")
103 . merge ENDDATE=^TMG("TMP","RPC","APPTLIST","ENDDATE")
104 ;
105 NEW TMGMSG,TMGRESULT
106 NEW COUNT SET COUNT=0
107 SET RESULT(COUNT)=$$APPTLIST^TMGSDAG(.STRTDATE,.ENDDATE,.FILTER,.TMGRESULT,.TMGMSG)
108 NEW IDX SET IDX=""
109 FOR SET IDX=$ORDER(TMGMSG(IDX)) QUIT:(IDX="") DO
110 . SET COUNT=COUNT+1
111 . SET RESULT(COUNT)=TMGMSG(IDX)
112 SET IDX=""
113 IF $DATA(TMGRESULT)=0 DO
114 . NEW TMGSTRTDT SET TMGSTRTDT=$$GETDATE^TMGSDAU2(.STRTDATE)
115 . SET COUNT=COUNT+1
116 . SET RESULT(COUNT)="0;<NONE>^"_TMGSTRTDT
117 ELSE FOR SET IDX=$ORDER(TMGRESULT(IDX)) QUIT:(IDX="") DO
118 . SET COUNT=COUNT+1
119 . SET RESULT(COUNT)=TMGRESULT(IDX)
120 QUIT
121 ;
122 ;
123GETAVAIL(RESULT,CLINIC,STRTDATE,ENDDATE)
124 ;"Purpose: Return an array with appt slot information: time, availibility
125 ;"Input:RESULTS: PASS BY REFERENCE. An OUT PARAMATER. (See format below)
126 ;" CLINIC-- Name, or IEN, of Clinic for appt (file 44)
127 ;" STRTDATE -- The beginning of the date range requested
128 ;" ENDDATE -- The end of the date range requested
129 ;"Results: None
130 ;"Output: RESULT is filled with results. Format below:
131 ;" RESULT(0)=1 for Success, 0 for Intermed success, -1^Msg for error
132 ;" RESULT(Count)=-1^Message <-- (if any)
133 ;" RESULT(Count)=-1^Message
134 ;" RESULT(Count)="INFO^APPTLEN"^LengthOfApptSlot
135 ;" RESULT(Count)=Date^SlotStartTime^NumOpenings^NumScheduled^NumTotalSlotsAtTime
136 ;" RESULT(Count)=Date^SlotStartTime^NumOpenings^NumScheduled^NumTotalSlotsAtTime
137 ;"Note: If a clinic is not set up for a given day in date range, no results will be
138 ;" returned for that invalid day.
139 ;
140 if 1=0 do
141 . kill ^TMG("TMP","RPC","GETAVAIL")
142 . merge ^TMG("TMP","RPC","GETAVAIL","CLINIC")=CLINIC
143 . merge ^TMG("TMP","RPC","GETAVAIL","STRTDATE")=STRTDATE
144 . merge ^TMG("TMP","RPC","GETAVAIL","ENDDATE")=ENDDATE
145 else if 1=0 do
146 . merge CLINIC=^TMG("TMP","RPC","GETAVAIL","CLINIC")
147 . merge STRTDATE=^TMG("TMP","RPC","GETAVAIL","STRTDATE")
148 . merge ENDDATE=^TMG("TMP","RPC","GETAVAIL","ENDDATE")
149 ;
150 NEW SC SET SC=$$GETCLIEN^TMGSDAU2(.CLINIC)
151 IF SC<1 DO GOTO GADONE
152 . SET RESULT(0)="-1^Bad clinic name: '"_$GET(CLINIC)_"'"
153 NEW TMGSTRTDT SET TMGSTRTDT=$$GETDATE^TMGSDAU2(.STRTDATE)
154 IF TMGSTRTDT<1 DO GOTO GADONE
155 . SET RESULT(0)="-1^Bad starting date: '"_$GET(TMGSTRTDT)_"'"
156 NEW TMGENDDT SET TMGENDDT=$$GETDATE^TMGSDAU2(.ENDDATE)
157 IF TMGENDDT<1 DO GOTO GADONE
158 . SET RESULT(0)="-1^Bad ending date: '"_$GET(TMGENDDT)_"'"
159 ;
160 NEW TMGAVAIL,TMGMSG
161 NEW COUNT SET COUNT=0
162 SET RESULT(COUNT)=$$GETAVAIL^TMGSDAVG(SC,TMGSTRTDT,TMGENDDT,.TMGAVAIL,.TMGMSG)
163 ;
164 NEW IDX SET IDX=""
165 FOR SET IDX=$ORDER(TMGMSG(IDX)) QUIT:(IDX="") DO
166 . SET COUNT=COUNT+1
167 . SET RESULT(COUNT)=TMGMSG(IDX)
168 NEW DATE SET DATE=""
169 FOR SET DATE=$ORDER(TMGAVAIL(DATE)) QUIT:(DATE="") DO
170 . NEW TIME SET TIME=""
171 . FOR SET TIME=$ORDER(TMGAVAIL(DATE,TIME)) QUIT:(TIME="") DO
172 . . SET COUNT=COUNT+1
173 . . SET RESULT(COUNT)=DATE_"^"_TIME_"^"_$GET(TMGAVAIL(DATE,TIME))
174GADONE ;
175 QUIT
176 ;
177 ;
178SETAVAIL(RESULT,CLINIC,FLAGS,PATTERN) ;
179 ;"Purpose: API to set availability for a given clinic
180 ;"NOTE: **See expanded notes in SETAVAIL^TMGSDAVS**
181 ;"Input: CLINIC -- IEN in HOSPITAL LOCATION file.
182 ;" FLAGS -- "D" = Delete appts (if not present then appts are SET)
183 ;" "I" = Ignore existing appts when changing slots (TO BE IMPLEMENTED)
184 ;" PATTERN -- PASS BY REFERENCE. Array Format:
185 ;" PATTERN(COUNT)=ADate^EndDate^ExtTime^ApptsPerSlot
186 ;" PATTERN(COUNT)=ADate^EndDate^ExtTime^ApptsPerSlot
187 ;" PATTERN(COUNT)=ADate^EndDate^ExtTime^ApptsPerSlot
188 ;"Results: None
189 ;"Output: RESULT is filled with results. Format below:
190 ;" RESULT(Count)=-1^ErrCode^Message <-- (if any)
191 ;" RESULT(Count)=-1^ErrCode^Message
192 ;" or RESULT(1)="1^Success"
193 ;
194 NEW SC SET SC=$$GETCLIEN^TMGSDAU2(.CLINIC)
195 IF SC<1 DO GOTO SDADONE
196 . SET RESULT(0)="-1^Bad clinic name: '"_$GET(CLINIC)_"'"
197 NEW TMGPATRN,ADATE,ENDDATE,EXTTIME,APS
198 NEW COUNT SET COUNT=""
199 FOR SET COUNT=$ORDER(PATTERN(COUNT)) DO
200 . NEW PAT SET PAT=$GET(PATTERN(COUNT)) ;"ADate^EndDate^ExtTime^ApptsPerSlot
201 . QUIT:PAT=""
202 . SET ADATE=$P(PAT,"^",1)
203 . SET ENDDATE=$P(PAT,"^",2)
204 . SET EXTTIME=$P(PAT,"^",3)
205 . SET APS=$P(PAT,"^",4)
206 . SET TMGPATRN(ADATE_"^"_ENDDATE,EXTTIME)=APS
207 ;
208 NEW TMGMSG,TEMP
209 NEW COUNT SET COUNT=0
210 SET RESULT(COUNT)=$$SETAVAIL^TMGSDAVS(SC,.TMGPATRN,FLAGS,.TMGMSG)
211 ;
212 NEW IDX SET IDX=""
213 FOR SET IDX=$ORDER(TMGMSG(IDX)) QUIT:(IDX="") DO
214 . SET COUNT=COUNT+1
215 . SET RESULT(COUNT)=TMGMSG(IDX)
216 IF COUNT=0 SET RESULT(1)="1^Success"
217SDADONE ;
218 QUIT
219 ;
220 ;
221CANCAPPT(RESULT,PATIENT,APPT,CLINIC,INFO) ;
222 ;"Purpose: CANCEL AN APPOINTMENT
223 ;"INPUT: RESULTS -- PASS BY REFERENCE, an OUT PARAMETER (See values below)
224 ;" PATIENT -- Patient Name (must be unique) or IEN
225 ;" APPT -- Appointment Date & Time to be cancelled -- External, or FM format
226 ;" CLINIC -- Name, or IEN, of Clinic for appt (file 44)
227 ;" INFO -- PASS BY REFERENCE.
228 ;" INFO("REASON IEN")= IEN of cancellation reason, from 409.2
229 ;" INFO("COMMENT") = Comment (3-160 chars length) (OPTIONAL)
230 ;"Result: None
231 ;"Output: RESULTS variable filled as follows
232 ;" RESULT(1) = 1 --> OK,APPOINTMENT SUCCESSFULLY CANCELLED
233 ;" RESULT(1) = -1^ErrorMessage.
234 ;
235 if 1=1 do
236 . kill ^TMG("TMP","RPC","CANCAPPT")
237 . merge ^TMG("TMP","RPC","CANCAPPT","PATIENT")=PATIENT
238 . merge ^TMG("TMP","RPC","CANCAPPT","APPT")=APPT
239 . merge ^TMG("TMP","RPC","CANCAPPT","CLINIC")=CLINIC
240 . merge ^TMG("TMP","RPC","CANCAPPT","INFO")=INFO
241 else if 1=0 do
242 . merge PATIENT=^TMG("TMP","RPC","CANCAPPT","PATIENT")
243 . merge APPT=^TMG("TMP","RPC","CANCAPPT","APPT")
244 . merge CLINIC=^TMG("TMP","RPC","CANCAPPT","CLINIC")
245 . merge INFO=^TMG("TMP","RPC","CANCAPPT","INFO")
246 ;
247 KILL RESULT
248 NEW DFN,SC,APPTDATE
249 SET RESULT(0)=1 ;"Default to success.
250 SET DFN=$$GETDFN^TMGSDAU2(.PATIENT)
251 IF DFN<1 DO GOTO CANCDONE
252 . SET RESULT(0)="-1^Invalid Patient: "_$GET(PATIENT)
253 SET SC=$$GETCLIEN^TMGSDAU2(.CLINIC)
254 IF SC<1 DO GOTO CANCDONE
255 . SET RESULT(0)="-1^Can't find clinic: "_$GET(CLINIC)
256 SET APPTDATE=$$GETDATE^TMGSDAU2(.APPT)
257 IF APPTDATE<1 DO GOTO CANCDONE
258 . SET RESULT(0)="-1^Invalid appt Date: "_$GET(APPT)
259 ;
260 SET RESULT(0)=$$CANCAPPT^TMGSDAC(DFN,APPTDATE,SC,.INFO)
261 ;
262CANCDONE ;
263 QUIT
Note: See TracBrowser for help on using the repository browser.