Here's a copy of a post to a newsgroup developing open source medical applications. I describe how I have been using tclxml-2.0. It explains how I used it in a prescription management module and plans I have for it in the future. I'll be showing it at the O'Reilly Open Source Convention in July in Monterey, CA. USA. The program also uses Plume as well. I feel you really have something powerful using XML with Plume - you can display HTML, post HTML forms and do tables but you can define all kinds of other functions via Tcl/Tk that ordinary web browsers will never be able to do. For a custom business application it's really got a lot of possibilities for client side processing.

-- Alex Caldwell

Recent TKFP developments

Some new features have been added to Tk_familypractice that use XML in what hopefully is a useful way. I looked at what I felt was necessary to define a "prescription event" - a refill, a new Rx, a dose change, discontinuation etc. I tried to come up with an XML model to represent prescription events and converted the functions that store the data in the prescription file so that the data is wrapped up in XML tags. Most of the prescription event components are represented as XML elements but some as attributes.

You can see the XML file format I came up with at XML File Format There is a cascading stylesheet so you can display the data in an XML capable browser like mozilla, doczilla or IE 5. However, I wanted to do more than just display it in a web page, I wanted to add interactive functions to the data display which I will explain further below. I looked at the HL7's current PDA proposal (tip from John Gage) and didn't see anything that quite fit what I needed for this (they have a very fine grained set of elements for defining the patient identity and the sender's identity but it's rather loose and unstructured when you get to the level of a note or prescription). I needed more structure for the prescription data so I used what I was already doing and added some more elements. This could still fit into the HL7 as an external entity reference in the future however. I looked at the FDA's "Orange Book" (tip from Dan Johnson) and how they store the drugs according to the various forms available for it and tried to emulate that format.

There is a DTD link here. In Tkfp however, I don't use the DTD. It isn't necessary since the program produces it's own XML, it doesn't really need to be validated. It does need to be well formed for the parser to operate on it, however.

The other end of the process involves parsing the patient's XML formatted prescription file for display in the program GUI. I used tclxml-2.0, an XML parser for Tcl/Tk by Steve Ball XML Parser . Steve is a very bright and prolific Tcl programmer from Australia. He has been developing a suite of XML tools for Tcl programmers. I used the SAX style event driven commands the parser makes available (defined by the W3C) to call handler functions from Tcl as the parser encounters the start and end tags as well as the attribute values. The data gets displayed in a Tk text widget. If you're not familiar with the Tk text widget, it is a part of the GUI components available with the Tk toolkit. The Tk text widget has numerous functions for handling text in interesting ways built into it. (There have been several projects that used the Tk text widget to develop HTML compliant web browsers that can display images, do tables and post HTML forms.)

I had the handler funtions wrap the text with Tk text widget "marks" as the data is inserted into the widget. These correspond to the XML elements. Tk text widget "tags" can be applied to ranges of text between the marks by the handler functions. You can control things like fonts, colors and more significantly, mouse or keyboard event bindings on text in the widget that have different tags applied. What I did so far was to have a mouse click on the text representing a previously prescribed drug call a function to read the data in the form, quantity, drugstore, no. of refills elements and plug these values into the appropriate place in the GUI to be sent to the drugstore for a refill authorization. A screenshot of what it looks like in raw XML format is at this link: Screenshot. Another shot of the rendered XML in the text widget is here: Rendered XML Screen shot

One problem I ran into is I still have all my old non-XML data and had to decide if I could write a script to convert it to XML. At this time I just have a toggle button that converts the text widget display from the old format to the new XML based one so if I'm working with the old data, I can use the old format and when working with XML data, I can use the new one in the same display window.

I am also experimenting with Xpath - a way of defining a pattern for finding data that matches certain criteria and extracting information from your XML database. This uses XML DOM (document object model) also defined by the W3C. You can find data by following the path to it among the nodes representing the structure of the XML data.

The other area I've been working on is changing the basic architecture of Tkfp over to a client/server TCP/IP socket based setup. I have gradually been shifting over the data writing and reading to a simple server written in Tcl. The GUI part of application gets the data from the server over the TCP/IP socket based setup. That way the data can be kept anywhere on the network and be accessed from the GUI interface part of the application running elsewhere - hopefully in the not to distant future from a YOPI or a Crusoe chip powered wireless mobile device carried into the exam room or the hospital. The server still needs a lot of work for security, locking and disaster recovery etc. none of which it currently has, but I have most of the data being handled by it now. The patient name browser, the drug browser, the prescription and progress note reader are using it. The demographic browser and the progress note/H. and P. generator aren't converted yet and still need to read files off the local disk.

I've thought about using an SQL database, but have been concentrating on figuring out XML and the flat file based system seems to suit my needs for the small office sized database I have at this time so I haven't expended much effort in that direction. I think there are some projects underway to integrate relational databases with XML better so am watching those - Lore is one from Stanford.

The Linux version of the program has the above mentioned features in the latest upload. You can get it here: Linux Version. It has been upgraded to use Tcl/Tk 8.3 (the latest version) and Incr Tcl 3.1 - the latest version of the extension that enables object oriented programming in Tcl/Tk. At the price of a rather bloated download (14mb), I included static binaries for these compiled on Slackware 7.0 kernel 2.2.13 with glibc, so you shouldn't have to compile anything and it should run right out of the box. Tkfp has it's own install script that seems to work according to my tests and several other reports. The Tcl/Tk stuff goes in sub-directories of the Tkfp install directory so it shouldn't overwrite other Tcl/Tk distributions you may already have installed on your machine. Install as an ordinary user, not as root, to be safe. Add link to comments for /community/features/familypractice.tml