Skip to content

nessakodo/caresense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐˜Š๐˜ข๐˜ณ๐˜ฆ๐˜š๐˜ฆ๐˜ฏ๐˜ด๐˜ฆ ๐˜Ÿ

Version Python FastAPI Pyfhel DiffPrivLib MIT License Made by Nessa Kodo


๐˜œ๐˜ฑ๐˜ฅ๐˜ข๐˜ต๐˜ฆ๐˜ด (๐˜ท0.3.0)

CareSense X evolves into a full-scale production-grade decision intelligence platform:

๐Ÿง  Explainable AI

  • SHAP and LIME explainability modules with security hardening
  • Per-prediction feature importance + global model insights
  • Transparent decision reasoning for clinician trust

๐Ÿ“„ Multi-Format Document Processing

  • Secure PDF, DOCX, TXT, and email parsing
  • Content sanitization + PII detection
  • File size validation + MIME type enforcement
  • Hash-based audit trails

๐Ÿค– Hybrid ML Architecture

  • Classical: Calibrated logistic regression (TF-IDF + SVD)
  • Modern: Sentence-transformers for semantic embeddings
  • Flexible: Switch models based on use case

๐Ÿฅ Clinician Review Workflow

  • Human-in-the-loop dashboard with priority queuing
  • Approval, rejection, and escalation workflows
  • Override capabilities with audit logging
  • Real-time case synchronization

๐Ÿ”’ Production Security

  • Rate limiting: Token bucket algorithm per IP + endpoint
  • Security headers: CSP, HSTS, X-Frame-Options, etc.
  • Input validation: Comprehensive sanitization across all endpoints
  • Audit trails: Every action signed with Ed25519

๐˜”๐˜ช๐˜ด๐˜ด๐˜ช๐˜ฐ๐˜ฏ

Healthcare teams need privacy-preserving automation that still learns from patient data while maintaining human oversight. CareSense X delivers explainable triage intelligence, biometric authentication, document processing, and zero-trust workflow orchestration without exposing PHIโ€”aligning with HIPAA, GDPR, and emerging FDA CDS guidance.


๐˜š๐˜ฐ๐˜ญ๐˜ถ๐˜ต๐˜ช๐˜ฐ๐˜ฏ

  • Privacy-preserving biometric attestation powered by CKKS homomorphic encryption via Pyfhel
  • Explainable predictions with SHAP/LIME showing top features driving each decision
  • Multi-format document ingestion (PDF, DOCX, email) with secure parsing and PII detection
  • Hybrid ML pipeline: classical + transformer models for accuracy and interpretability
  • Clinician review dashboard: human-in-the-loop workflow with override and audit trail
  • Encrypted symptom processing with calibrated ML, differential privacy, and structured audit logs
  • Automated care workflows: compliance-signed triage decisions ready for orchestration (EHR hooks, alerting)
  • Production security: rate limiting, security headers, input sanitization, audit logging
  • Continuous compliance: Ed25519-signed JSONL audit trail + security policy for rapid incident response

๐˜Œ๐˜ฏ๐˜ฉ๐˜ข๐˜ฏ๐˜ค๐˜ฆ๐˜ฅ ๐˜ˆ๐˜ณ๐˜ค๐˜ฉ๐˜ช๐˜ต๐˜ฆ๐˜ค๐˜ต๐˜ถ๐˜ณ๐˜ฆ

flowchart TB
    Client[Zero-Trust Client] -->|OAuth + FHE token| API[FastAPI Secure Core]
    Client -->|Document Upload| DocParser[Document Parser]

    DocParser -->|Sanitized Text| API
    API -->|Rate Limited| RateLimit[Rate Limiter]
    RateLimit -->|Validated| Triage[Triage Service]

    Triage -->|Classical ML| Model1[TF-IDF + Logistic]
    Triage -->|Transformer| Model2[Sentence-BERT]

    Model1 -->|Prediction| Explain[SHAP/LIME Explainer]
    Model2 -->|Prediction| Explain

    Explain -->|Explained Result| ReviewQueue[Clinician Review Queue]
    ReviewQueue -->|Human Approval| Clinician[Clinician Dashboard]

    Clinician -->|Decision + Override| Audit[Compliance Trail]
    Triage -->|Audit payload| Audit
    API -->|Secure storage| Vault[Encrypted Store]
    Audit -->|Signed JSONL| Ledger[(Immut. Ledger)]
Loading

๐˜›๐˜ฆ๐˜ค๐˜ฉ ๐˜š๐˜ต๐˜ข๐˜ค๐˜ฌ

Core

  • Backend: FastAPI, Uvicorn, Pydantic v2, Structlog, Python 3.11+
  • Frontend: React 18 + Vite 5, TailwindCSS, React Query 5, Heroicons, zod

ML & AI

  • Classical ML: Scikit-learn 1.4, Calibrated LogisticRegression, Truncated SVD
  • Transformers: Sentence-Transformers, HuggingFace Transformers, PyTorch
  • Explainability: SHAP 0.45+, LIME 0.2+
  • Privacy: DiffPrivLib (differential privacy ready)

Document Processing

  • Parsers: PyPDF (PDF), python-docx (DOCX), email-reply-parser
  • Sanitization: Bleach (HTML), python-magic (MIME detection)
  • OCR: Pytesseract, Pillow

Privacy & Security

  • Encryption: Pyfhel (CKKS), Cryptography (Ed25519, Fernet)
  • Authentication: python-jose (JWT), passlib (bcrypt)
  • Rate Limiting: slowapi, Redis-ready
  • Security: Comprehensive input validation, security headers, CORS

Tooling & Ops

  • Development: Docker, Make, Ruff, Pytest
  • Security Scanning: pip-audit, Safety
  • Monitoring: Prometheus metrics, Structlog
  • Performance: uvloop, orjson

๐˜ˆ๐˜—๐˜ ๐˜™๐˜ฐ๐˜ถ๐˜ต๐˜ฆ๐˜ด

Core Triage

Method Path Purpose
GET /version Service version + build info
GET /v1/health Readiness probe
POST /v1/triage Submit symptoms with optional biometric proof

Biometrics

Method Path Purpose
POST /v1/biometrics/enrol Encrypt + register biometric embeddings

Explainability (NEW)

Method Path Purpose
POST /v1/explain Get SHAP or LIME explanation for prediction
GET /v1/explain/global Get global feature importance across model

Document Processing (NEW)

Method Path Purpose
POST /v1/documents/upload Upload & parse PDF/DOCX/TXT/email
POST /v1/documents/triage Run triage on parsed document text

Clinician Review (NEW)

Method Path Purpose
GET /v1/review/pending Get pending review cases with priority filtering
GET /v1/review/{case_id} Get full case details including explanation
POST /v1/review/submit Submit clinician review decision with override

Compliance

Method Path Purpose
GET /v1/compliance/public-key Retrieve Ed25519 public key for audit verification

All responses include signed audit references for immutable compliance review.


๐˜˜๐˜ถ๐˜ช๐˜ค๐˜ฌ ๐˜š๐˜ต๐˜ข๐˜ณ๐˜ต (๐˜“๐˜ฐ๐˜ค๐˜ข๐˜ญ ๐˜™๐˜ถ๐˜ฏ)

Requirements

  • Python โ‰ฅ 3.11
  • Node.js โ‰ฅ 20
  • Tesseract OCR binary (for dataset extraction)
  • Optional: Docker 26+, Make, UV loop support
  • For macOS: OpenMP (via Homebrew) for pyfhel compilation

Setup

# Install OpenMP on macOS (required for pyfhel)
brew install libomp

# Install dependencies
make install              # installs runtime + dev dependencies

# Build dataset and train model
python ocr_extract.py     # builds hashed OCR dataset (once)
make train                # trains calibrated DP triage model

# Run backend
make serve                # boots FastAPI with reload on :8080

# Run frontend (separate terminal)
cd frontend && npm run dev  # launches command center on :5173

Browse interactive docs at http://localhost:8080/docs (Swagger) or http://localhost:8080/redoc.

Frontend command center available at http://localhost:5173.

Docker Compose (Recommended)

docker compose up --build
# FastAPI โ†’ http://localhost:8080
# Frontend โ†’ http://localhost:4173

๐˜œ๐˜ด๐˜ข๐˜จ๐˜ฆ ๐˜Œ๐˜น๐˜ข๐˜ฎ๐˜ฑ๐˜ญ๐˜ฆ๐˜ด

1. Basic Triage

curl -X POST http://localhost:8080/v1/triage \
  -H "Content-Type: application/json" \
  -d '{
    "symptoms": "severe chest pain, shortness of breath, sweating"
  }'

2. Explainable Prediction

curl -X POST http://localhost:8080/v1/explain \
  -H "Content-Type: application/json" \
  -d '{
    "text": "severe headache, blurred vision, dizziness",
    "method": "shap"
  }'

3. Document Upload

curl -X POST http://localhost:8080/v1/documents/upload \
  -F "file=@patient_report.pdf"

4. Clinician Review

# Get pending cases
curl "http://localhost:8080/v1/review/pending?clinician_id=dr_smith&priority=high"

# Submit review
curl -X POST http://localhost:8080/v1/review/submit \
  -H "Content-Type: application/json" \
  -d '{
    "case_id": "abc123...",
    "clinician_id": "dr_smith",
    "decision": "approved",
    "notes": "Confirmed high urgency, appropriate recommendation"
  }'

๐˜Š๐˜ญ๐˜ช๐˜ฆ๐˜ฏ๐˜ต ๐˜Œ๐˜น๐˜ฑ๐˜ฆ๐˜ณ๐˜ช๐˜ฆ๐˜ฏ๐˜ค๐˜ฆ (๐˜๐˜ณ๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ฅ)

  • Biometric enrollment wizard with synthetic demo embeddings
  • Document upload interface with drag-drop support
  • Encrypted triage submission with urgency badges and compliance signature cards
  • Explainability visualization showing top features and importance scores
  • Clinician review dashboard with priority queuing and real-time updates
  • Live compliance ledger key viewer for transparent verification
  • React Query cache with offline-friendly refresh behaviour
  • Tailwind-driven dark holographic UI tuned for clinical command centers

๐˜š๐˜ฆ๐˜ค๐˜ถ๐˜ณ๐˜ช๐˜ต๐˜บ ๐˜๐˜ฆ๐˜ข๐˜ต๐˜ถ๐˜ณ๐˜ฆ๐˜ด

Defense in Depth

  1. Input Validation: Length limits, type checking, pattern validation
  2. Sanitization: HTML stripping, XSS prevention, SQL injection protection
  3. Rate Limiting: 60 req/min per IP with burst tolerance
  4. Security Headers: CSP, HSTS, X-Frame-Options, X-Content-Type-Options
  5. Audit Logging: Ed25519-signed immutable trails for all actions

Privacy Controls

  • No PHI storage: Only hashes and encrypted data
  • PII detection: Automatic flagging of sensitive data in documents
  • Homomorphic encryption: Biometric comparisons without decryption
  • Differential privacy: Model training with privacy guarantees

Compliance

  • HIPAA-aligned: Encrypted storage, audit trails, access controls
  • GDPR-ready: Data minimization, right to erasure support
  • FDA CDS guidance: Human oversight, explainability, audit trails

๐˜ˆ๐˜ถ๐˜ฅ๐˜ช๐˜ต & ๐˜Š๐˜ฐ๐˜ฎ๐˜ฑ๐˜ญ๐˜ช๐˜ข๐˜ฏ๐˜ค๐˜ฆ

  • data/audit_logs.jsonl: append-only ledger signed via Ed25519
  • data/crypto/: CKKS context + secret keys (auto-generated, keep out of VCS)
  • SecureStore: Fernet-encrypted biometric payloads on disk
  • Makefile security-scan: pip-audit + Safety to flag vulnerable dependencies
  • docs/openapi.yaml: machine-readable spec for downstream SDK generation
  • docs/architecture.md: living diagram + hardening checklist for reviews
  • Review queue: JSONL-based clinician decision audit trail

๐˜”๐˜“ ๐˜–๐˜ฑ๐˜ด & ๐˜—๐˜ฆ๐˜ณ๐˜ง๐˜ฐ๐˜ณ๐˜ฎ๐˜ข๐˜ฏ๐˜ค๐˜ฆ

  • Classical Model: Balanced, calibrated logistic regression with class-weighting and isotonic calibration
  • Transformer Model: Sentence-BERT embeddings + lightweight classifier for semantic understanding
  • Explainability: SHAP kernel explainer + LIME text explainer for transparent decisions
  • reports/model_card.md: continuously regenerated model card + micro-F1 metrics
  • reports/model_report.json: raw classification report for dashboards
  • Differential privacy ready: plug in DP noise budgets via DiffPrivLib wrappers
  • Frontend overlays: display metrics and compliance handles for human-in-the-loop review

๐˜™๐˜ฐ๐˜ข๐˜ฅ๐˜ฎ๐˜ข๐˜ฑ (๐˜ท0.4+)

  • Advanced ML: Fine-tuned medical BERT models with domain adaptation
  • Multi-modal: Image + text analysis for comprehensive medical assessment
  • Zero-knowledge proofs: Enhanced biometric attestation
  • Secure enclave deployment: AWS Nitro Enclaves / Azure SEV-SNP profiles
  • FHIR R5 bridge: EHR integration with consent-aware data minimization
  • Real-time alerts: Clinician notification webhooks (Slack, Teams, PagerDuty)
  • Generative explanations: Guardrailed LLM explanations with PHI redaction
  • Mobile apps: iOS/Android clinician review clients
  • Advanced analytics: Outcome tracking, model performance monitoring, bias detection

๐˜‹๐˜ฆ๐˜ท๐˜ฆ๐˜ญ๐˜ฐ๐˜ฑ๐˜ฎ๐˜ฆ๐˜ฏ๐˜ต & ๐˜›๐˜ฆ๐˜ด๐˜ต๐˜ช๐˜ฏ๐˜จ

# Run tests
make test

# Lint code
make lint

# Format code
make format

# Security scan
make security-scan

# Generate OpenAPI spec
make openapi

๐˜Š๐˜ณ๐˜ฆ๐˜ฅ๐˜ช๐˜ต๐˜ด & ๐˜š๐˜ถ๐˜ฑ๐˜ฑ๐˜ฐ๐˜ณ๐˜ต

Built with care by Nessa Kodo. Licensed under the MIT License. For enterprise pilots or security reviews, reach out at security@caresense.app.

Contributing: See CONTRIBUTING.md for guidelines.

Security: See SECURITY.md for vulnerability reporting.

Stay vigilant. Stay encrypted. Stay explainable.


About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published