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

{{ complaint.title }}

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

👤 {% trans "Patient Information" %}

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

📝 {% trans "Complaint Details" %}

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

👨‍⚕️ {% trans "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 %}
{% trans "Reports to:" %} {{ complaint.staff.report_to.get_full_name }}
{% endif %}
{% endif %} {% if explanations %}

💬 {% trans "Staff Explanations" %}

{% for exp in explanations %}
{% if exp.staff.get_full_name %}{{ exp.staff.get_full_name }}{% else %}{% trans "Unknown Staff" %}{% endif %} {% if exp.metadata.is_escalation %} ({% trans "Manager - Escalated" %}) {% endif %}
{% if exp.submitted_via == 'email_link' %}{% trans "Via Email Link" %}{% else %}{% trans "Direct Entry" %}{% endif %} | {% trans "Submitted:" %} {{ exp.responded_at|date:"M d, Y H:i" }}
{% if exp.is_used %} {% if exp.acceptance_status == 'acceptable' %} ✓ {% trans "Acceptable" %} {% elif exp.acceptance_status == 'not_acceptable' %} ✗ {% trans "Not Acceptable" %} {% else %} ⏳ {% trans "Pending Review" %} {% endif %} {% else %} ⏳ {% trans "Awaiting Response" %} {% endif %}
{% if exp.is_used and exp.explanation %}
{{ exp.explanation|linebreaks }}
{% if exp.acceptance_notes %}
{% trans "Review Notes:" %} {{ exp.acceptance_notes }}
{% endif %}
{% if exp.accepted_by %} {% trans "Reviewed by" %} {{ exp.accepted_by.get_full_name }} {% trans "on" %} {{ exp.accepted_at|date:"M d, Y" }} {% endif %} {% if exp.attachments.count > 0 %} | {% blocktrans count counter=exp.attachments.count %}{{ counter }} attachment{% plural %}{{ counter }} attachments{% endblocktrans %} {% endif %}
{% else %}
{% trans "Explanation not yet submitted." %} {% trans "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 %}

🤖 {% trans "AI Analysis" %}

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

{% trans "Related PX Actions" %}

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

{% trans "Resolution" %}

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

📋 {% trans "Recent Activity" %}

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