fix(doctor): replicate exact HMS getCurrentAdmissions query joining ipd_master_doc_list and bed_assignment_history
This commit is contained in:
parent
5bfe0689f1
commit
820c904eff
|
|
@ -402,20 +402,35 @@ class DoctorApi extends BaseController
|
|||
$db = db_connect();
|
||||
helper('common');
|
||||
|
||||
$sql = "SELECT ipd.id as ipd_id, ipd.ipd_code, ipd.p_id, ipd.r_doc_id, ipd.r_doc_name, ipd.register_date, ipd.problem,
|
||||
p.p_fname as fname, p.p_code as uhid, p.mphone1, p.gender, p.age, p.age_in_month, p.estimate_dob, p.dob,
|
||||
b.bed_code, b.bed_number, w.ward_name
|
||||
FROM ipd_master ipd
|
||||
JOIN patient_master p ON p.id = ipd.p_id
|
||||
LEFT JOIN bed_master b ON b.id = ipd.bed_no
|
||||
LEFT JOIN ward_master w ON w.id = b.ward_id
|
||||
WHERE ipd.ipd_status = 0";
|
||||
$sql = "SELECT i.id as ipd_id, i.ipd_code, i.p_id, i.r_doc_id, i.r_doc_name, i.register_date, i.problem,
|
||||
p.p_fname as fname, p.p_rname as rname, p.p_code as uhid, p.mphone1, p.gender, p.age, p.age_in_month, p.estimate_dob, p.dob,
|
||||
concat('Bed No :', coalesce(b.bed_number, b.bed_code, 'N/A'), ' [', coalesce(w.ward_name, 'General Ward'), ']') as Bed_Desc,
|
||||
b.bed_code, b.bed_number, w.ward_name,
|
||||
ipd_doc_list.doc_name as assigned_doctors,
|
||||
ipd_doc_list.doc_list as doc_list
|
||||
FROM ipd_master i
|
||||
JOIN patient_master p ON i.p_id = p.id
|
||||
LEFT JOIN (
|
||||
select max(id) as id, ipd_id from bed_assignment_history group by ipd_id
|
||||
) bah_latest ON bah_latest.ipd_id = i.id
|
||||
LEFT JOIN bed_assignment_history bah ON bah.id = bah_latest.id
|
||||
LEFT JOIN bed_master b ON b.id = bah.bed_id
|
||||
LEFT JOIN ward_master w ON w.id = bah.ward_id
|
||||
LEFT JOIN (
|
||||
select i.ipd_id,
|
||||
group_concat(distinct concat_ws(' ', 'Dr.', d.p_fname, d.p_mname, d.p_lname)) as doc_name,
|
||||
group_concat(distinct d.id) as doc_list
|
||||
from ipd_master_doc_list i
|
||||
join doctor_master d on i.doc_id = d.id
|
||||
group by i.ipd_id
|
||||
) ipd_doc_list ON i.id = ipd_doc_list.ipd_id
|
||||
WHERE i.ipd_status = 0";
|
||||
|
||||
if ($docId > 0) {
|
||||
$sql .= " AND (ipd.r_doc_id = " . (int) $docId . " OR ipd.r_doc_id IS NULL OR ipd.r_doc_id = 0)";
|
||||
$sql .= " AND (FIND_IN_SET(" . (int) $docId . ", coalesce(ipd_doc_list.doc_list, '')) OR i.r_doc_id = " . (int) $docId . " OR i.r_doc_id IS NULL OR i.r_doc_id = 0)";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY ipd.id DESC";
|
||||
$sql .= " ORDER BY i.id DESC";
|
||||
|
||||
$query = $db->query($sql);
|
||||
$patients = $query->getResultArray();
|
||||
|
|
@ -435,7 +450,7 @@ class DoctorApi extends BaseController
|
|||
$r['age_display'] = $ageDisplay;
|
||||
$r['gender_label'] = ((int)($r['gender'] ?? 1) === 1) ? 'Male' : 'Female';
|
||||
$r['patient_display_name'] = $r['fname'] ?? 'Patient';
|
||||
$r['bed_label'] = ! empty($r['ward_name']) ? ($r['ward_name'] . ' - Bed ' . ($r['bed_number'] ?? $r['bed_code'] ?? '')) : 'General Ward';
|
||||
$r['bed_label'] = ! empty($r['Bed_Desc']) ? $r['Bed_Desc'] : (! empty($r['ward_name']) ? ($r['ward_name'] . ' - Bed ' . ($r['bed_number'] ?? '')) : 'General Ward');
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
|
|
|
|||
|
|
@ -495,7 +495,8 @@
|
|||
const name = (pat.patient_display_name || pat.fname || '').toLowerCase();
|
||||
const uhid = (pat.uhid || '').toLowerCase();
|
||||
const ipdCode = (pat.ipd_code || '').toLowerCase();
|
||||
return searchQuery === '' || name.includes(q) || uhid.includes(q) || ipdCode.includes(q);
|
||||
const docName = (pat.assigned_doctors || pat.r_doc_name || '').toLowerCase();
|
||||
return searchQuery === '' || name.includes(q) || uhid.includes(q) || ipdCode.includes(q) || docName.includes(q);
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
|
@ -751,22 +752,21 @@
|
|||
|
||||
<div className="card shadow-sm border-0">
|
||||
<div className="card-body p-0 table-responsive">
|
||||
<table className="table table-hover align-middle mb-0" style={{minWidth: '650px'}}>
|
||||
<table className="table table-hover align-middle mb-0" style={{minWidth: '700px'}}>
|
||||
<thead className="table-light">
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<th>IPD Code</th>
|
||||
<th>Admitted Patient</th>
|
||||
<th>Ward & Bed</th>
|
||||
<th>UHID</th>
|
||||
<th>Admitted Date</th>
|
||||
<th>Name / Patient Code</th>
|
||||
<th>Bed No. [Type]</th>
|
||||
<th>Register Date</th>
|
||||
<th>Dr. Name</th>
|
||||
<th className="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filteredIpdPatients.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan="7" className="text-center text-muted py-4">
|
||||
<td colSpan="6" className="text-center text-muted py-4">
|
||||
<i className="bi bi-hospital fs-1 d-block text-secondary mb-2"></i>
|
||||
No Admitted IPD Patients found for Dr. {authenticatedDoctor.name}.
|
||||
</td>
|
||||
|
|
@ -774,15 +774,24 @@
|
|||
) : (
|
||||
filteredIpdPatients.map(pat => (
|
||||
<tr key={pat.ipd_id}>
|
||||
<td><span className="badge bg-success text-uppercase">Admitted</span></td>
|
||||
<td><strong className="text-dark">{pat.ipd_code}</strong></td>
|
||||
<td>
|
||||
<div className="fw-bold text-primary">{pat.patient_display_name}</div>
|
||||
<small className="text-muted">({pat.age_display} / {pat.gender_label})</small>
|
||||
<strong className="text-dark d-block">{pat.ipd_code}</strong>
|
||||
<span className="badge bg-success" style={{fontSize: '9px'}}>CURRENT ADMISSION</span>
|
||||
</td>
|
||||
<td>
|
||||
<small className="text-danger fw-bold d-block">[{pat.uhid}]</small>
|
||||
<div className="fw-bold text-primary">{pat.patient_display_name}</div>
|
||||
<small className="text-muted">{pat.rname ? `S/D/W of ${pat.rname}` : `(${pat.age_display} / ${pat.gender_label})`}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span className="badge bg-primary-subtle text-primary border">{pat.bed_label}</span>
|
||||
</td>
|
||||
<td>
|
||||
<small className="text-dark fw-semibold">{pat.register_date || 'Today'}</small>
|
||||
</td>
|
||||
<td>
|
||||
<small className="text-dark fw-semibold">{pat.assigned_doctors || pat.r_doc_name || `Dr. ${authenticatedDoctor.name}`}</small>
|
||||
</td>
|
||||
<td><span className="badge bg-primary-subtle text-primary border">{pat.bed_label}</span></td>
|
||||
<td><code>{pat.uhid}</code></td>
|
||||
<td><small className="text-muted">{pat.register_date || 'Today'}</small></td>
|
||||
<td className="text-center">
|
||||
<button
|
||||
className="btn btn-sm btn-primary fw-bold"
|
||||
|
|
@ -810,7 +819,7 @@
|
|||
<button className="btn btn-sm btn-outline-dark" onClick={() => setActivePatient(null)}>
|
||||
<i className="bi bi-arrow-left me-1"></i> Back to Admitted IPDs
|
||||
</button>
|
||||
<span className="badge bg-success fs-6">Status: ADMITTED</span>
|
||||
<span className="badge bg-success fs-6">Status: CURRENT ADMISSION</span>
|
||||
</div>
|
||||
|
||||
<div className="card shadow-sm mb-3 border-0 bg-primary text-white">
|
||||
|
|
@ -818,7 +827,7 @@
|
|||
<h5 className="fw-bold mb-1">{activePatient.patient_display_name}</h5>
|
||||
<small className="opacity-90 me-3">Demographics: {activePatient.age_display} / {activePatient.gender_label}</small>
|
||||
<small className="opacity-90 me-3">UHID: {activePatient.uhid}</small>
|
||||
<small className="opacity-90 me-3">IPD: {activePatient.ipd_code}</small>
|
||||
<small className="opacity-90 me-3">IPD Code: {activePatient.ipd_code}</small>
|
||||
<small className="opacity-90">Bed: {activePatient.bed_label}</small>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user