Parsing Radiology Exam Data with Python Class

I’ve had a really clunky program to track what I do.  It lets me know how much volume I’m reading calculated each 30 min based a logfile.

I’ve decided to get a little more sophisticated with the program because it has grown to the point where it’s painful for me to edit, and if I wrote it, it must be completely abstruse to someone else.

I have never used a class in python but it solves many issues for me:

  • Cleans up the code
  • Moves functions to a module for importing and repurposing
  • Teaches me how to construct a class properly
  • Allows parsing of text with a structure that makes sense
    • Class instance attributes now make inherent sense
  • Eliminates having to bring global var into functions for modification
    • The class instance can access global counters
    • The class output can eliminate the need for global counters
  • Allows me to expand to the class to perform other manipulation
    • calculating age of patient
    • SQL archival
  • Works in python 2 and 3
  • Uses the Regex from hell
import re

class Parser:
    A class to parse data strings into components
    from parser_fx import *
    result = Parser()     ## Instantiate class
    result.parse(study)   ## Pass the instance a study string
    result.XXXXXXX        ## Attributes of result now available

    def __init__(self):
        """ Simply establishes the regex expression"""
        self.regex = re.compile(r'([\'A-Z\s-]+)(\[.+||\s])\s*'
                                '(CURRENT STUDY:)([A-Z\s/\[\]]+)'

    def parse(self, study_string=('SIMPSON HOMER J[Prelim  report]CURRENT STUDY:'
        'CT HEAD 2016-01-01 23:59:59 [DOB: 1111/1/11 ] [ID: 1234567]')):
        """Parser with failure options"""
        self.study_string = study_string
            self.matchobj = self.regex.match(self.study_string)
            ## Attributes: name, prelim/final, study, date, time dob, ID 
            self.type =[1:7].rstrip()
            self.study_name =
            self.time =
            self.DOB =
            self.ID =[1:-1]
            print("REGEX Match Failed")

    """  Leaving here as an example to follow 
    def ID(self):
        ''' returns study  '''
        self.ID =
        return self.ID   

study= ('SIMPSON HOMER J[Prelim  report]CURRENT STUDY:'
        'CT HEAD 2016-01-01 23:59:59 [DOB: 1111/1/11 ] [ID: 1234567]')
result = Parser()
print("%s | %s | %s | %s | %s | %s" %(result.type,,
        result.study_name,, result.time, result.ID))


After testing for a week, I’ll report back on success or failure.


A setup for mesenteric ischemia

ER case.  Likely unimportant in the current presentation but potentially important down the road.  2 vessel comp.png

  • Salient Points
    • Chronically occluded proximal SMA
    • >50% and probably 70% stenosis of Celiac origin
  • My recall from Sabistons book says that a single vessel can be ligated with impunity.  2 Vessels and the patient is on the threshold.  If this patient were to thrombose a collateral reconstituting the SMA or the Celiac, there could be a large territory of dead bowel.

Pneumomediastinum and pulmonary interstitial emphysema

I think this is the first time I’ve ever seen PIE in without trauma.  The patient has bad colitis and I caught the pneumomediastinum on the inferior slices of the chest.  Went back and scanned the chest and no visible esophageal perf, but lots of air.



I was not familiar with the term:

The Macklin effect: pulmonary interstitial emphysema and pneumomediastinum

I’m only used to seeing PIE in infants, but this is a rock solid demonstration of it.

Belly GIF: rocker_loop.gif


Xanthogranulomatous pyelonephritis (XGP)

Xanthogranulomatous pyelonephritis (XGP) is a rare form of chronic pyelonephritis and represents a chronic granulomatous disease resulting in a non-functioning kidney. Radiographic features are usually specific.



CT findings are most helpful in reaching the correct diagnosis. The normal renal outline is lost and enlarged with a paradoxical contracted renal pelvis. The calyces in contrast, are dilated giving a multiloculated appearance that has been likened to the paw print of a bear (bear’s paw sign) 3. Sometimes there is perinephric extension with thickening of Gerota’s fascia. Calcification can be better delineated on CT scan.


Boerhaave syndrome

An appropriate NEW YEARS POST!



MEDIASTINUM: pneumomediastinum is present. This extends from the gastroesophageal junction through the chest to the thoracic Inlet and there is gas dissecting cranially into the neck. The findings are typical for pneumomediastinum. No extravasation of oral contrast into the mediastinum however this does not exclude an esophageal perforation. No paraesophageal fluid collections or lymphadenopathy. No esophageal mass is identified. No convincing evidence of esophageal mural thickening.







Pneumomediastinum. In young patients, trauma is the most frequent cause. No given history of trauma.

In young patients without trauma, this is most commonly associated with either esophageal perforation or alveolar rupture, particularly if the patient has a history of asthma. Given the history of vomiting, Boerhaave syndrome is most likely.