92 lines
4.0 KiB
JavaScript
92 lines
4.0 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { createPreviewSnapshot } from '../fixtures.mjs'
|
|
import { memberIdForPatient, resolvePeople } from './people.mjs'
|
|
import { resolveDeptStats } from './dept-stats.mjs'
|
|
import { resolveAppointments } from './appointments.mjs'
|
|
const snap = (d) => createPreviewSnapshot(new Date(d))
|
|
const bookings = (s, q = {}) =>
|
|
resolveAppointments('/adminapi/local.preview/appointments', q, s, memberIdForPatient).data
|
|
for (const local of ['2026-12-01T10:00:00', '2027-01-01T08:00:00', '2028-02-29T22:00:00']) {
|
|
test(`关联完整、排班容量和唯一性:${local}`, () => {
|
|
const s = snap(local),
|
|
slots = new Map(s.slots.map((v) => [v.id, v])),
|
|
occupied = new Map(),
|
|
times = new Set(),
|
|
nos = new Set()
|
|
for (const b of s.appointments) {
|
|
const sl = slots.get(b.slot_id),
|
|
d = s.doctors.find((v) => v.id === b.doctor_id),
|
|
a = s.assistants.find((v) => v.id === b.assistant_id)
|
|
assert.ok(sl && d && a && s.patients.some((v) => v.id === b.patient_id))
|
|
assert.equal(d.dept_id, a.dept_id)
|
|
assert.equal(b.dept_id, a.dept_id)
|
|
assert.equal(b.date, sl.date)
|
|
assert.equal(sl.status, 1)
|
|
assert.equal(sl.doctor_id, d.id)
|
|
assert.ok(sl.start_time <= b.time && b.time < sl.end_time)
|
|
assert.ok(!nos.has(b.booking_no))
|
|
nos.add(b.booking_no)
|
|
if (b.status !== 'canceled') {
|
|
const key = [b.patient_id, b.date, b.time].join('/')
|
|
assert.ok(!times.has(key))
|
|
times.add(key)
|
|
occupied.set(sl.id, 1 + (occupied.get(sl.id) || 0))
|
|
}
|
|
}
|
|
const min = (t) => Number(t.slice(0, 2)) * 60 + Number(t.slice(3, 5))
|
|
for (const v of s.slots) {
|
|
assert.equal(v.booked_count, occupied.get(v.id) || 0)
|
|
assert.ok(
|
|
v.booked_count <=
|
|
Math.min(
|
|
v.quota || Infinity,
|
|
(min(v.end_time) - min(v.start_time)) / v.slot_minutes
|
|
)
|
|
)
|
|
}
|
|
assert.deepEqual(
|
|
new Set(s.appointments.map((v) => v.status)),
|
|
new Set(['registered', 'completed', 'expired', 'canceled'])
|
|
)
|
|
})
|
|
}
|
|
test('三个统计周期按部门下钻;状态分布与明细精确一致', () => {
|
|
const s = snap('2026-12-01T14:30:00')
|
|
for (const time_type of ['today', 'week', 'month']) {
|
|
const stats = resolveDeptStats('/adminapi/doctor.statistics/deptLists', { time_type }, s)
|
|
.data.lists
|
|
assert.ok(stats.length)
|
|
for (const r of stats) {
|
|
const data = bookings(s, {
|
|
dept_id: r.dept_id,
|
|
start_date: r.start_date,
|
|
end_date: r.end_date
|
|
})
|
|
assert.equal(data.all, r.total_count)
|
|
for (const [k, n] of Object.entries(data.summary)) assert.equal(n, r[k + '_count'])
|
|
}
|
|
}
|
|
})
|
|
test('预约、账号、订单同人关联;按预约号检索与分页一致', () => {
|
|
const s = snap('2026-12-01T14:30:00'),
|
|
one = bookings(s).lists[0]
|
|
const person = resolvePeople('/adminapi/user.user/detail', { id: one.member_id }, s).data
|
|
assert.equal(person.patient_id, one.patient_id)
|
|
assert.equal(bookings(s, { patient_id: one.patient_id }).count, person.appointment_count)
|
|
assert.equal(person.order_count, one.patient_order_count)
|
|
assert.equal(bookings(s, { keyword: one.booking_no }).count, 1)
|
|
assert.equal(bookings(s, { keyword: '某条不存在的演示预约' }).count, 0)
|
|
const next = bookings(s, { page_no: 2 }).lists
|
|
assert.ok(next.every((b) => !bookings(s).lists.some((r) => b.id === r.id)))
|
|
assert.equal(
|
|
resolveAppointments(
|
|
'/adminapi/local.preview/appointments',
|
|
{ export: 2 },
|
|
s,
|
|
memberIdForPatient
|
|
),
|
|
null
|
|
)
|
|
})
|