- Introduced a Dockerfile for building the application using a multi-stage build process. - Added docker-compose.yml to define services for the application and PostgreSQL database. - Updated README.md with instructions for running the application using Docker and Docker Compose.
124 lines
3.4 KiB
Markdown
124 lines
3.4 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.
|
|
|
|
This project was developed as a test project for exploring AI-assisted software development. It demonstrates how AI can be used to create, modify, and maintain a real-world application.
|
|
|
|
## 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"
|
|
}
|
|
```
|
|
|
|
## 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
|
|
```
|
|
|
|
## Docker Setup
|
|
|
|
### Prerequisites
|
|
|
|
- Docker
|
|
- Docker Compose
|
|
|
|
### Running with Docker
|
|
|
|
1. Make sure you have a `.env` file in the project root with the necessary configuration.
|
|
|
|
2. Build and start the containers:
|
|
```bash
|
|
docker-compose up -d
|
|
```
|
|
|
|
3. To view logs:
|
|
```bash
|
|
docker-compose logs -f
|
|
```
|
|
|
|
4. To stop the application:
|
|
```bash
|
|
docker-compose down
|
|
```
|
|
|
|
The application will be available at http://localhost:3000.
|
|
|
|
## License
|
|
|
|
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). This license ensures that:
|
|
|
|
- The software remains free and open source
|
|
- Any modifications or improvements must be shared back with the community
|
|
- The source code must be made available to users
|
|
- The license terms must be preserved in any derivative works
|
|
|
|
For the full license text, see the [LICENSE](LICENSE) file.
|
|
|
|
## Contributing
|
|
|
|
Contributions are welcome! Please feel free to submit a Pull Request.
|