Merge develop into test - sync latest code
This commit is contained in:
113
scripts/check_new_records.py
Normal file
113
scripts/check_new_records.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import psycopg2
|
||||
import json
|
||||
|
||||
DB_CONFIG = {
|
||||
"host": "192.168.110.252",
|
||||
"port": 15432,
|
||||
"database": "postgresql",
|
||||
"user": "postgresql",
|
||||
"password": "Jchl1528",
|
||||
"options": "-c search_path=hisdev",
|
||||
}
|
||||
|
||||
|
||||
def check_new_records():
|
||||
conn = None
|
||||
try:
|
||||
print("Connecting to database...")
|
||||
conn = psycopg2.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor()
|
||||
print("Connected!\n")
|
||||
|
||||
print("=" * 80)
|
||||
print("New Surgery Records Check")
|
||||
print("=" * 80)
|
||||
|
||||
# Check specific IDs
|
||||
ids = ["2039583488323280897", "2039583488231006210"]
|
||||
for id in ids:
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT
|
||||
wsr.id,
|
||||
wsr.category_enum,
|
||||
wsr.activity_id,
|
||||
wsr.content_json::jsonb->>'surgeryName' as surgery_name,
|
||||
wsr.content_json::jsonb->>'surgeryCode' as surgery_code,
|
||||
wsr.content_json as full_json,
|
||||
wsr.create_time,
|
||||
cs.surgery_name as cli_surgery_name,
|
||||
cs.surgery_code as cli_surgery_code
|
||||
FROM wor_service_request wsr
|
||||
LEFT JOIN cli_surgery cs ON cs.id = wsr.activity_id
|
||||
WHERE wsr.id = %s
|
||||
""",
|
||||
(id,),
|
||||
)
|
||||
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
print(f"\nRecord ID: {row[0]}")
|
||||
print(f" category_enum: {row[1]}")
|
||||
print(f" activity_id: {row[2]}")
|
||||
print(
|
||||
f" surgeryName from content_json: {row[3] if row[3] else 'EMPTY'}"
|
||||
)
|
||||
print(
|
||||
f" surgeryCode from content_json: {row[4] if row[4] else 'EMPTY'}"
|
||||
)
|
||||
print(f" cli_surgery_name: {row[7] if row[7] else 'N/A'}")
|
||||
print(f" create_time: {row[6]}")
|
||||
if row[5]:
|
||||
try:
|
||||
content = json.loads(row[5])
|
||||
print(f" Full content_json keys: {list(content.keys())}")
|
||||
except:
|
||||
print(f" Raw content_json: {row[5][:100]}")
|
||||
else:
|
||||
print(f"\nRecord {id} not found!")
|
||||
|
||||
# Check most recent 3 surgery records
|
||||
print("\n" + "=" * 80)
|
||||
print("Most Recent 3 Surgery Records")
|
||||
print("=" * 80)
|
||||
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
wsr.id,
|
||||
wsr.category_enum,
|
||||
wsr.activity_id,
|
||||
wsr.content_json::jsonb->>'surgeryName' as surgery_name,
|
||||
wsr.content_json::jsonb->>'surgeryCode' as surgery_code,
|
||||
wsr.create_time,
|
||||
cs.surgery_name as cli_surgery_name
|
||||
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'
|
||||
ORDER BY wsr.create_time DESC
|
||||
LIMIT 3
|
||||
""")
|
||||
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
print(f"\nID: {row[0]}")
|
||||
print(f" surgeryName: {row[3] if row[3] else 'EMPTY'}")
|
||||
print(f" surgeryCode: {row[4] if row[4] else 'EMPTY'}")
|
||||
print(f" cli_surgery_name: {row[6] if row[6] else 'N/A'}")
|
||||
print(f" create_time: {row[5]}")
|
||||
|
||||
cursor.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_new_records()
|
||||
Reference in New Issue
Block a user