Commit 7235b228 by luoqi

feat(sync/friday): 接入 appointment + encounter(到诊从预约拆,同 jvs-dw)

FRIDAY appointment_base → PAC appointment(全部预约)+ encounter(已到诊接诊事件),
与第一个宿主 jvs-dw 同款设计(一个预约源喂两张 canonical)。要点:
- status 编码两家一致(1/2/3/4/5/6/8/9);status=10=草稿(查 friday-saas
  origin/hotfix AppointmentDataCommons draft==1 实锤)→ filter 丢弃
- scheduledAt 用 appointment_date + appointment_start 经 derive 拼(datetime_str
  是区间且 14% 空,不用)
- 已到诊(status 4/5/6 且 in_time 非空)拆 appointment_encounter_rows → encounter,
  startedAt=in_time;externalId=预约 id,将来 EMR(med_emr_info.appointmentId)据此回挂
本地验证:809 appointment + 640 encounter,1449 txns/1449 facts,0 失败 0 drift;
patient timeline 正确重建「预约→到诊」就诊史。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
parent 4f228575
# 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
# encounter — 已到诊预约即接诊事件(与 jvs-dw 同款:从预约拆已到诊)
# 消费 transforms 输出表 appointment_encounter_rows(status IN 4/5/6 且 in_time 非空)
# 首版只给"到诊事件"骨架;诊断/治疗/牙位后续从 EMR(med_emr + MongoDB med_emr_info)
# 经 appointmentId 挂到本 encounter(externalId = 预约 id)。
canonical: encounter
emits:
action: doctor_encounter_started
subjectType: encounter
occurredAtField: startedAt
primary:
table: appointment_encounter_rows
key: id
field_mapping:
externalId: id # = 预约 id;EMR 侧 appointmentId 将据此回挂
patientExternalId: patient_appointment_id
clinicId: organization_id
startedAt: in_time # 到诊时刻 = 接诊开始
doctorId: doctor_user_id
createdAt: created_gmt_at
updatedAt: updated_gmt_at
# diagnoses / treatments / chiefComplaint:后续 EMR 接入再补(本表无结构化临床内容)
......@@ -30,9 +30,10 @@ timezone: Asia/Shanghai
tables:
- { table: customer_basic_info, file: customer_basic_info.csv } # 患者主档(原始)
- { table: customer_contacts, file: customer_contacts.csv } # 联系方式 1:N(原始)
- { table: appointment_base, file: appointment_base.csv } # 预约(原始,全状态)
# Layer A.5:把 1:N 联系方式归约成 patient.phone 标量(无需源侧 join)
transforms:
# ── 患者:把 1:N 联系方式归约成 patient.phone 标量(无需源侧 join)──
- kind: lookup
input: customer_basic_info
output: customer_basic_info # in-place 附加 phone 列
......@@ -48,5 +49,31 @@ transforms:
select:
phone: contacts_tel # patient.phone ← 选中候选的 contacts_tel
# ── 预约:丢草稿 → 全部预约(拼 scheduledAt)+ 已到诊拆成接诊事件(→ encounter)──
# 与 jvs-dw 同款设计:一个预约源喂两张 canonical(appointment / encounter)。
# status 编码两家一致(1正常/2改约/3取消/4到诊/5接诊/6结算/8walkin/9爽约);10=草稿丢弃。
- kind: filter
input: appointment_base
output: _appt_valid
where:
appointment_status: { in: ['1', '2', '3', '4', '5', '6', '8', '9'] } # 丢草稿 10
# 全部预约:拼精确预约时刻(appointment_datetime_str 是区间且 14% 空 → 用 date + start)
- kind: derive
input: _appt_valid
output: appointment_all_rows
fields:
scheduled_at_ts:
op: concat
parts: ['${appointment_date}', ' ', '${appointment_start}'] # "2026-07-13 15:30:00"
# 已到诊(4/5/6)且有到诊时刻 → 接诊事件(startedAt = in_time)
- kind: filter
input: _appt_valid
output: appointment_encounter_rows
where:
appointment_status: { in: ['4', '5', '6'] }
in_time: { not_empty: true }
assemblers:
- { file: assemblers/patient.yaml }
- { file: assemblers/appointment.yaml }
- { file: assemblers/encounter.yaml }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment