From c54860cb36870ffdc1acb391d587d32c91f36b39 Mon Sep 17 00:00:00 2001 From: erikvw Date: Mon, 3 Jun 2024 11:20:27 -0500 Subject: [PATCH] use default AE TMG action item classes --- effect_ae/action_items.py | 79 +++------------------------------------ 1 file changed, 6 insertions(+), 73 deletions(-) diff --git a/effect_ae/action_items.py b/effect_ae/action_items.py index 5d436e75..71ef1477 100644 --- a/effect_ae/action_items.py +++ b/effect_ae/action_items.py @@ -1,8 +1,12 @@ from django.apps import apps as django_apps from django.conf import settings -from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist from django.utils.html import format_html from edc_action_item import ActionWithNotification, site_action_items +from edc_adverse_event.action_items import ( + DeathReportTmgAction, + DeathReportTmgSecondAction, +) from edc_adverse_event.constants import ( AE_FOLLOWUP_ACTION, AE_INITIAL_ACTION, @@ -226,80 +230,9 @@ def get_next_actions(self): return next_actions -class DeathReportTmgAction(ActionWithNotification): - name = DEATH_REPORT_TMG_ACTION - display_name = "TMG Death Report pending" - notification_display_name = "TMG Death Report" - parent_action_names = [DEATH_REPORT_ACTION, DEATH_REPORT_TMG_ACTION] - reference_model = "effect_ae.deathreporttmg" - related_reference_model = "effect_ae.deathreport" - related_reference_fk_attr = "death_report" - priority = HIGH_PRIORITY - create_by_user = False - color_style = "info" - show_link_to_changelist = True - admin_site_name = "effect_ae_admin" - instructions = format_html("This report is to be completed by the TMG only.") - - def reopen_action_item_on_change(self): - """Do not reopen if status is CLOSED.""" - return self.reference_obj.report_status != CLOSED - - @property - def matching_cause_of_death(self): - """Returns True if cause_of_death on TMG Death Report matches - cause_of_death on Death Report. - """ - return ( - self.reference_obj.death_report.cause_of_death == self.reference_obj.cause_of_death - ) - - def close_action_item_on_save(self): - if self.matching_cause_of_death: - self.delete_children_if_new(parent_action_item=self.action_item) - return self.reference_obj.report_status == CLOSED - - def get_next_actions(self): - """Returns a second DeathReportTmgAction if the - submitted report does not match the cause of death - of the original death report. - - Also, no more than two DeathReportTmgAction can exist. - """ - next_actions = [] - try: - self.action_item_model_cls().objects.get( - parent_action_item=self.related_action_item, - related_action_item=self.related_action_item, - action_type__name=self.name, - ) - except ObjectDoesNotExist: - pass - except MultipleObjectsReturned: - # because more than one action item has the same - # parent_action_item and related_action_item. this - # only occurs for older data. - pass - else: - if ( - self.action_item_model_cls() - .objects.filter( - related_action_item=self.related_action_item, - action_type__name=self.name, - ) - .count() - < 2 - ): - if ( - self.reference_obj.cause_of_death - != self.related_action_item.reference_obj.cause_of_death - ): - next_actions = ["self"] - return next_actions - - site_action_items.register(DeathReportAction) site_action_items.register(DeathReportTmgAction) +site_action_items.register(DeathReportTmgSecondAction) site_action_items.register(AeFollowupAction) site_action_items.register(AeInitialAction) site_action_items.register(AeSusarAction)