From 1843460693908c4d423dd72091f4f445c70d6365 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Mon, 6 Apr 2026 11:24:11 +0530 Subject: [PATCH] feat: restore Old Prescription panel with add-one/add-all into current consult --- app/Controllers/Opd_prescription.php | 93 +++++++++++++++----- app/Views/billing/opd_prescription_basic.php | 36 ++++++++ 2 files changed, 107 insertions(+), 22 deletions(-) diff --git a/app/Controllers/Opd_prescription.php b/app/Controllers/Opd_prescription.php index 3c4d771..28e4b1e 100644 --- a/app/Controllers/Opd_prescription.php +++ b/app/Controllers/Opd_prescription.php @@ -5207,37 +5207,86 @@ class Opd_prescription extends BaseController ->getResultArray(); if (empty($rows)) { - return $this->response->setBody('

No old prescriptions found.

'); + return $this->response->setBody('

No old prescriptions found.

'); } $medicineTable = $this->findExistingTable(['opd_prescrption_prescribed', 'opd_prescription_prescribed']); - $html = '
'; - foreach ($rows as $index => $row) { - $rxLines = []; - if ($medicineTable !== null && !empty($row['session_id'])) { + if ($medicineTable === null) { + return $this->response->setBody('

Old medicine table not found.

'); + } + + $html = '
'; + foreach ($rows as $row) { + $sessionId = (int) ($row['session_id'] ?? 0); + $dateLabel = ! empty($row['apointment_date']) ? date('d/m/Y', strtotime((string) $row['apointment_date'])) : ''; + + $medRows = []; + if ($sessionId > 0) { $medRows = $this->db->table($medicineTable) - ->select('med_type,med_name,dosage,dosage_when,dosage_freq,no_of_days,qty,remark') - ->where('opd_pre_id', (int) $row['session_id']) + ->select('id,med_id,med_type,med_name,dosage,dosage_when,dosage_freq,no_of_days,qty,remark') + ->where('opd_pre_id', $sessionId) ->orderBy('id', 'ASC') ->get() ->getResultArray(); - foreach ($medRows as $med) { - $rxLines[] = esc(trim((string) ($med['med_type'] ?? ''))) . ' ' . esc(trim((string) ($med['med_name'] ?? ''))) . ' | ' - . esc(trim((string) ($med['dosage'] ?? ''))) . ' ' - . esc(trim((string) ($med['dosage_when'] ?? ''))) . ' ' - . esc(trim((string) ($med['dosage_freq'] ?? ''))) . ' ' - . esc(trim((string) ($med['no_of_days'] ?? ''))); - } } - $dateLabel = !empty($row['apointment_date']) ? date('d-m-Y', strtotime((string) $row['apointment_date'])) : ''; - $html .= '
' - . '
' . esc((string) ($row['opd_code'] ?? $row['opd_id'])) . ' ' . esc($dateLabel) . '
' - . '
' - . '
Complaints: ' . esc((string) ($row['complaints'] ?? '')) . '
' - . '
Diagnosis: ' . esc((string) ($row['diagnosis'] ?? '')) . '
' - . '
Rx:
' . (empty($rxLines) ? 'No medicine rows' : implode('
', $rxLines)) . '
' - . '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= 'OPD: ' . esc((string) ($row['opd_code'] ?? $row['opd_id'])) . ''; + if ($dateLabel !== '') { + $html .= '' . esc($dateLabel) . ''; + } + $html .= '
'; + $html .= ''; + $html .= '
'; + + $html .= '
'; + $html .= '
Complaint: ' . esc((string) ($row['complaints'] ?? '')) . '
'; + $html .= '
Diagnosis: ' . esc((string) ($row['diagnosis'] ?? '')) . '
'; + + if (empty($medRows)) { + $html .= '
No medicine row found.
'; + } else { + $html .= ''; + $html .= ''; + + foreach ($medRows as $med) { + $medType = trim((string) ($med['med_type'] ?? '')); + $medName = trim((string) ($med['med_name'] ?? '')); + $medLabel = trim($medType . ' ' . $medName); + $doseLabel = trim( + trim((string) ($med['dosage'] ?? '')) . ' ' + . trim((string) ($med['dosage_when'] ?? '')) . ' ' + . trim((string) ($med['dosage_freq'] ?? '')) + ); + if ($doseLabel === '') { + $doseLabel = '-'; + } + + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + } + + $html .= '
PrescribedDose+
' . esc($medLabel !== '' ? $medLabel : '-') . '' . esc($doseLabel) . '' + . '' + . '
'; + } + + $html .= '
'; + $html .= '
'; } $html .= '
'; diff --git a/app/Views/billing/opd_prescription_basic.php b/app/Views/billing/opd_prescription_basic.php index cf79436..3be848a 100644 --- a/app/Views/billing/opd_prescription_basic.php +++ b/app/Views/billing/opd_prescription_basic.php @@ -219,6 +219,11 @@ overflow-y: auto; padding-right: .15rem; } + .rx-old-prescribed-list { + max-height: 560px; + overflow-y: auto; + padding-right: .15rem; + } .rx-history-image-wrap { width: 84px; flex: 0 0 84px; @@ -259,6 +264,7 @@
+
@@ -394,6 +400,15 @@
+
+
+ Old Prescription + +
+
+
Loading old prescriptions...
+
+