diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index db54a49..8346621 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -1950,15 +1950,25 @@ class Opd extends BaseController } $rxAdvice = $rxRead($rx, ['advice', 'Advice', 'prescription_advice', 'advice_notes', 'advice_note']); + $rxAdviceLocal = ''; if ($rxAdvice === '' && !empty($data['rx_advices']) && is_array($data['rx_advices'])) { $parts = []; + $partsLocal = []; foreach ($data['rx_advices'] as $adv) { $txt = trim((string) ($adv['advice_txt'] ?? $adv['advice'] ?? '')); if ($txt !== '') { $parts[] = $txt; } + + $localTxt = trim((string) ($adv['advice_hindi'] ?? ($adv['advice_txt_hindi'] ?? ''))); + if ($localTxt !== '') { + $partsLocal[] = $localTxt; + } } $rxAdvice = implode(', ', $parts); + if (!empty($partsLocal)) { + $rxAdviceLocal = implode(' | ', $partsLocal); + } } $complaintText = $rxRead($rx, ['complaints', 'Complaint', 'complaint', 'chief_complaint', 'chief_complaints']); @@ -1981,7 +1991,9 @@ class Opd extends BaseController $complaintLocal = $this->translateToLocalPatientText($complaintText); $diagnosisLocal = $this->translateToLocalPatientText($diagnosisText); $investigationLocal = $this->translateToLocalPatientText($rxInvestigation); - $rxAdviceLocal = $this->translateToLocalPatientText($rxAdvice); + if ($rxAdviceLocal === '') { + $rxAdviceLocal = $this->translateToLocalPatientText($rxAdvice); + } if (strtolower(trim($complaintLocal)) === strtolower(trim($complaintText))) { $complaintLocal = ''; @@ -3202,8 +3214,9 @@ class Opd extends BaseController } foreach ($data['rx_advices'] as $idx => $advRow) { - $currentHindi = trim((string) ($advRow['advice_hindi'] ?? '')); + $currentHindi = trim((string) ($advRow['advice_hindi'] ?? ($advRow['advice_txt_hindi'] ?? ''))); if ($currentHindi !== '') { + $data['rx_advices'][$idx]['advice_hindi'] = $currentHindi; continue; } diff --git a/app/Controllers/Opd_prescription.php b/app/Controllers/Opd_prescription.php index 1d888d8..790f885 100644 --- a/app/Controllers/Opd_prescription.php +++ b/app/Controllers/Opd_prescription.php @@ -3930,6 +3930,7 @@ class Opd_prescription extends BaseController $sessionId = (int) $this->request->getPost('opd_session_id'); $adviceText = trim((string) $this->request->getPost('advice_text')); $adviceId = (int) $this->request->getPost('advice_id'); + $adviceHindi = trim((string) $this->request->getPost('advice_hindi')); if ($opdId <= 0 || $adviceText === '') { return $this->response->setJSON(['update' => 0, 'error_text' => 'Advice text is required']); @@ -3946,6 +3947,33 @@ class Opd_prescription extends BaseController } $fields = $this->db->getFieldNames($table); + + if ($adviceHindi === '' && $this->db->tableExists('opd_advice')) { + $masterFields = $this->db->getFieldNames('opd_advice'); + $masterIdField = $this->resolveFirstField($masterFields, ['id', 'advice_id']); + $masterAdviceField = $this->resolveFirstField($masterFields, ['advice', 'advice_txt', 'advice_text']); + $masterHindiField = $this->resolveFirstField($masterFields, ['advice_hindi', 'advice_local', 'hindi_advice', 'advice_hin']); + + if ($masterAdviceField !== null && $masterHindiField !== null) { + $masterBuilder = $this->db->table('opd_advice') + ->select($masterAdviceField . ' as advice_text, ' . $masterHindiField . ' as advice_hindi' + . ($masterIdField !== null ? (', ' . $masterIdField . ' as advice_id') : '')); + + if ($masterIdField !== null && $adviceId > 0) { + $masterBuilder->where($masterIdField, $adviceId); + } else { + $normalizedAdviceText = preg_replace('/\s+/', ' ', $adviceText) ?? $adviceText; + $masterBuilder->groupStart() + ->where($masterAdviceField, $adviceText) + ->orWhere($masterAdviceField, $normalizedAdviceText) + ->groupEnd(); + } + + $masterRow = $masterBuilder->get(1)->getRowArray() ?? []; + $adviceHindi = trim((string) ($masterRow['advice_hindi'] ?? '')); + } + } + $insert = []; if (in_array('opd_id', $fields, true)) { $insert['opd_id'] = $opdId; @@ -3961,6 +3989,13 @@ class Opd_prescription extends BaseController } elseif (in_array('advice', $fields, true)) { $insert['advice'] = $adviceText; } + if ($adviceHindi !== '') { + if (in_array('advice_txt_hindi', $fields, true)) { + $insert['advice_txt_hindi'] = $adviceHindi; + } elseif (in_array('advice_hindi', $fields, true)) { + $insert['advice_hindi'] = $adviceHindi; + } + } $this->db->table($table)->insert($insert); $insertId = (int) $this->db->insertID(); diff --git a/app/Views/billing/opd_letter_head.php b/app/Views/billing/opd_letter_head.php index 211c549..8d4c0ca 100644 --- a/app/Views/billing/opd_letter_head.php +++ b/app/Views/billing/opd_letter_head.php @@ -225,7 +225,10 @@ - + + + + diff --git a/app/Views/billing/opd_letter_head_pdf.php b/app/Views/billing/opd_letter_head_pdf.php index 6b0e85e..d0f10ae 100644 --- a/app/Views/billing/opd_letter_head_pdf.php +++ b/app/Views/billing/opd_letter_head_pdf.php @@ -397,7 +397,7 @@ $toLocalText = static function (string $input): string { } $adviceLine[] = $t; - $localStored = trim((string) ($adv['advice_hindi'] ?? '')); + $localStored = trim((string) ($adv['advice_hindi'] ?? ($adv['advice_txt_hindi'] ?? ''))); if ($localStored !== '') { $adviceLocalLine[] = $localStored; } else {