# recommendation — 医生建议("建议种植"/"建议拔除"等,EMR.treat_plan 路由产物)
# 消费 transforms 输出表 recommendation_rows(route_by_pattern starts_with ['建议','推荐'] 命中)
canonical: recommendation

emits:
  action: recommendation_extracted
  subjectType: recommendation
  occurredAtField: occurredAt

primary:
  table: recommendation_rows
  key: rec_external_id
  dedup_by: rec_external_id

field_mapping:
  externalId:        rec_external_id
  # W4 末 DW upsert:updatedAt 进 source_event_id 幂等键,host UPDATE → 新 transaction(否则永久 dedup 漏 update)
  updatedAt:         updated_date
  createdAt:         created_date
  patientExternalId: patient_id
  clinicId:          organization_id
  occurredAt:        created_date          # 精确就诊时刻(rq 只到日);created_date=医生写建议的时点,100% 同 rq 日
  code:              treat_name             # "建议种植" 等 → enum_mapping 翻译到 PAC 推荐码
  name:              treat_name             # 医生原文(无 enum,原样)— 病历忠实展示;长尾建议靠它
  sourceEncounterExternalId: emr_id         # 同次接诊病历 id — 病历快读按接诊匹配
  toothPosition:     tooth_position
  doctorId:          user_id                # 建议医生(从 emr 父级继承)
  doctorName:        doctor_name            # 建议医生名(快照)

# treat_name 自由文本,enum_mapping cover 高频"建议 XX"白名单
# 长尾 _default: '' parser 跳过(不入 recommendation_record fact)
enum_mapping:
  code:
    # ── 种植 ──
    建议种植:           IMPLANT_RECOMMENDED
    建议种植修复:       IMPLANT_RECOMMENDED
    推荐种植:           IMPLANT_RECOMMENDED
    建议种植治疗:       IMPLANT_RECOMMENDED
    建议种植牙:         IMPLANT_RECOMMENDED

    # ── 戴冠 / 修复 ──
    建议戴冠:           CROWN_RECOMMENDED
    建议冠修复:         CROWN_RECOMMENDED
    建议全冠:           CROWN_RECOMMENDED
    建议桩核冠:         CROWN_RECOMMENDED
    建议做冠:           CROWN_RECOMMENDED
    推荐冠修复:         CROWN_RECOMMENDED

    # ── 充填 ──
    建议充填:           FILLING_RECOMMENDED
    "建议充填。":        FILLING_RECOMMENDED
    建议树脂充填:       FILLING_RECOMMENDED
    建议补牙:           FILLING_RECOMMENDED

    # ── 牙周基础 ──
    建议洁牙:           SRP_RECOMMENDED
    建议龈上洁治:       SRP_RECOMMENDED
    建议牙周治疗:       SRP_RECOMMENDED
    建议牙周基础治疗:   SRP_RECOMMENDED

    # ── 拔除 ──
    建议拔除:           EXTRACTION_RECOMMENDED
    "建议拔除。":        EXTRACTION_RECOMMENDED
    建议拔牙:           EXTRACTION_RECOMMENDED
    推荐拔除:           EXTRACTION_RECOMMENDED

    # ── 复查 ──
    建议年度复查:       ANNUAL_REVIEW_RECOMMENDED
    建议定期复查:       ANNUAL_REVIEW_RECOMMENDED
    建议复查:           ANNUAL_REVIEW_RECOMMENDED

    # ── 正畸咨询 ──
    建议正畸咨询:       ORTHO_CONSULT_RECOMMENDED
    建议正畸:           ORTHO_CONSULT_RECOMMENDED
    建议矫正:           ORTHO_CONSULT_RECOMMENDED

    _default: ""    # 未识别"建议X" → 交下面 keyword_mapping 含词兜底;再不中 → 丢弃

# ─────────────────────────────────────────────────────────
# 含词兜底 —— 精确 enum 未命中时,按序含词匹配 → 召回码。
# 治本长尾:"建议X"变体太多(建议充填治疗/建议根管治疗后冠修复/建议拔除后种植…),
# 精确白名单永远漏(谢玉兰 44 "建议充填治疗" 漏配 → null → 44 漏召)。引擎按 canonicalKey 通用。
# 顺序=优先级:高价值/主操作在前(种植>冠、根管>冠、拔除独立)。错配最坏=_default(现状),无回归。
keyword_mapping:
  code:
    - { value: IMPLANT_RECOMMENDED,             any: [种植, 植体] }
    - { value: RCT_RECOMMENDED,                 any: [根管, RCT, 牙髓] }
    - { value: EXTRACTION_RECOMMENDED,          any: [拔除, 拔牙] }
    - { value: CROWN_RECOMMENDED,               any: [冠, 桥, 桩核] }
    - { value: FILLING_RECOMMENDED,             any: [充填, 补牙, 树脂] }
    - { value: HARD_TISSUE_REPAIR_RECOMMENDED,  any: [楔状, 牙体, 嵌体, 缺损] }
    - { value: SRP_RECOMMENDED,                 any: [洁治, 洗牙, 牙周, 龈下, 刮治] }
    - { value: ORTHO_CONSULT_RECOMMENDED,       any: [正畸, 矫正, 矫治] }
    - { value: GUM_TREATMENT_RECOMMENDED,       any: [牙龈, 牙槽嵴, 系带] }
    - { value: JAW_CYST_REMOVAL_RECOMMENDED,    any: [囊肿] }
    - { value: ERUPTION_INTERVENTION_RECOMMENDED, any: [萌出, 乳牙滞留, 多生牙] }
