# payment — FRIDAY 消费(patient_settlement 头单级,status∈{1,3})
# 消费 transforms 输出表 payment_rows(lookup settlement_modes 已附主导通道 method)
# status=3(含退费行的单)头单仍是原始消费 → 入 payment;其退费行走 refund_item.yaml,
# LTV = Σpayment − Σrefund 自然对账。
canonical: payment

emits:
  action: payment_received
  subjectType: payment
  occurredAtField: paidAt

primary:
  table: payment_rows
  key: uuid
  dedup_by: uuid

field_mapping:
  externalId:          uuid
  updatedAt:           updated_gmt_at
  createdAt:           created_gmt_at
  patientExternalId:   patient_id
  clinicId:            organization_id
  paidAt:              created_gmt_at     # 结算入库时间(jvs-dw 同款决策:billing_date 有预付失真)
  # amount = receivable_this(应收):LTV=患者带来的业务价值,非现金流(会员卡扣费单不清零)
  # FieldMapper.normalize 按 amount_unit=yuan 转 cents
  amount:              receivable_this
  method:              method             # lookup 主导支付通道(现金/微信/刷卡/医保…原样入 fact)
  doctorId:            doctor_id
  encounterExternalId: registration_id    # 关联接诊
  settlementSerialNum: settlement_serial_num   # 结算流水号(passthrough,对账用)
