# image — 影像 metadata(EMR.file_url 拆行而来,PAC 不持文件本体)
# 消费 transforms 输出表 image_rows(split_json_array file_url + derive external_id)
canonical: image

emits:
  action: image_uploaded
  subjectType: image
  occurredAtField: uploadedAt

primary:
  table: image_rows
  key: image_external_id
  dedup_by: image_external_id   # 同一影像跨 emr 行重复兜底

field_mapping:
  externalId:           image_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
  uploadedAt:           captured_at
  encounterExternalId:  registration_id
  modality:             check_name
  doctorId:             user_id            # 接诊医生(从 emr 父级继承,影像拍摄/解读医生)
  doctorName:           doctor_name

enum_mapping:
  # host check_name → PAC modality 闭集(pa/bw/pano/cbct/intraoral_photo/scan/other)
  # 真影像归对应类型;化验/表单/记录类(血常规/牙周大表/登记表…)无影像语义,归 other
  modality:
    "口内像照片":                 intraoral_photo
    "面相照":                     intraoral_photo
    "内窥镜":                     intraoral_photo
    "小牙片":                     pa
    "全景片/头颅正侧位片截图":     pano
    "全景片/侧位片/其他X线影像":   pano
    "CT影像截图":                 cbct
    "口腔扫描":                   scan
    "其他类型资料（非X影像）":     other
    "牙周大表":                   other
    "血常规":                     other
    "拔牙术前清单":               other
    "全身检查":                   other
    "凝血四项":                   other
    "术前讨论记录":               other
    "个人健康状况登记表":         other
    "分析结果":                   other
    _default:                     other
