devsofttech_hms_ci4/clear_legacy_food.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

60 lines
1.9 KiB
PHP

<?php
// Clear corrupt legacy food_text for IPD ID
$envFile = __DIR__ . '/.env';
$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");
}
$ipdId = isset($argv[1]) ? intval($argv[1]) : 1;
echo "=== Clearing corrupt legacy food_text for IPD ID: {$ipdId} ===\n\n";
// Check if table and column exist
$tableCheck = $conn->query("SHOW TABLES LIKE 'ipd_discharge_drug_food_interaction'");
if ($tableCheck->num_rows === 0) {
echo "Table does not exist, nothing to clean\n";
$conn->close();
exit(0);
}
$colCheck = $conn->query("SHOW COLUMNS FROM ipd_discharge_drug_food_interaction LIKE 'food_text'");
if ($colCheck->num_rows === 0) {
echo "Column food_text does not exist, nothing to clean\n";
$conn->close();
exit(0);
}
// Clear the food_text
$stmt = $conn->prepare("UPDATE ipd_discharge_drug_food_interaction SET food_text = '' WHERE ipd_id = ?");
$stmt->bind_param("i", $ipdId);
if ($stmt->execute()) {
echo "✅ Cleared food_text for IPD ID {$ipdId}\n";
echo "Affected rows: " . $stmt->affected_rows . "\n";
} else {
echo "❌ Failed to clear: " . $stmt->error . "\n";
}
$stmt->close();
$conn->close();
echo "\n=== Done ===\n";