Serve image lists and DICOM study UID lookup for EzDent

This commit is contained in:
SantaSpeen committed 2026-11-22 21:25:51 +03:00
1 parent 3cd0fde571
commit 9487744f33
3 files changed
+156 -2

No files matched your search

+62 -2
View File
@@ -47,6 +47,9 @@ final class WebConsoleAPI {
("e2ds", "useraccountsfornames", "GET"),
("e2ds", "patientsbychartno", "GET"),
("e2ds", "patients", "POST"),
("e2ds", "imagesbychartno", "POST"),
("e2ds", "imagesbystudyuid", "GET"),
("fs", "sysfilesnoconversionbytypeandpath", "GET"),
("e2ds", "patientsbychartnoforimage", "POST"),
("e2ds", "reportsbychartno", "GET"),
("e2ds", "trresultbychartno", "GET"),
@@ -76,7 +79,7 @@ final class WebConsoleAPI {
switch (path, method) {
case (["auth", "apploginr2"], "POST"), (["auth", "applogin"], "POST"),
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"), (["e2ds", "patients"], "POST"),
(["e2ds", "patientsbychartnoforimage"], "POST"):
(["e2ds", "patientsbychartnoforimage"], "POST"), (["e2ds", "imagesbychartno"], "POST"):
return true
case (let route, "GET"):
return route.starts(with: ["e2ds", "patientsbychartno"]) || isBootstrapRead(route)
@@ -86,6 +89,8 @@ final class WebConsoleAPI {
}
private func isBootstrapRead(_ path: [String]) -> Bool {
path.starts(with: ["e2ds", "imagesbystudyuid"]) ||
path.starts(with: ["fs", "sysfilesnoconversionbytypeandpath"]) ||
path.starts(with: ["e2ds", "useraccountsbynamer2"]) ||
path.starts(with: ["e2ds", "smartpayaccountsbyidandqueryuserid"]) ||
path.starts(with: ["e2ds", "reportsbychartno"]) ||
@@ -105,7 +110,8 @@ final class WebConsoleAPI {
let applicationBootstrap = (method == "GET" && isBootstrapRead(path))
|| (method == "GET" && path.starts(with: ["e2ds", "patientsbychartno"]))
|| (method == "POST" && (path == ["e2ds", "patientsbynumlistforrecentlyacquired"]
|| path == ["e2ds", "patients"] || path == ["e2ds", "patientsbychartnoforimage"]))
|| path == ["e2ds", "patients"] || path == ["e2ds", "patientsbychartnoforimage"]
|| path == ["e2ds", "imagesbychartno"]))
guard session.administrator || applicationBootstrap else {
return Reply(["errorMessage": "Administrator login required"],
status: "403 Forbidden", errorCode: -1013)
@@ -153,6 +159,33 @@ final class WebConsoleAPI {
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("e2ds", "imagesbychartno", "POST") where path.count == 2:
let page = input["pageNum"] as? Int ?? (input["pageNum"] as? String).flatMap(Int.init) ?? 0
let limit = input["numItems"] as? Int ?? (input["numItems"] as? String).flatMap(Int.init) ?? 50
guard let chart = input["strChartNo"] as? String, !chart.isEmpty,
page >= 0, (1...1000).contains(limit), page <= Int.max / limit else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
do {
return Self.imageList(try store.legacyImages(chartNumber: chart, offset: page * limit, limit: limit))
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("e2ds", "imagesbystudyuid", "GET"):
let uid = query.first(where: { $0.name == "studyuid" })?.value
?? (path.count == 4 && path[2] == "studyuid" ? queryPathLast : nil)
?? ""
guard uid.range(of: #"\A[0-9]+(?:\.[0-9]+)*\z"#, options: .regularExpression) != nil,
uid.utf8.count <= 64 else { return Reply(status: "400 Bad Request", errorCode: -1021) }
do {
return Self.imageList(try store.legacyImages(), studyUID: uid)
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("fs", "sysfilesnoconversionbytypeandpath", "GET"):
// Windows-specific templates and settings are absent from the Mac file store.
return Reply(["errorMessage": "No such file or directory exists"],
status: "400 Bad Request", errorCode: -1002)
case ("e2ds", "patients", "POST") where path.count == 2:
guard let chartNumber = input["strChartNo"] as? String,
!chartNumber.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
@@ -296,6 +329,33 @@ final class WebConsoleAPI {
}
}
private static func imageList(_ images: [ServerStore.LegacyImage], studyUID: String? = nil) -> Reply {
let formatter = ISO8601DateFormatter()
let items: [[String: Any]] = images.compactMap { image in
let metadata = LegacyDICOMMetadata(file: image.firstFile)
if let studyUID, metadata.studyUID != studyUID { return nil }
let modality: String
switch (metadata.modality, image.dicomCount ?? 0) {
case ("CT", _), ("CBCT", _), (_, 2...): modality = "eCT"
case ("PX", _): modality = "ePanorama"
case ("CR", _), ("DX", _):
modality = image.name.uppercased().hasPrefix("CEPH") ? "eCephalo" : "ePanorama"
default: modality = "eFile"
}
return [
"nImageID": image.id, "nPatID": image.patientID, "nRecordID": 0,
"strChartNo": image.chartNumber, "strImgFileName": image.name, "modality": modality,
"dtAcqTime": formatter.string(from: image.importedAt), "strStudyInstanceUID": metadata.studyUID,
"strAcqMode": "", "strRawFileName": "", "strVPanoFileName": "", "dtUpdateDateTime": "",
"strModelName": "", "strDeviceInfo": "", "strNote": "", "strDeviceSerialNumber": "",
"fKvp": 0, "fMa": 0, "fDose": 0, "fExposureTime": 0,
"bIsImported": true, "bPaidImage": true, "bIsThirdPartyGroupImage": false,
"eImageType": "eNormalDeviceImage", "eSourceType": "eUnknownSourceType",
]
}
return Reply(["vecImageInfo": items], errorCode: items.isEmpty ? -100037 : 0)
}
private static func chartNumber(query: [URLQueryItem], path: [String], last: String?) -> String {
let value = query.first(where: { $0.name == "chartno" })?.value
?? (path.count == 4 && path[2] == "chartno" ? last : nil)