60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
import psycopg2
|
|
|
|
DB_CONFIG = {
|
|
"host": "192.168.110.252",
|
|
"port": 15432,
|
|
"database": "postgresql",
|
|
"user": "postgresql",
|
|
"password": "Jchl1528",
|
|
"options": "-c search_path=hisdev",
|
|
}
|
|
|
|
|
|
def check():
|
|
conn = None
|
|
try:
|
|
conn = psycopg2.connect(**DB_CONFIG)
|
|
cursor = conn.cursor()
|
|
|
|
print("=" * 80)
|
|
print("Records WITHOUT surgeryName (need fix)")
|
|
print("=" * 80)
|
|
|
|
cursor.execute("""
|
|
SELECT
|
|
wsr.id,
|
|
wsr.activity_id,
|
|
wsr.create_time,
|
|
cs.surgery_name,
|
|
cs.surgery_code
|
|
FROM wor_service_request wsr
|
|
LEFT JOIN cli_surgery cs ON cs.id = wsr.activity_id
|
|
WHERE wsr.category_enum = 4
|
|
AND wsr.delete_flag = '0'
|
|
AND (wsr.content_json::jsonb->>'surgeryName' IS NULL OR wsr.content_json::jsonb->>'surgeryName' = '')
|
|
ORDER BY wsr.create_time DESC
|
|
""")
|
|
|
|
rows = cursor.fetchall()
|
|
print(f"\nTotal: {len(rows)} records\n")
|
|
|
|
for row in rows:
|
|
print(f"ID: {row[0]}")
|
|
print(f" activity_id: {row[1]}")
|
|
print(f" create_time: {row[2]}")
|
|
print(f" cli_surgery.surgery_name: {'[HAS]' if row[3] else '[NULL]'}")
|
|
print(f" cli_surgery.surgery_code: {'[HAS]' if row[4] else '[NULL]'}")
|
|
print()
|
|
|
|
cursor.close()
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
finally:
|
|
if conn:
|
|
conn.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
check()
|