Serve original patient chart lookup over EzDent API
This commit is contained in:
1 parent
96fb58fa4e
commit
5852266ed9
4 files changed
+38
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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() }
|
||||
|
||||
@@ -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"):
|
||||
|
||||
@@ -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 требуют переноса.
|
||||
Reference in new issue
Block a user