0% found this document useful (0 votes)
13 views2 pages

FastAPI CRUD API for Patients & Counsellors

Uploaded by

hassan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

FastAPI CRUD API for Patients & Counsellors

Uploaded by

hassan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Diya Interactive Python FastAPI Coding Test

Objective:​

To create a REST API based CRUD application in FastAPI

.
The objective of this task is to develop a RESTful API-based CRUD (Create, Read,
Update, and Delete) application using FastAPI, and MySQL/SQLite database. The
application should have the following schemas: Patient, Counsellor, and
Appointment, with each having their own attributes.

Suggested Schema:

Patient

● Id (unique identifier)
● Name (string)
● Email (unique identifier)
● Password (string)
● Is_active (boolean)

Counsellor

● Id (unique identifier)
● Name (string)
● Email (unique identifier)
● Password (string)
● Is_active (boolean)

Appointment

● Id (unique identifier)
● Patient (foreign key to Patient)
● Counsellor (foreign key to Counsellor)
● Appointment_Date (datetime)
● Is_active (boolean)
Requirements:

1. Develop APIs for creating, updating, reading, and deleting Patients,


Counsellors, and Appointments. Deletion will be soft delete only by
marking the record as deleted or inactive.
2. Develop APIs for:
a. Listing all active patients, active counsellors, and active
appointments
b. Listing all appointments for a specific patient or counsellor
c. Listing active appointments between a date range, sorted by date in
descending order.
3. Develop unit test cases for all APIs (bonus points for this)
4. Push the code to GitHub / GitLab repository and provide a link. The
repository should also contain a Readme file describing setup instructions
and [Link] with a list of packages used by the application.
5. Provide APIs in a Postman compatible json collection

Notes:

● A user can be both patient and counsellor.


● Password must be greater than 8 characters with strong strength
● Email is used as User ID which will be unique
● Only active patients and counsellors can create appointments
● A patient and counsellor can have only one active appointment at a time
● Code should be well documented

Development Stack:

● Python ver 3.8x


● FastAPI ver 0.95.x
● MySQL ver 5.x / SQLite

Common questions

Powered by AI

FastAPI offers several advantages over other web frameworks: it provides high performance, is easy to use, and allows for automatic generation of interactive API documentation. Its asynchronous capabilities make it suitable for handling concurrent requests efficiently, which can significantly improve performance for a CRUD application .

Ensuring only one active appointment requires enforcing constraints at both the application and database layers. This involves checking for existing active appointments before allowing the creation of a new one and handling concurrency issues that may arise from simultaneous requests. Challenges include ensuring the checks are efficient and do not lead to performance bottlenecks .

Using email as a unique identifier simplifies user authentication and ensures each account is unique. It also facilitates account recovery and communication. However, it necessitates validation logic to ensure email uniqueness and handle scenarios like change of email addresses without interfering with user identity .

Providing API documentation and a Postman collection enables developers and clients to understand how to interact with the APIs efficiently. This improves usability and integration across different platforms. Auto-generated documentation, a feature of FastAPI, ensures it is up-to-date with the actual API behavior, reducing human error in communicating API capabilities .

Optimizing API responses for large datasets can involve implementing pagination to limit the number of records returned at once, using query optimization techniques to reduce database load, and applying filtering and sorting on the server side. Additionally, employing caching strategies can optimize response times for frequently fetched data .

Developing unit test cases ensures each API function operates correctly and handles edge cases, contributing to the reliability and stability of the application. They serve as documentation for expected behaviors, facilitating future maintenance and improvements, and help detect issues early, reducing potential before-deployment failures .

Allowing a user to have dual roles implies that the application must handle role-based access control carefully. The system should enforce that while a user can have both roles, actions such as creating appointments are conditional on the status of the respective role being active. This also necessitates careful logic to prevent conflicts, such as ensuring a user does not counsel themselves .

MySQL offers robust performance features such as scalability needed for larger applications and more complex queries, while SQLite is lightweight and easier to set up but might not handle high-concurrency traffic efficiently. The choice impacts how the application is deployed; SQLite is more suitable for environments where simplicity is key, whereas MySQL is suited for production deployments requiring high availability .

Security considerations for managing passwords include enforcing a strong password policy (minimum of 8 characters with complexity), using secure hashing algorithms for storing passwords, and ensuring password transmission over secure channels like HTTPS to prevent interception. Additional measures include monitoring and preventing brute force attacks .

Implementing a soft delete affects database design by requiring an additional column, typically a boolean like 'Is_active', to mark records as inactive rather than removing them. This preserves historical data and maintains referential integrity, as relationships remain intact, allowing for potential recovery or auditing of data changes .

You might also like