# 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_appointment_id   # 预约患者 = customer_basic_info.id
  clinicId:          organization_id
  scheduledAt:       scheduled_at_ts          # derive 拼的 "yyyy-MM-dd HH:mm:ss"
  status:            appointment_status
  doctorId:          doctor_user_id
  durationMinutes:   appointment_time_length
  arrivedAt:         in_time                  # 到诊时刻(未到诊为空)
  createdAt:         created_gmt_at
  updatedAt:         updated_gmt_at
  # appointmentType / complaintCategory:FRIDAY 主诉走 accept_complaint_id(FK 字典),首版不接

# host appointment_status → PAC 8 态(与 jvs-dw 完全同码;10=草稿已在 transforms 丢弃)
enum_mapping:
  status:
    '1': scheduled
    '2': rescheduled
    '3': cancelled
    '4': arrived
    '5': in_treatment
    '6': completed
    '8': walk_in
    '9': no_show
