# Building an ML Project on AWS for DRG and ICD-10 Prediction from Healthcare Data ## Executive Summary Building an ML system for medical coding prediction requires careful orchestration of advanced machine learning models, secure AWS infrastructure, and sophisticated data pipelines. Based on comprehensive research of current best practices and real-world implementations, **DRG-LLaMA achieves 54.6% top-1 accuracy for DRG prediction** while **Clinical BERT variants deliver optimal ICD-10 prediction performance**, with successful deployments demonstrating **30-65% productivity improvements** and **85% accuracy increases** in production environments. The recommended architecture leverages AWS HealthLake for FHIR data storage, SageMaker for model training and deployment, and Snowflake for data warehousing, with Epic integration through both FHIR APIs and Clarity database connections. Healthcare organizations implementing these systems report average ROI of 464% with significant reductions in coding errors and billing delays. ## Best ML approaches for medical coding prediction ### State-of-the-art model architectures deliver breakthrough performance The landscape of medical coding ML has been transformed by large language models and specialized transformer architectures. **DRG-LLaMA represents the current state-of-the-art for DRG prediction**, achieving 54.6% top-1 accuracy with a 13B parameter model using 1024 token context windows. This represents a 40.3% improvement over ClinicalBERT and demonstrates the power of domain-adapted foundation models. For base DRG prediction (without complications), the model achieves 67.8% accuracy, making it highly effective for initial coding passes. For ICD-10 prediction, the extreme multi-label classification challenge of handling 70,000+ possible codes requires different approaches. **Hierarchical attention models combined with Clinical BERT variants** provide the best balance of performance and interpretability. The PLM-ICD framework currently leads benchmarks, while CAML (Convolutional Attention for Multi-Label classification) remains a strong baseline with micro-F1 scores of 0.54 on MIMIC-III datasets. Notably, recent replication studies found that properly configured Bi-GRU models can outperform CNNs, highlighting the importance of implementation details. The choice between models depends on specific requirements. For production systems prioritizing accuracy, ensemble approaches combining DRG-LLaMA for DRG codes with hierarchical BERT models for ICD-10 codes provide optimal results. For resource-constrained environments, CAML offers excellent performance with lower computational requirements. Organizations should expect top-5 accuracy rates of 86.5% for DRG codes and handle the long-tail distribution of ICD codes by focusing initial deployments on the most frequent 300-1000 codes. ## AWS architecture for healthcare ML projects ### HIPAA-compliant infrastructure with managed ML services The optimal AWS architecture for medical coding prediction centers on **Amazon SageMaker as the ML platform**, integrated with **AWS HealthLake for FHIR-compliant data storage** and **Amazon Comprehend Medical for NLP processing**. This combination provides end-to-end ML lifecycle management while maintaining HIPAA compliance through 166+ eligible AWS services covered under Business Associate Agreements. The recommended multi-account strategy separates development, staging, and production environments to contain security blast radius while enabling cost allocation by project. The architecture implements defense-in-depth security with AWS PrivateLink for private connectivity, KMS for encryption key management, and comprehensive audit logging through CloudTrail. For disaster recovery, a warm standby configuration provides minutes-level RTO/RPO suitable for critical coding systems. Key architectural components include SageMaker endpoints for real-time inference achieving sub-second latency, batch transform jobs for overnight coding runs, and Step Functions for orchestrating complex ML pipelines. The system leverages S3 for data lake storage with lifecycle policies, Aurora Serverless for variable workloads, and DynamoDB for patient lookup tables with millisecond latency. Cost optimization through SageMaker Savings Plans can reduce expenses by up to 64% for consistent workloads. ## Working with Epic on FHIR and Chronicles data ### Dual-path data extraction maximizes information capture Epic systems offer two primary data access paths that complement each other for ML applications. **The FHIR API provides real-time, standardized access** to clinical resources including Patient, Encounter, Condition, and Procedure records, while **the Clarity reporting database offers SQL-based access** to comprehensive clinical data with a one-day lag. For ML training data, bulk FHIR exports using the Flat FHIR specification provide efficient extraction of large datasets in NDJSON format. Key resources for coding prediction include DiagnosticReport for lab results, DocumentReference for clinical notes, and Observation for vital signs. Authentication uses OAuth 2.0 with SMART on FHIR for EHR-launched applications and JWT-based assertions for backend services. The Chronicles hierarchical database, accessed through Clarity, contains critical tables like CLARITY_DX for diagnoses, CLARITY_PRC for procedures, and HNO_INFO for clinical documentation. Organizations typically implement nightly ETL processes to extract this data, though real-time access remains possible through Epic's Cognitive Computing Platform for model deployment within Epic workflows. Common challenges include handling custom Epic configurations that vary between departments, incomplete data fields (smoking status shows ~88% completeness), and unstructured notes comprising 80% of patient data. Solutions involve comprehensive data quality monitoring, NLP pipelines for text extraction, and mapping common data elements across configurations. The recommended approach combines bulk FHIR exports for training data with real-time API calls for inference, using Clarity for complex analytics and retrospective analysis. ## Snowflake-AWS integration patterns for ML pipelines ### Unified data platform accelerates model development The integration between Snowflake and AWS creates a powerful foundation for healthcare ML pipelines through **AWS PrivateLink connectivity eliminating public internet traversal** and **Snowpark enabling in-database ML processing** without data movement. This architecture supports both batch and real-time inference patterns critical for medical coding workflows. Snowpipe provides continuous data ingestion from S3 with sub-minute latency, automatically processing new Epic data exports as they arrive. External stages facilitate bulk data movement with optimized 100-250MB compressed file sizes and parallel loading across 8 threads per warehouse node. For change data capture, Snowflake Streams combined with Tasks (now supporting 15-second intervals) enable near real-time processing of clinical data updates. The ML-specific integration leverages Snowpark Container Services for model training directly within Snowflake, supporting PyTorch, XGBoost, and Scikit-learn without manual environment configuration. The Snowflake Feature Store automates feature engineering while maintaining data governance, complemented by SageMaker Feature Store for real-time serving. Model inference patterns include batch scoring using Snowpark UDFs for overnight runs and SageMaker endpoints for real-time predictions. Cost optimization strategies include using Serverless Tasks Flex for 42% cost savings, implementing result set caching with 24-hour retention, and deploying in the same AWS region to minimize egress charges. Security features include end-to-end encryption, IAM role integration for cross-account access, and comprehensive audit logging meeting HIPAA requirements. ## Data preprocessing for medical coding models ### Sophisticated preprocessing addresses healthcare data complexity Medical coding prediction requires extensive preprocessing to handle the unique characteristics of clinical data. **Text preprocessing must address medical-specific challenges** including abbreviation expansion (converting "W/O" to "WITHOUT"), handling Epic record boundaries that break sentences, and removing templated content that doesn't contribute diagnostic information. Specialized tokenizers like scispaCy outperform general-purpose tools for medical text. For missing data, advanced imputation methods like 3D-MICE and gradient boosting consistently outperform simple techniques. Laboratory values require range normalization accounting for different reference ranges across institutions, while temporal features demand sliding window aggregations (30, 90, 365-day lookback periods) and trend analysis for vital sign trajectories. The creation of cross-sectional and longitudinal features captures both current state and historical patterns. Structured data preprocessing involves standardizing units (converting blood pressure measurements to consistent mmHg), detecting physiologically implausible outliers, and creating derived features like the Charlson Comorbidity Index. Feature engineering strategies include extracting clinical concepts using NER models, creating semantic features from medical ontologies, and combining structured and unstructured data through early or late fusion approaches. For production systems, implement comprehensive validation including range checks for numerical values, temporal consistency validation, and cross-reference validation with external sources. The preprocessing pipeline should maintain audit trails for data transformations and implement version control for reproducibility. ## Challenges specific to DRG and ICD-10 prediction ### Hierarchical classification and extreme multi-label complexity ICD-10 prediction faces the extreme multi-label classification challenge of **70,000+ possible codes with severe class imbalance**, where the majority of codes appear rarely in training data. Solutions include focusing initial deployments on the top 300-1000 most frequent codes (achieving 55.7% accuracy) versus 52.0% for all codes, implementing hierarchical classification that leverages the 7-digit alphanumeric code structure, and using label-wise attention mechanisms that create code-specific document representations. DRG prediction presents different challenges as a single-label classification task with ~800 possible groups. The DRG grouper logic considers principal diagnosis, secondary diagnoses, procedures, age, gender, and discharge status. The two-label approach separating base DRG prediction (67.8% accuracy) from CC/MCC status (67.5% accuracy) proves effective. Notably, surgical DRGs achieve near-perfect accuracy due to distinctive procedural patterns. Both tasks require handling the long-tail distribution through cost-sensitive learning, synthetic data generation for rare codes, and transfer learning from similar frequent codes. Multi-modal approaches combining diagnosis and procedure codes with clinical notes improve performance, while attention mechanisms provide necessary interpretability for clinical adoption. The hierarchical nature of both coding systems enables partial credit evaluation, where predictions within the correct code family receive recognition even if the specific code is incorrect. ## Compliance and security on AWS for Epic data ### Comprehensive security framework ensures HIPAA compliance Healthcare data on AWS requires strict adherence to HIPAA regulations through **Business Associate Agreements covering 166+ eligible services** and implementation of administrative, physical, and technical safeguards. The security architecture implements AES-256 encryption at rest using AWS KMS with automated key rotation, TLS 1.2+ for data in transit, and comprehensive audit logging through CloudTrail capturing all API calls and access events. AWS security services essential for healthcare include IAM for granular role-based permissions with mandatory MFA, Security Hub for centralized compliance monitoring across 100+ security tools, and Macie for ML-based PHI discovery in S3 buckets. Network isolation uses VPCs with private subnets, PrivateLink for service communication, and Direct Connect for secure on-premises connectivity. Organizations achieving HITRUST certification report a 99.41% breach-free rate, demonstrating the effectiveness of these controls. The multi-account strategy provides blast radius containment for security incidents while enabling compliance isolation for different data classifications. Regular requirements include security assessments, penetration testing, and incident response plan testing. Epic-specific considerations include secure handling of Chronicles data extracts, encryption of bulk FHIR exports, and audit trails for all data movements between Epic and AWS systems. Implementing shadow mode deployment allows risk-free validation before production use. ## Sample architectures and case studies ### Real-world implementations demonstrate significant ROI RadNet's deployment across **399 sites using Maverick Medical AI's autonomous coding** demonstrates enterprise-scale feasibility, achieving real-time coding intelligence with improved regulatory compliance. Large hospital networks report 45% coding efficiency improvements and 85% accuracy increases, with productivity surging from 40 to 66 cases per day. The typical implementation architecture follows a phased approach: assessment (2-4 weeks), pilot program (8-12 weeks), staged rollout (6-12 months), and full production (12-18 months). Epic's native AI coding assistant, available across their entire customer base, achieves 30% error reduction and 50% decrease in billing delays, demonstrating seamless EHR integration. Successful deployments utilize a shadow mode strategy where AI recommendations run parallel to human coding during validation. This approach enables performance monitoring without affecting production workflows, with gradual transition to automation for validated use cases. Organizations report average ROI of 464% with faster reimbursements and fewer claim denials. Commercial solutions from vendors like CodaMetrix, Fathom Health, and MediCodio provide pre-built integrations with Epic systems. The AI medical coding market is projected to reach $8.4B by 2033 (CAGR 13.6%), with 85% of healthcare organizations reporting increased efficiency from AI coding adoption. ## Model selection recommendations ### Transformer models lead performance with practical alternatives For production deployments, **Clinical BERT variants provide the optimal balance** of performance, interpretability, and computational requirements for ICD-10 prediction. These models, pre-trained on biomedical literature and fine-tuned on clinical notes, achieve mean macro-F1 scores of 0.761 while remaining deployable on standard GPU infrastructure. DRG prediction benefits from the superior performance of DRG-LLaMA, though organizations with resource constraints should consider Clinical BERT as a viable alternative achieving 37% top-1 accuracy. For initial proof of concepts, CAML offers excellent baseline performance with lower computational requirements and proven interpretability through attention weight visualization. The recommended approach implements ensemble methods combining specialized models: DRG-LLaMA or Clinical BERT for DRG codes, hierarchical attention models for high-frequency ICD-10 codes, and few-shot learning approaches for rare codes. Pre-trained models available through Hugging Face, including emilyalsentzer/Bio_ClinicalBERT and PubMedBERT, accelerate development by providing domain-adapted starting points. Organizations should select models based on their specific constraints. High-accuracy requirements favor large language models despite computational costs, while real-time applications benefit from optimized BERT variants. Interpretability needs may necessitate attention-based architectures that provide code-specific explanations for clinical validation. ## Evaluation metrics and validation approaches ### Multi-faceted evaluation ensures clinical validity Medical coding models require comprehensive evaluation beyond traditional accuracy metrics. **Top-k accuracy proves essential**, with successful systems achieving 86.5% top-5 accuracy for DRG codes, acknowledging that coders often consider multiple options. Hierarchical evaluation metrics account for ICD-10's taxonomic structure, providing partial credit for predictions within correct code families. Clinical validity assessment involves comparing AI predictions against certified medical coders with inter-rater reliability (Cohen's Kappa ≥ 0.8) and specialty-specific validation for complex cases. The evaluation framework should include exact match ratios for perfect predictions, mean average precision across different recall levels, and semantic similarity using medical embeddings like cui2vec. Validation strategies must prevent data leakage through strict temporal splits, ensuring training data predates validation periods to simulate real deployment. Patient-level splitting prevents the same patient appearing in training and test sets, while hospital-level cross-validation assesses generalizability across institutions. Shadow mode deployment enables risk-free validation with AI running parallel to human coders. Success metrics extend beyond accuracy to include coding efficiency improvements (30-65% productivity gains reported), claim denial rate reduction, and revenue cycle acceleration. A/B testing within production environments provides statistical validation of performance improvements, while continuous monitoring detects model degradation over time. ## Implementation Roadmap The path to production requires careful orchestration across three phases. **Phase 1 (Months 1-2)** establishes foundation infrastructure including Epic FHIR API access, Snowflake-AWS connectivity via PrivateLink, and basic SageMaker pipelines with HIPAA compliance controls. **Phase 2 (Months 3-4)** develops the ML system with comprehensive feature engineering, NLP pipeline implementation for clinical notes, and model training using historical data. **Phase 3 (Months 5-6)** achieves production readiness through model validation against human coders, shadow mode deployment for risk-free testing, and integration with Epic workflows via the Cognitive Computing Platform. Critical success factors include close collaboration with Epic administrators and clinical staff, establishing clear data use agreements, starting with high-value low-complexity use cases like common DRGs, and implementing continuous model monitoring. Organizations should expect 12-18 months for full production deployment with ongoing optimization thereafter. This comprehensive approach, validated through real-world implementations achieving significant ROI and efficiency gains, provides a robust foundation for building ML-powered medical coding systems that enhance accuracy, reduce administrative burden, and accelerate revenue cycles while maintaining the highest standards of security and compliance.