From addef914685a79bf4b7c953a0d8610359134cdff Mon Sep 17 00:00:00 2001
From: DevSoftTech Server
';
@@ -971,7 +974,7 @@ class Diagnosis extends BaseController
}
$repoFormat = $this->db->table('lab_repo')
- ->select('Title, HTMLData')
+ ->select('Title, HTMLData, RTFData')
->where('mstRepoKey', (int) ($labRequest->lab_repo_id ?? 0))
->get()
->getRow();
@@ -981,6 +984,9 @@ class Diagnosis extends BaseController
: (string) ($labRequest->report_name ?? 'Radiology Report');
$reportString = (string) ($repoFormat->HTMLData ?? '');
+ if (trim($reportString) === '') {
+ $reportString = (string) ($repoFormat->RTFData ?? '');
+ }
$reportHeader = '' .
htmlspecialchars((string) $reportTitle, ENT_QUOTES, 'UTF-8') .
'
';
diff --git a/app/Controllers/Setting/Template.php b/app/Controllers/Setting/Template.php
index 639415a..248cdb9 100644
--- a/app/Controllers/Setting/Template.php
+++ b/app/Controllers/Setting/Template.php
@@ -81,6 +81,47 @@ class Template extends BaseController
return $map[$modality] ?? null;
}
+ private function buildDefaultPathologyTemplate(string $reportName): string
+ {
+ $name = strtolower(trim($reportName));
+ $isCbc = str_contains($name, 'cbc') || str_contains($name, 'complete blood count') || str_contains($name, 'hemogram');
+
+ if (! $isCbc) {
+ return '';
+ }
+
+ return <<COMPLETE BLOOD COUNT (CBC)' .
htmlspecialchars($reportTitle, ENT_QUOTES, 'UTF-8') .
'
| Investigation | +Result | +Unit | +Reference Range | +
|---|---|---|---|
| Hemoglobin (Hb) | g/dL | 12.0 - 16.0 | |
| Total WBC Count (TLC) | /cumm | 4,000 - 11,000 | |
| Neutrophils | % | 40 - 75 | |
| Lymphocytes | % | 20 - 40 | |
| Eosinophils | % | 1 - 6 | |
| Monocytes | % | 2 - 10 | |
| Basophils | % | 0 - 2 | |
| RBC Count | million/cumm | 4.0 - 5.5 | |
| PCV (HCT) | % | 36 - 46 | |
| MCV | fL | 80 - 100 | |
| MCH | pg | 27 - 32 | |
| MCHC | g/dL | 31 - 36 | |
| Platelet Count | lakh/cumm | 1.5 - 4.5 | |
| ESR | mm/hr | 0 - 20 |
Peripheral Smear: Normocytic normochromic RBCs. No hemoparasite seen.
+HTML; + } + private function requireModalityPermission(int $modality) { $permission = $this->permissionForModality($modality); @@ -194,6 +235,24 @@ class Template extends BaseController $query = $this->db->query($sql); $data['labReport_master'] = $query->getResult(); + if (! empty($data['labReport_master'])) { + $existingHtml = trim((string) ($data['labReport_master'][0]->HTMLData ?? '')); + if ($existingHtml === '') { + $legacyHtml = trim((string) ($data['labReport_master'][0]->RTFData ?? '')); + if ($legacyHtml !== '') { + $data['labReport_master'][0]->HTMLData = $legacyHtml; + $existingHtml = $legacyHtml; + } + } + + if ($existingHtml === '') { + $defaultHtml = $this->buildDefaultPathologyTemplate((string) ($data['labReport_master'][0]->Title ?? '')); + if ($defaultHtml !== '') { + $data['labReport_master'][0]->HTMLData = $defaultHtml; + } + } + } + $itemId = 0; if (! empty($data['labReport_master'])) { $itemId = (int) ($data['labReport_master'][0]->charge_id ?? 0); @@ -264,6 +323,13 @@ class Template extends BaseController $groupId = (int) $this->request->getPost('group_id'); $htmlData = (string) $this->request->getPost('HTMLData'); + if (trim($htmlData) === '') { + $defaultHtml = $this->buildDefaultPathologyTemplate($inputReportName); + if ($defaultHtml !== '') { + $htmlData = $defaultHtml; + } + } + if ($repoId <= 0 || $inputReportName === '') { return $this->response->setJSON([ 'update_record' => 0, @@ -277,6 +343,7 @@ class Template extends BaseController 'GrpKey' => $groupId, 'charge_id' => $chargeId, 'HTMLData' => $htmlData, + 'RTFData' => $htmlData, ], $repoId); return $this->response->setJSON([ @@ -303,6 +370,13 @@ class Template extends BaseController $groupId = (int) $this->request->getPost('group_id'); $htmlData = (string) $this->request->getPost('HTMLData'); + if (trim($htmlData) === '') { + $defaultHtml = $this->buildDefaultPathologyTemplate($inputReportName); + if ($defaultHtml !== '') { + $htmlData = $defaultHtml; + } + } + if ($inputReportName === '') { return $this->response->setJSON([ 'insertid' => 0, @@ -316,6 +390,7 @@ class Template extends BaseController 'GrpKey' => $groupId, 'charge_id' => $chargeId, 'HTMLData' => $htmlData, + 'RTFData' => $htmlData, ]); return $this->response->setJSON([ diff --git a/app/Models/IpdModel.php b/app/Models/IpdModel.php index fb70753..d7ae749 100644 --- a/app/Models/IpdModel.php +++ b/app/Models/IpdModel.php @@ -56,11 +56,15 @@ class IpdModel extends Model $docList = $data['doc_list'] ?? []; if (! empty($docList)) { foreach ($docList as $docId) { - $this->db->table('ipd_master_doc_list')->insert([ + $docPayload = $this->filterTableDataByExistingColumns('ipd_master_doc_list', [ 'doc_id' => $docId, 'ipd_id' => $insertId, 'log' => 'Insert By :' . $userSignature, ]); + + if (! empty($docPayload)) { + $this->db->table('ipd_master_doc_list')->insert($docPayload); + } } } @@ -69,6 +73,11 @@ class IpdModel extends Model public function addIpdDoc(array $docData): int { + $docData = $this->filterTableDataByExistingColumns('ipd_master_doc_list', $docData); + if (empty($docData)) { + return 0; + } + $inserted = $this->db->table('ipd_master_doc_list')->insert($docData); return $inserted ? (int) $this->db->insertID() : 0; @@ -101,22 +110,93 @@ class IpdModel extends Model return 1; } + private function filterTableDataByExistingColumns(string $table, array $data): array + { + if (! $this->db->tableExists($table)) { + return []; + } + + $fields = $this->db->getFieldNames($table) ?? []; + if (empty($fields)) { + return $data; + } + + return array_intersect_key($data, array_flip($fields)); + } + public function bedAssign(array $data): int { - $inserted = $this->db->table('ipd_bed_assign')->insert($data); - if (! $inserted) { + $ipdId = (int) ($data['ipd_id'] ?? 0); + $bedId = (int) ($data['bed_id'] ?? 0); + $fromDate = (string) ($data['Fdate'] ?? date('Y-m-d H:i:s')); + $toDate = (string) ($data['TDate'] ?? $fromDate); + + if ($ipdId <= 0 || $bedId <= 0) { return 0; } - $insertId = (int) $this->db->insertID(); + $insertId = 0; - $this->db->table('hc_bed_master') - ->where('bed_used_p_id', $data['ipd_id']) - ->update(['bed_used_p_id' => 0]); + if ($this->db->tableExists('bed_assignment_history')) { + $wardId = null; + if ($this->db->tableExists('bed_master') && in_array('ward_id', $this->db->getFieldNames('bed_master') ?? [], true)) { + $bedRow = $this->db->table('bed_master') + ->select('ward_id') + ->where('id', $bedId) + ->get() + ->getRowArray(); + $wardId = isset($bedRow['ward_id']) ? (int) $bedRow['ward_id'] : null; + } - $this->db->table('hc_bed_master') - ->where('id', $data['bed_id']) - ->update(['bed_used_p_id' => $data['ipd_id']]); + $assignedBy = (int) ($this->getUserIdentity()['id'] ?? 0); + + $inserted = $this->db->table('bed_assignment_history')->insert([ + 'ipd_id' => $ipdId, + 'bed_id' => $bedId, + 'assignment_type' => 'admission', + 'assigned_date' => $fromDate, + 'discharged_date' => $toDate, + 'assigned_by' => $assignedBy > 0 ? $assignedBy : null, + 'ward_id' => $wardId, + ]); + + if (! $inserted) { + return 0; + } + + $insertId = (int) $this->db->insertID(); + } elseif ($this->db->tableExists('ipd_bed_assign')) { + $inserted = $this->db->table('ipd_bed_assign')->insert([ + 'ipd_id' => $ipdId, + 'Fdate' => $fromDate, + 'TDate' => $toDate, + 'bed_id' => $bedId, + ]); + + if (! $inserted) { + return 0; + } + + $insertId = (int) $this->db->insertID(); + } else { + return 0; + } + + if ($this->db->tableExists('hc_bed_master') && in_array('bed_used_p_id', $this->db->getFieldNames('hc_bed_master') ?? [], true)) { + $this->db->table('hc_bed_master') + ->where('bed_used_p_id', $ipdId) + ->update(['bed_used_p_id' => 0]); + + $this->db->table('hc_bed_master') + ->where('id', $bedId) + ->update(['bed_used_p_id' => $ipdId]); + } + + if ($this->db->tableExists('bed_master') && in_array('bed_status', $this->db->getFieldNames('bed_master') ?? [], true)) { + $this->db->table('bed_master') + ->where('id', $bedId) + ->update(['bed_status' => 'occupied']); + } return $insertId; } diff --git a/app/Views/Setting/Insurance/insurance_create_V.php b/app/Views/Setting/Insurance/insurance_create_V.php index 3917376..543b78d 100644 --- a/app/Views/Setting/Insurance/insurance_create_V.php +++ b/app/Views/Setting/Insurance/insurance_create_V.php @@ -1,4 +1,53 @@ -
+
+
+ +
+ Amount received : = esc(number_format($amountReceived, 2, '.', '')) ?>
+ / Balance Amount : = esc(number_format($balanceAmount, 2, '.', '')) ?>
+ / Net Amount : = esc(number_format($netAmount, 2, '.', '')) ?>
+
+
+ Amount in Words : Rs. = esc(convertNumberToWords($netAmount)) ?> Only
+ + Prepared By : = esc((string) ($invoice->prepared_by ?? '')) ?> +
+ payment_mode ?? 0) > 2) : ?>
+ Payment Details [= esc((string) ($invoice->Payment_type_str ?? '')) ?>]
+
+ Payment Details [Payment No.:Mode of Payment:Amount]:
+
+ [= esc((string) ($ph->id ?? '')) ?>:= esc((string) ($ph->Payment_type_str ?? '')) ?>:= esc(number_format((float) ($ph->amount ?? 0), 2, '.', '')) ?>]/
+
+
+
+
+ Signature
+ + Date : = esc((string) ($invoice->confirm_invoice_datetime ?? date('Y-m-d H:i:s'))) ?> + |
+
+
|
+
+ |
+
+ = esc($hospitalName) ?>
+
+ = esc(trim($hospitalAddress1 . ', ' . $hospitalAddress2, ', ')) ?>
+
+
+
+ = $hospitalPhone !== '' ? ('Phone: ' . esc($hospitalPhone)) : '' ?>
+ = ($hospitalPhone !== '' && $hospitalEmail !== '') ? ' | ' : '' ?>
+ = $hospitalEmail !== '' ? ('Email: ' . esc($hospitalEmail)) : '' ?>
+
+
+ |
+
+ INVOICE
+ = esc($invoiceCode) ?>
+
+
+
+ = esc($invoiceStatus) ?>
+
+
+
+ Scan for info
+ |
+
|
+
+ Patient ID: = esc((string) ($patient->p_code ?? '')) ?>
+ Name: = esc(trim((string) ($patient->p_fname ?? ''))) ?>
+ Gender: = esc((string) ($patient->xgender ?? '')) ?>
+ Age: = esc((string) ($patient->age ?? '')) ?>
+ Phone: = esc((string) ($patient->mphone1 ?? '')) ?>
+ |
+
+
+ Refer By: = esc((string) ($invoice->refer_by_other ?? '')) ?>
+ Invoice Date: = esc($invoiceDate) ?>
+ Printed On: = esc($printedOn) ?>
+ |
+
+
+ Invoice ID: = esc($invoiceCode) ?>
+ Status: = esc($invoiceStatus) ?>
+ Payment Mode: payment_mode ?? 0);
+ echo $mode === 1 ? 'Cash' : ($mode === 2 ? 'Bank Card/Online' : ($mode === 3 ? 'IPD Credit' : ($mode === 4 ? 'Org. Credit' : 'Pending')));
+ ?>
+ |
+
|
+
+
+ Insurance: = esc((string) ($insuranceRow->ins_company_name ?? '')) ?>
+
+
+ Org. Case No: = esc((string) ($caseRow->case_id_code ?? '')) ?>
+
+ |
+ + |
| # | +Charges Group | +Charge Name | +Rate | +Qty | +Amount | +
|---|---|---|---|---|---|
| = $srno ?> | += esc((string) ($row->group_desc ?? '')) ?> | += esc((string) ($row->item_name ?? '')) ?> | += esc((string) ($row->item_rate ?? '')) ?> | += esc((string) ($row->item_qty ?? '')) ?> | += esc($currencyPrefix) ?> = number_format((float) ($row->item_amount ?? 0), 2) ?> | +
| Discount= !empty($invoice->discount_desc ?? '') ? (' - ' . esc((string) ($invoice->discount_desc ?? ''))) : '' ?> | +-= esc($currencyPrefix) ?> = number_format($discount, 2) ?> | +||||
|
+
+
+ Amount received: = esc($currencyPrefix) ?> = number_format(0, 2) ?> | Balance Amount: = esc($currencyPrefix) ?> = number_format($netAmount, 2) ?> | Net Amount: = esc($currencyPrefix) ?> = number_format($netAmount, 2) ?>
+ Amount in Words:
+ |
+
+
|
+