# emr — 电子病历自由文本(诊断 / 治疗已拆出独立 fact,本资源只装自由文本)
# 消费 transforms 输出表 emr_rows(project keep 自由文本字段,剥离 JSON)
canonical: emr

emits:
  action: emr_submitted
  subjectType: emr
  occurredAtField: submittedAt

primary:
  table: emr_rows
  key: id
  dedup_by: id   # 炸行兜底(SQL 朴素化后理论上不再炸,留作保险)

field_mapping:
  externalId:           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
  submittedAt:          rq
  encounterExternalId:  registration_id
  doctorId:             user_id           # 医生 id(与 settlement.doctor_id 同源 99.7%)
  doctorName:           doctor_name       # 接诊医生名(快照)
  # SOAP 自由文本段落(之前漏映射 → emr_record content 全 null,Layer C 无源)
  illnessDesc:          illness_desc      # 主诉 / 现病史
  preIllness:           pre_illness       # 现病史
  pastHistory:          past_hist         # 既往史
  generalCondition:     gen_cond          # 全身情况
  examFindings:         examine           # 检查所见(JSON 原文,带牙位)
  disposal:             dispose           # 处置(JSON 原文)
  doctorAdvice:         doc_order         # 医嘱
