From aa4b0ee56b76db61788619647ac2900dd8697012 Mon Sep 17 00:00:00 2001
From: Simon Chapman
Date: Sat, 6 May 2023 12:47:07 +0100
Subject: [PATCH 01/10] fix none in snomed drugs
---
.../templatetags/epilepsy12_template_tags.py | 139 ++++++++++--------
.../antiepilepsy_medicine_list.html | 4 +-
.../partials/page_elements/select_model.html | 2 +-
3 files changed, 82 insertions(+), 63 deletions(-)
diff --git a/epilepsy12/templatetags/epilepsy12_template_tags.py b/epilepsy12/templatetags/epilepsy12_template_tags.py
index 57776f75..6ee7404c 100644
--- a/epilepsy12/templatetags/epilepsy12_template_tags.py
+++ b/epilepsy12/templatetags/epilepsy12_template_tags.py
@@ -34,10 +34,10 @@ def date_string(date):
@register.simple_tag
def characters_left(description):
- length = 2000-len(description)
- colour = 'black'
- if (length < 100):
- colour = 'red'
+ length = 2000 - len(description)
+ colour = "black"
+ if length < 100:
+ colour = "red"
safe_text = f'{length}'
return mark_safe(safe_text)
@@ -45,70 +45,73 @@ def characters_left(description):
@register.simple_tag
def percentage_of_total(numerator, denominator):
if numerator and denominator:
- if (int(denominator) > 0):
- return round(int(numerator)/int(denominator)*100)
+ if int(denominator) > 0:
+ return round(int(numerator) / int(denominator) * 100)
@register.simple_tag
def kpi_for_kpi_name(aggregated_kpi, kpi_name, color=False):
-
# guard clause check if color should be returned
if color:
- return aggregated_kpi['color']
- if aggregated_kpi['aggregated_kpis'][kpi_name] is None:
+ return aggregated_kpi["color"]
+ if aggregated_kpi["aggregated_kpis"][kpi_name] is None:
return -1
else:
- pct = 100*aggregated_kpi['aggregated_kpis'][kpi_name] / aggregated_kpi['aggregated_kpis']['total_number_of_cases']
+ pct = (
+ 100
+ * aggregated_kpi["aggregated_kpis"][kpi_name]
+ / aggregated_kpi["aggregated_kpis"]["total_number_of_cases"]
+ )
return pct
@register.simple_tag
def kpi_average_for_kpi_name(aggregated_kpi, kpi_name):
- if aggregated_kpi['aggregated_kpis'][kpi_name] is None:
+ if aggregated_kpi["aggregated_kpis"][kpi_name] is None:
return 0
else:
- return aggregated_kpi['aggregated_kpis'][f'{kpi_name}_average']
+ return aggregated_kpi["aggregated_kpis"][f"{kpi_name}_average"]
@register.simple_tag
def formatlabel(label):
if label is None:
- return 'Unclassified'
+ return "Unclassified"
else:
- nhs_icb_string = re.search(
- r'(NHS\s)(.+)(\sINTEGRATED CARE BOARD)', label)
+ nhs_icb_string = re.search(r"(NHS\s)(.+)(\sINTEGRATED CARE BOARD)", label)
if nhs_icb_string:
# \u002D fixes hyphen render for 'Stoke-on-trent'
- return nhs_icb_string.group(2).replace(r'\u002D','-').title()
+ return nhs_icb_string.group(2).replace(r"\u002D", "-").title()
return label
@register.filter
def custom_filter(text, color):
safe_text = '{text}'.format(
- color=color, text=text)
+ color=color, text=text
+ )
return mark_safe(safe_text)
@register.simple_tag
def permission_text(add_permission, change_permission, delete_permission, model_name):
- return_string = 'You do not have permission to'
+ return_string = "You do not have permission to"
if add_permission:
if change_permission and not delete_permission:
- return_string += f' delete {model_name}.'
+ return_string += f" delete {model_name}."
elif not change_permission and delete_permission:
- return_string += f' edit {model_name}.'
+ return_string += f" edit {model_name}."
elif not change_permission and not delete_permission:
- return_string += f' edit or delete {model_name}.'
+ return_string += f" edit or delete {model_name}."
else:
return_string = ""
else:
if change_permission and not delete_permission:
- return_string += f' add or delete {model_name}.'
+ return_string += f" add or delete {model_name}."
elif not change_permission and not delete_permission:
- return_string += f' add, edit or delete {model_name}.'
+ return_string += f" add, edit or delete {model_name}."
elif change_permission and delete_permission:
- return_string += f' add {model_name}.'
+ return_string += f" add {model_name}."
else:
return_string = ""
@@ -130,7 +133,7 @@ def snomed_concept(concept_id):
if concept_id is None:
return
concept = fetch_concept(concept_id)
- return concept['preferredDescription']['term']
+ return concept["preferredDescription"]["term"]
@register.filter
@@ -142,7 +145,7 @@ def is_in(url_name, args):
"""
if args is None:
return None
- arg_list = [arg.strip() for arg in args.split(',')]
+ arg_list = [arg.strip() for arg in args.split(",")]
if url_name in arg_list:
return True
else:
@@ -158,11 +161,20 @@ def match_two_values(val1, val2):
@register.simple_tag
-def value_for_field_name(model, field_name):
+def value_for_field_name(model, field_name, in_parentheses):
"""
Returns the field value for a given field name in a model
+ If in_parentheses is true, return the value in parentheses.
"""
- return getattr(model, field_name, None)
+ return_val = getattr(model, field_name, None)
+ if in_parentheses:
+ return_string = f"({return_val})"
+ else:
+ return_string = f"{return_val}"
+
+ if return_val is not None:
+ return return_string
+ return ""
@register.filter
@@ -170,18 +182,22 @@ def record_complete(model):
# helper largely for medicines table to report if complete or not
minimum_requirement_met = False
- if hasattr(model, 'medicine_entity'):
+ if hasattr(model, "medicine_entity"):
if model.medicine_entity is not None:
minimum_requirement_met = (
- model.antiepilepsy_medicine_start_date is not None and
- model.antiepilepsy_medicine_risk_discussed is not None and
- model.medicine_entity.medicine_name is not None
+ model.antiepilepsy_medicine_start_date is not None
+ and model.antiepilepsy_medicine_risk_discussed is not None
+ and model.medicine_entity.medicine_name is not None
)
- if model.management.registration.case.sex == 2 and model.medicine_entity.medicine_name == 'Sodium valproate':
+ if (
+ model.management.registration.case.sex == 2
+ and model.medicine_entity.medicine_name == "Sodium valproate"
+ ):
return minimum_requirement_met and (
- model.is_a_pregnancy_prevention_programme_needed is not None and
- model.has_a_valproate_annual_risk_acknowledgement_form_been_completed is not None and
- model.is_a_pregnancy_prevention_programme_in_place is not None
+ model.is_a_pregnancy_prevention_programme_needed is not None
+ and model.has_a_valproate_annual_risk_acknowledgement_form_been_completed
+ is not None
+ and model.is_a_pregnancy_prevention_programme_in_place is not None
)
return minimum_requirement_met
@@ -190,33 +206,33 @@ def record_complete(model):
@register.filter
def to_class_name(value):
if value.__class__.__name__ == "Registration":
- return 'Verification/Registration'
+ return "Verification/Registration"
elif value.__class__.__name__ == "FirstPaediatricAssessment":
- return 'First Paediatric Assessment'
+ return "First Paediatric Assessment"
elif value.__class__.__name__ == "EpilepsyContext":
- return 'Epilepsy Context'
+ return "Epilepsy Context"
elif value.__class__.__name__ == "MultiaxialDiagnosis":
- return 'Multiaxial Diagnosis'
+ return "Multiaxial Diagnosis"
elif value.__class__.__name__ == "Assessment":
- return 'Milestones'
+ return "Milestones"
elif value.__class__.__name__ == "Investigations":
- return 'Investigations'
+ return "Investigations"
elif value.__class__.__name__ == "Management":
- return 'Management'
+ return "Management"
elif value.__class__.__name__ == "Site":
- return 'Site'
+ return "Site"
elif value.__class__.__name__ == "Episode":
- return 'Episode'
+ return "Episode"
elif value.__class__.__name__ == "Syndrome":
- return 'Syndrome'
+ return "Syndrome"
elif value.__class__.__name__ == "Comorbidity":
- return 'Comorbidity'
+ return "Comorbidity"
elif value.__class__.__name__ == "Epilepsy12User":
- return 'Epilepsy12 User'
+ return "Epilepsy12 User"
elif value.__class__.__name__ == "Antiepilepsy Medicine":
- return 'Antiepilepsy Medicine'
+ return "Antiepilepsy Medicine"
else:
- return 'Error'
+ return "Error"
@register.filter
@@ -244,22 +260,22 @@ def return_case(value):
elif value.__class__.__name__ == "Comorbidity":
return value.multiaxial_diagnosis.registration.case
elif value.__class__.__name__ == "Epilepsy12User":
- return 'Epilepsy12 User'
+ return "Epilepsy12 User"
elif value.__class__.__name__ == "Antiepilepsy Medicine":
return value.management.registration.case
else:
- return 'Error'
+ return "Error"
-@register.filter('has_group')
+@register.filter("has_group")
def has_group(user, group_names_string):
# thanks to Lucas Simon for this efficiency
# https://stackoverflow.com/questions/1052531/get-user-group-in-a-template
"""
Check if user has permission
"""
- result = [x.strip() for x in group_names_string.split(',')]
- groups = user.groups.all().values_list('name', flat=True)
+ result = [x.strip() for x in group_names_string.split(",")]
+ groups = user.groups.all().values_list("name", flat=True)
match = False
for group in groups:
if group in result:
@@ -280,10 +296,10 @@ def none_percentage(field):
if field is None:
return "No data"
else:
- return f'{field} %'
+ return f"{field} %"
-@register.filter(name='icon_for_score')
+@register.filter(name="icon_for_score")
def icon_for_score(score):
if score is None:
return
@@ -296,7 +312,8 @@ def icon_for_score(score):
data-position="top right"
_="init js $('.rcpch_light_blue.exclamation.triangle.icon').popup(); end"
>
- """)
+ """
+ )
elif score > 1:
return mark_safe(
"""
- """)
+ """
+ )
else:
return mark_safe(
"""
- """)
+ """
+ )
diff --git a/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine_list.html b/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine_list.html
index cd777ee7..bec9e5f2 100644
--- a/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine_list.html
+++ b/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine_list.html
@@ -23,9 +23,9 @@
{% if medicine.antiepilepsy_medicine_start_date %}
{{ medicine.antiepilepsy_medicine_start_date }}
{% else %}
-
+
None
{% endif %}
diff --git a/templates/epilepsy12/partials/page_elements/select_model.html b/templates/epilepsy12/partials/page_elements/select_model.html
index 068ce18f..27523d7a 100644
--- a/templates/epilepsy12/partials/page_elements/select_model.html
+++ b/templates/epilepsy12/partials/page_elements/select_model.html
@@ -62,7 +62,7 @@
{{hx_default_text}}
From 6a16c8bb5882fb3b505c7fc6c490ca5cb1a7d4ec Mon Sep 17 00:00:00 2001
From: Simon Chapman
Date: Sat, 6 May 2023 13:17:34 +0100
Subject: [PATCH 02/10] fix kpis table region names if none
---
templates/epilepsy12/partials/kpis/kpis.html | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/templates/epilepsy12/partials/kpis/kpis.html b/templates/epilepsy12/partials/kpis/kpis.html
index 200fc702..a9045441 100644
--- a/templates/epilepsy12/partials/kpis/kpis.html
+++ b/templates/epilepsy12/partials/kpis/kpis.html
@@ -37,7 +37,7 @@ Clinical Team
class="info circle icon"
id='totals_organisation'
data-title='Epilepsy12 totals'
- data-content="Number of children registered in this organisation."
+ data-content="Number of children registered in this organisation" {% if organisation.OrganisationName is not None %} + "{({{organisation.OrganisationName}})" {% endif %}
data-position='top right'
_="init js $('#totals_organisation').popup(); end"
>({{organisation_kpis.total_number_of_cases}})
@@ -49,51 +49,51 @@ Clinical Team
class="info circle icon"
id='totals_trust'
data-title='Epilepsy12 totals'
- data-content="Number of children registered in this Trust."
+ data-content="Number of children registered in this Trust" {% if organisation.ParentOrganisation_OrganisationName is not None %} + "{({{organisation.ParentOrganisation_OrganisationName}})" {% endif %}
data-position='top right'
_="init js $('#totals_trust').popup(); end"
>({{trust_kpis.total_number_of_cases}})
- Integrated Care Board ({{organisation.ICBName}})
+ Integrated Care Board
({{icb_kpis.total_number_of_cases}})
|
- NHS Region ({{organisation.NHSEnglandRegion}})
+ NHS Region
({{nhs_kpis.total_number_of_cases}})
|
- OPEN UK Region ({{organisation.OPENUKNetworkName}})
+ OPEN UK Region
({{open_uk_kpis.total_number_of_cases}})
|
- Country ({{organisation.ons_region.ons_country.Country_ONS_Name}})
+ Country
({{country_kpis.total_number_of_cases}})
From 08890fe5ddc3e37d8714818abfd481d5ea2534c3 Mon Sep 17 00:00:00 2001
From: Simon Chapman
Date: Sat, 6 May 2023 14:11:54 +0100
Subject: [PATCH 03/10] add remove discontinue date button add to urls and
views add padding to button
---
epilepsy12/urls.py | 5 ++
epilepsy12/view_folder/management_views.py | 45 ++++++++++++-
static/styles/style.css | 4 ++
.../antiepilepsy_medicine.html | 63 ++++++++++++++-----
4 files changed, 100 insertions(+), 17 deletions(-)
diff --git a/epilepsy12/urls.py b/epilepsy12/urls.py
index 0eeec847..23814e4f 100644
--- a/epilepsy12/urls.py
+++ b/epilepsy12/urls.py
@@ -822,6 +822,11 @@
views.antiepilepsy_medicine_add_stop_date,
name="antiepilepsy_medicine_add_stop_date",
),
+ path(
+ "antiepilepsy_medicine//antiepilepsy_medicine_remove_stop_date",
+ views.antiepilepsy_medicine_remove_stop_date,
+ name="antiepilepsy_medicine_remove_stop_date",
+ ),
path(
"antiepilepsy_medicine//antiepilepsy_medicine_stop_date",
views.antiepilepsy_medicine_stop_date,
diff --git a/epilepsy12/view_folder/management_views.py b/epilepsy12/view_folder/management_views.py
index 98fdec9c..933e42f4 100644
--- a/epilepsy12/view_folder/management_views.py
+++ b/epilepsy12/view_folder/management_views.py
@@ -251,9 +251,6 @@ def edit_antiepilepsy_medicine(request, antiepilepsy_medicine_id):
is_rescue=antiepilepsy_medicine.is_rescue_medicine
).order_by("medicine_name")
- for medicine in MedicineEntity.objects.all():
- print(medicine)
-
if antiepilepsy_medicine.antiepilepsy_medicine_stop_date:
show_end_date = True
else:
@@ -516,6 +513,48 @@ def antiepilepsy_medicine_add_stop_date(request, antiepilepsy_medicine_id):
return response
+@login_required
+@user_may_view_this_child()
+@permission_required("epilepsy12.change_antiepilepsymedicine", raise_exception=True)
+def antiepilepsy_medicine_remove_stop_date(request, antiepilepsy_medicine_id):
+ """
+ POST callback from antiepilepsy_medicine.html partial to toggle closed antiepilepsy_medicine_end_date
+ """
+
+ error_message = ""
+
+ antiepilepsy_medicine = AntiEpilepsyMedicine.objects.get(
+ pk=antiepilepsy_medicine_id
+ )
+
+ # set antiepilepsy_medicine_stop_date to None and save
+ antiepilepsy_medicine.antiepilepsy_medicine_stop_date = None
+ antiepilepsy_medicine.save()
+
+ choices = MedicineEntity.objects.filter(
+ is_rescue=antiepilepsy_medicine.is_rescue_medicine
+ ).order_by("medicine_name")
+
+ context = {
+ "choices": choices,
+ "antiepilepsy_medicine": antiepilepsy_medicine,
+ "is_rescue_medicine": antiepilepsy_medicine.is_rescue_medicine,
+ "show_end_date": False,
+ }
+
+ template_name = "epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine.html"
+
+ response = recalculate_form_generate_response(
+ model_instance=antiepilepsy_medicine.management,
+ request=request,
+ context=context,
+ template=template_name,
+ error_message=error_message,
+ )
+
+ return response
+
+
@login_required
@user_may_view_this_child()
@permission_required("epilepsy12.change_antiepilepsymedicine", raise_exception=True)
diff --git a/static/styles/style.css b/static/styles/style.css
index d9e25321..e2ade3a3 100644
--- a/static/styles/style.css
+++ b/static/styles/style.css
@@ -1906,4 +1906,8 @@ div.sixteen.wide.column.search_field_wrapper > .ui.rcpch.icon.input {
.case_create_buttons_wrapper {
display: flex;
+}
+
+.padded.field {
+ padding-top: 33px;
}
\ No newline at end of file
diff --git a/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine.html b/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine.html
index 46094b73..5707aed8 100644
--- a/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine.html
+++ b/templates/epilepsy12/partials/management/antiepilepsy_medicines/antiepilepsy_medicine.html
@@ -10,9 +10,9 @@ |