This project is a REST API built with Django and Django REST Framework (DRF) to manage user registrations, health information, and health worker records. The API supports user authentication using JSON Web Tokens (JWT) provided by the djangorestframework-simplejwt
library. This documentation provides an overview of the available endpoints, request/response formats, and how to interact with the API.
- Endpoint:
/user-create/
- Method:
POST
- Description: Creates a new user account in the system.
- Request Body:
{ "username": "string", "password": "string", "email": "string", "role": "P" // P for patient, H for health worker }
- Response:
- Status 201:
{ "id": 1, "username": "string", "email": "string", "role": "P" }
- Status 400:
{ "error": "Invalid data" }
- Status 201:
- Endpoint:
/user-detail/
- Method:
GET
- Description: Retrieves details of the authenticated user.
- Authentication: JWT required.
- Response:
- Status 200:
{ "id": 1, "username": "string", "email": "string", "role": "P" }
- Status 401:
{ "detail": "Authentication credentials were not provided." }
- Status 200:
- Endpoint:
/health-info/create/
- Method:
PUT
- Description: Allows a patient to create or update their health information.
- Authentication: JWT required (Patient role only).
- Request Body:
{ "pregnancy_status": "string", "due_date": "YYYY-MM-DD", "health_conditions": "string" }
- Response:
- Status 200:
{ "message": "Health information created/updated successfully" }
- Status 403:
{ "detail": "You are not authorized to perform this action." }
- Status 400:
{ "error": "Error message" }
- Status 200:
- Endpoint:
/health-info/
- Method:
GET
- Description: Retrieves the health information of the authenticated patient.
- Authentication: JWT required (Patient role only).
- Response:
- Status 200:
{ "pregnancy_status": "string", "due_date": "YYYY-MM-DD", "health_conditions": "string" }
- Status 403:
{ "detail": "You are not authorized to perform this action." }
- Status 401:
{ "detail": "Authentication credentials were not provided." }
- Status 200:
- Endpoint:
/health-worker/create/
- Method:
PUT
- Description: Allows a health worker to create or update their professional information.
- Authentication: JWT required (Health worker role only).
- Request Body:
{ "medical_license_number": "string", "specialty": "string", "clinic_location": "string", "clinic_name": "string" }
- Response:
- Status 200:
{ "message": "Health worker information created/updated successfully" }
- Status 403:
{ "detail": "You are not authorized to perform this action." }
- Status 400:
{ "error": "Error message" }
- Status 200:
- Endpoint:
/health-worker/
- Method:
GET
- Description: Retrieves the professional information of the authenticated health worker.
- Authentication: JWT required (Health worker role only).
- Response:
- Status 200:
{ "medical_license_number": "string", "specialty": "string", "clinic_location": "string", "clinic_name": "string" }
- Status 403:
{ "detail": "You are not authorized to perform this action." }
- Status 401:
{ "detail": "Authentication credentials were not provided." }
- Status 200:
- Endpoint:
/login/
- Method:
POST
- Description: Authenticates a user and returns JWT tokens.
- Request Body:
{ "username": "string", "password": "string" }
- Response:
- Status 200:
{ "refresh": "string", "access": "string", "message": "Login successful", "data": { "user_details": "object" } }
- Status 401:
{ "error": "Invalid credentials" }
- Status 200:
- Endpoint:
/token/refresh/
- Method:
POST
- Description: Refreshes the access token using the refresh token.
- Request Body:
{ "refresh": "string" }
- Response:
- Status 200:
{ "access": "string" }
- Status 401:
{ "error": "Invalid refresh token" }
- Status 200:
- Endpoint:
/logout/
- Method:
POST
- Description: Invalidates the refresh token and logs out the user.
- Request Body:
{ "refresh": "string" }
- Response:
- Status 200:
{ "message": "Logout successful" }
- Status 400:
{ "error": "Error message" }
- Status 200:
All endpoints will return appropriate HTTP status codes along with error messages in JSON format if any issues occur during the request handling. Common status codes include 400
for bad requests, 401
for unauthorized access, 403
for forbidden actions, and 404
for resources not found.
The API uses JWT for authentication. After logging in, clients should include the JWT access token in the Authorization
header of each request as follows:
Authorization: Bearer <your_access_token>
If the access token expires, clients can refresh it using the /token/refresh/
endpoint.
- UserRegistration: Handles user information and roles (e.g., Patient or Health Worker).
- HealthInfo: Stores health information specific to patients.
- HealthWorkerInfo: Stores professional information for health workers.