# appointment — 全部预约(含未到诊)
# 消费 transforms 输出表 appointment_all_rows(derive 拼好精确预约时刻 scheduled_at_ts)
canonical: appointment

emits:
  action: appointment_created
  subjectType: appointment
  occurredAtField: scheduledAt

primary:
  table: appointment_all_rows
  key: id

field_mapping:
  externalId:        id
  patientExternalId: patient_id
  clinicId:          organization_id
  scheduledAt:       scheduled_at_ts    # transforms 拼好的精确时刻(日期 + 起始时分)
  arrivedAt:         in_time
  # ⚠️ appointmentType 不映射 appo_type:appo_type 实际值是"复诊/初诊"(=visit_category),
  #    不是 PAC appointment_type 通用语义"预约目的"(咨询/治疗/检查/拔牙等);
  #    且"初诊/复诊"是衍生信号,PAC 自己从 encounter_record 聚合算更可信(单一源 = PAC)。
  doctorId:          appo_doc_id
  status:            appo_status
  complaintCategory:  appo_complaint_category   # 预约科目 / 就诊意向(种植/正畸/…)
  complaintText:      appo_complaint            # 预约主诉自由文本(跟 category 配对)
  durationMinutes:    appo_time_period          # 预约时长(分钟)
  cancellationReason: cancel_reason             # 取消原因(自由文本:临时有事/再约/去了其他诊所…)
  staffNotes:         appo_remark               # 预约备注(运营内部 / Layer C 备料)

# host appo_status → PAC 8 态(1:1 细分,不再把已改约/结算都塞 scheduled/arrived):
#   1=正常→scheduled(唯一有效预约)/ 2=已改约→rescheduled(历史被取代,非有效)/ 3=已取消→cancelled
#   4=到诊→arrived / 5=接诊→in_treatment / 6=结算→completed(到诊+消费完成)
#   8=walk in 变更→walk_in / 9=爽约→no_show
enum_mapping:
  status:
    "1": scheduled
    "2": rescheduled
    "3": cancelled
    "4": arrived
    "5": in_treatment
    "6": completed
    "8": walk_in
    "9": no_show
