Skip to content

JoelHJames1/EMR-System

Repository files navigation

🏥 EMR System - Enterprise Electronic Medical Records

.NET License HL7 FHIR HIPAA Build Status

📋 Overview

A comprehensive, HL7 FHIR-compliant and HIPAA-ready Electronic Medical Records (EMR) system built with .NET 8, designed to digitize and streamline all aspects of healthcare operations. This enterprise-grade solution covers the complete spectrum of clinical, administrative, and financial workflows in modern healthcare facilities.

⚖️ LICENSE NOTICE

Copyright © 2025 Joel Hernandez James. All Rights Reserved.

This software is PROPRIETARY AND CONFIDENTIAL. Unauthorized copying, distribution, modification, or use of this software is STRICTLY PROHIBITED and will result in legal action including:

  • 💼 Civil damages up to $150,000 per violation under U.S. Copyright Act
  • ⚖️ Criminal prosecution with fines up to $250,000 and 5 years imprisonment
  • 🚫 Permanent injunctions and seizure of unauthorized copies
  • 💰 Full recovery of legal fees and litigation costs

This is NOT open source software. For commercial licensing, SaaS partnerships, or permission requests, contact Joel Hernandez James via the information in LICENSE.txt.

🎯 Key Features

  • HL7 FHIR Standard Compliance - Aligned with international healthcare data standards
  • 🔐 Enterprise Security - JWT authentication with role-based access control (RBAC)
  • 🏥 Complete Clinical Workflow - From patient registration to discharge
  • 💊 Medication Management - Prescription tracking with DEA controlled substance support
  • 🧪 Laboratory Integration - Orders, results, and LOINC coding
  • 💰 Billing & Insurance - Claims processing with CPT/ICD-10 coding
  • 📊 Clinical Documentation - SOAP notes, diagnoses, procedures
  • 📱 RESTful API - Modern API architecture with Swagger documentation
  • 🔄 Interoperability Ready - Designed for integration with external systems

🏗️ Architecture

Technology Stack

Frontend:  React 18.2 + Material-UI 5 + Framer Motion
Backend:   ASP.NET Core 8.0 Web API
ORM:       Entity Framework Core 8.0.11
Database:  SQL Server 2019+
Auth:      JWT Bearer Token with Refresh Token
Logging:   NLog
API Docs:  Swagger/OpenAPI 3.0
Charts:    Recharts 3.2.1
Forms:     React Hook Form 7.63.0

Layered Architecture

┌─────────────────────────────────┐
│    Presentation Layer           │  React Frontend / Swagger UI
├─────────────────────────────────┤
│    API Layer                    │  Controllers (RESTful)
├─────────────────────────────────┤
│    Business Logic Layer         │  Services & Domain Logic
├─────────────────────────────────┤
│    Data Access Layer            │  Repositories + EF Core
├─────────────────────────────────┤
│    Database Layer               │  SQL Server
└─────────────────────────────────┘

📊 Database Schema

HL7 FHIR Core Resources (27 Entities)

👥 Patient Management

  • Patient - Complete demographics, contacts, insurance
  • FamilyHistory - Hereditary conditions and family medical history
  • Allergy - Drug/food/environmental allergies with severity
  • Immunization - Vaccination records with CVX codes

🏥 Clinical Workflow

  • Encounter - Patient-provider interactions (visits, admissions)
  • Diagnosis - ICD-10/ICD-11 coded conditions
  • Procedure - CPT coded surgical/diagnostic procedures
  • Observation - LOINC coded clinical measurements
  • ClinicalNote - SOAP format documentation
  • VitalSign - Temperature, BP, heart rate, oxygen saturation
  • CarePlan - Treatment plans and care coordination
  • CarePlanActivity - Individual care plan tasks

💊 Medication Management

  • Medication - Drug database with NDC codes
  • Prescription - Dosage, frequency, refills
  • DEA Schedule support for controlled substances

🧪 Laboratory & Diagnostics

  • LabOrder - Test requisitions with priority
  • LabResult - Results with reference ranges and flags
  • LOINC code support

📅 Scheduling & Referrals

  • Appointment - Scheduling with status workflow
  • Referral - Specialist referrals and consults
  • Location - Rooms, wards, facilities
  • Department - Hospital departments and specialties

💰 Billing & Financial

  • Billing - Invoicing and payment tracking
  • BillingItem - Line items with CPT/ICD codes
  • Insurance - Policy information and claims

👨‍⚕️ Provider & Administration

  • Provider - Physicians, nurses, specialists
  • User - System users with role assignments
  • Document - Clinical documents and reports
  • MedicalRecord - Legacy medical records

Medical Coding Standards Support

Standard Purpose Implementation
ICD-10/11 Diagnosis coding Diagnosis.ICDCode
CPT Procedure coding Procedure.CPTCode, BillingItem.CPTCode
NDC Medication identification Medication.NDC
LOINC Lab observations Observation.ObservationCode
CVX Vaccine codes Immunization.CVXCode
SNOMED CT Clinical terminology Procedure.SNOMEDCode
DEA Controlled substances Medication.DEASchedule

🏥 HL7 FHIR Compliance Explained

What is HL7 FHIR?

HL7 FHIR (Fast Healthcare Interoperability Resources) is the latest standard for exchanging healthcare information electronically, developed by Health Level Seven International (HL7). It's designed to enable seamless data exchange between different healthcare systems worldwide.

Why This System is HL7 FHIR Compliant

This EMR system implements HL7 FHIR compliance through:

1. FHIR Resource Mapping

Our database entities are designed following FHIR resource specifications:

Our Entity FHIR Resource Compliance Level
Patient Patient Resource ✅ Full - Demographics, identifiers, contact, communication preferences
Encounter Encounter Resource ✅ Full - Visit types, status, class, period, participant, location
Observation Observation Resource ✅ Full - Vital signs, lab results, clinical findings with LOINC codes
Condition (Diagnosis) Condition Resource ✅ Full - Clinical status, verification status, severity, onset/abatement dates
Procedure Procedure Resource ✅ Full - Status, category, code, performed date, outcome, complications
MedicationRequest (Prescription) MedicationRequest Resource ✅ Full - Intent, medication, dosage, dispense request, substitution
AllergyIntolerance AllergyIntolerance Resource ✅ Full - Type, category, criticality, onset, reaction
Immunization Immunization Resource ✅ Full - Status, vaccine code (CVX), occurrence, site, route, dose quantity
CarePlan CarePlan Resource ✅ Full - Intent, status, category, activity, goal
ServiceRequest (Referral) ServiceRequest Resource ✅ Full - Intent, priority, code, occurrence, reason
DiagnosticReport (Lab Results) DiagnosticReport Resource ✅ Full - Status, category, code, results, conclusion
Location Location Resource ✅ Full - Status, name, type, address, managing organization

2. Medical Coding Standards Integration

We implement international coding standards mandated by FHIR:

  • ICD-10/11 Codes: Diagnosis classification (WHO standard)
  • CPT Codes: Procedure and service coding (AMA standard)
  • LOINC Codes: Laboratory and clinical observations (Regenstrief Institute)
  • SNOMED CT: Clinical terminology for procedures and findings
  • CVX Codes: Vaccine identification (CDC standard)
  • NDC Codes: National Drug Code for medications (FDA standard)
  • RxNorm: Normalized names for clinical drugs

3. FHIR Data Types Implementation

Our entities use FHIR-compliant data types:

// CodeableConcept - For coded values
public string ICDCode { get; set; }            // code
public string DiagnosisDescription { get; set; } // display text

// Period - For date ranges
public DateTime? StartDate { get; set; }       // start
public DateTime? EndDate { get; set; }         // end

// Quantity - For measurements
public decimal? ValueNumeric { get; set; }     // value
public string? Unit { get; set; }              // unit

// Identifier - For unique IDs
public string EncounterNumber { get; set; }    // system + value
public string NPI { get; set; }                // National Provider Identifier

4. FHIR Workflow Status Tracking

We implement FHIR-defined status values:

  • Encounter: Planned | Arrived | InProgress | Finished | Cancelled
  • Observation: Registered | Preliminary | Final | Amended | Corrected | Cancelled
  • MedicationRequest: Active | Completed | Cancelled | Stopped
  • Condition: Active | Recurrence | Relapse | Inactive | Remission | Resolved
  • Procedure: Preparation | InProgress | NotDone | OnHold | Stopped | Completed

5. FHIR RESTful API Design

Our API follows FHIR RESTful principles:

GET    /api/Patient/{id}              # Read
POST   /api/Patient                   # Create
PUT    /api/Patient/{id}              # Update
DELETE /api/Patient/{id}              # Delete
GET    /api/Patient?name=John         # Search
GET    /api/Encounter/patient/{id}    # Reference search

6. Interoperability Ready

The system is designed to:

  • ✅ Export data in FHIR JSON/XML format (DTOs can be serialized to FHIR format)
  • ✅ Accept FHIR resources as input (DTOs match FHIR resource structure)
  • ✅ Support FHIR search parameters (implemented in repository layer)
  • ✅ Implement FHIR references between resources (foreign keys)
  • ✅ Support FHIR bundles for batch operations (transaction support)

Benefits of FHIR Compliance

  1. Interoperability: Seamlessly exchange data with other healthcare systems, EHRs, and health information exchanges (HIEs)
  2. Standardization: Follow internationally recognized healthcare data standards
  3. Future-Proof: Easy integration with emerging healthcare technologies and AI systems
  4. Regulatory Compliance: Meet meaningful use requirements and government mandates
  5. Patient Access: Enable patient portals and mobile apps to access health data via FHIR APIs

🔒 HIPAA Compliance Explained

What is HIPAA?

HIPAA (Health Insurance Portability and Accountability Act) is a U.S. federal law that sets standards for protecting sensitive patient health information from being disclosed without patient consent or knowledge.

Why This System is HIPAA-Ready

This EMR system implements technical, physical, and administrative safeguards required for HIPAA compliance:

1. Access Controls (§164.312(a)(1))

User Authentication

// JWT Bearer Token Authentication
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)

// Password Requirements: 8+ chars, uppercase, lowercase, digit, special char
// Account lockout after 5 failed attempts

Role-Based Access Control (RBAC)

// 6 Predefined Healthcare Roles
[Authorize(Roles = "Administrator,Doctor,Nurse")]

// Roles: Administrator, Doctor, Nurse, Receptionist, Lab Technician, Billing Staff
// Each role has specific permissions to access only necessary PHI

Unique User Identification

  • Every user has a unique UserId (GUID)
  • All actions tracked with user attribution (CreatedBy, ModifiedBy)

2. Audit Controls (§164.312(b))

Audit Trail for All PHI Access

public DateTime CreatedDate { get; set; }      // When record was created
public DateTime? ModifiedDate { get; set; }    // When record was modified
public string? CreatedBy { get; set; }         // Who created the record
public string? ModifiedBy { get; set; }        // Who modified the record

NLog Comprehensive Logging

  • All API requests logged with timestamp, user, and action
  • Failed login attempts logged
  • Data access patterns tracked
  • Error logs maintained for security incident investigation

3. Integrity Controls (§164.312(c)(1))

Data Integrity Protection

// Entity Framework Core with parameterized queries (SQL injection prevention)
// Data validation at multiple layers (DTOs, Models, Database constraints)
// Transaction support for atomic operations
// Foreign key constraints for referential integrity

Electronic Signature Support

public bool IsSigned { get; set; }             // Document signature status
public DateTime? SignedDate { get; set; }      // When document was signed
public string? SignedBy { get; set; }          // Who signed the document

4. Transmission Security (§164.312(e)(1))

Encrypted Data Transmission

// HTTPS/TLS 1.2+ enforced for all API communications
app.UseHttpsRedirection();

// JWT tokens encrypted with HMAC-SHA256
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey));
var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

Secure API Architecture

  • All endpoints require authentication (except login/register)
  • API keys and secrets stored in environment variables (not in code)
  • CORS configured for specific origins only

5. Person or Entity Authentication (§164.312(d))

Multi-Factor Authentication Ready

  • JWT access tokens (short-lived: 24 hours)
  • Refresh tokens for extended sessions
  • Password complexity requirements enforced
  • Session management and token expiration

6. Encryption and Decryption (§164.312(a)(2)(iv))

Data at Rest Protection

// SQL Server Transparent Data Encryption (TDE) support
// ASP.NET Core Data Protection for sensitive fields
// Password hashing with PBKDF2 (ASP.NET Core Identity default)

Data in Transit Protection

  • All communications over HTTPS with TLS 1.2+
  • JWT tokens encrypted
  • Database connections encrypted (TrustServerCertificate configuration)

7. Automatic Logoff (§164.312(a)(2)(iii))

Session Management

"ExpireHours": "24"  // JWT tokens expire after 24 hours

// Frontend: Token expiration handling
// Backend: 401 Unauthorized responses trigger re-authentication

8. Emergency Access Procedure

Administrator Override Capability

// Administrator role has elevated privileges for emergency access
[Authorize(Roles = "Administrator")]

// All administrator actions logged for audit trail
_logger.LogWarning("Administrator emergency access: {Action}", action);

9. Minimum Necessary Standard

DTOs for Data Minimization

  • API returns only necessary data fields via DTOs
  • Sensitive fields (SSN, full medical history) require elevated permissions
  • Search results return limited information
  • Full details require explicit request with proper authorization

10. Business Associate Agreements (BAA)

This system provides:

  • ✅ Comprehensive audit logs for BAA compliance reporting
  • ✅ Data export capabilities for patient requests (HIPAA Right of Access)
  • ✅ Data retention policies (soft deletes with IsActive flags)
  • ✅ Breach notification support through logging and monitoring

Additional HIPAA Compliance Features

De-identification Support

// System supports creating de-identified datasets for research
// Can remove 18 HIPAA identifiers as specified in §164.514(b)(2)

Patient Rights Support

  • ✅ Right to Access: API endpoints for patient data export
  • ✅ Right to Amendment: Update and correction workflows
  • ✅ Right to Accounting: Audit logs track all PHI disclosures
  • ✅ Right to Restriction: IsActive flags support data suppression

Breach Notification Readiness

  • Comprehensive logging enables breach investigation
  • Timestamp tracking for 60-day notification requirement
  • User action audit trail for identifying scope of breach

What This System Does NOT Include (Requires Infrastructure)

⚠️ Important: Full HIPAA compliance requires organizational policies and infrastructure beyond the software:

  • 📋 Administrative Safeguards: Requires organizational policies, workforce training, contingency plans
  • 🏢 Physical Safeguards: Requires facility access controls, workstation security, device management
  • 💾 Backup and Disaster Recovery: Requires backup systems and disaster recovery plans
  • 🔐 Hardware Security: Requires encrypted storage devices, secure data centers
  • 📝 Business Associate Agreements: Must be executed with all third-party service providers
  • 👥 Workforce Training: Required annual HIPAA training for all system users
  • 📊 Risk Assessment: Required periodic security risk assessments

HIPAA Compliance Checklist

HIPAA Requirement Implementation Status
Access Control JWT + RBAC + Account Lockout
Audit Controls Comprehensive logging with NLog
Integrity Data validation + EF Core transactions
Transmission Security HTTPS/TLS 1.2+
Authentication JWT tokens + password policies
Encryption TLS + SQL Server TDE support
Automatic Logoff Token expiration
Emergency Access Administrator override
Minimum Necessary DTOs + role-based data filtering
Audit Trail CreatedBy/ModifiedBy + timestamps
Physical Safeguards Requires infrastructure ⚠️
Administrative Safeguards Requires policies ⚠️
Backup/DR Requires infrastructure ⚠️
BAA Requires legal agreements ⚠️

🚀 Getting Started

Prerequisites

Installation

1. Clone the Repository

git clone https://github.com/JoelHJames1/EMR-System.git
cd EMR-System

2. Configure Database Connection

Edit EMRWebAPI/appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=YOUR_SERVER;Database=EMRSystemDB;Trusted_Connection=True;TrustServerCertificate=True"
  }
}

For LocalDB (Development):

"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=EMRSystemDB;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True"

3. Update JWT Configuration (Required for Security)

⚠️ Important: Change the JWT secret key in production!

{
  "Jwt": {
    "Key": "YOUR-SECURE-SECRET-KEY-AT-LEAST-32-CHARACTERS-LONG",
    "Issuer": "EMRSystem",
    "Audience": "EMRSystemUsers",
    "ExpireHours": "24"
  }
}

4. Restore NuGet Packages

cd EMRWebAPI
dotnet restore

5. Create Database and Apply Migrations

# Create initial migration (if not exists)
dotnet ef migrations add InitialCreate --project ../EMRDataLayer --startup-project .

# Apply migrations to database
dotnet ef database update --project ../EMRDataLayer --startup-project .

6. Run the Application

dotnet run

API URL: https://localhost:7099 Swagger UI: https://localhost:7099/swagger

Frontend Setup

cd EMRWEB
npm install
npm start

Frontend URL: http://localhost:3000

The frontend will automatically proxy API requests to https://localhost:7099.

🔐 Authentication & Authorization

Default Roles

The system implements 6 predefined healthcare roles with granular permissions. For detailed information about each role including responsibilities, workflows, and permission matrix, see ROLES.md.

Role Permissions Use Case
Administrator Full system access System configuration, user management
Doctor Clinical records, prescriptions, orders Physicians, specialists
Nurse Patient care, vitals, medication admin Nursing staff
Receptionist Appointments, patient registration Front desk
Lab Technician Lab orders and results Laboratory staff
Billing Staff Billing, insurance, payments Financial department

Authentication Flow

  1. Register User (Admin only):
POST /api/Auth/register
{
  "firstName": "John",
  "lastName": "Doe",
  "email": "john.doe@hospital.com",
  "phoneNumber": "+1234567890",
  "password": "SecureP@ss123",
  "confirmPassword": "SecureP@ss123",
  "roles": ["Doctor"]
}
  1. Login:
POST /api/Auth/login
{
  "email": "john.doe@hospital.com",
  "password": "SecureP@ss123"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "base64-encoded-refresh-token",
  "user": {
    "id": "user-guid",
    "email": "john.doe@hospital.com",
    "firstName": "John",
    "lastName": "Doe",
    "roles": ["Doctor"]
  }
}
  1. Use Token in Requests:
GET /api/Auth/profile
Authorization: Bearer {your-jwt-token}

📚 API Documentation

Swagger UI

Navigate to https://localhost:7099/swagger for interactive API documentation.

Core API Endpoints

Authentication

  • POST /api/Auth/register - Register new user (Admin)
  • POST /api/Auth/login - User login
  • POST /api/Auth/refresh-token - Refresh access token
  • GET /api/Auth/profile - Get current user profile
  • POST /api/Auth/logout - Logout user

Patient Management

  • GET /api/Patient - List all patients
  • GET /api/Patient/{id} - Get patient details
  • POST /api/Patient - Register new patient
  • PUT /api/Patient/{id} - Update patient
  • DELETE /api/Patient/{id} - Deactivate patient

Clinical Workflow

  • POST /api/Encounter - Create encounter
  • POST /api/Diagnosis - Add diagnosis
  • POST /api/Procedure - Schedule/record procedure
  • POST /api/Observation - Record observation
  • POST /api/ClinicalNote - Create SOAP note

Medications

  • GET /api/Medication - List medications
  • POST /api/Prescription - Create prescription
  • GET /api/Prescription/patient/{id} - Patient prescriptions

Laboratory

  • POST /api/LabOrder - Create lab order
  • POST /api/LabResult - Enter lab results
  • GET /api/LabOrder/patient/{id} - Patient lab orders

Billing

  • POST /api/Billing - Create invoice
  • POST /api/Insurance - Add insurance
  • GET /api/Billing/patient/{id} - Patient billing history

See TECHNICAL_DOCUMENTATION.md for complete API specifications

🔒 Security Features

1. Authentication & Authorization

  • ✅ JWT Bearer Token authentication
  • ✅ Role-based access control (RBAC)
  • ✅ Policy-based authorization
  • ✅ Refresh token mechanism

2. Password Security

  • ✅ Minimum 8 characters
  • ✅ Requires uppercase, lowercase, digit, special character
  • ✅ PBKDF2 hashing (ASP.NET Core Identity)
  • ✅ Account lockout after 5 failed attempts

3. Data Protection

  • ✅ HTTPS enforcement
  • ✅ SQL injection prevention (parameterized queries)
  • ✅ Input validation
  • ✅ CORS configuration

4. Audit Trail

  • ✅ CreatedBy/ModifiedBy tracking
  • ✅ Timestamp tracking
  • ✅ NLog logging
  • ✅ User action tracking

5. HIPAA Compliance Considerations

  • ✅ Encrypted data transmission (HTTPS/TLS)
  • ✅ Access controls and user authentication
  • ✅ Audit logging
  • ✅ Data backup capabilities
  • ⚠️ Note: Full HIPAA compliance requires additional infrastructure controls

📈 Database Migrations

Create New Migration

dotnet ef migrations add MigrationName --project EMRDataLayer --startup-project EMRWebAPI

Apply Migrations

dotnet ef database update --project EMRDataLayer --startup-project EMRWebAPI

Rollback Migration

dotnet ef database update PreviousMigrationName --project EMRDataLayer --startup-project EMRWebAPI

Remove Last Migration

dotnet ef migrations remove --project EMRDataLayer --startup-project EMRWebAPI

🧪 Testing

Run Unit Tests

dotnet test

API Testing

Use Swagger UI (/swagger) or tools like:

📦 Deployment

Development

dotnet run --environment Development

Production

  1. Publish Application:
dotnet publish -c Release -o ./publish
  1. Configure Production Settings:

    • Update appsettings.Production.json
    • Set secure JWT key via environment variables
    • Configure production database connection
    • Enable HTTPS/TLS certificates
  2. Deploy to:

    • Azure App Service
    • AWS Elastic Beanstalk
    • Docker containers
    • IIS (Windows Server)
    • Linux with Nginx/Apache

Docker Deployment (Optional)

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["EMRWebAPI/EMRWebAPI.csproj", "EMRWebAPI/"]
COPY ["EMRDataLayer/EMRDataLayer.csproj", "EMRDataLayer/"]
RUN dotnet restore "EMRWebAPI/EMRWebAPI.csproj"
COPY . .
WORKDIR "/src/EMRWebAPI"
RUN dotnet build "EMRWebAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "EMRWebAPI.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EMRWebAPI.dll"]

🗂️ Project Structure

EMR-System/
├── 📁 EMRDataLayer/              # Data Access Layer
│   ├── 📁 Model/                 # Entity Models (27 entities)
│   │   ├── Patient.cs
│   │   ├── Encounter.cs
│   │   ├── Diagnosis.cs
│   │   ├── Procedure.cs
│   │   ├── Observation.cs
│   │   ├── ClinicalNote.cs
│   │   ├── Prescription.cs
│   │   ├── Medication.cs
│   │   ├── LabOrder.cs
│   │   ├── LabResult.cs
│   │   ├── Allergy.cs
│   │   ├── Immunization.cs
│   │   ├── Billing.cs
│   │   ├── BillingItem.cs
│   │   ├── Insurance.cs
│   │   ├── Appointment.cs
│   │   ├── Referral.cs
│   │   ├── CarePlan.cs
│   │   ├── CarePlanActivity.cs
│   │   ├── Provider.cs
│   │   ├── Location.cs
│   │   ├── Department.cs
│   │   ├── Document.cs
│   │   ├── MedicalRecord.cs
│   │   ├── FamilyHistory.cs
│   │   ├── User.cs
│   │   └── Address.cs
│   ├── 📁 DataContext/
│   │   └── EMRDbContext.cs       # EF Core DbContext
│   ├── 📁 Repository/            # Repository Pattern (18 repositories)
│   │   ├── 📁 IRepository/       # Repository Interfaces
│   │   │   ├── IRepository.cs    # Base repository interface
│   │   │   ├── IPatientRepository.cs
│   │   │   ├── IAppointmentRepository.cs
│   │   │   ├── IEncounterRepository.cs
│   │   │   ├── IDiagnosisRepository.cs
│   │   │   ├── IProcedureRepository.cs
│   │   │   ├── IPrescriptionRepository.cs
│   │   │   ├── IMedicationRepository.cs
│   │   │   ├── ILabOrderRepository.cs
│   │   │   ├── ILabResultRepository.cs
│   │   │   ├── IAllergyRepository.cs
│   │   │   ├── IImmunizationRepository.cs
│   │   │   ├── IObservationRepository.cs
│   │   │   ├── IClinicalNoteRepository.cs
│   │   │   ├── ICarePlanRepository.cs
│   │   │   ├── IReferralRepository.cs
│   │   │   ├── IProviderRepository.cs
│   │   │   ├── IBillingRepository.cs
│   │   │   ├── IInsuranceRepository.cs
│   │   │   ├── IUserRepository.cs
│   │   │   └── IAddressRepository.cs
│   │   ├── Repository.cs         # Base repository implementation
│   │   ├── PatientRepository.cs
│   │   ├── AppointmentRepository.cs
│   │   ├── EncounterRepository.cs
│   │   ├── DiagnosisRepository.cs
│   │   ├── ProcedureRepository.cs
│   │   ├── PrescriptionRepository.cs
│   │   ├── MedicationRepository.cs
│   │   ├── LabOrderRepository.cs
│   │   ├── LabResultRepository.cs
│   │   ├── AllergyRepository.cs
│   │   ├── ImmunizationRepository.cs
│   │   ├── ObservationRepository.cs
│   │   ├── ClinicalNoteRepository.cs
│   │   ├── CarePlanRepository.cs
│   │   ├── ReferralRepository.cs
│   │   ├── ProviderRepository.cs
│   │   ├── BillingRepository.cs
│   │   └── InsuranceRepository.cs
│   └── 📁 Migrations/            # EF Migrations
│
├── 📁 EMRWebAPI/                 # API Layer
│   ├── 📁 Controllers/           # API Controllers (19 controllers)
│   │   ├── AuthController.cs     # Authentication & authorization
│   │   ├── UserController.cs     # User management
│   │   ├── PatientController.cs  # Patient registration & demographics
│   │   ├── AppointmentController.cs # Appointment scheduling
│   │   ├── EncounterController.cs   # Clinical visits & encounters
│   │   ├── DiagnosisController.cs   # Diagnosis management
│   │   ├── ProcedureController.cs   # Medical procedures
│   │   ├── PrescriptionController.cs # Prescription management
│   │   ├── MedicationController.cs  # Medication database
│   │   ├── LabOrderController.cs    # Laboratory orders
│   │   ├── LabResultController.cs   # Lab results entry
│   │   ├── ObservationController.cs # Vital signs & observations
│   │   ├── AllergyController.cs     # Allergy tracking
│   │   ├── ImmunizationController.cs # Vaccine records
│   │   ├── ClinicalNoteController.cs # SOAP notes
│   │   ├── CarePlanController.cs    # Care plan management
│   │   ├── ReferralController.cs    # Patient referrals
│   │   ├── ProviderController.cs    # Provider management
│   │   ├── BillingController.cs     # Billing & invoices
│   │   └── InsuranceController.cs   # Insurance management
│   ├── 📁 Services/              # Business Logic (16 services)
│   │   ├── 📁 IServices/         # Service Interfaces
│   │   │   ├── IUserService.cs
│   │   │   ├── IPatientService.cs
│   │   │   ├── IAppointmentService.cs
│   │   │   ├── IEncounterService.cs
│   │   │   ├── IDiagnosisService.cs
│   │   │   ├── IProcedureService.cs
│   │   │   ├── IPrescriptionService.cs
│   │   │   ├── IMedicationService.cs
│   │   │   ├── ILabOrderService.cs
│   │   │   ├── IAllergyService.cs
│   │   │   ├── IImmunizationService.cs
│   │   │   ├── IObservationService.cs
│   │   │   ├── ICarePlanService.cs
│   │   │   ├── IReferralService.cs
│   │   │   ├── IProviderService.cs
│   │   │   ├── IBillingService.cs
│   │   │   └── IInsuranceService.cs
│   │   ├── JwtService.cs
│   │   ├── UserService.cs
│   │   ├── PatientService.cs
│   │   ├── AppointmentService.cs
│   │   ├── EncounterService.cs
│   │   ├── DiagnosisService.cs
│   │   ├── ProcedureService.cs
│   │   ├── PrescriptionService.cs
│   │   ├── MedicationService.cs
│   │   ├── LabOrderService.cs
│   │   ├── AllergyService.cs
│   │   ├── ImmunizationService.cs
│   │   ├── ObservationService.cs
│   │   ├── CarePlanService.cs
│   │   ├── ReferralService.cs
│   │   ├── ProviderService.cs
│   │   ├── BillingService.cs
│   │   └── InsuranceService.cs
│   ├── 📁 Model/                 # DTOs (20 data transfer objects)
│   │   ├── LoginDTO.cs
│   │   ├── RegisterDto.cs
│   │   ├── UserDto.cs
│   │   ├── AddressDto.cs
│   │   ├── TokenOptions.cs
│   │   ├── PatientDto.cs
│   │   ├── AppointmentDto.cs
│   │   ├── EncounterDto.cs
│   │   ├── DiagnosisDto.cs
│   │   ├── ProcedureDto.cs
│   │   ├── PrescriptionDto.cs
│   │   ├── MedicationDto.cs
│   │   ├── LabOrderDto.cs
│   │   ├── LabResultDto.cs
│   │   ├── AllergyDto.cs
│   │   ├── ImmunizationDto.cs
│   │   ├── ObservationDto.cs
│   │   ├── ClinicalNoteDto.cs
│   │   ├── CarePlanDto.cs
│   │   ├── ReferralDto.cs
│   │   ├── ProviderDto.cs
│   │   ├── BillingDto.cs
│   │   ├── InsuranceDto.cs
│   │   ├── LocationDto.cs
│   │   └── DepartmentDto.cs
│   ├── 📁 AutoMapper/            # Object Mapping
│   ├── Program.cs                # Application Entry
│   ├── appsettings.json          # Configuration
│   └── appsettings.Development.json
│
├── 📁 EMRWEB/                    # React Frontend
│   ├── 📁 src/
│   │   ├── 📁 components/        # React Components
│   │   │   ├── Login.js          # Modern login with animations
│   │   │   ├── DashboardLayout.js # Main layout with navigation
│   │   │   ├── UserContext.js    # Auth context
│   │   │   └── 📁 Dashboard/     # Feature modules
│   │   │       ├── EnhancedDashboard.js       # Analytics & statistics
│   │   │       ├── PatientManagement.js       # Patient CRUD
│   │   │       ├── AppointmentManagement.js   # Scheduling
│   │   │       ├── EncounterManagement.js     # Clinical visits
│   │   │       ├── PrescriptionManagement.js  # Medications
│   │   │       ├── LabOrderManagement.js      # Lab tests
│   │   │       ├── VitalsManagement.js        # Vital signs
│   │   │       ├── AllergyImmunizationManagement.js # Allergies/Vaccines
│   │   │       └── BillingManagement.js       # Invoices/Payments
│   │   ├── 📁 services/          # API Services
│   │   │   └── api.js            # Axios API layer (all endpoints)
│   │   ├── 📁 utils/             # Utilities
│   │   │   └── printDocument.js  # Document printing
│   │   └── App.js                # Main app with routing
│   ├── 📁 public/
│   └── package.json
│
├── 📄 README.md                  # This file
├── 📄 TECHNICAL_DOCUMENTATION.md # Detailed technical docs
├── 📄 ROLES.md                   # Healthcare roles documentation
├── 📄 LICENSE.txt                # MIT License
└── 📄 .gitignore

🎨 Frontend Components

1. EnhancedDashboard - Analytics & Real-Time Statistics

File: EMRWEB/src/components/Dashboard/EnhancedDashboard.js

Features:

  • Real-time statistics cards with trend indicators (patients, appointments, prescriptions, lab orders)
  • Interactive charts: Area chart (30-day appointments), Pie chart (lab order status)
  • Financial overview with collection rate calculation
  • Provider workload leaderboard (top 5 providers)
  • Recent activity feed (48-hour window)

Backend Integration:

dashboardAPI.getStatistics()           GET /api/Dashboard/statistics
dashboardAPI.getAppointmentStats(30)   GET /api/Dashboard/appointments?days=30
dashboardAPI.getLabStats()             GET /api/Dashboard/lab-statistics
dashboardAPI.getBillingSummary(30)     GET /api/Dashboard/billing-summary?days=30
dashboardAPI.getProviderWorkload(30)   GET /api/Dashboard/provider-workload?days=30
dashboardAPI.getActivity(48)           GET /api/Dashboard/recent-activity?hours=48

Controllers Used: DashboardController.cs


2. PatientManagement - Patient CRUD Operations

File: EMRWEB/src/components/Dashboard/PatientManagement.js

Features:

  • Patient list with search functionality
  • Create/Edit patient demographics (name, DOB, gender, contact, address, insurance)
  • View patient details with tabs (Demographics, Allergies, Immunizations)
  • Delete/deactivate patients
  • Form validation with react-hook-form

Backend Integration:

patientAPI.getAll()          GET /api/Patient
patientAPI.getById(id)       GET /api/Patient/{id}
patientAPI.create(data)      POST /api/Patient
patientAPI.update(id, data)  PUT /api/Patient/{id}
patientAPI.delete(id)        DELETE /api/Patient/{id}

Controllers Used: PatientController.cs Entities: Patient, Allergy, Immunization


3. AppointmentManagement - Scheduling System

File: EMRWEB/src/components/Dashboard/AppointmentManagement.js

Features:

  • Calendar view with appointment listing
  • Create appointments (patient, provider, date/time, type, reason)
  • Status workflow: Scheduled → Confirmed → CheckedIn → Completed/Cancelled
  • Patient and provider dropdowns
  • Appointment types: Consultation, Follow-up, Procedure, Lab Work, Imaging

Backend Integration:

appointmentAPI.getAll()            GET /api/Appointment
appointmentAPI.create(data)        POST /api/Appointment
appointmentAPI.updateStatus(id)    PUT /api/Appointment/{id}/status
appointmentAPI.cancel(id)          PUT /api/Appointment/{id}/cancel

Controllers Used: AppointmentController.cs Entities: Appointment, Patient, Provider


4. EncounterManagement - Clinical Visit Tracking

File: EMRWEB/src/components/Dashboard/EncounterManagement.js

Features:

  • Patient selection sidebar
  • Create encounters (type, provider, reason for visit)
  • Encounter types: Outpatient, Inpatient, Emergency, Virtual, Home Health
  • View encounter details with tabs (Overview, Clinical Notes, Vitals)
  • Complete encounter workflow (InProgress → Finished)
  • Clinical notes display (SOAP format)

Backend Integration:

encounterAPI.getByPatient(patientId)   GET /api/Encounter/patient/{patientId}
encounterAPI.create(data)              POST /api/Encounter
encounterAPI.getById(id)               GET /api/Encounter/{id}
encounterAPI.complete(id)              PUT /api/Encounter/{id}/complete
clinicalNoteAPI.getByEncounter(id)     GET /api/ClinicalNote/encounter/{id}

Controllers Used: EncounterController.cs, ClinicalNoteController.cs Entities: Encounter, ClinicalNote, Patient, Provider


5. PrescriptionManagement - Medication Management

File: EMRWEB/src/components/Dashboard/PrescriptionManagement.js

Features:

  • Patient selection with prescription history
  • Create prescriptions (medication, dosage, frequency, route, duration, refills)
  • Medication search/autocomplete
  • Refill management
  • Print prescription button (professional document generation)
  • Status tracking: Active, Completed, Cancelled

Backend Integration:

prescriptionAPI.getByPatient(patientId)  GET /api/Prescription/patient/{patientId}
prescriptionAPI.create(data)             POST /api/Prescription
prescriptionAPI.refill(id)               POST /api/Prescription/{id}/refill
medicationAPI.getAll()                   GET /api/Medication

Printing: printPrescription(prescription, patient, provider) generates HTML-to-PDF document

Controllers Used: PrescriptionController.cs, MedicationController.cs Entities: Prescription, Medication, Patient, Provider


6. LabOrderManagement - Laboratory Test Management

File: EMRWEB/src/components/Dashboard/LabOrderManagement.js

Features:

  • Patient selection with lab order history
  • Create lab orders (test type, priority, specimen, instructions)
  • Common lab tests: CBC, BMP, CMP, Lipid Panel, Liver Panel, TSH, HbA1c, Urinalysis
  • Priority levels: STAT, Urgent, Routine
  • Status workflow: Ordered → In Progress → Completed
  • Enter lab results with values, units, reference ranges, flags (Normal/Abnormal)
  • LOINC code support

Backend Integration:

labOrderAPI.getByPatient(patientId)  GET /api/LabOrder/patient/{patientId}
labOrderAPI.create(data)             POST /api/LabOrder
labOrderAPI.updateStatus(id, status) PUT /api/LabOrder/{id}/status
labOrderAPI.addResult(orderId, data) POST /api/LabResult

Controllers Used: LabOrderController.cs, LabResultController.cs Entities: LabOrder, LabResult, Patient, Provider


7. VitalsManagement - Vital Signs Recording

File: EMRWEB/src/components/Dashboard/VitalsManagement.js

Features:

  • Patient selection with vitals history
  • Latest vitals display cards (Blood Pressure, Heart Rate, Temperature, O2 Saturation)
  • Record vital signs form with validation:
    • Blood Pressure (Systolic/Diastolic in mmHg)
    • Heart Rate (bpm)
    • Temperature (°F)
    • Respiratory Rate (/min)
    • Oxygen Saturation (%)
    • Weight (lbs)
    • Height (inches)
  • History table with all measurements

Backend Integration:

observationAPI.getByPatient(patientId)  GET /api/Observation/patient/{patientId}
observationAPI.create(data)             POST /api/Observation

Data Structure: Stored as Observation with components array

components: [
  { name: 'Blood Pressure', value: '120/80', unit: 'mmHg' },
  { name: 'Heart Rate', value: '72', unit: 'bpm' },
  // ... more vitals
]

Controllers Used: ObservationController.cs Entities: Observation, Patient


8. AllergyImmunizationManagement - Allergy & Vaccine Tracking

File: EMRWEB/src/components/Dashboard/AllergyImmunizationManagement.js

Features:

  • Tabbed interface (Allergies / Immunizations)
  • Allergies:
    • Add allergies (allergen, type, severity, reaction, notes)
    • Allergy types: Drug/Medication, Food, Environmental, Other
    • Severity levels: Mild, Moderate, Severe, Critical
    • Visual severity badges with color coding
    • Deactivate allergies
  • Immunizations:
    • Add vaccine records (name, CVX code, dose number, lot number, manufacturer, administered by)
    • History display with all vaccine details

Backend Integration:

allergyAPI.getByPatient(patientId)       GET /api/Allergy/patient/{patientId}
allergyAPI.create(data)                  POST /api/Allergy
allergyAPI.deactivate(id)                PUT /api/Allergy/{id}/deactivate
immunizationAPI.getByPatient(patientId)  GET /api/Immunization/patient/{patientId}
immunizationAPI.create(data)             POST /api/Immunization

Controllers Used: AllergyController.cs, ImmunizationController.cs Entities: Allergy, Immunization, Patient


9. BillingManagement - Financial & Insurance Management

File: EMRWEB/src/components/Dashboard/BillingManagement.js

Features:

  • Patient selection with billing history
  • Create invoices (service description, amount, CPT/ICD codes, notes)
  • Invoice table showing:
    • Invoice number (INV-{id})
    • Date, Total amount, Paid amount, Balance
    • Status (Pending, Paid, Overdue)
  • Record payments:
    • Payment amount with balance validation
    • Payment methods: Cash, Credit Card, Debit Card, Insurance, Check
  • Print invoice functionality
  • Automatic due date calculation (30 days)

Backend Integration:

billingAPI.getByPatient(patientId)          GET /api/Billing/patient/{patientId}
billingAPI.create(data)                     POST /api/Billing
billingAPI.recordPayment(billingId, data)   POST /api/Billing/{id}/payment

Payment Processing:

{
  amount: parseFloat(data.amount),
  paymentMethod: data.paymentMethod,
  paymentDate: new Date().toISOString()
}

Controllers Used: BillingController.cs, InsuranceController.cs Entities: Billing, BillingItem, Insurance, Patient


10. Login Component - Modern Authentication

File: EMRWEB/src/components/Login.js

Features:

  • Modern UI with Framer Motion animations
  • Password strength validator with visual progress bar
  • Real-time password strength calculation:
    • 25% - Length ≥ 8 characters
    • 25% - Mixed case (uppercase + lowercase)
    • 25% - Contains digits
    • 25% - Contains special characters
  • Form validation with react-hook-form
  • JWT token storage in localStorage
  • Auto-redirect to dashboard on successful login

Backend Integration:

authAPI.login(credentials)  POST /api/Auth/login

Response:

{
  "token": "jwt-token-string",
  "refreshToken": "refresh-token-string",
  "user": {
    "id": "user-guid",
    "email": "user@email.com",
    "firstName": "John",
    "lastName": "Doe",
    "roles": ["Doctor"]
  }
}

Controllers Used: AuthController.cs


11. API Service Layer - Centralized API Management

File: EMRWEB/src/services/api.js

Features:

  • Axios instance with JWT token interceptor
  • All API endpoints mapped to backend controllers
  • Automatic token injection in request headers
  • 401 error handling (auto-redirect to login)
  • Response interceptor for error handling

API Modules:

authAPI               /api/Auth/*
patientAPI            /api/Patient/*
appointmentAPI        /api/Appointment/*
encounterAPI          /api/Encounter/*
prescriptionAPI       /api/Prescription/*
labOrderAPI           /api/LabOrder/*
observationAPI        /api/Observation/*
allergyAPI            /api/Allergy/*
immunizationAPI       /api/Immunization/*
billingAPI            /api/Billing/*
dashboardAPI          /api/Dashboard/*
providerAPI           /api/Provider/*
medicationAPI         /api/Medication/*
clinicalNoteAPI       /api/ClinicalNote/*
diagnosisAPI          /api/Diagnosis/*
procedureAPI          /api/Procedure/*
insuranceAPI          /api/Insurance/*

Token Management:

api.interceptors.request.use((config) => {
  const token = localStorage.getItem('token');
  if (token) {
    config.headers.Authorization = `Bearer ${JSON.parse(token)}`;
  }
  return config;
});

12. Document Printing Utility

File: EMRWEB/src/utils/printDocument.js

Features:

  • Professional HTML-to-PDF document generation
  • Three document types:

1. Prescription:

printPrescription(prescription, patient, provider)
  • Provider information (name, NPI, DEA, contact)
  • Patient demographics
  • Prescription details (medication, dosage, frequency, route, duration, refills)
  • Signature line and date
  • Controlled substance warnings (if applicable)

2. Lab Order:

printLabOrder(labOrder, patient, provider)
  • Provider information
  • Patient demographics
  • Lab test details (test type, LOINC code, priority, specimen)
  • Special instructions
  • Collection date and signature

3. Patient Summary:

printPatientSummary(patient, encounters, allergies, prescriptions)
  • Patient demographics
  • Active allergies
  • Current medications
  • Recent encounters
  • Comprehensive patient overview

Styling: Print-optimized CSS with proper page breaks, professional fonts, and medical document formatting


🔗 Backend-Frontend Integration Architecture

Data Flow

┌─────────────────┐
│  React Frontend │
│  (Port 3000)    │
└────────┬────────┘
         │
         │ Axios HTTP Request (JWT Token)
         │
         ▼
┌─────────────────┐
│  ASP.NET Core   │
│  Web API        │
│  (Port 7099)    │
└────────┬────────┘
         │
         │ JWT Validation → Role-Based Authorization
         │
         ▼
┌─────────────────┐
│  Controllers    │
│  (18 endpoints) │
└────────┬────────┘
         │
         │ Business Logic & Validation
         │
         ▼
┌─────────────────┐
│  Repositories   │
│  (EF Core)      │
└────────┬────────┘
         │
         │ LINQ Queries
         │
         ▼
┌─────────────────┐
│  SQL Server     │
│  Database       │
│  (27 tables)    │
└─────────────────┘

Authentication Flow

  1. Login: User submits credentials → AuthController.Login()
  2. Token Generation: JWT token with user claims + refresh token
  3. Token Storage: Frontend stores token in localStorage
  4. Request Interceptor: Axios adds token to all requests
  5. Token Validation: Backend validates JWT on each request
  6. Authorization: Role-based policies check permissions
  7. Response: Data returned or 401 Unauthorized

Component-to-Controller Mapping

Frontend Component Backend Controller(s) Entities Used
EnhancedDashboard DashboardController All entities (statistics)
PatientManagement PatientController Patient, Allergy, Immunization
AppointmentManagement AppointmentController Appointment, Patient, Provider
EncounterManagement EncounterController, ClinicalNoteController Encounter, ClinicalNote, Patient, Provider
PrescriptionManagement PrescriptionController, MedicationController Prescription, Medication, Patient, Provider
LabOrderManagement LabOrderController, LabResultController LabOrder, LabResult, Patient, Provider
VitalsManagement ObservationController Observation, Patient
AllergyImmunizationManagement AllergyController, ImmunizationController Allergy, Immunization, Patient
BillingManagement BillingController, InsuranceController Billing, BillingItem, Insurance, Patient
Login AuthController User, AspNetRoles, AspNetUserRoles

🌟 Roadmap & Future Enhancements

Phase 1 (Current - ✅ COMPLETED)

  • ✅ Core EMR functionality with 9 modules
  • ✅ HL7 FHIR compliance (27 entities)
  • ✅ JWT authentication with refresh tokens
  • ✅ RESTful API (100+ endpoints)
  • ✅ Modern React frontend with Material-UI
  • ✅ Real-time dashboard with analytics
  • ✅ Document printing (prescriptions, lab orders, patient summaries)

Phase 2 (Planned)

  • Patient Portal (self-service)
  • Mobile applications (iOS/Android)
  • Telemedicine integration
  • E-prescribing integration (SureScripts)
  • SignalR for real-time notifications

Phase 3 (Future)

  • AI-powered diagnostic assistance
  • Predictive analytics
  • DICOM viewer (radiology)
  • Advanced reporting & dashboards
  • Multi-language support

🤝 Contributing

Contributions are welcome! Please follow these steps:

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

📄 License

This project is licensed under a Proprietary License - see the LICENSE.txt file for details.

Copyright © 2025 Joel Hernandez James. All Rights Reserved.

📞 Support & Contact

For commercial licensing, partnership opportunities, or permission requests, please contact Joel Hernandez James via the information above.

🙏 Acknowledgments

📊 Statistics

  • Total Entities: 27 HL7 FHIR-compliant models
  • Lines of Code: 20,000+ (Backend + Frontend)
  • API Endpoints: 100+ RESTful endpoints
  • Frontend Modules: 9 complete feature modules
  • Security Roles: 6 predefined healthcare roles
  • Medical Standards: ICD-10/11, CPT, NDC, LOINC, CVX, SNOMED CT, DEA
  • Controllers: 18 fully-implemented API controllers
  • Frontend Components: 12 major components with real API integration

Made with ❤️ for Healthcare

GitHub Stars GitHub Forks

About

EMR System .NET 8

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages