# treatment_review — 复查 / 拆线 / 暂观 / 无治疗 等流程性事实
# 消费 transforms 输出表 treatment_review_rows(route_by_pattern 已分流)
# 全部 fact 都打 category='review'(canonical-codes 第 11 类)
canonical: treatment

emits:
  action: treatment_planned
  subjectType: treatment
  occurredAtField: occurredAt
  kind: planned   # 复查 / 暂观 都是"未来安排"语义,kind=planned

primary:
  table: treatment_review_rows
  key: treat_external_id
  dedup_by: treat_external_id

field_mapping:
  externalId:                  treat_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:                  rq
  sourceEncounterExternalId:   emr_id
  category:                    category_raw    # transforms 已固定填 _review_sentinel
  subtype:                     treat_name      # 原始动作名("常规复查"/"拆线"等)
  toothPosition:               tooth_position
  doctorId:                    user_id          # 计划医生(从 emr 父级继承)
  doctorName:                  doctor_name      # 计划医生名(快照)

enum_mapping:
  category:
    _review_sentinel: review
