feat(discharge): add department and time placeholders
This commit is contained in:
parent
23fd1bf73f
commit
561adb9647
|
|
@ -356,6 +356,7 @@ class Ipd_discharge extends BaseController
|
|||
'AGE_GENDER' => esc($ageGender),
|
||||
'ADMIT_DATE' => esc($this->safeDate((string) ($ipd->str_register_date ?? $ipd->register_date ?? ''))),
|
||||
'DISCHARGE_DATE' => esc($this->safeDate((string) ($ipd->str_discharge_date ?? $ipd->discharge_date ?? ''))),
|
||||
'ISDELIVERY' => esc((string) ($ipd->isdelivery ?? '')),
|
||||
'CURRENT_DATE' => esc(date('d-m-Y')),
|
||||
'PRINT_TIME' => esc(date('d-m-Y H:i:s')),
|
||||
'H_Name' => esc($hName),
|
||||
|
|
@ -445,8 +446,12 @@ class Ipd_discharge extends BaseController
|
|||
'GUARDIAN_NAME' => esc($guardianName),
|
||||
'GUARDIAN' => esc($guardianCombined),
|
||||
'PATIENT_ADDRESS' => esc($address),
|
||||
'DEPARTMENT' => esc($this->getDischargeDepartmentName($ipd)),
|
||||
'ADMIT_DATE_ONLY' => esc($this->safeDate((string) ($ipd->str_register_date ?? $ipd->register_date ?? ''))),
|
||||
'DISCHARGE_DATE_ONLY' => esc($this->safeDate((string) ($ipd->str_discharge_date ?? $ipd->discharge_date ?? ''))),
|
||||
'ADMISSION_TIME' => esc($this->safeTime((string) ($ipd->register_date ?? $ipd->register_time ?? $ipd->admission_time ?? $ipd->str_register_date ?? ''))),
|
||||
'DISCHARGE_TIME' => esc($this->safeTime((string) ($ipd->discharge_date ?? $ipd->discharge_time ?? $ipd->str_discharge_date ?? ''))),
|
||||
'ADMIT_TIME' => esc($this->safeTime((string) ($ipd->register_date ?? $ipd->register_time ?? $ipd->admission_time ?? $ipd->str_register_date ?? ''))),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -734,6 +739,11 @@ class Ipd_discharge extends BaseController
|
|||
return false;
|
||||
}
|
||||
|
||||
// If the template explicitly places section placeholders, preserve that order.
|
||||
if ($this->templateHasDischargeSectionPlaceholders($templateHtml)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$templateHasMeta = strpos($templateHtml, '{{PATIENT_NAME}}') !== false
|
||||
|| strpos($templateHtml, '{{UHID}}') !== false
|
||||
|| strpos($templateHtml, '{{IPD_CODE}}') !== false
|
||||
|
|
@ -756,6 +766,43 @@ class Ipd_discharge extends BaseController
|
|||
return $hasHeading && $hasPatientGrid && $hasClinicalBody;
|
||||
}
|
||||
|
||||
private function templateHasDischargeSectionPlaceholders(string $templateHtml): bool
|
||||
{
|
||||
$templateHtml = trim($templateHtml);
|
||||
if ($templateHtml === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sectionTokens = [
|
||||
'DISCHARGE_SUMMARY',
|
||||
'FINAL_DIAGNOSIS',
|
||||
'SURGERY',
|
||||
'PROCEDURE',
|
||||
'PERSONAL_HISTORY',
|
||||
'PRESENTING_COMPLAINTS',
|
||||
'PAIN_MEASUREMENT_SCALE',
|
||||
'GENERAL_EXAM_ADMISSION',
|
||||
'CLINICAL_INVESTIGATION_REPORTS',
|
||||
'COURSE_IN_HOSPITAL',
|
||||
'EXAMINATION_ON_DISCHARGE',
|
||||
'DRUG_ALLERGY_ADR',
|
||||
'CO_MORBIDITIES',
|
||||
'DISCHARGE_MEDICATIONS',
|
||||
'DIETARY_ADVICE',
|
||||
'DISCHARGE_INSTRUCTIONS',
|
||||
'SIGNATURE_BLOCK',
|
||||
];
|
||||
|
||||
foreach ($sectionTokens as $token) {
|
||||
if (preg_match('/\{\{\s*' . preg_quote($token, '/') . '\s*\}\}/i', $templateHtml) === 1
|
||||
|| preg_match('/\{\s*' . preg_quote($token, '/') . '\s*\}/i', $templateHtml) === 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function stripLegacyTopSummaryFromContent(
|
||||
string $content,
|
||||
string $templateHtml,
|
||||
|
|
@ -1134,6 +1181,21 @@ class Ipd_discharge extends BaseController
|
|||
return date('d-m-Y', $ts);
|
||||
}
|
||||
|
||||
private function safeTime(?string $dateValue): string
|
||||
{
|
||||
$value = trim((string) $dateValue);
|
||||
if ($value === '' || $value === '00:00:00' || $value === '00:00') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$ts = strtotime($value);
|
||||
if ($ts === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return date('h:i A', $ts);
|
||||
}
|
||||
|
||||
private function normalizeRichText(string $raw): string
|
||||
{
|
||||
$value = trim($raw);
|
||||
|
|
@ -1436,8 +1498,9 @@ class Ipd_discharge extends BaseController
|
|||
|
||||
$allergySection = '';
|
||||
$allergyLines = [];
|
||||
if ((string) ($opdHistory['drug_allergy_status'] ?? '') !== '') {
|
||||
$allergyLines[] = '<div><b>Drug Allergy Status:</b> ' . esc((string) ($opdHistory['drug_allergy_status'] ?? '')) . '</div>';
|
||||
$drugAllergyStatus = trim((string) ($opdHistory['drug_allergy_status'] ?? ''));
|
||||
if (! $this->isNoAllergyDataStatus($drugAllergyStatus)) {
|
||||
$allergyLines[] = '<div><b>Drug Allergy Status:</b> ' . esc($drugAllergyStatus) . '</div>';
|
||||
}
|
||||
if ((string) ($opdHistory['drug_allergy_details'] ?? '') !== '') {
|
||||
$allergyLines[] = '<div><b>Drug Allergy Details:</b> ' . esc((string) ($opdHistory['drug_allergy_details'] ?? '')) . '</div>';
|
||||
|
|
@ -3798,6 +3861,29 @@ class Ipd_discharge extends BaseController
|
|||
return trim(implode(PHP_EOL, $lines));
|
||||
}
|
||||
|
||||
private function isNoAllergyDataStatus(string $status): bool
|
||||
{
|
||||
$normalized = strtolower(trim($status));
|
||||
if ($normalized === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$noDataValues = [
|
||||
'allergies not known',
|
||||
'allergy not known',
|
||||
'drug allergy not known',
|
||||
'not known',
|
||||
'unknown',
|
||||
'none',
|
||||
'nil',
|
||||
'no',
|
||||
'n/a',
|
||||
'na',
|
||||
];
|
||||
|
||||
return in_array($normalized, $noDataValues, true);
|
||||
}
|
||||
|
||||
private function saveNabhHistoryFromDischarge(int $patientId, array $payload): bool
|
||||
{
|
||||
if ($patientId <= 0 || ! $this->db->tableExists('opd_prescription')) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ $status = (int) ($edit['status'] ?? 1);
|
|||
<div class="alert alert-info py-2 small">
|
||||
Available placeholders: <code>{{CONTENT}}</code>, <code>{{PATIENT_NAME}}</code>, <code>{{UHID}}</code>, <code>{{IPD_CODE}}</code>,
|
||||
<code>{{AGE_GENDER}}</code>, <code>{{GUARDIAN}}</code>, <code>{{GUARDIAN_RELATION}}</code>, <code>{{GUARDIAN_NAME}}</code>, <code>{{PATIENT_ADDRESS}}</code>,
|
||||
<code>{{ADMIT_DATE}}</code>, <code>{{DISCHARGE_DATE}}</code>, <code>{{ADMIT_DATE_ONLY}}</code>, <code>{{DISCHARGE_DATE_ONLY}}</code>, <code>{{CURRENT_DATE}}</code>,
|
||||
<code>{{DEPARTMENT}}</code>, <code>{{ADMIT_DATE}}</code>, <code>{{DISCHARGE_DATE}}</code>, <code>{{ADMIT_DATE_ONLY}}</code>, <code>{{DISCHARGE_DATE_ONLY}}</code>,
|
||||
<code>{{ADMISSION_TIME}}</code>, <code>{{DISCHARGE_TIME}}</code>, <code>{{ADMIT_TIME}}</code>, <code>{{CURRENT_DATE}}</code>,
|
||||
<code>{{H_Name}}</code>, <code>{{H_address_1}}</code>, <code>{{H_address_2}}</code>, <code>{{H_phone_No}}</code>, <code>{{H_Email}}</code>,
|
||||
<code>{{hospital_name}}</code>, <code>{{hospital_address}}</code>, <code>{{hospital_phone}}</code>, <code>{{hospital_email}}</code>,
|
||||
<code>{{PRINT_TIME}}</code>.<br>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user