Marwan Alwali 263292f6be update
2025-11-04 00:50:06 +03:00

221 lines
14 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Specimens - {{ block.super }}{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title mb-0">
<i class="fas fa-flask me-2"></i>Specimen Management
</h4>
</div>
<div class="card-body">
<!-- Filters -->
<form method="get" class="mb-3">
<div class="row">
<div class="col-md-2">
<select name="status" class="form-select">
<option value="">All Status</option>
<option value="COLLECTED" {% if status == 'COLLECTED' %}selected{% endif %}>Collected</option>
<option value="RECEIVED" {% if status == 'RECEIVED' %}selected{% endif %}>Received</option>
<option value="PROCESSING" {% if status == 'PROCESSING' %}selected{% endif %}>Processing</option>
<option value="COMPLETED" {% if status == 'COMPLETED' %}selected{% endif %}>Completed</option>
<option value="REJECTED" {% if status == 'REJECTED' %}selected{% endif %}>Rejected</option>
</select>
</div>
<div class="col-md-2">
<select name="quality" class="form-select">
<option value="">All Quality</option>
<option value="ACCEPTABLE" {% if quality == 'ACCEPTABLE' %}selected{% endif %}>Acceptable</option>
<option value="HEMOLYZED" {% if quality == 'HEMOLYZED' %}selected{% endif %}>Hemolyzed</option>
<option value="CLOTTED" {% if quality == 'CLOTTED' %}selected{% endif %}>Clotted</option>
<option value="INSUFFICIENT" {% if quality == 'INSUFFICIENT' %}selected{% endif %}>Insufficient</option>
<option value="CONTAMINATED" {% if quality == 'CONTAMINATED' %}selected{% endif %}>Contaminated</option>
</select>
</div>
<div class="col-md-2">
<select name="specimen_type" class="form-select">
<option value="">All Types</option>
<option value="BLOOD" {% if specimen_type == 'BLOOD' %}selected{% endif %}>Blood</option>
<option value="URINE" {% if specimen_type == 'URINE' %}selected{% endif %}>Urine</option>
<option value="STOOL" {% if specimen_type == 'STOOL' %}selected{% endif %}>Stool</option>
<option value="SPUTUM" {% if specimen_type == 'SPUTUM' %}selected{% endif %}>Sputum</option>
<option value="CSF" {% if specimen_type == 'CSF' %}selected{% endif %}>CSF</option>
<option value="TISSUE" {% if specimen_type == 'TISSUE' %}selected{% endif %}>Tissue</option>
<option value="SWAB" {% if specimen_type == 'SWAB' %}selected{% endif %}>Swab</option>
</select>
</div>
<div class="col-md-2">
<input type="date" name="date_from" class="form-control"
value="{{ date_from }}" placeholder="From Date">
</div>
<div class="col-md-3">
<input type="text" name="search" class="form-control"
value="{{ search }}" placeholder="Search specimens, patients, orders...">
</div>
<div class="col-md-1">
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-search"></i>
</button>
</div>
</div>
</form>
<!-- Specimens Table -->
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Specimen #</th>
<th>Patient</th>
<th>Order #</th>
<th>Type</th>
<th>Collected</th>
<th>Quality</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for specimen in page_obj %}
<tr {% if specimen.quality != 'ACCEPTABLE' %}class="table-warning"{% endif %}>
<td>
<strong>{{ specimen.specimen_number }}</strong>
{% if specimen.container_type %}
<br><small class="text-muted">{{ specimen.container_type }}</small>
{% endif %}
</td>
<td>
<strong>{{ specimen.order.patient.get_full_name }}</strong><br>
<small class="text-muted">
MRN: {{ specimen.order.patient.mrn }} •
{{ specimen.order.patient.age }}y {{ specimen.order.patient.get_gender_display }}
</small>
</td>
<td>{{ specimen.order.order_number }}</td>
<td>{{ specimen.get_specimen_type_display }}</td>
<td>
{{ specimen.collected_datetime|date:"M d, Y H:i" }}
{% if specimen.collected_by %}
<br><small class="text-muted">By: {{ specimen.collected_by.get_full_name }}</small>
{% endif %}
</td>
<td>
{% if specimen.quality == 'ACCEPTABLE' %}
<span class="badge bg-success">Acceptable</span>
{% elif specimen.quality == 'HEMOLYZED' %}
<span class="badge bg-warning">Hemolyzed</span>
{% elif specimen.quality == 'CLOTTED' %}
<span class="badge bg-warning">Clotted</span>
{% elif specimen.quality == 'INSUFFICIENT' %}
<span class="badge bg-danger">Insufficient</span>
{% elif specimen.quality == 'CONTAMINATED' %}
<span class="badge bg-danger">Contaminated</span>
{% endif %}
</td>
<td>
{% if specimen.status == 'COLLECTED' %}
<span class="badge bg-info">Collected</span>
{% elif specimen.status == 'RECEIVED' %}
<span class="badge bg-primary">Received</span>
{% elif specimen.status == 'PROCESSING' %}
<span class="badge bg-warning">Processing</span>
{% elif specimen.status == 'COMPLETED' %}
<span class="badge bg-success">Completed</span>
{% elif specimen.status == 'REJECTED' %}
<span class="badge bg-danger">Rejected</span>
{% endif %}
</td>
<td>
<div class="btn-group btn-group-sm">
<button class="btn btn-outline-primary" title="View Details">
<i class="fas fa-eye"></i>
</button>
{% if specimen.status == 'COLLECTED' %}
<button class="btn btn-outline-success"
title="Mark Received"
hx-post="{% url 'laboratory:receive_specimen' specimen.specimen_id %}"
hx-confirm="Mark specimen as received?"
hx-swap="none">
<i class="fas fa-check"></i>
</button>
{% elif specimen.status == 'RECEIVED' and specimen.quality == 'ACCEPTABLE' %}
<button class="btn btn-outline-info"
title="Start Processing"
hx-post="{% url 'laboratory:start_processing' specimen.specimen_id %}"
hx-confirm="Start processing this specimen?"
hx-swap="none">
<i class="fas fa-play"></i>
</button>
{% endif %}
{% if specimen.quality != 'ACCEPTABLE' and specimen.status != 'REJECTED' %}
<button class="btn btn-outline-danger"
title="Reject Specimen"
hx-post="{% url 'laboratory:reject_specimen' specimen.specimen_id %}"
hx-confirm="Reject this specimen due to quality issues?"
hx-swap="none">
<i class="fas fa-times"></i>
</button>
{% endif %}
<button class="btn btn-outline-secondary" title="Print Label">
<i class="fas fa-print"></i>
</button>
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="8" class="text-center py-4">
<i class="fas fa-flask fa-3x text-muted mb-3"></i>
<h5 class="text-muted">No specimens found</h5>
<p class="text-muted">No specimens match your current filters.</p>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if page_obj.has_other_pages %}
<nav aria-label="Specimen pagination">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page=1{% if search %}&search={{ search }}{% endif %}{% if status %}&status={{ status }}{% endif %}">First</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}{% if search %}&search={{ search }}{% endif %}{% if status %}&status={{ status }}{% endif %}">Previous</a>
</li>
{% endif %}
<li class="page-item active">
<span class="page-link">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
</span>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}{% if search %}&search={{ search }}{% endif %}{% if status %}&status={{ status }}{% endif %}">Next</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}{% if search %}&search={{ search }}{% endif %}{% if status %}&status={{ status }}{% endif %}">Last</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}