How Python could save your live: automatic code generation for medical reports

Mayte Giménez

Audience level:


The aim is to present how using Python, we have been able to develop an automatic code generator which starting from an XML file representing a structured medical report following DICOM-SR standard and it will generate an Android application. Briefly we will explain what simple Python tools we used: virtualev , xml.sax, ConfigParser y string.Template and Jinja2.


First I would like to give an overview of the problem in which we are working and how Python has been a key to solving it. The introduction of digitized medical imaging has revolutionized clinical practice, if we add the development efforts of the systems computer-aided diagnosis we realize the great impact of information technology in the medical field. Most of picture archiving and communication systems (tacs, radiology, MRI ...), use the DICOM standard. But in addition to medical imaging, the DICOM standard defines in its appendices a standard for structured medical reports, this standard is DICOM-SR. In these reports, the information is stored in plain text inside a tree structure. It is easy to conclude that we could extract valuable information from these reports. The problem we found is to fill these reports with traditional workstations is a very tedious task. So we took advantage of new technology to simplify user-machine interaction. Tablets have demonstrated that the input methods used are much more intuitive. The tablets have shown that its input methods used are much more intuitive. So our task is to convert a DICOM-SR report in to an Android application. It is at this point in the python has been a lifesaver. We developed a SAX parser in python, once we have loaded data in memory we generate all Android needed code using standard string.Template package and Jinja templating system. We also use ConfigParser package to configure the application. Firstly what I found more interesting about this project to share with the community is how we can deal with difficult problems, as code generation, because Python doesn't add more complexity. We could explain how we assemble this jigsaw using Python batteries (templates from the String package, ConfigParser, xml.sax, ...). When we run out of energy, Python has a power community writing useful libraries, and we use Jinja2 for more complex templates in our system wrapped using virtualevn. The second point that may be interesting for the community, is the experience of how Python has been integrated in the field of medical imaging. And since code always speaks louder than words I leave the application repository for you to take a look. [][1] [1]: