diff --git a/invesalius/gui/import_network_panel.py b/invesalius/gui/import_network_panel.py index 51f1042..5f9bcb7 100644 --- a/invesalius/gui/import_network_panel.py +++ b/invesalius/gui/import_network_panel.py @@ -389,12 +389,11 @@ class FindPanel(wx.Panel): sizer_txt_find = wx.BoxSizer(wx.HORIZONTAL) sizer_txt_find.Add((5, 0), 0, wx.EXPAND|wx.HORIZONTAL) - find_txt = wx.TextCtrl(self, -1,size=(225, -1)) + self.find_txt = wx.TextCtrl(self, -1,size=(225, -1)) self.btn_find = wx.Button(self, -1, _("Search")) - - sizer_txt_find.Add(find_txt) + sizer_txt_find.Add(self.find_txt) sizer_txt_find.Add(self.btn_find) self.sizer.Add((0, 5), 0, wx.EXPAND|wx.HORIZONTAL) @@ -415,6 +414,7 @@ class FindPanel(wx.Panel): self._bind_gui_evt() def __bind_evt(self): + ps.Publisher().subscribe(self.SetHostsList, 'Set FindPanel hosts list') #ps.Publisher().subscribe(self.ShowDicomSeries, 'Load dicom preview') #ps.Publisher().subscribe(self.SetDicomSeries, 'Load group into import panel') #ps.Publisher().subscribe(self.SetPatientSeries, 'Load patient into import panel') @@ -426,9 +426,26 @@ class FindPanel(wx.Panel): self.Bind(wx.EVT_BUTTON, self.OnButtonFind, self.btn_find) def OnButtonFind(self, evt): - print "clicked...." + hosts = self.GetHostList() + + for key in hosts.keys(): + if key != 0: + dn = dcm_net.DicomNet() + dn.SetHost(self.hosts[key][1]) + dn.SetPort(self.hosts[key][2]) + dn.SetAETitleCall(self.hosts[key][3]) + dn.SetAETitle(self.hosts[0][3]) + dn.SetSearchWord(self.find_txt.GetValue()) + print dn.RunCFind() + def SetHostsList(self, evt_pub): + self.hosts = evt_pub.data + + def GetHostList(self): + ps.Publisher().sendMessage('Get NodesPanel host list') + return self.hosts + class HostFindPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, -1) @@ -525,6 +542,7 @@ class NodesPanel(wx.Panel): self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.EndEdition, self.tree_node) ps.Publisher().subscribe(self.CheckItemDict, "Check item dict") + ps.Publisher().subscribe(self.GetHostsList, "Get NodesPanel host list") #ps.Publisher().subscribe(self.UnCheckItemDict, "Uncheck item dict") @@ -583,6 +601,10 @@ class NodesPanel(wx.Panel): self.SetAutoLayout(1) self.sizer = sizer + def GetHostsList(self, pub_evt): + ps.Publisher().sendMessage('Set FindPanel hosts list', self.hosts) + + def EndEdition(self, evt): index = evt.m_itemIndex item = evt.m_item @@ -637,9 +659,6 @@ class NodesPanel(wx.Panel): else: self.tree_node.SetStringItem(key, 4, _("error")) - - - def RightButton(self,evt): event.Skip() @@ -651,7 +670,6 @@ class NodesPanel(wx.Panel): if evt.m_itemIndex != 0: self.tree_node.SetDeselected(evt.m_itemIndex) - def CheckItemDict(self, evt_pub): index, flag = evt_pub.data if index != 0: diff --git a/invesalius/net/dicom.py b/invesalius/net/dicom.py index e1b8893..d1a9ace 100644 --- a/invesalius/net/dicom.py +++ b/invesalius/net/dicom.py @@ -7,6 +7,11 @@ class DicomNet: self.port = '' self.aetitle_call = '' self.aetitle = '' + self.search_word = '' + self.search_type = 'patient' + + def __call__(self): + return self def SetHost(self, address): self.address = address @@ -20,7 +25,93 @@ class DicomNet: def SetAETitle(self, ae_title): self.aetitle = ae_title + def SetSearchWord(self, word): + self.search_word = word + + def SetSearchType(self, stype): + self.search_type = stype + + def GetValueFromDICOM(self, ret, tag): + value = str(ret.GetDataElement(gdcm.Tag(tag[0],\ + tag[1])).GetValue()) + return value + + def RunCEcho(self): cnf = gdcm.CompositeNetworkFunctions() return cnf.CEcho(self.address, int(self.port),\ self.aetitle, self.aetitle_call) + + def RunCFind(self): + + tags = [(0x0010, 0x0010), (0x0010, 0x1010), (0x0010,0x0040), (0x0008,0x1030),\ + (0x0008,0x0060), (0x0008,0x0022), (0x0008,0x0080), (0x0010,0x0030),\ + (0x0008,0x0050), (0x0008,0x0090)] + + + 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': + de.SetByteValue(str(self.search_word + '*'), gdcm.VL(bit_size)) + else: + de.SetByteValue('*', gdcm.VL(1)) + + ds.Insert(de) + + + cnf = gdcm.CompositeNetworkFunctions() + theQuery = cnf.ConstructQuery(gdcm.ePatientRootType, gdcm.eImageOrFrame, ds) + ret = gdcm.DataSetArrayType() + + cnf.CFind(self.address, int(self.port), theQuery, ret, self.aetitle,\ + self.aetitle_call) + + patients = {} + + exist_images = False + c = 0 + for i in range(0,ret.size()): + patient_id = str(ret[i].GetDataElement(gdcm.Tag(0x0010, 0x0020)).GetValue()) + serie_id = str(ret[i].GetDataElement(gdcm.Tag(0x0020, 0x000e)).GetValue()) + + if not(patient_id in patients.keys()): + patients[patient_id] = {} + + + if not(serie_id in patients[patient_id]): + + 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))) + + patients[patient_id][serie_id] = {'name':name, 'age':age, 'gender':gender,\ + 'study_description':study_description,\ + 'modality':modality, \ + 'date_acquision':date_acquisition,\ + 'institution':institution,\ + 'date_of_birth':date_of_birth,\ + 'acession_number':acession_number,\ + 'ref_physician':ref_physician} + + patients[patient_id][serie_id]['n_images'] = 1 + else: + patients[patient_id][serie_id]['n_images'] += 1 + diff --git a/invesalius/reader/dicom_reader.py b/invesalius/reader/dicom_reader.py index 768725d..ea53101 100644 --- a/invesalius/reader/dicom_reader.py +++ b/invesalius/reader/dicom_reader.py @@ -125,7 +125,10 @@ class LoadDicom: encoding = "ISO_IR 100" else: encoding = const.DICOM_ENCODING_TO_PYTHON[encoding_value] - + else: + encoding = "ISO_IR 100" + + # Iterate through the Header iterator = header.GetDES().begin() while (not iterator.equal(header.GetDES().end())): -- libgit2 0.21.2