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 | 1416 | return "" |
1417 | 1417 | |
1418 | 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 | 1427 | data = time.gmtime(float(value)) |
1422 | - elif (len(value.split(".")) > 2): | |
1428 | + elif (len(sp1) > 2): | |
1423 | 1429 | data = time.strptime(value, "%H.%M.%S") |
1424 | - elif(len(value.split(":")) > 1): | |
1430 | + elif(len(sp2) > 1): | |
1425 | 1431 | data = time.strptime(value, "%H:%M:%S") |
1426 | 1432 | else: |
1427 | 1433 | data = time.strptime(value, "%H%M%S") |
1428 | 1434 | return time.strftime("%H:%M:%S",data) |
1429 | 1435 | |
1430 | 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 | 1444 | elif(len(value.split("//")) > 1): |
1435 | 1445 | data = time.strptime(value, "%D/%M/%Y") |
1436 | 1446 | else: |
... | ... | @@ -1450,7 +1460,18 @@ class Parser(): |
1450 | 1460 | return self.__format_time(data) |
1451 | 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 | 1477 | class DicomWriter: |
... | ... | @@ -1622,7 +1643,7 @@ class DicomWriter: |
1622 | 1643 | str(institution)) |
1623 | 1644 | |
1624 | 1645 | |
1625 | - | |
1646 | + | |
1626 | 1647 | |
1627 | 1648 | |
1628 | 1649 | |
... | ... | @@ -1769,6 +1790,7 @@ class Acquisition(object): |
1769 | 1790 | self.series_description = parser.GetSeriesDescription() |
1770 | 1791 | self.time = parser.GetAcquisitionTime() |
1771 | 1792 | self.protocol_name = parser.GetProtocolName() |
1793 | + self.serie_number = parser.GetSerieNumber() | |
1772 | 1794 | |
1773 | 1795 | class Image(object): |
1774 | 1796 | ... | ... |
invesalius/reader/dicom_grouper.py
... | ... | @@ -278,30 +278,31 @@ class DicomGroups: |
278 | 278 | #for each item on the list is created |
279 | 279 | #a new position in the dictionary. |
280 | 280 | size_tmp_list = len(tmp_list) |
281 | - | |
281 | + | |
282 | 282 | for x in xrange(size_tmp_list): |
283 | 283 | |
284 | 284 | tmp1 = tmp_list[x] |
285 | + | |
285 | 286 | |
286 | 287 | for m in xrange(len(tmp1.keys())): |
287 | 288 | |
288 | 289 | key = tmp1.keys()[m] |
289 | 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 | 295 | if (new_key in groups_dcm_.keys()): |
296 | 296 | groups_dcm_[new_key][0].append(information) |
297 | 297 | else: |
298 | 298 | groups_dcm_[new_key] = [[information]] |
299 | - | |
299 | + | |
300 | 300 | #the number of previously existing number is |
301 | 301 | #greater or equal then the group keeps up, |
302 | 302 | #but maintains the same group of positions. |
303 | 303 | if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()): |
304 | 304 | self.groups_dcm = groups_dcm_ |
305 | + | |
305 | 306 | |
306 | 307 | for j in xrange(len(self.groups_dcm.keys())): |
307 | 308 | key = self.groups_dcm.keys()[j] | ... | ... |