# image_finding — 影像 AI 分析 → 诊断信号源(独立 subject,code_source=image_ai)
#
# 消费 sql_source.image_finding_rows(源 SQL 已 pivot + 炸牙位成长表:
#   patient_id / brand / organization_id / emr_id / rq / code(K码) / code_source / tooth / diag_external_id)
#
# 复用 diagnosis canonical + diagnosis.parser → 落 diagnosis_record fact(跟医生诊断同类型,
#   召回 scenario 自动消费)。externalId 带 |imgai| → 跟医生诊断不同 subject(不合并,保留来源)。
# 去重:不靠 subject 合并,靠召回层 (subKey, tooth) 聚类(AI cavity@16 与 医生 K02@16 → 一条召回)。
canonical: diagnosis

emits:
  action: diagnosis_recorded
  subjectType: diagnosis
  occurredAtField: occurredAt

primary:
  table: image_finding_rows
  key: diag_external_id
  dedup_by: diag_external_id   # 同 emr×code×tooth 去重(AI 多次拍片同发现)

field_mapping:
  externalId:                diag_external_id
  updatedAt:                 rq            # AI 分析日(进 source_event_id 幂等键)
  createdAt:                 rq
  patientExternalId:         patient_id
  clinicId:                  organization_id   # 患者 EMR 诊所代理(image 无诊所)
  occurredAt:                rq
  sourceEncounterExternalId: emr_id
  code:                      code          # 已是 K 码(源 SQL pivot 给定)
  codeSource:                code_source   # 'image_ai' → diagnosis.parser 显式优先
  toothPosition:             tooth

# code 已是 K 码,直通校验(parser PACDiagnosisCodeSchema 闭集)。仍给 K 大类 passthrough 防意外。
enum_mapping:
  code:
    K00: K00
    K01: K01
    K02: K02
    K03: K03
    K04: K04
    K05: K05
    K08: K08
    K09: K09
    _default: ""
