diff --git a/invesalius/gui/import_network_panel.py b/invesalius/gui/import_network_panel.py index 5f9bcb7..f136d52 100644 --- a/invesalius/gui/import_network_panel.py +++ b/invesalius/gui/import_network_panel.py @@ -219,7 +219,7 @@ class TextPanel(wx.Panel): def __bind_pubsub_evt(self): #ps.Publisher().subscribe(self.SelectSeries, 'Select series in import panel') - pass + ps.Publisher().subscribe(self.Populate, 'Populate tree') def __bind_events_wx(self): self.Bind(wx.EVT_SIZE, self.OnSize) @@ -268,10 +268,83 @@ class TextPanel(wx.Panel): def SelectSeries(self, pubsub_evt): group_index = pubsub_evt.data - def Populate(self, patient_list): + def Populate(self, pubsub_evt): tree = self.tree + #print ">>>>>>>>>>>>>>>>>>>>>>>>>>", dir(tree.GetRootItem()) + #print ">>>>>>>>>>>>",dir(self.tree) + patients = pubsub_evt.data first = 0 + self.idserie_treeitem = {} + + for patient in patients.keys(): + + + #ngroups = patient.ngroups + #dicom = patient.GetDicomSample() + #title = dicom.patient.name + " (%d series)"%(ngroups) + #date_time = "%s %s"%(dicom.acquisition.date, + # dicom.acquisition.time) + + first_serie = patients[patient].keys()[0] + title = patients[patient][first_serie]['name'] + p = patients[patient][first_serie] + + p_id = patient + age = p['age'] + gender = p['gender'] + study_description = p['study_description'] + modality = p['modality'] + date = p['acquisition_date'] + time = p['acquisition_time'] + institution = p['institution'] + birthdate = p['date_of_birth'] + acession_number = p['acession_number'] + physician = p['ref_physician'] + + parent = tree.AppendItem(self.root, title) + + n_amount_images = 0 + for se in patients[patient]: + n_amount_images = n_amount_images + patients[patient][se]['n_images'] + + + tree.SetItemPyData(parent, patient) + tree.SetItemText(parent, "%s" % p_id, 1) + tree.SetItemText(parent, "%s" % age, 2) + tree.SetItemText(parent, "%s" % gender, 3) + tree.SetItemText(parent, "%s" % study_description, 4) + tree.SetItemText(parent, "%s" % modality, 5) + tree.SetItemText(parent, "%s" % date + " " + time, 6) + tree.SetItemText(parent, "%s" % str(n_amount_images), 7) + tree.SetItemText(parent, "%s" % institution, 8) + tree.SetItemText(parent, "%s" % birthdate, 9) + tree.SetItemText(parent, "%s" % acession_number, 10) + tree.SetItemText(parent, "%s" % physician, 11) + + + + for series in patients[patient].keys(): + + serie_description = patients[patient][series]['serie_description'] + n_images = patients[patient][series]['n_images'] + date = patients[patient][series]['acquisition_date'] + time = patients[patient][series]['acquisition_time'] + + child = tree.AppendItem(parent, serie_description) + tree.SetItemPyData(child, series) + + tree.SetItemText(child, "%s" % serie_description, 0) + #tree.SetItemText(child, "%s" % dicom.acquisition.protocol_name, 4) + #tree.SetItemText(child, "%s" % dicom.acquisition.modality, 5) + tree.SetItemText(child, "%s" % date + " " + time, 6) + tree.SetItemText(child, "%s" % n_images , 7) + + self.idserie_treeitem[child] = (patient, series) + + + """ + for patient in patient_list: if not isinstance(patient, dcm.PatientGroup): return None @@ -319,7 +392,7 @@ class TextPanel(wx.Panel): tree.Expand(self.root) tree.SelectItem(parent_select) tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate) - tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged) + tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged)""" def OnSelChanged(self, evt): item = self.tree.GetSelection() @@ -436,7 +509,8 @@ class FindPanel(wx.Panel): dn.SetAETitleCall(self.hosts[key][3]) dn.SetAETitle(self.hosts[0][3]) dn.SetSearchWord(self.find_txt.GetValue()) - print dn.RunCFind() + + ps.Publisher().sendMessage('Populate tree', dn.RunCFind()) def SetHostsList(self, evt_pub): diff --git a/invesalius/net/dicom.py b/invesalius/net/dicom.py index c8f0f97..9a22643 100644 --- a/invesalius/net/dicom.py +++ b/invesalius/net/dicom.py @@ -1,4 +1,6 @@ import gdcm +import utils + class DicomNet: @@ -34,6 +36,8 @@ class DicomNet: def GetValueFromDICOM(self, ret, tag): value = str(ret.GetDataElement(gdcm.Tag(tag[0],\ tag[1])).GetValue()) + if value == 'None' and tag != (0x0008,0x103E): + value = '' return value @@ -46,20 +50,22 @@ class DicomNet: tags = [(0x0010, 0x0010), (0x0010, 0x1010), (0x0010,0x0040), (0x0008,0x1030),\ (0x0008,0x0060), (0x0008,0x0022), (0x0008,0x0080), (0x0010,0x0030),\ - (0x0008,0x0050), (0x0008,0x0090)] + (0x0008,0x0050), (0x0008,0x0090), (0x0008,0x103E), (0x0008,0x0033),\ + (0x0008,0x0032)] ds = gdcm.DataSet() for tag in tags: - bit_size = len(self.search_word) + 1 tg = gdcm.Tag(tag[0], tag[1]) de = gdcm.DataElement(tg) - if self.search_type == 'patient': + if self.search_type == 'patient' and tag == (0x0010, 0x0010): + + bit_size = len(self.search_word) + 1 de.SetByteValue(str(self.search_word + '*'), gdcm.VL(bit_size)) else: de.SetByteValue('*', gdcm.VL(1)) @@ -90,26 +96,29 @@ class DicomNet: rt = ret[i] - - name = self.GetValueFromDICOM(rt, ((0x0010, 0x0010))) - age = self.GetValueFromDICOM(rt, ((0x0010, 0x1010))) - gender = self.GetValueFromDICOM(rt, ((0x0010),(0x0040))) - study_description = self.GetValueFromDICOM(rt, ((0x0008),(0x1030))) - modality = self.GetValueFromDICOM(rt, ((0x0008),(0x0060))) - date_acquisition = self.GetValueFromDICOM(rt, ((0x0008),(0x0022))) - institution = self.GetValueFromDICOM(rt, ((0x0008),(0x0080))) - date_of_birth = self.GetValueFromDICOM(rt, ((0x0010),(0x0030))) - acession_number = self.GetValueFromDICOM(rt, ((0x0008),(0x0050))) - ref_physician = self.GetValueFromDICOM(rt, ((0x0008),(0x0090))) + name = self.GetValueFromDICOM(rt, (0x0010, 0x0010)) + age = self.GetValueFromDICOM(rt, (0x0010, 0x1010)) + gender = self.GetValueFromDICOM(rt, (0x0010,0x0040)) + study_description = self.GetValueFromDICOM(rt, (0x0008,0x1030)) + modality = self.GetValueFromDICOM(rt, (0x0008,0x0060)) + institution = self.GetValueFromDICOM(rt, (0x0008,0x0080)) + date_of_birth = utils.format_date(self.GetValueFromDICOM(rt, (0x0010,0x0030))) + acession_number = self.GetValueFromDICOM(rt, (0x0008,0x0050)) + ref_physician = self.GetValueFromDICOM(rt, (0x0008,0x0090)) + serie_description = self.GetValueFromDICOM(rt, (0x0008,0x103E)) + acquisition_time = utils.format_time(self.GetValueFromDICOM(rt, (0x0008,0x0032))) + acquisition_date = utils.format_date(self.GetValueFromDICOM(rt, (0x0008,0x0022))) patients[patient_id][serie_id] = {'name':name, 'age':age, 'gender':gender,\ 'study_description':study_description,\ 'modality':modality, \ - 'date_acquision':date_acquisition,\ + 'acquisition_time':acquisition_time,\ + 'acquisition_date':acquisition_date,\ 'institution':institution,\ 'date_of_birth':date_of_birth,\ 'acession_number':acession_number,\ - 'ref_physician':ref_physician} + 'ref_physician':ref_physician,\ + 'serie_description':serie_description} patients[patient_id][serie_id]['n_images'] = 1 else: diff --git a/invesalius/utils.py b/invesalius/utils.py index 5b1d92a..02c192e 100755 --- a/invesalius/utils.py +++ b/invesalius/utils.py @@ -17,11 +17,53 @@ # detalhes. #-------------------------------------------------------------------------- import platform +import time import sigar import sys import re import locale +def format_time(value): + sp1 = value.split(".") + sp2 = value.split(":") + + 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(sp1) > 2): + data = time.strptime(value, "%H.%M.%S") + elif(len(sp2) > 1): + data = time.strptime(value, "%H:%M:%S") + else: + try: + data = time.strptime(value, "%H%M%S") + # If the time is not in a bad format only return it. + except ValueError: + return value + return time.strftime("%H:%M:%S",data) + +def format_date(value): + + sp1 = value.split(".") + try: + + 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: + data = time.strptime(value, "%Y%M%d") + return time.strftime("%d/%M/%Y",data) + + except(ValueError): + return "" + def debug(error_str): """ Redirects output to file, or to the terminal -- libgit2 0.21.2