feat: implement doctor data migration and update booking link UI in doctor-detail template
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import csv
|
||||
import sys
|
||||
|
||||
csv_file = '/home/x79/sisvietnamvn_01/Media/HÌNH ẢNH BÁC SĨ NGỒI PHÒNG KHÁM/ALL_IMAGES/DANH SÁCH BÁC SĨ NGỒI PHÒNG KHÁM.csv'
|
||||
|
||||
sql_statements = []
|
||||
|
||||
try:
|
||||
with open(csv_file, 'r', encoding='utf-8-sig') as f:
|
||||
reader = csv.DictReader(f)
|
||||
specialties = set()
|
||||
doctor_mappings = []
|
||||
for row in reader:
|
||||
doctor_code = row.get('MSNV', '').strip()
|
||||
specialty_name = row.get('Khoa / phòng', '').strip()
|
||||
if doctor_code and specialty_name:
|
||||
specialties.add(specialty_name)
|
||||
doctor_mappings.append((doctor_code, specialty_name))
|
||||
|
||||
# We will assume there's a sequence sis_specialty_seq or we just use IDs starting from 1000
|
||||
# Wait, the best way in Oracle is to use MERGE or just PL/SQL block
|
||||
|
||||
plsql = "BEGIN\n"
|
||||
for spec in specialties:
|
||||
safe_spec = spec.replace("'", "''")
|
||||
plsql += f"""
|
||||
DECLARE
|
||||
v_count NUMBER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO v_count FROM sis_specialty WHERE name = '{safe_spec}';
|
||||
IF v_count = 0 THEN
|
||||
INSERT INTO sis_specialty (id, name, active, created_by, created_date, last_modified_by, last_modified_date)
|
||||
VALUES (sequenceGenerator.NEXTVAL, '{safe_spec}', 1, 'system', sysdate, 'system', sysdate);
|
||||
END IF;
|
||||
END;
|
||||
"""
|
||||
|
||||
for doc_code, spec in doctor_mappings:
|
||||
safe_spec = spec.replace("'", "''")
|
||||
safe_code = doc_code.replace("'", "''")
|
||||
plsql += f"""
|
||||
UPDATE sis_doctor
|
||||
SET specialty_id = (SELECT id FROM sis_specialty WHERE name = '{safe_spec}' FETCH FIRST 1 ROWS ONLY)
|
||||
WHERE doctor_code = '{safe_code}';
|
||||
"""
|
||||
|
||||
plsql += "COMMIT;\nEND;\n/"
|
||||
|
||||
with open('/home/x79/sisvietnamvn_01/sisvietnamvn_main/src/main/resources/config/liquibase/data/map_specialties.sql', 'w', encoding='utf-8') as out_f:
|
||||
out_f.write(plsql)
|
||||
|
||||
print("Generated map_specialties.sql")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
Reference in New Issue
Block a user