tmp
This commit is contained in:
66
agent/escort-admin/tools/db/escort_record_query.js
Normal file
66
agent/escort-admin/tools/db/escort_record_query.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import { tool } from "@langchain/core/tools";
|
||||
import z from "zod";
|
||||
import { DBModel } from "../../../../models/index.js";
|
||||
|
||||
const escortRecordQueryTool = tool(
|
||||
async ({ patientName, mobile, status, page = 1, pageSize = 20 }) => {
|
||||
try {
|
||||
const filter = {};
|
||||
|
||||
if (patientName) {
|
||||
filter["patient.name"] = { $regex: patientName, $options: "i" };
|
||||
}
|
||||
|
||||
if (mobile) {
|
||||
filter["patient.mobile"] = mobile;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
filter.status = status;
|
||||
}
|
||||
|
||||
const skip = (page - 1) * pageSize;
|
||||
|
||||
const records = await DBModel.EscortRecord.find(filter)
|
||||
.sort({ "schedule.date": -1 })
|
||||
.skip(skip)
|
||||
.limit(pageSize)
|
||||
.lean();
|
||||
|
||||
const total = await DBModel.EscortRecord.countDocuments(filter);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: records,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "escort_record_query",
|
||||
description:
|
||||
"Query escort records from database. Supports filtering by patient name, mobile phone number, and appointment status. Returns paginated results sorted by appointment date in descending order.",
|
||||
schema: z.object({
|
||||
patientName: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Patient name for fuzzy search"),
|
||||
mobile: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Patient mobile phone number for exact match"),
|
||||
status: z
|
||||
.enum(["pending", "confirmed", "in_progress", "completed", "cancelled"])
|
||||
.optional()
|
||||
.describe(
|
||||
"Appointment status: pending (待确认), confirmed (已确认), in_progress (进行中), completed (已完成), cancelled (已取消)"
|
||||
),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
export { escortRecordQueryTool };
|
||||
109
agent/escort-admin/tools/db/escort_record_set.js
Normal file
109
agent/escort-admin/tools/db/escort_record_set.js
Normal file
@@ -0,0 +1,109 @@
|
||||
import { tool } from "@langchain/core/tools";
|
||||
import z from "zod";
|
||||
import { DBModel } from "../../../../models/index.js";
|
||||
|
||||
const escortRecordSetTool = tool(
|
||||
async ({ mobile, status, notes, payment }) => {
|
||||
try {
|
||||
if (!mobile) {
|
||||
return {
|
||||
success: false,
|
||||
error: "Mobile phone number is required as the lookup key",
|
||||
};
|
||||
}
|
||||
|
||||
const record = await DBModel.EscortRecord.findOne({ "patient.mobile": mobile });
|
||||
if (!record) {
|
||||
return {
|
||||
success: false,
|
||||
error: `No escort record found for mobile: ${mobile}`,
|
||||
};
|
||||
}
|
||||
|
||||
const update = {};
|
||||
|
||||
if (status !== undefined) {
|
||||
update.status = status;
|
||||
}
|
||||
|
||||
if (notes !== undefined) {
|
||||
if (notes.patientNote !== undefined) {
|
||||
update["notes.patientNote"] = notes.patientNote;
|
||||
}
|
||||
if (notes.escortNote !== undefined) {
|
||||
update["notes.escortNote"] = notes.escortNote;
|
||||
}
|
||||
if (notes.medicalSummary !== undefined) {
|
||||
update["notes.medicalSummary"] = notes.medicalSummary;
|
||||
}
|
||||
}
|
||||
|
||||
if (payment !== undefined) {
|
||||
if (payment.totalFee !== undefined) {
|
||||
update["payment.totalFee"] = payment.totalFee;
|
||||
}
|
||||
if (payment.paidFee !== undefined) {
|
||||
update["payment.paidFee"] = payment.paidFee;
|
||||
}
|
||||
if (payment.status !== undefined) {
|
||||
update["payment.status"] = payment.status;
|
||||
}
|
||||
}
|
||||
|
||||
update["meta.updatetime"] = Date.now();
|
||||
|
||||
const updatedRecord = await DBModel.EscortRecord.findByIdAndUpdate(
|
||||
record._id,
|
||||
{ $set: update },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: updatedRecord,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "escort_record_set",
|
||||
description:
|
||||
"Update escort record fields by patient mobile phone number. Supports updating status, notes (patientNote, escortNote, medicalSummary), and payment (totalFee, paidFee, status). Only provided fields will be updated.",
|
||||
schema: z.object({
|
||||
mobile: z
|
||||
.string()
|
||||
.describe("Patient mobile phone number used as the lookup key"),
|
||||
status: z
|
||||
.enum(["pending", "confirmed", "in_progress", "completed", "cancelled"])
|
||||
.optional()
|
||||
.describe(
|
||||
"Appointment status: pending (待确认), confirmed (已确认), in_progress (进行中), completed (已完成), cancelled (已取消)"
|
||||
),
|
||||
notes: z
|
||||
.object({
|
||||
patientNote: z.string().optional().describe("Patient remarks / special requirements"),
|
||||
escortNote: z.string().optional().describe("Escort service notes"),
|
||||
medicalSummary: z.string().optional().describe("Medical visit summary"),
|
||||
})
|
||||
.optional()
|
||||
.describe("Notes information to update"),
|
||||
payment: z
|
||||
.object({
|
||||
totalFee: z.number().optional().describe("Total service fee (RMB)"),
|
||||
paidFee: z.number().optional().describe("Amount already paid (RMB)"),
|
||||
status: z
|
||||
.enum(["unpaid", "partial", "paid", "refunded"])
|
||||
.optional()
|
||||
.describe("Payment status: unpaid, partial, paid, refunded"),
|
||||
})
|
||||
.optional()
|
||||
.describe("Payment information to update"),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
export { escortRecordSetTool };
|
||||
Reference in New Issue
Block a user