# treatment_planned — EMR.treat_plan 真治疗动作(planned)
# 消费 transforms 输出表 treatment_planned_rows(route_by_pattern 后剩下的 = 排除复查/建议)
canonical: treatment

emits:
  action: treatment_planned
  subjectType: treatment
  occurredAtField: occurredAt
  kind: planned

primary:
  table: treatment_planned_rows
  key: treat_external_id
  dedup_by: treat_external_id   # 炸行兜底:同 emr × treatName × tooth_position 因影像 JOIN 重复

field_mapping:
  externalId:                  treat_external_id
  patientExternalId:           patient_id
  clinicId:                    organization_id
  occurredAt:                  rq
  sourceEncounterExternalId:   emr_id
  category:                    category_raw    # transforms 已带 treat_name 原文,这里 enum_mapping 翻译
  subtype:                     treat_name      # 原始 treatName 留作 subtype
  toothPosition:               tooth_position

# treatName 实测 21k distinct,top 100 cover 80%。下面是按实测高频 + 临床合理拼出来的白名单。
# 长尾兜底 _default: ""(parser 见空 category 跳过该 fact,数据损失换数据质量)。
#
# 维护:跑 SQL `SELECT DISTINCT treatName, count() FROM ... GROUP BY 1 ORDER BY 2 DESC LIMIT 200`
# 看新出现的高频项,补到本表。
enum_mapping:
  category:
    # ── 牙周(periodontic)— 龈上洁治 / 牙周治疗 各种写法
    龈上洁治:                                       periodontic
    "龈上洁治。":                                    periodontic
    龈上洁治术:                                      periodontic
    "龈上洁治术。":                                  periodontic
    "龈上洁治术/预防性洁治/洁牙/洗牙":               periodontic
    龈上洁治+牙周治疗:                              periodontic
    全口龈上洁治:                                    periodontic
    全口洁治:                                        periodontic
    全口洁牙:                                        periodontic
    全口超声洁治:                                    periodontic
    全口龈上超声洁治:                                periodontic
    定期全口洁治:                                    periodontic
    "定期全口洁治\r\n":                              periodontic
    "全口洁治\r\n":                                  periodontic
    定期洁牙:                                        periodontic
    洁牙:                                            periodontic
    洁治:                                            periodontic
    "洁治。":                                        periodontic
    洗牙:                                            periodontic
    洁治 OHI:                                       periodontic
    牙周基础治疗:                                    periodontic
    牙周系统治疗:                                    periodontic
    牙周治疗:                                        periodontic
    龈下刮治:                                        periodontic
    龈下刮治术:                                      periodontic
    根面平整术:                                      periodontic

    # ── 充填修复(restorative)
    充填:                                            restorative
    充填治疗:                                        restorative
    树脂充填:                                        restorative
    光固化树脂充填:                                  restorative
    "垫底+充填":                                     restorative
    重新充填:                                        restorative
    嵌体修复:                                        restorative
    嵌体:                                            restorative
    龋齿充填:                                        restorative

    # ── 牙髓 / 根管(endodontic)
    根管治疗:                                        endodontic
    根管再治疗:                                      endodontic
    牙髓治疗:                                        endodontic
    根尖诱导成形术:                                  endodontic
    根管充填:                                        endodontic
    拔髓:                                            endodontic
    干髓术:                                          endodontic
    盖髓术:                                          endodontic
    间接盖髓:                                        endodontic
    直接盖髓:                                        endodontic
    MTA盖髓:                                         endodontic

    # ── 种植(implant)— 注意"种植上部修复"算 prostho
    种植:                                            implant
    种植手术:                                        implant
    种植体植入:                                      implant
    种植修复:                                        implant
    种植二期:                                        implant
    种植耗材:                                        implant
    种植基台:                                        implant

    # ── 修复(prostho)— 冠 / 桥 / 义齿 / 桩核
    冠修复:                                          prosthodontic
    全冠修复:                                        prosthodontic
    戴冠:                                            prosthodontic
    戴牙:                                            prosthodontic
    桩核:                                            prosthodontic
    桩核冠:                                          prosthodontic
    固定修复:                                        prosthodontic
    活动修复:                                        prosthodontic
    重新修复:                                        prosthodontic
    种植上部修复:                                    prosthodontic
    种植体上部修复:                                  prosthodontic

    # ── 外科(surgical)— 拔除
    拔除:                                            surgical
    拔除术:                                          surgical
    牙拔除术:                                        surgical
    择期拔除:                                        surgical
    阻生齿拔除术:                                    surgical
    阻生牙拔除:                                      surgical

    # ── 正畸(orthodontic)
    正畸:                                            orthodontic
    正畸治疗:                                        orthodontic
    隐形正畸:                                        orthodontic
    固定正畸:                                        orthodontic
    保持器:                                          orthodontic
    正畸保持器:                                      orthodontic
    正畸矫治器:                                      orthodontic
    正畸辅助治疗:                                    orthodontic
    粘附件:                                          orthodontic
    粘接附件:                                        orthodontic

    # ── 预防(preventive)
    涂氟:                                            preventive
    全口涂氟:                                        preventive
    窝沟封闭:                                        preventive
    OHI:                                             preventive
    "OHI，涂氟":                                     preventive
    "OHI,涂氟":                                      preventive
    口腔卫生宣教:                                    preventive
    全景片:                                          preventive
    CBCT:                                            preventive
    曲面断层:                                        preventive
    根尖片:                                          preventive

    # ── 美学(cosmetic)
    美白:                                            cosmetic
    冷光美白:                                        cosmetic
    贴面:                                            cosmetic

    # 长尾兜底:enum_mapping 未命中 → category='',parser 跳过该 fact(silently warn)
    _default: ""
