Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit introducing new patient search service #130

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/api/handlers/patients/getPatients.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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;
};
Loading