38960-vm/update_actions.py
2026-03-05 18:47:27 +00:00

38 lines
2.1 KiB
Python

import re
file_path = 'includes/actions.php'
with open(file_path, 'r') as f:
content = f.read()
# 1. Update variable assignments
# This is safe to replace globally as it adds variables where address is defined.
content = content.replace(
"$address = $_POST['address'] ?? '';",
"$address = $_POST['address'] ?? '';\n $civil_id = $_POST['civil_id'] ?? '';\n $nationality = $_POST['nationality'] ?? '';\n $city = $_POST['city'] ?? '';"
)
# 2. Update INSERT query (Add Patient)
old_insert = '"INSERT INTO patients (name, phone, dob, gender, blood_group, insurance_company_id, policy_number, address) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"'
new_insert = '"INSERT INTO patients (name, phone, dob, gender, blood_group, insurance_company_id, policy_number, address, civil_id, nationality, city) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"'
content = content.replace(old_insert, new_insert)
# Update INSERT execution array
old_exec_insert = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address]'
new_exec_insert = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address, $civil_id, $nationality, $city]'
content = content.replace(old_exec_insert, new_exec_insert)
# 3. Update UPDATE query (Edit Patient)
old_update = '"UPDATE patients SET name = ?, phone = ?, dob = ?, gender = ?, blood_group = ?, insurance_company_id = ?, policy_number = ?, address = ? WHERE id = ?"'
new_update = '"UPDATE patients SET name = ?, phone = ?, dob = ?, gender = ?, blood_group = ?, insurance_company_id = ?, policy_number = ?, address = ?, civil_id = ?, nationality = ?, city = ? WHERE id = ?"'
content = content.replace(old_update, new_update)
# Update UPDATE execution array
old_exec_update = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address, $id]'
new_exec_update = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address, $civil_id, $nationality, $city, $id]'
content = content.replace(old_exec_update, new_exec_update)
with open(file_path, 'w') as f:
f.write(content)
print("Updated actions.php")