#!/usr/bin/env python3 # -*- coding: utf-8 -*- import psycopg2 import json from datetime import datetime DB_CONFIG = { "host": "192.168.110.252", "port": 15432, "database": "postgresql", "user": "postgresql", "password": "Jchl1528", "options": "-c search_path=hisdev", } def check_surgery(): conn = None try: print("Connecting to database...") conn = psycopg2.connect(**DB_CONFIG) cursor = conn.cursor() print("Connected!\n") # Query recent surgery advice cursor.execute(""" SELECT id, content_json::jsonb->>'surgeryName' as surgery_name, content_json::jsonb->>'surgeryCode' as surgery_code, create_time FROM wor_service_request WHERE category_enum = 4 AND delete_flag = '0' ORDER BY create_time DESC LIMIT 3 """) rows = cursor.fetchall() print("=" * 60) print("Surgery Advice Check") print("=" * 60) if not rows: print("No surgery advice found!") else: for row in rows: print(f"\nID: {row[0]}") print(f"surgeryName: {row[1] if row[1] else 'EMPTY'}") print(f"surgeryCode: {row[2] if row[2] else 'EMPTY'}") print(f"create_time: {row[3]}") cursor.close() except Exception as e: print(f"Error: {e}") finally: if conn: conn.close() if __name__ == "__main__": check_surgery()