Commit 0525da39347a5282dbb8545d03faf3fcca124db1

Authored by Paulo Henrique Junqueira Amorim
1 parent ef8fe454

ENH: Date and Time Formated

Showing 1 changed file with 29 additions and 16 deletions   Show diff stats
invesalius/reader/dicom.py
1 #--------------------------------------------------------------------- 1 #---------------------------------------------------------------------
2 # Software: InVesalius Software de Reconstrucao 3D de Imagens Medicas 2 # Software: InVesalius Software de Reconstrucao 3D de Imagens Medicas
3 -  
4 # Copyright: (c) 2001 Centro de Pesquisas Renato Archer 3 # Copyright: (c) 2001 Centro de Pesquisas Renato Archer
5 # Homepage: http://www.softwarepublico.gov.br 4 # Homepage: http://www.softwarepublico.gov.br
6 # Contact: invesalius@cenpra.gov.br 5 # Contact: invesalius@cenpra.gov.br
@@ -70,6 +69,7 @@ INFO_KEYS = \ @@ -70,6 +69,7 @@ INFO_KEYS = \
70 69
71 import vtkgdcm 70 import vtkgdcm
72 import gdcm 71 import gdcm
  72 +import time
73 73
74 class Parser(): 74 class Parser():
75 """ 75 """
@@ -90,7 +90,7 @@ class Parser(): @@ -90,7 +90,7 @@ class Parser():
90 def __init__(self): 90 def __init__(self):
91 self.filename = "" 91 self.filename = ""
92 self.vtkgdcm_reader = vtkgdcm.vtkGDCMImageReader() 92 self.vtkgdcm_reader = vtkgdcm.vtkGDCMImageReader()
93 - 93 +
94 def GetAcquisitionDate(self): 94 def GetAcquisitionDate(self):
95 """ 95 """
96 Return string containing the acquisition date using the 96 Return string containing the acquisition date using the
@@ -103,10 +103,7 @@ class Parser(): @@ -103,10 +103,7 @@ class Parser():
103 date = self.vtkgdcm_reader.GetMedicalImageProperties()\ 103 date = self.vtkgdcm_reader.GetMedicalImageProperties()\
104 .GetAcquisitionDate() 104 .GetAcquisitionDate()
105 if (date): 105 if (date):
106 - year = date[0:4]  
107 - month = date[4:6]  
108 - day = date[6:8]  
109 - return day + "/" + month + "/" + year 106 + return self.__format_date(date)
110 return "" 107 return ""
111 108
112 def GetAcquisitionNumber(self): 109 def GetAcquisitionNumber(self):
@@ -149,10 +146,7 @@ class Parser(): @@ -149,10 +146,7 @@ class Parser():
149 time = self.vtkgdcm_reader.GetMedicalImageProperties()\ 146 time = self.vtkgdcm_reader.GetMedicalImageProperties()\
150 .GetAcquisitionTime() 147 .GetAcquisitionTime()
151 if (time): 148 if (time):
152 - hh = time[0:2]  
153 - mm = time[2:4]  
154 - ss = time[4:6]  
155 - return hh + ":" + mm + ":" + ss 149 + return self.__format_time(time)
156 return "" 150 return ""
157 151
158 def GetPatientAdmittingDiagnosis(self): 152 def GetPatientAdmittingDiagnosis(self):
@@ -1055,10 +1049,7 @@ class Parser(): @@ -1055,10 +1049,7 @@ class Parser():
1055 date = self.vtkgdcm_reader.GetMedicalImageProperties()\ 1049 date = self.vtkgdcm_reader.GetMedicalImageProperties()\
1056 .GetPatientBirthDate() 1050 .GetPatientBirthDate()
1057 if (date): 1051 if (date):
1058 - year = date[0:4]  
1059 - month = date[4:6]  
1060 - day = date[6:8]  
1061 - return day + "/" + month + "/" + year 1052 + self.__format_date(date)
1062 return "" 1053 return ""
1063 1054
1064 1055
@@ -1421,9 +1412,31 @@ class Parser(): @@ -1421,9 +1412,31 @@ class Parser():
1421 if ds.FindDataElement(tag): 1412 if ds.FindDataElement(tag):
1422 data = str(ds.GetDataElement(tag).GetValue()) 1413 data = str(ds.GetDataElement(tag).GetValue())
1423 if (data): 1414 if (data):
1424 - return data 1415 + return self.__format_time(data)
1425 return "" 1416 return ""
1426 1417
  1418 + def __format_time(self,value):
  1419 + if (len(value.split(".")) > 1):
  1420 + data = time.strptime(value, "%H.%M.%S")
  1421 + elif(len(value.split(":")) > 1):
  1422 + data = time.strptime(value, "%H:%M:%S")
  1423 + else:
  1424 + data = time.strptime(value, "%H%M%S")
  1425 + return time.strftime("%H:%M:%S",data)
  1426 +
  1427 + def __format_date(self, value):
  1428 +
  1429 + if (len(value.split(".")) > 1):
  1430 + data = time.strptime(value, "%D.%M.%Y")
  1431 + elif(len(value.split("//")) > 1):
  1432 + data = time.strptime(value, "%D/%M/%Y")
  1433 + else:
  1434 + data = time.strptime(value, "%Y%M%d")
  1435 +
  1436 + print time.strftime("%d/%M/%Y",data)
  1437 +
  1438 + return time.strftime("%d/%M/%Y",data)
  1439 +
1427 def GetAcquisitionTime(self): 1440 def GetAcquisitionTime(self):
1428 """ 1441 """
1429 Return the acquisition time. 1442 Return the acquisition time.
@@ -1434,7 +1447,7 @@ class Parser(): @@ -1434,7 +1447,7 @@ class Parser():
1434 if ds.FindDataElement(tag): 1447 if ds.FindDataElement(tag):
1435 data = str(ds.GetDataElement(tag).GetValue()) 1448 data = str(ds.GetDataElement(tag).GetValue())
1436 if (data): 1449 if (data):
1437 - return data 1450 + return self.__format_time(data)
1438 return "" 1451 return ""
1439 1452
1440 1453