Commit 04c353392e49f727e3b9929ec60e7460f3e12d25
1 parent
077895cd
Exists in
master
and in
68 other branches
FIX: Bug parser datetime
Showing
2 changed files
with
37 additions
and
14 deletions
Show diff stats
invesalius/reader/dicom.py
@@ -1416,21 +1416,31 @@ class Parser(): | @@ -1416,21 +1416,31 @@ class Parser(): | ||
1416 | return "" | 1416 | return "" |
1417 | 1417 | ||
1418 | def __format_time(self,value): | 1418 | def __format_time(self,value): |
1419 | + sp1 = value.split(".") | ||
1420 | + sp2 = value.split(":") | ||
1419 | 1421 | ||
1420 | - if (len(value.split(".")) == 2): | 1422 | + if (len(sp1) == 2) and (len(sp2) == 3): |
1423 | + new_value = str(sp2[0]+sp2[1]+ | ||
1424 | + str(int(float(sp2[2])))) | ||
1425 | + data = time.strptime(new_value, "%H%M%S") | ||
1426 | + elif (len(sp1) == 2): | ||
1421 | data = time.gmtime(float(value)) | 1427 | data = time.gmtime(float(value)) |
1422 | - elif (len(value.split(".")) > 2): | 1428 | + elif (len(sp1) > 2): |
1423 | data = time.strptime(value, "%H.%M.%S") | 1429 | data = time.strptime(value, "%H.%M.%S") |
1424 | - elif(len(value.split(":")) > 1): | 1430 | + elif(len(sp2) > 1): |
1425 | data = time.strptime(value, "%H:%M:%S") | 1431 | data = time.strptime(value, "%H:%M:%S") |
1426 | else: | 1432 | else: |
1427 | data = time.strptime(value, "%H%M%S") | 1433 | data = time.strptime(value, "%H%M%S") |
1428 | return time.strftime("%H:%M:%S",data) | 1434 | return time.strftime("%H:%M:%S",data) |
1429 | 1435 | ||
1430 | def __format_date(self, value): | 1436 | def __format_date(self, value): |
1431 | - | ||
1432 | - if (len(value.split(".")) > 1): | ||
1433 | - data = time.strptime(value, "%D.%M.%Y") | 1437 | + |
1438 | + sp1 = value.split(".") | ||
1439 | + if (len(sp1) > 1): | ||
1440 | + if (len(sp1[0]) <= 2): | ||
1441 | + data = time.strptime(value, "%D.%M.%Y") | ||
1442 | + else: | ||
1443 | + data = time.strptime(value, "%Y.%M.%d") | ||
1434 | elif(len(value.split("//")) > 1): | 1444 | elif(len(value.split("//")) > 1): |
1435 | data = time.strptime(value, "%D/%M/%Y") | 1445 | data = time.strptime(value, "%D/%M/%Y") |
1436 | else: | 1446 | else: |
@@ -1450,7 +1460,18 @@ class Parser(): | @@ -1450,7 +1460,18 @@ class Parser(): | ||
1450 | return self.__format_time(data) | 1460 | return self.__format_time(data) |
1451 | return "" | 1461 | return "" |
1452 | 1462 | ||
1453 | - | 1463 | + def GetSerieNumber(self): |
1464 | + """ | ||
1465 | + Return the serie number | ||
1466 | + DICOM standard tag (0x0020, 0x0011) was used. | ||
1467 | + """ | ||
1468 | + tag = gdcm.Tag(0x0020, 0x0011) | ||
1469 | + ds = self.gdcm_reader.GetFile().GetDataSet() | ||
1470 | + if ds.FindDataElement(tag): | ||
1471 | + data = str(ds.GetDataElement(tag).GetValue()) | ||
1472 | + if (data): | ||
1473 | + return data | ||
1474 | + return "" | ||
1454 | 1475 | ||
1455 | 1476 | ||
1456 | class DicomWriter: | 1477 | class DicomWriter: |
@@ -1622,7 +1643,7 @@ class DicomWriter: | @@ -1622,7 +1643,7 @@ class DicomWriter: | ||
1622 | str(institution)) | 1643 | str(institution)) |
1623 | 1644 | ||
1624 | 1645 | ||
1625 | - | 1646 | + |
1626 | 1647 | ||
1627 | 1648 | ||
1628 | 1649 | ||
@@ -1769,6 +1790,7 @@ class Acquisition(object): | @@ -1769,6 +1790,7 @@ class Acquisition(object): | ||
1769 | self.series_description = parser.GetSeriesDescription() | 1790 | self.series_description = parser.GetSeriesDescription() |
1770 | self.time = parser.GetAcquisitionTime() | 1791 | self.time = parser.GetAcquisitionTime() |
1771 | self.protocol_name = parser.GetProtocolName() | 1792 | self.protocol_name = parser.GetProtocolName() |
1793 | + self.serie_number = parser.GetSerieNumber() | ||
1772 | 1794 | ||
1773 | class Image(object): | 1795 | class Image(object): |
1774 | 1796 |
invesalius/reader/dicom_grouper.py
@@ -278,30 +278,31 @@ class DicomGroups: | @@ -278,30 +278,31 @@ class DicomGroups: | ||
278 | #for each item on the list is created | 278 | #for each item on the list is created |
279 | #a new position in the dictionary. | 279 | #a new position in the dictionary. |
280 | size_tmp_list = len(tmp_list) | 280 | size_tmp_list = len(tmp_list) |
281 | - | 281 | + |
282 | for x in xrange(size_tmp_list): | 282 | for x in xrange(size_tmp_list): |
283 | 283 | ||
284 | tmp1 = tmp_list[x] | 284 | tmp1 = tmp_list[x] |
285 | + | ||
285 | 286 | ||
286 | for m in xrange(len(tmp1.keys())): | 287 | for m in xrange(len(tmp1.keys())): |
287 | 288 | ||
288 | key = tmp1.keys()[m] | 289 | key = tmp1.keys()[m] |
289 | information = tmp1[key] | 290 | information = tmp1[key] |
290 | - new_key = (information.patient.name, None, x, information.image.orientation_label, information.acquisition.time) | ||
291 | - | ||
292 | - | ||
293 | - list = [information] | 291 | + new_key = (information.patient.name, information.image.orientation_label, |
292 | + information.acquisition.serie_number) | ||
294 | 293 | ||
294 | + | ||
295 | if (new_key in groups_dcm_.keys()): | 295 | if (new_key in groups_dcm_.keys()): |
296 | groups_dcm_[new_key][0].append(information) | 296 | groups_dcm_[new_key][0].append(information) |
297 | else: | 297 | else: |
298 | groups_dcm_[new_key] = [[information]] | 298 | groups_dcm_[new_key] = [[information]] |
299 | - | 299 | + |
300 | #the number of previously existing number is | 300 | #the number of previously existing number is |
301 | #greater or equal then the group keeps up, | 301 | #greater or equal then the group keeps up, |
302 | #but maintains the same group of positions. | 302 | #but maintains the same group of positions. |
303 | if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()): | 303 | if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()): |
304 | self.groups_dcm = groups_dcm_ | 304 | self.groups_dcm = groups_dcm_ |
305 | + | ||
305 | 306 | ||
306 | for j in xrange(len(self.groups_dcm.keys())): | 307 | for j in xrange(len(self.groups_dcm.keys())): |
307 | key = self.groups_dcm.keys()[j] | 308 | key = self.groups_dcm.keys()[j] |