feat(api): 接入医签通业务接口与类型
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import axios from 'axios'
|
||||
|
||||
import { unwrapApiResponse } from '@/utils/api-response'
|
||||
import { request } from '@/utils/request'
|
||||
import { resendSigningSms as resendSigningSmsDelivery } from './deliveries'
|
||||
|
||||
import type {
|
||||
ApiPageResponse,
|
||||
@@ -368,22 +370,6 @@ function addHours(value: string, hours: number) {
|
||||
|
||||
export const isSigningMockEnabled = useMockData
|
||||
|
||||
function isSuccessCode(code: number | string) {
|
||||
return code === 0 || code === '0'
|
||||
}
|
||||
|
||||
function unwrapApiResponse<T>(response: ApiResponseOf<T>): T {
|
||||
if (!isSuccessCode(response.code)) {
|
||||
throw new Error(response.message || '接口请求失败')
|
||||
}
|
||||
|
||||
if (response.data === null) {
|
||||
throw new Error(response.message || '接口未返回业务数据')
|
||||
}
|
||||
|
||||
return response.data
|
||||
}
|
||||
|
||||
function isNotFoundError(error: unknown) {
|
||||
return axios.isAxiosError(error) && error.response?.status === 404
|
||||
}
|
||||
@@ -521,7 +507,8 @@ function mapSigningTask(
|
||||
return {
|
||||
id: dto.id,
|
||||
templateVersionId: dto.templateVersionId,
|
||||
campus: options.campus ?? '本部院区',
|
||||
campus: options.campusNames?.[dto.campusId] ?? options.campus ?? '本部院区',
|
||||
campusId: dto.campusId,
|
||||
patientId: dto.patientSnapshot.patientId,
|
||||
patientName: dto.patientSnapshot.name,
|
||||
sex: normalizePatientSex(dto.patientSnapshot.sex),
|
||||
@@ -532,11 +519,13 @@ function mapSigningTask(
|
||||
documentId: template?.id ?? dto.templateVersionId,
|
||||
documentName: template?.name ?? `模板版本 ${dto.templateVersionNumber}`,
|
||||
department: dto.visitSnapshot.departmentName || '未指定科室',
|
||||
departmentId: dto.departmentId,
|
||||
signerName: dto.patientSnapshot.name,
|
||||
method: normalizeSigningMethod(dto.signMethod),
|
||||
status: normalizeTaskStatus(dto.status),
|
||||
source: dto.visitSnapshot.sourceSystem || dto.patientSnapshot.sourceSystem || '—',
|
||||
expiresAt: formatApiDateTime(dto.expiredAt),
|
||||
createdAt: formatApiDateTime(dto.createdAt),
|
||||
updatedAt: formatApiDateTime(dto.updatedAt),
|
||||
rowVersion: dto.rowVersion,
|
||||
backendStatus: dto.status,
|
||||
@@ -559,7 +548,7 @@ function createTemplateFromInput(input: CreateSigningTaskInput): SigningTemplate
|
||||
}
|
||||
}
|
||||
|
||||
function toBackendTaskQuery(query: SigningTaskQuery, templates?: SigningTemplate[]) {
|
||||
function toBackendTaskQuery(query: SigningTaskQuery, options: SigningApiOptions = {}) {
|
||||
const params: Record<string, string | number> = {
|
||||
page: Math.max(query.page, 1),
|
||||
size: Math.min(Math.max(query.pageSize, 1), 200),
|
||||
@@ -592,7 +581,7 @@ function toBackendTaskQuery(query: SigningTaskQuery, templates?: SigningTemplate
|
||||
|
||||
if (query.documentId) {
|
||||
params.templateVersionId =
|
||||
findTemplate(templates, query.documentId)?.versionId ?? query.documentId
|
||||
findTemplate(options.templates, query.documentId)?.versionId ?? query.documentId
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
@@ -615,8 +604,14 @@ function toBackendTaskQuery(query: SigningTaskQuery, templates?: SigningTemplate
|
||||
params.createdTo = end.toISOString()
|
||||
}
|
||||
|
||||
// 院区、科室和就诊类型在页面中使用展示名称,不能直接当作 UUID 发送。
|
||||
// 后端会按当前登录用户的数据范围默认过滤,待院区/科室字典接入后再补充 ID 映射。
|
||||
if (query.campus && query.campus !== 'all' && options.campusId) {
|
||||
params.campusId = options.campusId
|
||||
}
|
||||
|
||||
if (query.department && options.departmentIds?.[query.department]) {
|
||||
params.departmentId = options.departmentIds[query.department]
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
@@ -675,7 +670,7 @@ export async function getSigningTasks(
|
||||
if (!useMockData) {
|
||||
const response = await request.get<ApiResponseOf<ApiPageResponse<SignTaskResponseDto>>>(
|
||||
'/v1/sign-tasks',
|
||||
{ params: toBackendTaskQuery(query, options.templates) },
|
||||
{ params: toBackendTaskQuery(query, options) },
|
||||
)
|
||||
const page = unwrapApiResponse(response)
|
||||
|
||||
@@ -853,12 +848,15 @@ export async function getSigningTemplates(
|
||||
} = {},
|
||||
): Promise<SigningTemplate[]> {
|
||||
if (!useMockData) {
|
||||
const response = await request.get<ApiResponseOf<AvailableTemplateVersionResponseDto[]>>(
|
||||
'/v1/templates/available-versions',
|
||||
{ params: query },
|
||||
)
|
||||
const response = await request.get<
|
||||
ApiResponseOf<
|
||||
AvailableTemplateVersionResponseDto[] | ApiPageResponse<AvailableTemplateVersionResponseDto>
|
||||
>
|
||||
>('/v1/templates/available-versions', { params: query })
|
||||
|
||||
return unwrapApiResponse(response).map(mapAvailableTemplate)
|
||||
const data = unwrapApiResponse(response)
|
||||
const records = Array.isArray(data) ? data : data.records
|
||||
return records.map(mapAvailableTemplate)
|
||||
}
|
||||
|
||||
return Promise.resolve(mockTemplates.map((template) => ({ ...template })))
|
||||
@@ -1033,11 +1031,7 @@ export async function resendSigningSms(
|
||||
options: SigningTaskActionOptions = {},
|
||||
): Promise<SigningTaskRecord | null> {
|
||||
if (!useMockData) {
|
||||
const response = await request.post<ApiResponseOf<SignTaskSendPreparationResponseDto>>(
|
||||
`/v1/sign-tasks/${encodeURIComponent(id)}/resend`,
|
||||
getTaskActionBody(options.expectedRowVersion),
|
||||
)
|
||||
unwrapApiResponse(response)
|
||||
await resendSigningSmsDelivery(id, options.expectedRowVersion)
|
||||
return getSigningTaskDetail(id, options)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user