Merge develop into test - sync latest code
This commit is contained in:
116
scripts/test_doctorstation_sql.py
Normal file
116
scripts/test_doctorstation_sql.py
Normal file
@@ -0,0 +1,116 @@
|
||||
import psycopg2
|
||||
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("测试 DoctorStation SQL (模拟 doctor-station API)")
|
||||
print("=" * 80)
|
||||
print()
|
||||
|
||||
encounter_id = 2038823905749327873
|
||||
practitioner_id = 1980296166230962178
|
||||
|
||||
# 使用修改后的 SQL 查询(第三部分 - ServiceRequest)
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT
|
||||
COALESCE(T1.category_enum, 3) AS advice_type,
|
||||
T1.id AS request_id,
|
||||
T1.id || '-3' AS unique_key,
|
||||
'' AS prescription_no,
|
||||
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', T1.content_json::jsonb->>'adviceName') 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,
|
||||
99 AS sort_number,
|
||||
T1.based_on_id AS based_on_id,
|
||||
T1.category_enum AS category_enum
|
||||
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_type = row[0]
|
||||
request_id = row[1]
|
||||
advice_name = row[10]
|
||||
category_enum = row[25]
|
||||
|
||||
print(f"request_id: {request_id}")
|
||||
print(f" advice_type: {advice_type} (应该=4)")
|
||||
print(f" category_enum: {category_enum}")
|
||||
print(f" advice_name: {advice_name}")
|
||||
print(f" advice_name是否为空: {advice_name is None or advice_name == ''}")
|
||||
print()
|
||||
|
||||
# 特别检查手术医嘱
|
||||
surgery_rows = [r for r in rows if r[24] == 4] # category_enum = 4
|
||||
print(f"手术医嘱 (category_enum=4) 数量: {len(surgery_rows)}")
|
||||
print()
|
||||
|
||||
if surgery_rows:
|
||||
for row in surgery_rows:
|
||||
print(f"✓ 手术医嘱:")
|
||||
print(f" request_id: {row[1]}")
|
||||
print(f" advice_type: {row[0]} (应该=4)")
|
||||
print(f" advice_name: {row[10]}")
|
||||
print(
|
||||
f" 是否通过前端过滤: {'否 (adviceName为空)' if not row[10] or row[10].strip() == '' else '是'}"
|
||||
)
|
||||
else:
|
||||
print("✗ 未找到手术医嘱")
|
||||
print()
|
||||
print("可能原因:")
|
||||
print(" 1. SQL COALESCE 语法错误")
|
||||
print(" 2. content_json 中没有 surgeryName 字段")
|
||||
print(" 3. 数据未正确保存")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user