Commit dd1c83b9b56330fe51d672d5261df8937ec223da
1 parent
aa5e2841
Exists in
master
and in
67 other branches
ADD: Showing patient series in CFind
Showing
3 changed files
with
145 additions
and
20 deletions
Show diff stats
invesalius/gui/import_network_panel.py
@@ -219,7 +219,7 @@ class TextPanel(wx.Panel): | @@ -219,7 +219,7 @@ class TextPanel(wx.Panel): | ||
219 | 219 | ||
220 | def __bind_pubsub_evt(self): | 220 | def __bind_pubsub_evt(self): |
221 | #ps.Publisher().subscribe(self.SelectSeries, 'Select series in import panel') | 221 | #ps.Publisher().subscribe(self.SelectSeries, 'Select series in import panel') |
222 | - pass | 222 | + ps.Publisher().subscribe(self.Populate, 'Populate tree') |
223 | 223 | ||
224 | def __bind_events_wx(self): | 224 | def __bind_events_wx(self): |
225 | self.Bind(wx.EVT_SIZE, self.OnSize) | 225 | self.Bind(wx.EVT_SIZE, self.OnSize) |
@@ -268,10 +268,83 @@ class TextPanel(wx.Panel): | @@ -268,10 +268,83 @@ class TextPanel(wx.Panel): | ||
268 | def SelectSeries(self, pubsub_evt): | 268 | def SelectSeries(self, pubsub_evt): |
269 | group_index = pubsub_evt.data | 269 | group_index = pubsub_evt.data |
270 | 270 | ||
271 | - def Populate(self, patient_list): | 271 | + def Populate(self, pubsub_evt): |
272 | tree = self.tree | 272 | tree = self.tree |
273 | + #print ">>>>>>>>>>>>>>>>>>>>>>>>>>", dir(tree.GetRootItem()) | ||
274 | + #print ">>>>>>>>>>>>",dir(self.tree) | ||
275 | + patients = pubsub_evt.data | ||
273 | 276 | ||
274 | first = 0 | 277 | first = 0 |
278 | + self.idserie_treeitem = {} | ||
279 | + | ||
280 | + for patient in patients.keys(): | ||
281 | + | ||
282 | + | ||
283 | + #ngroups = patient.ngroups | ||
284 | + #dicom = patient.GetDicomSample() | ||
285 | + #title = dicom.patient.name + " (%d series)"%(ngroups) | ||
286 | + #date_time = "%s %s"%(dicom.acquisition.date, | ||
287 | + # dicom.acquisition.time) | ||
288 | + | ||
289 | + first_serie = patients[patient].keys()[0] | ||
290 | + title = patients[patient][first_serie]['name'] | ||
291 | + p = patients[patient][first_serie] | ||
292 | + | ||
293 | + p_id = patient | ||
294 | + age = p['age'] | ||
295 | + gender = p['gender'] | ||
296 | + study_description = p['study_description'] | ||
297 | + modality = p['modality'] | ||
298 | + date = p['acquisition_date'] | ||
299 | + time = p['acquisition_time'] | ||
300 | + institution = p['institution'] | ||
301 | + birthdate = p['date_of_birth'] | ||
302 | + acession_number = p['acession_number'] | ||
303 | + physician = p['ref_physician'] | ||
304 | + | ||
305 | + parent = tree.AppendItem(self.root, title) | ||
306 | + | ||
307 | + n_amount_images = 0 | ||
308 | + for se in patients[patient]: | ||
309 | + n_amount_images = n_amount_images + patients[patient][se]['n_images'] | ||
310 | + | ||
311 | + | ||
312 | + tree.SetItemPyData(parent, patient) | ||
313 | + tree.SetItemText(parent, "%s" % p_id, 1) | ||
314 | + tree.SetItemText(parent, "%s" % age, 2) | ||
315 | + tree.SetItemText(parent, "%s" % gender, 3) | ||
316 | + tree.SetItemText(parent, "%s" % study_description, 4) | ||
317 | + tree.SetItemText(parent, "%s" % modality, 5) | ||
318 | + tree.SetItemText(parent, "%s" % date + " " + time, 6) | ||
319 | + tree.SetItemText(parent, "%s" % str(n_amount_images), 7) | ||
320 | + tree.SetItemText(parent, "%s" % institution, 8) | ||
321 | + tree.SetItemText(parent, "%s" % birthdate, 9) | ||
322 | + tree.SetItemText(parent, "%s" % acession_number, 10) | ||
323 | + tree.SetItemText(parent, "%s" % physician, 11) | ||
324 | + | ||
325 | + | ||
326 | + | ||
327 | + for series in patients[patient].keys(): | ||
328 | + | ||
329 | + serie_description = patients[patient][series]['serie_description'] | ||
330 | + n_images = patients[patient][series]['n_images'] | ||
331 | + date = patients[patient][series]['acquisition_date'] | ||
332 | + time = patients[patient][series]['acquisition_time'] | ||
333 | + | ||
334 | + child = tree.AppendItem(parent, serie_description) | ||
335 | + tree.SetItemPyData(child, series) | ||
336 | + | ||
337 | + tree.SetItemText(child, "%s" % serie_description, 0) | ||
338 | + #tree.SetItemText(child, "%s" % dicom.acquisition.protocol_name, 4) | ||
339 | + #tree.SetItemText(child, "%s" % dicom.acquisition.modality, 5) | ||
340 | + tree.SetItemText(child, "%s" % date + " " + time, 6) | ||
341 | + tree.SetItemText(child, "%s" % n_images , 7) | ||
342 | + | ||
343 | + self.idserie_treeitem[child] = (patient, series) | ||
344 | + | ||
345 | + | ||
346 | + """ | ||
347 | + | ||
275 | for patient in patient_list: | 348 | for patient in patient_list: |
276 | if not isinstance(patient, dcm.PatientGroup): | 349 | if not isinstance(patient, dcm.PatientGroup): |
277 | return None | 350 | return None |
@@ -319,7 +392,7 @@ class TextPanel(wx.Panel): | @@ -319,7 +392,7 @@ class TextPanel(wx.Panel): | ||
319 | tree.Expand(self.root) | 392 | tree.Expand(self.root) |
320 | tree.SelectItem(parent_select) | 393 | tree.SelectItem(parent_select) |
321 | tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate) | 394 | tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate) |
322 | - tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged) | 395 | + tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged)""" |
323 | 396 | ||
324 | def OnSelChanged(self, evt): | 397 | def OnSelChanged(self, evt): |
325 | item = self.tree.GetSelection() | 398 | item = self.tree.GetSelection() |
@@ -436,7 +509,8 @@ class FindPanel(wx.Panel): | @@ -436,7 +509,8 @@ class FindPanel(wx.Panel): | ||
436 | dn.SetAETitleCall(self.hosts[key][3]) | 509 | dn.SetAETitleCall(self.hosts[key][3]) |
437 | dn.SetAETitle(self.hosts[0][3]) | 510 | dn.SetAETitle(self.hosts[0][3]) |
438 | dn.SetSearchWord(self.find_txt.GetValue()) | 511 | dn.SetSearchWord(self.find_txt.GetValue()) |
439 | - print dn.RunCFind() | 512 | + |
513 | + ps.Publisher().sendMessage('Populate tree', dn.RunCFind()) | ||
440 | 514 | ||
441 | 515 | ||
442 | def SetHostsList(self, evt_pub): | 516 | def SetHostsList(self, evt_pub): |
invesalius/net/dicom.py
1 | import gdcm | 1 | import gdcm |
2 | +import utils | ||
3 | + | ||
2 | 4 | ||
3 | class DicomNet: | 5 | class DicomNet: |
4 | 6 | ||
@@ -34,6 +36,8 @@ class DicomNet: | @@ -34,6 +36,8 @@ class DicomNet: | ||
34 | def GetValueFromDICOM(self, ret, tag): | 36 | def GetValueFromDICOM(self, ret, tag): |
35 | value = str(ret.GetDataElement(gdcm.Tag(tag[0],\ | 37 | value = str(ret.GetDataElement(gdcm.Tag(tag[0],\ |
36 | tag[1])).GetValue()) | 38 | tag[1])).GetValue()) |
39 | + if value == 'None' and tag != (0x0008,0x103E): | ||
40 | + value = '' | ||
37 | return value | 41 | return value |
38 | 42 | ||
39 | 43 | ||
@@ -46,20 +50,22 @@ class DicomNet: | @@ -46,20 +50,22 @@ class DicomNet: | ||
46 | 50 | ||
47 | tags = [(0x0010, 0x0010), (0x0010, 0x1010), (0x0010,0x0040), (0x0008,0x1030),\ | 51 | tags = [(0x0010, 0x0010), (0x0010, 0x1010), (0x0010,0x0040), (0x0008,0x1030),\ |
48 | (0x0008,0x0060), (0x0008,0x0022), (0x0008,0x0080), (0x0010,0x0030),\ | 52 | (0x0008,0x0060), (0x0008,0x0022), (0x0008,0x0080), (0x0010,0x0030),\ |
49 | - (0x0008,0x0050), (0x0008,0x0090)] | 53 | + (0x0008,0x0050), (0x0008,0x0090), (0x0008,0x103E), (0x0008,0x0033),\ |
54 | + (0x0008,0x0032)] | ||
50 | 55 | ||
51 | 56 | ||
52 | ds = gdcm.DataSet() | 57 | ds = gdcm.DataSet() |
53 | 58 | ||
54 | for tag in tags: | 59 | for tag in tags: |
55 | 60 | ||
56 | - bit_size = len(self.search_word) + 1 | ||
57 | 61 | ||
58 | tg = gdcm.Tag(tag[0], tag[1]) | 62 | tg = gdcm.Tag(tag[0], tag[1]) |
59 | 63 | ||
60 | de = gdcm.DataElement(tg) | 64 | de = gdcm.DataElement(tg) |
61 | 65 | ||
62 | - if self.search_type == 'patient': | 66 | + if self.search_type == 'patient' and tag == (0x0010, 0x0010): |
67 | + | ||
68 | + bit_size = len(self.search_word) + 1 | ||
63 | de.SetByteValue(str(self.search_word + '*'), gdcm.VL(bit_size)) | 69 | de.SetByteValue(str(self.search_word + '*'), gdcm.VL(bit_size)) |
64 | else: | 70 | else: |
65 | de.SetByteValue('*', gdcm.VL(1)) | 71 | de.SetByteValue('*', gdcm.VL(1)) |
@@ -90,26 +96,29 @@ class DicomNet: | @@ -90,26 +96,29 @@ class DicomNet: | ||
90 | 96 | ||
91 | rt = ret[i] | 97 | rt = ret[i] |
92 | 98 | ||
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))) | 99 | + name = self.GetValueFromDICOM(rt, (0x0010, 0x0010)) |
100 | + age = self.GetValueFromDICOM(rt, (0x0010, 0x1010)) | ||
101 | + gender = self.GetValueFromDICOM(rt, (0x0010,0x0040)) | ||
102 | + study_description = self.GetValueFromDICOM(rt, (0x0008,0x1030)) | ||
103 | + modality = self.GetValueFromDICOM(rt, (0x0008,0x0060)) | ||
104 | + institution = self.GetValueFromDICOM(rt, (0x0008,0x0080)) | ||
105 | + date_of_birth = utils.format_date(self.GetValueFromDICOM(rt, (0x0010,0x0030))) | ||
106 | + acession_number = self.GetValueFromDICOM(rt, (0x0008,0x0050)) | ||
107 | + ref_physician = self.GetValueFromDICOM(rt, (0x0008,0x0090)) | ||
108 | + serie_description = self.GetValueFromDICOM(rt, (0x0008,0x103E)) | ||
109 | + acquisition_time = utils.format_time(self.GetValueFromDICOM(rt, (0x0008,0x0032))) | ||
110 | + acquisition_date = utils.format_date(self.GetValueFromDICOM(rt, (0x0008,0x0022))) | ||
104 | 111 | ||
105 | patients[patient_id][serie_id] = {'name':name, 'age':age, 'gender':gender,\ | 112 | patients[patient_id][serie_id] = {'name':name, 'age':age, 'gender':gender,\ |
106 | 'study_description':study_description,\ | 113 | 'study_description':study_description,\ |
107 | 'modality':modality, \ | 114 | 'modality':modality, \ |
108 | - 'date_acquision':date_acquisition,\ | 115 | + 'acquisition_time':acquisition_time,\ |
116 | + 'acquisition_date':acquisition_date,\ | ||
109 | 'institution':institution,\ | 117 | 'institution':institution,\ |
110 | 'date_of_birth':date_of_birth,\ | 118 | 'date_of_birth':date_of_birth,\ |
111 | 'acession_number':acession_number,\ | 119 | 'acession_number':acession_number,\ |
112 | - 'ref_physician':ref_physician} | 120 | + 'ref_physician':ref_physician,\ |
121 | + 'serie_description':serie_description} | ||
113 | 122 | ||
114 | patients[patient_id][serie_id]['n_images'] = 1 | 123 | patients[patient_id][serie_id]['n_images'] = 1 |
115 | else: | 124 | else: |
invesalius/utils.py
@@ -17,11 +17,53 @@ | @@ -17,11 +17,53 @@ | ||
17 | # detalhes. | 17 | # detalhes. |
18 | #-------------------------------------------------------------------------- | 18 | #-------------------------------------------------------------------------- |
19 | import platform | 19 | import platform |
20 | +import time | ||
20 | import sigar | 21 | import sigar |
21 | import sys | 22 | import sys |
22 | import re | 23 | import re |
23 | import locale | 24 | import locale |
24 | 25 | ||
26 | +def format_time(value): | ||
27 | + sp1 = value.split(".") | ||
28 | + sp2 = value.split(":") | ||
29 | + | ||
30 | + if (len(sp1) == 2) and (len(sp2) == 3): | ||
31 | + new_value = str(sp2[0]+sp2[1]+ | ||
32 | + str(int(float(sp2[2])))) | ||
33 | + data = time.strptime(new_value, "%H%M%S") | ||
34 | + elif (len(sp1) == 2): | ||
35 | + data = time.gmtime(float(value)) | ||
36 | + elif (len(sp1) > 2): | ||
37 | + data = time.strptime(value, "%H.%M.%S") | ||
38 | + elif(len(sp2) > 1): | ||
39 | + data = time.strptime(value, "%H:%M:%S") | ||
40 | + else: | ||
41 | + try: | ||
42 | + data = time.strptime(value, "%H%M%S") | ||
43 | + # If the time is not in a bad format only return it. | ||
44 | + except ValueError: | ||
45 | + return value | ||
46 | + return time.strftime("%H:%M:%S",data) | ||
47 | + | ||
48 | +def format_date(value): | ||
49 | + | ||
50 | + sp1 = value.split(".") | ||
51 | + try: | ||
52 | + | ||
53 | + if (len(sp1) > 1): | ||
54 | + if (len(sp1[0]) <= 2): | ||
55 | + data = time.strptime(value, "%D.%M.%Y") | ||
56 | + else: | ||
57 | + data = time.strptime(value, "%Y.%M.%d") | ||
58 | + elif(len(value.split("//")) > 1): | ||
59 | + data = time.strptime(value, "%D/%M/%Y") | ||
60 | + else: | ||
61 | + data = time.strptime(value, "%Y%M%d") | ||
62 | + return time.strftime("%d/%M/%Y",data) | ||
63 | + | ||
64 | + except(ValueError): | ||
65 | + return "" | ||
66 | + | ||
25 | def debug(error_str): | 67 | def debug(error_str): |
26 | """ | 68 | """ |
27 | Redirects output to file, or to the terminal | 69 | Redirects output to file, or to the terminal |