{% extends base_layout %} {% load i18n %} {% load static %} {% load math %} {% block title %}Complaint #{{ complaint.id|slice:":8" }} - PX360{% endblock %} {% block extra_css %} {% endblock %} {% block content %}
{% if source_user %} {{ _("Back to My Complaints")}} {% else %} {% trans "Back to Complaints" %} {% endif %}

{{ complaint.title }}

{% if complaint.complaint_type == 'appreciation' %} {% trans "Appreciation" %} {% else %} {% trans "Complaint" %} {% endif %} {{ complaint.get_status_display }} {{ complaint.get_severity_display }}

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

{% trans "Hospital" %}: {{ complaint.hospital.name_en }} {% if complaint.department %} | {% trans "Department" %}: {{ complaint.department.name_en }} {% endif %}

{% trans "SLA Deadline" %}

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

{% if complaint.is_overdue %}
{% trans "OVERDUE" %}
{% else %} {{ complaint.due_at|timeuntil }} {% trans "remaining" %} {% endif %}
{% trans "Complaint Details" %}
{% trans "Category" %}
{{ complaint.get_category_display }} {% if complaint.subcategory %} / {{ complaint.subcategory }} {% endif %}
{% trans "Source" %}
{{ complaint.get_source_display }}
{% trans "Priority" %}
{{ complaint.get_priority_display }}
{% trans "Encounter ID" %}
{% if complaint.encounter_id %} {{ complaint.encounter_id }} {% else %} {% trans "N/A" %} {% endif %}
{% if complaint.department %}
{% trans "Department" %}
{{ complaint.department.name_en }} {% if complaint.department.name_ar %} ({{ complaint.department.name_ar }}) {% endif %}
{% if complaint.metadata.ai_analysis.old_department %} {% trans "AI Mapped" %} {% endif %}
{% endif %} {% if complaint.staff %}
{% trans "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 %}
{% trans "AI Matched" %}
{% if complaint.metadata.ai_analysis.extracted_staff_name %} {% trans "Extracted from complaint" %}: "{{ complaint.metadata.ai_analysis.extracted_staff_name }}" {% if complaint.metadata.ai_analysis.staff_confidence %} ({% trans "confidence" %}: {{ complaint.metadata.ai_analysis.staff_confidence|floatformat:0 }}%) {% endif %} {% endif %}
{% endif %} {% if complaint.metadata.ai_analysis.staff_matches %}
{% trans "AI Staff Matches" %}
{% if complaint.metadata.ai_analysis.needs_staff_review %} {% trans "Needs Review" %} {% endif %}
{% if complaint.metadata.ai_analysis.extracted_staff_names %}
{% trans "Extracted from Complaint" %}
{% for name in complaint.metadata.ai_analysis.extracted_staff_names %} {{ name }} {% endfor %}
{% if complaint.metadata.ai_analysis.primary_staff_name %} {% trans "Primary" %}: "{{ complaint.metadata.ai_analysis.primary_staff_name }}" {% endif %}
{% endif %}
{% for staff_match in complaint.metadata.ai_analysis.staff_matches|slice:":5" %}
{{ staff_match.name_en }} {% if staff_match.name_ar %} ({{ staff_match.name_ar }}) {% endif %} {% if complaint.staff and staff_match.id == complaint.staff.id|stringformat:"s" %} {% trans "Assigned" %} {% 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 }}% {% trans "confidence" %}
{% if user.is_px_admin and not complaint.staff %} {% elif user.is_px_admin and complaint.staff and staff_match.id != complaint.staff.id|stringformat:"s" %} {% endif %}
{% endfor %}
{% if user.is_px_admin %}
{% endif %}
{% endif %}
{% trans "Description" %}

{{ complaint.description|linebreaks }}

{% if complaint.short_description_ar or complaint.suggested_action_ar %}
{% trans "AI Analysis" %}
{% trans "AI Generated" %}
{% if complaint.emotion %}
{% trans "Emotion Analysis" %}
{{ complaint.get_emotion_display }}
{% trans "Confidence" %}: {{ complaint.emotion_confidence|mul:100|floatformat:0 }}%
{% trans "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 %}
{% trans "Summary" %}
{{ complaint.short_description_ar }}
{% endif %} {% if complaint.suggested_action_ar %}
{% trans "Suggested Action" %}
{{ complaint.suggested_action_ar }}
{% endif %}
{% endif %} {% if complaint.resolution %}
{% trans "Resolution" %}

{{ complaint.resolution|linebreaks }}

{% trans "Resolved by" %} {{ complaint.resolved_by.get_full_name }} {% trans "on" %} {{ complaint.resolved_at|date:"M d, Y H:i" }}
{% endif %}
{% trans "Created" %}
{{ complaint.created_at|date:"M d, Y H:i" }}
{% trans "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 %}

{% trans "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 %}

{% trans "No attachments" %}

{% endif %}
{% trans "Staff Explanations" %} {{ explanations|length }}
{% if explanations %} {% for exp in explanations %}
{% if exp.is_used %} {% trans "Explanation from Staff" %} {% else %} {% trans "Pending Explanation" %} {% endif %}
{% if exp.is_used %} {% trans "Submitted" %} {% else %} {% trans "Pending" %} {% endif %}
{% if exp.staff %}

{% trans "Staff Member:" %} {{ exp.staff.get_full_name }} {% if exp.staff.job_title %} ({{ exp.staff.job_title }}) {% endif %}

{% endif %} {% if exp.is_used and exp.explanation %}

{{ exp.explanation|linebreaks }}

{% else %}

{% trans "No explanation submitted yet." %}

{% endif %}
{% if exp.responded_at %} {% trans "Responded:" %} {{ exp.responded_at|date:"M d, Y H:i" }} {% else %} {% trans "Requested:" %} {{ exp.email_sent_at|date:"M d, Y H:i" }} {% endif %} {% if exp.attachments.all %} | {{ exp.attachments.all.count }} {% trans "attachment(s)" %} {% endif %} {% if exp.attachments.all %}
{% trans "Attachments:" %}
{% for attachment in exp.attachments.all %} {{ attachment.filename }} {% endfor %}
{% endif %} {% if exp.request_message %}
{% trans "Request Message:" %}
{{ exp.request_message }}
{% endif %}
{% if exp.token and not exp.is_used %}
{% trans "Explanation ID:" %} {{ exp.id }} | {% trans "Token:" %} {{ exp.token|slice:":8" }}...
{% endif %}
{% endfor %} {% else %}

{% trans "No explanation has been submitted yet." %}

{% if can_edit %}
{% trans "Request Explanation" %}

{% trans "Send a link to the assigned staff member requesting their explanation about this complaint." %}

{% if complaint.staff %}
{% trans "Will be sent to:" %} {{ complaint.staff.get_full_name }} {% if complaint.staff.user %}
{{ complaint.staff.user.email }} {% elif complaint.staff.email %}
{{ complaint.staff.email }} {% else %}
{% trans "No email configured" %} {% endif %}
{% else %}
{% trans "Please assign a staff member to this complaint before requesting an explanation." %}
{% endif %}
{% endif %}
{% 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 }}
{% trans "View" %}
{% endfor %} {% else %}

{% trans "No PX actions created yet" %}

{% endif %}
{% trans "PDF View" %}
{% trans "Download PDF" %}
{% trans "This will generate a professionally formatted PDF with all complaint details, including AI analysis, staff assignment, and resolution information." %}

{% trans "PDF Contents" %}
  • {% trans "Header:" %} Complaint title, ID, status, severity, patient info
  • {% trans "Basic Information:" %} Category, source, priority, encounter ID, dates
  • {% trans "Description:" %} Full complaint details
  • {% trans "Staff Assignment:" %} Assigned staff member (if any)
  • {% trans "AI Analysis:" %} Emotion analysis, summary, suggested action (if available)
  • {% trans "Resolution:" %} Resolution details (if resolved)
{% trans "Note" %}

{% trans "PDF generation requires WeasyPrint to be installed. If you see an error message, please contact your system administrator." %}

{% if user.is_px_admin %}
{% trans "Staff Assignment" %}
{% trans "Staff member that complaint is about" %} {% if complaint.staff %}
{{ complaint.staff.get_full_name }} {% if complaint.staff.job_title %}
{{ complaint.staff.job_title }} {% endif %}
{% else %} {% if complaint.metadata.ai_analysis.needs_staff_review %} {% trans "This complaint needs staff review" %} {% endif %} {% endif %}
{% endif %} {% if can_edit %}
{% trans "Quick Actions" %}
{% csrf_token %}
{% if complaint.complaint_type == 'appreciation' and not complaint.metadata.appreciation_id %}
{% elif complaint.metadata.appreciation_id %}
{% trans "Converted to Appreciation" %} {% trans "View Appreciation" %}
{% endif %}
{% endif %}
{% trans "Add Note" %}
{% csrf_token %}
{% trans "Assignment Info" %}
{% if user.is_px_admin %} {% endif %}
{% trans "Assigned To" %}
{% if complaint.assigned_to %}
{{ complaint.assigned_to.get_full_name }}
{% if complaint.assigned_to.is_px_admin %}{% trans "PX Admin" %}{% endif %} {% if complaint.assigned_to.is_hospital_admin %}{% trans "Hospital Admin" %}{% endif %}
Assigned {{ complaint.assigned_at|date:"M d, Y H:i" }}
{% else %}

{% trans "No admin assigned to this complaint" %}

{% endif %}
{% if complaint.resolved_by %}
{% trans "Resolved By" %}
{{ complaint.resolved_by.get_full_name }}
{{ complaint.resolved_at|date:"M d, Y H:i" }}
{% endif %} {% if complaint.closed_by %}
{% trans "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" %}

{% trans "Status" %}: {{ complaint.resolution_survey.get_status_display }}

{% if complaint.resolution_survey.score %}

{% trans "Score" %}: {{ complaint.resolution_survey.score }}/100

{% endif %} {% trans "View Survey" %}
{% endif %}
{% endblock %}