- Added an overview of the Hospital API service and its purpose. - Included detailed features of the API, such as automatic shift management and real-time information. - Documented API endpoints with descriptions, response examples, and setup instructions. - Provided configuration details and database schema information. - Explained background tasks and logging format for better understanding of the application.
113 lines
2.8 KiB
Markdown
113 lines
2.8 KiB
Markdown
# Hospital API
|
|
|
|
A Rust-based API service that manages and provides information about hospitals on duty in Luxembourg City.
|
|
|
|
## Overview
|
|
|
|
This API service tracks which hospital is currently on duty in Luxembourg City and provides endpoints to access this information. The system automatically manages hospital shifts and ensures there's always a hospital assigned for emergency services.
|
|
|
|
## Features
|
|
|
|
- **Automatic Shift Management**: Creates and manages hospital shifts automatically
|
|
- **Real-time Hospital Information**: Provides current on-duty hospital information via API
|
|
- **Periodic Checks**: Regularly verifies and updates future shifts
|
|
- **Timestamped Logging**: All system events are logged with timestamps for better tracking
|
|
|
|
## API Endpoints
|
|
|
|
### Root Endpoint
|
|
- **URL**: `/`
|
|
- **Method**: `GET`
|
|
- **Description**: Returns basic API information
|
|
- **Response Example**:
|
|
```json
|
|
{
|
|
"name": "HospitalAPI",
|
|
"version": "0.1",
|
|
"description": "This API provides you with the current hospital on duty in luxembourg city. Call the /getHospital endpoint."
|
|
}
|
|
```
|
|
|
|
### Current Hospital Endpoint
|
|
- **URL**: `/current-hospital`
|
|
- **Method**: `GET`
|
|
- **Description**: Returns information about the hospital currently on duty
|
|
- **Response Example**:
|
|
```json
|
|
{
|
|
"success": true,
|
|
"hospital": {
|
|
"id": 1,
|
|
"name": "Centre Hospitalier",
|
|
"start_time": "2023-04-15T08:00:00Z",
|
|
"end_time": "2023-04-16T08:00:00Z"
|
|
},
|
|
"message": "Current hospital retrieved successfully"
|
|
}
|
|
```
|
|
|
|
## Setup and Installation
|
|
|
|
### Prerequisites
|
|
|
|
- Rust (latest stable version)
|
|
- PostgreSQL database
|
|
- Environment variables (see Configuration section)
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone https://github.com/yourusername/hospitalapi.git
|
|
cd hospitalapi
|
|
```
|
|
|
|
2. Build the project:
|
|
```bash
|
|
cargo build --release
|
|
```
|
|
|
|
3. Run the application:
|
|
```bash
|
|
cargo run
|
|
```
|
|
|
|
## Configuration
|
|
|
|
The application uses environment variables for configuration. Create a `.env` file in the project root with the following variables:
|
|
|
|
```
|
|
DATABASE_URL=postgres://username:password@localhost/hospitaldb
|
|
HOST=127.0.0.1
|
|
PORT=3000
|
|
```
|
|
|
|
## Database Schema
|
|
|
|
The application uses a PostgreSQL database with the following main tables:
|
|
|
|
- **hospitals**: Stores information about hospitals
|
|
- **shifts**: Stores hospital shift information
|
|
|
|
## Background Tasks
|
|
|
|
The application runs two background tasks:
|
|
|
|
1. **Future Shifts Check**: Runs every 48 hours to ensure future shifts are created
|
|
2. **Current Hospital Monitor**: Runs every minute to log the current on-duty hospital
|
|
|
|
## Logging
|
|
|
|
All system events are logged with timestamps in the format:
|
|
```
|
|
[YYYY-MM-DD HH:MM:SS] Message
|
|
```
|
|
|
|
## License
|
|
|
|
[MIT License](LICENSE)
|
|
|
|
## Contributing
|
|
|
|
Contributions are welcome! Please feel free to submit a Pull Request.
|