296 lines
11 KiB
Markdown
296 lines
11 KiB
Markdown
# Hospital Management API (Extended Version)
|
||
|
||

|
||

|
||
|
||
Extended REST API for Hospital Management, built on top of the original project by Mirna Gama. This version includes new features for user management, inventory, and medical records.
|
||
|
||
---
|
||
|
||
## ✨ Improvements and New Features
|
||
|
||
### 1. Code Structure and Architecture
|
||
|
||
* **Entity-Driven Design**: The `UserService` and `AuthServiceImpl` have been refactored to handle user data directly as a `User` entity, making the code cleaner and more aligned with standard Spring Boot practices.
|
||
* **Simplified Registration**: The old `UserDTO` has been replaced with a new `PatientRegistrationDTO`, which combines user and patient information into a single, comprehensive DTO for a smoother registration process.
|
||
|
||
### 2. Endpoint and Data Handling Changes
|
||
|
||
* **New Patient Registration Endpoint**: The old endpoint `POST /api/auth/register` has been replaced with `POST /api/auth/register-patient` to more accurately reflect its function.
|
||
* **Data Integrity Fix**: We fixed a `DataIntegrityViolationException` caused by an overly long `state` value. Test data has been updated to use a 2-character abbreviation (e.g., "CA") to conform to database constraints.
|
||
|
||
### 3. Major Test Suite Refinement
|
||
|
||
* **Integration Test**: The `AuthenticationControllerTest` has been updated to support the new `PatientRegistrationDTO` and the new `/api/auth/register-patient` endpoint.
|
||
* **Unit Test**: Resolved a `NullPointerException` in `AuthServiceTest` by ensuring each test case runs independently, without relying on shared static variables.
|
||
* **Data Cleanup Order**: Fixed a `Referential integrity constraint violation` by adjusting the data cleanup order in `@AfterAll` to ensure patients are deleted before users.
|
||
|
||
### 4. Additional Features
|
||
|
||
* Refined the user and patient registration flow.
|
||
* Introduced **RBAC (Role-Based Access Control)** to manage system permissions.
|
||
* Improved the database schema for better data management.
|
||
* Added a **Default Admin** user for easier initial setup.
|
||
|
||
---
|
||
|
||
## 🛠 Tech Stack
|
||
- Java 17
|
||
- Spring Boot 3.x
|
||
- PostgreSQL + pgAdmin (via Docker)
|
||
- Spring Security (JWT + RBAC)
|
||
- JUnit 5 & Mockito (Testing)
|
||
- Swagger / OpenAPI
|
||
|
||
---
|
||
|
||
## 🚀 Features - v2.0
|
||
|
||
### Core Data Management
|
||
* **`Doctor`**
|
||
* [x] **R1** - Doctor Registration
|
||
* [x] **R2** - Doctor List
|
||
* [x] **R3** - Doctor Data Update
|
||
* [x] **R4** - Doctor Data Exclusion
|
||
* **`Patient`**
|
||
* [x] **R5** - Patient Registration
|
||
* [x] **R6** - Patient List
|
||
* [x] **R7** - Patient Data Update
|
||
* [x] **R8** - Patient Data Exclusion
|
||
* **`Staff`**
|
||
* [x] **R9** - Staff Creation
|
||
* **`Nurse`**
|
||
* [x] **R10** - Nurse Registration
|
||
* [x] **R11** - Nurse List
|
||
* [x] **R12** - Nurse Data Update
|
||
* [x] **R13** - Nurse Data Exclusion
|
||
|
||
### Specialized Management
|
||
* **`Consultation`**
|
||
* [x] **R14** - Scheduling a Consultation
|
||
* [x] **R15** - Canceling a Consultation
|
||
* [x] **R16** - Viewing an Individual Consultation
|
||
* **`Doctor Schedule`**
|
||
* [x] **R17** - Adding a new Doctor Schedule
|
||
* **`Nurse Schedule`**
|
||
* [x] **R18** - Adding a new Nurse Schedule
|
||
* [x] **R19** - Viewing Nurse Schedules (Pagination)
|
||
* **`Operating Room`**
|
||
* [x] **R20** - Add / Update / Delete Operating Room
|
||
* [x] **R21** - View Operating Rooms List
|
||
* **`Operating Room Schedule`**
|
||
* [x] **R22** - Add / View Operating Room Schedules
|
||
* **`Medical Record`**
|
||
* [x] **R23** - Medical Record Creation
|
||
* [x] **R24** - Medical Record Update
|
||
* [x] **R25** - Medical Record Exclusion
|
||
* [x] **R26** - Viewing a Medical Record by ID
|
||
* **`Prescription`**
|
||
* [x] **R27** - New Prescription Creation
|
||
* **`Medical Image`**
|
||
* [x] **R28** - Upload / Download Medical Images
|
||
* **`Lab Result`**
|
||
* [x] **R29** - Create / View Lab Results by Medical Record ID
|
||
|
||
### Inventory Management
|
||
* **`Inventory Item`**
|
||
* [x] **R30** - Inventory Item Creation
|
||
* [x] **R31** - Inventory Item Update
|
||
* [x] **R32** - Inventory Item Exclusion
|
||
* [x] **R33** - Viewing an Inventory Item by ID
|
||
* **`Inventory Transaction`**
|
||
* [x] **R34** - Inventory Transaction Creation
|
||
* **`Inventory Supplier`**
|
||
* [x] **R35** - Supplier Creation
|
||
* **`Inventory Item Type`**
|
||
* [x] **R36** - Item Type Creation
|
||
|
||
### Insurance Management
|
||
* **`Insurance Provider`**
|
||
* [x] **R37** - Provider Creation / Update / Delete
|
||
* [x] **R38** - Viewing Providers List
|
||
* **`Insurance Claim`**
|
||
* [x] **R39** - Claim Creation / Update / Delete
|
||
* [x] **R40** - Viewing Claims List
|
||
|
||
### Billing & Payment
|
||
* **`Billing`**
|
||
* [x] **R41** - Billing Record Creation / Update / Delete
|
||
* [x] **R42** - Viewing Billing by ID
|
||
* **`Payment`**
|
||
* [x] **R43** - Payment Record Creation
|
||
* [x] **R44** - Viewing all Payment Records
|
||
* [x] **R45** - Viewing an Individual Payment Record
|
||
|
||
### Reports
|
||
* **`Inventory Reports`**
|
||
* [x] **R46** - Low Stock Report
|
||
* **`Financial Reports`**
|
||
* [x] **R47** - Financial Overview Report
|
||
* **`Appointment Reports`**
|
||
* [x] **R48** - Appointments Report
|
||
|
||
### User Management
|
||
* [x] **R49** - Update Username
|
||
* [x] **R50** - Update Password
|
||
* [x] **R51** - Update Role
|
||
* [x] **R52** - Deactivate User Account
|
||
* [x] **R53** - Activate User Account
|
||
* [x] **R54** - Link Patient to User
|
||
* [x] **R55** - Register Nurse and Link
|
||
* [x] **R56** - Register Doctor and Link
|
||
|
||
---
|
||
|
||
## 🔑 Default Credentials
|
||
|
||
For initial administrative access, use the following credentials:
|
||
|
||
* **Username:** `admin@softwarecraft.tech`
|
||
* **Password:** `pasword123`
|
||
|
||
---
|
||
|
||
## 📖 API Endpoints
|
||
|
||
### 🔑 Authentication (`authentication-controller`)
|
||
* `POST` `/api/auth/register-patient` - Register a new patient
|
||
* `POST` `/api/auth/register-doctor-and-link` - Register a new doctor and link them to a user account
|
||
* `POST` `/api/auth/register-staff` - Register a new staff member
|
||
* `POST` `/api/auth/login` - Log in to the system
|
||
* `POST` `/api/auth/link-patient-to-user` - Link a patient to an existing user account
|
||
|
||
### 👤 User Management (`user-controller`)
|
||
* `PUT` `/api/v1.0/users/{id}/username` - Update a user's username
|
||
* `PUT` `/api/v1.0/users/{id}/role` - Update a user's role
|
||
* `PUT` `/api/v1.0/users/{id}/password` - Update a user's password
|
||
* `PATCH` `/api/v1.0/users/{id}/deactivate` - Deactivate a user's account
|
||
* `PATCH` `/api/v1.0/users/{id}/activate` - Activate a user's account
|
||
|
||
### 🧑⚕️ Doctors (`doctor-controller`)
|
||
* `GET` `/api/v1.0/doctors` - Retrieve a list of all doctors
|
||
* `POST` `/api/v1.0/doctors` - Create a new doctor
|
||
* `GET` `/api/v1.0/doctors/{id}` - Retrieve a single doctor by ID
|
||
* `PUT` `/api/v1.0/doctors` - Update an existing doctor
|
||
* `DELETE` `/api/v1.0/doctors/{id}` - Delete a doctor by ID
|
||
|
||
### 🤒 Patients (`patient-controller`)
|
||
* `GET` `/api/v1.0/patients` - Retrieve a list of all patients
|
||
* `POST` `/api/v1.0/patients` - Create a new patient
|
||
* `GET` `/api/v1.0/patients/{id}` - Retrieve a single patient by ID
|
||
* `PUT` `/api/v1.0/patients` - Update an existing patient
|
||
* `DELETE` `/api/v1.0/patients/{id}` - Delete a patient by ID
|
||
|
||
### 🏥 Staff (`staff-controller`)
|
||
* `POST` `/api/v1.0/staff` - Add a new staff member
|
||
|
||
### 🩺 Consultations (`consultation-controller`)
|
||
* `POST` `/api/v1.0/consultations` - Create a new consultation
|
||
* `GET` `/api/v1.0/consultations/{id}` - Retrieve a consultation by ID
|
||
* `DELETE` `/api/v1.0/consultations` - Cancel a consultation
|
||
|
||
### 📆 Doctor Schedules (`doctor-schedules-controller`)
|
||
* `POST` `/api/v1.0/doctor-schedules` - Add a new doctor schedule
|
||
|
||
### 📝 Medical Records (`medical-record-controller`)
|
||
* `POST` `/api/v1.0/medical-records` - Create a new medical record
|
||
* `GET` `/api/v1.0/medical-records/{id}` - Retrieve a medical record by ID
|
||
* `PUT` `/api/v1.0/medical-records/{id}` - Update a medical record
|
||
* `DELETE` `/api/v1.0/medical-records/{id}` - Delete a medical record
|
||
|
||
### 💊 Prescriptions (`prescriptions-controller`)
|
||
* `POST` `/api/v1.0/prescriptions` - Create a new prescription
|
||
|
||
### 💲 Payments (`payment-controller`)
|
||
* `POST` `/api/v1.0/payments` - Create a new payment record
|
||
* `GET` `/api/v1.0/payments` - Retrieve all payment records
|
||
* `GET` `/api/v1.0/payments/{id}` - Retrieve a single payment record by ID
|
||
|
||
### 📦 Inventory (`inventory-controller`)
|
||
* `POST` `/api/v1.0/inventory/items` - Create a new inventory item
|
||
* `GET` `/api/v1.0/inventory/items/{id}` - Retrieve an inventory item by ID
|
||
* `PUT` `/api/v1.0/inventory/items/{id}` - Update an inventory item
|
||
* `DELETE` `/api/v1.0/inventory/items/{id}` - Delete an inventory item
|
||
* `POST` `/api/v1.0/inventory/transactions` - Create a new inventory transaction
|
||
* `POST` `/api/v1.0/inventory/suppliers` - Create a new supplier
|
||
* `POST` `/api/v1.0/inventory/item-types` - Create a new inventory item type
|
||
|
||
---
|
||
|
||
## 🚀 How to Run
|
||
|
||
### 1️⃣ Clone the Repository
|
||
```bash
|
||
git clone <this repository>
|
||
cd hospital-management-api
|
||
```
|
||
|
||
### 2️⃣ Set Environment Variables for IntelliJ
|
||
|
||
เปิด IntelliJ → ไปที่ Run → Edit Configurations
|
||
|
||
เลือก Configuration ของ Spring Boot ของโปรเจค
|
||
|
||
ในส่วน Environment Variables กำหนดค่าตามนี้:
|
||
```
|
||
POSTGRES_HOST=localhost
|
||
POSTGRES_PORT=5432
|
||
POSTGRES_DB=<your_database_name>
|
||
POSTGRES_USER=<your_database_user>
|
||
POSTGRES_PASSWORD=<your_database_password>
|
||
JWT_SECRET=<your_jwt_secret>
|
||
MINIO_URL=<your_minio_url>
|
||
MINIO_ACCESS=<your_minio_access_key>
|
||
MINIO_SECRET=<your_minio_secret_key>
|
||
MINIO_BUCKET=<your_minio_bucket>
|
||
PGADMIN_DEFAULT_EMAIL=<your_pgadmin_email>
|
||
PGADMIN_DEFAULT_PASSWORD=<your_pgadmin_password>
|
||
```
|
||
|
||
### 3️⃣ Run PostgreSQL and pgAdmin
|
||
```
|
||
# รันเฉพาะ PostgreSQL และ pgAdmin
|
||
docker-compose up -d postgresdb pgadmin
|
||
|
||
```
|
||
|
||
### 4️⃣ Run Spring Boot Application
|
||
|
||
เปิด IntelliJ
|
||
|
||
Run Spring Boot จาก Configuration ที่ตั้งค่า Environment Variables แล้ว
|
||
|
||
✅ แอปจะเชื่อมต่อ PostgreSQL และ MinIO ตามค่าที่กำหนด
|
||
|
||
---
|
||
|
||
### Future Development Plan (v2.1+)
|
||
|
||
We will continue to develop on Spring Boot following standard best practices to add the following capabilities:
|
||
|
||
**AI-Driven Enhancements**
|
||
- Implement predictive analytics for patient admissions and resource allocation.
|
||
- Integrate AI models for anomaly detection in lab results or vital signs.
|
||
- Use Natural Language Processing (NLP) for automated parsing of medical notes.
|
||
- Suggest treatment plans or risk alerts based on historical patient data.
|
||
---
|
||
|
||
## 📝 API Documentation
|
||
Full API documentation (Swagger UI) is available at:
|
||
https://his-backend.softwarecraft.tech/swagger-ui/index.html
|
||
|
||
---
|
||
|
||
## 📜 License
|
||
|
||
This project uses a **dual-license structure**:
|
||
|
||
- 🟢 **MIT License** applies to all new contributions and improvements by SoftwareCraft.
|
||
See [LICENSE](./LICENSE).
|
||
|
||
- 🔒 **Unlicensed / Permission Required** applies to portions derived from
|
||
[MirnaGama/hospital-management-api](https://github.com/MirnaGama/hospital-management-api).
|
||
See [LICENSE-THIRD-PARTY](./LICENSE-THIRD-PARTY).
|
||
|
||
⚠️ If you plan to redistribute or use this project commercially,
|
||
ensure that you have the necessary rights for third-party portions. |