235 lines
6.3 KiB
JavaScript
235 lines
6.3 KiB
JavaScript
|
|
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';
|
|||
|
|
|
|||
|
|
const FeeType = ['YB', 'ZF'];
|
|||
|
|
const ConsultTypeByFeeType = {
|
|||
|
|
YB: 'onlineConsult',
|
|||
|
|
ZF: 'onlineConsult',
|
|||
|
|
};
|
|||
|
|
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",
|
|||
|
|
];
|
|||
|
|
const hospitalId = 100002;
|
|||
|
|
export default defineStore("orderStore", () => {
|
|||
|
|
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;
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
function init({ feeType, socialno }) {
|
|||
|
|
if (!FeeType.includes(feeType)) {
|
|||
|
|
toast('不支持的费用类型');
|
|||
|
|
uni.navigateBack();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
const profile = patientList.value.find((i) => i.socialno === socialno);
|
|||
|
|
regFee.value = 0;
|
|||
|
|
order.value = {
|
|||
|
|
accountId: userInfo.value.userId,
|
|||
|
|
hospitalId,
|
|||
|
|
diseases: [],
|
|||
|
|
description: "",
|
|||
|
|
images: [],
|
|||
|
|
drugs: [],
|
|||
|
|
patientId: profile.patientid,
|
|||
|
|
idCard: profile.socialno,
|
|||
|
|
name: profile.name,
|
|||
|
|
mobile: profile.tel,
|
|||
|
|
blhno: profile.blhno,
|
|||
|
|
age: profile.age,
|
|||
|
|
sex: profile.sex,
|
|||
|
|
address: profile.address,
|
|||
|
|
orderSource,
|
|||
|
|
feeType,
|
|||
|
|
consultType: ConsultTypeByFeeType[feeType],
|
|||
|
|
};
|
|||
|
|
histories.forEach((item) => (order.value[item.prop] = item.options[1]));
|
|||
|
|
order.value.pastHistoryStr = pastHistoryStr.value;
|
|||
|
|
console.log("order init", order.value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
watch(
|
|||
|
|
pastHistoryStr,
|
|||
|
|
(n) => {
|
|||
|
|
order.value.pastHistoryStr = n || "";
|
|||
|
|
},
|
|||
|
|
{ immediate: true }
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
watch(ybVisitRecord, n => {
|
|||
|
|
if (n) {
|
|||
|
|
const { date, drugsStr, mdtrtId, medinsName } = n;
|
|||
|
|
order.value.visitRecord = { date, drugsStr, mdtrtId, medinsName }
|
|||
|
|
} else {
|
|||
|
|
order.value.visitRecord = null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
order,
|
|||
|
|
init,
|
|||
|
|
ybVisitRecord,
|
|||
|
|
regFee,
|
|||
|
|
pastHistoryStr,
|
|||
|
|
histories: ref(histories),
|
|||
|
|
formatDrugs,
|
|||
|
|
reuse,
|
|||
|
|
inappropriateDrugs,
|
|||
|
|
repeatDrugs,
|
|||
|
|
};
|
|||
|
|
});
|