# treatment_actual — 从 fact_settlement_out 反推已做治疗
# 消费 transforms 输出表 treatment_actual_rows(transforms.project + derive)
# settlement_type 是闭集 ~45 个(DW 实测),enum_mapping 全枚举映射 PAC category
canonical: treatment

emits:
  action: treatment_completed
  subjectType: treatment
  occurredAtField: occurredAt
  kind: actual

primary:
  table: treatment_actual_rows
  key: id
  dedup_by: id   # settlement 表内多视角合一炸行兜底

field_mapping:
  externalId:           id
  patientExternalId:    patient_id
  clinicId:             organization_id
  occurredAt:           rq
  category:             category_raw           # transforms.derive 已把 settlement_type 复制到这
  subtype:              settlement_project_name
  status:               settlement_type        # 留原 settlement_type 文字作 status(parser 不强消费)

# settlement_type 全枚举(实测 distinct ~45)→ PAC category
# 维护:DW 加新 settlement_type 时跑 SQL `SELECT DISTINCT settlement_type FROM fact_settlement_out`
# 补到本表;长尾兜底 _default: '' parser 跳过
enum_mapping:
  category:
    # ── 种植(implant)
    种植手术:           implant
    种植耗材:           implant
    种植基台:           implant
    种植上部修复:       prosthodontic   # ⚠️ 注意:种植上部修复阶段算修复,不是种植
    种植体上部修复:     prosthodontic

    # ── 牙髓 / 根管(endodontic)
    根管:               endodontic
    牙髓病:             endodontic
    儿童-牙髓病:        pediatric        # 儿牙优先

    # ── 充填修复(restorative)
    充填:               restorative
    嵌体:               restorative
    龋病:               restorative
    儿童-龋病:          pediatric

    # ── 修复(prosthodontic)
    牙冠:               prosthodontic
    固定修复:           prosthodontic
    活动修复:           prosthodontic
    桩核:               prosthodontic
    儿童-牙冠:          pediatric

    # ── 牙周(periodontic)
    牙周:               periodontic

    # ── 外科(surgical)
    牙外科:             surgical
    口腔外科:           surgical
    儿童-牙外科:        pediatric

    # ── 正畸(orthodontic)
    正畸:               orthodontic
    隐形正畸:           orthodontic
    正畸矫治器:         orthodontic
    正畸保持器:         orthodontic
    正畸辅助治疗:       orthodontic
    正畸辅助附件:       orthodontic
    固定正畸:           orthodontic
    儿童-正畸保持器:    pediatric
    儿童-正畸矫治器:    pediatric
    儿童-固定正畸:      pediatric

    # ── 美学(cosmetic)
    牙齿美白:           cosmetic
    贴面:               cosmetic

    # ── 预防 / 检查(preventive)
    预防:               preventive
    保健/预防:          preventive
    检查:               preventive
    放射:               preventive
    儿童-预防:          pediatric

    # ── 儿牙
    儿科:               pediatric

    # ── 长尾杂项 → 不算治疗,丢 fact
    麻醉:               ""
    儿童-麻醉:          ""
    诊疗服务:           ""
    其它收费项目:       ""
    其他:               ""
    加急费:             ""

    _default: ""   # settlement_type 未识别 → parser 跳过(不入 fact)
