diff --git a/app/Controllers/Api/v1/DoctorApi.php b/app/Controllers/Api/v1/DoctorApi.php index 1391c76..886d342 100644 --- a/app/Controllers/Api/v1/DoctorApi.php +++ b/app/Controllers/Api/v1/DoctorApi.php @@ -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([ diff --git a/public/App/Doctor/index.html b/public/App/Doctor/index.html index 38fe60d..5563a17 100644 --- a/public/App/Doctor/index.html +++ b/public/App/Doctor/index.html @@ -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 @@
- +
- - - - - + + + + {filteredIpdPatients.length === 0 ? ( - @@ -774,15 +774,24 @@ ) : ( filteredIpdPatients.map(pat => ( - - + + + + - - -
Status IPD CodeAdmitted PatientWard & BedUHIDAdmitted DateName / Patient CodeBed No. [Type]Register DateDr. Name Action
+ No Admitted IPD Patients found for Dr. {authenticatedDoctor.name}.
Admitted{pat.ipd_code} -
{pat.patient_display_name}
- ({pat.age_display} / {pat.gender_label}) + {pat.ipd_code} + CURRENT ADMISSION +
+ [{pat.uhid}] +
{pat.patient_display_name}
+ {pat.rname ? `S/D/W of ${pat.rname}` : `(${pat.age_display} / ${pat.gender_label})`} +
+ {pat.bed_label} + + {pat.register_date || 'Today'} + + {pat.assigned_doctors || pat.r_doc_name || `Dr. ${authenticatedDoctor.name}`} {pat.bed_label}{pat.uhid}{pat.register_date || 'Today'} - Status: ADMITTED + Status: CURRENT ADMISSION
@@ -818,7 +827,7 @@
{activePatient.patient_display_name}
Demographics: {activePatient.age_display} / {activePatient.gender_label} UHID: {activePatient.uhid} - IPD: {activePatient.ipd_code} + IPD Code: {activePatient.ipd_code} Bed: {activePatient.bed_label}