304 lines
8.9 KiB
JavaScript
304 lines
8.9 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 hospitalId = process.env.HOSPITAL_ID;
|
||
|
||
const FeeType = ['YB', 'ZF'];
|
||
|
||
const outpatientMedType = { med_type: '11', diseType: '普通门诊', dise_codg: '', dise_name: '' };
|
||
|
||
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",
|
||
];
|
||
export default defineStore("orderStore", () => {
|
||
const medTypeList = ref([]);
|
||
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, hisArchive }) {
|
||
if (!FeeType.includes(feeType)) {
|
||
toast('不支持的费用类型');
|
||
uni.navigateBack();
|
||
return;
|
||
}
|
||
if (!hisArchive || hisArchive.socialno !== socialno) {
|
||
toast('档案与就诊人不匹配');
|
||
uni.navigateBack();
|
||
return;
|
||
}
|
||
const tmbxx = Array.isArray(hisArchive.tmbxx) ? hisArchive.tmbxx : [];
|
||
medTypeList.value = [outpatientMedType, ...tmbxx];
|
||
const profile = patientList.value.find((i) => i.socialno === socialno);
|
||
regFee.value = 0;
|
||
order.value = {
|
||
accountId: userInfo.value.userId,
|
||
hospitalId,
|
||
diseases: [],
|
||
description: "",
|
||
images: [],
|
||
drugs: [],
|
||
patientId: hisArchive.patientId,
|
||
idCard: profile.socialno,
|
||
name: profile.name,
|
||
mobile: profile.tel,
|
||
blhno: hisArchive.blhno,
|
||
age: profile.age,
|
||
sex: profile.sex,
|
||
address: profile.address,
|
||
orderSource,
|
||
feeType,
|
||
medInfo: { ...outpatientMedType },
|
||
// 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 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;
|
||
}
|
||
|
||
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) {
|
||
order.value.visitRecord = { ...n }
|
||
} else {
|
||
order.value.visitRecord = null;
|
||
}
|
||
|
||
})
|
||
|
||
return {
|
||
order,
|
||
init,
|
||
restoreForEdit,
|
||
ybVisitRecord,
|
||
medTypeList,
|
||
regFee,
|
||
pastHistoryStr,
|
||
histories: ref(histories),
|
||
formatDrugs,
|
||
reuse,
|
||
inappropriateDrugs,
|
||
repeatDrugs,
|
||
};
|
||
});
|