Skip to content

Joeboy77/drug-guard_ghana-be

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DrugGuard Ghana Backend

A comprehensive Spring Boot backend application for the DrugGuard Ghana platform, providing drug verification, management, and analytics services for FDA Ghana.

πŸ₯ Overview

DrugGuard Ghana Backend is a robust API service that enables:

  • Drug Verification: QR code scanning and authenticity verification
  • Drug Management: CRUD operations for FDA drug database
  • Analytics: Comprehensive reporting and insights
  • Voice Processing: Multi-language voice recognition and text-to-speech
  • User Management: Admin authentication and authorization
  • Reporting System: Citizen drug report management

πŸš€ Features

Core Features

  • βœ… Drug Verification System - QR code scanning and authenticity checks
  • βœ… Drug Management - Complete CRUD operations for drug database
  • βœ… Analytics Dashboard - Comprehensive reporting and insights
  • βœ… Voice Processing - Multi-language voice recognition and TTS
  • βœ… User Authentication - JWT-based admin authentication
  • βœ… Drug Reporting - Citizen report submission and management
  • βœ… QR Code Generation - Dynamic QR code creation for drugs
  • βœ… Search Functionality - Advanced drug search capabilities

Security Features

  • πŸ” JWT-based authentication
  • πŸ›‘οΈ Role-based access control (FDA_ADMIN)
  • πŸ”’ Secure password encryption (BCrypt)
  • 🌐 CORS configuration
  • πŸ“ Request/response logging

API Features

  • πŸ“Š RESTful API design
  • πŸ” Advanced search capabilities
  • πŸ“± Pagination support
  • 🎯 Multi-language support (English, Twi, Ga, Ewe)
  • πŸ“ˆ Real-time analytics
  • πŸ—‚οΈ File upload support (QR codes, images)

πŸ› οΈ Technology Stack

  • Framework: Spring Boot 3.x
  • Language: Java 17+
  • Database: H2 (Development), MySQL/PostgreSQL (Production)
  • Security: Spring Security + JWT
  • Build Tool: Maven
  • API Documentation: OpenAPI/Swagger
  • Testing: JUnit 5, Mockito
  • Logging: SLF4J + Logback

πŸ“‹ Prerequisites

  • Java 17 or higher
  • Maven 3.6+
  • Git
  • IDE (IntelliJ IDEA, Eclipse, VS Code)

πŸš€ Quick Start

1. Clone the Repository

git clone <repository-url>
cd ghana-backend

2. Configure Database

Edit src/main/resources/application.properties:

# Database Configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password

# JPA Configuration
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true

# H2 Console (Development)
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

3. Build and Run

# Build the project
mvn clean install

# Run the application
mvn spring-boot:run

4. Access the Application

  • API Base URL: http://localhost:8080/api
  • H2 Console: http://localhost:8080/h2-console
  • Swagger UI: http://localhost:8080/swagger-ui.html

πŸ“š API Documentation

Authentication Endpoints

Login

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

{
  "username": "admin",
  "password": "password"
}

Validate Token

GET /api/auth/validate
Authorization: Bearer <jwt-token>

Drug Management Endpoints

Get All Drugs

GET /api/admin/drugs?page=0&size=20&sortBy=name&sortDirection=asc
Authorization: Bearer <jwt-token>

Create Drug

POST /api/admin/drugs
Authorization: Bearer <jwt-token>
Content-Type: application/json

{
  "name": "Paracetamol 500mg",
  "manufacturer": "ABC Pharmaceuticals",
  "batchNumber": "BATCH001",
  "registrationNumber": "FDA123456",
  "activeIngredient": "Paracetamol",
  "strength": "500mg",
  "dosageForm": "Tablet",
  "category": "Analgesic",
  "manufactureDate": "2024-01-01",
  "expiryDate": "2026-01-01",
  "description": "Pain reliever and fever reducer"
}

Search Drugs

GET /api/drugs/search?query=paracetamol&page=0&size=20

Verify Drug

POST /api/drugs/verify
Content-Type: application/json

{
  "qrCode": "drug_123_abc123",
  "location": "Accra, Ghana"
}

Public Drug Search

GET /api/public/drugs/search?query=paracetamol&page=0&size=20

Voice Processing Endpoints

Voice Recognition

POST /api/voice/recognize
Content-Type: multipart/form-data

audio: <audio-file>
language: en

Text to Speech

POST /api/voice/speak
Content-Type: application/json

{
  "text": "Hello, this is a test message",
  "language": "en"
}

Get Available Languages

GET /api/voice/languages

Drug Reporting Endpoints

Submit Report

POST /api/reports
Content-Type: application/json

{
  "drugName": "Suspicious Drug",
  "manufacturer": "Unknown",
  "description": "Found suspicious packaging",
  "issueType": "COUNTERFEIT",
  "severity": "HIGH",
  "location": "Accra",
  "contactInfo": "[email protected]"
}

Get Recent Reports

GET /api/reports/recent

Analytics Endpoints

Overview Statistics

GET /api/admin/analytics/overview
Authorization: Bearer <jwt-token>

Drug Analytics

GET /api/admin/analytics/drugs
Authorization: Bearer <jwt-token>

Scan Analytics

GET /api/admin/analytics/scans?days=30
Authorization: Bearer <jwt-token>

πŸ—‚οΈ Project Structure

src/main/java/com/drugguard/ghana/
β”œβ”€β”€ config/                 # Configuration classes
β”‚   β”œβ”€β”€ DataInitializer.java
β”‚   β”œβ”€β”€ DrugDataInitializer.java
β”‚   └── WebSecurityConfig.java
β”œβ”€β”€ controller/            # REST controllers
β”‚   β”œβ”€β”€ AdminController.java
β”‚   β”œβ”€β”€ AdminDrugController.java
β”‚   β”œβ”€β”€ AnalyticsController.java
β”‚   β”œβ”€β”€ AuthController.java
β”‚   β”œβ”€β”€ DrugReportController.java
β”‚   β”œβ”€β”€ HealthAiController.java
β”‚   β”œβ”€β”€ PublicDrugController.java
β”‚   β”œβ”€β”€ QrCodeController.java
β”‚   β”œβ”€β”€ SearchController.java
β”‚   └── VoiceController.java
β”œβ”€β”€ dto/                  # Data Transfer Objects
β”‚   β”œβ”€β”€ AdvancedSearchRequest.java
β”‚   β”œβ”€β”€ CreateDrugReportRequest.java
β”‚   β”œβ”€β”€ CreateDrugRequest.java
β”‚   β”œβ”€β”€ DrugReportResponse.java
β”‚   β”œβ”€β”€ DrugSearchRequest.java
β”‚   β”œβ”€β”€ DrugVerificationResponse.java
β”‚   β”œβ”€β”€ JwtResponse.java
β”‚   β”œβ”€β”€ LoginRequest.java
β”‚   β”œβ”€β”€ MessageResponse.java
β”‚   β”œβ”€β”€ PublicDrugResponse.java
β”‚   β”œβ”€β”€ QrCodeResponse.java
β”‚   β”œβ”€β”€ SearchResponse.java
β”‚   β”œβ”€β”€ SearchSuggestionsResponse.java
β”‚   └── UpdateDrugRequest.java
β”œβ”€β”€ model/                # Entity models
β”‚   β”œβ”€β”€ Drug.java
β”‚   β”œβ”€β”€ DrugReport.java
β”‚   β”œβ”€β”€ FdaAdmin.java
β”‚   └── ScanTracking.java
β”œβ”€β”€ repository/           # Data access layer
β”‚   β”œβ”€β”€ DrugReportRepository.java
β”‚   β”œβ”€β”€ DrugRepository.java
β”‚   β”œβ”€β”€ FdaAdminRepository.java
β”‚   └── ScanTrackingRepository.java
β”œβ”€β”€ security/            # Security configuration
β”‚   β”œβ”€β”€ AuthTokenFilter.java
β”‚   └── JwtUtils.java
β”œβ”€β”€ service/             # Business logic
β”‚   β”œβ”€β”€ AnalyticsService.java
β”‚   β”œβ”€β”€ AuthService.java
β”‚   β”œβ”€β”€ DrugReportService.java
β”‚   β”œβ”€β”€ DrugService.java
β”‚   β”œβ”€β”€ FdaAdminDetailsService.java
β”‚   β”œβ”€β”€ HealthAiService.java
β”‚   β”œβ”€β”€ QrCodeService.java
β”‚   β”œβ”€β”€ ScanTrackingService.java
β”‚   β”œβ”€β”€ SearchService.java
β”‚   └── VoiceProcessingService.java
└── DrugguardGhanaBackendApplication.java

πŸ”§ Configuration

Environment Variables

# Server Configuration
server.port=8080
server.servlet.context-path=/api

# Database Configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=password

# JWT Configuration
jwt.secret=your-secret-key
jwt.expiration=86400000

# File Upload Configuration
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

# Logging Configuration
logging.level.com.drugguard=DEBUG
logging.level.org.springframework.security=DEBUG

Security Configuration

The application uses Spring Security with JWT authentication:

  • Public Endpoints: /api/public/**, /api/auth/**, /api/drugs/search/**, /api/voice/**
  • Admin Endpoints: /api/admin/** (requires FDA_ADMIN role)
  • Protected Endpoints: All other endpoints require authentication

πŸ§ͺ Testing

Run Tests

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=DrugServiceTest

# Run with coverage
mvn test jacoco:report

Test Coverage

The project includes comprehensive tests for:

  • βœ… Service layer tests
  • βœ… Controller layer tests
  • βœ… Repository layer tests
  • βœ… Security configuration tests
  • βœ… Integration tests

πŸš€ Deployment

Docker Deployment

# Build Docker image
docker build -t drugguard-ghana-backend .

# Run container
docker run -p 8080:8080 drugguard-ghana-backend

Production Configuration

For production deployment:

  1. Database: Use MySQL or PostgreSQL
  2. Security: Configure proper JWT secrets
  3. Logging: Configure production logging levels
  4. Monitoring: Add health checks and metrics
  5. SSL: Configure HTTPS

πŸ“Š Monitoring & Health Checks

Health Endpoints

  • Health Check: GET /actuator/health
  • Info: GET /actuator/info
  • Metrics: GET /actuator/metrics

Logging

The application uses structured logging with different levels:

  • DEBUG: Detailed debugging information
  • INFO: General application information
  • WARN: Warning messages
  • ERROR: Error messages

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow Java coding conventions
  • Use meaningful variable and method names
  • Add proper documentation
  • Include unit tests for new features

πŸ“ License

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

πŸ†˜ Support

For support and questions:

πŸ™ Acknowledgments

  • FDA Ghana for regulatory guidance
  • Spring Boot community for the excellent framework
  • All contributors and stakeholders

DrugGuard Ghana Backend - Empowering drug safety and verification in Ghana πŸ‡¬πŸ‡­

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages