Skip to content

Commit a2d2ea7

Browse files
Pass module name with consumables when tracking individual histories (#1786)
Co-authored-by: Asif Tamuri <tamuri@gmail.com>
1 parent 85ec43b commit a2d2ea7

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/tlo/methods/consumables.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,17 @@ def _request_consumables(
354354
items_used=items_used,
355355
)
356356

357-
data = {
358-
"target": target,
359-
"module": module,
360-
"event_name": event_name,
361-
"Item_Available": str(items_available),
362-
"Item_NotAvailable": str(items_not_available),
363-
"Item_Used": str(items_used),
364-
}
365-
366-
notifier.dispatch("consumables.post-request_consumables", data=data)
357+
if notifier.has_listeners("consumables.post-request_consumables"):
358+
data = {
359+
"target": target,
360+
"module": module.name,
361+
"event_name": event_name,
362+
"Item_Available": str(items_available),
363+
"Item_NotAvailable": str(items_not_available),
364+
"Item_Used": str(items_used),
365+
}
366+
367+
notifier.dispatch("consumables.post-request_consumables", data=data)
367368

368369
# Return the result of the check on availability
369370
return available

src/tlo/methods/individual_history_tracker.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,14 @@ def on_consumable_request(self,data):
192192
return
193193

194194
# Copy this info for individual
195-
self.consumable_access[data['target']] = {
196-
('ConsCall' + str(self.cons_call_number_within_event) + '_' + k): v
197-
for k, v in data.items() if k != 'target'}
198-
195+
if data['target'] not in self.consumable_access:
196+
self.consumable_access[data['target']] = {}
197+
198+
self.consumable_access[data['target']][f'ConsCall{self.cons_call_number_within_event}'] = {
199+
(k): v
200+
for k, v in data.items() if k not in ['target', 'module', 'event_name']
201+
}
202+
199203
self.cons_call_number_within_event += 1
200204
return
201205

0 commit comments

Comments
 (0)