diff --git a/epilepsy12/views/assessment_views.py b/epilepsy12/views/assessment_views.py index cd4460b1..f2c1fbe8 100644 --- a/epilepsy12/views/assessment_views.py +++ b/epilepsy12/views/assessment_views.py @@ -9,6 +9,146 @@ 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, + "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} + update_fields = { + "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} + update_fields = { + "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 + 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 + ) # update only the status requested + + # 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 +183,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") @@ -209,33 +363,12 @@ 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( + 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 +409,19 @@ 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( + 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 +599,26 @@ 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_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( + 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") @@ -662,31 +779,12 @@ 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, + case=assessment.registration.case, + user=request.user, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -728,32 +826,13 @@ def edit_paediatric_neurology_centre(request, assessment_id, site_id): assessment = Assessment.objects.get(pk=assessment_id) - if Site.objects.filter( + 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 +923,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 +1055,32 @@ 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 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") @@ -1202,31 +1296,12 @@ 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, + case=assessment.registration.case, + user=request.user, + ) # filter list to include only NHS organisations organisation_list = Organisation.objects.order_by("name") @@ -1267,38 +1342,19 @@ 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( + 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 +1449,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 16cfdd56..f07db138 100644 --- a/epilepsy12/views/case_views.py +++ b/epilepsy12/views/case_views.py @@ -11,7 +11,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 @@ -386,33 +385,90 @@ 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 = Site.objects.get( + 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 orgin organisation + # 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, + 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 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") - 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..9de02eb3 100644 --- a/epilepsy12/views/registration_views.py +++ b/epilepsy12/views/registration_views.py @@ -266,7 +266,14 @@ 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() + # remove the currently selected organisation from the list - should not be able to + # transfer to the current organisation + organisation_list = ( + Organisation.objects.filter() + .exclude(pk=site.organisation.pk) + .order_by("name") + .all() + ) context = { "organisation_list": organisation_list, @@ -349,28 +356,34 @@ 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() - # 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 for this child in some capacity, either past or present + # this new site already cares actively for this child in some capacity new_lead_site = Site.objects.filter( - organisation=new_organisation, case=registration.case + 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() + 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( @@ -385,6 +398,36 @@ def update_lead_site(request, registration_id, site_id, update): case=registration.case, ) + 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, + ) + + # 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", + ] + ) + """ Update complete Send emails to lead clinicians +/- E12 @@ -402,7 +445,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" 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 diff --git a/templates/epilepsy12/forms/case_form.html b/templates/epilepsy12/forms/case_form.html index 70080704..faff211d 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" %}
{% if organisation.trust %} - {{organisation.name}}({{organisation.trust.name}}) ({{form.id}}) + {{organisation.name}}({{organisation.trust.name}}) {% else %} {{organisation.name}}({{organisation.local_health_board.name}}) {% endif %} @@ -136,7 +133,11 @@ Cancel {% if perms.epilepsy12.change_case or perms.epilepsy12.add_case %} -