Merge develop into test - sync latest code
This commit is contained in:
106
scripts/test_sql.py
Normal file
106
scripts/test_sql.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import psycopg2
|
||||
import json
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
conn = psycopg2.connect(
|
||||
host="192.168.110.252",
|
||||
port=15432,
|
||||
database="postgresql",
|
||||
user="postgresql",
|
||||
password="Jchl1528",
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SET search_path TO hisdev, public")
|
||||
|
||||
print("=" * 80)
|
||||
print("使用实际部署的SQL查询数据")
|
||||
print("=" * 80)
|
||||
print()
|
||||
|
||||
practitioner_id = 1980296166230962178
|
||||
encounter_id = 2038823905749327873
|
||||
|
||||
# 只查询第三部分(ServiceRequest)使用COALESCE
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT
|
||||
3 AS advice_type,
|
||||
T1.id AS request_id,
|
||||
T1.id || '-3' AS unique_key,
|
||||
T1.requester_id AS requester_id,
|
||||
T1.create_time AS request_time,
|
||||
CASE WHEN T1.requester_id = %s THEN '1' ELSE '0' END AS biz_request_flag,
|
||||
T1.content_json AS content_json,
|
||||
null AS skin_test_flag,
|
||||
null AS inject_flag,
|
||||
null AS group_id,
|
||||
COALESCE(T2.NAME, T1.content_json::jsonb->>'surgeryName') AS advice_name,
|
||||
'' AS volume,
|
||||
'' AS lot_number,
|
||||
T1.quantity AS quantity,
|
||||
T1.unit_code AS unit_code,
|
||||
T1.status_enum AS status_enum,
|
||||
'' AS method_code,
|
||||
'' AS rate_code,
|
||||
NULL AS dose,
|
||||
'' AS dose_unit_code,
|
||||
T3.id AS charge_item_id,
|
||||
T3.total_price AS total_price,
|
||||
T3.status_enum AS charge_status,
|
||||
ao.id AS position_id,
|
||||
ao.name AS position_name,
|
||||
null AS dispense_per_duration,
|
||||
1 AS part_percent,
|
||||
'' AS condition_definition_name,
|
||||
COALESCE(T1.therapy_enum, 2) AS therapyEnum,
|
||||
99 AS sort_number,
|
||||
T1.based_on_id AS based_on_id
|
||||
FROM wor_service_request AS T1
|
||||
LEFT JOIN wor_activity_definition AS T2
|
||||
ON T2.ID = T1.activity_id
|
||||
AND T2.delete_flag = '0'
|
||||
LEFT JOIN adm_charge_item AS T3 ON T3.service_id = T1.ID AND T3.delete_flag = '0' AND
|
||||
T3.service_table = 'wor_service_request'
|
||||
LEFT JOIN adm_organization AS ao ON ao.ID = T1.org_id AND ao.delete_flag = '0'
|
||||
WHERE T1.delete_flag = '0' AND T1.generate_source_enum = 1
|
||||
AND T1.parent_id IS NULL
|
||||
AND T1.encounter_id = %s
|
||||
ORDER BY T1.status_enum
|
||||
""",
|
||||
(practitioner_id, encounter_id),
|
||||
)
|
||||
|
||||
rows = cursor.fetchall()
|
||||
print(f"查询到 {len(rows)} 条 ServiceRequest 记录")
|
||||
print()
|
||||
|
||||
for row in rows:
|
||||
advice_name = row[10]
|
||||
therapy_enum = row[25]
|
||||
status = row[14]
|
||||
content_json = row[6]
|
||||
|
||||
print(f"advice_name: {advice_name}")
|
||||
print(f"therapyEnum: {therapy_enum} (类型: {type(therapy_enum)})")
|
||||
print(f"status_enum: {status}")
|
||||
print(f"content_json: {content_json[:80] if content_json else 'None'}...")
|
||||
print("-" * 80)
|
||||
|
||||
print()
|
||||
print("结论:")
|
||||
if len(rows) > 0 and rows[0][10] and rows[0][25] is not None:
|
||||
print("✓ SQL查询正常,数据完整")
|
||||
print(" - advice_name 已正确返回")
|
||||
print(" - therapyEnum 已正确返回")
|
||||
print()
|
||||
print("如果前端仍不显示,请检查:")
|
||||
print(" 1. 浏览器控制台的网络请求返回值")
|
||||
print(" 2. 前端代码是否正确处理了数据")
|
||||
else:
|
||||
print("✗ SQL查询有问题")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user