65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"inou/lib"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
fmt.Println("Usage: reimport-dicom <dossier_id_hex>")
|
|
os.Exit(1)
|
|
}
|
|
|
|
dossierID := os.Args[1]
|
|
if err := lib.Init(); err != nil {
|
|
fmt.Printf("Init error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer lib.DBClose()
|
|
|
|
// Find all encrypted upload files
|
|
uploadDir := filepath.Join("/tank/inou", "uploads", dossierID)
|
|
files, err := os.ReadDir(uploadDir)
|
|
if err != nil {
|
|
fmt.Printf("Error reading %s: %v\n", uploadDir, err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Printf("Found %d upload files\n", len(files))
|
|
|
|
// Decrypt all to temp dir
|
|
tempDir, err := os.MkdirTemp("", "reimport-*")
|
|
if err != nil {
|
|
fmt.Printf("Error creating temp dir: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
decrypted := 0
|
|
for _, f := range files {
|
|
srcPath := filepath.Join(uploadDir, f.Name())
|
|
content, err := lib.DecryptFile(srcPath)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
outPath := filepath.Join(tempDir, f.Name())
|
|
os.WriteFile(outPath, content, 0644)
|
|
decrypted++
|
|
}
|
|
fmt.Printf("Decrypted %d files to %s\n", decrypted, tempDir)
|
|
|
|
// Run import
|
|
logFn := func(format string, args ...interface{}) {
|
|
fmt.Printf(format, args...)
|
|
}
|
|
result, err := lib.ImportDICOMFromPath(dossierID, tempDir, "", logFn)
|
|
if err != nil {
|
|
fmt.Printf("Import error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Printf("\nDone: %d studies, %d series, %d slices\n", result.Studies, result.Series, result.Slices)
|
|
}
|