From 04c353392e49f727e3b9929ec60e7460f3e12d25 Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Wed, 7 Oct 2009 14:21:00 +0000 Subject: [PATCH] FIX: Bug parser datetime --- invesalius/reader/dicom.py | 38 ++++++++++++++++++++++++++++++-------- invesalius/reader/dicom_grouper.py | 13 +++++++------ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/invesalius/reader/dicom.py b/invesalius/reader/dicom.py index fc7d5eb..1a934d2 100644 --- a/invesalius/reader/dicom.py +++ b/invesalius/reader/dicom.py @@ -1416,21 +1416,31 @@ class Parser(): return "" def __format_time(self,value): + sp1 = value.split(".") + sp2 = value.split(":") - if (len(value.split(".")) == 2): + if (len(sp1) == 2) and (len(sp2) == 3): + new_value = str(sp2[0]+sp2[1]+ + str(int(float(sp2[2])))) + data = time.strptime(new_value, "%H%M%S") + elif (len(sp1) == 2): data = time.gmtime(float(value)) - elif (len(value.split(".")) > 2): + elif (len(sp1) > 2): data = time.strptime(value, "%H.%M.%S") - elif(len(value.split(":")) > 1): + elif(len(sp2) > 1): data = time.strptime(value, "%H:%M:%S") else: data = time.strptime(value, "%H%M%S") return time.strftime("%H:%M:%S",data) def __format_date(self, value): - - if (len(value.split(".")) > 1): - data = time.strptime(value, "%D.%M.%Y") + + sp1 = value.split(".") + if (len(sp1) > 1): + if (len(sp1[0]) <= 2): + data = time.strptime(value, "%D.%M.%Y") + else: + data = time.strptime(value, "%Y.%M.%d") elif(len(value.split("//")) > 1): data = time.strptime(value, "%D/%M/%Y") else: @@ -1450,7 +1460,18 @@ class Parser(): return self.__format_time(data) return "" - + def GetSerieNumber(self): + """ + Return the serie number + DICOM standard tag (0x0020, 0x0011) was used. + """ + tag = gdcm.Tag(0x0020, 0x0011) + ds = self.gdcm_reader.GetFile().GetDataSet() + if ds.FindDataElement(tag): + data = str(ds.GetDataElement(tag).GetValue()) + if (data): + return data + return "" class DicomWriter: @@ -1622,7 +1643,7 @@ class DicomWriter: str(institution)) - + @@ -1769,6 +1790,7 @@ class Acquisition(object): self.series_description = parser.GetSeriesDescription() self.time = parser.GetAcquisitionTime() self.protocol_name = parser.GetProtocolName() + self.serie_number = parser.GetSerieNumber() class Image(object): diff --git a/invesalius/reader/dicom_grouper.py b/invesalius/reader/dicom_grouper.py index 8c7d5a4..c502ada 100644 --- a/invesalius/reader/dicom_grouper.py +++ b/invesalius/reader/dicom_grouper.py @@ -278,30 +278,31 @@ class DicomGroups: #for each item on the list is created #a new position in the dictionary. size_tmp_list = len(tmp_list) - + for x in xrange(size_tmp_list): tmp1 = tmp_list[x] + for m in xrange(len(tmp1.keys())): key = tmp1.keys()[m] information = tmp1[key] - new_key = (information.patient.name, None, x, information.image.orientation_label, information.acquisition.time) - - - list = [information] + new_key = (information.patient.name, information.image.orientation_label, + information.acquisition.serie_number) + if (new_key in groups_dcm_.keys()): groups_dcm_[new_key][0].append(information) else: groups_dcm_[new_key] = [[information]] - + #the number of previously existing number is #greater or equal then the group keeps up, #but maintains the same group of positions. if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()): self.groups_dcm = groups_dcm_ + for j in xrange(len(self.groups_dcm.keys())): key = self.groups_dcm.keys()[j] -- libgit2 0.21.2