Serve EzDent startup profile and recent acquisitions

This commit is contained in:
SantaSpeen committed 2026-11-22 21:10:22 +03:00
1 parent a46a111d50
commit aeefb0f7f0
2 files changed
+64 -7

No files matched your search

+52 -7
View File
@@ -41,6 +41,9 @@ final class WebConsoleAPI {
("e2ds", "useraccountsbynamer2", "GET"),
("e2ds", "useraccountsfornames", "GET"),
("e2ds", "patientsbychartno", "GET"),
("e2ds", "doctors", "GET"),
("e2ds", "smartpayaccountsbyidandqueryuserid", "GET"),
("e2ds", "patientsbynumlistforrecentlyacquired", "POST"),
("analytics", "eventsforsearch", "POST"),
("analytics", "eventsr2", "POST"),
("settings", "fileserversettings", "GET"),
@@ -63,15 +66,21 @@ final class WebConsoleAPI {
func allowsNetworkAccess(_ path: [String], method: String) -> Bool {
switch (path, method) {
case (["auth", "apploginr2"], "POST"), (["auth", "applogin"], "POST"),
(["e2ds", "useraccountsbynamer2", "name", Self.admin.lowercased()], "GET"):
return true
case (let route, "GET") where route.starts(with: ["e2ds", "patientsbychartno"]):
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"):
return true
case (let route, "GET"):
return route.starts(with: ["e2ds", "patientsbychartno"]) || isBootstrapRead(route)
default:
return false
}
}
private func isBootstrapRead(_ path: [String]) -> Bool {
path.starts(with: ["e2ds", "useraccountsbynamer2"]) ||
path.starts(with: ["e2ds", "smartpayaccountsbyidandqueryuserid"]) ||
path == ["e2ds", "doctors"]
}
func reply(path: [String], method: String, body: Data, authorization: String?, query: [URLQueryItem], store: ServerStore) -> Reply {
if path == ["auth", "apploginr2"] || path == ["auth", "applogin"] {
return login(body)
@@ -81,17 +90,53 @@ final class WebConsoleAPI {
let session = sessions[String(authorization.dropFirst(7))], session.expiry > now else {
return Reply(["errorMessage": "Auth token has expired"], status: "401 Unauthorized", errorCode: -8001511)
}
guard session.administrator else {
guard session.administrator || (method == "GET" && isBootstrapRead(path)) else {
return Reply(["errorMessage": "Administrator login required"],
status: "403 Forbidden", errorCode: -1013)
}
let input = (try? JSONSerialization.jsonObject(with: body)) as? [String: Any] ?? [:]
switch (path[0], path[1], method) {
case ("e2ds", "useraccountsbynamer2", "GET"):
guard path == ["e2ds", "useraccountsbynamer2", "name", Self.admin.lowercased()] else {
return Reply(status: "404 Not Found", errorCode: -100037)
let queryName = query.first(where: { $0.name == "name" })?.value?.lowercased()
let pathName = path.count == 4 && path[2] == "name" ? path[3] : nil
guard let name = pathName ?? queryName, !name.isEmpty else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
guard name == Self.admin.lowercased() else {
return Reply(errorCode: -100037)
}
return Reply(["accountInfo": [
"nAccountId": 1, "strAccountName": Self.admin, "strAccountPasswd": "", "strGrade": "M",
"bDataDel": true, "bDataTransfer": true, "bDataExport": true, "bDataAddModify": true,
"bPatientAddModify": true, "bUserAccountEdit": true, "bSharedContentsEdit": true,
"strAccountStatus": "eActive", "nFailedLoginCount": 0, "dtPasswordUpdated": "",
]])
case ("e2ds", "doctors", "GET"):
return Reply(["doctorNameList": [String]()], errorCode: -100037)
case ("e2ds", "smartpayaccountsbyidandqueryuserid", "GET"):
return Reply(["strUserID": "", "strPassword": ""], errorCode: -100037)
case ("e2ds", "patientsbynumlistforrecentlyacquired", "POST"):
guard let doctor = input["DoctorNameAccountTypePair"] as? [String: String],
doctor["first"] != nil, let selection = doctor["second"],
["eDoctorAccountAll", "eDoctorAccountNone", "eDoctorAccountName"].contains(selection) else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
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 page >= 0, limit > 0, limit <= 1000, page <= Int.max / limit else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
do {
let patients = selection == "eDoctorAccountName" ? []
: try store.recentlyAcquiredPatients(offset: page * limit, limit: limit)
let items = patients.map {
["strChartNo": $0.chartNumber, "strLastName": $0.name, "strFirstName": "",
"strMiddleName": "", "dtBirthdate": "", "strGender": ""]
}
return Reply(["searchedPatientList": items], errorCode: items.isEmpty ? -100037 : 0)
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
return Reply(["accountInfo": ["strAccountName": Self.admin, "strGrade": "M"]])
case ("e2ds", "patientsbychartno", "GET"):
let argument = query.first(where: { $0.name == "chartno" })?.value
// CodeIgniter receives an already decoded query value and the controller calls urldecode again.