fix: 问题修复
This commit is contained in:
parent
5fbe5d3550
commit
399432202a
@ -17,15 +17,14 @@ const rules = [
|
|||||||
{
|
{
|
||||||
key: 'phone',
|
key: 'phone',
|
||||||
validate: val => {
|
validate: val => {
|
||||||
if (typeof val === 'number') val = String(val);
|
const valStr = ['number', 'string'].includes(typeof val) ? String(val).trim() : null;
|
||||||
if (typeof val !== 'string' || val.trim() === '') {
|
if (valStr) {
|
||||||
return [false, '手机号不能为空'];
|
if (!validator.isMobile(valStr)) {
|
||||||
|
return [false, '手机号格式不正确'];
|
||||||
|
}
|
||||||
|
return [true, valStr];
|
||||||
}
|
}
|
||||||
const s = val.trim();
|
return [true, '']
|
||||||
if (!validator.isMobile(s)) {
|
|
||||||
return [false, '手机号格式不正确'];
|
|
||||||
}
|
|
||||||
return [true, s];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -482,28 +482,26 @@ async function addCorpAccount(ctx) {
|
|||||||
if (/\W/.test(accountData.mobile)) {
|
if (/\W/.test(accountData.mobile)) {
|
||||||
return { success: false, message: "登录账号不能包含特殊字符" };
|
return { success: false, message: "登录账号不能包含特殊字符" };
|
||||||
}
|
}
|
||||||
|
const orList = [
|
||||||
// 校验 phone 字段是否存在
|
{ corpId: data.corpId, mobile: data.mobile } // 账号相同
|
||||||
if (!accountData.phone || typeof accountData.phone !== 'string' || accountData.phone.trim() === '') {
|
];
|
||||||
return { success: false, message: "手机号不能为空" };
|
if (accountData.phone) {
|
||||||
|
orList.push({ corpId: data.corpId, phone: data.phone }); // 手机号相同
|
||||||
|
}
|
||||||
|
if (relatedHlwPeople) {
|
||||||
|
orList.push({ corpId: data.corpId, relatedHlwPeople }); // 关联人员相同
|
||||||
}
|
}
|
||||||
|
|
||||||
const sameMobile = { corpId: data.corpId, mobile: data.mobile }; // 账号相同
|
|
||||||
const samePhone = { corpId: data.corpId, phone: data.phone }; // 手机号相同
|
|
||||||
const sameRelatedPeople = relatedHlwPeople
|
|
||||||
? [{ corpId: data.corpId, relatedHlwPeople }]
|
|
||||||
: []; // 关联人员相同
|
|
||||||
const account = await db
|
const account = await db
|
||||||
.collection("corp-member")
|
.collection("corp-member")
|
||||||
.findOne(
|
.findOne(
|
||||||
{ $or: [sameMobile, samePhone, ...sameRelatedPeople] },
|
{ $or: orList },
|
||||||
{ projection: { mobile: 1, phone: 1, relatedHlwPeople: 1 } }
|
{ projection: { mobile: 1, phone: 1, relatedHlwPeople: 1 } }
|
||||||
);
|
);
|
||||||
if (account && account.mobile === data.mobile) {
|
if (account && account.mobile === data.mobile) {
|
||||||
return { success: false, message: "该账号已存在" };
|
return { success: false, message: "该账号已存在" };
|
||||||
} else if (account && account.phone === data.phone) {
|
} else if (account && account.phone && account.phone === data.phone) {
|
||||||
return { success: false, message: "该手机号已被使用" };
|
return { success: false, message: "该手机号已被使用" };
|
||||||
} else if (account) {
|
} else if (account && account.relatedHlwPeople && account.relatedHlwPeople === relatedHlwPeople) {
|
||||||
return { success: false, message: "该人员已关联其他账号" };
|
return { success: false, message: "该人员已关联其他账号" };
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
@ -582,28 +580,22 @@ async function editCorpAccount(ctx) {
|
|||||||
) {
|
) {
|
||||||
return { success: false, message: "登录账号不能修改" };
|
return { success: false, message: "登录账号不能修改" };
|
||||||
}
|
}
|
||||||
|
const orList = [{ corpId: data.corpId, mobile: data.mobile, _id: { $ne: record._id } }];
|
||||||
const sameMobile = { corpId: data.corpId, mobile: data.mobile }; // 账号相同
|
if (accountData.phone) {
|
||||||
const samePhone = accountData.phone ? { corpId: data.corpId, phone: accountData.phone } : null; // 手机号相同
|
orList.push({ corpId: data.corpId, phone: accountData.phone, _id: { $ne: record._id } }); // 手机号相同
|
||||||
const sameRelatedPeople =
|
}
|
||||||
typeof relatedHlwPeople == "string" && relatedHlwPeople
|
if (relatedHlwPeople) {
|
||||||
? [{ corpId: data.corpId, relatedHlwPeople }]
|
orList.push({ corpId: data.corpId, relatedHlwPeople, _id: { $ne: record._id } }); // 关联人员相同
|
||||||
: []; // 关联人员相同
|
|
||||||
|
|
||||||
const queryConditions = [sameMobile, ...sameRelatedPeople];
|
|
||||||
if (samePhone) {
|
|
||||||
queryConditions.push(samePhone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = await db.collection("corp-member").findOne(
|
const account = await db.collection("corp-member").findOne(
|
||||||
{ $or: queryConditions, _id: { $ne: record._id } }, // 排除当前账号
|
{ $or: orList },
|
||||||
{ projection: { mobile: 1, phone: 1, doctorNo: 1, workNo: 1 } }
|
{ projection: { mobile: 1, phone: 1, doctorNo: 1, workNo: 1 } }
|
||||||
);
|
);
|
||||||
if (account && account.mobile === data.mobile) {
|
if (account && account.mobile === data.mobile) {
|
||||||
return { success: false, message: "该账号已存在" };
|
return { success: false, message: "该账号已存在" };
|
||||||
} else if (account && accountData.phone && account.phone === accountData.phone) {
|
} else if (account && accountData.phone && account.phone === accountData.phone) {
|
||||||
return { success: false, message: "该手机号已被使用" };
|
return { success: false, message: "该手机号已被使用" };
|
||||||
} else if (account) {
|
} else if (account && account.relatedHlwPeople && account.relatedHlwPeople === relatedHlwPeople) {
|
||||||
return { success: false, message: "该人员已关联其他账号" };
|
return { success: false, message: "该人员已关联其他账号" };
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
|||||||
57
hlw/drug-info/applicable-diagnosis.js
Normal file
57
hlw/drug-info/applicable-diagnosis.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
const { ObjectId } = require("mongodb");
|
||||||
|
|
||||||
|
let ensureIndexesPromise = null;
|
||||||
|
|
||||||
|
async function ensureApplicableDiagnosisIndexes(db) {
|
||||||
|
if (!ensureIndexesPromise) {
|
||||||
|
ensureIndexesPromise = Promise.all([
|
||||||
|
db.collection("drug-info").createIndex({ applicableDiagnosisIds: 1 }),
|
||||||
|
db.collection("online-drug-info").createIndex({ applicableDiagnosisIds: 1 }),
|
||||||
|
]).catch((error) => {
|
||||||
|
ensureIndexesPromise = null;
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await ensureIndexesPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function validateApplicableDiagnosisIds(params, db) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(params, "applicableDiagnosisIds")) {
|
||||||
|
return { present: false, value: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawIds = params.applicableDiagnosisIds;
|
||||||
|
if (!Array.isArray(rawIds)) {
|
||||||
|
throw new Error("适应诊断格式错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqueIds = [];
|
||||||
|
const seen = new Set();
|
||||||
|
for (const rawId of rawIds) {
|
||||||
|
if (typeof rawId !== "string" || !ObjectId.isValid(rawId.trim())) {
|
||||||
|
throw new Error("适应诊断包含无效ID");
|
||||||
|
}
|
||||||
|
const id = rawId.trim();
|
||||||
|
if (!seen.has(id)) {
|
||||||
|
seen.add(id);
|
||||||
|
uniqueIds.push(new ObjectId(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uniqueIds.length) {
|
||||||
|
const diagnosisCount = await db.collection("hlw-diagnosis").countDocuments({
|
||||||
|
_id: { $in: uniqueIds },
|
||||||
|
});
|
||||||
|
if (diagnosisCount !== uniqueIds.length) {
|
||||||
|
throw new Error("部分适应诊断不存在,请重新选择");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await ensureApplicableDiagnosisIndexes(db);
|
||||||
|
return { present: true, value: uniqueIds };
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ensureApplicableDiagnosisIndexes,
|
||||||
|
validateApplicableDiagnosisIds,
|
||||||
|
};
|
||||||
@ -2,6 +2,7 @@ const dayjs = require("dayjs");
|
|||||||
const { ObjectId } = require("mongodb");
|
const { ObjectId } = require("mongodb");
|
||||||
|
|
||||||
const { getDrugList } = require('./verify');
|
const { getDrugList } = require('./verify');
|
||||||
|
const { validateApplicableDiagnosisIds } = require('./applicable-diagnosis');
|
||||||
let db = "";
|
let db = "";
|
||||||
|
|
||||||
module.exports = async (item, mongodb) => {
|
module.exports = async (item, mongodb) => {
|
||||||
@ -219,7 +220,8 @@ async function addHlwDrugInfo(ctx) {
|
|||||||
creatorId: typeof ctx.operatorId === "string" ? ctx.operatorId : "",
|
creatorId: typeof ctx.operatorId === "string" ? ctx.operatorId : "",
|
||||||
createTime: Date.now()
|
createTime: Date.now()
|
||||||
}
|
}
|
||||||
const { onSale, ...data } = params;
|
const diagnosisIds = await validateApplicableDiagnosisIds(params, db);
|
||||||
|
const { onSale, applicableDiagnosisIds, ...data } = params;
|
||||||
let newDrug = {};
|
let newDrug = {};
|
||||||
if (Object.keys(data).length) {
|
if (Object.keys(data).length) {
|
||||||
const [item] = getDrugList([data], true, peopleInfo);
|
const [item] = getDrugList([data], true, peopleInfo);
|
||||||
@ -232,6 +234,9 @@ async function addHlwDrugInfo(ctx) {
|
|||||||
if (typeof onSale === "boolean") {
|
if (typeof onSale === "boolean") {
|
||||||
newDrug.onSale = onSale;
|
newDrug.onSale = onSale;
|
||||||
}
|
}
|
||||||
|
if (diagnosisIds.present) {
|
||||||
|
newDrug.applicableDiagnosisIds = diagnosisIds.value;
|
||||||
|
}
|
||||||
newDrug.createTime = Date.now();
|
newDrug.createTime = Date.now();
|
||||||
const res = await db.collection("drug-info").insertOne(newDrug);
|
const res = await db.collection("drug-info").insertOne(newDrug);
|
||||||
return { success: true, message: "新增药品成功", id: res.insertedId }
|
return { success: true, message: "新增药品成功", id: res.insertedId }
|
||||||
@ -246,7 +251,8 @@ async function editHlwDrugInfo(ctx) {
|
|||||||
return { success: false, message: "参数错误" }
|
return { success: false, message: "参数错误" }
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const { onSale, ...data } = params;
|
const diagnosisIds = await validateApplicableDiagnosisIds(params, db);
|
||||||
|
const { onSale, applicableDiagnosisIds, ...data } = params;
|
||||||
const currentDrug = await db.collection("drug-info").findOne(
|
const currentDrug = await db.collection("drug-info").findOne(
|
||||||
{ _id: new ObjectId(id) },
|
{ _id: new ObjectId(id) },
|
||||||
{ projection: { erpId: 1, product_id: 1, product_id_str: 1 } }
|
{ projection: { erpId: 1, product_id: 1, product_id_str: 1 } }
|
||||||
@ -278,6 +284,9 @@ async function editHlwDrugInfo(ctx) {
|
|||||||
if (typeof onSale === "boolean") {
|
if (typeof onSale === "boolean") {
|
||||||
updateData.onSale = onSale;
|
updateData.onSale = onSale;
|
||||||
}
|
}
|
||||||
|
if (diagnosisIds.present) {
|
||||||
|
updateData.applicableDiagnosisIds = diagnosisIds.value;
|
||||||
|
}
|
||||||
if (Object.keys(updateData).length) {
|
if (Object.keys(updateData).length) {
|
||||||
updateData.updateTime = Date.now();
|
updateData.updateTime = Date.now();
|
||||||
const res = await db.collection("drug-info").updateOne({ _id: new ObjectId(id) }, { $set: updateData });
|
const res = await db.collection("drug-info").updateOne({ _id: new ObjectId(id) }, { $set: updateData });
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
let db = "";
|
let db = "";
|
||||||
const { ObjectId } = require("mongodb");
|
const { ObjectId } = require("mongodb");
|
||||||
const validator = require('../../utils/validator.js')
|
const validator = require('../../utils/validator.js')
|
||||||
|
const { ensureApplicableDiagnosisIndexes } = require('../drug-info/applicable-diagnosis');
|
||||||
module.exports = async (item, mongodb) => {
|
module.exports = async (item, mongodb) => {
|
||||||
db = mongodb;
|
db = mongodb;
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
@ -20,10 +21,22 @@ module.exports = async (item, mongodb) => {
|
|||||||
// 获取诊断列表
|
// 获取诊断列表
|
||||||
|
|
||||||
async function getDiagnosisList(item) {
|
async function getDiagnosisList(item) {
|
||||||
const { page, pageSize, name, code, keyword, category } = item;
|
const { name, code, keyword, category } = item;
|
||||||
try {
|
try {
|
||||||
|
const page = Number.isInteger(item.page) && item.page > 0 ? item.page : 1;
|
||||||
|
const pageSize = Number.isInteger(item.pageSize) && item.pageSize > 0 ? item.pageSize : 30;
|
||||||
// 调用mongo 数据库查询
|
// 调用mongo 数据库查询
|
||||||
let query = {};
|
let query = {};
|
||||||
|
if (Array.isArray(item.ids)) {
|
||||||
|
if (item.ids.some(id => typeof id !== 'string')) {
|
||||||
|
return { success: false, message: '诊断ID格式错误' };
|
||||||
|
}
|
||||||
|
const ids = [...new Set(item.ids.map(id => id.trim()))];
|
||||||
|
if (ids.some(id => !ObjectId.isValid(id))) {
|
||||||
|
return { success: false, message: '诊断ID格式错误' };
|
||||||
|
}
|
||||||
|
query._id = { $in: ids.map(id => new ObjectId(id)) };
|
||||||
|
}
|
||||||
if (name && typeof name === "string") {
|
if (name && typeof name === "string") {
|
||||||
query.name = new RegExp(name.trim(), "i");
|
query.name = new RegExp(name.trim(), "i");
|
||||||
}
|
}
|
||||||
@ -71,9 +84,21 @@ async function deleteHlwDiagnosis(item) {
|
|||||||
return { success: false, message: 'id不能为空' }
|
return { success: false, message: 'id不能为空' }
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (!ObjectId.isValid(id.trim())) {
|
||||||
|
return { success: false, message: '诊断ID格式错误' }
|
||||||
|
}
|
||||||
|
const diagnosisId = new ObjectId(id.trim());
|
||||||
|
await ensureApplicableDiagnosisIndexes(db);
|
||||||
|
const [hlwDrugCount, onlineDrugCount] = await Promise.all([
|
||||||
|
db.collection("drug-info").countDocuments({ applicableDiagnosisIds: diagnosisId }, { limit: 1 }),
|
||||||
|
db.collection("online-drug-info").countDocuments({ applicableDiagnosisIds: diagnosisId }, { limit: 1 }),
|
||||||
|
]);
|
||||||
|
if (hlwDrugCount > 0 || onlineDrugCount > 0) {
|
||||||
|
return { success: false, message: '该诊断已被药品引用,请先解除关联后再删除' }
|
||||||
|
}
|
||||||
// 调用mongo 数据库删除
|
// 调用mongo 数据库删除
|
||||||
const res = await db.collection("hlw-diagnosis").deleteOne({
|
const res = await db.collection("hlw-diagnosis").deleteOne({
|
||||||
_id: new ObjectId(id),
|
_id: diagnosisId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const { ObjectId } = require("mongodb");
|
const { ObjectId } = require("mongodb");
|
||||||
const { getDrugList } = require("../drug-info/verify");
|
const { getDrugList } = require("../drug-info/verify");
|
||||||
|
const { validateApplicableDiagnosisIds } = require("../drug-info/applicable-diagnosis");
|
||||||
const validator = require("../../utils/validator");
|
const validator = require("../../utils/validator");
|
||||||
|
|
||||||
exports.main = async (item, db) => {
|
exports.main = async (item, db) => {
|
||||||
@ -169,7 +170,8 @@ async function addOnlineDrugInfo(ctx, db) {
|
|||||||
typeof ctx.operatorId === "string" ? ctx.operatorId : "",
|
typeof ctx.operatorId === "string" ? ctx.operatorId : "",
|
||||||
createTime: Date.now(),
|
createTime: Date.now(),
|
||||||
};
|
};
|
||||||
const { onSale, ...data } = params;
|
const diagnosisIds = await validateApplicableDiagnosisIds(params, db);
|
||||||
|
const { onSale, applicableDiagnosisIds, ...data } = params;
|
||||||
let newDrug = {};
|
let newDrug = {};
|
||||||
if (Object.keys(data).length) {
|
if (Object.keys(data).length) {
|
||||||
if (!data.his_drug_code || !String(data.his_drug_code).trim()) {
|
if (!data.his_drug_code || !String(data.his_drug_code).trim()) {
|
||||||
@ -191,6 +193,9 @@ async function addOnlineDrugInfo(ctx, db) {
|
|||||||
if (typeof onSale === "boolean") {
|
if (typeof onSale === "boolean") {
|
||||||
newDrug.onSale = onSale;
|
newDrug.onSale = onSale;
|
||||||
}
|
}
|
||||||
|
if (diagnosisIds.present) {
|
||||||
|
newDrug.applicableDiagnosisIds = diagnosisIds.value;
|
||||||
|
}
|
||||||
newDrug.createTime = Date.now();
|
newDrug.createTime = Date.now();
|
||||||
const res = await db
|
const res = await db
|
||||||
.collection("online-drug-info")
|
.collection("online-drug-info")
|
||||||
@ -218,7 +223,8 @@ async function editOnlineDrugInfo(ctx, db) {
|
|||||||
return { success: false, message: "参数错误" };
|
return { success: false, message: "参数错误" };
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const { onSale, ...data } = params;
|
const diagnosisIds = await validateApplicableDiagnosisIds(params, db);
|
||||||
|
const { onSale, applicableDiagnosisIds, ...data } = params;
|
||||||
let updateData = {};
|
let updateData = {};
|
||||||
if (Object.keys(data).length) {
|
if (Object.keys(data).length) {
|
||||||
if ("his_drug_code" in data && !String(data.his_drug_code).trim()) {
|
if ("his_drug_code" in data && !String(data.his_drug_code).trim()) {
|
||||||
@ -246,6 +252,9 @@ async function editOnlineDrugInfo(ctx, db) {
|
|||||||
if (typeof onSale === "boolean") {
|
if (typeof onSale === "boolean") {
|
||||||
updateData.onSale = onSale;
|
updateData.onSale = onSale;
|
||||||
}
|
}
|
||||||
|
if (diagnosisIds.present) {
|
||||||
|
updateData.applicableDiagnosisIds = diagnosisIds.value;
|
||||||
|
}
|
||||||
if (Object.keys(updateData).length) {
|
if (Object.keys(updateData).length) {
|
||||||
updateData.updateTime = Date.now();
|
updateData.updateTime = Date.now();
|
||||||
const res = await db
|
const res = await db
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user