2024-09-11 12:58:50 +08:00
|
|
|
import { dialog, ipcMain } from "electron";
|
|
|
|
import { filterDicoms, uploadFilesInBatches } from "./util";
|
2024-09-11 17:01:22 +08:00
|
|
|
import { selectStructuredDicom } from "../../core/pacs";
|
|
|
|
import dayjs from "dayjs";
|
2024-09-11 12:58:50 +08:00
|
|
|
|
|
|
|
export const registerDicomHandler = () => {
|
2024-09-11 17:01:22 +08:00
|
|
|
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]);
|
2024-09-11 17:01:22 +08:00
|
|
|
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
|
|
|
});
|
|
|
|
};
|