{% extends "layouts/base.html" %} {% load i18n %} {% load static %} {% load math %} {% block title %}Complaint #{{ complaint.id|slice:":8" }} - PX360{% endblock %} {% block extra_css %} {% endblock %} {% block content %}
{{ _("Back to Complaints")}}

{{ complaint.title }}

{{ complaint.get_status_display }} {{ complaint.get_severity_display }}

{{ _("ID") }}: {{ complaint.id|slice:":8" }} | {{ _("Patient") }}: {{ complaint.patient.get_full_name }} ({{ _("MRN") }}: {{ complaint.patient.mrn }})

{{ _("Hospital") }}: {{ complaint.hospital.name_en }} {% if complaint.department %} | {{ _("Department") }}: {{ complaint.department.name_en }} {% endif %}

{{ _("SLA Deadline")}}

{{ complaint.due_at|date:"M d, Y H:i" }}

{% if complaint.is_overdue %}
{{ _("OVERDUE") }}
{% else %} {{ complaint.due_at|timeuntil }} {{ _("remaining") }} {% endif %}
{% trans "Complaint Details" %}
{{ _("Category") }}
{{ complaint.get_category_display }} {% if complaint.subcategory %} / {{ complaint.subcategory }} {% endif %}
{{ _("Source") }}
{{ complaint.get_source_display }}
{{ _("Priority") }}
{{ complaint.get_priority_display }}
{{ _("Encounter ID")}}
{% if complaint.encounter_id %} {{ complaint.encounter_id }} {% else %} {{ _("N/A")}} {% endif %}
{% if complaint.department %}
{{ _("Department") }}
{{ complaint.department.name_en }} {% if complaint.department.name_ar %} ({{ complaint.department.name_ar }}) {% endif %}
{% if complaint.metadata.ai_analysis.old_department %} {{ _("AI Mapped")}} {% endif %}
{% endif %} {% if complaint.staff %}
{{ _("Staff Member") }}
{{ complaint.staff.first_name }} {{ complaint.staff.last_name }} {% if complaint.staff.first_name_ar or complaint.staff.last_name_ar %} ({{ complaint.staff.first_name_ar }} {{ complaint.staff.last_name_ar }}) {% endif %} {% if complaint.staff.job_title %}
{{ complaint.staff.job_title }}
{% endif %}
{{ _("AI Matched")}}
{% if complaint.metadata.ai_analysis.extracted_staff_name %} {{ _("Extracted from complaint")}}: "{{ complaint.metadata.ai_analysis.extracted_staff_name }}" {% if complaint.metadata.ai_analysis.staff_confidence %} ({{ _("confidence") }}: {{ complaint.metadata.ai_analysis.staff_confidence|floatformat:0 }}%) {% endif %} {% endif %}
{% endif %} {% if complaint.metadata.ai_analysis.staff_matches and user.is_px_admin %}
{{ _("Staff Suggestions")}} {% if complaint.metadata.ai_analysis.needs_staff_review %} {{ _("Needs Review")}} {% endif %}
{% if complaint.metadata.ai_analysis.extracted_staff_name %}

{{ _("AI extracted name")}}: "{{ complaint.metadata.ai_analysis.extracted_staff_name }}" ({% if complaint.metadata.ai_analysis.staff_match_count %}{{ complaint.metadata.ai_analysis.staff_match_count }}{{ _("potential match")}}{{ complaint.metadata.ai_analysis.staff_match_count|pluralize }}{% else %}{{ _("No matches found")}}{% endif %})

{% endif %}
{% for staff_match in complaint.metadata.ai_analysis.staff_matches %}
{{ staff_match.name_en }} {% if staff_match.name_ar %} ({{ staff_match.name_ar }}) {% endif %}
{% if staff_match.job_title %} {{ staff_match.job_title }} {% endif %} {% if staff_match.specialization %} • {{ staff_match.specialization }} {% endif %} {% if staff_match.department %} • {{ staff_match.department }} {% endif %}
{{ staff_match.confidence|mul:100|floatformat:0 }}% {{ _("confidence") }} {% if complaint.staff and staff_match.id == complaint.staff.id|stringformat:"s" %}
{{ _("Currently assigned")}}
{% elif not complaint.staff %} {% endif %}
{% endfor %}
{% endif %}
{{ _("Description") }}

{{ complaint.description|linebreaks }}

{% if complaint.short_description_ar or complaint.suggested_action_ar %}
{{ _("AI Analysis")}}
{{ _("AI Generated")}}
{% if complaint.emotion %}
{{ _("Emotion Analysis")}}
{{ complaint.get_emotion_display }}
{{ _("Confidence") }}: {{ complaint.emotion_confidence|mul:100|floatformat:0 }}%
{{ _("Intensity") }} {{ complaint.emotion_intensity|floatformat:2 }} / 1.0
{% if complaint.emotion == 'anger' %}
{% elif complaint.emotion == 'sadness' %}
{% elif complaint.emotion == 'confusion' %}
{% elif complaint.emotion == 'fear' %}
{% else %}
{% endif %}
{% endif %} {% if complaint.short_description_ar %}
{{ _("Summary") }}
{{ complaint.short_description_ar }}
{% endif %} {% if complaint.suggested_action_ar %}
{{ _("Suggested Action")}}
{{ complaint.suggested_action_ar }}
{% endif %}
{% endif %} {% if complaint.resolution %}
{{ _("Resolution") }}

{{ complaint.resolution|linebreaks }}

{{ _("Resolved by")}} {{ complaint.resolved_by.get_full_name }} {{ _("on") }} {{ complaint.resolved_at|date:"M d, Y H:i" }}
{% endif %}
{{ _("Created") }}
{{ complaint.created_at|date:"M d, Y H:i" }}
{{ _("Last Updated")}}
{{ complaint.updated_at|date:"M d, Y H:i" }}
{% trans "Activity Timeline" %}
{% if timeline %}
{% for update in timeline %}
{{ update.get_update_type_display }} {% if update.created_by %} by {{ update.created_by.get_full_name }} {% endif %}
{{ update.created_at|date:"M d, Y H:i" }}

{{ update.message }}

{% if update.old_status and update.new_status %}
{{ update.old_status }} {{ update.new_status }}
{% endif %}
{% endfor %}
{% else %}

{{ _("No timeline entries yet")}}

{% endif %}
{% trans "Attachments" %}
{% if attachments %}
{% for attachment in attachments %}
{{ attachment.filename }}
Uploaded by {{ attachment.uploaded_by.get_full_name }} on {{ attachment.created_at|date:"M d, Y H:i" }} ({{ attachment.file_size|filesizeformat }}) {% if attachment.description %}
{{ attachment.description }} {% endif %}
{% endfor %}
{% else %}

{{ _("No attachments")}}

{% endif %}
{% trans "Related PX Actions" %}
{% if px_actions %} {% for action in px_actions %}
{{ action.title }}

{{ action.description|truncatewords:20 }}

{{ action.get_status_display }} {{ action.get_priority_display }}
{{ _("View") }}
{% endfor %} {% else %}

{{ _("No PX actions created yet")}}

{% endif %}
{% if can_edit %}
{% trans "Quick Actions" %}
{% if user.is_px_admin %}
{% if complaint.metadata.ai_analysis.needs_staff_review %} This complaint needs staff review {% endif %}

{% endif %} {% if can_edit and hospital_departments %}
{% csrf_token %}
{% endif %}
{% csrf_token %}
{% csrf_token %}
{% endif %}
{% trans "Add Note" %}
{% csrf_token %}
{% trans "Assignment Info" %}
{{ _("Assigned To")}}
{% if complaint.assigned_to %} {{ complaint.assigned_to.get_full_name }}
Assigned {{ complaint.assigned_at|date:"M d, Y H:i" }} {% else %} {{ _("Unassigned") }} {% endif %}
{% if complaint.resolved_by %}
{{ _("Resolved By")}}
{{ complaint.resolved_by.get_full_name }}
{{ complaint.resolved_at|date:"M d, Y H:i" }}
{% endif %} {% if complaint.closed_by %}
{{ _("Closed By")}}
{{ complaint.closed_by.get_full_name }}
{{ complaint.closed_at|date:"M d, Y H:i" }}
{% endif %}
{% if complaint.resolution_survey %}
{% trans "Resolution Survey" %}

{{ _("Status") }}: {{ complaint.resolution_survey.get_status_display }}

{% if complaint.resolution_survey.score %}

{{ _("Score") }}: {{ complaint.resolution_survey.score }}/100

{% endif %} {{ _("View Survey")}}
{% endif %}
{% endblock %}