Thursday, May 07, 2009

GNUmed plugin development - part 11

Python comes with various XML tools. Fortunately there is a library called ElementTree which makes XML mangling quite a bit easier. The task is to extract the information on each device from the XML file and format a string that can be fed to the display.

I had to tidy up my pyhon skills a lot and started with a standalone python script that reads in an XML file and parses it for a number of known tags such as 'vendor', 'model' and much more. The next step is to format this into the string I would like to display on the screen. The benefit of seperating the data extraction from the data formating part is that many different display options can be catered for.

In short my preferred mode of display it to group by logical device unit. Each device such as a pacemaker and its leads make up a device. Each device has subparts such as the generator consisting of a mainboard and battery. This is not mandatory but makes sense because I would like to have the option to document software updates and battery types. Not every pacemaker of the same model has the same battery model over time.

I admit the demo-XML file changed a number of times and will most likely see some more restructuring until the plugin is complete.

They say it is best to commit often and early to not lose work on one hand and get feedback on the other.

Having said that I am going to check in the XML file and standalone XML-parser into CVS. It is wise to use the folder 'test-area' in the CVS tree for that.

cvs add GNUmed6.xml

Enter passphrase for key '/home/basti/.ssh/id_rsa':

cvs add: scheduling file `GNUmed6.xml' for addition

cvs add: scheduling file `' for addition

cvs add: use `cvs commit' to add these files permanently
cvs commit GNUmed6.xml
Enter passphrase for key '/home/basti/.ssh/id_rsa':

/sources/gnumed/gnumed/gnumed/test-area/shilbert/GNUmed6.xml,v  <--  GNUmed6.xml
initial revision: 1.1
/sources/gnumed/gnumed/gnumed/test-area/shilbert/,v  <--
initial revision: 1.1
When you update your CVS tree you get my work located in the folder gnumed/gnumed/test-area/shilbert

to try it run:
Reading the XML file GNUmed6.xml it will output this:
The file has the following devices: <Element CardicacDevice at b7bfb20c>:
The device has the following parts: <Element DevicePart at b7bfb18c>
hey we are dealing with a generator here:-)
('St. Jude Medical', 'Atlas DR', 'active')

Seems like we are getting there. Next up is to finish the parsing. While this is getting done Karsten needs to write the routine to store and retrieve and xml object in the database.

No comments: