在线复诊选择药品、说明主诉
This commit is contained in:
80
utils/clinicFollowUpAssistantIm.js
Normal file
80
utils/clinicFollowUpAssistantIm.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import { sendToUserApi } from '@/request/api/im';
|
||||
|
||||
/** 挂号支付后进「复诊用药确认」页时写入,与聊天内打开的 payload 分离 */
|
||||
export const CLINIC_POST_REGISTER_STORAGE_KEY = '__clinic_post_register_payload';
|
||||
|
||||
/**
|
||||
* 从 r_info 解析复诊西药列表(与 register.vue 原 sendClinicFollowUpAssistantMessage 一致)
|
||||
* @returns {{ registerInfoId: string, drugsPayload: Array<{drug_id:number,name:string,quantity:number}> }}
|
||||
*/
|
||||
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;
|
||||
return {
|
||||
drug_id: Number(d.drug_id || d.id),
|
||||
name: d.name || d.drug_name || '药品',
|
||||
quantity,
|
||||
};
|
||||
});
|
||||
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,
|
||||
}) {
|
||||
const payload = {
|
||||
flow: 'follow_up_drug',
|
||||
register_info_id: registerInfoId,
|
||||
register_id: registerId,
|
||||
drugs: drugsPayload,
|
||||
question: question || '您是否曾使用过以上药品?',
|
||||
answer_status: answerStatus,
|
||||
};
|
||||
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}`));
|
||||
}
|
||||
Reference in New Issue
Block a user