1
2
3
4
5
6
7 __version__ = "$Revision: 1.4 $"
8 __author__ = "Sebastian Hilbert"
9 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
10
11
12 import sys, logging
13
14
15 if __name__ == '__main__':
16 sys.path.insert(0, '../../')
17
18 _log = logging.getLogger('gm.dev')
19 _log.info(__version__)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
39 Devices = []
40
41 for Device in DevicesTree:
42 Devices.append(Device)
43 return Devices
44
48
50 DeviceParts = []
51 for DevicePart in Device:
52 if DevicePart.get("type") == Type:
53 DeviceParts.append(DevicePart)
54 return DeviceParts
55
59
61 Actions = []
62
63 for tag in DevicePart.getchildren():
64 if tag.get("type") == Type:
65 Actions.append(tag)
66 return Actions
67
69
70 for tag in start_node.getchildren():
71 if tag.tag==SearchTag:
72 return tag.text
73
75 for tag in start_node.getchildren():
76 if tag.tag == SearchTag:
77 return tag.get(Attribute)
78
80 DevicesDict = {}
81 DevicePartSpecsDict = {}
82 DevicesDisplayed = []
83
84 """ In this area GNUmed will place the status of all cardiac devices and device parts.
85 There can be more than one device at a time\n\n
86 It potentially looks like this\n
87 ----------------------------------------------------------------------------------------------------------------\n
88 Device: SJM Atlas DR (active) Battery: 2.4V (MOL) Implanted: Feb 09 2008\n\n
89 RA: Medtronic Sprint fidelis (active, flaky, replacement) Implanted: Feb 09 2008\n
90 Sensing: 2 (1.5) mV Threshold: 0.7/0.5 (1/0.4) V/ms Impedance: 800 (900) Ohm\n\n
91 RV: Medtronic Sprint fidelis (active, flaky, replacement) Implanted: Feb 09 2008\n
92 Sensing: 7 (15) mV Threshold: 0.7/0.5 (1/0.4) V/ms Impedance: 800 (900) Ohm\n\n
93 LV: Medtronic Sprint fidelis (active, flaky, Y-connector) Implanted: Feb 09 2008\n
94 Sensing: 7 ( ?) mV Threshold: 1/1.5 (1/1) V/ms Impedance: 800 (900) Ohm\n
95 ----------------------------------------------------------------------------------------------------------------\n
96 Device: Medtronic Relia SR (inactive) Battery 2.1V (EOL) Implanted: Jan 23 2000\n\n
97 Device: Medtronic Kappa SR (explanted) Battery 2.1V (EOL) Explanted: Jan 23 2000 (Jan 23 1995)\n
98 -----------------------------------------------------------------------------------------------------------------\n
99 RA Lead: Medtronic ? (inactive, capped) Implanted: Jan 23 2000\n
100 RV Lead: Medtronic ? (explanted) Explanted: Feb 09 2008
101 """
102 """
103 first search for devices, produce a list,
104 sort in active devices first, ICD befor pacemaker before disconnted devices
105 per convention a single generator or lead which is not connected is a self contained device
106 there are virtual devices such as 'ICD' or 'pacemaker' which consist of parts such as leads and generator
107 there are true devices such as inactive leads or non-explanted generators
108 class will be 'lead' instead of type 'lead' for DeviceParts
109 """
110
111 DevicesTree = tree.getroot()
112 Devices = extractDevices(DevicesTree)
113 DevicesSorted = sortDevicesByTypeAndStatus(Devices)
114
115
116 for Device in DevicesSorted:
117 DevicesDisplayed.append('-------------------------------------------------------------\n')
118
119 DeviceClass=Device.get("class")
120 if DeviceClass == 'ICD':
121
122 Generator = extractDeviceParts(Device=Device,Type='generator')[0]
123
124 vendor = extractTagData(start_node=Generator,SearchTag='vendor')
125 model = extractTagData(start_node=Generator,SearchTag='model')
126 devicestate = extractTagData(start_node=Generator,SearchTag='devicestate')
127
128 battery = extractDeviceParts(Device=Generator,Type='battery')[0]
129 action = extractActions(DevicePart=battery,Type='interrogation')[0]
130 battery_voltage = extractTagData(start_node=action,SearchTag='voltage')
131 battery_voltage_unit = extractTagAttribute(start_node=action,SearchTag='voltage',Attribute='unit')
132 battery_status = extractTagData(start_node=action,SearchTag='status')
133 implantation_date= extractTagData(start_node=Generator,SearchTag='doi')
134 line = _('Device(%s):') %DeviceClass + ' ' + vendor + ' ' + model + ' ' + '('+ devicestate + ')'+' '+_('Battery:')+' '+battery_voltage+' '+battery_voltage_unit+'('+battery_status+')'+' '+_('Implanted:')+' '+implantation_date+'\n\n'
135
136 DevicesDisplayed.append(line)
137
138
139
140 Leads = extractDeviceParts(Device=Device,Type='lead')
141 LeadsSorted = sortLeadsByPosition(Leads)
142 for Lead in LeadsSorted:
143 leadposition = extractTagData(start_node=Lead,SearchTag='leadposition')
144 leadslot = extractTagData(start_node=Lead,SearchTag='leadslot')
145 vendor = extractTagData(start_node=Lead,SearchTag='manufacturer')
146 model = extractTagData(start_node=Lead,SearchTag='model')
147 devicestate = extractTagData(start_node=Lead,SearchTag='devicestate')
148 comment = extractTagData(start_node=Lead,SearchTag='comment')
149 implantation_date = extractTagData(start_node=Lead,SearchTag='doi')
150 line = '%s-lead in %s-position:' %(leadposition,leadslot) + ' ' + vendor + ' ' + model + ' ' + '(' + devicestate + ',' + comment + ')' + ' ' + 'Implanted:' + ' ' + implantation_date +'\n'
151 DevicesDisplayed.append(line)
152
153 action = extractActions(DevicePart=Lead,Type='interrogation')[0]
154 action_date = extractTagData(start_node=action,SearchTag='dop')
155 sensing = extractTagData(start_node=action,SearchTag='sensing')
156 sensingunit = extractTagAttribute(start_node=action,SearchTag='sensing',Attribute='unit')
157 threshold = extractTagData(start_node=action,SearchTag='thresholdvoltage')
158 thresholdunit = extractTagAttribute(start_node=action,SearchTag='thresholdvoltage',Attribute='unit')
159 impedance = extractTagData(start_node=action,SearchTag='impedance')
160 impedanceunit = extractTagAttribute(start_node=action,SearchTag='impedance',Attribute='unit')
161 line = _('last check:')+' '+action_date+' '+_('Sensing:')+' '+sensing+sensingunit+' '+_('Threshold')+' '+threshold+thresholdunit+' '+_('Impedance:')+' '+impedance+' '+impedanceunit+'\n\n'
162 DevicesDisplayed.append(line)
163
164 return DevicesDisplayed
165
166
167
168
169 if __name__ == '__main__':
170
171 from lxml import etree
172
173 from Gnumed.pycommon import gmI18N
174 gmI18N.activate_locale()
175 gmI18N.install_domain()
176
177 if len(sys.argv) > 1 and sys.argv[1] == 'test':
178
179
181
182
183 print "parsing device status from XML file:", sys.argv[2]
184 xml_device_desc = etree.parse(sys.argv[2])
185 formatted_device_status = device_status_as_text(xml_device_desc)
186 for line in formatted_device_status:
187 print line
188
189
190 test_parsing_cardio_dev_state()
191
192
193
194
195
196
197
198
199
200
201
202
203
204