Commit f3bf427920feac1e8264c46aa7ece08300fef0dc

Authored by Paulo Henrique Junqueira Amorim
1 parent 2b4b1746

FIX: Error getting date from dicom (case \_other\DICOM Dornelas\)

Showing 1 changed file with 15 additions and 9 deletions   Show diff stats
invesalius/reader/dicom.py
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais 17 # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
18 # detalhes. 18 # detalhes.
19 #--------------------------------------------------------------------- 19 #---------------------------------------------------------------------
  20 +from numpy.lib import type_check
20 21
21 # In DICOM file format, if multiple values are present for the 22 # In DICOM file format, if multiple values are present for the
22 # "Window Center" (Level) and "Window Width", both attributes 23 # "Window Center" (Level) and "Window Width", both attributes
@@ -1438,16 +1439,21 @@ class Parser(): @@ -1438,16 +1439,21 @@ class Parser():
1438 def __format_date(self, value): 1439 def __format_date(self, value):
1439 1440
1440 sp1 = value.split(".") 1441 sp1 = value.split(".")
1441 - if (len(sp1) > 1):  
1442 - if (len(sp1[0]) <= 2):  
1443 - data = time.strptime(value, "%D.%M.%Y") 1442 + try:
  1443 +
  1444 + if (len(sp1) > 1):
  1445 + if (len(sp1[0]) <= 2):
  1446 + data = time.strptime(value, "%D.%M.%Y")
  1447 + else:
  1448 + data = time.strptime(value, "%Y.%M.%d")
  1449 + elif(len(value.split("//")) > 1):
  1450 + data = time.strptime(value, "%D/%M/%Y")
1444 else: 1451 else:
1445 - data = time.strptime(value, "%Y.%M.%d")  
1446 - elif(len(value.split("//")) > 1):  
1447 - data = time.strptime(value, "%D/%M/%Y")  
1448 - else:  
1449 - data = time.strptime(value, "%Y%M%d")  
1450 - return time.strftime("%d/%M/%Y",data) 1452 + data = time.strptime(value, "%Y%M%d")
  1453 + return time.strftime("%d/%M/%Y",data)
  1454 +
  1455 + except(ValueError):
  1456 + return ""
1451 1457
1452 def GetAcquisitionTime(self): 1458 def GetAcquisitionTime(self):
1453 """ 1459 """