+ def SetOutputFileName(self,s):
+ self._OutputFilename = s
+
+ def Parse(self):
+ infile = file(self._InputFilename, 'r')
+ outLines = []
+ for line in infile.readlines():
+ print self.Reformat(line)
+ outLines.append( self.Reformat(line) + '\n' )
+ outfile = file(self._OutputFilename, 'w')
+ outfile.writelines( outLines )
+ outfile.close()
+
+"""
+Parse line from a dicom3tools document, line are like this:
+
+(0003,0008) VERS="SSPI" VR="US" VM="1" Owner="SIEMENS ISI" Keyword="ISICommandField" Name="ISI Command Field"
+"""
+class Dicom3ToolsParser:
+ def __init__(self):
+ self._InputFilename = ''
+ self._OutputFilename = ''
+
+ def Reformat(self,s):
+ assert self.IsGood(s)
+ patt = re.compile("^\(([0-9a-f]+),([0-9a-f]+)\)\s+VERS=\".*\"\s+VR=\"([A-Z][A-Z])\"\s+VM=\"(.*)\"\s+Owner=\".*\"\s+Keyword=\".*\"\s+Name=\"(.*)\"$")
+ m = patt.match(s)
+ dicom = ''
+ if m:
+ # Apparently some have Name == '?', skip those
+ name = m.group(5)
+ if name != '?' and name != '? ':
+ dicom = m.group(1) + ' ' + m.group(2) + ' ' + m.group(3) + ' ' + m.group(4) + ' ' + m.group(5)
+ else:
+ print "oops"
+ else:
+ print "oops"
+ return dicom
+
+ def IsGood(self,s):
+ #patt = re.compile("^\([0-9a-f]+,[0-9a-f]+\) VERS=\".*\" VR=\"[A-Z][A-Z]\" VM=\".*\" Owner=\".*\" Keyword=\".*\" Name=\".*\"$")
+ patt = re.compile("^\([0-9a-f]+,[0-9a-f]+\)\s+VERS=\".*\"\s+VR=\"[A-Z][A-Z]\"\s+VM=\".*\"\s+Owner=\".*\"\s+Keyword=\".*\"\s+Name=\".*\".*$")
+ if patt.match(s):
+ return True
+ print "Not good:", s
+ return False
+
+ def SetInputFileName(self,s):
+ self._InputFilename = s
+
+ def SetOutputFileName(self,s):
+ self._OutputFilename = s
+
+ def Parse(self):
+ infile = file(self._InputFilename, 'r')
+ outLines = []
+ for line in infile.readlines():
+ newline = self.Reformat(line)
+ print newline
+ if newline:
+ outLines.append( newline + '\n' )
+ outfile = file(self._OutputFilename, 'w')
+ outfile.writelines( outLines )
+ outfile.close()
+
+"""
+Parse line from a PhilipsAdvance document, line are like this:
+
+GE Advance Implementation Version Name (0009,1001) 3 LO 2 n/a
+"""
+class GEAdvanceParser:
+ def __init__(self):
+ self._InputFilename = ''
+ self._OutputFilename = ''
+
+ def Reformat(self,s):
+ assert self.IsGood(s)
+ #patt = re.compile("^\(([0-9a-f]+),([0-9a-f]+)\)\s+VERS=\".*\"\s+VR=\"([A-Z][A-Z])\"\s+VM=\"(.*)\"\s+Owner=\".*\"\s+Keyword=\".*\"\s+Name=\"(.*)\"$")
+ patt = re.compile("^([A-Za-z0-9 ._>]+) \\(([0-9A-F]+),([0-9A-F]+)\\) [0-9] ([A-Z][A-Z]) ([0-9]) .*$")
+ m = patt.match(s)
+ dicom = ''
+ if m:
+ dicom = m.group(2) + ' ' + m.group(3).lower() + ' ' + m.group(4) + ' ' + m.group(5) + ' ' + m.group(1)
+ else:
+ print "oops"
+ return dicom
+
+ def IsGood(self,s):
+ #patt = re.compile("^\([0-9a-f]+,[0-9a-f]+\)\s+VERS=\".*\"\s+VR=\"[A-Z][A-Z]\"\s+VM=\".*\"\s+Owner=\".*\"\s+Keyword=\".*\"\s+Name=\".*\".*$")
+ patt = re.compile("^[A-Za-z0-9 ._>]+ \\([0-9A-F]+,[0-9A-F]+\\) [0-9] [A-Z][A-Z] [0-9] .*$")
+ if patt.match(s):
+ return True
+ print "Not good:", s
+ return False
+
+ def SetInputFileName(self,s):
+ self._InputFilename = s
+
+ def SetOutputFileName(self,s):
+ self._OutputFilename = s
+
+ def Parse(self):
+ infile = file(self._InputFilename, 'r')
+ outLines = []
+ for line in infile.readlines():
+ newline = self.Reformat(line)
+ #print newline
+ if newline:
+ outLines.append( newline + '\n' )
+ outfile = file(self._OutputFilename, 'w')
+ outfile.writelines( outLines )
+ outfile.close()
+