2026-07-27 11:26:39 +08:00
|
|
|
|
import { computed, ref, watch } from "vue";
|
|
|
|
|
|
import { storeToRefs } from "pinia";
|
|
|
|
|
|
import { defineStore } from "pinia";
|
|
|
|
|
|
import userStore from "./user";
|
|
|
|
|
|
import { toast } from "@/utils/widget";
|
|
|
|
|
|
const orderSource = 'ALIPAY_MINI';
|
2026-07-30 16:48:56 +08:00
|
|
|
|
const hospitalId = process.env.HOSPITAL_ID;
|
2026-09-04 16:34:50 +08:00
|
|
|
|
import { getDrugMatchedDisease } from "@/utils/api";
|
2026-07-27 11:26:39 +08:00
|
|
|
|
|
|
|
|
|
|
const FeeType = ['YB', 'ZF'];
|
2026-07-30 16:48:56 +08:00
|
|
|
|
|
|
|
|
|
|
const outpatientMedType = { med_type: '11', diseType: '普通门诊', dise_codg: '', dise_name: '' };
|
|
|
|
|
|
|
2026-07-27 11:26:39 +08:00
|
|
|
|
const histories = [
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "过往病史",
|
|
|
|
|
|
prop: "pastHistory",
|
|
|
|
|
|
options: ["有", "无"],
|
|
|
|
|
|
format: (val, label) => `${val}${label}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "过敏史",
|
|
|
|
|
|
prop: "allergyHistory",
|
|
|
|
|
|
options: ["有", "无"],
|
|
|
|
|
|
format: (val, label) => `${val}${label}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "家族病史",
|
|
|
|
|
|
prop: "familyHistory",
|
|
|
|
|
|
options: ["有", "无"],
|
|
|
|
|
|
format: (val, label) => `${val}${label}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "妊娠、哺乳、备孕",
|
|
|
|
|
|
prop: "gestation",
|
|
|
|
|
|
options: ["有", "无"],
|
|
|
|
|
|
format: (val, label) => `${val === "有" ? "在" : "未在"}${label}期`,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "肝功能",
|
|
|
|
|
|
prop: "liver",
|
|
|
|
|
|
options: ["异常", "正常"],
|
|
|
|
|
|
format: (val, label) => `${label}${val}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "肾功能",
|
|
|
|
|
|
prop: "renal",
|
|
|
|
|
|
options: ["异常", "正常"],
|
|
|
|
|
|
format: (val, label) => `${label}${val}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const drugKeys = [
|
|
|
|
|
|
"_id",
|
|
|
|
|
|
"product_id",
|
|
|
|
|
|
"name",
|
|
|
|
|
|
"specification",
|
|
|
|
|
|
"manufacturer",
|
|
|
|
|
|
"unit",
|
|
|
|
|
|
"insurance_code",
|
|
|
|
|
|
"dosage",
|
|
|
|
|
|
"dosage_unit",
|
|
|
|
|
|
"quantity",
|
|
|
|
|
|
"usageName",
|
|
|
|
|
|
"usageCode",
|
|
|
|
|
|
"frequencyName",
|
|
|
|
|
|
"frequencyCode",
|
|
|
|
|
|
"memo",
|
|
|
|
|
|
"medication_proof_desc",
|
2026-08-25 13:38:40 +08:00
|
|
|
|
"dose_time_name"
|
2026-07-27 11:26:39 +08:00
|
|
|
|
];
|
|
|
|
|
|
export default defineStore("orderStore", () => {
|
2026-07-30 16:48:56 +08:00
|
|
|
|
const medTypeList = ref([]);
|
2026-07-27 11:26:39 +08:00
|
|
|
|
const { userInfo, patientList } = storeToRefs(userStore());
|
|
|
|
|
|
const regFee = ref(undefined);
|
|
|
|
|
|
const ybVisitRecord = ref(null);
|
|
|
|
|
|
const order = ref({
|
|
|
|
|
|
hospitalId,
|
|
|
|
|
|
diseases: [],
|
|
|
|
|
|
description: "",
|
|
|
|
|
|
images: [],
|
|
|
|
|
|
drugs: [],
|
|
|
|
|
|
visitRecord: null
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const inappropriateDrugs = computed(() => {
|
|
|
|
|
|
const sex = order.value.sex;
|
|
|
|
|
|
const opposingGender = sex === '男' ? 'female' : (sex === '女' ? 'male' : '');
|
|
|
|
|
|
const gender = sex === '男' ? '女' : '男';
|
|
|
|
|
|
const isAdult = Number(order.value.age) > 16;
|
|
|
|
|
|
// 性别不适应或儿童用药不适应
|
|
|
|
|
|
return order.value.drugs.map(i => {
|
|
|
|
|
|
const data = { ...i };
|
|
|
|
|
|
const genderError = opposingGender && i.suitableGender === opposingGender;
|
|
|
|
|
|
const childError = isAdult && i.suitableChild;
|
|
|
|
|
|
if (genderError && childError) {
|
|
|
|
|
|
data.errMsg = `该药品仅限${gender}性使用,且为儿童(≤16周岁)用药。`
|
|
|
|
|
|
} else if (genderError) {
|
|
|
|
|
|
data.errMsg = `该药品仅限${gender}性使用。`
|
|
|
|
|
|
} else if (childError) {
|
|
|
|
|
|
data.errMsg = `该药品仅限儿童(≤16周岁)用药。`
|
|
|
|
|
|
}
|
|
|
|
|
|
return data
|
|
|
|
|
|
}).filter(i => Boolean(i.errMsg))
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const repeatDrugs = computed(() => {
|
|
|
|
|
|
// 按 repeatTag 分组药品
|
|
|
|
|
|
const tagGroups = {};
|
|
|
|
|
|
order.value.drugs.forEach(drug => {
|
|
|
|
|
|
const repeatTags = Array.isArray(drug.repeatTag) ? drug.repeatTag : [];
|
|
|
|
|
|
repeatTags.forEach(tag => {
|
|
|
|
|
|
if (!tagGroups[tag]) tagGroups[tag] = [];
|
|
|
|
|
|
tagGroups[tag].push(drug);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 过滤出有重复的组,生成提示文本,并基于 idStr 去重
|
|
|
|
|
|
const uniqueGroups = new Map();
|
|
|
|
|
|
Object.values(tagGroups)
|
|
|
|
|
|
.filter(drugs => drugs.length > 1)
|
|
|
|
|
|
.forEach(drugs => {
|
|
|
|
|
|
const idStr = drugs.map(d => d._id).sort().join(',');
|
|
|
|
|
|
// 如果该组合已存在,跳过(去重)
|
|
|
|
|
|
if (uniqueGroups.has(idStr)) return;
|
|
|
|
|
|
|
|
|
|
|
|
const drugNames = drugs.map(d => `【${d.name}】`).join('、');
|
|
|
|
|
|
uniqueGroups.set(idStr, `${drugNames}存在重复用药`);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return Array.from(uniqueGroups.values());
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const pastHistoryStr = computed(() => {
|
|
|
|
|
|
const arr = histories.map((i) => {
|
|
|
|
|
|
if (i.options.includes(order.value[i.prop])) {
|
|
|
|
|
|
return i.format(order.value[i.prop], i.label);
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
});
|
|
|
|
|
|
const str = arr.filter((i) => i).join(",");
|
|
|
|
|
|
return str;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const formatDrugs = computed(() => {
|
|
|
|
|
|
return order.value.drugs.map((i) => {
|
|
|
|
|
|
const obj = {};
|
|
|
|
|
|
drugKeys.forEach((key) => {
|
|
|
|
|
|
obj[key] = i[key];
|
|
|
|
|
|
});
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-07-30 16:48:56 +08:00
|
|
|
|
function init({ feeType, socialno, hisArchive }) {
|
2026-07-27 11:26:39 +08:00
|
|
|
|
if (!FeeType.includes(feeType)) {
|
|
|
|
|
|
toast('不支持的费用类型');
|
|
|
|
|
|
uni.navigateBack();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-07-30 16:48:56 +08:00
|
|
|
|
if (!hisArchive || hisArchive.socialno !== socialno) {
|
|
|
|
|
|
toast('档案与就诊人不匹配');
|
|
|
|
|
|
uni.navigateBack();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const tmbxx = Array.isArray(hisArchive.tmbxx) ? hisArchive.tmbxx : [];
|
2026-09-04 16:34:50 +08:00
|
|
|
|
// const tmbxx = [
|
|
|
|
|
|
// {
|
|
|
|
|
|
// "med_type": "140201",
|
|
|
|
|
|
// "diseType": "特病",
|
|
|
|
|
|
// "dise_codg": "M01600",
|
|
|
|
|
|
// "dise_name": "糖尿病"
|
|
|
|
|
|
// },
|
|
|
|
|
|
// {
|
|
|
|
|
|
// "med_type": "140104",
|
|
|
|
|
|
// "diseType": "慢病",
|
|
|
|
|
|
// "dise_codg": "M03900",
|
|
|
|
|
|
// "dise_name": "高血压"
|
|
|
|
|
|
// }
|
|
|
|
|
|
// ]
|
2026-08-04 16:45:11 +08:00
|
|
|
|
medTypeList.value = [outpatientMedType, ...tmbxx];
|
2026-07-27 11:26:39 +08:00
|
|
|
|
const profile = patientList.value.find((i) => i.socialno === socialno);
|
|
|
|
|
|
regFee.value = 0;
|
|
|
|
|
|
order.value = {
|
|
|
|
|
|
accountId: userInfo.value.userId,
|
|
|
|
|
|
hospitalId,
|
|
|
|
|
|
diseases: [],
|
|
|
|
|
|
description: "",
|
|
|
|
|
|
images: [],
|
|
|
|
|
|
drugs: [],
|
2026-07-30 16:48:56 +08:00
|
|
|
|
patientId: hisArchive.patientId,
|
2026-07-27 11:26:39 +08:00
|
|
|
|
idCard: profile.socialno,
|
|
|
|
|
|
name: profile.name,
|
|
|
|
|
|
mobile: profile.tel,
|
2026-07-30 16:48:56 +08:00
|
|
|
|
blhno: hisArchive.blhno,
|
2026-07-27 11:26:39 +08:00
|
|
|
|
age: profile.age,
|
|
|
|
|
|
sex: profile.sex,
|
|
|
|
|
|
address: profile.address,
|
|
|
|
|
|
orderSource,
|
|
|
|
|
|
feeType,
|
2026-07-30 16:48:56 +08:00
|
|
|
|
medInfo: { ...outpatientMedType },
|
|
|
|
|
|
// consultType: ConsultTypeByFeeType[feeType],
|
2026-07-27 11:26:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
histories.forEach((item) => (order.value[item.prop] = item.options[1]));
|
|
|
|
|
|
order.value.pastHistoryStr = pastHistoryStr.value;
|
|
|
|
|
|
console.log("order init", order.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-04 16:45:11 +08:00
|
|
|
|
function restoreForEdit(record) {
|
|
|
|
|
|
if (!record || typeof record !== "object") return false;
|
|
|
|
|
|
|
|
|
|
|
|
const medInfo = record.medInfo && typeof record.medInfo === "object"
|
|
|
|
|
|
? { ...record.medInfo }
|
|
|
|
|
|
: { ...outpatientMedType };
|
|
|
|
|
|
const medTypeKey = (item) => [
|
|
|
|
|
|
item && item.med_type,
|
|
|
|
|
|
item && item.diseType,
|
|
|
|
|
|
item && item.dise_codg,
|
|
|
|
|
|
item && item.dise_name,
|
|
|
|
|
|
].join("-");
|
|
|
|
|
|
medTypeList.value = [{ ...outpatientMedType }];
|
|
|
|
|
|
if (medTypeKey(medInfo) !== medTypeKey(outpatientMedType)) {
|
|
|
|
|
|
medTypeList.value.push({ ...medInfo });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const restoredOrder = {
|
|
|
|
|
|
accountId: record.accountId || userInfo.value.userId,
|
|
|
|
|
|
hospitalId: record.hospitalId || hospitalId,
|
|
|
|
|
|
areaCode: record.areaCode || "",
|
|
|
|
|
|
diseases: Array.isArray(record.diseases) ? [...record.diseases] : [],
|
|
|
|
|
|
description: typeof record.description === "string" ? record.description : "",
|
|
|
|
|
|
images: Array.isArray(record.images) ? [...record.images] : [],
|
|
|
|
|
|
drugs: Array.isArray(record.drugs)
|
|
|
|
|
|
? record.drugs.filter((drug) => drug && typeof drug === "object").map((drug) => ({
|
|
|
|
|
|
...drug,
|
|
|
|
|
|
proofImages: Array.isArray(drug.proofImages) ? [...drug.proofImages] : drug.proofImages,
|
|
|
|
|
|
}))
|
|
|
|
|
|
: [],
|
|
|
|
|
|
patientId: record.patientId || "",
|
|
|
|
|
|
idCard: record.idCard || record.socialno || "",
|
|
|
|
|
|
name: record.name || "",
|
|
|
|
|
|
mobile: record.mobile || record.tel || "",
|
|
|
|
|
|
blhno: record.blhno || "",
|
|
|
|
|
|
age: record.age || "",
|
|
|
|
|
|
sex: record.sex || "",
|
|
|
|
|
|
address: record.address || "",
|
|
|
|
|
|
orderSource: record.orderSource || orderSource,
|
|
|
|
|
|
feeType: record.feeType || "",
|
|
|
|
|
|
consultType: record.consultType || "",
|
|
|
|
|
|
medInfo,
|
|
|
|
|
|
visitRecord: record.visitRecord && typeof record.visitRecord === "object"
|
|
|
|
|
|
? { ...record.visitRecord }
|
|
|
|
|
|
: null,
|
|
|
|
|
|
};
|
|
|
|
|
|
histories.forEach((item) => {
|
|
|
|
|
|
restoredOrder[item.prop] = item.options.includes(record[item.prop])
|
|
|
|
|
|
? record[item.prop]
|
|
|
|
|
|
: item.options[1];
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
order.value = restoredOrder;
|
|
|
|
|
|
order.value.pastHistoryStr = pastHistoryStr.value;
|
|
|
|
|
|
ybVisitRecord.value = restoredOrder.visitRecord;
|
|
|
|
|
|
const chargeFee = Number(record.chargeFee);
|
|
|
|
|
|
regFee.value = Number.isFinite(chargeFee) ? chargeFee : 0;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-27 11:26:39 +08:00
|
|
|
|
function reuse(record) {
|
|
|
|
|
|
init();
|
|
|
|
|
|
order.value.diseases = Array.isArray(record.diseases)
|
|
|
|
|
|
? record.diseases.filter((i) => typeof i === "string" && i.trim())
|
|
|
|
|
|
: [];
|
|
|
|
|
|
order.value.description =
|
|
|
|
|
|
typeof record.description === "string" ? record.description.trim() : "";
|
|
|
|
|
|
order.value.visitRecord =
|
|
|
|
|
|
typeof record.visitRecord === "object" ? record.visitRecord : null;
|
|
|
|
|
|
order.value.images = Array.isArray(record.images)
|
|
|
|
|
|
? record.images.filter((i) => typeof i === "string" && i.trim())
|
|
|
|
|
|
: [];
|
|
|
|
|
|
order.value.drugs = Array.isArray(record.drugs) ? record.drugs : [];
|
|
|
|
|
|
histories.forEach(
|
|
|
|
|
|
(item) => (order.value[item.prop] = record[item.prop] || "")
|
|
|
|
|
|
);
|
|
|
|
|
|
order.value.pastHistoryStr = pastHistoryStr.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-06 18:26:58 +08:00
|
|
|
|
async function autoFillDisease(drugIds) {
|
|
|
|
|
|
if (drugIds.length === 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const res = await getDrugMatchedDisease({ drugIds });
|
2026-09-04 16:34:50 +08:00
|
|
|
|
const diseases = res && Array.isArray(res.list) ? res.list.filter(i => typeof i === "string" && i.trim()) : [];
|
2026-08-06 18:26:58 +08:00
|
|
|
|
const newDiseases = diseases.filter(i => !order.value.diseases.includes(i));
|
|
|
|
|
|
order.value.diseases = [...order.value.diseases, ...newDiseases];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-27 11:26:39 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
pastHistoryStr,
|
|
|
|
|
|
(n) => {
|
|
|
|
|
|
order.value.pastHistoryStr = n || "";
|
|
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
watch(ybVisitRecord, n => {
|
|
|
|
|
|
if (n) {
|
2026-08-04 16:45:11 +08:00
|
|
|
|
order.value.visitRecord = { ...n }
|
2026-07-27 11:26:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
order.value.visitRecord = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
order,
|
|
|
|
|
|
init,
|
2026-08-04 16:45:11 +08:00
|
|
|
|
restoreForEdit,
|
2026-07-27 11:26:39 +08:00
|
|
|
|
ybVisitRecord,
|
2026-07-30 16:48:56 +08:00
|
|
|
|
medTypeList,
|
2026-07-27 11:26:39 +08:00
|
|
|
|
regFee,
|
|
|
|
|
|
pastHistoryStr,
|
|
|
|
|
|
histories: ref(histories),
|
|
|
|
|
|
formatDrugs,
|
|
|
|
|
|
reuse,
|
|
|
|
|
|
inappropriateDrugs,
|
|
|
|
|
|
repeatDrugs,
|
2026-08-06 18:26:58 +08:00
|
|
|
|
autoFillDisease
|
2026-07-27 11:26:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
});
|