USE `medical_consultation_agent`;

SET NAMES utf8mb4;

INSERT INTO `departments` (`id`, `name`, `code`, `parent_id`, `sort_order`, `is_active`)
VALUES (1, '儿科', 'PEDIATRICS', NULL, 1, 1)
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`), `is_active` = VALUES(`is_active`);

INSERT INTO `users` (`id`, `external_user_id`, `display_name`)
VALUES (1, 'system_seed', '系统种子数据')
ON DUPLICATE KEY UPDATE `display_name` = VALUES(`display_name`);

INSERT INTO `cases` (
  `id`,
  `case_code`,
  `department_id`,
  `title`,
  `difficulty`,
  `patient_name`,
  `patient_age`,
  `patient_gender`,
  `patient_occupation`,
  `chief_complaint`,
  `present_illness`,
  `past_history`,
  `personal_history`,
  `family_history`,
  `physical_exam`,
  `auxiliary_exam`,
  `diagnosis_primary`,
  `diagnosis_differential`,
  `diagnosis_basis`,
  `treatment_plan`,
  `consultation_config`,
  `inquiry_options`,
  `knowledge_videos`,
  `quiz_questions`,
  `key_symptoms`,
  `key_exams`,
  `key_points`,
  `evidence_reasoning_chain`,
  `assessment_config`,
  `ai_patient_profile`,
  `patient_opening`,
  `hidden_patient_info`,
  `has_teaching_video`,
  `has_knowledge_points`,
  `has_quiz`,
  `source_pdf_name`,
  `supported_training_type`,
  `supported_mode`,
  `is_active`,
  `created_by`
) VALUES (
  1,
  'PED_PNEUMONIA_001',
  1,
  '支气管肺炎 - 6岁男性患儿',
  'medium',
  '王**',
  6,
  'male',
  '学龄前儿童',
  '发热、咳嗽4天，喘息1天。',
  '患儿4天前出现发热，体温最高39.2℃，伴阵发性咳嗽，夜间明显。1天前出现喘息及精神稍差，在社区门诊口服退热药后体温反复。无惊厥，无呕吐腹泻。',
  '既往体健，出生足月，疫苗接种基本完整；有湿疹病史，无明确哮喘诊断史；无药物过敏史。',
  '与父母同住，近期幼儿园同班多人有上呼吸道感染；被动吸烟暴露。',
  '母亲有过敏性鼻炎史，否认家族遗传代谢病史。',
  JSON_OBJECT(
    'general', JSON_OBJECT('temperature','38.7℃','pulse','126次/分','respiration','30次/分','blood_pressure','96/60mmHg','mental_status','精神稍差','nasal_flaring','轻度鼻翼煽动'),
    'lung', '双肺呼吸音粗，可闻及散在湿啰音及少量哮鸣音',
    'heart', '心音有力',
    'abdomen', '腹软，无压痛，肝脾未触及肿大，肠鸣音正常',
    'neuro', '神经系统查体未见定位体征'
  ),
  JSON_ARRAY(
    JSON_OBJECT('name','血常规','result','WBC 12.4×10^9/L，中性粒细胞72%','is_abnormal',true,'is_key',false),
    JSON_OBJECT('name','CRP','result','32 mg/L','is_abnormal',true,'is_key',false),
    JSON_OBJECT('name','胸片','result','双下肺纹理增多，右下肺片状模糊影','is_abnormal',true,'is_key',true),
    JSON_OBJECT('name','肺炎支原体抗体IgM','result','弱阳性','is_abnormal',true,'is_key',false),
    JSON_OBJECT('name','血氧饱和度','result','室内空气 SpO2 94%','is_abnormal',true,'is_key',true)
  ),
  '支气管肺炎',
  JSON_ARRAY('毛细支气管炎','支气管哮喘急性发作','肺结核'),
  '患儿发热咳嗽伴喘息，肺部听诊有湿啰音，胸片示右下肺片状模糊影，炎症指标升高，符合支气管肺炎诊断。',
  JSON_OBJECT(
    'principle', JSON_ARRAY('抗感染','止咳平喘','改善氧合','严密观察病情变化'),
    'measures', JSON_ARRAY('根据病情和病原学选择抗感染治疗','必要时雾化吸入缓解喘息','监测体温、呼吸、血氧饱和度','评估是否住院观察'),
    'risk_plan', JSON_ARRAY('关注低氧','关注呼吸困难加重','关注持续高热','关注精神反应差'),
    'communication', JSON_ARRAY('向家属说明病情','说明观察指标','说明用药注意事项','说明复诊指征')
  ),
  JSON_OBJECT(),
  JSON_ARRAY(),
  JSON_ARRAY(),
  JSON_ARRAY(
    JSON_OBJECT('question','该患儿的首要诊断是？','type','single','answer','支气管肺炎'),
    JSON_OBJECT('question','本病例关键检查包括哪些？','type','multiple','answer',JSON_ARRAY('肺部湿啰音','胸片异常','血氧饱和度下降'))
  ),
  JSON_ARRAY('发热','咳嗽','喘息'),
  JSON_ARRAY('肺部湿啰音','胸片异常','血氧饱和度下降'),
  JSON_ARRAY('问诊完整性','儿科查体规范','关键症状识别','诊断准确性','治疗计划合理性'),
  JSON_OBJECT(
    'clinical_prediction_rule','根据患儿症状（发热、咳嗽、喘息）及体征（肺部湿啰音），结合实验室炎症指标升高和胸部影像学典型新发浸润影，符合儿童支气管肺炎临床诊断标准，参考《儿童社区获得性肺炎诊疗规范（2019年版）》。',
    'severity_assessment', JSON_ARRAY(
      '问题识别：判断患儿是否为重症肺炎，以决定治疗地点。',
      '证据检索与整合：检索儿童肺炎严重程度评估工具，结合儿童CURB-65改良标准或WHO儿童肺炎分级。',
      '应用评分：本例呼吸30次/分、SpO2 94%、无意识障碍、血压正常，尚未达到重症肺炎阈值。',
      '决策：判断为非重症肺炎，因血氧偏低和喘息存在，纳入住院观察和严密随访讨论。'
    )
  ),
  JSON_OBJECT(
    'score_dimensions', JSON_ARRAY('信息获取','分析推理','处置决策','沟通人文','临床整合'),
    'must_cover', JSON_ARRAY('发热持续时间','咳嗽特点','喘息出现时间','精神食欲睡眠','疫苗接种','过敏史','既往喘息史','肺部听诊','胸片','血氧饱和度')
  ),
  JSON_OBJECT(
    'role','患儿家属',
    'personality','担心、焦虑，但配合问诊',
    'speech_style','以家长口吻回答，描述孩子症状，回答简洁',
    'visible_info', JSON_ARRAY('发热咳嗽4天','喘息1天','精神稍差'),
    'rules', JSON_ARRAY('只回答病例内事实','不主动给出诊断','不一次性泄露所有隐藏信息')
  ),
  '家长：医生，孩子发烧咳嗽好几天了，昨天开始喘得厉害，精神也不太好。',
  JSON_ARRAY('近期幼儿园同班多人上呼吸道感染','被动吸烟暴露','母亲有过敏性鼻炎史','有湿疹病史','无明确哮喘诊断史'),
  0,
  1,
  1,
  '儿科 病例样例（SOAP+循证）.pdf',
  'diagnosis_treatment',
  'free_chat',
  1,
  1
) ON DUPLICATE KEY UPDATE
  `title` = VALUES(`title`),
  `updated_at` = CURRENT_TIMESTAMP;

INSERT INTO `case_exam_items` (`case_id`, `item_code`, `item_name`, `item_type`, `category`, `result_text`, `result_structured`, `is_key`, `is_abnormal`, `score_weight`, `display_order`)
VALUES
(1, 'blood_routine', '血常规', 'lab', '炎症指标', 'WBC 12.4×10^9/L，中性粒细胞72%。', JSON_OBJECT('WBC','12.4×10^9/L','neutrophil_percent','72%'), 0, 1, 3.00, 1),
(1, 'crp', 'CRP', 'lab', '炎症指标', 'CRP 32 mg/L。', JSON_OBJECT('CRP','32 mg/L'), 0, 1, 2.00, 2),
(1, 'chest_xray', '胸片', 'imaging', '影像学', '双下肺纹理增多，右下肺片状模糊影。', JSON_OBJECT('finding','右下肺片状模糊影'), 1, 1, 5.00, 3),
(1, 'mp_igm', '肺炎支原体抗体IgM', 'lab', '病原学', '肺炎支原体抗体IgM 弱阳性。', JSON_OBJECT('mp_igm','弱阳性'), 0, 1, 2.00, 4),
(1, 'spo2', '血氧饱和度', 'vital_sign', '生命体征', '室内空气 SpO2 94%。', JSON_OBJECT('SpO2','94%','condition','室内空气'), 1, 1, 5.00, 5)
ON DUPLICATE KEY UPDATE
  `result_text` = VALUES(`result_text`),
  `result_structured` = VALUES(`result_structured`);

INSERT INTO `knowledge_sources` (`id`, `source_code`, `source_name`, `source_type`, `authority_level`, `is_active`)
VALUES
(1, 'CAP_2019', '儿童社区获得性肺炎诊疗规范（2019年版）', 'clinical_guideline', 5, 1),
(2, 'HUMANISTIC_CARE', '卫健委人文关怀与医患沟通要求', 'humanistic_care', 4, 1),
(3, 'PED_EXAM_REQ', '儿科期末考试问诊与诊疗评分要求', 'exam_requirement', 3, 1)
ON DUPLICATE KEY UPDATE `source_name` = VALUES(`source_name`);

INSERT INTO `knowledge_documents` (`id`, `source_id`, `department_id`, `title`, `task_type`, `summary`, `is_active`)
VALUES
(1, 1, 1, '儿童社区获得性肺炎诊疗规范（2019年版）评分参考', 'diagnosis_treatment', '儿童肺炎诊断、严重程度评估和治疗原则参考。', 1),
(2, 2, 1, '儿科场景人文关怀评分参考', 'diagnosis_treatment', '儿童患者家属沟通、病情告知和健康教育评分参考。', 1),
(3, 3, 1, '儿科问诊考试评分要求', 'diagnosis_treatment', '儿科病史采集、查体、诊断依据和治疗计划评分参考。', 1)
ON DUPLICATE KEY UPDATE `summary` = VALUES(`summary`);

INSERT INTO `knowledge_chunks` (`document_id`, `department_id`, `task_type`, `chunk_text`, `keywords`, `weight`, `is_active`)
VALUES
(1, 1, 'diagnosis_treatment', '儿童支气管肺炎诊断需结合发热、咳嗽、喘息等症状，肺部湿啰音等体征，炎症指标升高以及胸部影像学新发浸润影。', JSON_ARRAY('支气管肺炎','发热','咳嗽','喘息','胸片'), 5.00, 1),
(1, 1, 'diagnosis_treatment', '儿童肺炎严重程度评估关注呼吸频率、血氧饱和度、意识状态、血压和全身情况。SpO2 94%属于需要密切观察的临界表现。', JSON_ARRAY('严重程度','SpO2','呼吸频率','血氧'), 4.50, 1),
(2, 1, 'diagnosis_treatment', '儿科沟通需面向家属解释病情、观察指标、用药注意事项、复诊指征，并回应家属焦虑。', JSON_ARRAY('人文关怀','家属沟通','健康教育'), 4.00, 1),
(3, 1, 'diagnosis_treatment', '儿科病例考核重点包括问诊完整性、儿科查体规范、关键症状识别、诊断准确性、治疗计划合理性。', JSON_ARRAY('考核','问诊完整性','治疗计划'), 4.00, 1);

INSERT INTO `prompt_templates` (`template_code`, `agent_type`, `scene`, `version_no`, `model_type`, `output_format`, `file_path`, `is_active`)
VALUES
('patient_free_chat', 'patient', 'free_chat', 'v1', 'fast', 'text', 'backend/app/prompts/patient/free_chat.md', 1),
('patient_practice', 'patient', 'practice', 'v1', 'fast', 'text', 'backend/app/prompts/patient/practice.md', 1),
('patient_novice', 'patient', 'novice', 'v1', 'fast', 'text', 'backend/app/prompts/patient/novice.md', 1),
('patient_teaching', 'patient', 'teaching', 'v1', 'fast', 'text', 'backend/app/prompts/patient/teaching.md', 1),
('scoring_default_percentage', 'scoring', 'default_percentage', 'v1', 'reason', 'json', 'backend/app/prompts/scoring/default_percentage.md', 1),
('scoring_default_five_point', 'scoring', 'default_five_point', 'v1', 'reason', 'json', 'backend/app/prompts/scoring/default_five_point.md', 1),
('scoring_pediatrics_pneumonia', 'scoring', 'pediatrics_pneumonia', 'v1', 'reason', 'json', 'backend/app/prompts/scoring/pediatrics_pneumonia.md', 1),
('report_evaluation', 'report', 'evaluation_report', 'v1', 'fast', 'json', 'backend/app/prompts/report/evaluation_report.md', 1),
('novice_hint', 'hint', 'novice', 'v1', 'fast', 'text', 'backend/app/prompts/hint/novice_hint.md', 1),
('doctor_question_polish', 'polish', 'doctor_question', 'v1', 'fast', 'text', 'backend/app/prompts/polish/doctor_question_polish.md', 1),
('guideline_search_query', 'knowledge', 'guideline_search', 'v1', 'fast', 'json', 'backend/app/prompts/knowledge/guideline_search_query.md', 1)
ON DUPLICATE KEY UPDATE `file_path` = VALUES(`file_path`);

INSERT INTO `rubric_templates` (`rubric_code`, `rubric_name`, `version_no`, `department_id`, `training_type`, `score_type`, `dimensions`, `is_active`)
VALUES
('PED_DIAG_TX_PERCENTAGE', '儿科诊疗训练百分制评分规则', 'v1', 1, 'diagnosis_treatment', 'percentage',
 JSON_ARRAY(
   JSON_OBJECT('dimension','信息获取','max_score',25,'items',JSON_ARRAY('问诊完整性','查体针对性','辅助检查')),
   JSON_OBJECT('dimension','分析推理','max_score',25,'items',JSON_ARRAY('病例归纳','诊断准确性','鉴别诊断')),
   JSON_OBJECT('dimension','处置决策','max_score',20,'items',JSON_ARRAY('检查计划','治疗方案','风险预案')),
   JSON_OBJECT('dimension','沟通人文','max_score',15,'items',JSON_ARRAY('信息告知','共情回应','共识达成')),
   JSON_OBJECT('dimension','临床整合','max_score',15,'items',JSON_ARRAY('时间管理','流程连贯','整体思维'))
 ), 1),
('PED_DIAG_TX_FIVE_POINT', '儿科诊疗训练五分制评分规则', 'v1', 1, 'diagnosis_treatment', 'five_point',
 JSON_ARRAY(
   JSON_OBJECT('dimension','综合表现','max_score',5,'conversion','percentage / 20')
 ), 1)
ON DUPLICATE KEY UPDATE `dimensions` = VALUES(`dimensions`);
