Skip to content

Commit

Permalink
Initial commit introducing new patient search service
Browse files Browse the repository at this point in the history
  • Loading branch information
timmytonyboots committed Nov 21, 2023
1 parent bb355cd commit ca45854
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/api/handlers/patients/getPatients.js
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));
}
3 changes: 3 additions & 0 deletions src/api/handlers/patients/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import getPatients from "./getPatients";

export { getPatients };
4 changes: 4 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getToken } from "./handlers/auth";
import { getCommunications } from "./handlers/communications";
import { getLanguages } from "./handlers/languages";
import { postReply } from "./handlers/twilio";
import getPatients from "./handlers/patients/getPatients";

// eslint-disable-next-line no-unused-vars
export default ({ config }) => {
Expand All @@ -34,6 +35,9 @@ export default ({ config }) => {
api.post("/appointments", postAppointments);
api.patch("/appointments/:appointmentId", patchAppointments);

// -- Patients
api.get("/patients", getPatients);

// -- Languages
api.get("/languages", getLanguages);

Expand Down
16 changes: 16 additions & 0 deletions src/models/patient.js
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
}

0 comments on commit ca45854

Please sign in to comment.