diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index cd69260..2a572d6 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -1977,6 +1977,30 @@ class Ipd_discharge extends BaseController return '

' . esc($title) . ' :
' . implode('
', $lines) . '

'; } + private function sanitizeComplaintNarrativeRemark(string $remark): string + { + $remark = trim($remark); + if ($remark === '') { + return ''; + } + + $patterns = [ + '/^\s*Drug\s*Allergy\s*Status\s*:\s*.+$/im', + '/^\s*Drug\s*Allergy\s*Details\s*:\s*.+$/im', + '/^\s*ADR\s*History\s*:\s*.+$/im', + '/^\s*Current\s*Medications\s*:\s*.+$/im', + '/^\s*Co-Morbidities\s*:\s*.+$/im', + ]; + + foreach ($patterns as $pattern) { + $remark = (string) preg_replace($pattern, '', $remark); + } + + $remark = (string) preg_replace('/(?:\r\n?|\n){3,}/', "\n\n", $remark); + + return trim($remark); + } + private function buildInlineExamSummary(array $rows): string { $parts = []; @@ -2077,7 +2101,9 @@ class Ipd_discharge extends BaseController $complaints = $this->byIpdRows('ipd_discharge_complaint', ['comp_report', 'comp_remark'], 'id ASC', $ipdId); $complaintRemark = $this->firstRowByIpd('ipd_discharge_complaint_remark', $ipdId); - $complaintRemarkText = $this->normalizeRichText((string) ($complaintRemark['comp_remark'] ?? '')); + $complaintRemarkText = $this->sanitizeComplaintNarrativeRemark( + $this->normalizeRichText((string) ($complaintRemark['comp_remark'] ?? '')) + ); $complaintBlock = $this->buildNarrativeSection('Presenting Complaints and Reason for Admission', $complaints, $complaintRemarkText); if ($complaintBlock !== '') { $sections[] = $complaintBlock; @@ -2176,6 +2202,11 @@ class Ipd_discharge extends BaseController } $coMorbText = trim((string) ($opdHistory['co_morbidities'] ?? '')); + + if ($allergySection !== '') { + $sections[] = $allergySection; + } + if ($coMorbText !== '') { $sections[] = '

Co-Morbidities

' . esc($coMorbText) . '
'; } @@ -2319,10 +2350,6 @@ class Ipd_discharge extends BaseController $sections[] = $painSection; } - if ($allergySection !== '') { - $sections[] = $allergySection; - } - $nursingTrendSection = $this->buildNursingTrendSection($ipdId); if ($nursingTrendSection !== '') { $sections[] = $nursingTrendSection; diff --git a/app/Views/billing/ipd/discharge_create.php b/app/Views/billing/ipd/discharge_create.php index 42a08e3..59592c3 100644 --- a/app/Views/billing/ipd/discharge_create.php +++ b/app/Views/billing/ipd/discharge_create.php @@ -90,7 +90,7 @@ $legacyDrugRows = $legacy_drug_rows ?? []; $doseMasterMaps = $dose_master_maps ?? ['dose' => [], 'when' => [], 'freq' => [], 'where' => []]; // Helper function to get dose label from ID -$getDoseLabel = function($id, $type) use ($doseMasterMaps) { +$getDoseLabel = function ($id, $type) use ($doseMasterMaps) { $id = (int) $id; if ($id <= 0 || !isset($doseMasterMaps[$type][$id])) { return ''; @@ -224,18 +224,18 @@ $allergyStatusNormalized = strtolower($drugAllergyStatus); $allergyStatusKnown = in_array($allergyStatusNormalized, ['known'], true); $allergyStatusUnknown = in_array($allergyStatusNormalized, ['allergies not known', 'not known', 'unknown'], true); $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug allergy', 'none', 'no known allergy'], true); - - $historyFields = [ - 'is_smoking' => 'Smoking', - 'is_alcohol' => 'Alcohol', - 'is_tobacoo' => 'Tobacco', - 'is_drug_abuse' => 'Drug abuse', - 'is_hypertesion' => 'Hypertension', - 'is_niddm' => 'Type 2 diabetes mellitus (DM)', - 'is_hbsag' => 'HBsAg', - 'is_hcv' => 'HCV', - 'is_hiv_I_II' => 'HIV I & II', - ]; + +$historyFields = [ + 'is_smoking' => 'Smoking', + 'is_alcohol' => 'Alcohol', + 'is_tobacoo' => 'Tobacco', + 'is_drug_abuse' => 'Drug abuse', + 'is_hypertesion' => 'Hypertension', + 'is_niddm' => 'Type 2 diabetes mellitus (DM)', + 'is_hbsag' => 'HBsAg', + 'is_hcv' => 'HCV', + 'is_hiv_I_II' => 'HIV I & II', +]; ?>