2026-05-06 16:41:19 +08:00
|
|
|
|
import { sendToUserApi } from '@/request/api/im';
|
|
|
|
|
|
|
|
|
|
|
|
/** 挂号支付后进「复诊用药确认」页时写入,与聊天内打开的 payload 分离 */
|
|
|
|
|
|
export const CLINIC_POST_REGISTER_STORAGE_KEY = '__clinic_post_register_payload';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 从 r_info 解析复诊西药列表(与 register.vue 原 sendClinicFollowUpAssistantMessage 一致)
|
2026-07-28 14:22:56 +08:00
|
|
|
|
* @returns {{ registerInfoId: string, drugsPayload: Array<{drug_id:number,name:string,quantity:number,indications?:string,indications_array?:Array}> }}
|
2026-05-06 16:41:19 +08:00
|
|
|
|
*/
|
|
|
|
|
|
export function resolveFollowUpDrugsFromRInfo(rInfo) {
|
|
|
|
|
|
const empty = { registerInfoId: '', drugsPayload: [] };
|
|
|
|
|
|
if (!rInfo || typeof rInfo !== 'object') return empty;
|
|
|
|
|
|
const infoId = rInfo.info_id;
|
|
|
|
|
|
if (!infoId) return empty;
|
|
|
|
|
|
let drugs = Array.isArray(rInfo.follow_up_drugs) ? rInfo.follow_up_drugs : [];
|
|
|
|
|
|
if (!drugs.length && rInfo.drug_ids) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const ids = typeof rInfo.drug_ids === 'string' ? JSON.parse(rInfo.drug_ids) : rInfo.drug_ids;
|
|
|
|
|
|
if (Array.isArray(ids)) {
|
|
|
|
|
|
drugs = ids.map((id) => ({ drug_id: Number(id), name: '' })).filter((d) => d.drug_id > 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
drugs = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!drugs.length) return empty;
|
|
|
|
|
|
const fallbackQty = Math.min(99, Math.max(1, Number(rInfo.follow_up_number || rInfo.number || 1) || 1));
|
|
|
|
|
|
const drugsPayload = drugs.map((d) => {
|
|
|
|
|
|
const row = Number(d.quantity ?? d.number);
|
|
|
|
|
|
const quantity =
|
|
|
|
|
|
Number.isFinite(row) && row >= 1 ? Math.min(99, row) : fallbackQty;
|
2026-07-28 14:22:56 +08:00
|
|
|
|
// 规范化适用症数组,兼容字符串 indications
|
|
|
|
|
|
let indicationsArray = Array.isArray(d.indications_array) ? d.indications_array : [];
|
|
|
|
|
|
if (!indicationsArray.length && d.indications) {
|
|
|
|
|
|
indicationsArray = String(d.indications)
|
|
|
|
|
|
.split(',')
|
|
|
|
|
|
.map((s) => s.trim())
|
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
|
.map((s) => ({ value: s, label: s }));
|
|
|
|
|
|
}
|
2026-05-06 16:41:19 +08:00
|
|
|
|
return {
|
|
|
|
|
|
drug_id: Number(d.drug_id || d.id),
|
|
|
|
|
|
name: d.name || d.drug_name || '药品',
|
|
|
|
|
|
quantity,
|
2026-07-28 14:22:56 +08:00
|
|
|
|
indications: d.indications || '',
|
|
|
|
|
|
indications_array: indicationsArray,
|
2026-05-06 16:41:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
return { registerInfoId: String(infoId), drugsPayload };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 助理号发送 type11 follow_up_drug 卡片
|
|
|
|
|
|
* @param {string} answerStatus 'pending' | 'yes' | 'no'
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function sendFollowUpDrugAssistantMessage({
|
|
|
|
|
|
roomId,
|
|
|
|
|
|
doctorId,
|
|
|
|
|
|
registerId,
|
|
|
|
|
|
registerInfoId,
|
|
|
|
|
|
drugsPayload,
|
|
|
|
|
|
question,
|
|
|
|
|
|
answerStatus,
|
2026-07-28 14:22:56 +08:00
|
|
|
|
illnessInfo,
|
|
|
|
|
|
supplement,
|
2026-07-30 07:37:29 +08:00
|
|
|
|
hasVisited,
|
2026-05-06 16:41:19 +08:00
|
|
|
|
}) {
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
flow: 'follow_up_drug',
|
|
|
|
|
|
register_info_id: registerInfoId,
|
|
|
|
|
|
register_id: registerId,
|
|
|
|
|
|
drugs: drugsPayload,
|
|
|
|
|
|
question: question || '您是否曾使用过以上药品?',
|
|
|
|
|
|
answer_status: answerStatus,
|
2026-07-28 14:22:56 +08:00
|
|
|
|
// 症状摘要给医生聊天侧展示
|
|
|
|
|
|
illness_info: illnessInfo || '',
|
|
|
|
|
|
supplement: supplement || '',
|
2026-07-30 07:37:29 +08:00
|
|
|
|
// 是否曾线下就诊(与药店就诊经历字段对齐)
|
|
|
|
|
|
has_visited: hasVisited != null && hasVisited !== '' ? String(hasVisited) : '',
|
2026-05-06 16:41:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
await sendToUserApi({
|
|
|
|
|
|
room_id: roomId,
|
|
|
|
|
|
sender_user_id: 'doctor_assistant',
|
|
|
|
|
|
receiver_user_id: `doctor-${doctorId}`,
|
|
|
|
|
|
message_type: 11,
|
|
|
|
|
|
message_content: JSON.stringify(payload),
|
|
|
|
|
|
duration: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function markFollowUpAssistSent(registerId) {
|
|
|
|
|
|
if (registerId) {
|
|
|
|
|
|
uni.setStorageSync(`followup_assist_sent_${registerId}`, '1');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function wasFollowUpAssistSent(registerId) {
|
|
|
|
|
|
return !!(registerId && uni.getStorageSync(`followup_assist_sent_${registerId}`));
|
|
|
|
|
|
}
|