cvpilot-tool/apps/desktop/electron/ipcEvent/dicom/handler.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-09-11 12:58:50 +08:00
import { dialog, ipcMain } from "electron";
import { filterDicoms, uploadFilesInBatches } from "./util";
import { selectStructuredDicom } from "../../core/pacs";
import dayjs from "dayjs";
2024-09-11 12:58:50 +08:00
export const registerDicomHandler = () => {
ipcMain.on("dicom:upload", async (event) => {
2024-09-11 12:58:50 +08:00
const dia = await dialog.showOpenDialog({ properties: ["openDirectory"] });
if (dia.canceled) return null;
const dcmPaths = await filterDicoms(dia.filePaths[0]);
uploadFilesInBatches({
filePaths: dcmPaths,
batchSize: 6,
feedback: (d) => event.reply("dicom:upload:detail", d),
});
});
ipcMain.handle("dicom:select", async () => {
const patients = await selectStructuredDicom();
const sortedPatients = [...patients]
.map((patient) => ({
...patient,
LastUpdate: dayjs(patient.LastUpdate).format("YYYY-MM-DD HH:mm:ss"), // 格式化日期
}))
.sort((a, b) => {
return (
new Date(b.LastUpdate).getTime() - new Date(a.LastUpdate).getTime()
);
});
return sortedPatients;
2024-09-11 12:58:50 +08:00
});
};