Part 3: Designing the Database Schema with GraphQL for our Dental Clinic Management System ๐๏ธ๐
Rest API using GraphQL
Github Repo ๐: DentalArt
GraqhQL API
In this part of our blog series, we'll dive into the heart of our Dental Clinic Management System - the database schema using GraphQL. We'll explore what GraphQL is, its advantages, and then proceed to explain the components of our schema. Let's get started! ๐๐ฆท
What is GraphQL?
GraphQL is a powerful query language for APIs, developed by Facebook. Unlike traditional REST APIs, where you make multiple requests for different endpoints, GraphQL allows clients to request exactly the data they need in a single query. It provides a flexible and efficient way to interact with your backend, making it a perfect fit for our Dental Clinic Management System.
Advantages of GraphQL
Efficiency: Clients can fetch only the required data, reducing unnecessary data transfers and improving performance.
Strong Typing: GraphQL schemas are strongly typed, ensuring type safety and reducing runtime errors.
Flexibility: The client has control over the data shape, enabling seamless updates to the frontend without server-side changes.
Multiple Data Sources: GraphQL allows aggregating data from various sources, making it ideal for complex applications like our Dental Clinic Management System.
Understanding the Schema
Now, let's break down the components of our GraphQL schema:
Tasks: Represents the tasks or errands assigned to staff members. It includes attributes like title, creation date, due date, details, and staff members associated with the task.
type Tasks @model @auth(rules: [{allow: public}]) { id: ID! title: String date_created: AWSDateTime date_due: AWSDateTime details: String staff_assigned: [Staff] @manyToMany(relationName: "TasksStaff") }
Staff: Represents the clinic's staff members, including doctors, receptionists, nurses, and assistants. Each staff member has attributes like first name, last name, email, phone number, role, assigned appointments, and tasks.
enum StaffRoleEnum { DOCTOR RECEPTIONIST NURSE NURSEAID ASSISTANT } type Staff @model @auth(rules: [{allow: public}]) { id: ID! first_name: String last_name: String email: AWSEmail username: String phone_number: AWSPhone role: StaffRoleEnum staff_appointments: [Appointments] @hasMany(indexName: "byStaff", fields: ["id"]) taskss: [Tasks] @manyToMany(relationName: "TasksStaff") }
Appointments: Represents the scheduled appointments for patients. It includes attributes such as appointment date, start and end times, status (done, pending, missed, rescheduled), the staff member assigned to the appointment, and the patient ID associated with the appointment.
enum AppointmentStatusEnum { DONE PENDING MISSED RESCHEDULED } type Appointments @model @auth(rules: [{allow: public}]) { id: ID! appointment_date: AWSDate created_at: AWSDateTime start_time: AWSTime end_time: AWSTime status: AppointmentStatusEnum assigned_to: String patientID: ID! @index(name: "byPatient") staffID: ID! @index(name: "byStaff") }
Patient: Represents the patients visiting the clinic. It includes attributes like first name, last name, email, date of birth, phone number, gender, and the appointments associated with each patient.
type Patient @model @auth(rules: [{allow: public}]) { id: ID! first_name: String last_name: String email: AWSEmail date_of_birth: AWSDate phone_number: AWSPhone pat_appointments: [Appointments] @hasMany(indexName: "byPatient", fields: ["id"]) gender: String }
Database Relationships
Staff
andTasks
have a many-to-many relationship, allowing tasks to be assigned to multiple staff members and vice versa.Staff
andAppointments
have a one-to-many relationship, where each staff member can be associated with multiple appointments.Patient
andAppointments
have a one-to-many relationship, allowing each patient to have multiple appointments.
GraphQL Resolvers
GraphQL resolvers are responsible for fetching data from the underlying data sources. In our case, AWS Amplify's GraphQL API will handle the resolvers, automatically managing data storage and retrieval from the database.
Data Access Control
With @auth
rules defined in the schema, we ensure that specific parts of the data are protected and accessible only to authorized users. In our Dental Clinic Management System, we'll allow public access to appointments, staff, tasks, and patients while restricting sensitive information access as needed.
By adopting this well-designed GraphQL schema, our Dental Clinic Management System will efficiently manage appointments, tasks, staff, and patients, providing a seamless experience for both the clinic staff and the patients.
In the next part of our series, we'll dive into the implementation details of building our GraphQL API and connecting it with AWS Amplify. Stay tuned, as we move closer to bringing our Dental Clinic Management System to life! ๐๐ฅ๐ฆท
Feel free to share your thoughts and questions in the comments below. Happy coding! ๐ป๐