source: cprs/branches/tmg-cprs/m_files/TMGRPC1.m.bak@ 796

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

Initial upload

File size: 51.4 KB
Line 
1TMGRPC1 ;TMG/kst-RPC Functions ;03/25/06
2 ;;1.0;TMG-LIB;**1**;08/18/09
3
4 ;"TMG RPC FUNCTIONS
5
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"3/24/07
9
10 ;"=======================================================================
11 ;" RPC -- Public Functions.
12 ;"=======================================================================
13 ;"DOWNLOAD(GREF,FPATH,FNAME,LOCIEN)
14 ;"UPLOAD(RESULT,FPATH,FNAME,LOCIEN,ARRAY)
15 ;"DOWNDROP(RESULT,FPATH,FNAME,LOCIEN) -- Download drop box file
16 ;"UPLDDROP(RESULT,FPATH,FNAME,LOCIEN) -- Upload Dropbox File
17 ;"GETLONG(GREF,IMAGEIEN)
18 ;"GETDFN(RESULT,RECNUM,RECFIELD,LNAME,FNAME,MNAME,DOB,SEX,SSNUM)
19 ;"BLANKTIU(RESULT,DFN,PERSON,LOC,DOS,TITLE)
20 ;"AUTOSIGN(RESULT,DOCIEN)
21 ;"FNINFO(RESULT,DFN) -- GET PATIENT DEMOGRAPHICS
22 ;"PTADD(RESULT,INFO) -- ADD PATIENT
23 ;"STPTINFO(RESULT,DFN,INFO) -- SET PATIENT DEMOGRAPHICS
24 ;"GETURLS(RESULT) -- TMG CPRS GET URL LIST
25
26 ;"=======================================================================
27 ;"PRIVATE API FUNCTIONS
28 ;"=======================================================================
29 ;"ENCODE(GRef,incSubscr,encodeFn)
30 ;"DECODE(GRef,incSubscr,decodeFn)
31 ;"$$HEXCODER(INPUT) ;"encode the input string. Currently using simple hex encoding/
32 ;"$$B64CODER(INPUT) ;"encode the input string via UUENCODE (actually Base64)
33 ;"$$B64DECODER(INPUT) ;"encode the input string via UUDECODE (actually Base64)
34
35 ;"=======================================================================
36 ;"=======================================================================
37 ;"Dependencies:
38 ;"TMGBINF
39 ;"TMGSTUTL
40 ;"RGUTUU
41 ;"=======================================================================
42 ;"=======================================================================
43
44DOWNLOAD(GREF,FPATH,FNAME,LOCIEN)
45 ;"SCOPE: Public
46 ;"Purpose: To provide an entry point for a RPC call from a client. The client
47 ;" will ask for a given file, and it will be passed back in the form
48 ;" of an array (in BASE64 ascii encoding)
49 ;"Input: GREF -- OUT PARAM -- the array to pass the result back in (PASSED BY REFERENCE)
50 ;" FPATH -- the file path up to, but not including, the filename
51 ;" Use '/' to NOT specify any subdirectory
52 ;" FNAME -- the name of the file to pass back
53 ;" LOCIEN-- [optional] -- the IEN from file 2005.2 (network location) to download from
54 ;" default value is 1
55 ;" Note: For security reasons, all path requests will be considered relative to a root path.
56 ;" e.g. if user asks for /download/SomeFile.jpg, this function will retrieve:
57 ;" /var/local/Dir1/Dir2/download/SomeFile.jpg
58 ;" This root path is found in custom field 22701 in file 2005.2
59 ;"Output: results are passed out in @GREF
60 ;" @GREF@(0)=success; 1=success, 0=failure
61 ;" @GREF@(1..xxx) = actual data
62
63 set FPATH=$get(FPATH)
64 set FNAME=$get(FNAME)
65 set LOCIEN=$GET(LOCIEN,1)
66
67 new PathRoot
68 set PathRoot=$piece($get(^MAG(2005.2,LOCIEN,22700)),"^",1) ;"NOTE: CUSTOM FIELD
69
70 new NodeDiv
71 set NodeDiv=$piece($get(^MAG(2005.2,LOCIEN,22701),"/"),"^",1) ;"default is "/" NOTE: CUSTOM FIELD
72
73 new EndRoot set EndRoot=$extract(PathRoot,$length(PathRoot))
74 new StartPath set StartPath=$extract(FPATH,1)
75
76 if (EndRoot=NodeDiv)&(StartPath=NodeDiv) do
77 . set FPATH=$extract(FPATH,2,1024)
78 else if (EndRoot'=NodeDiv)&(StartPath'=NodeDiv) do
79 . set PathRoot=PathRoot_NodeDiv
80
81 set FPATH=PathRoot_FPATH
82
83 set GREF="^TMP(""DOWNLOAD^TMGRPC1"","_$J_")"
84
85 kill @GREF
86 set @GREF@(0)=$$BFTG^TMGBINF(.FPATH,.FNAME,$name(@GREF@(1)),3)
87
88 do ENCODE($name(@GREF@(1)),3)
89
90 quit
91
92
93UPLOAD(RESULT,FPATH,FNAME,LOCIEN,ARRAY)
94 ;"SCOPE: Public
95 ;"RPC That calls this: TMG UPLOAD FILE
96 ;"Purpose: To provide an entry point for a RPC call from a client. The client
97 ;" will provide a file for upload (in BASE64 ascii encoding)
98 ;"Input: GREF -- OUT PARAM -- the array to pass the result back in (PASSED BY REFERENCE)
99 ;" FPATH -- the file path up to, but not including, the filename
100 ;" Use '/' to NOT specify any subdirectory
101 ;" FNAME -- the name of the file to pass back
102 ;" LOCIEN-- [optional] -- the IEN from file 2005.2 (network location) to upload to
103 ;" default value is 1
104 ;" Note: For security reasons, all path requests will be considered relative to a root path.
105 ;" e.g. if user asks for /download/SomeFile.jpg, this function will retrieve:
106 ;" /var/local/Dir1/Dir2/download/SomeFile.jpg
107 ;" This root path is found in custom field 22701 in file 2005.2
108 ;" ARRAY -- the array that will hold the file, in BASE64 ascii encoding
109 ;"Output: results are passed out in RESULT: 1^SuccessMessage or 0^FailureMessage
110
111 new result
112 new resultMsg set resultMsg="1^Successful Upload"
113
114 set ^TMP("UPLOAD^TMGRPC1",$J,"FPATH")=$GET(FPATH)
115 set ^TMP("UPLOAD^TMGRPC1",$J,"FNAME")=$GET(FNAME)
116 set ^TMP("UPLOAD^TMGRPC1",$J,"LOCIEN")=$GET(LOCIEN)
117
118 if $data(ARRAY)=0 set resultMsg="0^No data received to upload" goto UpDone
119 set FPATH=$get(FPATH)
120 if FPATH="" set resultMsg="0^No file path received" goto UpDone
121 set FNAME=$get(FNAME)
122 if FNAME="" set resultMsg="0^No file name received" goto UpDone
123 set LOCIEN=$GET(LOCIEN,1);
124 new GREF
125
126 new PathRoot
127 set PathRoot=$piece($get(^MAG(2005.2,LOCIEN,22700)),"^",1)
128
129 new NodeDiv
130 set NodeDiv=$piece($get(^MAG(2005.2,LOCIEN,22701),"/"),"^",1) ;"default is "/"
131
132 new EndRoot set EndRoot=$extract(PathRoot,$length(PathRoot))
133 new StartPath set StartPath=$extract(FPATH,1)
134 if (EndRoot=NodeDiv)&(StartPath=NodeDiv) do
135 . set FPATH=$extract(FPATH,2,1024)
136 else if (EndRoot'=NodeDiv)&(StartPath'=NodeDiv) do
137 . set PathRoot=PathRoot_NodeDiv
138
139 set FPATH=PathRoot_FPATH
140
141 merge ^TMP("UPLOAD^TMGRPC1",$J,"ENCODED")=ARRAY ;"//TEMP
142 do DECODE("ARRAY(0)",1)
143 merge ^TMP("UPLOAD^TMGRPC1",$J,"DECODED")=ARRAY ;"//TEMP
144
145 if $$GTBF^TMGBINF("ARRAY(0)",1,FPATH,FNAME)=0 do
146 . set resultMsg="0^Error while saving file"
147
148UpDone
149 set RESULT=resultMsg
150 quit
151
152
153DOWNDROP(RESULT,FPATH,FNAME,LOCIEN) ;"i.e. Download drop box file
154 ;"SCOPE: Public
155 ;"RPC That calls this: TMG DOWNLOAD FILE DROPBOX
156 ;"Purpose: To provide an entry point for a RPC call from a client. The client
157 ;" will request for the file to be placed into in a 'dropbox' file
158 ;" location that both the client and server can access. File may be
159 ;" moved from there to its final destination by the client.
160 ;" This method alloows file-hiding ability on the server side.
161 ;"Input: RESULT -- OUT PARAM -- the array to pass the result back in (PASSED BY REFERENCE)
162 ;" FPATH -- the file path up to, but not including, the filename. This
163 ;" is the path that the file is stored at (relative to a root path,
164 ;" see comments below). It is NOT the path of the dropbox.
165 ;" Use '/' to NOT specify any subdirectory
166 ;" FNAME -- the name of the file to be uploaded. Note: This is also the
167 ;" name of the file to be put into the dropbox. It is the
168 ;" responsibility of the client to ensure that there is not already
169 ;" a similarly named file in the dropbox before requesting a file
170 ;" be put there. It is the responsibility of the client to delete
171 ;" the file from the drop box.
172 ;" LOCIEN-- [optional] -- the IEN from file 2005.2 (network location) to download from
173 ;" default value is 1
174 ;" Note: For security reasons, all path requests will be considered relative to a root path.
175 ;" e.g. if user asks for /download/SomeFile.jpg, this function will retrieve:
176 ;" /var/local/Dir1/Dir2/download/SomeFile.jpg
177 ;" This root path is found in custom field 22701 in file 2005.2
178 ;" Also: dropbox location is obtained from custom field 22702 in file 2005.2
179 ;"NOTE RE DROPBOX:
180 ;" This system is designed for a system where by the server and the client have a
181 ;" shared filesystem, but the directory paths will be different. For example:
182 ;" Linux server has dropbox at: /mnt/WinServer/dropbox/
183 ;" Windows Client has access to dropbox at: V:\Dropbox\
184
185 ;"Output: results are 1^Success, or 0^Error Message
186
187 new resultMsg set resultMsg="1^Successful Download"
188
189 set FPATH=$get(FPATH)
190 if FPATH="" set resultMsg="0^No file path received" goto DnDBxDone
191 set FNAME=$get(FNAME)
192 if FNAME="" set resultMsg="0^No file name received" goto DnDBxDone
193 set LOCIEN=$GET(LOCIEN,1);
194 new GREF
195
196 new PathRoot
197 set PathRoot=$piece($get(^MAG(2005.2,LOCIEN,22700)),"^",1)
198
199 new NodeDiv
200 set NodeDiv=$piece($get(^MAG(2005.2,LOCIEN,22701),"/"),"^",1) ;"default is "/"
201
202 new DropBox
203 set DropBox=$piece($get(^MAG(2005.2,LOCIEN,22702)),"^",1)
204 if DropBox="" do goto UpDBxDone
205 . set resultMsg="0^Dropbox location not configured in file 2005.2, IEN "_LOCIEN_", field 22702"
206 ;"Ensure DropBox ends in a node divider
207 if $extract(DropBox,$length(DropBox))'=NodeDiv do
208 . set DropBox=DropBox_NodeDiv
209
210 ;"Ensure PathRoot ends in a node divider
211 if $extract(PathRoot,$length(PathRoot))'=NodeDiv do
212 . set PathRoot=PathRoot_NodeDiv
213
214 ;"Ensure Fpath does NOT start in a node divider
215 if $extract(FPATH,1)=NodeDiv do
216 . set FPATH=$extract(FPATH,2,1024)
217
218 set FPATH=PathRoot_FPATH
219
220 new SrcNamePath set SrcNamePath=FPATH_FNAME
221 ;"new DestNamePath set DestNamePath=DropBox_FNAME
222
223 new moveResult
224 set moveResult=$$Copy^TMGKERNL(SrcNamePath,DropBox)
225 if moveResult>0 do
226 . set resultMsg="0^Move failed, returning OS error code: "_moveResult
227
228DnDBxDone
229 set RESULT=resultMsg
230 quit
231
232
233UPLDDROP(RESULT,FPATH,FNAME,LOCIEN) ;"i.e. Upload Dropbox File
234 ;"SCOPE: Public
235 ;"RPC That calls this: TMG UPLOAD FILE DROPBOX
236 ;"Purpose: To provide an entry point for a RPC call from a client. The client
237 ;" will put the file in a 'dropbox' file location that both the client
238 ;" and server can access. File will be moved from there to its final
239 ;" destination. This will provide file-hiding ability on the server side.
240 ;"Input: RESULT -- OUT PARAM -- the array to pass the result back in (PASSED BY REFERENCE)
241 ;" FPATH -- the file path up to, but not including, the filename. This
242 ;" is the path to store the file at. (relative to a root path,
243 ;" see comments below). It is NOT the path of the dropbox.
244 ;" Use '/' to NOT specify any subdirectory
245 ;" FNAME -- the name of the file to be uploaded. Note: This is also the
246 ;" name of the file to be pulled from the dropbox. It is the
247 ;" responsibility of the client to ensure that there is not already
248 ;" a similarly named file in the dropbox before depositing a file there.
249 ;" The server will remove the file from the dropbox, unless there is
250 ;" an error with the host OS (which will be returned as an error message)
251 ;" LOCIEN-- [optional] -- the IEN from file 2005.2 (network location) to upload to
252 ;" default value is 1
253 ;" Note: For security reasons, all path requests will be considered relative to a root path.
254 ;" e.g. if user asks for /download/SomeFile.jpg, this function will retrieve:
255 ;" /var/local/Dir1/Dir2/download/SomeFile.jpg
256 ;" This root path is found in custom field 22700 in file 2005.2
257 ;" Also: dropbox location is obtained from custom field 22702 in file 2005.2
258 ;"NOTE RE DROPBOX:
259 ;" This system is designed for a system where by the server and the client have a
260 ;" shared filesystem, but the directory paths will be different. For example:
261 ;" Linux server has dropbox at: /mnt/WinServer/dropbox/
262 ;" Windows Client has access to dropbox at: V:\Dropbox\
263
264 ;"Output: results are passed out in RESULT:
265 ;" 1^SuccessMessage or 0^FailureMessage
266
267 new result
268 new resultMsg set resultMsg="1^Successful Upload"
269
270 set FPATH=$get(FPATH)
271 if FPATH="" set resultMsg="0^No file path received" goto UpDBxDone
272 set FNAME=$get(FNAME)
273 if FNAME="" set resultMsg="0^No file name received" goto UpDBxDone
274 set LOCIEN=$GET(LOCIEN,1);
275 new GREF
276
277 new PathRoot
278 set PathRoot=$piece($get(^MAG(2005.2,LOCIEN,22700)),"^",1)
279
280 new NodeDiv
281 set NodeDiv=$piece($get(^MAG(2005.2,LOCIEN,22701),"/"),"^",1) ;"default is "/"
282
283 new DropBox
284 set DropBox=$piece($get(^MAG(2005.2,LOCIEN,22702)),"^",1)
285 if DropBox="" do goto UpDBxDone
286 . set resultMsg="0^Dropbox location not configured in file 2005.2, IEN "_LOCIEN_", field 22702"
287 ;"Ensure DropBox ends in a node divider
288 if $extract(DropBox,$length(DropBox))'=NodeDiv do
289 . set DropBox=DropBox_NodeDiv
290
291 ;"Ensure PathRoot ends in a node divider
292 if $extract(PathRoot,$length(PathRoot))'=NodeDiv do
293 . set PathRoot=PathRoot_NodeDiv
294
295 ;"Ensure Fpath does NOT start in a node divider
296 if $extract(FPATH,1)=NodeDiv do
297 . set FPATH=$extract(FPATH,2,1024)
298
299 set FPATH=PathRoot_FPATH
300
301 new SrcNamePath,DestNamePath
302 set SrcNamePath=DropBox_FNAME
303 set DestNamePath=FPATH_FNAME
304
305 new moveResult
306 set moveResult=$$Move^TMGKERNL(SrcNamePath,DestNamePath)
307 if moveResult>0 do
308 . set resultMsg="0^Move failed, returning OS error code: "_moveResult
309
310UpDBxDone
311 set RESULT=resultMsg
312 quit
313
314
315ENCODE(GRef,incSubscr,encodeFn)
316 ;"Purpose: ENCODE a BINARY GLOBAL.
317 ;"Input:
318 ;" GRef-- Global reference of the SOURCE binary global array, in fully resolved
319 ;" (closed root) format.
320 ;" Note:
321 ;" At least one subscript must be numeric. This will be the incrementing
322 ;" subscript (i.e. the subscript that $$BIN2WP^TMGBINWP will increment
323 ;" to store each new global node). This subscript need not be the final
324 ;" subscript. For example, to load into a WORD PROCESSING field, the
325 ;" incrementing node is the second-to-last subscript; the final subscript
326 ;" is always zero.
327 ;" REQUIRED
328 ;" incSubscr-- (required) Identifies the incrementing subscript level, for the source global
329 ;" For example, if you pass ^TMP(115,1,1,0) as the global_ref parameter and
330 ;" pass 3 as the inc_subscr parameter, $$BIN2GBL will increment the third
331 ;" subscript, such as ^TMP(115,1,x), but will WRITE notes at the full global
332 ;" reference, such as ^TMP(115,1,x,0).
333 ;" REQUIRED
334 ;" encodeFn- (OPTIONAL) the name of a function that will encode a line of data.
335 ;" e.g. "CODER^ZZZCODER" or "LOCALCODER". The function should
336 ;" take one input variable (the line of raw binary data), and return a converted
337 ;" line. e.g.
338 ;" CODER(INPUT)
339 ;" ... ;"convert INPUT to RESULT
340 ;" QUIT RESULT
341 ;" default value is B64CODER^TMGRPC1
342 ;"
343 ;"Output: @GRef is converted to encoded data
344 ;"Result: None
345
346 if $get(GRef)="" goto EncodeDone
347 if $get(incSubscr)="" goto EncodeDone
348
349 set encodeFn=$get(encodeFn,"B64CODER")
350
351 new encoder
352 set encoder="set temp=$$"_encodeFn_"(.temp)"
353
354 for do quit:(GRef="")
355 . new temp
356 . set temp=$get(@GRef)
357 . if temp="" set GRef="" quit
358 . xecute encoder ;"i.e. set temp=$$encoderFn(.temp)
359 . set @GRef=temp
360 . set GRef=$$NEXTNODE^TMGBINF(GRef,incSubscr,1,1)
361
362EncodeDone
363 quit
364
365
366HEXCODER(INPUT)
367 ;"Purpose: to encode the input string. Currently using simple hex encoding/
368 quit $$STRB2H^TMGSTUTL(.INPUT,0,1)
369
370
371B64CODER(INPUT)
372 ;"Purpose: to encode the input string via UUENCODE (actually Base64)
373 quit $$ENCODE^RGUTUU(.INPUT)
374
375B64DECODER(INPUT)
376 ;"Purpose: to encode the input string via UUENCODE (actually Base64)
377 quit $$DECODE^RGUTUU(.INPUT)
378
379
380DECODE(GRef,incSubscr,decodeFn)
381 ;"Purpose: ENCODE a BINARY GLOBAL.
382 ;"Input:
383 ;" GRef-- Global reference of the SOURCE binary global array, in fully resolved
384 ;" (closed root) format.
385 ;" Note:
386 ;" At least one subscript must be numeric. This will be the incrementing
387 ;" subscript (i.e. the subscript that $$BIN2WP^TMGBINWP will increment
388 ;" to store each new global node). This subscript need not be the final
389 ;" subscript. For example, to load into a WORD PROCESSING field, the
390 ;" incrementing node is the second-to-last subscript; the final subscript
391 ;" is always zero.
392 ;" REQUIRED
393 ;" incSubscr-- (required) Identifies the incrementing subscript level, for the source global
394 ;" For example, if you pass ^TMP(115,1,1,0) as the global_ref parameter and
395 ;" pass 3 as the inc_subscr parameter, $$BIN2GBL will increment the third
396 ;" subscript, such as ^TMP(115,1,x), but will WRITE notes at the full global
397 ;" reference, such as ^TMP(115,1,x,0).
398 ;" REQUIRED
399 ;" decodeFn- (OPTIONAL) the name of a function that will decode a line of data.
400 ;" e.g. "DECODER^ZZZCODER" or "DECODER". The function should take
401 ;" one input variable (the line of encoded data), and return a decoded line. e.g.
402 ;" DECODER(INPUT)
403 ;" ... ;"convert INPUT to RESULT
404 ;" QUIT RESULT
405 ;" default value is B64DECODER^TMGRPC1
406 ;"
407 ;"Output: @GRef is converted to decoded data
408 ;"Result: None
409
410 if $get(GRef)="" goto DecodeDone
411 if $get(incSubscr)="" goto DecodeDone
412 set decodeFn=$get(decodeFn,"B64DECODER")
413
414 new decoder
415 set decoder="set temp=$$"_decodeFn_"(.temp)"
416
417 for do quit:(GRef="")
418 . new temp
419 . set temp=$get(@GRef)
420 . if temp="" set GRef="" quit
421 . xecute decoder ;"i.e. set temp=$$decoderFn(.temp)
422 . set @GRef=temp
423 . set GRef=$$NEXTNODE^TMGBINF(GRef,incSubscr,1,1)
424
425DecodeDone
426 quit
427
428
429GETLONG(GREF,IMAGEIEN)
430 ;"SCOPE: Public
431 ;"Purpose: To provide an entry point for a RPC call from a client.
432 ;" Will return results of field 11 (LONG DESCRIPTION) from file IMAGE(2005)
433 ;"Input: GREF -- OUT PARAM -- the array to pass the result back in (PASSED BY REFERENCE)
434 ;" IMAGEIEN-- The IEN (record number) from file 2005 (IMAGE)
435 ;"Output: results are passed out in @GREF
436 ;" @GREF@(0) = WP header line: format is: ^^MaxLine^MaxLine^TimeStamp(FM Date/Time Format)
437 ;" @GREF@(1) = WP line 1
438 ;" @GREF@(2) = WP line 2
439 ;" @GREF@(3) = WP line 3
440 ;" @GREF@(4) = WP line 4 ... etc.
441
442 set GREF="^TMP(""GETLONG^TMGRPC1"","_$J_")"
443
444 kill @GREF
445
446 new i,s,MaxLines,header
447 set header=""
448 if +$get(IMAGEIEN)>0 do
449 . set header=$get(^MAG(2005,IMAGEIEN,3,0)) ;"NOTE: Field 11 held in node 3;0
450 set @GREF@(0)=header
451 set MaxLines=+$piece(header,"^",3)
452 for i=1:1:MaxLines do
453 . set @GREF@(i)=$get(^MAG(2005,IMAGEIEN,3,i,0))
454
455 quit
456
457
458
459GETDFN(RESULT,RECNUM,PMS,FNAME,LNAME,MNAME,DOB,SEX,SSNUM,AUTOADD)
460 ;"Purpose: This is a RPC entry point for looking up a patient.
461 ;"Input:
462 ;" RESULT -- an OUT PARAMETER
463 ;" RECNUM -- Record number from a PMS
464 ;" PMS -- Which PMS RECNUM refers to (1=Medic,2=Sequel,3=Paradigm)
465 ;" FNAME -- First Name
466 ;" LNAME -- Last name
467 ;" MNAME -- Middle Name or initial
468 ;" DOB -- Date of birth in EXTERNAL format
469 ;" SEX -- Patient sex: M or F
470 ;" SSNUM -- Social security number (digits only)
471 ;" AUTOADD -- Automatically register patient if needed (if value=1)
472 ;"Output: Patient may be added to database if AUTOADD=1
473 ;"Results: Returns DFN (i.e. IEN in PATIENT file) or -1 if not found or error
474
475 new Patient,TMGFREG
476 set RESULT=-1 ;"default to not found
477
478 if $get(LNAME)'="" do
479 . set Patient("NAME")=$get(LNAME)
480 . if $get(FNAME)'="" set Patient("NAME")=Patient("NAME")_","_FNAME
481 . if $get(MNAME)'="" set Patient("NAME")=Patient("NAME")_" "_MNAME
482 set Patient("DOB")=$get(DOB)
483 set Patient("SEX")=$get(SEX)
484 set Patient("SSNUM")=$get(SSNUM)
485test if $get(AUTOADD)=1 set TMGFREG=1
486
487 if $get(PMS)=1 set Patient("PATIENTNUM")=$get(RECNUM) ;" <-- Medic account number
488 if $get(PMS)=2 set Patient("SEQUELNUM")=$get(RECNUM) ;" <-- Sequel or other account number
489 if $get(PMS)=3 set Patient("PARADIGMNUM")=$get(RECNUM) ;" <-- Paradigm or other account number
490
491 ;"temp
492 ;"merge ^TMG("TMP","GETDFN","KILLLATER")=Patient
493 ;"set ^TMG("TMP","GETDFN","KILLLATER","FNAME")=FNAME
494 ;"set ^TMG("TMP","GETDFN","KILLLATER","LNAME")=LNAME
495 ;"set ^TMG("TMP","GETDFN","KILLLATER","MNAME")=MNAME
496
497 set RESULT=$$GetDFN^TMGGDFN(.Patient)
498
499 quit
500
501
502BLANKTIU(RESULT,DFN,PERSON,LOC,DOS,TITLE)
503 ;"Purpose: To create a new, blank TIU note and return it's IEN
504 ;"Input: DFN -- IEN in PATIENT file of patient
505 ;" PERSON -- Provider NAME
506 ;" LOC -- Location for new document
507 ;" DOS -- Date of Service
508 ;" TITLE -- Title of new document
509 ;"Results: IEN in file 8925 is returned in RESULT,
510 ;" or -1^ErrMsg1;ErrMsg2... if failure
511 ;"Note: This functionality probably duplicates that of RPC call:
512 ;" TIU CREATE NOTE -- found after writing this...
513
514 new Document,Flag
515
516 set Document("DFN")=DFN
517 set Document("PROVIDER IEN")=$$GetProvIEN^TMGPUTN0(PERSON)
518 set Document("LOCATION")=$get(LOC)
519 set Document("DATE")=$get(DOS)
520 set Document("TITLE")=$get(TITLE)
521 set Document("TRANSCRIPTIONIST")=""
522 set Document("CHARACTER COUNT - TRANSCRIPTIONIST'S")=0
523
524 set RESULT=$$PrepDoc^TMGPUTN0(.Document)
525 if +RESULT>0 do ;"change capture method from Upload (default) to RPC
526 . new TMGFDA,TMGMSG
527 . set TMGFDA(8925,RESULT_",",1303)="R" ;"1303 = capture method. "R" = RPC
528 . do FILE^DIE("E","TMGFDA","TMGMSG") ;"ignore any errors.
529 else do
530 . new i,ErrMsg set ErrMsg=""
531 . for i=1:1:+$get(Document("ERROR","NUM")) do
532 . . set ErrMsg=ErrMsg_$get(Document("ERROR",i))_" ||"
533 . if $data(Document("ERROR","FM INFO"))>0 do
534 . . new ref set ref="Document(""ERROR"",""FM INFO"")"
535 . . set ErrMsg=ErrMsg_"FILEMAN SAYS:"
536 . . for set ref=$query(@ref) quit:(ref="")!(ref'["FM INFO") do
537 . . . if ErrMsg'="" set ErrMsg=ErrMsg_" ||"
538 . . . set ErrMsg=ErrMsg_$piece(ref,"DIERR",2)_"="_$get(@ref)
539 . if ErrMsg="" set ErrMsg="Unknown error"
540 . set ErrMsg=$translate(ErrMsg,"^","@")
541 . set $piece(RESULT,"^",2)=ErrMsg
542
543 ;"temp
544 merge ^TMG("TMP","BLANKTIU","RESULT")=RESULT
545 merge ^TMG("TMP","BLANKTIU","Document")=Document
546
547
548 quit
549
550
551AUTOSIGN(RESULT,DOCIEN)
552 ;"Purpose: To automatically sign TIU note (8925).
553 ;"Input: DOCIEN -- the IEN in 8925 of the file to be automatically signed.
554 ;"Note: This function will not succeed unless field 1303 holds "R"
555 ;" and an Author found for note
556 ;"Results: Results passed back in RESULT(0) ARRAY
557 ;" -1 = failure. 1= success
558 ;" Any error message is passed back in RESULT("DIERR")
559 ;"Note: This differs from RPC CALL: TIU SIGN RECORD in that a signiture
560 ;" code is NOT required
561
562 new TMGFDA,TMGMSG
563 new AuthorIEN,AuthorName
564 new CaptureMethod
565
566 set DOCIEN=+$get(DOCIEN)
567 set RESULT=-1 ;"default to failure
568
569 set CaptureMethod=$piece($get(^TIU(8925,DOCIEN,13)),"^",3)
570 if CaptureMethod'="R" do goto ASDone
571 . set RESULT("DIERR")="Unable to auto-sign. Upload-Method was not 'R'."
572 set AuthorIEN=$piece($get(^TIU(8925,DOCIEN,12)),"^",2)
573 if AuthorIEN'>0 do goto ASDone
574 . set RESULT("DIERR")="Unable to find author of document."
575 set AuthorName=$piece($get(^VA(200,AuthorIEN,0)),"^",1)
576
577 set TMGFDA(8925,DOCIEN_",",.05)="COMPLETED" ;"field .05 = STATUS
578 set TMGFDA(8925,DOCIEN_",",1501)="NOW" ;"field 1501 = Signed date
579 set TMGFDA(8925,DOCIEN_",",1502)="`"_AuthorIEN ;"field 1502 = signed by
580 set TMGFDA(8925,DOCIEN_",",1503)=AuthorName ;"field 1503 = Signature block name
581 set TMGFDA(8925,DOCIEN_",",1504)="[Scanned image auto-signed]" ;"field 1504 = Signature block title
582 set TMGFDA(8925,DOCIEN_",",1505)="C" ;C=Chart ;"field 1505 = Signature mode
583 do FILE^DIE("E","TMGFDA","TMGMSG")
584 if $data(TMGMSG("DIERR")) do goto ASDone
585 . merge RESULT("DIERR")=TMGMSG("DIERR")
586
587 set RESULT(0)=1 ;"set success if we got this far.
588ASDone
589 quit
590
591
592DFNINFO(RESULT,DFN)
593 ;"Purpose: To return array with demographcs details about patient
594 ;"Input: RESULT (this is the output array)
595 ;" DFN : The record number in file #2 of the patient to inquire about.
596 ;"Results: Results passed back in RESULT array. Format as follows:
597 ;" The results are in format: KeyName=Value,
598 ;" There is no set order these will appear.
599 ;" Here are the KeyName names that will be provided.
600 ;" If the record has no value, then value will be empty
601 ;" IEN=record#
602 ;" COMBINED_NAME=
603 ;" LNAME=
604 ;" FNAME=
605 ;" MNAME=
606 ;" PREFIX=
607 ;" SUFFIX=
608 ;" DEGREE
609 ;" DOB=
610 ;" SEX=
611 ;" SS_NUM=
612 ;" ADDRESS_LINE_1=
613 ;" ADDRESS_LINE_2=
614 ;" ADDRESS_LINE_3=
615 ;" CITY=
616 ;" STATE=
617 ;" ZIP4=
618 ;" BAD_ADDRESS=
619 ;" TEMP_ADDRESS_LINE_1=
620 ;" TEMP_ADDRESS_LINE_2=
621 ;" TEMP_ADDRESS_LINE_3=
622 ;" TEMP_CITY=
623 ;" TEMP_STATE=
624 ;" TEMP_ZIP4=
625 ;" TEMP_STARTING_DATE=
626 ;" TEMP_ENDING_DATE=
627 ;" TEMP_ADDRESS_ACTIVE=
628 ;" CONF_ADDRESS_LINE_1=
629 ;" CONF_ADDRESS_LINE_2=
630 ;" CONF_ADDRESS_LINE_3=
631 ;" CONF_CITY=
632 ;" CONF_STATE=
633 ;" CONF_ZIP4=
634 ;" CONF_STARTING_DATE=
635 ;" CONF_ENDING_DATE=
636 ;" CONF_ADDRESS_ACTIVE=
637 ;" PHONE_RESIDENCE=
638 ;" PHONE_WORK=
639 ;" PHONE_CELL=
640 ;" PHONE_TEMP=
641
642 ;"Note, for the following, there may be multiple entries. # is record number
643 ;" ALIAS # NAME
644 ;" ALIAS # SSN
645
646 new TMGFDA,TMGMSG,IENS
647 set IENS=""
648 new ptrParts set ptrParts=0
649 set DFN=+$get(DFN)
650 if DFN>0 do
651 . set ptrParts=+$piece($get(^DPT(DFN,"NAME")),"^",1) ;"ptr to file #20, NAME COMPONENTS
652 . set IENS=DFN_","
653 . do GETS^DIQ(2,IENS,"**","N","TMGFDA","TMGMSG")
654
655 new line set line=0
656 set RESULT(line)="IEN="_DFN set line=line+1
657 set RESULT(line)="COMBINED_NAME="_$get(TMGFDA(2,IENS,.01)) set line=line+1
658 new s set s=""
659 if ptrParts>0 set s=$get(^VA(20,ptrParts,1))
660 set RESULT(line)="LNAME="_$piece(s,"^",1) set line=line+1
661 set RESULT(line)="FNAME="_$piece(s,"^",2) set line=line+1
662 set RESULT(line)="MNAME="_$piece(s,"^",3) set line=line+1
663 set RESULT(line)="PREFIX="_$piece(s,"^",4) set line=line+1
664 set RESULT(line)="SUFFIX="_$piece(s,"^",5) set line=line+1
665 set RESULT(line)="DEGREE="_$piece(s,"^",5) set line=line+1
666 set RESULT(line)="DOB="_$get(TMGFDA(2,IENS,.03)) set line=line+1
667 set RESULT(line)="SEX="_$get(TMGFDA(2,IENS,.02)) set line=line+1
668 set RESULT(line)="SS_NUM="_$get(TMGFDA(2,IENS,.09)) set line=line+1
669 set RESULT(line)="EMAIL="_$get(TMGFDA(2,IENS,.133)) set line=line+1
670 set RESULT(line)="ADDRESS_LINE_1="_$get(TMGFDA(2,IENS,.111)) set line=line+1
671 set RESULT(line)="ADDRESS_LINE_2="_$get(TMGFDA(2,IENS,.112)) set line=line+1
672 set RESULT(line)="ADDRESS_LINE_3="_$get(TMGFDA(2,IENS,.113)) set line=line+1
673 set RESULT(line)="CITY="_$get(TMGFDA(2,IENS,.114)) set line=line+1
674 set RESULT(line)="STATE="_$get(TMGFDA(2,IENS,.115)) set line=line+1
675 if $get(TMGFDA(2,IENS,.1122))'="" do
676 . set RESULT(line)="ZIP4="_$get(TMGFDA(2,IENS,.1122)) set line=line+1
677 else if $get(TMGFDA(2,IENS,.1116))'="" do
678 . set RESULT(line)="ZIP4="_$get(TMGFDA(2,IENS,.1116)) set line=line+1
679 set RESULT(line)="BAD_ADDRESS="_$get(TMGFDA(2,IENS,.121)) set line=line+1
680 set RESULT(line)="TEMP_ADDRESS_LINE_1="_$get(TMGFDA(2,IENS,.1211)) set line=line+1
681 set RESULT(line)="TEMP_ADDRESS_LINE_2="_$get(TMGFDA(2,IENS,.1212)) set line=line+1
682 set RESULT(line)="TEMP_ADDRESS_LINE_3="_$get(TMGFDA(2,IENS,.1213)) set line=line+1
683 set RESULT(line)="TEMP_CITY="_$get(TMGFDA(2,IENS,.1214)) set line=line+1
684 set RESULT(line)="TEMP_STATE="_$get(TMGFDA(2,IENS,.1215)) set line=line+1
685 set RESULT(line)="TEMP_ZIP4="_$get(TMGFDA(2,IENS,.1216)) set line=line+1
686 set RESULT(line)="TEMP_STARTING_DATE="_$get(TMGFDA(2,IENS,.1217)) set line=line+1
687 set RESULT(line)="TEMP_ENDING_DATE="_$get(TMGFDA(2,IENS,.1218)) set line=line+1
688 set RESULT(line)="TEMP_ADDRESS_ACTIVE="_$get(TMGFDA(2,IENS,.12105)) set line=line+1
689 set RESULT(line)="CONF_ADDRESS_LINE_1="_$get(TMGFDA(2,IENS,.1411)) set line=line+1
690 set RESULT(line)="CONF_ADDRESS_LINE_1="_$get(TMGFDA(2,IENS,.1412)) set line=line+1
691 set RESULT(line)="CONF_ADDRESS_LINE_1="_$get(TMGFDA(2,IENS,.1413)) set line=line+1
692 set RESULT(line)="CONF_CITY="_$get(TMGFDA(2,IENS,.1414)) set line=line+1
693 set RESULT(line)="CONF_STATE="_$get(TMGFDA(2,IENS,.1415)) set line=line+1
694 set RESULT(line)="CONF_ZIP4="_$get(TMGFDA(2,IENS,.1416)) set line=line+1
695 set RESULT(line)="CONF_STARTING_DATE="_$get(TMGFDA(2,IENS,.1417)) set line=line+1
696 set RESULT(line)="CONF_ENDING_DATE="_$get(TMGFDA(2,IENS,.1418)) set line=line+1
697 set RESULT(line)="CONF_ADDRESS_ACTIVE="_$get(TMGFDA(2,IENS,.14105)) set line=line+1
698 set RESULT(line)="PHONE_RESIDENCE="_$get(TMGFDA(2,IENS,.131)) set line=line+1
699 set RESULT(line)="PHONE_WORK="_$get(TMGFDA(2,IENS,.132)) set line=line+1
700 set RESULT(line)="PHONE_CELL="_$get(TMGFDA(2,IENS,.134)) set line=line+1
701 set RESULT(line)="PHONE_TEMP="_$get(TMGFDA(2,IENS,.1219)) set line=line+1
702
703 ;"the GETS doesn't return ALIAS entries, so will do manually:
704 new Itr,IEN
705 set IEN=$$ItrInit^TMGITR(2.01,.Itr,DFN_",")
706 if IEN'="" for do quit:(+$$ItrNext^TMGITR(.Itr,.IEN)'>0)
707 . new s set s=$get(^DPT(DFN,.01,IEN,0))
708 . if s="" quit
709 . set RESULT(line)="ALIAS "_IEN_" NAME="_$piece(s,"^",1) set line=line+1
710 . set RESULT(line)="ALIAS "_IEN_" SSN="_$piece(s,"^",2) set line=line+1
711 . ;"maybe later do something with NAME COMPONENTS in Alias.
712
713 quit
714
715
716STPTINFO(RESULT,DFN,INFO) ;" SET PATIENT INFO
717 ;"Purpose: To set demographcs details about patient
718 ;"Input: RESULT (this is the output array)
719 ;" DFN : The record number in file #2 of the patient to inquire about.
720 ;" INFO: Format as follows:
721 ;" The results are in format: INFO("KeyName")=Value,
722 ;" There is no set order these will appear.
723 ;" Here are the KeyName names that will be provided.
724 ;" If the record has no value, then value will be empty
725 ;" If a record should be deleted, its value will be @
726 ;" INFO("COMBINED_NAME")=
727 ;" INFO("PREFIX")=
728 ;" INFO("SUFFIX")=
729 ;" INFO("DEGREE")=
730 ;" INFO("DOB")=
731 ;" INFO("SEX")=
732 ;" INFO("SS_NUM")=
733 ;" INFO("ADDRESS_LINE_1")=
734 ;" INFO("ADDRESS_LINE_2")=
735 ;" INFO("ADDRESS_LINE_3")=
736 ;" INFO("CITY")=
737 ;" INFO("STATE")=
738 ;" INFO("ZIP4")=
739 ;" INFO("BAD_ADDRESS")=
740 ;" INFO("TEMP_ADDRESS_LINE_1")=
741 ;" INFO("TEMP_ADDRESS_LINE_2")=
742 ;" INFO("TEMP_ADDRESS_LINE_3")=
743 ;" INFO("TEMP_CITY")=
744 ;" INFO("TEMP_STATE")=
745 ;" INFO("TEMP_ZIP4")=
746 ;" INFO("TEMP_STARTING_DATE")=
747 ;" INFO("TEMP_ENDING_DATE")=
748 ;" INFO("TEMP_ADDRESS_ACTIVE")=
749 ;" INFO("CONF_ADDRESS_LINE_1")=
750 ;" INFO("CONF_ADDRESS_LINE_2")=
751 ;" INFO("CONF_ADDRESS_LINE_3")=
752 ;" INFO("CONF_CITY")=
753 ;" INFO("CONF_STATE")=
754 ;" INFO("CONF_ZIP4")=
755 ;" INFO("CONF_STARTING_DATE")=
756 ;" INFO("CONF_ENDING_DATE")=
757 ;" INFO("CONF_ADDRESS_ACTIVE")=
758 ;" INFO("PHONE_RESIDENCE")=
759 ;" INFO("PHONE_WORK")=
760 ;" INFO("PHONE_CELL")=
761 ;" INFO("PHONE_TEMP")=
762 ;"Note, for the following, there may be multiple entries. # is record number
763 ;" If a record should be added, it will be marked +1, +2 etc.
764 ;" INFO("ALIAS # NAME")=
765 ;" INFO("ALIAS # SSN")=
766 ;"
767 ;"Results: Results passed back in RESULT string:
768 ;" 1 = success
769 ;" -1^Message = failure
770
771 set RESULT=1 ;"default to success
772
773 ;"kill ^TMG("TMP","RPC")
774 ;"merge ^TMG("TMP","RPC")=INFO ;"temp... remove later
775
776 new TMGFDA,TMGMSG,IENS
777 set IENS=DFN_","
778 new key set key=""
779 for set key=$order(INFO(key)) quit:(key="") do
780 . if key="COMBINED_NAME" set TMGFDA(2,IENS,.01)=INFO("COMBINED_NAME")
781 . else if +key=key set TMGFDA(2,IENS,key)=INFO(key)
782 . else if key="DOB" set TMGFDA(2,IENS,.03)=INFO("DOB")
783 . else if key="SEX" set TMGFDA(2,IENS,.02)=INFO("SEX")
784 . else if key="SS_NUM" set TMGFDA(2,IENS,.09)=INFO("SS_NUM")
785 . else if key="ADDRESS_LINE_1" set TMGFDA(2,IENS,.111)=INFO("ADDRESS_LINE_1")
786 . else if key="ADDRESS_LINE_2" set TMGFDA(2,IENS,.112)=INFO("ADDRESS_LINE_2")
787 . else if key="ADDRESS_LINE_3" set TMGFDA(2,IENS,.113)=INFO("ADDRESS_LINE_3")
788 . else if key="CITY" set TMGFDA(2,IENS,.114)=INFO("CITY")
789 . else if key="STATE" set TMGFDA(2,IENS,.115)=INFO("STATE")
790 . else if key="ZIP4" set TMGFDA(2,IENS,.1112)=INFO("ZIP4")
791 . else if key="BAD_ADDRESS" set TMGFDA(2,IENS,.121)=INFO("BAD_ADDRESS")
792 . else if key="TEMP_ADDRESS_LINE_1" set TMGFDA(2,IENS,.1211)=INFO("TEMP_ADDRESS_LINE_1")
793 . else if key="TEMP_ADDRESS_LINE_2" set TMGFDA(2,IENS,.1212)=INFO("TEMP_ADDRESS_LINE_2")
794 . else if key="TEMP_ADDRESS_LINE_3" set TMGFDA(2,IENS,.1213)=INFO("TEMP_ADDRESS_LINE_3")
795 . else if key="TEMP_CITY" set TMGFDA(2,IENS,.1214)=INFO("TEMP_CITY")
796 . else if key="TEMP_STATE" set TMGFDA(2,IENS,.1215)=INFO("TEMP_STATE")
797 . else if key="TEMP_ZIP4" set TMGFDA(2,IENS,.12112)=INFO("TEMP_ZIP4")
798 . else if key="TEMP_STARTING_DATE" set TMGFDA(2,IENS,.1217)=INFO("TEMP_STARTING_DATE")
799 . else if key="TEMP_ENDING_DATE" set TMGFDA(2,IENS,.1218)=INFO("TEMP_ENDING_DATE")
800 . else if key="TEMP_ADDRESS_ACTIVE" set TMGFDA(2,IENS,.12105)=INFO("TEMP_ADDRESS_ACTIVE")
801 . else if key="CONF_ADDRESS_LINE_1" set TMGFDA(2,IENS,.1411)=INFO("CONF_ADDRESS_LINE_1")
802 . else if key="CONF_ADDRESS_LINE_2" set TMGFDA(2,IENS,.1412)=INFO("CONF_ADDRESS_LINE_2")
803 . else if key="CONF_ADDRESS_LINE_3" set TMGFDA(2,IENS,.1413)=INFO("CONF_ADDRESS_LINE_3")
804 . else if key="CONF_CITY" set TMGFDA(2,IENS,.1414)=INFO("CONF_CITY")
805 . else if key="CONF_STATE" set TMGFDA(2,IENS,.1415)=INFO("CONF_STATE")
806 . else if key="CONF_ZIP" set TMGFDA(2,IENS,.1416)=INFO("CONF_ZIP")
807 . else if key="CONF_STARTING_DATE" set TMGFDA(2,IENS,.1417)=INFO("CONF_STARTING_DATE")
808 . else if key="CONF_ENDING_DATE" set TMGFDA(2,IENS,.1418)=INFO("CONF_ENDING_DATE")
809 . else if key="CONF_ADDRESS_ACTIVE" set TMGFDA(2,IENS,.14105)=INFO("CONF_ADDRESS_ACTIVE")
810 . else if key="PHONE_RESIDENCE" set TMGFDA(2,IENS,.131)=INFO("PHONE_RESIDENCE")
811 . else if key="PHONE_WORK" set TMGFDA(2,IENS,.132)=INFO("PHONE_WORK")
812 . else if key="PHONE_CELL" set TMGFDA(2,IENS,.134)=INFO("PHONE_CELL")
813 . else if key="PHONE_TEMP" set TMGFDA(2,IENS,.1219)=INFO("PHONE_TEMP")
814 . else if key="EMAIL" set TMGFDA(2,IENS,.133)=INFO("EMAIL")
815
816 if $data(TMGFDA) do
817 . do FILE^DIE("EKST","TMGFDA","TMGMSG")
818 . if $data(TMGMSG("DIERR")) do
819 . . set RESULT="-1^Filing Error Occured: "_$get(TMGMSG("DIERR",1,"TEXT",1))
820 . . ;"merge ^TMG("TMP","RPC","DIERR")=TMGMSG("DIERR")
821 . . ;"merge ^TMG("TMP","RPC","FDA")=TMGFDA
822
823 ;"now file Alias info separately
824 if RESULT=1 do
825 . new tempArray,index,key2
826 . new key set key=""
827 . for set key=$order(INFO(key)) quit:(key="") do
828 . . if key["ALIAS" do
829 . . . set index=$piece(key," ",2) quit:(index="")
830 . . . set key2=$piece(key," ",3)
831 . . . set tempArray(index,key2)=INFO(key)
832 . set index=0 for set index=$order(tempArray(index)) quit:(index="")!(RESULT'=1) do
833 . . new TMGFDA,TMGMSG,TMGIEN,newRec
834 . . set newRec=0
835 . . set key="" for set key=$order(tempArray(index,key)) quit:(key="")!(RESULT'=1) do
836 . . . if key="NAME" set TMGFDA(2.01,index_","_DFN_",",.01)=$get(tempArray(index,"NAME"))
837 . . . if key="SSN" set TMGFDA(2.01,index_","_DFN_",",1)=$get(tempArray(index,"SSN"))
838 . . . if index["+" set newRec=1
839 . . if $data(TMGFDA) do
840 . . . if newRec=0 do FILE^DIE("EKST","TMGFDA","TMGMSG")
841 . . . else do UPDATE^DIE("ES","TMGFDA","TMGIEN","TMGMSG")
842 . . if $data(TMGMSG("DIERR")) do
843 . . . set RESULT="-1^Filing Error Occured: "_$get(TMGMSG("DIERR",1,"TEXT",1))
844 . . . ;"merge ^TMG("TMP","RPC","DIERR")=TMGMSG("DIERR")
845 . . . ;"merge ^TMG("TMP","RPC","FDA")=TMGFDA
846
847 quit
848
849PTADD(RESULT,INFO) ;" ADD PATIENT
850 ;"Purpose: To add a patient
851 ;"Input: RESULT (this is the output array)
852 ;"
853 ;" INFO: Format as follows:
854 ;" The results are in format: INFO("KeyName")=Value,
855 ;" There is no set order these will appear.
856 ;" Here are the KeyName names that will be provided.
857 ;" If the record has no value, then value will be empty
858 ;" If a record should be deleted, its value will be @
859 ;" INFO("COMBINED_NAME")=
860 ;" INFO("DOB")=
861 ;" INFO("SEX")=
862 ;" INFO("SS_NUM")=
863 ;" INFO("Veteran")=
864 ;" INFO("PtType")=
865 ;"Results: Results passed back in RESULT string:
866 ;" DFN = success
867 ;" -1^Message = failure
868 ;" 0^DFN = already exists
869
870 set RESULT=1 ;"default to success
871
872 kill ^TMG("TMP","RPC")
873 merge ^TMG("TMP","RPC")=INFO ;"temp... remove later
874
875 new TMGFDA,TMGMSG,IENS,PATIENT,DFN,TMGFREG
876 ;" set IENS=DFN_","
877 new key set key=""
878 for set key=$order(INFO(key)) quit:(key="") do
879 . if key="COMBINED_NAME" set PATIENT("NAME")=INFO("COMBINED_NAME")
880 . else if key="DOB" set PATIENT("DOB")=INFO("DOB")
881 . else if key="SEX" set PATIENT("SEX")=INFO("SEX")
882 . else if key="SS_NUM" set PATIENT("SSNUM")=INFO("SS_NUM")
883 . else if key="Veteran" set PATIENT("VETERAN")=INFO("Veteran")
884 . else if key="PtType" set PATIENT("PT_TYPE")=INFO("PtType")
885 set DFN=$$GetDFN^TMGGDFN(.PATIENT)
886 if DFN=-1 do
887 . new Entry,result,ErrMsg
888 . do Pat2Entry^TMGGDFN(.PATIENT,.Entry)
889 . set DFN=$$AddNewPt^TMGGDFN(.Entry,.ErrMsg)
890 . ;"set DFN=$$GetDFN^TMGGDFN(.PATIENT)
891 . if DFN'>0 do
892 . . set RESULT="-1^ERROR ADDING" ;"should use ErrMsg from above. Fix later
893 . . set RESULT=RESULT_". "_$$GetErrStr^TMGDEBUG(.ErrMsg)
894 . else do
895 .. set RESULT=DFN
896 else do
897 . set RESULT="0^"_DFN
898
899 quit
900
901
902GETBARCD(GREF,MESSAGE,OPTION)
903 ;"SCOPE: Public
904 ;"RPC that calls this: TMG BARCODE ENCODE
905 ;"Purpose: To provide an entry point for a RPC call from a client.
906 ;" A 2D DataMatrix Bar Code will be create and passed to client.
907 ;" It will not be stored on server
908 ;"Input: GREF -- OUT PARAM -- the array to pass the result back in (PASSED BY REFERENCE)
909 ;" MESSAGE-- The text to use to create the barcode
910 ;" OPTION -- Array that may hold optional settings, as follows:
911 ;" OPTION("IMAGE TYPE")="jpg" <-- if not specified, then default is "png"
912 ;"Output: results are passed out in @GREF
913 ;" @GREF@(0)=success; 1=success, 0=failure
914 ;" @GREF@(1..xxx) = actual data
915
916 ;"NOTE: dmtxread must be installed on linux host.
917 ;" I found source code here:
918 ;" http://sourceforge.net/projects/libdmtx/
919 ;" After installing (./configure --> make --> make install), I
920 ;" copied dmtxread and dmtxwrite, which were found in the
921 ;" (installdir)/util/dmtxread/.libs and (installdir)/util/dmtxwrite/.libs
922 ;" folders, into a folder on the system path. I chose /usr/bin/
923 ;" Also, to achieve compile of above, I had to install required libs.
924 ;" See notes included with dmtx source code.
925
926 new FileSpec
927 new file
928 new FName,FPath
929
930 set GREF="^TMP(""GETBARCD^TMGRPC1"","_$J_")"
931 kill @GREF
932 set @GREF@(0)="" ;"default to failure
933 set MESSAGE=$get(MESSAGE)
934 if MESSAGE="" goto GBCDone
935
936 ;"Create the barcode and get file name and path
937 set file=$$MAKEBC^TMGBARC(MESSAGE,.OPTION)
938 do SplitFNamePath^TMGIOUTL(file,.FPath,.FName,"/")
939
940 ;"Load binary image into global array
941 set @GREF@(0)=$$BFTG^TMGBINF(.FPath,.FName,$name(@GREF@(1)),3)
942
943 ;"convert binary data to ascii encoded data
944 do ENCODE($name(@GREF@(1)),3)
945
946 ;"delete temp image file
947 do SplitFNamePath^TMGIOUTL(file,.FPath,.FName,"/")
948 set FileSpec(FName)=""
949 new temp set temp=$$DEL^%ZISH(FPath,"FileSpec")
950
951GBCDone
952 quit
953
954
955DECODEBC(RESULT,ARRAY,IMGTYPE)
956 ;"SCOPE: Public
957 ;"RPC that calls this: TMG BARCODE DECODE
958 ;"Purpose: To provide an entry point for a RPC call from a client. The client
959 ;" will upload an image file (.png format only) of a barcode (Datamatrix
960 ;" format) for decoding. Decoded message is passed back.
961 ;"Input: RESULT -- an OUT PARAMETER. See output below.
962 ;" ARRAY -- the array that will hold the image file, in BASE64 ascii encoding
963 ;" IMGTYPE -- Image type, e.g. "jpg" (Note: don't include any '.')
964 ;"Output: results are passed out in RESULT: 1^Decoded Message or 0^FailureMessage
965
966 ;"NOTE: dmtxread must be installed on linux host.
967 ;" I found source code here:
968 ;" http://sourceforge.net/projects/libdmtx/
969 ;" After installing (./configure --> make --> make install), I
970 ;" copied dmtxread and dmtxwrite, which were found in the
971 ;" (installdir)/util/dmtxread/.libs and (installdir)/util/dmtxwrite/.libs
972 ;" folders, into a folder on the system path. I chose /usr/bin/
973 ;" Also, to achieve compile of above, I had to install required libs.
974 ;" See notes included with dmtx source code.
975 ;"NOTE: if image types other than .png will be uploaded, then the linux host
976 ;" must have ImageMagick utility 'convert' installed for conversion
977 ;" between image types.
978
979 kill ^TMG("TMP","BARCODE")
980 ;"set ^TMG("TMP","BARCODE","LOG")=1 ;"temp
981
982 ;"new Stack do GetStackInfo^TMGIDE2(.Stack)
983 ;"merge ^TMG("TMP","BARCODE","STACK")=Stack
984
985 new resultMsg
986 if $data(ARRAY)=0 set resultMsg="0^No image data received to decode" goto DBCDone
987
988 new imageType set imageType=$$LOW^XLFSTR($get(IMGTYPE))
989 if imageType="" set resultMsg="0^Image type not specified" goto DBCDone
990
991 new imageFName set imageFName="/tmp/barcode."_imageType
992 set imageFName=$$UNIQUE^%ZISUTL(imageFName)
993 new FName,FPath,FileSpec
994 do SplitFNamePath^TMGIOUTL(imageFName,.FPath,.FName,"/")
995 set FileSpec(FName)=""
996
997 ;"temp...
998 ;"merge ^TMG("TMP","BARCODE","DATA")=ARRAY
999 ;"merge ^TMG("TMP","BARCODE","IMGTYPE")=IMGTYPE
1000
1001 ;"set ^TMG("TMP","BARCODE","LOG")=2 ;"temp
1002 ;"Remove BASE64 ascii encoding
1003 do DECODE("ARRAY(0)",1)
1004
1005 ;"set ^TMG("TMP","BARCODE","LOG")=3 ;"temp
1006 ;"set ^TMG("TMP","BARCODE","LOG","Orig file: "_FPath_FName)=""
1007
1008 ;"Save to host file system
1009 if $$GTBF^TMGBINF("ARRAY(0)",1,FPath,FName)=0 do goto DBCDone
1010 . set resultMsg="0^Error while saving file to HFS"
1011
1012 ;"set ^TMG("TMP","BARCODE","LOG")=4 ;"temp
1013
1014 ;"convert image file to .png format, if needed
1015 if imageType'="png" do
1016 . set imageFName=$$Convert^TMGKERNL(imageFName,"png")
1017 . if imageFName="" do quit
1018 . . set resultMsg="0^Error while converting image from ."_imageType_" to .png format."
1019 . do SplitFNamePath^TMGIOUTL(imageFName,.FPath,.FName,"/")
1020 . set FileSpec(FName)=""
1021 if imageFName="" goto DBCDone
1022
1023 ;"set ^TMG("TMP","BARCODE","LOG")=5 ;"temp
1024
1025 ;"Decode the barcode.png image
1026 new result set result=$$READBC^TMGBARC(imageFName)
1027 if result'="" set resultMsg="1^"_result
1028 else set resultMsg="0^Unable to Decode Image"
1029
1030 ;"delete temp image file
1031 ;"temp REMOVE COMMENTS LATER TO DELETE FILE. !!!!!
1032 ;"set result=$$DEL^%ZISH(FPath,"FileSpec")
1033
1034DBCDone
1035 ;"set ^TMG("TMP","BARCODE","LOG")=6 ;"temp
1036
1037 set RESULT=resultMsg
1038 quit
1039
1040 ;"--------------------
1041GETURLS(RESULT)
1042 ;"SCOPE: Public
1043 ;"RPC that calls this: TMG CPRS GET URL LIST
1044 ;"Purpose: To provide an entry point for a RPC call from a client. The client
1045 ;" will request URLs to display in custom tabs inside CPRS, in an
1046 ;" imbedded web browser
1047 ;"Input: RESULT -- an OUT PARAMETER. See output below.
1048 ;"Output: results are passed out in RESULT:
1049 ;" RESULT(0)="1^Success" or "0^SomeFailureMessage"
1050 ;" RESULT(1)="Name1^URL#1" ; shows URL#1 in tab #1, named 'Name1'
1051 ;" RESULT(2)="Name2^URL#2" ; etc.
1052 ;" RESULT(3)="Name3^URL#3"
1053 ;"
1054 ;" E.g. RESULT(1)="cnn^www.cnn.com"
1055 ;" RESULT(2)="INFO^192.168.0.1/home.html"
1056 ;"
1057 ;" The number of allowed tabs is determined by code in CPRS
1058 ;" Reference to tab numbers > specified in CPRS will be ignored by CPRS
1059 ;" If a web tab is NOT specified, then the page previously
1060 ;" displayed will be left in place. It will not be cleared.
1061 ;" To clear a given page, a url of "about:blank" will cause a
1062 ;" blank page to be displayed. e.g.
1063 ;" RESULT(3)="^about:blank"
1064 ;" To HIDE a tab on CPRS use this:
1065 ;" RESULT(3)="^<!HIDE!>" ;triggers tab #3 to be hidden
1066 ;" To have the browser remain UNCHANGED use this:
1067 ;" RESULT(3)="^<!NOCHANGE!>" ;triggers tab #3 to remain unchanged.
1068 ;" Note: the rationale for this is that the web tab may have info
1069 ;" that should not be refreshed when the patient info is refreshed
1070 ;" i.e. the user may have navigated somewhere, and doesn't want
1071 ;" to loose their location.
1072 ;" --to be implemented.
1073 ;" Note: The other way to do this, as above, is to simply have NO
1074 ;" entry for a given tab. I.e. don't have any value for RESULT(3)
1075 ;" --already implemented.
1076 ;"Notice to others: Below is where code should be added to return
1077 ;" proper URL's to CPRS. This will be called whenever a new patient
1078 ;" is opened, or a Refresh Information is requested.
1079 ;" FYI, 'DFN' should be defined as a globally-scoped variable that can be used
1080 ;" to pass back URLS specific for a given patient.
1081
1082 set RESULT(0)="1^Success"
1083 set RESULT(1)="CNN^www.cnn.com"
1084 set RESULT(2)="(x)^about:blank"
1085 set RESULT(3)=$GET(^TMG("TMP","RPC","GETURLS"))
1086 set RESULT(4)="<!HIDE!>"
1087
1088 ;"kill RESULT
1089 ;"merge RESULT=^TMG("TMP","URLS") ;"TEMP!!!
1090
1091 quit
Note: See TracBrowser for help on using the repository browser.