更新
This commit is contained in:
@@ -0,0 +1,504 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export type Permission =
|
||||
| 'view'
|
||||
| 'analyze'
|
||||
| 'draftReply'
|
||||
| 'record'
|
||||
| 'adoptAction'
|
||||
| 'completeAction'
|
||||
| 'reviewQuality'
|
||||
| 'manageKnowledge'
|
||||
export type Scenario = 'initial' | 'followup' | 'revisit'
|
||||
export type Days = 7 | 30 | 90
|
||||
export type JobStatus = 'queued' | 'running' | 'ready' | 'failed' | 'needs_reconciliation' | 'stale'
|
||||
export interface Page<T> {
|
||||
lists: T[]
|
||||
count: number
|
||||
page_no: number
|
||||
page_size: number
|
||||
}
|
||||
export interface Capabilities {
|
||||
enabled: boolean
|
||||
ready: boolean
|
||||
reason: string
|
||||
schema_ready: boolean
|
||||
permissions: Permission[]
|
||||
scenarios: Array<{ value: Scenario; label: string }>
|
||||
limits: { max_manual_chars: number; max_source_chars: number }
|
||||
}
|
||||
export interface Patient {
|
||||
diagnosis_id: number
|
||||
patient_id: number
|
||||
patient_name: string
|
||||
phone_masked?: string
|
||||
assistant_id: number
|
||||
}
|
||||
export interface Staff {
|
||||
id: number
|
||||
name: string
|
||||
is_self: boolean
|
||||
assistant?: boolean
|
||||
role_name?: string
|
||||
}
|
||||
export interface StaffCase extends Patient {
|
||||
im_messages: number | null
|
||||
manual_records: number
|
||||
last_activity_at: number
|
||||
}
|
||||
export interface StaffQuality {
|
||||
key: string
|
||||
label: string
|
||||
met: number
|
||||
missed: number
|
||||
insufficient: number
|
||||
not_applicable: number
|
||||
confirmed: number
|
||||
dismissed: number
|
||||
unreviewed: number
|
||||
}
|
||||
export interface StaffOverview {
|
||||
staff: Staff
|
||||
days: Days
|
||||
metrics: {
|
||||
assigned_cases: number
|
||||
im_messages: number | null
|
||||
manual_records: number
|
||||
analyzed_cases: number
|
||||
pending_actions: number
|
||||
overdue_actions: number
|
||||
completed_actions: number
|
||||
}
|
||||
quality: StaffQuality[]
|
||||
coverage_notes: string[]
|
||||
}
|
||||
export type TeamFilter = 'all' | 'today_pending' | 'today_done' | 'issues' | 'overdue' | 'attention'
|
||||
export type DailyStatus = 'all' | 'pending' | 'reported' | 'contacted' | 'exempt'
|
||||
export interface DailyCounts {
|
||||
required: number | null
|
||||
contacted: number | null
|
||||
reported: number | null
|
||||
pending: number | null
|
||||
outstanding: number | null
|
||||
exempt: number | null
|
||||
state: 'no_tasks' | 'pending' | 'reported' | 'done' | 'unavailable'
|
||||
}
|
||||
export interface DailyMeta {
|
||||
business_date: string
|
||||
timezone: 'Asia/Shanghai'
|
||||
as_of: number
|
||||
state: 'ready' | 'waiting' | 'partial' | 'unavailable'
|
||||
reason: string
|
||||
last_scan_at: number
|
||||
rule_label: string
|
||||
coverage: Array<{
|
||||
source: string
|
||||
status: 'available' | 'empty' | 'unavailable' | 'not_connected'
|
||||
note: string
|
||||
}>
|
||||
}
|
||||
export interface DailyPatient {
|
||||
key: string
|
||||
patient_id: number
|
||||
patient_name: string
|
||||
diagnosis_id: number
|
||||
diagnosis_ids: number[]
|
||||
status: Exclude<DailyStatus, 'all'>
|
||||
reasons: Array<{ type: 'revisit' | 'action'; label: string; due_at: number; source_id: number }>
|
||||
last_contact_at: number
|
||||
evidence: Array<{
|
||||
type: 'im' | 'revisit_contact' | 'action_completed'
|
||||
id: number
|
||||
at: number
|
||||
label: string
|
||||
}>
|
||||
exempt_reason: string
|
||||
}
|
||||
export interface StaffDailyContacts extends Page<DailyPatient> {
|
||||
staff: Staff
|
||||
daily: DailyMeta
|
||||
summary: DailyCounts
|
||||
}
|
||||
export type StaffAnalysisState =
|
||||
| 'no_sources'
|
||||
| 'pending'
|
||||
| 'queued'
|
||||
| 'running'
|
||||
| 'ready'
|
||||
| 'attention'
|
||||
export interface TeamStaff {
|
||||
staff: Staff
|
||||
today_contact: DailyCounts
|
||||
metrics: StaffOverview['metrics']
|
||||
unreviewed_issues: number
|
||||
last_analyzed_at: number
|
||||
analysis_state: StaffAnalysisState
|
||||
queued_jobs: number
|
||||
running_jobs: number
|
||||
attention_jobs: number
|
||||
}
|
||||
export type AlertStatus = 'open' | 'confirmed' | 'false_positive' | 'followed'
|
||||
export type AlertSeverity = 'high' | 'medium' | 'low'
|
||||
export interface ServiceAlert {
|
||||
id: number
|
||||
staff: Staff
|
||||
patient_id: number
|
||||
patient_name: string
|
||||
diagnosis_id: number
|
||||
channel: 'im' | 'call' | 'wecom'
|
||||
rule_code: string
|
||||
rule_label: string
|
||||
rule_version: number
|
||||
severity: AlertSeverity
|
||||
snippet: string
|
||||
status: AlertStatus
|
||||
occurred_at: number
|
||||
review_note: string
|
||||
reviewed_at: number
|
||||
}
|
||||
export interface AlertPage extends Page<ServiceAlert> {
|
||||
schema_ready: boolean
|
||||
summary: {
|
||||
open: number
|
||||
high_open: number
|
||||
im_open: number
|
||||
call_open: number
|
||||
assistant_open: number
|
||||
doctor_open: number
|
||||
}
|
||||
scan: {
|
||||
enabled: boolean
|
||||
state: 'disabled' | 'ready' | 'waiting' | 'error' | 'unavailable'
|
||||
last_scan_at: number
|
||||
reason: string
|
||||
}
|
||||
coverage: Array<{ channel: string; status: string; note: string }>
|
||||
empty_reason: string
|
||||
}
|
||||
export interface TeamOverview extends Page<TeamStaff> {
|
||||
days: 30
|
||||
daily: DailyMeta
|
||||
daily_summary: DailyCounts
|
||||
summary: {
|
||||
staff_count: number
|
||||
active_staff: number
|
||||
analyzed_cases: number
|
||||
unreviewed_issues: number
|
||||
pending_actions: number
|
||||
overdue_actions: number
|
||||
queued_jobs: number
|
||||
running_jobs: number
|
||||
attention_jobs: number
|
||||
}
|
||||
automation: {
|
||||
enabled: boolean
|
||||
state: 'disabled' | 'running' | 'waiting' | 'error'
|
||||
last_scan_at: number
|
||||
next_scan_at: number
|
||||
interval_seconds: number
|
||||
quiet_seconds: number
|
||||
days: 30
|
||||
reason: string
|
||||
}
|
||||
}
|
||||
export interface StaffIssue {
|
||||
job_id: number
|
||||
version: number
|
||||
diagnosis_id: number
|
||||
patient_name: string
|
||||
item_key: string
|
||||
label: string
|
||||
status: string
|
||||
reason: string
|
||||
decision: '' | 'confirmed'
|
||||
created_at: number
|
||||
}
|
||||
export interface Source {
|
||||
id: string
|
||||
channel: string
|
||||
text: string
|
||||
occurred_at: number
|
||||
speaker: 'patient' | 'service' | 'unknown'
|
||||
actor_admin_id: number
|
||||
quality_eligible: boolean
|
||||
}
|
||||
export interface Coverage {
|
||||
channel: string
|
||||
status: string
|
||||
count: number
|
||||
note: string
|
||||
}
|
||||
export interface Claim {
|
||||
text: string
|
||||
evidence_ids: string[]
|
||||
}
|
||||
export interface SuggestedAction extends Claim {
|
||||
key: string
|
||||
}
|
||||
export interface QualityCheck {
|
||||
key: string
|
||||
label: string
|
||||
status: 'met' | 'missed' | 'not_applicable' | 'insufficient'
|
||||
reason: string
|
||||
evidence_ids: string[]
|
||||
actor_admin_id: number
|
||||
}
|
||||
export interface AnalysisResult {
|
||||
summary: Claim[]
|
||||
needs: Claim[]
|
||||
unresolved: Claim[]
|
||||
tags: Claim[]
|
||||
suggested_actions: SuggestedAction[]
|
||||
quality_checks: QualityCheck[]
|
||||
}
|
||||
export interface ReplyResult {
|
||||
reply: string
|
||||
knowledge_refs: Array<{ id: number; version: number }>
|
||||
evidence_ids: string[]
|
||||
needs_confirmation: boolean
|
||||
reason: string
|
||||
}
|
||||
export type ReviewDecision = 'confirmed' | 'dismissed' | 'not_applicable'
|
||||
export interface Review {
|
||||
id: number
|
||||
item_key: string
|
||||
reviewer_id: number
|
||||
decision: ReviewDecision
|
||||
note: string
|
||||
created_at: number
|
||||
}
|
||||
export interface Job {
|
||||
id: number
|
||||
subject_admin_id: number
|
||||
type: 'analysis' | 'reply'
|
||||
diagnosis_id: number
|
||||
scenario: Scenario
|
||||
status: JobStatus
|
||||
version: number
|
||||
created_at: number
|
||||
updated_at: number
|
||||
error_code: string
|
||||
error_message: string
|
||||
result: AnalysisResult | ReplyResult | null
|
||||
coverage: Coverage[]
|
||||
sources: Source[]
|
||||
reviews: Review[]
|
||||
stale: boolean
|
||||
}
|
||||
export interface Context {
|
||||
subject_admin_id: number
|
||||
patient: Patient
|
||||
sources: Source[]
|
||||
coverage: Coverage[]
|
||||
source_hash: string
|
||||
scope_hash: string
|
||||
days: Days
|
||||
latest_job: Job | null
|
||||
latest_analysis_job: Job | null
|
||||
}
|
||||
export type BusinessState = 'pending' | 'in_progress' | 'completed' | 'cancelled'
|
||||
export interface ServiceAction {
|
||||
id: number
|
||||
diagnosis_id: number
|
||||
patient_name: string
|
||||
content: string
|
||||
contact_required: boolean
|
||||
due_at: number
|
||||
business_state: BusinessState
|
||||
completed_at: number
|
||||
completion_note: string
|
||||
assignee_id: number
|
||||
notification_status: string | number | null
|
||||
}
|
||||
export type KnowledgeStatus = 'draft' | 'published' | 'disabled'
|
||||
export interface Knowledge {
|
||||
id: number
|
||||
question: string
|
||||
answer: string
|
||||
category: string
|
||||
status: KnowledgeStatus
|
||||
version: number
|
||||
source_note: string
|
||||
updated_at: number
|
||||
}
|
||||
export class AssistantServiceError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly code = ''
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'AssistantServiceError'
|
||||
}
|
||||
}
|
||||
interface Envelope<T> {
|
||||
code: number
|
||||
msg?: string
|
||||
data: T
|
||||
}
|
||||
// 异步提交不能因超时自动重发,也不能被相同 URL 的另一患者请求取消。
|
||||
const options = {
|
||||
isTransformResponse: false,
|
||||
ignoreCancelToken: true,
|
||||
isOpenRetry: false,
|
||||
retryCount: 0
|
||||
}
|
||||
const base = '/tcm.assistantService/'
|
||||
function unwrap<T>(response: Envelope<T>): T {
|
||||
if (response.code !== 1) {
|
||||
const data = response.data as { code?: string; error_code?: string } | null
|
||||
throw new AssistantServiceError(
|
||||
response.msg || '请求失败,请刷新后重试',
|
||||
data?.error_code || data?.code || ''
|
||||
)
|
||||
}
|
||||
return response.data
|
||||
}
|
||||
async function get<T>(action: string, params: object = {}, signal?: AbortSignal): Promise<T> {
|
||||
return unwrap(
|
||||
await request.get<Envelope<T>>(
|
||||
{ url: base + action, params, signal, timeout: 30000 },
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
async function post<T>(action: string, data: object): Promise<T> {
|
||||
return unwrap(
|
||||
await request.post<Envelope<T>>({ url: base + action, data, timeout: 30000 }, options)
|
||||
)
|
||||
}
|
||||
type Paging = { page_no: number; page_size: number }
|
||||
type JobInput = { diagnosis_id: number; days: Days; scenario: Scenario; assistant_id?: number }
|
||||
export type StaffScope = { assistant_id: number; days: Days }
|
||||
export const assistantAlerts = (
|
||||
params: Partial<Paging> & {
|
||||
keyword?: string
|
||||
status?: AlertStatus | 'all'
|
||||
severity?: AlertSeverity | 'all'
|
||||
role?: 'all' | 'assistant' | 'doctor'
|
||||
} = {},
|
||||
signal?: AbortSignal
|
||||
) => get<AlertPage>('alerts', params, signal)
|
||||
export interface WecomDirectory {
|
||||
ready: boolean
|
||||
staff: Array<Staff & { conversations: number }>
|
||||
accounts: Array<{ external_id: string; name: string; conversations: number }>
|
||||
}
|
||||
export interface WecomConversation {
|
||||
id: string
|
||||
name: string
|
||||
conversation_type: string
|
||||
last_message_at: string
|
||||
message_count: number
|
||||
preview: string
|
||||
account: string
|
||||
}
|
||||
export interface WecomMessage {
|
||||
id: string
|
||||
sent_at: string
|
||||
direction: string
|
||||
message_type: string
|
||||
sender_name: string
|
||||
content: string
|
||||
}
|
||||
export const assistantWecomDirectory = (signal?: AbortSignal) =>
|
||||
get<WecomDirectory>('wecomDirectory', {}, signal)
|
||||
export const assistantWecomChats = (
|
||||
params: { assistant_id?: number; account?: string },
|
||||
signal?: AbortSignal
|
||||
) => get<{ conversations: WecomConversation[] }>('wecomChats', params, signal)
|
||||
export const assistantWecomMessages = (
|
||||
params: { assistant_id?: number; account?: string; conversation_id: string },
|
||||
signal?: AbortSignal
|
||||
) => get<{ messages: WecomMessage[] }>('wecomMessages', params, signal)
|
||||
export const assistantReviewAlert = (data: {
|
||||
id: number
|
||||
status: Exclude<AlertStatus, 'open'>
|
||||
note: string
|
||||
}) => post<{ id: number; status: string }>('reviewAlert', data)
|
||||
export const assistantTeamOverview = (
|
||||
params: Partial<Paging> & { keyword?: string; filter?: TeamFilter } = {},
|
||||
signal?: AbortSignal
|
||||
) => get<TeamOverview>('teamOverview', params, signal)
|
||||
export const assistantStaff = (
|
||||
params: Partial<Paging> & { keyword?: string } = {},
|
||||
signal?: AbortSignal
|
||||
) => get<Page<Staff>>('staff', params, signal)
|
||||
export const assistantStaffOverview = (params: StaffScope, signal?: AbortSignal) =>
|
||||
get<StaffOverview>('staffOverview', params, signal)
|
||||
export const assistantStaffDailyContacts = (
|
||||
params: Partial<Paging> & { assistant_id: number; status?: DailyStatus },
|
||||
signal?: AbortSignal
|
||||
) => get<StaffDailyContacts>('staffDailyContacts', params, signal)
|
||||
export const assistantStaffCases = (
|
||||
params: StaffScope & Partial<Paging> & { keyword?: string },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<StaffCase>>('staffCases', params, signal)
|
||||
export const assistantStaffIssues = (params: StaffScope & Partial<Paging>, signal?: AbortSignal) =>
|
||||
get<Page<StaffIssue>>('staffIssues', params, signal)
|
||||
export const assistantAnalyzeStaff = (
|
||||
data: StaffScope & { scenario: Scenario; diagnosis_ids: number[] }
|
||||
) => post<{ jobs: Job[]; count: number }>('analyzeStaff', data)
|
||||
export const assistantCapabilities = (signal?: AbortSignal) =>
|
||||
get<Capabilities>('capabilities', {}, signal)
|
||||
export const assistantPatients = (params: Paging & { keyword?: string }, signal?: AbortSignal) =>
|
||||
get<Page<Patient>>('patients', params, signal)
|
||||
export const assistantContext = (
|
||||
params: { diagnosis_id: number; days: Days; assistant_id?: number },
|
||||
signal?: AbortSignal
|
||||
) => get<Context>('context', params, signal)
|
||||
export const assistantRecord = (data: {
|
||||
diagnosis_id: number
|
||||
content: string
|
||||
occurred_at: number
|
||||
record_type: 'service_note' | 'verified_transcript'
|
||||
speaker_confirmed: boolean
|
||||
}) => post<{ id: number }>('record', data)
|
||||
export const assistantAnalyze = (data: JobInput) => post<Job>('analyze', data)
|
||||
export const assistantDraftReply = (data: JobInput & { question: string }) =>
|
||||
post<Job>('draftReply', data)
|
||||
export const assistantJob = (id: number, signal?: AbortSignal) => get<Job>('job', { id }, signal)
|
||||
export const assistantJobs = (
|
||||
params: Paging & { diagnosis_id?: number; status?: JobStatus; assistant_id?: number },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<Job>>('jobs', params, signal)
|
||||
export const assistantReviewQuality = (data: {
|
||||
job_id: number
|
||||
item_key: string
|
||||
decision: ReviewDecision
|
||||
note: string
|
||||
version: number
|
||||
}) => post<{ id: number }>('reviewQuality', data)
|
||||
export const assistantAdoptAction = (data: {
|
||||
job_id: number
|
||||
action_key: string
|
||||
version: number
|
||||
due_at: number
|
||||
content?: string
|
||||
contact_required?: boolean
|
||||
}) => post<{ id: number; todo_id: number }>('adoptAction', data)
|
||||
export const assistantActions = (
|
||||
params: Paging & { diagnosis_id?: number; state?: BusinessState; assistant_id?: number },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<ServiceAction>>('actions', params, signal)
|
||||
export const assistantCompleteAction = (data: {
|
||||
id: number
|
||||
state: Exclude<BusinessState, 'pending'>
|
||||
note: string
|
||||
}) => post<{ id: number }>('completeAction', data)
|
||||
export const assistantKnowledge = (
|
||||
params: Paging & { keyword?: string; status?: KnowledgeStatus },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<Knowledge>>('knowledge', params, signal)
|
||||
export const assistantSaveKnowledge = (data: {
|
||||
id?: number
|
||||
version?: number
|
||||
question: string
|
||||
answer: string
|
||||
category: string
|
||||
source_note: string
|
||||
}) => post<{ id: number; version: number }>('saveKnowledge', data)
|
||||
export const assistantPublishKnowledge = (data: {
|
||||
id: number
|
||||
version: number
|
||||
status: 'published' | 'disabled'
|
||||
}) => post<{ id: number; version: number }>('publishKnowledge', data)
|
||||
Reference in New Issue
Block a user