Hospital Management API (Extended Version)

API Version Developed by

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
    • 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 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

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:

⚠️ If you plan to redistribute or use this project commercially, ensure that you have the necessary rights for third-party portions.

Description
No description provided
Readme 1.1 MiB
Languages
Java 99.8%
Dockerfile 0.2%