source: cprs/branches/tmg-cprs/m_files/TMGHTML1.m@ 1725

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

Initial upload

File size: 16.8 KB
Line 
1TMGHTML1 ;TMG/kst/HTML Mini-chart creator ;03/25/06
2 ;;1.0;TMG-LIB;**1**;01/10/06
3
4 ;"TMG HTML EXPORT FUNCTION
5 ;"Kevin Toppenberg MD
6 ;"GNU General Public License (GPL) applies
7 ;"1-10-2006
8
9 ;"=======================================================================
10 ;" API -- Public Functions.
11 ;"=======================================================================
12
13 ;"=======================================================================
14 ;"PRIVATE API FUNCTIONS
15 ;"=======================================================================
16 ;"DumpNtes(List,FPath,OutArray)
17 ;"MakeFName(IEN)
18 ;"GetTemplateRecs(pRecs,Template)
19 ;"Write1Note(IEN)
20
21
22 ;"=======================================================================
23 ;"Dependencies (duplicates shown in parenthesies)
24 ;"=======================================================================
25 ;"^TMGMISC
26
27MAKESITE(FPath,Template)
28 ;"Purpose: To create an interlinked site with specified notes.
29 ;"Input: FPath OPTIONAL -- if not provided, user will be asked
30 ;" This is the directory where output is to be sent
31 ;" Input OPTIONAL -- if not provided, user will be asked
32 ;" This is the name of the search/sort template holding
33 ;" a list of IENs to output
34 ;"Output: files are written to file system
35 ;"Result: none.
36
37
38 if $get(FPath)="" do
39 . write !!,"This will export TIU DOCUMENT records to an interlinked website.",!!
40 . read "Enter destination directory path: ",FPath,!
41 if FPath="^" goto MSDone
42
43 ;"Create core index.htm
44 ;"----------------------
45 if $$OpenIO(FPath,"index.htm")=0 do goto MSDone
46 . write "Error. Aborting.",!
47 new offset
48 for offset=1:1 do quit:(s["{^}")
49 . set s=$piece($TEXT(IndexDat+offset),";;",2)
50 . quit:(s["{^}")
51 . write s,!
52 do ^%ZISC ;" Close the output device
53
54 ;"Create core intro.htm
55 ;"----------------------
56 if $$OpenIO(FPath,"intro.htm")=0 do goto MSDone
57 . write "Error. Aborting.",!
58 new offset
59 for offset=1:1 do quit:(s["{^}")
60 . set s=$piece($TEXT(IntroDat+offset),";;",2)
61 . quit:(s["{^}")
62 . write s,!
63 do ^%ZISC ;" Close the output device
64
65 ;"Create individual files with notes.
66 ;"-----------------------------------
67 new OutArray
68 do WriteTemplate(.FPath,.Template,.OutArray)
69
70
71 ;"Create toc.htm-- the table of contents.
72 ;"---------------------------------------
73 if $$OpenIO(FPath,"toc.htm")=0 do goto MSDone
74 . write "Error. Aborting.",!
75 do MakeTOC(.OutArray)
76 do ^%ZISC ;" Close the output device
77
78MSDone
79 write "Good bye.",!!
80 quit
81
82WriteTemplate(FPath,Template,OutArray)
83 ;"Purpose: To write out notes listed in Template to directory FPath
84 ;"Input: FPath -- The name of the directory to put the output files to
85 ;" Template -- OPTIONAL -- the name of a search/sort template that contains
86 ;" list of IENS's to output
87 ;" If not supplied, user will be asked for name.
88 ;" OutArray -- An OUT parameter. PASS BY REFERENCE
89 ;" An array to receive results of names written. See WriteList for format
90 ;"Output: files are written to directory
91 ;"Result: none
92
93 new List,count
94 set count=$$GetTemplateRecs("List",.Template)
95
96 new PrgsFn set PrgsFn="do ProgressBar^TMGUSRIF(TMGCUR,""Progress"",1,TMGMAX,,TMGSTART)"
97
98 if count>0 do
99 . do WriteList(.List,FPath,.OutArray,PrgsFn)
100
101 quit
102
103
104WriteList(List,FPath,OutArray,PrgCallback)
105 ;"Purpose: To write out all notes given in List to separate files in FPath
106 ;"Input: List -- PASS BY REFERENCE. A list of IEN's that must be written.
107 ;" Format as follows:
108 ;" List(IEN1)=""
109 ;" List(IEN2)=""
110 ;" List(IEN3)=""
111 ;" List(IEN4)=""
112 ;" ...
113 ;" FPath -- The name of the directory that files should be written to
114 ;" e.g. "/tmp/output/"
115 ;" OutArray -- An OUT parameter. PASS BY REFERENCE
116 ;" An array to receive results of names written. Format:
117 ;" OutArray(IEN1)=Filename1
118 ;" OutArray(IEN1,PatientNameAndDOB1)=""
119 ;" OutArray(IEN2)=Filename2
120 ;" OutArray(IEN2,PatientNameAndDOB2)=""
121 ;" OutArray(IEN3)=Filename3
122 ;" OutArray(IEN3,PatientNameAndDOB3)=""
123 ;" OutArray(IEN4)=Filename4
124 ;" OutArray(IEN4,PatientNameAndDOB4)=""
125 ;" OutArray("B",PatientNameAndDOB1,IEN1)=""
126 ;" OutArray("B",PatientNameAndDOB1,IEN1b)="" <-- if more than one IEN per patient.
127 ;" OutArray("B",PatientNameAndDOB2,IEN2)=""
128 ;" OutArray("B",PatientNameAndDOB3,IEN3)=""
129 ;" OutArray("B",PatientNameAndDOB4,IEN4)=""
130 ;" PrgCallback: OPTIONAL -- if supplied, then M code contained in this string
131 ;" will be xecuted periodically, to allow display of a progress bar etc.
132 ;" Note: the following variables with global scope will be declared and
133 ;" available for use: TMGCUR (current count), TMGMAX (max count),
134 ;" TMGSTART (the start time
135 ;"
136 ;"Output: A series of files will be written (or overwritten) to directory
137 ;" Each file will be a TIU DOCUMENT in .htm format.
138 ;" Filename format: lastname_firstname_title_datetime.htm
139 ;"Result: none
140
141 new ien
142 kill OutArray
143 new TMGMAX set TMGMAX=0
144 new TMGSTART set TMGSTART=$H
145 new TMGCUR set TMGCUR=0
146 set ien=$order(List(""))
147 if ien'="" for do quit:(ien="")
148 . set TMGMAX=TMGMAX+1
149 . set ien=$order(List(ien))
150 new delay set delay=0
151
152 set ien=$order(List(""))
153 if ien'="" for do quit:(ien="")
154 . set TMGCUR=TMGCUR+1
155 . new FName
156 . set FName=$$MakeFName(ien)
157 . if $$OpenIO(FPath,FName)'=0 do
158 . . do Write1Note(ien)
159 . . do ^%ZISC ;" Close the output device
160 . . set OutArray(ien)=FName
161 . . new PtName,DOB,DFN
162 . . set DFN=$$GET1^DIQ(8925,ien_",",.02,"I")
163 . . set PtName=$$GET1^DIQ(2,DFN_",",.01)
164 . . set DOB=$$GET1^DIQ(2,DFN_",",.03)
165 . . set PtName=PtName_" "_DOB
166 . . set OutArray(ien,PtName)=""
167 . . set OutArray("B",PtName,ien)=""
168 . if (delay>30),$get(PrgCallback)'="" do ;"update progress bar every 30 cycles
169 . . new $etrap set $etrap="write ""(Invalid M Code!. Error Trapped.)"" set $etrap="""",$ecode="""""
170 . . xecute PrgCallback ;"call the specified progress code.
171 . . set delay=0
172 . else set delay=delay+1
173 . set ien=$order(List(ien))
174
175 quit
176
177
178OpenIO(FPath,FName,NodeDiv)
179 ;"Purpose: to open the IO channel such that all writes
180 ;" will go to the file specified.
181 ;"Input: FPath -- the path to open file in
182 ;" FName -- the name of the file to open
183 ;" NodeDiv -- OPTIONAL (default is "/") -- the path delimiter for OS
184 ;"result: 1=OK To continue, 0=error
185
186 new result set result=1
187 new PFName set PFName=FPath
188 set NodeDiv=$get(NodeDiv,"/")
189 new ch
190 set ch=$extract(PFName,$length(PFName))
191 if ch'=NodeDiv set PFName=PFName_NodeDiv
192 set PFName=PFName_FName
193
194 ;"Select IO channel
195 set %ZIS("HFSNAME")=PFName
196 set %ZIS="Q" ;"queing allowed
197 set %ZIS("HFSMODE")="W" ;"write mode
198 set IOP="HFS"
199
200 do ^%ZIS ;"standard device call
201 if POP do goto OIODone
202 . set result=0
203
204 use IO
205
206OIODone
207 quit result
208
209
210MakeFName(IEN)
211 ;"Purpose: To create a filename from TIU DOCUMENT IEN
212 ;"Input -- IEN. and IEN from file 8925
213 ;"Result -- the filename
214
215 new result set result=""
216 new name,type,datetime
217
218 set name=$$GET1^DIQ(8925,IEN_",",.02)
219 set name=$translate(name,",","_")
220 set name=$translate(name," ","-")
221
222 set type=$$GET1^DIQ(8925,IEN_",",.01)
223 set type=$translate(type," ","-")
224
225 set date=$$GET1^DIQ(8925,IEN_",",.07,"I")
226 set date=$$DTFormat^TMGMISC(date,"mm-dd-yyyy")
227
228 set result=name_"_"_type_"_"_date_".htm"
229 quit result
230
231
232GetTemplateRecs(pRecs,Template)
233 ;"Purpose: to ask user for a search/sort template to inport records from.
234 ;"Input -- pRecs -- pointer to (i.e. name of) array to fill
235 ;" will probably be passed with "Array(12345)"
236 ;" Template -- OPTIONAL. Name of template to import.
237 ;" If not supplied, user will be asked for name
238 ;"Output: Data is put into pRecs like this:
239 ;" @pRecs@(IEN1)=""
240 ;" @pRecs@(IEN2)=""
241 ;" @pRecs@(IEN3)=""
242 ;"Result: Count of records imported
243 ;"Note: uses global variable pHeader
244
245 new File set File=8925
246 new count set count=0
247 new Y
248 if $get(pRecs)="" goto GTRDone
249
250 for do quit:((+Y>0)!(+Y=-1))
251 . new DIC
252 . set DIC=.401
253 . if $get(Template)'="" do
254 . . set X=Template
255 . else do
256 . . set DIC(0)="AEQ"
257 . . write "Select a Template containing records for import. ",!
258 . . write "(? for list, ^ to quit) "
259 . . set DIC("A")="Enter Template: "
260 . do ^DIC
261 . if $get(Template)="" write !
262 . if +Y'>0 quit
263 . new node set node=$get(^DIBT(+Y,0))
264 . if $piece(node,"^",4)'=File do quit
265 . . set Y=0 ;"signal to try again
266 . . new PriorErrorFound
267 . . write "Error: That template doesn't contain a list of progress notes. Please select another.",!
268
269 if (+Y>0)&($data(^DIBT(+Y,1))>1) do
270 . new index set index=$order(^DIBT(+Y,1,0))
271 . if index'="" for do quit:(index="")
272 . . set @pRecs@(index)=""
273 . . set count=count+1
274 . . set index=$order(^DIBT(+Y,1,index))
275
276 if $get(Template)="" write count," Records selected.",!
277
278GTRDone
279 quit count
280
281
282
283Write1Note(IEN)
284 ;"Purpose: To write out a progress note in HTML format
285 ;"Input: IEN -- the IEN in file 8925 (TIU DOCUMENT)
286 ;"Output: The note (in complete HTML format) is written to current
287 ;" output device.
288 ;"Result: none:
289
290 new offset,s
291 new IENS set IENS=IEN_","
292
293 for offset=1:1 do quit:(s["{^}")
294 . set s=$piece($TEXT(NoteHdr+offset),";;",2)
295 . quit:(s["{^}")
296 . write s,!
297
298 write "<h2><strong>",$$GET1^DIQ(8925,IENS,".01"),"</strong></h2>",! ;"Note type
299 write "<p><strong>Name: </strong>",$$GET1^DIQ(8925,IENS,".02"),"<br>",! ;"patient name
300 new Date set Date=$$GET1^DIQ(8925,IENS,".07","I")
301 set Date=$$DTFormat^TMGMISC(Date,"mmmm d,yyyy")
302 write "<strong>Date: </strong>",Date,"</p>",! ;"note date
303 write "<p><strong>Note: </strong></p>",!
304
305 new TMGWP,x
306 set x=$$GET1^DIQ(8925,IENS,2,"","TMGWP")="WP"
307 do
308 . new i
309 . write "<p>"
310 . set i=$order(TMGWP(""))
311 . for do quit:(i="")
312 . . new line set line=$get(TMGWP(i))
313 . . set line=$$SYMENC^MXMLUTL(line)
314 . . write line,"<br>",!
315 . . set i=$order(TMGWP(i))
316 . write "</p>",!
317
318 write "<p><strong><u>Note Detail</u>:</strong><br>",!
319 write "<font size=""2""><strong>Author</strong>: ",$$GET1^DIQ(8925,IENS,"1202"),"</font><br>",!
320 write "<font size=""2""><strong>Signature Date/Time</strong>: ",$$GET1^DIQ(8925,IENS,"1501"),"</font><br>",!
321 write "<font size=""2""><strong>Status</strong>: ",$$GET1^DIQ(8925,IENS,".05"),"</font><br>",!
322 write "<font size=""2""><strong>Location</strong>: ",$$GET1^DIQ(8925,IENS,"1211"),"</font><br>",!
323 write "<font size=""2""><strong>Transcriptionist</strong>: ",$$GET1^DIQ(8925,IENS,"1302"),"</font><br>",!
324 write "<font size=""2""><strong>Transcription Date/Time</strong>: ",$$GET1^DIQ(8925,IENS,"1201"),"</font><br>",!
325 ;"write "<font size=""2""><strong>Line count</strong>: ",$$GET1^DIQ(8925,IENS,".1"),"</font><br>",!
326 ;"write "<font size=""2""><strong>Character count</strong>: ",$$GET1^DIQ(8925,IENS,"22711"),"</font><br>",!
327 write "</p>",!
328
329 write "</body",!
330 write "</html>",!
331
332 quit
333
334
335MakeTOC(OutArray)
336 ;"Purpose: To write toc.htm (the table of contents side panel)
337 ;"Input: IEN -- the IEN in file 8925 (TIU DOCUMENT)
338 ;"Output: OutArray -- PASS BY REFERENCE
339 ;" An array with file names written. Format:
340 ;" OutArray(IEN1)=Filename1
341 ;" OutArray(IEN1,PatientNameAndDOB1)=""
342 ;" OutArray(IEN2)=Filename2
343 ;" OutArray(IEN2,PatientNameAndDOB2)=""
344 ;" OutArray(IEN3)=Filename3
345 ;" OutArray(IEN3,PatientNameAndDOB3)=""
346 ;" OutArray(IEN4)=Filename4
347 ;" OutArray(IEN4,PatientNameAndDOB4)=""
348 ;" OutArray("B",PatientNameAndDOB1,IEN1)=""
349 ;" OutArray("B",PatientNameAndDOB1,IEN1b)="" <-- if more than one IEN per patient.
350 ;" OutArray("B",PatientNameAndDOB2,IEN2)=""
351 ;" OutArray("B",PatientNameAndDOB3,IEN3)=""
352 ;" OutArray("B",PatientNameAndDOB4,IEN4)=""
353 ;"
354 ;"Result: none:
355
356 new offset,s
357
358 for offset=1:1 do quit:(s["{^}")
359 . set s=$piece($TEXT(TOCHdr+offset),";;",2)
360 . quit:(s["{^}")
361 . write s,!
362
363 ;"Write Patient name and DOB, then list of their notes , then repeat.
364 new Patient
365 set Patient=$order(OutArray("B",""))
366 if Patient'="" for do quit:(Patient="")
367 . write "<p><strong>",Patient,"</strong></p>",!
368 . write "<ul>",!
369 . new ien set ien=$order(OutArray("B",Patient,""))
370 . if ien'="" for do quit:(ien="")
371 . . new Type,Date,FName
372 . . set Type=$$GET1^DIQ(8925,ien_",",".01") ;"Note type
373 . . set Date=$$GET1^DIQ(8925,ien_",",".07","I") ;"note date
374 . . set Date=$$DTFormat^TMGMISC(Date,"mm/dd/yyyy")
375 . . set FName=OutArray(ien)
376 . . write "<li><a href=""",FName,""" target=""main"">"
377 . . write Type," -- ",Date
378 . . write "</a></li>",!
379 . . set ien=$order(OutArray("B",Patient,ien))
380 . set Patient=$order(OutArray("B",Patient))
381 . write "</ul>",!
382
383 write "</body",!
384 write "</html>",!
385
386 quit
387
388
389
390 ;"=======================================================================
391IndexDat
392 ;;<html>
393 ;; <head>
394 ;; <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
395 ;; <meta name="Author" content="Open Vista Team &amp; ed. by Kevin Toppenberg">
396 ;; <meta name="GENERATOR" content="Kate 2.1 on Linux">
397 ;; <title>Open VistA Exported Notes</title>
398 ;; </head>
399 ;; <frameset cols="200,*">
400 ;; <frame name="toc" src="toc.htm" resize>
401 ;; <frame name="main" src="intro.htm">
402 ;; <noframes>
403 ;; <body>
404 ;; </body>
405 ;; </noframes>
406 ;; </frameset>
407 ;;</html>
408 ;;
409 ;;{^} ;"Kevin's custom end-of-data symbol
410
411IntroDat
412 ;;<html>
413 ;;<head>
414 ;; <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
415 ;; <meta name="GENERATOR" content="Kate 2.1 on Linux">
416 ;; <title>OpenVistA Exported Notes</title>
417 ;; </head>
418 ;; <body bgcolor="#FFFFFF" link="#FFFF00" vlink="#800080">
419 ;; <p><strong>Please Select A Patient from List at Left</strong></p>
420 ;; </body>
421 ;;</html>
422 ;;
423 ;;{^} ;"Kevin's custom end-of-data symbol
424
425
426TOCHdr
427 ;;<html>
428 ;;<head>
429 ;;<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
430 ;;<title>OpenVista List of Patients</title>
431 ;;</head>
432 ;;<body link="#0000FF" vlink="#800080">
433 ;;<p><a href="intro.htm" target="main">Introduction</a></p>
434 ;;<p><font size="5"><b>Patients</b></font></p>
435 ;;
436 ;;{^} ;"Kevin's custom end-of-data symbol
437
438
439NoteHdr
440 ;;<html>
441 ;;
442 ;; <head>
443 ;; <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
444 ;; <title>OpenVistA Introduction</title>
445 ;; </head>
446 ;; <body>
447 ;
448 ;;{^} ;"Kevin's custom end-of-data symbol
449
450
Note: See TracBrowser for help on using the repository browser.