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
UserServiceandAuthServiceImplhave been refactored to handle user data directly as aUserentity, making the code cleaner and more aligned with standard Spring Boot practices. - Simplified Registration: The old
UserDTOhas been replaced with a newPatientRegistrationDTO, 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/registerhas been replaced withPOST /api/auth/register-patientto more accurately reflect its function. - Data Integrity Fix: We fixed a
DataIntegrityViolationExceptioncaused by an overly longstatevalue. 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
AuthenticationControllerTesthas been updated to support the newPatientRegistrationDTOand the new/api/auth/register-patientendpoint. - Unit Test: Resolved a
NullPointerExceptioninAuthServiceTestby ensuring each test case runs independently, without relying on shared static variables. - Data Cleanup Order: Fixed a
Referential integrity constraint violationby adjusting the data cleanup order in@AfterAllto 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- R1 - Doctor Registration
- R2 - Doctor List
- R3 - Doctor Data Update
- R4 - Doctor Data Exclusion
Patient- R5 - Patient Registration
- R6 - Patient List
- R7 - Patient Data Update
- R8 - Patient Data Exclusion
Staff- R9 - Staff Creation
Nurse- R10 - Nurse Registration
- R11 - Nurse List
- R12 - Nurse Data Update
- R13 - Nurse Data Exclusion
Specialized Management
Consultation- R14 - Scheduling a Consultation
- R15 - Canceling a Consultation
- R16 - Viewing an Individual Consultation
Doctor Schedule- R17 - Adding a new Doctor Schedule
Nurse Schedule- R18 - Adding a new Nurse Schedule
- R19 - Viewing Nurse Schedules (Pagination)
Operating Room- R20 - Add / Update / Delete Operating Room
- R21 - View Operating Rooms List
Operating Room Schedule- R22 - Add / View Operating Room Schedules
Medical Record- R23 - Medical Record Creation
- R24 - Medical Record Update
- R25 - Medical Record Exclusion
- R26 - Viewing a Medical Record by ID
Prescription- R27 - New Prescription Creation
Medical Image- R28 - Upload / Download Medical Images
Lab Result- R29 - Create / View Lab Results by Medical Record ID
Inventory Management
Inventory Item- R30 - Inventory Item Creation
- R31 - Inventory Item Update
- R32 - Inventory Item Exclusion
- R33 - Viewing an Inventory Item by ID
Inventory Transaction- R34 - Inventory Transaction Creation
Inventory Supplier- R35 - Supplier Creation
Inventory Item Type- R36 - Item Type Creation
Insurance Management
Insurance Provider- R37 - Provider Creation / Update / Delete
- R38 - Viewing Providers List
Insurance Claim- R39 - Claim Creation / Update / Delete
- R40 - Viewing Claims List
Billing & Payment
Billing- R41 - Billing Record Creation / Update / Delete
- R42 - Viewing Billing by ID
Payment- R43 - Payment Record Creation
- R44 - Viewing all Payment Records
- R45 - Viewing an Individual Payment Record
Reports
Inventory Reports- R46 - Low Stock Report
Financial Reports- R47 - Financial Overview Report
Appointment Reports- R48 - Appointments Report
User Management
- R49 - Update Username
- R50 - Update Password
- R51 - Update Role
- R52 - Deactivate User Account
- R53 - Activate User Account
- R54 - Link Patient to User
- R55 - Register Nurse and Link
- 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 patientPOST/api/auth/register-doctor-and-link- Register a new doctor and link them to a user accountPOST/api/auth/register-staff- Register a new staff memberPOST/api/auth/login- Log in to the systemPOST/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 usernamePUT/api/v1.0/users/{id}/role- Update a user's rolePUT/api/v1.0/users/{id}/password- Update a user's passwordPATCH/api/v1.0/users/{id}/deactivate- Deactivate a user's accountPATCH/api/v1.0/users/{id}/activate- Activate a user's account
🧑⚕️ Doctors (doctor-controller)
GET/api/v1.0/doctors- Retrieve a list of all doctorsPOST/api/v1.0/doctors- Create a new doctorGET/api/v1.0/doctors/{id}- Retrieve a single doctor by IDPUT/api/v1.0/doctors- Update an existing doctorDELETE/api/v1.0/doctors/{id}- Delete a doctor by ID
🤒 Patients (patient-controller)
GET/api/v1.0/patients- Retrieve a list of all patientsPOST/api/v1.0/patients- Create a new patientGET/api/v1.0/patients/{id}- Retrieve a single patient by IDPUT/api/v1.0/patients- Update an existing patientDELETE/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 consultationGET/api/v1.0/consultations/{id}- Retrieve a consultation by IDDELETE/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 recordGET/api/v1.0/medical-records/{id}- Retrieve a medical record by IDPUT/api/v1.0/medical-records/{id}- Update a medical recordDELETE/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 recordGET/api/v1.0/payments- Retrieve all payment recordsGET/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 itemGET/api/v1.0/inventory/items/{id}- Retrieve an inventory item by IDPUT/api/v1.0/inventory/items/{id}- Update an inventory itemDELETE/api/v1.0/inventory/items/{id}- Delete an inventory itemPOST/api/v1.0/inventory/transactions- Create a new inventory transactionPOST/api/v1.0/inventory/suppliers- Create a new supplierPOST/api/v1.0/inventory/item-types- Create a new inventory item type
🚀 How to Run
1️⃣ Clone the Repository
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. -
🔒 Unlicensed / Permission Required applies to portions derived from
MirnaGama/hospital-management-api.
See LICENSE-THIRD-PARTY.
⚠️ If you plan to redistribute or use this project commercially,
please ensure that you have the necessary rights for third-party portions,
or re-implement those parts independently if required.