Skip to content

abdulrahman-masoud/Graduation_BackEnd

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GP Medical Imaging Server

A comprehensive medical imaging management system built with .NET 8, providing DICOM image storage, AI-powered report generation, and user management for medical professionals.

πŸ₯ Overview

This system serves as a backend for a medical imaging platform that integrates with Orthanc PACS server for DICOM storage and an AI service for automated radiology report generation. It's designed for hospitals, clinics, and medical imaging centers to streamline their radiology workflow.

πŸš€ Features

πŸ” Authentication & Authorization

  • JWT-based authentication with role-based access control
  • Multi-role support: SuperAdmin, Admin, Doctor, Technician roles
  • Secure user management with profile picture uploads
  • Password-based authentication with Identity framework

πŸ“Š DICOM Management

  • Orthanc PACS integration for medical image storage
  • Complete DICOM hierarchy support: Patients β†’ Studies β†’ Series β†’ Instances
  • DICOM file upload (single and bulk upload)
  • Image preview generation (PNG, JPEG formats)
  • DICOM metadata extraction and tag viewing
  • Study viewer data for DICOM viewing applications

πŸ€– AI-Powered Reporting

  • Automated report generation using external AI service
  • Background processing with queue-based report generation
  • DICOM Structured Reports (SR) creation and storage
  • Report status tracking: Pending β†’ InProgress β†’ Generated β†’ Failed
  • Findings and impressions extraction from AI responses
  • Study assignment to doctors for review

πŸ‘₯ User Management

  • User CRUD operations with role assignment
  • Profile management with picture uploads
  • Role management with custom role creation
  • User filtering and pagination support

πŸ“ˆ Statistics & Monitoring

  • System statistics and reporting
  • Study status monitoring
  • Health checks for Orthanc server connectivity
  • Comprehensive logging with structured logging

πŸ—οΈ Architecture

The project follows Clean Architecture principles with clear separation of concerns:

β”œβ”€β”€ GP_Server.Api/              # API Layer (Controllers, Middleware)
β”œβ”€β”€ GP_Server.Application/      # Application Layer (Services, DTOs, Interfaces)
β”œβ”€β”€ GP_Server.Domain/          # Domain Layer (Entities, Business Logic)
└── GP_Server.Infrastructure/  # Infrastructure Layer (Data Access, External Services)

Key Components

  • OrthancService: Handles all DICOM operations with Orthanc PACS server
  • ReportGenerationWorker: Background service for AI report generation
  • AuthService: JWT token generation and user authentication
  • UserService: User management and role assignment
  • StudyService: Study lifecycle and status management

πŸ› οΈ Technology Stack

  • .NET 8 - Modern C# development platform
  • ASP.NET Core - Web API framework
  • Entity Framework Core - ORM with PostgreSQL
  • PostgreSQL - Primary database
  • Orthanc - DICOM PACS server
  • JWT Authentication - Secure token-based auth
  • Docker - Containerization
  • AutoMapper - Object mapping
  • FellowOak DICOM - DICOM file processing

πŸ“‹ Prerequisites

  • Docker & Docker Compose
  • .NET 8 SDK (for local development)
  • PostgreSQL (handled by Docker)
  • Orthanc PACS Server (handled by Docker)
  • AI Report Generation Service (external)

πŸš€ Quick Start

1. Clone and Configure

git clone <repository-url>
cd GP/Back-End

2. Configuration

Update configuration in Server/src/GP_Server.Api/appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=postgres;Database=GP_Database;Username=postgres;Password=mysecretpassword;Port=5432;"
  },
  "Jwt": {
    "SecretKey": "your-secret-key-here",
    "Issuer": "http://localhost:7150",
    "ExpirationInHours": 24
  },
  "Orthanc": {
    "BaseUrl": "http://orthanc:8042",
    "Username": "orthanc",
    "Password": "orthanc"
  },
  "AI": {
    "Endpoint": "http://host.docker.internal:8000/generate_report_dicom"
  }
}

3. Start with Docker

# Start all services
docker-compose up --build

# Or run in detached mode
docker-compose up -d --build

4. Access the Services

πŸ“š API Documentation

Authentication Endpoints

POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password"
}

DICOM Operations

# Upload DICOM file
POST /api/orthanc/upload
Content-Type: multipart/form-data
Authorization: Bearer <jwt-token>

# Get all patients
GET /api/orthanc/patients?pageNumber=1&pageSize=20
Authorization: Bearer <jwt-token>

# Get patient studies
GET /api/orthanc/patients/{patientId}/studies
Authorization: Bearer <jwt-token>

# Get study viewer data
GET /api/orthanc/studies/{studyId}/viewer-data
Authorization: Bearer <jwt-token>

# Queue study for report generation
POST /api/orthanc/studies/{studyId}/queue-report
Authorization: Bearer <jwt-token>

User Management

# Get all users
GET /api/users?pageNumber=1&pageSize=20
Authorization: Bearer <jwt-token>

# Create user
POST /api/users
Content-Type: application/json
Authorization: Bearer <jwt-token>

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "john.doe@example.com",
  "password": "SecurePassword123",
  "roles": ["doctor-role-id"]
}

πŸ”§ Development Setup

Local Development (without Docker)

  1. Start PostgreSQL and Orthanc (keep these in Docker):
docker-compose up postgres orthanc -d
  1. Update connection strings for local development in appsettings.Development.json

  2. Run the API:

cd Server/src/GP_Server.Api
dotnet run

Database Migrations

# Add new migration
cd Server/src/GP_Server.Infrastructure
dotnet ef migrations add MigrationName --startup-project ../GP_Server.Api

# Update database
dotnet ef database update --startup-project ../GP_Server.Api

πŸ”„ AI Report Generation Workflow

  1. DICOM Upload: Medical images uploaded to Orthanc PACS server
  2. Queue Generation: Study queued for report generation
  3. Background Processing: ReportGenerationWorker processes the queue
  4. AI Analysis: DICOM sent to AI service for analysis
  5. Report Creation: AI response formatted into medical report
  6. SR Generation: DICOM Structured Report created and stored
  7. Status Update: Study status updated to "Generated" or "Failed"

AI Service Integration

The system expects an AI service at the configured endpoint that accepts:

  • Input: DICOM file via multipart/form-data
  • Output: JSON response with findings and impressions

Expected AI response format:

{
  "generated_report": {
    "findings": "Clinical findings text...",
    "impression": "Clinical impression text..."
  },
  "dicom_metadata": {
    "patient_id": "12345",
    "study_date": "20231201",
    "modality": "CT",
    "body_part": "CHEST"
  }
}

🐳 Docker Services

The docker-compose.yml includes:

  • api: Main .NET application (Port 8080)
  • postgres: PostgreSQL database (Port 5432)
  • orthanc: DICOM PACS server (Ports 8042, 4242)

πŸ“Š Default Users & Roles

The system seeds default data on startup:

Default Roles

  • SuperAdmin: Full system access
  • Admin: Administrative tasks
  • Doctor: Medical professional access
  • Technician: Technical operations

Default Users

Check the UserSeeder.cs for default user accounts.

πŸ”’ Security Features

  • JWT token authentication with configurable expiration
  • Role-based authorization on all endpoints
  • Secure password hashing with Identity framework
  • HTTPS support (configurable)
  • CORS policy for frontend integration
  • File upload validation for DICOM files

πŸ“ Project Structure

Server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ GP_Server.Api/           # Controllers, Program.cs, appsettings
β”‚   β”œβ”€β”€ GP_Server.Application/   # Services, DTOs, Interfaces, Background Services
β”‚   β”œβ”€β”€ GP_Server.Domain/        # Entities, Domain Logic
β”‚   └── GP_Server.Infrastructure/ # Data Access, Repositories, External Services
β”œβ”€β”€ docker-compose.yml           # Docker services configuration
β”œβ”€β”€ Dockerfile                   # Application container
└── README.md                    # This file

πŸ“– Additional Resources

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Note: This is a medical imaging system. Ensure compliance with healthcare regulations (HIPAA, GDPR, etc.) in your jurisdiction before deploying in production.

About

Backend for Automated Radiology Report Generation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.4%
  • Other 0.6%