import { dialog, ipcMain } from "electron"; import { filterDicoms, uploadFilesInBatches } from "./util"; import { selectStructuredDicom } from "../../core/pacs"; import dayjs from "dayjs"; export const registerDicomHandler = () => { ipcMain.on("dicom:upload", async (event) => { 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; }); };