Support original EzDent patient creation and lookup

This commit is contained in:
SantaSpeen committed 2026-11-22 21:16:21 +03:00
1 parent 56fa065b77
commit fd09b81a7c
3 files changed
+74 -16

No files matched your search

+47 -10
View File
@@ -15,6 +15,11 @@ final class WebConsoleAPI {
}
private static let admin = "Master Admin"
private static let legacyPatientFields = [
"strLastName", "strFirstName", "strMiddleName", "strGender", "strAge", "dtBirthdate",
"strEmail", "strSocialID", "strPhone", "strPhotoIDName", "dtRegisteredDateTime",
"strZipCode", "strAddress", "strMobile", "strRace", "strClassification", "strJob", "eSourceType",
]
private static let wireKey = Data(base64Encoded: "fCVpkpDy3QII1bJ0uklkvQ==")!
private static let wireIV = Data(base64Encoded: "p+O8XWH7eWQw1xifYtxx5Q==")!
private let passwordDigest = SHA256.hash(data: Data(
@@ -41,6 +46,7 @@ final class WebConsoleAPI {
("e2ds", "useraccountsbynamer2", "GET"),
("e2ds", "useraccountsfornames", "GET"),
("e2ds", "patientsbychartno", "GET"),
("e2ds", "patients", "POST"),
("e2ds", "doctors", "GET"),
("e2ds", "smartpayaccountsbyidandqueryuserid", "GET"),
("e2ds", "patientsbynumlistforrecentlyacquired", "POST"),
@@ -66,7 +72,7 @@ final class WebConsoleAPI {
func allowsNetworkAccess(_ path: [String], method: String) -> Bool {
switch (path, method) {
case (["auth", "apploginr2"], "POST"), (["auth", "applogin"], "POST"),
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"):
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"), (["e2ds", "patients"], "POST"):
return true
case (let route, "GET"):
return route.starts(with: ["e2ds", "patientsbychartno"]) || isBootstrapRead(route)
@@ -81,7 +87,7 @@ final class WebConsoleAPI {
path == ["e2ds", "doctors"]
}
func reply(path: [String], method: String, body: Data, authorization: String?, query: [URLQueryItem], store: ServerStore) -> Reply {
func reply(path: [String], method: String, body: Data, authorization: String?, query: [URLQueryItem], queryPathLast: String?, store: ServerStore) -> Reply {
if path == ["auth", "apploginr2"] || path == ["auth", "applogin"] {
return login(body)
}
@@ -91,7 +97,9 @@ final class WebConsoleAPI {
return Reply(["errorMessage": "Auth token has expired"], status: "401 Unauthorized", errorCode: -8001511)
}
let applicationBootstrap = (method == "GET" && isBootstrapRead(path))
|| (method == "POST" && path == ["e2ds", "patientsbynumlistforrecentlyacquired"])
|| (method == "GET" && path.starts(with: ["e2ds", "patientsbychartno"]))
|| (method == "POST" && (path == ["e2ds", "patientsbynumlistforrecentlyacquired"]
|| path == ["e2ds", "patients"]))
guard session.administrator || applicationBootstrap else {
return Reply(["errorMessage": "Administrator login required"],
status: "403 Forbidden", errorCode: -1013)
@@ -139,8 +147,40 @@ final class WebConsoleAPI {
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
case ("e2ds", "patients", "POST") where path.count == 2:
guard let chartNumber = input["strChartNo"] as? String,
!chartNumber.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
var fields: [String: String] = [:]
for field in Self.legacyPatientFields {
guard let raw = input[field], !(raw is NSNull) else { continue }
guard let value = raw as? String, value.utf8.count <= 4096, !value.contains("\0") else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
fields[field] = value
}
let gender = fields["strGender"]?.prefix(1).uppercased() ?? ""
guard ["", "O", "M", "F"].contains(gender) else {
return Reply(status: "400 Bad Request", errorCode: -1021)
}
fields["strGender"] = gender.isEmpty ? "O" : gender
let displayName = ["strLastName", "strFirstName", "strMiddleName"].compactMap { fields[$0] }
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }.joined(separator: " ")
do {
_ = try store.createPatient(name: displayName.isEmpty ? chartNumber : displayName,
chartNumber: chartNumber, legacyFields: fields)
return Reply()
} catch StoreError.conflict {
return Reply(errorCode: -100029)
} catch StoreError.invalid {
return Reply(status: "400 Bad Request", errorCode: -1021)
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)
}
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: " ") }
@@ -149,15 +189,12 @@ final class WebConsoleAPI {
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
var info: [String: Any] = Dictionary(uniqueKeysWithValues: Self.legacyPatientFields.map { ($0, "") })
info["strChartNo"] = patient.record.chartNumber
info["strLastName"] = patient.record.name
info["strlDoctor"] = [String]()
info["eSourceType"] = "eUnknownSourceType"
for (field, value) in patient.fields { info[field] = value }
return Reply(["patientInfo": info])
} catch {
return Reply(status: "503 Service Unavailable", errorCode: -1005)