Complete the EzDent patient creation follow-up

This commit is contained in:
SantaSpeen committed 2026-11-22 21:20:02 +03:00
1 parent fd09b81a7c
commit 3cd0fde571
1 file changed
+39 -8
+39 -8
View File
@@ -47,6 +47,9 @@ final class WebConsoleAPI {
("e2ds", "useraccountsfornames", "GET"),
("e2ds", "patientsbychartno", "GET"),
("e2ds", "patients", "POST"),
("e2ds", "patientsbychartnoforimage", "POST"),
("e2ds", "reportsbychartno", "GET"),
("e2ds", "trresultbychartno", "GET"),
("e2ds", "doctors", "GET"),
("e2ds", "smartpayaccountsbyidandqueryuserid", "GET"),
("e2ds", "patientsbynumlistforrecentlyacquired", "POST"),
@@ -72,7 +75,8 @@ final class WebConsoleAPI {
func allowsNetworkAccess(_ path: [String], method: String) -> Bool {
switch (path, method) {
case (["auth", "apploginr2"], "POST"), (["auth", "applogin"], "POST"),
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"), (["e2ds", "patients"], "POST"):
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"), (["e2ds", "patients"], "POST"),
(["e2ds", "patientsbychartnoforimage"], "POST"):
return true
case (let route, "GET"):
return route.starts(with: ["e2ds", "patientsbychartno"]) || isBootstrapRead(route)
@@ -84,6 +88,8 @@ final class WebConsoleAPI {
private func isBootstrapRead(_ path: [String]) -> Bool {
path.starts(with: ["e2ds", "useraccountsbynamer2"]) ||
path.starts(with: ["e2ds", "smartpayaccountsbyidandqueryuserid"]) ||
path.starts(with: ["e2ds", "reportsbychartno"]) ||
path.starts(with: ["e2ds", "trresultbychartno"]) ||
path == ["e2ds", "doctors"]
}
@@ -99,7 +105,7 @@ 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", "patients"] || path == ["e2ds", "patientsbychartnoforimage"]))
guard session.administrator || applicationBootstrap else {
return Reply(["errorMessage": "Administrator login required"],
status: "403 Forbidden", errorCode: -1013)
@@ -178,13 +184,29 @@ final class WebConsoleAPI {
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("e2ds", "patientsbychartnoforimage", "POST") where path.count == 2:
guard let chartNumber = input["strChartNo"] as? String, !chartNumber.isEmpty else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
do {
guard let patient = try store.patient(chartNumber: chartNumber),
try store.imageCount(patient.record.id) > 0 else {
return Reply(errorCode: -100037)
}
return Reply()
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("e2ds", "reportsbychartno", "GET"), ("e2ds", "trresultbychartno", "GET"):
guard !Self.chartNumber(query: query, path: path, last: queryPathLast).isEmpty else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
if path[1] == "reportsbychartno" {
return Reply(["vecReport": [String]()], errorCode: -100037)
}
return Reply(["errorMessage": "No such data in DB"], errorCode: -100037)
case ("e2ds", "patientsbychartno", "GET"):
let argument = query.first(where: { $0.name == "chartno" })?.value
?? (path.count == 4 && path[2] == "chartno" ? queryPathLast : nil)
// CodeIgniter receives an already decoded query value and the controller calls urldecode again.
let chartNumber = argument
.map { $0.replacingOccurrences(of: "+", with: " ") }
.flatMap { $0.removingPercentEncoding ?? $0 } ?? ""
let chartNumber = Self.chartNumber(query: query, path: path, last: queryPathLast)
do {
guard !chartNumber.isEmpty, let patient = try store.patient(chartNumber: chartNumber) else {
return Reply(["patientInfo": []], errorCode: -100037)
@@ -274,6 +296,15 @@ final class WebConsoleAPI {
}
}
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)
?? ""
// The original controller URL-decodes the value again after CodeIgniter parses it.
let normalized = value.replacingOccurrences(of: "+", with: " ")
return normalized.removingPercentEncoding ?? normalized
}
private func login(_ body: Data) -> Reply {
let now = Date()
guard now >= lockedUntil else {