devsofttech_hms_ci4/check_instruction_db.php
DevSoftTech Server 2b95bb8b7c Fix: Data mixing between instruction_other and instruction_remark fields
ISSUE: instruction_remark (Discharge Summary) data appearing in instruction_other (Other Advice) field after save

ROOT CAUSE: Legacy table sync was writing wrong variable
- Save handler at line 5478 was writing \ to legacy food_text
- Should have been writing \
- When legacy fallback loads (if food_ids empty), wrong data copied to instruction_other

FIX: Changed line 5478 in Ipd_discharge.php
- Before: \['food_text'] = \;
- After:  \['food_text'] = \;

FILES MODIFIED:
1. app/Controllers/Ipd_discharge.php - Fixed legacy save handler
2. app/Views/billing/ipd/discharge_create.php - Removed debug comments

TESTING STEPS:
1. Clear corrupt legacy data: php clear_legacy_food.php 1
2. Go to /Ipd_discharge/ipd_select/1
3. Clear both fields
4. Type 'Hello Other' in Other Advice
5. Type 'Hello Discharge' in Discharge Summary
6. Click 'Save Discharge Advice'
7. After reload: Other Advice should show 'Hello Other', NOT 'Hello Discharge'

SCRIPTS ADDED:
- check_instruction_db.php - Check database values
- check_legacy_food.php - Check legacy table
- clear_legacy_food.php - Clean corrupt legacy data
- list_instruction_records.php - List all records
2026-06-07 20:00:59 +05:30

70 lines
2.3 KiB
PHP

<?php
// Direct database check - no CI4 bootstrap needed
$envFile = __DIR__ . '/.env';
if (!file_exists($envFile)) {
die("ERROR: .env file not found\n");
}
// Manually parse .env because parse_ini_file doesn't handle CI4 format well
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = 'hms_data_ci4';
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, 'database.default.hostname') !== false) {
$dbHost = trim(explode('=', $line, 2)[1] ?? 'localhost');
} elseif (strpos($line, 'database.default.username') !== false) {
$dbUser = trim(explode('=', $line, 2)[1] ?? 'root');
} elseif (strpos($line, 'database.default.password') !== false) {
$dbPass = trim(explode('=', $line, 2)[1] ?? '');
} elseif (strpos($line, 'database.default.database') !== false) {
$dbName = trim(explode('=', $line, 2)[1] ?? 'hms_data_ci4');
}
}
$conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
if ($conn->connect_error) {
die("ERROR: Connection failed: " . $conn->connect_error . "\n");
}
// Get IPD ID from command line or use default
$ipdId = isset($argv[1]) ? intval($argv[1]) : 1;
echo "=== Checking instruction data for IPD ID: {$ipdId} ===\n\n";
$stmt = $conn->prepare("SELECT id, ipd_id, comp_report, comp_remark, review_after FROM ipd_discharge_instructions WHERE ipd_id = ? LIMIT 1");
$stmt->bind_param("i", $ipdId);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
echo "ID: " . $row['id'] . "\n";
echo "IPD ID: " . $row['ipd_id'] . "\n\n";
echo "=== comp_remark (Discharge Summary field) ===\n";
echo $row['comp_remark'] . "\n\n";
echo "=== comp_report JSON (contains other_text = Other Advice field) ===\n";
echo $row['comp_report'] . "\n\n";
if (!empty($row['comp_report'])) {
$decoded = json_decode($row['comp_report'], true);
if ($decoded && isset($decoded['other_text'])) {
echo "=== Extracted other_text (Other Advice) ===\n";
echo $decoded['other_text'] . "\n\n";
}
}
echo "=== Review After ===\n";
echo ($row['review_after'] ?? '(empty)') . "\n\n";
} else {
echo "No instruction record found for IPD ID {$ipdId}\n";
}
$stmt->close();
$conn->close();
echo "=== Done ===\n";