Commit 53293b76a35f96c1806b4110485cc5b62fe3f493
1 parent
e7bf8988
Exists in
master
and in
67 other branches
FIX: Fixed encoding problem
Showing
3 changed files
with
121 additions
and
9 deletions
Show diff stats
invesalius/gui/import_network_panel.py
@@ -389,12 +389,11 @@ class FindPanel(wx.Panel): | @@ -389,12 +389,11 @@ class FindPanel(wx.Panel): | ||
389 | 389 | ||
390 | sizer_txt_find = wx.BoxSizer(wx.HORIZONTAL) | 390 | sizer_txt_find = wx.BoxSizer(wx.HORIZONTAL) |
391 | sizer_txt_find.Add((5, 0), 0, wx.EXPAND|wx.HORIZONTAL) | 391 | sizer_txt_find.Add((5, 0), 0, wx.EXPAND|wx.HORIZONTAL) |
392 | - find_txt = wx.TextCtrl(self, -1,size=(225, -1)) | 392 | + self.find_txt = wx.TextCtrl(self, -1,size=(225, -1)) |
393 | 393 | ||
394 | self.btn_find = wx.Button(self, -1, _("Search")) | 394 | self.btn_find = wx.Button(self, -1, _("Search")) |
395 | - | ||
396 | 395 | ||
397 | - sizer_txt_find.Add(find_txt) | 396 | + sizer_txt_find.Add(self.find_txt) |
398 | sizer_txt_find.Add(self.btn_find) | 397 | sizer_txt_find.Add(self.btn_find) |
399 | 398 | ||
400 | self.sizer.Add((0, 5), 0, wx.EXPAND|wx.HORIZONTAL) | 399 | self.sizer.Add((0, 5), 0, wx.EXPAND|wx.HORIZONTAL) |
@@ -415,6 +414,7 @@ class FindPanel(wx.Panel): | @@ -415,6 +414,7 @@ class FindPanel(wx.Panel): | ||
415 | self._bind_gui_evt() | 414 | self._bind_gui_evt() |
416 | 415 | ||
417 | def __bind_evt(self): | 416 | def __bind_evt(self): |
417 | + ps.Publisher().subscribe(self.SetHostsList, 'Set FindPanel hosts list') | ||
418 | #ps.Publisher().subscribe(self.ShowDicomSeries, 'Load dicom preview') | 418 | #ps.Publisher().subscribe(self.ShowDicomSeries, 'Load dicom preview') |
419 | #ps.Publisher().subscribe(self.SetDicomSeries, 'Load group into import panel') | 419 | #ps.Publisher().subscribe(self.SetDicomSeries, 'Load group into import panel') |
420 | #ps.Publisher().subscribe(self.SetPatientSeries, 'Load patient into import panel') | 420 | #ps.Publisher().subscribe(self.SetPatientSeries, 'Load patient into import panel') |
@@ -426,9 +426,26 @@ class FindPanel(wx.Panel): | @@ -426,9 +426,26 @@ class FindPanel(wx.Panel): | ||
426 | self.Bind(wx.EVT_BUTTON, self.OnButtonFind, self.btn_find) | 426 | self.Bind(wx.EVT_BUTTON, self.OnButtonFind, self.btn_find) |
427 | 427 | ||
428 | def OnButtonFind(self, evt): | 428 | def OnButtonFind(self, evt): |
429 | - print "clicked...." | 429 | + hosts = self.GetHostList() |
430 | + | ||
431 | + for key in hosts.keys(): | ||
432 | + if key != 0: | ||
433 | + dn = dcm_net.DicomNet() | ||
434 | + dn.SetHost(self.hosts[key][1]) | ||
435 | + dn.SetPort(self.hosts[key][2]) | ||
436 | + dn.SetAETitleCall(self.hosts[key][3]) | ||
437 | + dn.SetAETitle(self.hosts[0][3]) | ||
438 | + dn.SetSearchWord(self.find_txt.GetValue()) | ||
439 | + print dn.RunCFind() | ||
430 | 440 | ||
431 | 441 | ||
442 | + def SetHostsList(self, evt_pub): | ||
443 | + self.hosts = evt_pub.data | ||
444 | + | ||
445 | + def GetHostList(self): | ||
446 | + ps.Publisher().sendMessage('Get NodesPanel host list') | ||
447 | + return self.hosts | ||
448 | + | ||
432 | class HostFindPanel(wx.Panel): | 449 | class HostFindPanel(wx.Panel): |
433 | def __init__(self, parent): | 450 | def __init__(self, parent): |
434 | wx.Panel.__init__(self, parent, -1) | 451 | wx.Panel.__init__(self, parent, -1) |
@@ -525,6 +542,7 @@ class NodesPanel(wx.Panel): | @@ -525,6 +542,7 @@ class NodesPanel(wx.Panel): | ||
525 | self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.EndEdition, self.tree_node) | 542 | self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.EndEdition, self.tree_node) |
526 | 543 | ||
527 | ps.Publisher().subscribe(self.CheckItemDict, "Check item dict") | 544 | ps.Publisher().subscribe(self.CheckItemDict, "Check item dict") |
545 | + ps.Publisher().subscribe(self.GetHostsList, "Get NodesPanel host list") | ||
528 | #ps.Publisher().subscribe(self.UnCheckItemDict, "Uncheck item dict") | 546 | #ps.Publisher().subscribe(self.UnCheckItemDict, "Uncheck item dict") |
529 | 547 | ||
530 | 548 | ||
@@ -583,6 +601,10 @@ class NodesPanel(wx.Panel): | @@ -583,6 +601,10 @@ class NodesPanel(wx.Panel): | ||
583 | self.SetAutoLayout(1) | 601 | self.SetAutoLayout(1) |
584 | self.sizer = sizer | 602 | self.sizer = sizer |
585 | 603 | ||
604 | + def GetHostsList(self, pub_evt): | ||
605 | + ps.Publisher().sendMessage('Set FindPanel hosts list', self.hosts) | ||
606 | + | ||
607 | + | ||
586 | def EndEdition(self, evt): | 608 | def EndEdition(self, evt): |
587 | index = evt.m_itemIndex | 609 | index = evt.m_itemIndex |
588 | item = evt.m_item | 610 | item = evt.m_item |
@@ -637,9 +659,6 @@ class NodesPanel(wx.Panel): | @@ -637,9 +659,6 @@ class NodesPanel(wx.Panel): | ||
637 | else: | 659 | else: |
638 | self.tree_node.SetStringItem(key, 4, _("error")) | 660 | self.tree_node.SetStringItem(key, 4, _("error")) |
639 | 661 | ||
640 | - | ||
641 | - | ||
642 | - | ||
643 | def RightButton(self,evt): | 662 | def RightButton(self,evt): |
644 | event.Skip() | 663 | event.Skip() |
645 | 664 | ||
@@ -651,7 +670,6 @@ class NodesPanel(wx.Panel): | @@ -651,7 +670,6 @@ class NodesPanel(wx.Panel): | ||
651 | if evt.m_itemIndex != 0: | 670 | if evt.m_itemIndex != 0: |
652 | self.tree_node.SetDeselected(evt.m_itemIndex) | 671 | self.tree_node.SetDeselected(evt.m_itemIndex) |
653 | 672 | ||
654 | - | ||
655 | def CheckItemDict(self, evt_pub): | 673 | def CheckItemDict(self, evt_pub): |
656 | index, flag = evt_pub.data | 674 | index, flag = evt_pub.data |
657 | if index != 0: | 675 | if index != 0: |
invesalius/net/dicom.py
@@ -7,6 +7,11 @@ class DicomNet: | @@ -7,6 +7,11 @@ class DicomNet: | ||
7 | self.port = '' | 7 | self.port = '' |
8 | self.aetitle_call = '' | 8 | self.aetitle_call = '' |
9 | self.aetitle = '' | 9 | self.aetitle = '' |
10 | + self.search_word = '' | ||
11 | + self.search_type = 'patient' | ||
12 | + | ||
13 | + def __call__(self): | ||
14 | + return self | ||
10 | 15 | ||
11 | def SetHost(self, address): | 16 | def SetHost(self, address): |
12 | self.address = address | 17 | self.address = address |
@@ -20,7 +25,93 @@ class DicomNet: | @@ -20,7 +25,93 @@ class DicomNet: | ||
20 | def SetAETitle(self, ae_title): | 25 | def SetAETitle(self, ae_title): |
21 | self.aetitle = ae_title | 26 | self.aetitle = ae_title |
22 | 27 | ||
28 | + def SetSearchWord(self, word): | ||
29 | + self.search_word = word | ||
30 | + | ||
31 | + def SetSearchType(self, stype): | ||
32 | + self.search_type = stype | ||
33 | + | ||
34 | + def GetValueFromDICOM(self, ret, tag): | ||
35 | + value = str(ret.GetDataElement(gdcm.Tag(tag[0],\ | ||
36 | + tag[1])).GetValue()) | ||
37 | + return value | ||
38 | + | ||
39 | + | ||
23 | def RunCEcho(self): | 40 | def RunCEcho(self): |
24 | cnf = gdcm.CompositeNetworkFunctions() | 41 | cnf = gdcm.CompositeNetworkFunctions() |
25 | return cnf.CEcho(self.address, int(self.port),\ | 42 | return cnf.CEcho(self.address, int(self.port),\ |
26 | self.aetitle, self.aetitle_call) | 43 | self.aetitle, self.aetitle_call) |
44 | + | ||
45 | + def RunCFind(self): | ||
46 | + | ||
47 | + tags = [(0x0010, 0x0010), (0x0010, 0x1010), (0x0010,0x0040), (0x0008,0x1030),\ | ||
48 | + (0x0008,0x0060), (0x0008,0x0022), (0x0008,0x0080), (0x0010,0x0030),\ | ||
49 | + (0x0008,0x0050), (0x0008,0x0090)] | ||
50 | + | ||
51 | + | ||
52 | + ds = gdcm.DataSet() | ||
53 | + | ||
54 | + for tag in tags: | ||
55 | + | ||
56 | + bit_size = len(self.search_word) + 1 | ||
57 | + | ||
58 | + tg = gdcm.Tag(tag[0], tag[1]) | ||
59 | + | ||
60 | + de = gdcm.DataElement(tg) | ||
61 | + | ||
62 | + if self.search_type == 'patient': | ||
63 | + de.SetByteValue(str(self.search_word + '*'), gdcm.VL(bit_size)) | ||
64 | + else: | ||
65 | + de.SetByteValue('*', gdcm.VL(1)) | ||
66 | + | ||
67 | + ds.Insert(de) | ||
68 | + | ||
69 | + | ||
70 | + cnf = gdcm.CompositeNetworkFunctions() | ||
71 | + theQuery = cnf.ConstructQuery(gdcm.ePatientRootType, gdcm.eImageOrFrame, ds) | ||
72 | + ret = gdcm.DataSetArrayType() | ||
73 | + | ||
74 | + cnf.CFind(self.address, int(self.port), theQuery, ret, self.aetitle,\ | ||
75 | + self.aetitle_call) | ||
76 | + | ||
77 | + patients = {} | ||
78 | + | ||
79 | + exist_images = False | ||
80 | + c = 0 | ||
81 | + for i in range(0,ret.size()): | ||
82 | + patient_id = str(ret[i].GetDataElement(gdcm.Tag(0x0010, 0x0020)).GetValue()) | ||
83 | + serie_id = str(ret[i].GetDataElement(gdcm.Tag(0x0020, 0x000e)).GetValue()) | ||
84 | + | ||
85 | + if not(patient_id in patients.keys()): | ||
86 | + patients[patient_id] = {} | ||
87 | + | ||
88 | + | ||
89 | + if not(serie_id in patients[patient_id]): | ||
90 | + | ||
91 | + rt = ret[i] | ||
92 | + | ||
93 | + | ||
94 | + name = self.GetValueFromDICOM(rt, ((0x0010, 0x0010))) | ||
95 | + age = self.GetValueFromDICOM(rt, ((0x0010, 0x1010))) | ||
96 | + gender = self.GetValueFromDICOM(rt, ((0x0010),(0x0040))) | ||
97 | + study_description = self.GetValueFromDICOM(rt, ((0x0008),(0x1030))) | ||
98 | + modality = self.GetValueFromDICOM(rt, ((0x0008),(0x0060))) | ||
99 | + date_acquisition = self.GetValueFromDICOM(rt, ((0x0008),(0x0022))) | ||
100 | + institution = self.GetValueFromDICOM(rt, ((0x0008),(0x0080))) | ||
101 | + date_of_birth = self.GetValueFromDICOM(rt, ((0x0010),(0x0030))) | ||
102 | + acession_number = self.GetValueFromDICOM(rt, ((0x0008),(0x0050))) | ||
103 | + ref_physician = self.GetValueFromDICOM(rt, ((0x0008),(0x0090))) | ||
104 | + | ||
105 | + patients[patient_id][serie_id] = {'name':name, 'age':age, 'gender':gender,\ | ||
106 | + 'study_description':study_description,\ | ||
107 | + 'modality':modality, \ | ||
108 | + 'date_acquision':date_acquisition,\ | ||
109 | + 'institution':institution,\ | ||
110 | + 'date_of_birth':date_of_birth,\ | ||
111 | + 'acession_number':acession_number,\ | ||
112 | + 'ref_physician':ref_physician} | ||
113 | + | ||
114 | + patients[patient_id][serie_id]['n_images'] = 1 | ||
115 | + else: | ||
116 | + patients[patient_id][serie_id]['n_images'] += 1 | ||
117 | + |
invesalius/reader/dicom_reader.py
@@ -125,7 +125,10 @@ class LoadDicom: | @@ -125,7 +125,10 @@ class LoadDicom: | ||
125 | encoding = "ISO_IR 100" | 125 | encoding = "ISO_IR 100" |
126 | else: | 126 | else: |
127 | encoding = const.DICOM_ENCODING_TO_PYTHON[encoding_value] | 127 | encoding = const.DICOM_ENCODING_TO_PYTHON[encoding_value] |
128 | - | 128 | + else: |
129 | + encoding = "ISO_IR 100" | ||
130 | + | ||
131 | + | ||
129 | # Iterate through the Header | 132 | # Iterate through the Header |
130 | iterator = header.GetDES().begin() | 133 | iterator = header.GetDES().begin() |
131 | while (not iterator.equal(header.GetDES().end())): | 134 | while (not iterator.equal(header.GetDES().end())): |