From 815fa8353bd8e4e82f82c0472ea8bd2ee8ba714f Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Wed, 20 Dec 2023 20:56:40 +0000 Subject: [PATCH 01/12] Patient transfer notification emails Fixes #538 --- epilepsy12/views/case_views.py | 37 +++++++++++++------ epilepsy12/views/registration_views.py | 3 +- templates/epilepsy12/partials/case_table.html | 4 +- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/epilepsy12/views/case_views.py b/epilepsy12/views/case_views.py index 4da37cea..379fb968 100644 --- a/epilepsy12/views/case_views.py +++ b/epilepsy12/views/case_views.py @@ -10,7 +10,6 @@ from django.contrib.gis.db.models import Q from django.contrib import messages from django.core.paginator import Paginator -from django.db import DatabaseError # third party imports from django_htmx.http import trigger_client_event, HttpResponseClientRedirect @@ -393,23 +392,39 @@ def transfer_response(request, organisation_id, case_id, organisation_response): ) origin_organisation = site.transfer_origin_organisation if organisation_response == "reject": - # reset the child back to the orgin organisation - site.active_transfer = False - site.organisation = site.transfer_origin_organisation - site.transfer_origin_organisation = None - site.transfer_request_date = None + # reset the child back to the origin organisation + if Site.objects.filter( + organisation=origin_organisation, + site_is_primary_centre_of_epilepsy_care=True, + site_is_actively_involved_in_epilepsy_care=False, + ).exists(): + # old record exist - reactivate + old_site = Site.objects.filter( + organisation=origin_organisation, + site_is_primary_centre_of_epilepsy_care=True, + site_is_actively_involved_in_epilepsy_care=False, + ).get() + old_site.site_is_actively_involved_in_epilepsy_care = True + old_site.save() + # delete this record + site.delete() + else: + # no previous record to reanimate + # continue with this record + # no longer in active transfer + site.active_transfer = False + site.organisation = site.transfer_origin_organisation + site.transfer_origin_organisation = None + site.transfer_request_date = None + site.save() elif organisation_response == "accept": site.active_transfer = False site.transfer_origin_organisation = None site.transfer_request_date = None + site.save() else: raise Exception("No organisation response supplied") - try: - site.save() - except: - raise DatabaseError - # send email asynchronously to lead clinician(s) of origin organisation notifying them of outcome outcome = f"{organisation_response.upper()}ED" if Epilepsy12User.objects.filter( diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index cdc98680..e9fe02ca 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -402,7 +402,6 @@ def update_lead_site(request, registration_id, site_id, update): & Q(is_active=True) & Q(role=1) # Audit Centre Lead Clinician ) - | (Q(is_active=True) & Q(is_rcpch_audit_team_member=True)) ).values_list("email", flat=True) ) subject = "Epilepsy12 Lead Site Transfer" @@ -411,6 +410,8 @@ def update_lead_site(request, registration_id, site_id, update): recipients = [settings.SITE_CONTACT_EMAIL] subject = "Epilepsy12 Lead Site Transfer - NO LEAD CLINICIAN" + print(recipients) + email = construct_transfer_epilepsy12_site_email( request=request, target_organisation=new_organisation, diff --git a/templates/epilepsy12/partials/case_table.html b/templates/epilepsy12/partials/case_table.html index 01a2c33f..e5f4c83e 100644 --- a/templates/epilepsy12/partials/case_table.html +++ b/templates/epilepsy12/partials/case_table.html @@ -243,7 +243,7 @@
{{total_percent}}% ({{case.registration.audit_progress.total_completed_field showCancelButton: true, confirmButtonColor: '#11a7f2', cancelButtonColor: '#e60700', - confirmButtonText: 'I accept' + confirmButtonText: 'I confirm' }) if result.isConfirmed issueRequest()" > @@ -268,7 +268,7 @@
{{total_percent}}% ({{case.registration.audit_progress.total_completed_field showCancelButton: true, confirmButtonColor: '#11a7f2', cancelButtonColor: '#e60700', - confirmButtonText: 'I accept' + confirmButtonText: 'I confirm' }) if result.isConfirmed issueRequest()" > From c817c37e2085c76558a9ab330b007b8786d2e475 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Wed, 20 Dec 2023 20:57:13 +0000 Subject: [PATCH 02/12] remove print statement --- epilepsy12/views/registration_views.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index e9fe02ca..09a92f06 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -410,8 +410,6 @@ def update_lead_site(request, registration_id, site_id, update): recipients = [settings.SITE_CONTACT_EMAIL] subject = "Epilepsy12 Lead Site Transfer - NO LEAD CLINICIAN" - print(recipients) - email = construct_transfer_epilepsy12_site_email( request=request, target_organisation=new_organisation, From be4baaa87abea08efbe6d47935fb4495ef1ddb82 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Wed, 20 Dec 2023 21:08:41 +0000 Subject: [PATCH 03/12] remove current organisation from drop down in transfer child not fixed --- epilepsy12/views/registration_views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index 09a92f06..2a80e2fc 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -266,7 +266,12 @@ def transfer_lead_site(request, registration_id, site_id): registration = Registration.objects.get(pk=registration_id) site = Site.objects.get(pk=site_id) - organisation_list = Organisation.objects.order_by("name").all() + organisation_list = ( + Organisation.objects.all() + .exclude(pk__in=site.organisation.pk) + .order_by("name") + .all() + ) context = { "organisation_list": organisation_list, From ee8e0eeba0c9949e73cdba39129d4b16b52bbbe2 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Wed, 20 Dec 2023 21:49:39 +0000 Subject: [PATCH 04/12] remove current organisation from transfer list --- epilepsy12/views/registration_views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index 2a80e2fc..c24b0322 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -266,9 +266,11 @@ def transfer_lead_site(request, registration_id, site_id): registration = Registration.objects.get(pk=registration_id) site = Site.objects.get(pk=site_id) + # remove the currently selected organisation from the list - should not be able to + # transfer to the current organisation organisation_list = ( - Organisation.objects.all() - .exclude(pk__in=site.organisation.pk) + Organisation.objects.filter() + .exclude(pk=site.organisation.pk) .order_by("name") .all() ) From 5e6155cf7d08d72a01c10403ace4a4be79bf4d1b Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Tue, 2 Jan 2024 20:10:43 +0000 Subject: [PATCH 05/12] local health board epilepsy12user filter bug - fixes #727 --- epilepsy12/views/user_management_views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/epilepsy12/views/user_management_views.py b/epilepsy12/views/user_management_views.py index 3a686560..428387ca 100644 --- a/epilepsy12/views/user_management_views.py +++ b/epilepsy12/views/user_management_views.py @@ -141,10 +141,14 @@ def epilepsy12_user_list(request, organisation_id): # filters all primary Trust level centres, irrespective of if active or inactive if organisation.country.boundary_identifier == "W92000004": parent_trust = organisation.local_health_board.name + basic_filter = Q( + organisation_employer__local_health_board__name__contains=parent_trust + ) else: parent_trust = organisation.trust.name - - basic_filter = Q(organisation_employer__trust__name__contains=parent_trust) + basic_filter = Q( + organisation_employer__trust__name__contains=parent_trust + ) elif request.user.view_preference == 0: # filters all primary centres at organisation level, irrespective of if active or inactive From aa652054a4c681f2f12557cc08f124c1406e00ea Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sat, 6 Jan 2024 12:00:35 +0000 Subject: [PATCH 06/12] remove empty brackets in case_form in footer message --- templates/epilepsy12/forms/case_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/epilepsy12/forms/case_form.html b/templates/epilepsy12/forms/case_form.html index 70080704..e1200cbb 100644 --- a/templates/epilepsy12/forms/case_form.html +++ b/templates/epilepsy12/forms/case_form.html @@ -115,7 +115,7 @@
Organisation

{% if organisation.trust %} - {{organisation.name}}({{organisation.trust.name}}) ({{form.id}}) + {{organisation.name}}({{organisation.trust.name}}) {% else %} {{organisation.name}}({{organisation.local_health_board.name}}) {% endif %} From 749bf08a8c5a3a151a96939ecc7b1bb79a856523 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sat, 6 Jan 2024 12:13:28 +0000 Subject: [PATCH 07/12] remove template test for group to edit NHS number field in case_form.html closes #728 --- templates/epilepsy12/forms/case_form.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/epilepsy12/forms/case_form.html b/templates/epilepsy12/forms/case_form.html index e1200cbb..526eaba8 100644 --- a/templates/epilepsy12/forms/case_form.html +++ b/templates/epilepsy12/forms/case_form.html @@ -65,15 +65,12 @@ - - {% if request.user|has_group:"trust_audit_team_full_access, trust_audit_team_edit_access, epilepsy12_audit_team_edit_access, epilepsy12_audit_team_full_access" %}

{{form.nhs_number}} {% if form.nhs_number.errors %}
{{form.nhs_number.errors}}
{% endif %}
- {% endif %}
From 65b76ad06e3565e28970feb33dfc607aec8f6b21 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sat, 6 Jan 2024 17:42:18 +0000 Subject: [PATCH 08/12] fixes case where lead site transfer still has other responsibilities --- epilepsy12/views/case_views.py | 40 +++++++++++++++++++++++++- epilepsy12/views/registration_views.py | 34 ++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/epilepsy12/views/case_views.py b/epilepsy12/views/case_views.py index 379fb968..10c6ed30 100644 --- a/epilepsy12/views/case_views.py +++ b/epilepsy12/views/case_views.py @@ -383,7 +383,9 @@ def transfer_response(request, organisation_id, case_id, organisation_response): """ case = Case.objects.get(pk=case_id) - site = Site.objects.get(case=case, active_transfer=True) + site = Site.objects.get( + case=case, active_transfer=True, site_is_primary_centre_of_epilepsy_care=True + ) # prepare email response to requesting organisation clinical lead email = construct_transfer_epilepsy12_site_outcome_email( request=request, @@ -400,12 +402,40 @@ def transfer_response(request, organisation_id, case_id, organisation_response): ).exists(): # old record exist - reactivate old_site = Site.objects.filter( + case=case, organisation=origin_organisation, site_is_primary_centre_of_epilepsy_care=True, site_is_actively_involved_in_epilepsy_care=False, ).get() old_site.site_is_actively_involved_in_epilepsy_care = True old_site.save() + # if the old site had other responsibilities that were retained, need to reallocate them back + # and delete any records that stored them + if Site.objects.filter( + ( + Q(site_is_childrens_epilepsy_surgery_centre=True) + | Q(site_is_paediatric_neurology_centre=True) + | Q(site_is_general_paediatric_centre=True) + ), + case=case, + organisation=origin_organisation, + active_transfer=True, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=True, + ).exists(): + old_site_additional_responsibilities = Site.objects.filter( + ( + Q(site_is_childrens_epilepsy_surgery_centre=True) + | Q(site_is_paediatric_neurology_centre=True) + | Q(site_is_general_paediatric_centre=True) + ), + case=case, + organisation=origin_organisation, + active_transfer=True, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=True, + ).first() + old_site_additional_responsibilities.delete() # delete this record site.delete() else: @@ -422,6 +452,14 @@ def transfer_response(request, organisation_id, case_id, organisation_response): site.transfer_origin_organisation = None site.transfer_request_date = None site.save() + # if the original organisation has ongoing other responsibilities and a new record had to be created + # to track these, find those records and set the active_transfer flag to False + Site.objects.filter( + case=case, + organisation=origin_organisation, + active_transfer=True, + site_is_actively_involved_in_epilepsy_care=True, + ).update(active_transfer=False) else: raise Exception("No organisation response supplied") diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index c24b0322..ae04af55 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -356,11 +356,35 @@ def update_lead_site(request, registration_id, site_id, update): new_organisation_id = request.POST.get("transfer_lead_site") new_organisation = Organisation.objects.get(pk=new_organisation_id) - # update current site record to show nolonger actively involved in care - updated_previous_lead_site = Site.objects.filter(pk=site_id).get() - updated_previous_lead_site.site_is_primary_centre_of_epilepsy_care = True - updated_previous_lead_site.site_is_actively_involved_in_epilepsy_care = False - updated_previous_lead_site.save() + if ( + previous_lead_site.site_is_childrens_epilepsy_surgery_centre + or previous_lead_site.site_is_paediatric_neurology_centre + or previous_lead_site.site_is_general_paediatric_centre + ): + # the old site retains responsibility for one/all of neuro/gen paeds/surgery + # but is not the lead site anymore + # To allow us to track the fact that this site was once the lead site for this child, + # we must create a new record to track the fact that this site is still involved in the care + Site.objects.create( + case=registration.case, + organisation=origin_organisation, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=True, + site_is_childrens_epilepsy_surgery_centre=previous_lead_site.site_is_childrens_epilepsy_surgery_centre, + site_is_paediatric_neurology_centre=previous_lead_site.site_is_paediatric_neurology_centre, + site_is_general_paediatric_centre=previous_lead_site.site_is_general_paediatric_centre, + active_transfer=True, # this flag will be set to false if transfer accepted or used to delete record if transfer ultimately refused + ) + + # update current site record to show nolonger actively involved in care as primary centre + previous_lead_site.site_is_primary_centre_of_epilepsy_care = True + previous_lead_site.site_is_actively_involved_in_epilepsy_care = False + previous_lead_site.save( + update_fields=[ + "site_is_primary_centre_of_epilepsy_care", + "site_is_actively_involved_in_epilepsy_care", + ] + ) # create new record in Site table for child against new centre, or update existing record if # organisation already involved in child's care From b2c1a62db3b623084da9f7b0c507f2004bb032b0 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sat, 6 Jan 2024 22:49:04 +0000 Subject: [PATCH 09/12] fix sites for assessment tab breaks transfers --- epilepsy12/views/assessment_views.py | 582 +++++++++++++++++++-------- epilepsy12/views/case_views.py | 2 +- 2 files changed, 406 insertions(+), 178 deletions(-) diff --git a/epilepsy12/views/assessment_views.py b/epilepsy12/views/assessment_views.py index cd4460b1..d032f397 100644 --- a/epilepsy12/views/assessment_views.py +++ b/epilepsy12/views/assessment_views.py @@ -9,6 +9,135 @@ from ..decorator import user_may_view_this_child, login_and_otp_required +def update_site_model( + centre_role: str, selected_organisation, case, user, site_id=None +): + """ + Helper function to update sites model with attributes describing role of site + (general paediatric, neurology, surgical centre) + This is complicated because historical records of lead centre status are persisted + whereas historical records of other roles are not. + + If the organisation is the lead site for this child, and also the neurology/surgery + or general paediatric centre, all this information can be stored in one record. + + If the organisation used to be the lead site for this child, and now is actively + the neurology/surgery or general paediatric centre, two records are stored: one where + site_is_actively_involved_in_epilepsy_care is False and site_is_primary_centre_of_epilepsy_care is True, + the other where site_is_actively_involved_in_epilepsy_care is True and one/some of the other attributes + is True. site_is_primary_centre_of_epilepsy_care here is False. + """ + + if centre_role == "general_paediatric_centre": + update_field = {"site_is_general_paediatric_centre": True} + update_fields = { + "site_is_general_paediatric_centre": True, + "site_is_paediatric_neurology_centre": False, + "site_is_childrens_epilepsy_surgery_centre": False, + } + elif centre_role == "paediatric_neurology_centre": + update_field = {"site_is_paediatric_neurology_centre": True} + update_fields = { + "site_is_general_paediatric_centre": False, + "site_is_paediatric_neurology_centre": True, + "site_is_childrens_epilepsy_surgery_centre": False, + } + elif centre_role == "epilepsy_surgery_centre": + update_field = {"site_is_childrens_epilepsy_surgery_centre": True} + update_fields = { + "site_is_general_paediatric_centre": False, + "site_is_paediatric_neurology_centre": False, + "site_is_childrens_epilepsy_surgery_centre": True, + } + + # selected_organisation has never been involved in child's care + if not Site.objects.filter( + case=case, + organisation=selected_organisation, + ).exists(): + Site.objects.create( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=False, + updated_at=timezone.now(), + updated_by=user, + site_is_actively_involved_in_epilepsy_care=True, + **update_fields + ) + else: + # selected_organisation is active lead centre + if Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=True, + site_is_actively_involved_in_epilepsy_care=True, + ).exists(): + # there can be only one of these + + Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=True, + site_is_actively_involved_in_epilepsy_care=True, + ).update(**update_field) + + # selected_organisation was previously lead centre + elif Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=True, + site_is_actively_involved_in_epilepsy_care=False, + ).exists(): + # create a new centre to be actively involved in care but + # not be primary centre. This allows historical lead centres to be recorded + + Site.objects.create( + case=case, + organisation=selected_organisation, + site_is_actively_involved_in_epilepsy_care=True, + site_is_primary_centre_of_epilepsy_care=False, + **update_fields + ) + + # selected_organisation was previously actively involved in care but not as primary centre + elif Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=False, + ).exists(): + # reactivate record and update for new role + + Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=False, + ).update(site_is_actively_involved_in_epilepsy_care=True, **update_fields) + + # selected_organisation is actively involved in care but not as primary centre + elif Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=True, + ).exists(): + # update role + + Site.objects.filter( + case=case, + organisation=selected_organisation, + site_is_primary_centre_of_epilepsy_care=False, + site_is_actively_involved_in_epilepsy_care=True, + ).update(**update_field) + + if site_id is not None: + # must delete the old record if this is an edit + old_site = Site.objects.get(pk=site_id) + if old_site.site_is_primary_centre_of_epilepsy_care == False: + old_site.delete() + + @login_and_otp_required() @permission_required("epilepsy12.change_assessment", raise_exception=True) @user_may_view_this_child() @@ -43,17 +172,31 @@ def consultant_paediatrician_referral_made(request, assessment_id): # refresh all objects and return assessment = Assessment.objects.get(pk=assessment_id) - # if any allocated sites make them historical + # if any allocated sites remove them if Site.objects.filter( case=assessment.registration.case, - site_is_actively_involved_in_epilepsy_care=True, site_is_general_paediatric_centre=True, ).exists(): - Site.objects.filter( + # loop through these and delete any site where the organisation + # is not used elsewhere for this child actively for any other attribute (surgery or neurology) + # or is not a historical or active lead site. If it is, set site_is_general_paediatric_centre to False + updated_general_paediatric_status_sites = Site.objects.filter( case=assessment.registration.case, - site_is_actively_involved_in_epilepsy_care=True, site_is_general_paediatric_centre=True, - ).update(site_is_actively_involved_in_epilepsy_care=False) + ) + for site in updated_general_paediatric_status_sites: + if ( + site.site_is_primary_centre_of_epilepsy_care == True + or ( + site.site_is_paediatric_neurology_centre + or site.site_is_childrens_epilepsy_surgery_centre + ) + and site.site_is_general_paediatric_centre + ): + site.site_is_general_paediatric_centre = False + site.save(update_fields=["site_is_general_paediatric_centre"]) + else: + site.delete() # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -212,30 +355,36 @@ def general_paediatric_centre(request, assessment_id): # if this registration already has a record in sites # associated with this organisation, # update it include general paediatrics, else create a new record - if Site.objects.filter( + # if Site.objects.filter( + # case=assessment.registration.case, + # organisation=general_paediatric_centre, + # site_is_actively_involved_in_epilepsy_care=True, + # ).exists(): + # Site.objects.filter( + # case=assessment.registration.case, organisation=general_paediatric_centre + # ).update( + # site_is_general_paediatric_centre=True, + # site_is_actively_involved_in_epilepsy_care=True, + # updated_at=timezone.now(), + # updated_by=request.user, + # ) + # else: + # site = Site.objects.create( + # case=assessment.registration.case, + # organisation=general_paediatric_centre, + # site_is_primary_centre_of_epilepsy_care=False, + # site_is_childrens_epilepsy_surgery_centre=False, + # site_is_actively_involved_in_epilepsy_care=True, + # site_is_paediatric_neurology_centre=False, + # site_is_general_paediatric_centre=True, + # ) + # site.save() + update_site_model( + centre_role="general_paediatric_centre", + selected_organisation=general_paediatric_centre, case=assessment.registration.case, - organisation=general_paediatric_centre, - site_is_actively_involved_in_epilepsy_care=True, - ).exists(): - Site.objects.filter( - case=assessment.registration.case, organisation=general_paediatric_centre - ).update( - site_is_general_paediatric_centre=True, - site_is_actively_involved_in_epilepsy_care=True, - updated_at=timezone.now(), - updated_by=request.user, - ) - else: - site = Site.objects.create( - case=assessment.registration.case, - organisation=general_paediatric_centre, - site_is_primary_centre_of_epilepsy_care=False, - site_is_childrens_epilepsy_surgery_centre=False, - site_is_actively_involved_in_epilepsy_care=True, - site_is_paediatric_neurology_centre=False, - site_is_general_paediatric_centre=True, - ) - site.save() + user=request.user, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -276,44 +425,51 @@ def edit_general_paediatric_centre(request, assessment_id, site_id): "edit_general_paediatric_centre" ) - new_organisation = Organisation.objects.get( + general_paediatric_centre = Organisation.objects.get( pk=selected_general_paediatric_centre_id ) assessment = Assessment.objects.get(pk=assessment_id) - if Site.objects.filter( + # if Site.objects.filter( + # case=assessment.registration.case, + # organisation=new_organisation, + # site_is_actively_involved_in_epilepsy_care=True, + # ).exists(): + # # this organisation trust already exists as an active site for this registration + # # update that record, update this to show + + # site = Site.objects.filter( + # case=assessment.registration.case, + # organisation=new_organisation, + # site_is_actively_involved_in_epilepsy_care=True, + # ).get() + # site.site_is_general_paediatric_centre = True + # site.updated_at = (timezone.now(),) + # site.updated_by = request.user + # site.save() + + # # update the old site to become historical + # old_site = Site.objects.get(pk=site_id) + # old_site.site_is_general_paediatric_centre = False + # old_site.save() + + # else: + # # this change is a new organisation + # Site.objects.filter(pk=site_id).update( + # organisation=new_organisation, + # site_is_general_paediatric_centre=True, + # site_is_actively_involved_in_epilepsy_care=True, + # updated_at=timezone.now(), + # updated_by=request.user, + # ) + update_site_model( + centre_role="general_paediatric_centre", + selected_organisation=general_paediatric_centre, case=assessment.registration.case, - organisation=new_organisation, - site_is_actively_involved_in_epilepsy_care=True, - ).exists(): - # this organisation trust already exists as an active site for this registration - # update that record, update this to show - - site = Site.objects.filter( - case=assessment.registration.case, - organisation=new_organisation, - site_is_actively_involved_in_epilepsy_care=True, - ).get() - site.site_is_general_paediatric_centre = True - site.updated_at = (timezone.now(),) - site.updated_by = request.user - site.save() - - # update the old site to become historical - old_site = Site.objects.get(pk=site_id) - old_site.site_is_general_paediatric_centre = False - old_site.save() - - else: - # this change is a new organisation - Site.objects.filter(pk=site_id).update( - organisation=new_organisation, - site_is_general_paediatric_centre=True, - site_is_actively_involved_in_epilepsy_care=True, - updated_at=timezone.now(), - updated_by=request.user, - ) + user=request.user, + site_id=site_id, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -491,17 +647,39 @@ def paediatric_neurologist_referral_made(request, assessment_id): # get new instance of Assessment assessment = Assessment.objects.get(pk=assessment_id) - # if any allocated sites make them historical + # # if any allocated sites make them historical + # if Site.objects.filter( + # case=assessment.registration.case, + # site_is_paediatric_neurology_centre=True, + # ).exists(): + # Site.objects.filter( + # case=assessment.registration.case, + # site_is_paediatric_neurology_centre=True, + # ).update(site_is_actively_involved_in_epilepsy_care=False) + # if any allocated sites remove them if Site.objects.filter( - case=assessment.registration.case, - site_is_actively_involved_in_epilepsy_care=True, - site_is_paediatric_neurology_centre=True, + case=assessment.registration.case, site_is_paediatric_neurology_centre=True ).exists(): - Site.objects.filter( + # loop through these and delete any site where the organisation + # is not used elsewhere for this child actively for any other attribute (surgery or neurology) + # or is not a historical or active lead site. If it is, set site_is_paediatric_neurology_centre to False + updated_neurology_status_sites = Site.objects.filter( case=assessment.registration.case, - site_is_actively_involved_in_epilepsy_care=True, site_is_paediatric_neurology_centre=True, - ).update(site_is_actively_involved_in_epilepsy_care=False) + ) + for site in updated_neurology_status_sites: + if ( + site.site_is_primary_centre_of_epilepsy_care == True + or ( + site.site_is_general_paediatric_centre + or site.site_is_childrens_epilepsy_surgery_centre + ) + and site.site_is_general_paediatric_centre + ): + site.site_is_paediatric_neurology_centre = False + site.save(update_fields=["site_is_paediatric_neurology_centre"]) + else: + site.delete() # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -665,28 +843,34 @@ def paediatric_neurology_centre(request, assessment_id): # if this registration already has a record in sites # associated with this organisation, # update it include paediatric neurology, else create a new record - if Site.objects.filter( - case=assessment.registration.case, organisation=paediatric_neurology_centre - ).exists(): - Site.objects.filter( - case=assessment.registration.case, organisation=paediatric_neurology_centre - ).update( - site_is_actively_involved_in_epilepsy_care=True, - site_is_paediatric_neurology_centre=True, - updated_at=timezone.now(), - updated_by=request.user, - ) - else: - site = Site.objects.create( - case=assessment.registration.case, - organisation=paediatric_neurology_centre, - site_is_primary_centre_of_epilepsy_care=False, - site_is_childrens_epilepsy_surgery_centre=False, - site_is_actively_involved_in_epilepsy_care=True, - site_is_paediatric_neurology_centre=True, - site_is_general_paediatric_centre=False, - ) - site.save() + # if Site.objects.filter( + # case=assessment.registration.case, organisation=paediatric_neurology_centre + # ).exists(): + # Site.objects.filter( + # case=assessment.registration.case, organisation=paediatric_neurology_centre + # ).update( + # site_is_actively_involved_in_epilepsy_care=True, + # site_is_paediatric_neurology_centre=True, + # updated_at=timezone.now(), + # updated_by=request.user, + # ) + # else: + # site = Site.objects.create( + # case=assessment.registration.case, + # organisation=paediatric_neurology_centre, + # site_is_primary_centre_of_epilepsy_care=False, + # site_is_childrens_epilepsy_surgery_centre=False, + # site_is_actively_involved_in_epilepsy_care=True, + # site_is_paediatric_neurology_centre=True, + # site_is_general_paediatric_centre=False, + # ) + # site.save() + update_site_model( + centre_role="paediatric_neurology_centre", + selected_organisation=paediatric_neurology_centre, + case=assessment.registration.case, + user=request.user, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -728,32 +912,39 @@ def edit_paediatric_neurology_centre(request, assessment_id, site_id): assessment = Assessment.objects.get(pk=assessment_id) - if Site.objects.filter( + # if Site.objects.filter( + # case=assessment.registration.case, + # organisation=paediatric_neurology_centre, + # site_is_actively_involved_in_epilepsy_care=True, + # ).exists(): + # # this organisation trust already exists for this registration + # # update that record, delete this + + # site = Site.objects.filter( + # case=assessment.registration.case, + # organisation=paediatric_neurology_centre, + # site_is_actively_involved_in_epilepsy_care=True, + # ).get() + # site.site_is_paediatric_neurology_centre = True + # site.save() + # Site.objects.get(pk=site_id).delete() + + # else: + # # this change is a new organisation + # Site.objects.filter(pk=site_id).update( + # organisation=paediatric_neurology_centre, + # site_is_paediatric_neurology_centre=True, + # site_is_actively_involved_in_epilepsy_care=True, + # updated_at=timezone.now(), + # updated_by=request.user, + # ) + update_site_model( + centre_role="paediatric_neurology_centre", + selected_organisation=paediatric_neurology_centre, case=assessment.registration.case, - organisation=paediatric_neurology_centre, - site_is_actively_involved_in_epilepsy_care=True, - ).exists(): - # this organisation trust already exists for this registration - # update that record, delete this - - site = Site.objects.filter( - case=assessment.registration.case, - organisation=paediatric_neurology_centre, - site_is_actively_involved_in_epilepsy_care=True, - ).get() - site.site_is_paediatric_neurology_centre = True - site.save() - Site.objects.get(pk=site_id).delete() - - else: - # this change is a new organisation - Site.objects.filter(pk=site_id).update( - organisation=paediatric_neurology_centre, - site_is_paediatric_neurology_centre=True, - site_is_actively_involved_in_epilepsy_care=True, - updated_at=timezone.now(), - updated_by=request.user, - ) + user=request.user, + site_id=site_id, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -844,14 +1035,14 @@ def delete_paediatric_neurology_centre(request, assessment_id, site_id): if ( associated_site.site_is_primary_centre_of_epilepsy_care - or associated_site.site_is_childrens_epilepsy_surgery_centre or associated_site.site_is_general_paediatric_centre + or associated_site.site_is_childrens_epilepsy_surgery_centre ): # this site also delivers (or has delivered) surgical or general paediatric care - # update to remove neurology - - associated_site.site_is_paediatric_neurology_centre = False - associated_site.save() + # update to remove general paeds + Site.objects.filter(pk=associated_site.pk).update( + site_is_paediatric_neurology_centre=False + ) else: # there are no other associated centres with this record: can delete @@ -976,17 +1167,41 @@ def childrens_epilepsy_surgical_service_referral_made(request, assessment_id): # get new instance of Assessment assessment = Assessment.objects.get(pk=assessment_id) - # if any allocated sites make them historical + # # if any allocated sites deallocate surgery + # if Site.objects.filter( + # case=assessment.registration.case, + # site_is_childrens_epilepsy_surgery_centre=True, + # ).exists(): + # Site.objects.filter( + # case=assessment.registration.case, + # site_is_childrens_epilepsy_surgery_centre=True, + # ).update(site_is_actively_involved_in_epilepsy_care=False) if Site.objects.filter( case=assessment.registration.case, - site_is_actively_involved_in_epilepsy_care=True, site_is_childrens_epilepsy_surgery_centre=True, ).exists(): - Site.objects.filter( + # loop through these and delete any site where the organisation + # is not used elsewhere for this child actively for any other attribute (general paediatric or neurology) + # or is not a historical or active lead site. If it is, set site_is_childrens_epilepsy_surgery_centre to False + updated_surgery_status_sites = Site.objects.filter( case=assessment.registration.case, - site_is_actively_involved_in_epilepsy_care=True, site_is_childrens_epilepsy_surgery_centre=True, - ).update(site_is_actively_involved_in_epilepsy_care=False) + ) + for site in updated_surgery_status_sites: + if ( + site.site_is_primary_centre_of_epilepsy_care == True + or ( + site.site_is_general_paediatric_centre + or site.site_is_paediatric_neurology_centre + ) + and site.site_is_general_paediatric_centre + ): + site.site_is_childrens_epilepsy_surgery_centre = False + site.save( + update_fields=["site_is_childrens_epilepsy_surgery_centre"] + ) + else: + site.delete() # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -1205,28 +1420,34 @@ def epilepsy_surgery_centre(request, assessment_id): # if this registration already has a record in sites # associated with this organisation, # update it to include epilepsy surgery, else create a new record - if Site.objects.filter( - case=assessment.registration.case, organisation=epilepsy_surgery_centre - ).exists(): - Site.objects.filter( - case=assessment.registration.case, organisation=epilepsy_surgery_centre - ).update( - site_is_actively_involved_in_epilepsy_care=True, - site_is_childrens_epilepsy_surgery_centre=True, - updated_at=timezone.now(), - updated_by=request.user, - ) - else: - site = Site.objects.create( - case=assessment.registration.case, - organisation=epilepsy_surgery_centre, - site_is_primary_centre_of_epilepsy_care=False, - site_is_childrens_epilepsy_surgery_centre=True, - site_is_actively_involved_in_epilepsy_care=True, - site_is_paediatric_neurology_centre=False, - site_is_general_paediatric_centre=False, - ) - site.save() + # if Site.objects.filter( + # case=assessment.registration.case, organisation=epilepsy_surgery_centre + # ).exists(): + # Site.objects.filter( + # case=assessment.registration.case, organisation=epilepsy_surgery_centre + # ).update( + # site_is_actively_involved_in_epilepsy_care=True, + # site_is_childrens_epilepsy_surgery_centre=True, + # updated_at=timezone.now(), + # updated_by=request.user, + # ) + # else: + # site = Site.objects.create( + # case=assessment.registration.case, + # organisation=epilepsy_surgery_centre, + # site_is_primary_centre_of_epilepsy_care=False, + # site_is_childrens_epilepsy_surgery_centre=True, + # site_is_actively_involved_in_epilepsy_care=True, + # site_is_paediatric_neurology_centre=False, + # site_is_general_paediatric_centre=False, + # ) + # site.save() + update_site_model( + centre_role="epilepsy_surgery_centre", + selected_organisation=epilepsy_surgery_centre, + case=assessment.registration.case, + user=request.user, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -1267,38 +1488,45 @@ def edit_epilepsy_surgery_centre(request, assessment_id, site_id): It updates the Site object with the new centre and returns the same partial template. """ - new_organisation = Organisation.objects.get( + epilepsy_surgery_centre = Organisation.objects.get( pk=request.POST.get("edit_epilepsy_surgery_centre") ) assessment = Assessment.objects.get(pk=assessment_id) - if Site.objects.filter( + # if Site.objects.filter( + # case=assessment.registration.case, + # organisation=new_organisation, + # site_is_actively_involved_in_epilepsy_care=True, + # ).exists(): + # # this organisation trust already exists for this registration + # # update that record, delete this + + # site = Site.objects.filter( + # case=assessment.registration.case, + # organisation=new_organisation, + # site_is_actively_involved_in_epilepsy_care=True, + # ).get() + # site.site_is_childrens_epilepsy_surgery_centre = True + # site.save() + # Site.objects.get(pk=site_id).delete() + + # else: + # # this change is a new organisation + # Site.objects.filter(pk=site_id).update( + # organisation=new_organisation, + # site_is_childrens_epilepsy_surgery_centre=True, + # site_is_actively_involved_in_epilepsy_care=True, + # updated_at=timezone.now(), + # updated_by=request.user, + # ) + update_site_model( + centre_role="epilepsy_surgery_centre", + selected_organisation=epilepsy_surgery_centre, case=assessment.registration.case, - organisation=new_organisation, - site_is_actively_involved_in_epilepsy_care=True, - ).exists(): - # this organisation trust already exists for this registration - # update that record, delete this - - site = Site.objects.filter( - case=assessment.registration.case, - organisation=new_organisation, - site_is_actively_involved_in_epilepsy_care=True, - ).get() - site.site_is_childrens_epilepsy_surgery_centre = True - site.save() - Site.objects.get(pk=site_id).delete() - - else: - # this change is a new organisation - Site.objects.filter(pk=site_id).update( - organisation=new_organisation, - site_is_childrens_epilepsy_surgery_centre=True, - site_is_actively_involved_in_epilepsy_care=True, - updated_at=timezone.now(), - updated_by=request.user, - ) + user=request.user, + site_id=site_id, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -1393,14 +1621,14 @@ def delete_epilepsy_surgery_centre(request, assessment_id, site_id): if ( associated_site.site_is_primary_centre_of_epilepsy_care - or associated_site.site_is_paediatric_neurology_centre or associated_site.site_is_general_paediatric_centre + or associated_site.site_is_paediatric_neurology_centre ): - # this site also delivers (or has delivered) paediatric or general paediatric care + # this site also delivers (or has delivered) neurology or general paediatric care # update to remove surgery - - associated_site.site_is_childrens_epilepsy_surgery_centre = False - associated_site.save() + Site.objects.filter(pk=associated_site.pk).update( + site_is_childrens_epilepsy_surgery_centre=False + ) else: # there are no other associated centres with this record: can delete diff --git a/epilepsy12/views/case_views.py b/epilepsy12/views/case_views.py index 10c6ed30..1c5ed331 100644 --- a/epilepsy12/views/case_views.py +++ b/epilepsy12/views/case_views.py @@ -408,7 +408,7 @@ def transfer_response(request, organisation_id, case_id, organisation_response): site_is_actively_involved_in_epilepsy_care=False, ).get() old_site.site_is_actively_involved_in_epilepsy_care = True - old_site.save() + old_site.save(update_fields=["site_is_actively_involved_in_epilepsy_care"]) # if the old site had other responsibilities that were retained, need to reallocate them back # and delete any records that stored them if Site.objects.filter( From 63e1393a4c320670cc099a2b25d696f0ed2119ba Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 7 Jan 2024 17:21:03 +0000 Subject: [PATCH 10/12] fix reject transfer request lose associated centres --- epilepsy12/views/assessment_views.py | 13 ++- epilepsy12/views/case_views.py | 109 +++++++++++++------------ epilepsy12/views/registration_views.py | 73 ++++++++++------- 3 files changed, 111 insertions(+), 84 deletions(-) diff --git a/epilepsy12/views/assessment_views.py b/epilepsy12/views/assessment_views.py index d032f397..45d51e42 100644 --- a/epilepsy12/views/assessment_views.py +++ b/epilepsy12/views/assessment_views.py @@ -34,6 +34,9 @@ def update_site_model( "site_is_general_paediatric_centre": True, "site_is_paediatric_neurology_centre": False, "site_is_childrens_epilepsy_surgery_centre": False, + "active_transfer": False, + "transfer_origin_organisation": None, + "transfer_request_date": None, } elif centre_role == "paediatric_neurology_centre": update_field = {"site_is_paediatric_neurology_centre": True} @@ -41,6 +44,9 @@ def update_site_model( "site_is_general_paediatric_centre": False, "site_is_paediatric_neurology_centre": True, "site_is_childrens_epilepsy_surgery_centre": False, + "active_transfer": False, + "transfer_origin_organisation": None, + "transfer_request_date": None, } elif centre_role == "epilepsy_surgery_centre": update_field = {"site_is_childrens_epilepsy_surgery_centre": True} @@ -48,6 +54,9 @@ def update_site_model( "site_is_general_paediatric_centre": False, "site_is_paediatric_neurology_centre": False, "site_is_childrens_epilepsy_surgery_centre": True, + "active_transfer": False, + "transfer_request_date": None, + "transfer_origin_organisation": None, } # selected_organisation has never been involved in child's care @@ -79,7 +88,9 @@ def update_site_model( organisation=selected_organisation, site_is_primary_centre_of_epilepsy_care=True, site_is_actively_involved_in_epilepsy_care=True, - ).update(**update_field) + ).update( + **update_field + ) # update only the status requested # selected_organisation was previously lead centre elif Site.objects.filter( diff --git a/epilepsy12/views/case_views.py b/epilepsy12/views/case_views.py index 1c5ed331..0938ee0e 100644 --- a/epilepsy12/views/case_views.py +++ b/epilepsy12/views/case_views.py @@ -382,71 +382,74 @@ def transfer_response(request, organisation_id, case_id, organisation_response): Updates associated Site instance and redirects back to case table """ + target_organisation = Organisation.objects.get(pk=organisation_id) case = Case.objects.get(pk=case_id) site = Site.objects.get( - case=case, active_transfer=True, site_is_primary_centre_of_epilepsy_care=True + case=case, + active_transfer=True, + site_is_primary_centre_of_epilepsy_care=True, + organisation=target_organisation, ) + # prepare email response to requesting organisation clinical lead email = construct_transfer_epilepsy12_site_outcome_email( request=request, - target_organisation=Organisation.objects.get(pk=organisation_id), + target_organisation=target_organisation, outcome=f"{organisation_response}ed", ) origin_organisation = site.transfer_origin_organisation if organisation_response == "reject": - # reset the child back to the origin organisation - if Site.objects.filter( - organisation=origin_organisation, - site_is_primary_centre_of_epilepsy_care=True, - site_is_actively_involved_in_epilepsy_care=False, - ).exists(): - # old record exist - reactivate - old_site = Site.objects.filter( - case=case, - organisation=origin_organisation, - site_is_primary_centre_of_epilepsy_care=True, - site_is_actively_involved_in_epilepsy_care=False, - ).get() - old_site.site_is_actively_involved_in_epilepsy_care = True - old_site.save(update_fields=["site_is_actively_involved_in_epilepsy_care"]) - # if the old site had other responsibilities that were retained, need to reallocate them back - # and delete any records that stored them - if Site.objects.filter( - ( - Q(site_is_childrens_epilepsy_surgery_centre=True) - | Q(site_is_paediatric_neurology_centre=True) - | Q(site_is_general_paediatric_centre=True) - ), - case=case, - organisation=origin_organisation, - active_transfer=True, + # Any additional responsibilities that were previously maintained before + # transfer by the target organisation must be handed back by creating new record + if ( + site.site_is_childrens_epilepsy_surgery_centre + or site.site_is_paediatric_neurology_centre + or site.site_is_general_paediatric_centre + ): + Site.objects.create( + site_is_childrens_epilepsy_surgery_centre=site.site_is_childrens_epilepsy_surgery_centre, + site_is_paediatric_neurology_centre=site.site_is_paediatric_neurology_centre, + site_is_general_paediatric_centre=site.site_is_general_paediatric_centre, site_is_primary_centre_of_epilepsy_care=False, site_is_actively_involved_in_epilepsy_care=True, - ).exists(): - old_site_additional_responsibilities = Site.objects.filter( - ( - Q(site_is_childrens_epilepsy_surgery_centre=True) - | Q(site_is_paediatric_neurology_centre=True) - | Q(site_is_general_paediatric_centre=True) - ), - case=case, - organisation=origin_organisation, - active_transfer=True, - site_is_primary_centre_of_epilepsy_care=False, - site_is_actively_involved_in_epilepsy_care=True, - ).first() - old_site_additional_responsibilities.delete() - # delete this record - site.delete() - else: - # no previous record to reanimate - # continue with this record - # no longer in active transfer - site.active_transfer = False - site.organisation = site.transfer_origin_organisation - site.transfer_origin_organisation = None - site.transfer_request_date = None - site.save() + case=case, + organisation=target_organisation, + ) + # Reset the site back to original organisation + site.site_is_childrens_epilepsy_surgery_centre = False + site.site_is_paediatric_neurology_centre = False + site.site_is_general_paediatric_centre = False + site.active_transfer = False + site.organisation = site.transfer_origin_organisation + site.transfer_origin_organisation = None + site.transfer_request_date = None + site.site_is_primary_centre_of_epilepsy_care = True + site.site_is_actively_involved_in_epilepsy_care = True + + site.save( + update_fields=[ + "site_is_childrens_epilepsy_surgery_centre", + "site_is_paediatric_neurology_centre", + "site_is_general_paediatric_centre", + "active_transfer", + "organisation", + "transfer_origin_organisation", + "transfer_request_date", + "site_is_primary_centre_of_epilepsy_care", + "site_is_actively_involved_in_epilepsy_care", + ] + ) + + # if the origin lead site had other responsibilities prior to transfer, a new record + # would have been created in the transfer process to hold these. This record + # now needs deleting + + Site.objects.filter( + case=case, + organisation=site.organisation, # this is the origin organisation + site_is_actively_involved_in_epilepsy_care=False, + ).delete() + elif organisation_response == "accept": site.active_transfer = False site.transfer_origin_organisation = None diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index ae04af55..9bbc7e97 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -356,6 +356,48 @@ def update_lead_site(request, registration_id, site_id, update): new_organisation_id = request.POST.get("transfer_lead_site") new_organisation = Organisation.objects.get(pk=new_organisation_id) + # create new record in Site table for child against new centre, or update existing record if + # organisation already involved in child's care + if Site.objects.filter( + organisation=new_organisation, + case=registration.case, + site_is_actively_involved_in_epilepsy_care=True, + ).exists(): + # this new site already cares actively for this child in some capacity + new_lead_site = Site.objects.filter( + organisation=new_organisation, + case=registration.case, + site_is_actively_involved_in_epilepsy_care=True, + ).get() + new_lead_site.site_is_primary_centre_of_epilepsy_care = True + new_lead_site.site_is_actively_involved_in_epilepsy_care = True + new_lead_site.active_transfer = True + new_lead_site.transfer_origin_organisation = origin_organisation + new_lead_site.transfer_request_date = timezone.now() + new_lead_site.save( + update_fields=[ + "site_is_primary_centre_of_epilepsy_care", + "site_is_actively_involved_in_epilepsy_care", + "active_transfer", + "transfer_origin_organisation", + "transfer_request_date", + ] + ) + + else: + # this new organisation does not care for this child. Create a new site associated with this organisation + new_lead_site = Site.objects.create( + organisation=new_organisation, + site_is_primary_centre_of_epilepsy_care=True, + site_is_actively_involved_in_epilepsy_care=True, + active_transfer=True, + transfer_origin_organisation=origin_organisation, + transfer_request_date=timezone.now(), + updated_at=timezone.now(), + updated_by=request.user, + case=registration.case, + ) + if ( previous_lead_site.site_is_childrens_epilepsy_surgery_centre or previous_lead_site.site_is_paediatric_neurology_centre @@ -365,6 +407,7 @@ def update_lead_site(request, registration_id, site_id, update): # but is not the lead site anymore # To allow us to track the fact that this site was once the lead site for this child, # we must create a new record to track the fact that this site is still involved in the care + Site.objects.create( case=registration.case, organisation=origin_organisation, @@ -386,36 +429,6 @@ def update_lead_site(request, registration_id, site_id, update): ] ) - # create new record in Site table for child against new centre, or update existing record if - # organisation already involved in child's care - if Site.objects.filter( - organisation=new_organisation, - case=registration.case, - ).exists(): - # this new site already cares for this child in some capacity, either past or present - new_lead_site = Site.objects.filter( - organisation=new_organisation, case=registration.case - ).get() - new_lead_site.site_is_primary_centre_of_epilepsy_care = True - new_lead_site.site_is_actively_involved_in_epilepsy_care = True - new_lead_site.active_transfer = True - new_lead_site.transfer_origin_organisation = origin_organisation - new_lead_site.transfer_request_date = timezone.now() - new_lead_site.save() - else: - # this new organisation does not care for this child. Create a new site associated with this organisation - new_lead_site = Site.objects.create( - organisation=new_organisation, - site_is_primary_centre_of_epilepsy_care=True, - site_is_actively_involved_in_epilepsy_care=True, - active_transfer=True, - transfer_origin_organisation=origin_organisation, - transfer_request_date=timezone.now(), - updated_at=timezone.now(), - updated_by=request.user, - case=registration.case, - ) - """ Update complete Send emails to lead clinicians +/- E12 From 4354fc2683b1a30166017712fcdd21b1dcc0d13d Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 7 Jan 2024 18:21:32 +0000 Subject: [PATCH 11/12] remove transfer flag from newly created site --- epilepsy12/views/registration_views.py | 1 - templates/epilepsy12/forms/case_form.html | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/epilepsy12/views/registration_views.py b/epilepsy12/views/registration_views.py index 9bbc7e97..9de02eb3 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -416,7 +416,6 @@ def update_lead_site(request, registration_id, site_id, update): site_is_childrens_epilepsy_surgery_centre=previous_lead_site.site_is_childrens_epilepsy_surgery_centre, site_is_paediatric_neurology_centre=previous_lead_site.site_is_paediatric_neurology_centre, site_is_general_paediatric_centre=previous_lead_site.site_is_general_paediatric_centre, - active_transfer=True, # this flag will be set to false if transfer accepted or used to delete record if transfer ultimately refused ) # update current site record to show nolonger actively involved in care as primary centre diff --git a/templates/epilepsy12/forms/case_form.html b/templates/epilepsy12/forms/case_form.html index 526eaba8..faff211d 100644 --- a/templates/epilepsy12/forms/case_form.html +++ b/templates/epilepsy12/forms/case_form.html @@ -133,7 +133,11 @@ Cancel {% if perms.epilepsy12.change_case or perms.epilepsy12.add_case %} - From 1babb6f79c6ec6cb2500366bf46f5646e3bc97b9 Mon Sep 17 00:00:00 2001 From: Marcus Baw Date: Mon, 8 Jan 2024 15:40:00 +0000 Subject: [PATCH 12/12] removes commented out code --- epilepsy12/views/assessment_views.py | 183 --------------------------- 1 file changed, 183 deletions(-) diff --git a/epilepsy12/views/assessment_views.py b/epilepsy12/views/assessment_views.py index 45d51e42..f2c1fbe8 100644 --- a/epilepsy12/views/assessment_views.py +++ b/epilepsy12/views/assessment_views.py @@ -363,33 +363,6 @@ def general_paediatric_centre(request, assessment_id): ) assessment = Assessment.objects.get(pk=assessment_id) - # if this registration already has a record in sites - # associated with this organisation, - # update it include general paediatrics, else create a new record - # if Site.objects.filter( - # case=assessment.registration.case, - # organisation=general_paediatric_centre, - # site_is_actively_involved_in_epilepsy_care=True, - # ).exists(): - # Site.objects.filter( - # case=assessment.registration.case, organisation=general_paediatric_centre - # ).update( - # site_is_general_paediatric_centre=True, - # site_is_actively_involved_in_epilepsy_care=True, - # updated_at=timezone.now(), - # updated_by=request.user, - # ) - # else: - # site = Site.objects.create( - # case=assessment.registration.case, - # organisation=general_paediatric_centre, - # site_is_primary_centre_of_epilepsy_care=False, - # site_is_childrens_epilepsy_surgery_centre=False, - # site_is_actively_involved_in_epilepsy_care=True, - # site_is_paediatric_neurology_centre=False, - # site_is_general_paediatric_centre=True, - # ) - # site.save() update_site_model( centre_role="general_paediatric_centre", selected_organisation=general_paediatric_centre, @@ -442,38 +415,6 @@ def edit_general_paediatric_centre(request, assessment_id, site_id): assessment = Assessment.objects.get(pk=assessment_id) - # if Site.objects.filter( - # case=assessment.registration.case, - # organisation=new_organisation, - # site_is_actively_involved_in_epilepsy_care=True, - # ).exists(): - # # this organisation trust already exists as an active site for this registration - # # update that record, update this to show - - # site = Site.objects.filter( - # case=assessment.registration.case, - # organisation=new_organisation, - # site_is_actively_involved_in_epilepsy_care=True, - # ).get() - # site.site_is_general_paediatric_centre = True - # site.updated_at = (timezone.now(),) - # site.updated_by = request.user - # site.save() - - # # update the old site to become historical - # old_site = Site.objects.get(pk=site_id) - # old_site.site_is_general_paediatric_centre = False - # old_site.save() - - # else: - # # this change is a new organisation - # Site.objects.filter(pk=site_id).update( - # organisation=new_organisation, - # site_is_general_paediatric_centre=True, - # site_is_actively_involved_in_epilepsy_care=True, - # updated_at=timezone.now(), - # updated_by=request.user, - # ) update_site_model( centre_role="general_paediatric_centre", selected_organisation=general_paediatric_centre, @@ -658,22 +599,9 @@ def paediatric_neurologist_referral_made(request, assessment_id): # get new instance of Assessment assessment = Assessment.objects.get(pk=assessment_id) - # # if any allocated sites make them historical - # if Site.objects.filter( - # case=assessment.registration.case, - # site_is_paediatric_neurology_centre=True, - # ).exists(): - # Site.objects.filter( - # case=assessment.registration.case, - # site_is_paediatric_neurology_centre=True, - # ).update(site_is_actively_involved_in_epilepsy_care=False) - # if any allocated sites remove them if Site.objects.filter( case=assessment.registration.case, site_is_paediatric_neurology_centre=True ).exists(): - # loop through these and delete any site where the organisation - # is not used elsewhere for this child actively for any other attribute (surgery or neurology) - # or is not a historical or active lead site. If it is, set site_is_paediatric_neurology_centre to False updated_neurology_status_sites = Site.objects.filter( case=assessment.registration.case, site_is_paediatric_neurology_centre=True, @@ -851,31 +779,6 @@ def paediatric_neurology_centre(request, assessment_id): ) assessment = Assessment.objects.get(pk=assessment_id) - # if this registration already has a record in sites - # associated with this organisation, - # update it include paediatric neurology, else create a new record - # if Site.objects.filter( - # case=assessment.registration.case, organisation=paediatric_neurology_centre - # ).exists(): - # Site.objects.filter( - # case=assessment.registration.case, organisation=paediatric_neurology_centre - # ).update( - # site_is_actively_involved_in_epilepsy_care=True, - # site_is_paediatric_neurology_centre=True, - # updated_at=timezone.now(), - # updated_by=request.user, - # ) - # else: - # site = Site.objects.create( - # case=assessment.registration.case, - # organisation=paediatric_neurology_centre, - # site_is_primary_centre_of_epilepsy_care=False, - # site_is_childrens_epilepsy_surgery_centre=False, - # site_is_actively_involved_in_epilepsy_care=True, - # site_is_paediatric_neurology_centre=True, - # site_is_general_paediatric_centre=False, - # ) - # site.save() update_site_model( centre_role="paediatric_neurology_centre", selected_organisation=paediatric_neurology_centre, @@ -923,32 +826,6 @@ def edit_paediatric_neurology_centre(request, assessment_id, site_id): assessment = Assessment.objects.get(pk=assessment_id) - # if Site.objects.filter( - # case=assessment.registration.case, - # organisation=paediatric_neurology_centre, - # site_is_actively_involved_in_epilepsy_care=True, - # ).exists(): - # # this organisation trust already exists for this registration - # # update that record, delete this - - # site = Site.objects.filter( - # case=assessment.registration.case, - # organisation=paediatric_neurology_centre, - # site_is_actively_involved_in_epilepsy_care=True, - # ).get() - # site.site_is_paediatric_neurology_centre = True - # site.save() - # Site.objects.get(pk=site_id).delete() - - # else: - # # this change is a new organisation - # Site.objects.filter(pk=site_id).update( - # organisation=paediatric_neurology_centre, - # site_is_paediatric_neurology_centre=True, - # site_is_actively_involved_in_epilepsy_care=True, - # updated_at=timezone.now(), - # updated_by=request.user, - # ) update_site_model( centre_role="paediatric_neurology_centre", selected_organisation=paediatric_neurology_centre, @@ -1178,15 +1055,6 @@ def childrens_epilepsy_surgical_service_referral_made(request, assessment_id): # get new instance of Assessment assessment = Assessment.objects.get(pk=assessment_id) - # # if any allocated sites deallocate surgery - # if Site.objects.filter( - # case=assessment.registration.case, - # site_is_childrens_epilepsy_surgery_centre=True, - # ).exists(): - # Site.objects.filter( - # case=assessment.registration.case, - # site_is_childrens_epilepsy_surgery_centre=True, - # ).update(site_is_actively_involved_in_epilepsy_care=False) if Site.objects.filter( case=assessment.registration.case, site_is_childrens_epilepsy_surgery_centre=True, @@ -1428,31 +1296,6 @@ def epilepsy_surgery_centre(request, assessment_id): ) assessment = Assessment.objects.get(pk=assessment_id) - # if this registration already has a record in sites - # associated with this organisation, - # update it to include epilepsy surgery, else create a new record - # if Site.objects.filter( - # case=assessment.registration.case, organisation=epilepsy_surgery_centre - # ).exists(): - # Site.objects.filter( - # case=assessment.registration.case, organisation=epilepsy_surgery_centre - # ).update( - # site_is_actively_involved_in_epilepsy_care=True, - # site_is_childrens_epilepsy_surgery_centre=True, - # updated_at=timezone.now(), - # updated_by=request.user, - # ) - # else: - # site = Site.objects.create( - # case=assessment.registration.case, - # organisation=epilepsy_surgery_centre, - # site_is_primary_centre_of_epilepsy_care=False, - # site_is_childrens_epilepsy_surgery_centre=True, - # site_is_actively_involved_in_epilepsy_care=True, - # site_is_paediatric_neurology_centre=False, - # site_is_general_paediatric_centre=False, - # ) - # site.save() update_site_model( centre_role="epilepsy_surgery_centre", selected_organisation=epilepsy_surgery_centre, @@ -1505,32 +1348,6 @@ def edit_epilepsy_surgery_centre(request, assessment_id, site_id): assessment = Assessment.objects.get(pk=assessment_id) - # if Site.objects.filter( - # case=assessment.registration.case, - # organisation=new_organisation, - # site_is_actively_involved_in_epilepsy_care=True, - # ).exists(): - # # this organisation trust already exists for this registration - # # update that record, delete this - - # site = Site.objects.filter( - # case=assessment.registration.case, - # organisation=new_organisation, - # site_is_actively_involved_in_epilepsy_care=True, - # ).get() - # site.site_is_childrens_epilepsy_surgery_centre = True - # site.save() - # Site.objects.get(pk=site_id).delete() - - # else: - # # this change is a new organisation - # Site.objects.filter(pk=site_id).update( - # organisation=new_organisation, - # site_is_childrens_epilepsy_surgery_centre=True, - # site_is_actively_involved_in_epilepsy_care=True, - # updated_at=timezone.now(), - # updated_by=request.user, - # ) update_site_model( centre_role="epilepsy_surgery_centre", selected_organisation=epilepsy_surgery_centre,