source: cprs/branches/tmg-cprs/m_files/TMGRPCS0.m@ 1687

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

Initial upload

File size: 11.7 KB
Line 
1TMGRPCS0 ;TMG/kst/RPC entry points for Search API ; 6/4/10
2 ;;1.0;TMG-LIB;**1**;05/25/10
3 ;
4 ;"RPC ENTRY POINTS FOR TMG FILEMAN SEARCH API
5 ;
6 ;"Copyright Kevin Toppenberg MD 5/25/10
7 ;"Released under GNU General Public License (GPL)
8 ;"
9 ;"NOTE: this function depends on new version of LIST^DIC, from G. Timpson Patch
10 ;"=======================================================================
11 ;" RPC -- Public Functions.
12 ;"=======================================================================
13 ;"LAUNCH(OUT,PARAMS) -- launch background search thread, return JOB #
14 ;"STATUS(OUT,JOBNUM) --Return status of background job.
15 ;"IENLIST(OUT,JOBNUM) -- Return results from background search job.
16 ;"IENDETAL(OUT,TMGPARAMS) -- Return Detail of 1 IEN from from results from background search job.
17 ;"CLEAR(OUT,JOBNUM) -- Clear data from background search job.
18 ;"
19 ;"=======================================================================
20 ;"PRIVATE API FUNCTIONS
21 ;"=======================================================================
22 ;"
23 ;"=======================================================================
24 ;"=======================================================================
25 ;"Dependencies:
26 ;" ^DIQ, ^XLFSTR, ^TMGSRCH
27 ;"=======================================================================
28 ;"=======================================================================
29 ;
30TEST ;
31 NEW STR,OUT
32 ;"SET STR="8925:(STATUS=COMPLETED)&((PATIENT[CUTSHALL)!(PATIENT[CUTSHAW))"
33 ;"SET STR="8925:(REPORT TEXT[DM-2)!(REPORT TEXT[HTN) AND 120.5:((VITAL TYPE=PULSE)&(RATE>70))"
34 ;"SET STR="8925:(REPORT TEXT[DM-2) AND 120.5:((VITAL TYPE=PULSE)&(RATE>70))"
35 ;"SET STR="8925:(REPORT TEXT[DM-2)!(REPORT TEXT[HTN)"
36 SET STR="8925:(REPORT TEXT[HTN) AND 120.5:((VITAL TYPE=PULSE)&(RATE{70..75))"
37 NEW RESULT
38 DO LAUNCH(.RESULT,"2^"_STR)
39 SET JOBNUM=+$GET(RESULT(0))
40 FOR DO QUIT:(STATUS["#DONE#")
41 . HANG 1
42 . DO STATUS(.STATUS,JOBNUM)
43 . WRITE "STATUS: ",STATUS,!
44 DO IENLIST(.OUT,JOBNUM) ;
45 IF $DATA(OUT) ZWR OUT
46 DO PRESSTOCONT^TMGUSRIF
47 QUIT
48 ;
49LAUNCH(OUT,TMGPARAM) ;
50 ;"Purpose: to launch background search thread, and return its JOB number
51 ;"Input: OUT -- Passed by REFERENCE. A single value
52 ;" TMGPARAM -- Filenumber^SearchString
53 ;" Filenumber -- The file number to search for
54 ;" SearchStr -- The logic string. See docs in TMGSRCH.m
55 ;"Output: OUT=Job# or -1^Message
56 ;"Results: None
57 NEW FILENUM SET FILENUM=$PIECE(TMGPARAM,"^",1)
58 NEW SRCHSTR SET SRCHSTR=$PIECE(TMGPARAM,"^",2)
59 JOB BKSRCH^TMGSRCH(FILENUM,SRCHSTR)
60 SET OUT(0)="1^"_$ZJOB
61 QUIT
62 ;
63STATUS(OUT,JOBNUM) ;
64 ;"Purpose: Return status of background job.
65 ;"Input: OUT -- Passed by REFERENCE. A single value
66 ;" JOBNUM -- The job number of task to query
67 ;"Output: OUT(0)=1^%Done^Message. Will be '100^#DONE#' when task is done.
68 ;"Results: None
69 NEW REF SET REF=$NAME(^TMP("TMG","TMGSRCH",JOBNUM))
70 NEW PCT SET PCT=$GET(@REF@("PCT"))
71 NEW MSG SET MSG=$GET(@REF@("MSG"))
72 NEW CNT SET CNT=$GET(@REF@("OUT","COUNT"))
73 SET OUT(0)="1^"_PCT_"^"_MSG_"^"_CNT
74 QUIT
75 ;
76IENLIST(OUT,TMGPARAM) ;
77 ;"Purpose: Return IEN LIST from results from background search job.
78 ;" NOTE: This should not be called until STATUS() returns #DONE#
79 ;"Input: OUT -- Passed by REFERENCE. And out array
80 ;" TMGPARAM -- JOBNUM^FLDNUM
81 ;" JOBNUM = The job number of task to query
82 ;" FLDNUM = The desired field number. OPTIONAL. Default is none
83 ;"Output: OUT(0)=status
84 ;" OUT(index)=IEN^[VALUE] <-- Value is external value of FLD
85 ;" OUT(index)=IEN^[VALUE] <-- Value is external value of FLD
86 ;"Results: None
87 NEW JOBNUM SET JOBNUM=+$PIECE(TMGPARAM,"^",1)
88 NEW TMGFLD SET TMGFLD=+$PIECE(TMGPARAM,"^",2)
89 NEW REF SET REF=$NAME(^TMP("TMG","TMGSRCH",JOBNUM))
90 NEW TMGFNUM SET TMGFNUM=+$GET(@REF@("OUT","FILENUM"))
91 NEW I SET I=1
92 NEW IEN SET IEN=0
93 IF (TMGFLD>0),(TMGFNUM>0) GOTO IL2 ;"Handle differently
94 ;"------------------------------------
95 FOR SET IEN=$ORDER(@REF@("OUT",IEN)) QUIT:(+IEN'>0) DO
96 . NEW VALUE SET VALUE=""
97 . IF (TMGFLD>0),(TMGFNUM>0) SET VALUE=$$GET1^DIQ(TMGFNUM,IEN_",",TMGFLD)
98 . SET OUT(I)=IEN_"^"_VALUE
99 . SET I=I+1
100 GOTO ILDN
101 ;"------------------------------------
102IL2 ;"Sort by FLD value, not IEN value
103 NEW TEMP,VALUE
104 FOR SET IEN=$ORDER(@REF@("OUT",IEN)) QUIT:(+IEN'>0) DO
105 . SET VALUE=$$GET1^DIQ(TMGFNUM,IEN_",",TMGFLD)
106 . SET TEMP(VALUE,IEN)=""
107 SET VALUE=""
108 FOR SET VALUE=$ORDER(TEMP(VALUE)) QUIT:(VALUE="") DO
109 . SET IEN=0 FOR SET IEN=$ORDER(TEMP(VALUE,IEN)) QUIT:(IEN="") DO
110 . . SET OUT(I)=IEN_"^"_VALUE
111 . . SET I=I+1
112 ;"------------------------------------
113ILDN IF $DATA(OUT)=0 SET OUT(0)="-1^NO RESULTS"
114 ELSE SET OUT(0)="1^Success"
115 QUIT
116 ;
117PREPSB(OUT,TMGPARAMS) ;"Prep Subset
118 ;"Purpose: Prepare an array that can be used by an TORComboBox.NeedData
119 ;" to return a subset of the results.
120 ;" NOTE: This should not be called until STATUS() returns #DONE#
121 ;"Input: OUT -- Passed by REFERENCE. And out array
122 ;" TMGPARAM -- JOBNUM^Field[;FLD[;FLD...]]
123 ;" JOBNUM = The job number of task to query
124 ;" Field... = The desired field number(s). OPTIONAL. DEFAULT is .01
125 ;" If more than one supplied, then output is
126 ;" concatinated. Separate fieldnumbers with ';'
127 ;"Output: OUT(0)=1^Success or -1^Message
128 ;"Results: None
129 NEW JOBNUM SET JOBNUM=+$PIECE(TMGPARAMS,"^",1)
130 NEW TMGFLDS SET TMGFLDS=$PIECE(TMGPARAMS,"^",2)
131 IF TMGFLDS="" SET TMGFLDS=".01"
132 NEW REF SET REF=$NAME(^TMP("TMG","TMGSRCH",JOBNUM))
133 NEW TMGFNUM SET TMGFNUM=+$GET(@REF@("OUT","FILENUM"))
134 IF TMGFNUM'>0 DO GOTO PREPDN
135 . SET OUT(0)="-1^Unable to find file number at "_$NAME(@REF@("OUT","FILENUM"))
136 NEW IEN SET IEN=0
137 NEW VALUE
138 NEW TMGERR SET TMGERR=0
139 FOR SET IEN=$ORDER(@REF@("OUT",IEN)) QUIT:(+IEN'>0)!TMGERR DO
140 . SET VALUE=""
141 . NEW I FOR I=1:1:$LENGTH(TMGFLDS,";") DO
142 . . NEW TMG1FLD SET TMG1FLD=+$PIECE(TMGFLDS,";",I) QUIT:TMG1FLD'>0
143 . . SET VALUE=VALUE_$$GET1^DIQ(TMGFNUM,IEN_",",TMG1FLD,,"TMGERR")_" "
144 . . IF $DATA(TMGERR("DIERR")) DO
145 . . . SET TMGERR=1
146 . . . SET TMGERR("MSG")=$$GetErrStr^TMGDEBUG(.TMGERR)
147 . SET VALUE=$$TRIM^XLFSTR(VALUE)
148 . QUIT:VALUE=""
149 . SET @REF@("B",VALUE,IEN)=""
150 ;"------------------------------------
151 IF TMGERR SET OUT(0)="-1^"_$GET(TMGERR("MSG"))
152 IF $DATA(@REF@("B"))=0 SET OUT(0)="-1^NO RESULTS"
153 ELSE SET OUT(0)="1^Success"
154PREPDN QUIT
155 ;
156IENDETAL(OUT,TMGPARAMS) ;
157 ;"Purpose: Return Detail of 1 IEN from from results from background search job.
158 ;" NOTE: This should not be called until STATUS() returns #DONE#
159 ;" Example: Imagine that a search has been made for a PATIENT with
160 ;" an associated TIU DOCUMENT containing "HTN". The primary
161 ;" goal of the search is to get the IEN of the found PATIENT(s)
162 ;" However, after finding this patient, one might want to be
163 ;" able to reference the particular TIU DOCUMENTS leading to
164 ;" the match. That is the purpose of this function. So, in
165 ;" the parameters below, the input IEN would be the IEN in
166 ;" the PATIENT file, and the output would include the file
167 ;" number for TIU DOCUMENT, and the IEN's of the entries in
168 ;" this file that lead to the final results
169 ;"Input: OUT -- Passed by REFERENCE. And out array
170 ;" TMGPARAM -- JobNum^IEN
171 ;" JOBNUM -- The job number of task to query
172 ;" IEN -- The End Search IEN
173 ;"Output: OUT(0)=status
174 ;" OUT(index)=FileNum^IENInFile^.01Value
175 ;" OUT(index)=FileNum^IENInFile^.01Value
176 ;" OUT(index)=FileNum^IENInFile^.01Value
177 ;"Results: None
178 NEW JOBNUM SET JOBNUM=+$PIECE($GET(TMGPARAMS),"^",1)
179 IF JOBNUM=0 DO GOTO IEDDN
180 . SET OUT(0)="-1^Invalid Job Number."
181 NEW SRCHIEN SET SRCHIEN=+$PIECE($GET(TMGPARAMS),"^",2)
182 IF SRCHIEN=0 DO GOTO IEDDN
183 . SET OUT(0)="-1^Invalid IEN Number."
184 NEW REF SET REF=$NAME(^TMP("TMG","TMGSRCH",JOBNUM,"OUT","DETAILS",SRCHIEN))
185 NEW I SET I=1
186 NEW FNUM SET FNUM=0
187 FOR SET FNUM=$ORDER(@REF@(FNUM)) QUIT:(+FNUM'>0) DO
188 . NEW SUPIEN SET SUPIEN=0
189 . FOR SET SUPIEN=$ORDER(@REF@(FNUM,SUPIEN)) QUIT:(+SUPIEN'>0) DO
190 . . NEW VALUE SET VALUE=$GET(@REF@(FNUM,SUPIEN))
191 . . IF VALUE="" DO
192 . . . SET VALUE=$$GET1^DIQ(FNUM,SUPIEN_",",.01)
193 . . . SET @REF@(FNUM,SUPIEN)=VALUE
194 . . SET OUT(I)=FNUM_"^"_SUPIEN_"^"_VALUE
195 . . SET I=I+1
196 IF $DATA(OUT)=0 SET OUT(0)="-1^NO RESULTS"
197 ELSE SET OUT(0)="1^Success"
198IEDDN QUIT
199 ;
200GETRSLTSB(TMGOUT,TMGPARAMS) ;
201 ;"Purpose: Get RESULTS list subset, for job number. NOTE: This should
202 ;" only be called after a successful call to PREPSB^TMGRPCS0()
203 ;" which will prepair the list.
204 ;"Input: TMGPARAMS -- JobNum^ListStartValue^direction^MaxCount(optional, def=44)
205 ;" JobNum -- this is job number of results to return.
206 ;" ListStartValue -- OPTIONAL -- text to $ORDER() from
207 ;" Direction -- $ORDER(xx,Direction) direction (should be 1 or -1) -- OPTIONAL
208 ;" MaxCount -- OPTIONAL. Default is 44 values returned.
209 ;"Output: TMGRESULTS is filled as follows.
210 ;" TMGRESULT(0)="1^Success" or "-1^Message"
211 ;" TMGRESULT(1)=IENNum^RequestedFieldNames
212 ;" TMGRESULT(2)=IENNum^RequestedFieldNames
213 ;"NOTE: Any files that don't have data are excluded. Subfiles also excluded
214 ;
215 NEW JOBNUM SET JOBNUM=+$PIECE(TMGPARAMS,"^",1)
216 IF JOBNUM'>0 DO GOTO GAFSDN
217 . SET TMGOUT(0)="-1^No Job Number Supplied"
218 NEW TMGFROM SET TMGFROM=$PIECE(TMGPARAMS,"^",2)
219 NEW TMGDIR SET TMGDIR=$PIECE(TMGPARAMS,"^",3)
220 IF TMGDIR'=-1 SET TMGDIR=1
221 NEW TMGMAXCT SET TMGMAXCT=+$PIECE(TMGPARAMS,"^",4)
222 IF TMGMAXCT=0 SET TMGMAXCT=44
223 ;
224 NEW TMGREF SET TMGREF=$NAME(^TMP("TMG","TMGSRCH",JOBNUM))
225 NEW TMGI SET TMGI=0
226 FOR SET TMGFROM=$ORDER(@TMGREF@("B",TMGFROM),TMGDIR) QUIT:(TMGFROM="")!(TMGI'<TMGMAXCT) DO
227 . NEW TMGIEN SET TMGIEN=""
228 . FOR SET TMGIEN=$ORDER(@TMGREF@("B",TMGFROM,TMGIEN),TMGDIR) QUIT:(+TMGIEN'>0)!(TMGI'<TMGMAXCT) DO
229 . . SET TMGI=TMGI+1
230 . . SET TMGOUT(TMGI)=TMGIEN_"^"_TMGFROM
231 ;
232 IF $DATA(TMGOUT)=0 SET TMGOUT(0)="-1^NO RESULTS"
233 ELSE SET TMGOUT(0)="1^Success"
234GAFSDN QUIT
235 ;
236CLEAR(OUT,JOBNUM) ;
237 ;"Purpose: Clear results from background search job.
238 ;"Output: OUT(0)=1^Success"
239 ;"Results: None
240 NEW REF SET REF=$NAME(^TMP("TMG","TMGSRCH",JOBNUM))
241 KILL @REF
242 SET OUT(0)="1^Success"
243 QUIT
244 ;
Note: See TracBrowser for help on using the repository browser.