{% load i18n %} Complaint Report - {{ complaint.reference_number }}

{{ complaint.title }}

Ref: {{ complaint.reference_number }}
Status: {{ complaint.get_status_display }}
Severity: {{ complaint.get_severity_display }}
Priority: {{ complaint.get_priority_display }}

👤 Patient Information

Patient Name
{% if complaint.patient %} {{ complaint.patient.get_full_name }} {% else %} {{ complaint.contact_name|default:"Anonymous" }} {% endif %}
MRN / National ID
{% if complaint.patient %} {{ complaint.patient.mrn }} {% else %} {{ complaint.national_id|default:"N/A" }} {% endif %}
Hospital
{{ complaint.hospital.name }}
Department
{{ complaint.department.name|default:"Not Assigned" }}
Location
{% if complaint.location %}{{ complaint.location.name }}{% endif %} {% if complaint.main_section %} / {{ complaint.main_section.name }}{% endif %} {% if complaint.subsection %} / {{ complaint.subsection.name }}{% endif %}
Incident Date
{{ complaint.incident_date|date:"M d, Y"|default:"Not Specified" }}

📝 Complaint Details

Category
{{ complaint.get_category_display|default:"Not Categorized" }}
Source
{{ complaint.get_source_display }}
Created Date
{{ complaint.created_at|date:"M d, Y H:i" }}
SLA Deadline
{{ complaint.due_at|date:"M d, Y H:i" }}
Description
{{ complaint.description|linebreaks }}
{% if complaint.expected_result %}
Patient Expected Result
{{ complaint.expected_result|linebreaks }}
{% endif %}
{% if complaint.staff %}

👨‍⚕️ Staff Assignment

{{ complaint.staff.first_name|first|upper }}
{{ complaint.staff.get_full_name }}
{% if complaint.staff.job_title %}{{ complaint.staff.job_title }}{% endif %} {% if complaint.staff.department %} | {{ complaint.staff.department.name }}{% endif %}
{% if complaint.staff.report_to %}
Reports to: {{ complaint.staff.report_to.get_full_name }}
{% endif %}
{% endif %} {% if explanations %}

💬 Staff Explanations

{% for exp in explanations %}
{{ exp.staff.get_full_name|default:"Unknown Staff" }} {% if exp.metadata.is_escalation %} (Manager - Escalated) {% endif %}
{% if exp.submitted_via == 'email_link' %}Via Email Link{% else %}Direct Entry{% endif %} | Submitted: {{ exp.responded_at|date:"M d, Y H:i" }}
{% if exp.is_used %} {% if exp.acceptance_status == 'acceptable' %} ✓ Acceptable {% elif exp.acceptance_status == 'not_acceptable' %} ✗ Not Acceptable {% else %} ⏳ Pending Review {% endif %} {% else %} ⏳ Awaiting Response {% endif %}
{% if exp.is_used and exp.explanation %}
{{ exp.explanation|linebreaks }}
{% if exp.acceptance_notes %}
Review Notes: {{ exp.acceptance_notes }}
{% endif %}
{% if exp.accepted_by %} Reviewed by {{ exp.accepted_by.get_full_name }} on {{ exp.accepted_at|date:"M d, Y" }} {% endif %} {% if exp.attachments.count > 0 %} | {{ exp.attachments.count }} attachment(s) {% endif %}
{% else %}
Explanation not yet submitted. Request sent on {{ exp.email_sent_at|date:"M d, Y" }}
{% endif %}
{% endfor %}
{% endif %} {% if complaint.short_description_en or complaint.suggested_action_en or complaint.emotion %}

🤖 AI Analysis

{% if complaint.emotion %}
Emotion Analysis
{{ complaint.get_emotion_display }} Confidence: {{ complaint.emotion_confidence|floatformat:0 }}%
Intensity
{{ complaint.emotion_intensity|floatformat:2 }}
{% endif %} {% if complaint.short_description_en %}
AI Summary
{{ complaint.short_description_en }}
{% if complaint.short_description_ar %}
{{ complaint.short_description_ar }}
{% endif %}
{% endif %} {% if complaint.suggested_action_en %}
💡 Suggested Action
{{ complaint.suggested_action_en }}
{% if complaint.suggested_action_ar %}
{{ complaint.suggested_action_ar }}
{% endif %}
{% endif %} {% if complaint.reasoning_en %}
AI Reasoning
{{ complaint.reasoning_en }}
{% endif %}
{% endif %} {% if px_actions %}

Related PX Actions

{% for action in px_actions %}
{{ action.title }}
Status: {{ action.get_status_display }} | Priority: {{ action.get_priority_display }} | Created: {{ action.created_at|date:"M d, Y" }}
{% endfor %}
{% endif %} {% if complaint.resolution %}

Resolution

Complaint Resolved
{{ complaint.resolution|linebreaks }}
{% if complaint.resolution_category %}
Category: {{ complaint.get_resolution_category_display }}
{% endif %}
Resolved by: {{ complaint.resolved_by.get_full_name|default:"N/A" }}
Resolved on: {{ complaint.resolved_at|date:"F d, Y at H:i"|default:"N/A" }}
{% endif %} {% if timeline %}

📋 Recent Activity

{% for update in timeline %}
{{ update.created_at|date:"M d, Y H:i" }}
{{ update.message }}
{% if update.created_by %}
by {{ update.created_by.get_full_name }}
{% endif %}
{% endfor %}
{% endif %}