diff --git a/Sources/EzServerMac/LocalServer.swift b/Sources/EzServerMac/LocalServer.swift index fdca93e..3aa42f8 100644 --- a/Sources/EzServerMac/LocalServer.swift +++ b/Sources/EzServerMac/LocalServer.swift @@ -135,7 +135,8 @@ final class LocalServer { } let reply: (Data) -> Void = { [self] body in let response = webConsole.reply(path: route, method: method, body: body, - authorization: bearer, store: library.store) + authorization: bearer, query: target.queryItems ?? [], + store: library.store) guard let json = try? JSONSerialization.data(withJSONObject: response.body) else { connection.cancel() return diff --git a/Sources/EzServerMac/ServerStore.swift b/Sources/EzServerMac/ServerStore.swift index 615320f..de5085d 100644 --- a/Sources/EzServerMac/ServerStore.swift +++ b/Sources/EzServerMac/ServerStore.swift @@ -143,6 +143,13 @@ final class ServerStore { return records } + func patient(chartNumber: String) throws -> PatientRecord? { + lock.lock() + defer { lock.unlock() } + return try query("SELECT id, name, chart_number FROM patients WHERE chart_number = ? COLLATE BINARY", + values: [.text(chartNumber)], map: { try self.patient($0) }).first + } + func patient(_ id: UUID) throws -> PatientRecord? { lock.lock() defer { lock.unlock() } diff --git a/Sources/EzServerMac/WebConsoleAPI.swift b/Sources/EzServerMac/WebConsoleAPI.swift index 350a436..9dc4c7a 100644 --- a/Sources/EzServerMac/WebConsoleAPI.swift +++ b/Sources/EzServerMac/WebConsoleAPI.swift @@ -33,6 +33,7 @@ final class WebConsoleAPI { ("auth", "applogin", "POST"), ("e2ds", "useraccountsbynamer2", "GET"), ("e2ds", "useraccountsfornames", "GET"), + ("e2ds", "patientsbychartno", "GET"), ("analytics", "eventsforsearch", "POST"), ("analytics", "eventsr2", "POST"), ("settings", "fileserversettings", "GET"), @@ -57,12 +58,14 @@ final class WebConsoleAPI { 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"]): + return true default: return false } } - func reply(path: [String], method: String, body: Data, authorization: String?, store: ServerStore) -> Reply { + 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) } @@ -78,6 +81,29 @@ final class WebConsoleAPI { return Reply(status: "404 Not Found", errorCode: -100037) } 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. + let chartNumber = argument + .map { $0.replacingOccurrences(of: "+", with: " ") } + .flatMap { $0.removingPercentEncoding ?? $0 } ?? "" + do { + guard !chartNumber.isEmpty, let patient = try store.patient(chartNumber: chartNumber) else { + return Reply(["patientInfo": []], errorCode: -100037) + } + // Imported Mac records store one display name without separate family / given names. + let emptyFields = ["strFirstName", "strMiddleName", "strGender", "strAge", "dtBirthdate", + "strEmail", "strSocialID", "strPhone", "strPhotoIDName", "dtRegisteredDateTime", + "strZipCode", "strAddress", "strMobile", "strRace", "strClassification", "strJob"] + var info: [String: Any] = Dictionary(uniqueKeysWithValues: emptyFields.map { ($0, "") }) + info["strChartNo"] = patient.chartNumber + info["strLastName"] = patient.name + info["strlDoctor"] = [String]() + info["eSourceType"] = "eUnknownSourceType" + return Reply(["patientInfo": info]) + } catch { + return Reply(status: "503 Service Unavailable", errorCode: -1005) + } case ("e2ds", "useraccountsfornames", "GET"): return Reply(["strlUserName": [Self.admin]]) case ("settings", "fileserversettings", "GET"): diff --git a/context.md b/context.md index d343592..ed54150 100644 --- a/context.md +++ b/context.md @@ -33,3 +33,5 @@ ## Следующая техническая проверка Проверен оригинальный PHP GET карточки по номеру через отдельную SQLite с таблицей `e2_pat` и оригинальной проверкой JWT с локальным ключом. См. README для параметров запуска. Следующие шаги — выдача JWT через оригинальный вход, запись и поиск карточек, перенос файловых моделей и запуск из меню приложения. Текущие маршруты Swift описаны в README. + +- Запущенный Swift-сервер обслуживает оригинальный `GET /api/v1/e2ds/patientsByChartNo?chartno=…` с JWT приложения. Чтение идёт из той же SQLite, что и `/mac/v1`. Импортированные из Mac записи хранят одно полное имя, оно выдаётся в `strLastName`. Снимки и остальные операции оригинального API требуют переноса.