-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit introducing new patient search service
- Loading branch information
1 parent
bb355cd
commit ca45854
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getPatients } from "../../../models/patient"; | ||
|
||
export default async(req, res) => { | ||
|
||
const filter = req.query.filter; | ||
|
||
if (filter === null || | ||
typeof filter !== 'string' || | ||
filter.length < 3) { | ||
return res.status(400).send({ | ||
message: "Invalid filter criteria." | ||
}); | ||
} | ||
|
||
return res.status(200).send(await getPatients(filter)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import getPatients from "./getPatients"; | ||
|
||
export { getPatients }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { db } from "../../knex"; | ||
|
||
const patientFields = [ | ||
"patientName", | ||
"patientPhoneNumber", | ||
"language", | ||
{ patientLanguage: "language" }, | ||
]; | ||
|
||
export const getPatients = (substring) => { | ||
const query = db("appointments") | ||
.distinct(patientFields) | ||
.where("patientName", "like", `%${substring}%`) | ||
|
||
return query | ||
} |