Skip to content

Commit

Permalink
add lead centre to context processors and templates and session
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourpeas committed Feb 1, 2025
1 parent 54e56a3 commit b8568a2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 21 deletions.
6 changes: 3 additions & 3 deletions project/npda/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from project.npda.general_functions import get_current_audit_year


def session_data(request):
return {
"can_complete_questionnaire": request.session.get(
Expand All @@ -11,6 +12,7 @@ def session_data(request):
"pz_code": request.session.get("pz_code", None),
"requested_audit_year": request.session.get("requested_audit_year", None),
"audit_years": request.session.get("audit_years", []),
"lead_organisation": request.session.get("lead_organisation", None),
}


Expand Down Expand Up @@ -50,6 +52,4 @@ def can_use_questionnaire(request):
):
return {"can_use_questionnaire": True}

return {
"can_use_questionnaire": False
}
return {"can_use_questionnaire": False}
34 changes: 34 additions & 0 deletions project/npda/general_functions/rcpch_nhs_organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,37 @@ def fetch_local_authorities_within_radius(
response.raise_for_status()

return response.json()


def synchronize_pdus_with_rcpch_nhs_organisations():
"""
This function synchronizes the NHS organisations from the RCPCH dataset with the local database.
"""

PDU = apps.get_model("npda", "PaediatricDiabetesUnit")
Organisation = apps.get_model("npda", "Organisation")

request_url = (
f"{settings.RCPCH_NHS_ORGANISATIONS_API_URL}/paeidatric_diabetes_units/"
)

headers = {"Ocp-Apim-Subscription-Key": settings.RCPCH_NHS_ORGANISATIONS_API_KEY}

response = requests.get(request_url, headers=headers, timeout=10)
response.raise_for_status()

print(response.json())

# for pz_code, trust in all_pz_codes_with_their_trust_and_primary_organisation:
# try:
# organisation = Organisation.objects.get(ods_code=pz_code)
# except NHSOrganisation.DoesNotExist:
# organisation = Organisation(ods_code=pz_code)

# organisation.trust = trust
# organisation.save()

# pdus = PDU.objects.filter(ods_code=pz_code)
# for pdu in pdus:
# pdu.nhs_organisation = organisation
# pdu.save()
11 changes: 8 additions & 3 deletions project/npda/general_functions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
organisations_adapter,
get_audit_period_for_date,
get_current_audit_year,
SUPPORTED_AUDIT_YEARS
SUPPORTED_AUDIT_YEARS,
)

logger = logging.getLogger(__name__)
Expand All @@ -34,7 +34,7 @@ def get_submission_actions(pz_code, audit_year):
else:
can_upload_csv = False
can_complete_questionnaire = True

return {
"can_upload_csv": can_upload_csv,
"can_complete_questionnaire": can_complete_questionnaire,
Expand Down Expand Up @@ -63,6 +63,7 @@ def create_session_object(user):

session = {
"pz_code": pz_code,
"lead_organisation": primary_organisation.paediatric_diabetes_unit.lead_organisation_name,
"pdu_choices": list(pdu_choices),
"selected_audit_year": audit_year,
"audit_years": SUPPORTED_AUDIT_YEARS,
Expand All @@ -81,6 +82,7 @@ def get_new_session_fields(user, pz_code):
ret = {}

Submission = apps.get_model("npda", "Submission")
PaediatricDiabetesUnit = apps.get_model("npda", "PaediatricDiabetesUnit")
can_upload_csv = True
can_complete_questionnaire = True

Expand All @@ -99,12 +101,15 @@ def get_new_session_fields(user, pz_code):
raise PermissionDenied()

ret["pz_code"] = pz_code
ret["lead_organisation"] = PaediatricDiabetesUnit.objects.get(
pz_code=pz_code
).lead_organisation_name
ret["pdu_choices"] = list(
organisations_adapter.paediatric_diabetes_units_to_populate_select_field(
requesting_user=user, user_instance=None
)
)

ret |= get_submission_actions(pz_code, audit_year)

return ret
Expand Down
5 changes: 3 additions & 2 deletions project/npda/models/paediatric_diabetes_unit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib.gis.db.models import Model, CharField
from django.contrib.gis.db import models
from django.contrib.gis.db.models import CharField


class PaediatricDiabetesUnit(Model):
class PaediatricDiabetesUnit(models.Model):
"""
This model stores the paediatric diabetes unit reference PZ code and ODS code of the associated organisation
"""
Expand Down
13 changes: 2 additions & 11 deletions project/npda/templates/dashboard/dashboard_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
hx-swap="innerHTML">
<div class="my-6">
<h1 class="text-5xl text-center">
PDU Dashboard for {{ pdu_lead_organisation.name }} ({{ pdu_object.pz_code }})

PDU Dashboard for {{ lead_organisation }} ({{ pdu_object.pz_code }})
</h1>
<p class="text-center text-gray-500 mt-2">
Calculated at {{ kpi_calculations_object.calculation_datetime }}
Expand All @@ -21,38 +20,30 @@ <h1 class="text-5xl text-center">
{% include 'dashboard/components/cards/pdu_card.html' %}
<!-- Audit Details Card -->
{% include 'dashboard/components/cards/audit_details_card.html' %}

<div class="flex flex-col gap-3">
<!-- HBa1c CARD -->
{% include 'dashboard/components/cards/hba1c_card.html' %}
<!-- ADMISSIONS CARD -->
{% include 'dashboard/components/cards/admissions_card.html' %}
</div>


</div>
<!-- UNIT REPORT -->
<h1 class="text-5xl text-center my-6">Unit Report</h1>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">

<!-- PATIENT CHARACTERISTICS CARD -->
{% include 'dashboard/components/cards/patient_characteristics_card.html' %}

<div class="flex flex-col gap-3">
<!-- TREATMENT REGIMEN CARD -->
{% include 'dashboard/components/cards/treatment_regimen_card.html' %}
<!-- GLUCOSE MONITORING CARD -->
{% include 'dashboard/components/cards/glucose_monitoring_card.html' %}
</div>

<div class="flex flex-col gap-3">
<!-- Total Eligible Patients Card -->
{% include 'dashboard/components/cards/total_eligible_patients_card.html' %}
<!-- HCL CARD -->
{% include 'dashboard/components/cards/hcl_use_card.html' %}

</div>

</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 my-4">
<!-- HEALTH CHECKS COMPLETION RATE CARD -->
Expand All @@ -77,5 +68,5 @@ <h1 class="text-5xl text-center my-6">Unit Report</h1>
<!-- PATIENT LEVEL REPORT -->
<h1 class="text-5xl text-center my-6">Patient-Level Report</h1>
<!-- SELECT TABS & TABLE -->
{% include 'dashboard/pt_level_report_table_partial.html' with text=default_pt_level_menu_text selected=default_pt_level_menu_tab_selected highlight=default_highlight table_data=default_table_data %}
{% include 'dashboard/pt_level_report_table_partial.html' with text=default_pt_level_menu_text selected=default_pt_level_menu_tab_selected highlight=default_highlight table_data=default_table_data %}
</div>
2 changes: 1 addition & 1 deletion project/npda/templates/partials/npda_user_table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load npda_tags %}
<h1 class="font-montserrat text-md text-rcpch_dark_blue font-semibold">
NPDA Users at {{ chosen_pdu }}
NPDA Users at {{ lead_organisation }} ({{ chosen_pdu }})
</h1>
{% if npdauser_list %}
<table class="font-montserrat table-md w-full table mb-5 text-sm text-left text-gray-400 text-gray-500 rtl:text-right">
Expand Down
2 changes: 1 addition & 1 deletion project/npda/templates/partials/submission_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% if request.user.view_preference == 1 %}
<!-- national view -->
<h1 class="font-montserrat text-md text-rcpch_dark_blue font-semibold">
All Submissions for {{ pz_code }}
All Submissions for {{ lead_organisation }} ({{ pz_code }})
</h1>
{% elif request.user.view_preference == 2 %}
<!-- PDU view -->
Expand Down

0 comments on commit b8568a2

Please sign in to comment.