Skip to content

sharpoverride/medicine_track2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MedicineTrack API

A comprehensive medication management system built with .NET Aspire that enables users to track medications, schedules, dosing logs, and potential drug interactions.

πŸ—οΈ Architecture

MedicineTrack follows a microservices architecture built on .NET Aspire, providing a scalable and cloud-native solution for medication management.

Services Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    API Gateway (Port 5000)                      β”‚
β”‚                   Route: /medicines/* /configs/*                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    MedicineTrack.Api            β”‚  β”‚  MedicineTrack.Configuration    β”‚
β”‚       (Port 5001)               β”‚  β”‚       (Port 5002)               β”‚
β”‚                                 β”‚  β”‚                                 β”‚
β”‚ β€’ Medication Management         β”‚  β”‚ β€’ Organization Management       β”‚
β”‚ β€’ Medication Logging            β”‚  β”‚ β€’ User Management               β”‚
β”‚ β€’ Drug Interaction Checking     β”‚  β”‚ β€’ System Configuration          β”‚
β”‚ β€’ Medication Database Lookup    β”‚  β”‚                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚                               β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Infrastructure                                β”‚
β”‚                                                                 β”‚
β”‚ β€’ PostgreSQL (Medication & Configuration DBs)                  β”‚
β”‚ β€’ Redis/Valkey (Caching)                                       β”‚
β”‚ β€’ Entity Framework Core (Data Access)                          β”‚
β”‚ β€’ Migrations (Database Schema Management)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

medicine_track/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ MedicineTrack.AppHost/              # .NET Aspire App Host
β”‚   β”œβ”€β”€ MedicineTrack.Api/                  # Main API service
β”‚   β”œβ”€β”€ MedicineTrack.Configuration/        # Configuration service
β”‚   β”œβ”€β”€ MedicineTrack.Gateway/              # API Gateway (YARP)
β”‚   β”œβ”€β”€ MedicineTrack.Medication.Data/      # Medication domain models
β”‚   β”œβ”€β”€ MedicineTrack.Configuration.Data/   # Configuration domain models
β”‚   β”œβ”€β”€ MedicineTrack.Medication.Migrations/    # Database migrations
β”‚   β”œβ”€β”€ MedicineTrack.Configuration.Migrations/ # Database migrations
β”‚   β”œβ”€β”€ MedicineTrack.Tests/                # Unit tests
β”‚   └── MedicineTrack.End2EndTests/         # End-to-end tests
β”œβ”€β”€ deploy-aspire.sh                        # Kubernetes deployment script
└── README.md

πŸš€ Features

Core Functionality

  • Medication Management: Create, read, update, and delete medications with detailed information
  • Flexible Scheduling: Support for complex medication regimens with multiple frequency types
  • Medication Logging: Track when medications are taken, skipped, or taken as needed
  • Drug Interaction Checking: Identify potential dangerous medication combinations
  • Medication Database: Search and lookup medications with NDC codes and detailed information
  • User Management: Multi-tenant system with organization and user management
  • Health Monitoring: Built-in health checks and observability

Scheduling System

Supports various frequency types:

  • Daily: Once or multiple times per day
  • Weekly: Specific days of the week
  • Monthly: Specific days of the month
  • As Needed: PRN medications
  • Custom Intervals: Every X days, weeks, or months

Data Models

Medication

  • Basic information (name, generic name, brand name, strength, form)
  • Physical properties (shape, color)
  • Lifecycle management (start date, end date, archival)
  • Multiple independent schedules

Schedule

  • Flexible frequency patterns
  • Multiple daily dosing times
  • Quantity and unit tracking
  • Day-of-week specifications

Medication Log

  • Timestamp tracking (taken vs. logged)
  • Status tracking (taken, skipped, as-needed)
  • Actual quantity taken
  • Schedule association
  • Notes and additional context

πŸ› οΈ Technology Stack

  • Framework: .NET 9.0 with ASP.NET Core Minimal APIs
  • Orchestration: .NET Aspire
  • Database: PostgreSQL with Entity Framework Core
  • Caching: Redis/Valkey
  • API Gateway: YARP (Yet Another Reverse Proxy)
  • Documentation: OpenAPI/Swagger
  • Testing: xUnit, End-to-end testing framework
  • Deployment: Kubernetes with Aspire integration

πŸ“‹ Prerequisites

πŸš€ Quick Start

Development with .NET Aspire

  1. Clone the repository

    git clone <repository-url>
    cd medicine_track
  2. Install .NET Aspire workload

    dotnet workload install aspire
  3. Run the application

    cd src
    dotnet run --project MedicineTrack.AppHost
  4. Access the services

    • Aspire Dashboard: http://localhost:15888
    • API Gateway: http://localhost:5000
    • Medicine API: http://localhost:5001
    • Configuration API: http://localhost:5002

API Documentation

Once running, access the OpenAPI documentation:

  • Gateway API: http://localhost:5000/openapi
  • Medicine API: http://localhost:5001/openapi
  • Configuration API: http://localhost:5002/openapi

πŸ“š API Endpoints

Medication Management (/medicines/users/{userId}/medications)

  • POST / - Create new medication
  • GET / - List user medications (with filtering)
  • GET /{medicationId} - Get specific medication
  • PUT /{medicationId} - Update medication
  • DELETE /{medicationId} - Archive medication

Medication Logging (/medicines/users/{userId})

  • POST /medications/{medicationId}/logs - Log medication dose
  • GET /medication-logs - Get all user logs
  • GET /medications/{medicationId}/logs - Get logs for specific medication
  • PUT /medication-logs/{logId} - Update log entry
  • DELETE /medication-logs/{logId} - Delete log entry

Medication Database (/medicines/medication-database)

  • GET /search - Search medication database

Drug Interactions (/medicines/users/{userId}/medication-interactions)

  • POST /check - Check for drug interactions

Organization Management (/configs/organizations)

  • POST / - Create organization
  • GET / - List organizations
  • GET /{organizationId} - Get specific organization
  • PUT /{organizationId} - Update organization
  • DELETE /{organizationId} - Delete organization

User Management (/configs/organizations/{organizationId}/users)

  • POST / - Create user
  • GET / - List users
  • GET /{userId} - Get specific user
  • PUT /{userId} - Update user
  • DELETE /{userId} - Delete user

πŸ§ͺ Testing

Unit Tests

cd src
dotnet test MedicineTrack.Tests

End-to-End Tests

cd src
dotnet test MedicineTrack.End2EndTests

HTTP Testing

Use the provided .http files in VS Code with the REST Client extension:

  • src/MedicineTrack.Api/Medicines.http
  • src/MedicineTrack.Api/Health.http
  • src/MedicineTrack.Configuration/MedicineTrack.Configuration.http
  • src/MedicineTrack.Gateway/MedicineTrack.Gateway.http

🚒 Deployment

Local Kubernetes Deployment

Use the provided deployment script:

./deploy-aspire.sh

This script will:

  1. Check prerequisites (kubectl, Docker, .NET SDK)
  2. Create Kubernetes namespace
  3. Build the application
  4. Generate Aspire manifest
  5. Convert to Kubernetes manifests using aspirate
  6. Deploy to local cluster
  7. Set up port forwarding

Manual Deployment Steps

  1. Build the application

    cd src
    dotnet build
  2. Generate Aspire manifest

    dotnet run --project MedicineTrack.AppHost --publisher manifest --output-path ../infra/aspire-manifest.json
  3. Install aspirate tool

    dotnet tool install -g aspirate
  4. Generate Kubernetes manifests

    cd infra
    aspirate generate \
      --input-path aspire-manifest.json \
      --output-path k8s-manifests \
      --namespace medicine-track \
      --container-registry docker.io \
      --container-image-tag latest
  5. Apply to Kubernetes

    kubectl apply -f k8s-manifests -n medicine-track

Environment Variables

Configure the following environment variables for production:

  • ASPNETCORE_ENVIRONMENT=Production
  • ConnectionStrings__DefaultConnection=<PostgreSQL connection string>
  • ConnectionStrings__Redis=<Redis connection string>

πŸ”§ Configuration

Database Configuration

The application uses Entity Framework Core with PostgreSQL. Database migrations are handled by dedicated migration projects:

  • MedicineTrack.Medication.Migrations
  • MedicineTrack.Configuration.Migrations

Caching Configuration

Redis/Valkey is used for caching. Configuration is handled through .NET Aspire's service discovery.

Gateway Configuration

The API Gateway uses YARP for reverse proxy functionality. Routes are configured in appsettings.json:

  • /medicines/* β†’ Medicine API
  • /configs/* β†’ Configuration API

πŸ“Š Monitoring and Observability

Health Checks

  • Gateway: GET /health
  • Medicine API: GET /health
  • Configuration API: GET /health

Aspire Dashboard

The Aspire dashboard provides comprehensive monitoring:

  • Service health and metrics
  • Distributed tracing
  • Log aggregation
  • Resource utilization

Access at: http://localhost:15888 (development) or via port forwarding (Kubernetes)

🀝 Contributing

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

Development Guidelines

  • Follow C# coding conventions
  • Use nullable reference types
  • Write unit tests for new features
  • Update API documentation
  • Ensure all tests pass before submitting

πŸ“ License

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

πŸ†˜ Support

For questions and support:

  • Create an issue in the GitHub repository
  • Check the API documentation for endpoint details
  • Review the test files for usage examples

🎯 Roadmap

  • Authentication and authorization
  • Real-time notifications
  • Mobile app integration
  • Advanced analytics and reporting
  • Integration with pharmacy systems
  • Machine learning for adherence predictions
  • Multi-language support
  • Offline capability

Built with ❀️ using .NET Aspire and modern cloud-native technologies.

About

Medicine Track project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •