source: cprs/branches/tmg-cprs/m_files/TMGSDAG.m@ 1724

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

Initial upload

File size: 11.7 KB
Line 
1TMGSDAG ;TMG/kst/API FOR GETTING LIST OF APPTS;1/11/09
2 ;;1.0;TMG-LIB;**1**;1/11/09
3 ;
4 ;"Called into from TMGRPC5
5 ;
6 ;"=======================================================================
7 ;" API -- Public Functions.
8 ;"=======================================================================
9 ;"APPTLIST(STRTDATE,ENDDATE,FILTER,RESULTS,TMGMSG)
10 ;
11 ;"=======================================================================
12 ;"Dependancies
13 ;"=======================================================================
14 ;"SDAMA301,DIC
15 ;"=======================================================================
16 ;
17APPTLIST(STRTDATE,ENDDATE,FILTER,RESULTS,TMGMSG)
18 ;"Purpose: To return a listing of appts, based on dates and filters). Provide a wrapper to $$SDAPI^SDAMA301
19 ;" that accepts data in external formats, and returns custom results in array.
20 ;"Input:STRTDATE -- Starting Date (in FMDate format, OR External format, e.g. Jan 1, 2005) (Time ignored)
21 ;" If value="I" or "" (i.e. 'indefinite'), then all dates up to End Date on returned
22 ;" ENDDATE -- OPTIONAL. Ending date (in FMDate, OR External format) (Time ignored)
23 ;" If not provided, then only dates for Starting date returned
24 ;" If value="I" (i.e. 'indefinite'), then all dates from Start Date on returned
25 ;" FILTER -- PASS BY REFERENCE. OPTIONAL. Format below. Any or all of the filters can be applied at once.
26 ;" All filters are optional.
27 ;" 1. LOCATION FILTER: "CLINIC"
28 ;" Specify one or more clinic names or IEN's, separated by "^", so that only
29 ;" appointments for these clincs will be retuned
30 ;" e.g. FILTER("CLINIC")="TEST CLINIC"
31 ;" e.g. FILTER("CLINIC")="PULM CLINIC^GYN CLINIC"
32 ;" e.g. FILTER("CLINIC")="123" <-- IEN in file 44 (HOSPITAL LOCATION)
33 ;" e.g. FILTER("CLINIC")="123^234^345" etc.
34 ;" 2. STATUS FILTER - "STATUS"
35 ;" Specify one or more status values, separated by "^", so that only
36 ;" appointments matching these status values will be returned
37 ;" Possible codEs:
38 ;" R -- Appointment cept
39 ;" I -- Inpatient
40 ;" NS -- No Show
41 ;" NSR -- No-show, rescheduled
42 ;" CP -- Cancelled by patient
43 ;" CPR -- Cancelled by patient, rescheduled
44 ;" CC -- Cancelled by clinic
45 ;" CCR -- Cancelled by clinic, rescheduled
46 ;" NT -- No action taken
47 ;" e.g. FILTER("STATUS")="NS"
48 ;" e.g. FILTER("STATUS")="CP^CPR^I" etc.
49 ;" 3. PATIENT FILTER -- "PATIENT"
50 ;" Specify one or more Patient names (External format) or IEN's, separated by "^",
51 ;" so that only appointments for these patients will be returned.
52 ;" e.g. FILTER("PATIENT")="JONES,DAVID S"
53 ;" e.g. FILTER("PATIENT")="JONES,DAVID S^SMITH,JOHN A" etc.
54 ;" e.g. FILTER("PATIENT")="123456" <-- IEN in PATIENT file
55 ;" e.g. FILTER("PATIENT")="123456^234567^345678" etc.
56 ;" 4. STOP CODES FILTER -- "STOP CODE"
57 ;" Specify one or more valid Primary Stop Code values (not IEN's), separated by "^",
58 ;" so that only appointments matching these values will be returned.
59 ;" Stop Code must be a valied AMIS REPORTING STOP CODE (field #1) on the CLINIC STOP file (#40.7)
60 ;" e.g. FILTER("STOP CODE")="197" <-- STOP CODE, not IEN
61 ;" e.g. FILTER("STOP CODE")="197^234^345"
62 ;" 5. QUANTITY FILTER -- "MAX"
63 ;" Specify a value, such that only the first N appts will be returned. If specified, then must
64 ;" be whole value > 0
65 ;" e.g. FILTER("MAX")=25 <-- Only return 1st 25 found appts
66 ;" NOTE: The $$SDAPI^SDAMA301 seems to support more filters. I could add support for them later...
67 ;" RESULTS: PASS BY REFERENCE. An OUT PARAMATER.
68 ;" RESULTS(Count)=RESULTS(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
69 ;" RESULTS(Count)=RESULTS(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
70 ;" RESULTS(Count)=RESULTS(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
71 ;" TMGMSG: PASS BY REFERENCE. An OUT PARAMETER -- Used for passing back errors.
72 ;" TMGMSG=Max count of error messages
73 ;" TMGMSG(Count)=ErrCode^Message (Count starts at 1,2,3...)
74 ;" TMGMSG(Count)=ErrCode^Message
75 ;" TMGMSG(Count)=ErrCode^Message
76 ;"Results: Returns # of found matching appts, or 0 if none, or -1 if error.
77 ;
78 NEW TMGRESULT SET TMGRESULT=0
79 SET TMGMSG=0
80 NEW TMGSDATE,TMGEDATE,TMGARRAY
81 KILL RESULTS
82 DO SETDATES(.STRTDATE,.ENDDATE,.TMGARRAY,.TMGMSG)
83 IF TMGMSG>0 SET TMGRESULT=-1 GOTO ALDONE
84 ;
85 IF $DATA(FILTER("CLINIC")) DO FILTR2(.FILTER,.TMGARRAY,.TMGMSG)
86 IF $DATA(FILTER("STATUS")) DO FILTR3(.FILTER,.TMGARRAY,.TMGMSG)
87 IF $DATA(FILTER("PATIENT")) DO FILTR4(.FILTER,.TMGARRAY,.TMGMSG)
88 IF $DATA(FILTER("STOP CODE")) DO FILTR13(.FILTER,.TMGARRAY,.TMGMSG)
89 IF TMGMSG>0 SET TMGRESULT=-1 GOTO ALDONE
90 ;
91 SET TMGARRAY("FLDS")="1;2;3"
92 SET TMGARRAY("SORT")="P" ;"Specify output format"
93 SET TMGRESULT=$$SDAPI^SDAMA301(.TMGARRAY)
94 IF TMGRESULT<0 DO
95 . DO HANDLERR(.TMGMSG)
96 ELSE DO GETRSLTS(.RESULTS)
97 ;
98ALDONE QUIT TMGRESULT
99 ;
100 ;
101SETDATES(TMGSDATE,TMGEDATE,TMGARRAY,TMGMSG)
102 ;"Purpose: convert external dates into internal format, Validate dates,
103 ;" and insert into TMGARRAY(1) filter
104 ;"Result: None
105 NEW DATE1,DATE2
106 SET TMGSDATE=$GET(TMGSDATE)
107 SET TMGEDATE=$GET(TMGEDATE)
108 IF TMGEDATE="" SET TMGEDATE=TMGSDATE
109 IF +TMGSDATE=TMGSDATE SET DATE1=TMGSDATE
110 ELSE DO GOTO:TMGMSG>0 SDDONE
111 . IF (TMGSDATE="I")!(TMGSDATE="") SET DATE1="" QUIT
112 . NEW MSG
113 . DO DT^DILF("T",TMGSDATE,.MSG)
114 . IF MSG=-1 DO QUIT
115 . . SET TMGMSG=TMGMSG+1
116 . . SET TMGMSG(TMGMSG)="-1^Invalid Start Date"
117 . SET DATE1=MSG\1
118 IF +TMGEDATE=TMGEDATE SET DATE2=TMGEDATE
119 ELSE DO
120 . IF (TMGEDATE="I")!(TMGEDATE="") SET DATE2="" QUIT
121 . NEW MSG
122 . DO DT^DILF("T",TMGEDATE,.MSG)
123 . IF MSG=-1 DO QUIT
124 . . SET TMGMSG=+$GET(TMGMSG)+1
125 . . SET TMGMSG(TMGMSG)="-1^Invalid End Date"
126 . SET DATE2=MSG\1
127 IF (DATE1="")&(DATE2="") GOTO SDDONE
128 SET DATE1=DATE1\1
129 SET DATE2=DATE2\1
130 SET TMGARRAY(1)=DATE1_";"_DATE2
131SDDONE ;
132 QUIT
133 ;
134 ;
135FILTR2(FILTER,TMGARRAY,TMGMSG)
136 ;"Purpose: To take and validate user input, and insert into TMGARRAY(2) filter
137 ;
138 NEW PLACES SET PLACES=$GET(FILTER("CLINIC"))
139 NEW LOC,STR
140 SET STR=""
141 FOR SET LOC=$PIECE(PLACES,"^",1) QUIT:(LOC="") DO
142 . IF +LOC'=LOC DO
143 . . NEW DIC,X,Y
144 . . SET DIC=44,DIC(0)="M"
145 . . SET X=LOC DO ^DIC
146 . . IF +Y>0 SET LOC=+Y
147 . . ELSE DO
148 . . . SET TMGMSG=+$GET(TMGMSG)+1
149 . . . SET TMGMSG(TMGMSG)="-1^'"_LOC_"' clinic location NOT FOUND."
150 . IF LOC>0 DO
151 . . IF STR'="" SET STR=STR_";"
152 . . SET STR=STR_LOC
153 . IF $LENGTH(PLACES,"^")=1 SET PLACES="" QUIT
154 . ELSE SET PLACES=$PIECE(PLACES,2,$LENGTH(PLACES,"^"))
155 IF STR'="" SET TMGARRAY(2)=STR
156 ;
157F2DONE QUIT
158 ;
159 ;
160FILTR3(FILTER,TMGARRAY,TMGMSG)
161 ;"Purpose: To take user input, and insert into TMGARRAY(3) filter
162 NEW STR SET STR=$GET(FILTER("STATUS"))
163 SET STR=$TRANSLATE(STR,"^",";")
164 IF STR'="" SET TMGARRAY(3)=STR
165 QUIT
166 ;
167 ;
168FILTR4(FILTER,TMGARRAY,TMGMSG)
169 ;"Purpose: To take and validate user input, and insert into TMGARRAY(4) filter
170 ;
171 NEW NAMES SET NAMES=$GET(FILTER("PATIENT"))
172 NEW ANAME,STR,DFN
173 SET STR=""
174 FOR SET ANAME=$PIECE(NAMES,"^",1) QUIT:(ANAME="") DO
175 . SET DFN=0
176 . IF +ANAME'=ANAME DO
177 . . NEW TMG2MSG
178 . . DO FIND^DIC(2,,".01","MP",ANAME,"*","","","","TMG2MSG")
179 . . NEW NUM SET NUM=+$GET(TMG2MSG("DILIST",0))
180 . . IF NUM=0 DO QUIT
181 . . . SET TMGMSG=+$GET(TMGMSG)+1
182 . . . SET TMGMSG(TMGMSG)="-1^Patient name: '"_ANAME_"' NOT FOUND"
183 . . IF NUM>1 DO QUIT
184 . . . SET TMGMSG=+$GET(TMGMSG)+1
185 . . . SET TMGMSG(TMGMSG)="-1^Name: "_ANAME_" Not specific. Multiple patients with this name exist."
186 . . SET DFN=+$GET(TMG2MSG("DILIST",1,0))
187 . IF DFN>0 DO
188 . . IF STR'="" SET STR=STR_";"
189 . . SET STR=STR_DFN
190 . IF $LENGTH(NAMES,"^")=1 SET NAMES="" QUIT
191 . ELSE SET NAMES=$PIECE(NAMES,2,$LENGTH(NAMES,"^"))
192 IF STR'="" SET TMGARRAY(4)=STR
193 ;
194F4DONE QUIT
195 ;
196 ;
197FILTR13(FILTER,TMGARRAY,TMGMSG)
198 ;"Purpose: To take user input, and insert into TMGARRAY(13) filter
199 NEW STR SET STR=$GET(FILTER("STOP CODE"))
200 SET STR=$TRANSLATE(STR,"^",";")
201 IF STR'="" SET TMGARRAY(13)=STR
202 QUIT
203 ;
204 ;
205HANDLERR(TMGMSG)
206 ;"Purpose: repackage errors into format for this function
207 ;"
208 NEW CODE SET CODE=0
209 FOR SET CODE=$ORDER(^TMG($J,"SDAMA301",CODE)) QUIT:(CODE="") DO
210 . NEW DESCR SET DESCR=$GET(^TMG($J,"SDAMA301",CODE))
211 . SET TMGMSG=+$GET(TMGMSG)+1
212 . SET TMGMSG(TMGMSG)=CODE_"^"_DESCR
213 QUIT
214 ;
215 ;
216GETRSLTS(RESULTS)
217 ;"Purpose: To repackage results into format for this function
218 ;"Input: RESULTS -- PASS BY REFERENCE. An OUT PARAMETER.
219 ;"Output: RESULTS(Count)=PatientIEN;PatientName^DOB^FMFormatApptDateTime;ExtFormatApptDateTime^ClinicIEN;ClinicName^StatusCode;StatusName
220 KILL RESULTS
221 NEW COUNT SET COUNT=0
222 NEW DFN SET DFN=0
223 FOR SET DFN=$ORDER(^TMP($J,"SDAMA301",DFN)) QUIT:(DFN="") DO
224 . NEW NAME SET NAME=$PIECE($GET(^DPT(DFN,0)),"^",1)
225 . NEW STR SET STR=DFN_";"_NAME
226 . NEW DOB SET DOB=$PIECE($GET(^DPT(DFN,0)),"^",3)
227 . SET DOB=$PIECE($$FMTE^XLFDT(DOB,+5),"@",1)
228 . SET STR=STR_"^"_DOB
229 . NEW APPT SET APPT=""
230 . FOR SET APPT=$ORDER(^TMP($J,"SDAMA301",DFN,APPT)) QUIT:(APPT="") DO
231 . . NEW VALUE SET VALUE=$GET(^TMP($J,"SDAMA301",DFN,APPT)) QUIT:VALUE=""
232 . . NEW TIME SET TIME=$$FMTE^XLFDT(APPT,+5) ;"+5 = MM/DD/YYYY@HH:MM:SS format
233 . . SET $PIECE(VALUE,"^",1)=APPT_";"_TIME
234 . . SET VALUE=STR_"^"_VALUE
235 . . SET COUNT=COUNT+1
236 . . SET RESULTS(COUNT)=VALUE
237 ;
238 QUIT
Note: See TracBrowser for help on using the repository browser.