Complete the EzDent patient creation follow-up
This commit is contained in:
1 parent
fd09b81a7c
commit
3cd0fde571
1 file changed
+39
-8
@@ -47,6 +47,9 @@ final class WebConsoleAPI {
|
|||||||
("e2ds", "useraccountsfornames", "GET"),
|
("e2ds", "useraccountsfornames", "GET"),
|
||||||
("e2ds", "patientsbychartno", "GET"),
|
("e2ds", "patientsbychartno", "GET"),
|
||||||
("e2ds", "patients", "POST"),
|
("e2ds", "patients", "POST"),
|
||||||
|
("e2ds", "patientsbychartnoforimage", "POST"),
|
||||||
|
("e2ds", "reportsbychartno", "GET"),
|
||||||
|
("e2ds", "trresultbychartno", "GET"),
|
||||||
("e2ds", "doctors", "GET"),
|
("e2ds", "doctors", "GET"),
|
||||||
("e2ds", "smartpayaccountsbyidandqueryuserid", "GET"),
|
("e2ds", "smartpayaccountsbyidandqueryuserid", "GET"),
|
||||||
("e2ds", "patientsbynumlistforrecentlyacquired", "POST"),
|
("e2ds", "patientsbynumlistforrecentlyacquired", "POST"),
|
||||||
@@ -72,7 +75,8 @@ final class WebConsoleAPI {
|
|||||||
func allowsNetworkAccess(_ path: [String], method: String) -> Bool {
|
func allowsNetworkAccess(_ path: [String], method: String) -> Bool {
|
||||||
switch (path, method) {
|
switch (path, method) {
|
||||||
case (["auth", "apploginr2"], "POST"), (["auth", "applogin"], "POST"),
|
case (["auth", "apploginr2"], "POST"), (["auth", "applogin"], "POST"),
|
||||||
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"), (["e2ds", "patients"], "POST"):
|
(["e2ds", "patientsbynumlistforrecentlyacquired"], "POST"), (["e2ds", "patients"], "POST"),
|
||||||
|
(["e2ds", "patientsbychartnoforimage"], "POST"):
|
||||||
return true
|
return true
|
||||||
case (let route, "GET"):
|
case (let route, "GET"):
|
||||||
return route.starts(with: ["e2ds", "patientsbychartno"]) || isBootstrapRead(route)
|
return route.starts(with: ["e2ds", "patientsbychartno"]) || isBootstrapRead(route)
|
||||||
@@ -84,6 +88,8 @@ final class WebConsoleAPI {
|
|||||||
private func isBootstrapRead(_ path: [String]) -> Bool {
|
private func isBootstrapRead(_ path: [String]) -> Bool {
|
||||||
path.starts(with: ["e2ds", "useraccountsbynamer2"]) ||
|
path.starts(with: ["e2ds", "useraccountsbynamer2"]) ||
|
||||||
path.starts(with: ["e2ds", "smartpayaccountsbyidandqueryuserid"]) ||
|
path.starts(with: ["e2ds", "smartpayaccountsbyidandqueryuserid"]) ||
|
||||||
|
path.starts(with: ["e2ds", "reportsbychartno"]) ||
|
||||||
|
path.starts(with: ["e2ds", "trresultbychartno"]) ||
|
||||||
path == ["e2ds", "doctors"]
|
path == ["e2ds", "doctors"]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +105,7 @@ final class WebConsoleAPI {
|
|||||||
let applicationBootstrap = (method == "GET" && isBootstrapRead(path))
|
let applicationBootstrap = (method == "GET" && isBootstrapRead(path))
|
||||||
|| (method == "GET" && path.starts(with: ["e2ds", "patientsbychartno"]))
|
|| (method == "GET" && path.starts(with: ["e2ds", "patientsbychartno"]))
|
||||||
|| (method == "POST" && (path == ["e2ds", "patientsbynumlistforrecentlyacquired"]
|
|| (method == "POST" && (path == ["e2ds", "patientsbynumlistforrecentlyacquired"]
|
||||||
|| path == ["e2ds", "patients"]))
|
|| path == ["e2ds", "patients"] || path == ["e2ds", "patientsbychartnoforimage"]))
|
||||||
guard session.administrator || applicationBootstrap else {
|
guard session.administrator || applicationBootstrap else {
|
||||||
return Reply(["errorMessage": "Administrator login required"],
|
return Reply(["errorMessage": "Administrator login required"],
|
||||||
status: "403 Forbidden", errorCode: -1013)
|
status: "403 Forbidden", errorCode: -1013)
|
||||||
@@ -178,13 +184,29 @@ final class WebConsoleAPI {
|
|||||||
} catch {
|
} catch {
|
||||||
return Reply(status: "503 Service Unavailable", errorCode: -1005)
|
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"):
|
case ("e2ds", "patientsbychartno", "GET"):
|
||||||
let argument = query.first(where: { $0.name == "chartno" })?.value
|
let chartNumber = Self.chartNumber(query: query, path: path, last: queryPathLast)
|
||||||
?? (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 } ?? ""
|
|
||||||
do {
|
do {
|
||||||
guard !chartNumber.isEmpty, let patient = try store.patient(chartNumber: chartNumber) else {
|
guard !chartNumber.isEmpty, let patient = try store.patient(chartNumber: chartNumber) else {
|
||||||
return Reply(["patientInfo": []], errorCode: -100037)
|
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 {
|
private func login(_ body: Data) -> Reply {
|
||||||
let now = Date()
|
let now = Date()
|
||||||
guard now >= lockedUntil else {
|
guard now >= lockedUntil else {
|
||||||
|
|||||||
Reference in new issue
Block a user