# 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)

# ── 字典分层(2026-07 重构):标准"建议X"词典在 _shared/dict;本地留 host 标点变体 ──
dict_includes:
  - ../../_shared/dict/recommendation-code.yaml

enum_mapping:
  code:
    # host 数据尾标点残留(normalize 前旧形态,保真保留)
    "建议充填。":        FILLING_RECOMMENDED
    "建议拔除。":        EXTRACTION_RECOMMENDED
    _default: ""    # 未识别"建议X" → 共享 keyword 含词兜底;再不中 → 丢弃
