CoolFace
Apppublic

cryogenic22/phy_dig_twin

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
api_simulator.py196 linesDownload Raw Back to root
1import time2 3def simulate_claude_api_call(prompt):4    """Simulate a call to Anthropic's Claude API"""5    # In a real implementation, this would make an actual API call6    # For demo purposes, we'll return predefined responses based on the prompt7    8    # Mock waiting time for API call to seem realistic9    time.sleep(1.5)  10    11    if "primary care" in prompt.lower() and "diabetes" in prompt.lower():12        return """Based on the digital twin simulation for Primary Care Physicians treating diabetes:13 141. 72% would prescribe XenoGlip as a second-line therapy after metformin failure for patients with an A1C between 7.5-8.5%152. Key drivers include: perceived cardiovascular safety profile (83%), once-daily dosing (76%), and favorable formulary status (68%)163. Main barriers to adoption are: concerns about pancreatitis risk (41%), patient cost concerns (37%), and preference for newer GLP-1 options (29%)174. When comparing to competitors, physicians rate XenoGlip higher on "ease of use" and "patient adherence" but lower on "glycemic efficacy" and "weight management"18 19This microsegment shows high receptivity to messages focused on cardiovascular outcomes data and patient support programs."""20 21    elif "endocrinologist" in prompt.lower():22        return """Based on the digital twin simulation for Endocrinologists:23 241. Only 38% would prescribe XenoGlip as a second-line therapy, preferring GLP-1 agonists (47%) or SGLT2 inhibitors (15%)252. Key considerations include: comprehensive glycemic control (91%), weight effects (87%), and cardiorenal protection (83%)263. This segment is highly influenced by recent clinical trial data and guideline updates274. They express specific concerns about XenoGlip's efficacy in patients with A1C >9.0% and its neutral effect on weight28 29Messages emphasizing XenoGlip's role in a comprehensive treatment approach and compatibility with other agents would resonate better than positioning it as monotherapy."""30 31    elif "messaging" in prompt.lower():32        return """Based on digital twin simulations, the following messaging approaches would be most effective for XenoGlip:33 341. For Primary Care: "XenoGlip provides reliable A1C reduction with once-daily dosing and proven cardiovascular safety" (estimated 76% receptivity)35 362. For Endocrinologists: "XenoGlip offers flexible integration into treatment regimens with minimal drug-drug interactions and established safety profile" (estimated 64% receptivity)37 383. For Cardiologists: "XenoGlip demonstrated no increased cardiovascular risk in patients with established heart disease, with neutral effects on weight and blood pressure" (estimated 71% receptivity)39 404. Messaging around patient support programs shows 2.3x higher engagement across all specialties compared to clinical data messaging alone."""41 42    elif "formulary" in prompt.lower() or "payer" in prompt.lower():43        return """The digital twin simulation predicts the following impact of formulary changes for XenoGlip:44 451. If moved from Tier 3 to Tier 2 status on major commercial plans:46   - 43% increase in new prescriptions among PCPs47   - 26% increase among endocrinologists48   - Overall market share would likely increase by 2.3 percentage points within 6 months49 502. If prior authorization requirements were removed:51   - 38% of physicians who currently prescribe competitors would consider XenoGlip52   - Time to first prescription would decrease by approximately 22 days53 543. The most impactful coverage improvement would be reducing patient out-of-pocket costs below $30/month, which would influence 79% of prescribers."""55 56    elif "patient profile" in prompt.lower():57        return """For the described patient profile (58-year-old male, A1C 8.2%, on metformin 1000mg BID, obese with hypertension):58 591. 64% of PCPs would add XenoGlip602. 22% would add a GLP-1 agonist613. 14% would add an SGLT2 inhibitor62 63Key factors influencing this decision include:64- Patient's commercial insurance status and formulary positioning65- Moderate A1C elevation (suggesting DPP-4 could be sufficient)66- Presence of obesity (though many physicians still consider XenoGlip weight-neutral)67- Comorbid hypertension (some physicians believe SGLT2s might offer better overall benefit)68 69If the patient profile included CKD or established cardiovascular disease, XenoGlip selection would drop to approximately 31%."""70 71    elif "sales" in prompt.lower() or "uptake" in prompt.lower():72        return """The digital twin model predicts the following regarding XenoGlip uptake:73 741. Near-term projection (6 months):75   - 11.2% growth in total prescriptions76   - Highest growth among PCPs practicing in group settings (17.4%)77   - Limited growth among specialists (5.1%)78 792. Key drivers of adoption:80   - Recent label update regarding renal dosing (influencing 43% of providers)81   - New cardiovascular safety data (influencing 58% of providers)82   - Competitor supply constraints (temporary advantage)83 843. Regional variations show strongest growth in the Midwest and Southeast regions, with more challenging uptake in the Northeast where formulary positions are less favorable.85 864. The model forecasts peak market share of approximately 14.3% within the DPP-4 class, dependent on maintaining current access."""87 88    elif "barriers" in prompt.lower():89        return """The digital twin analysis identifies the following key barriers to XenoGlip adoption:90 911. Perceived efficacy limitations:92   - 68% of non-prescribers cite concerns about efficacy relative to newer classes93   - This is particularly pronounced among physicians who see patients with higher baseline A1C values (>8.5%)94   - This perception persists despite head-to-head trials showing non-inferiority in certain patient populations95 962. Formulary and access issues:97   - 72% indicate tier positioning as a significant barrier98   - Prior authorization requirements delay initiation by an average of 18.4 days99   - Patient abandonment rates of 31% when out-of-pocket costs exceed $50/month100 1013. Competition from newer therapeutic classes:102   - Growing preference for GLP-1s and SGLT2s due to extra-glycemic benefits103   - Decreasing comfort with initiating DPP-4 inhibitors in patients with cardiovascular disease104   - Perception gap between clinical trial results and real-world expectations105 1064. Knowledge gaps in specific areas:107   - 41% of physicians uncertain about long-term safety profile108   - 36% unfamiliar with newest data on cardiovascular outcomes109   - 28% unclear on appropriate patient selection criteria110 111The simulation suggests that addressing the perception gap around efficacy and improving formulary positioning would have the greatest impact on adoption rates."""112 113    elif "competitive" in prompt.lower():114        return """Based on the digital twin simulations, XenoGlip's competitive positioning reveals:115 1161. Relative to other DPP-4 inhibitors:117   - Perceived as therapeutically similar by 76% of physicians118   - Differentiated primarily on formulary status rather than clinical attributes119   - Slight preference (53%) for XenoGlip among physicians who express a DPP-4 class preference120 1212. Compared to GLP-1 receptor agonists:122   - Positioned as less efficacious for A1C reduction (average perceived difference of 0.4-0.6%)123   - Significantly preferred for ease of administration (oral vs. injectable)124   - Viewed as more appropriate for earlier stage patients and the elderly125   - Cost advantage perceived by 82% of physicians, though this varies by plan126 1273. Against SGLT2 inhibitors:128   - Lower perception of cardiorenal benefit (cited by 89% of physicians)129   - Higher perceived safety in patients with renal impairment130   - Fewer concerns about genitourinary side effects (important for 64% of PCPs)131   - Similar formulary positioning in most regions132 1334. Across all diabetes treatments:134   - Ranked 4th in overall prescriber preference for second-line therapy135   - Highest ranked for "ease of initiation" and "minimal monitoring requirements"136   - Lowest ranked for "weight management" and "impact beyond glycemic control"137 138The digital twin analysis suggests that XenoGlip could strengthen its competitive position by emphasizing its role in specific patient types (elderly, renally impaired) and by more effectively communicating recent data on cardiovascular safety."""139 140    else:141        return """Based on the digital twin simulation for physicians regarding XenoGlip:142 143The analysis indicates 68% of physicians in this microsegment would prescribe XenoGlip for appropriate patients with Type 2 Diabetes. Key decision factors include efficacy data (cited by 72%), tolerability profile (68%), and formulary status (84%).144 145The simulation identified specific knowledge gaps around XenoGlip's cardiovascular safety data, with 37% of physicians uncertain about the CAROLINA trial results.146 147For this microsegment, educational messaging focused on simplified patient selection criteria and step-by-step initiation protocols would likely increase confidence in prescribing by approximately 23%.148 149When comparing promotional channels, virtual detailing with targeted clinical content shows 1.6x higher engagement than traditional sales visits for this specific physician group."""150 151def simulate_anthropic_api_call(model, prompt, max_tokens=1000):152    """153    Simulate a call to Anthropic API with Claude154    155    In a real implementation, this would use:156    157    import anthropic158    client = anthropic.Client(api_key="your-api-key")159    response = client.completions.create(160        model=model,161        prompt=prompt,162        max_tokens_to_sample=max_tokens,163    )164    return response.completion165    """166    167    # Mock API call with delay for realism168    time.sleep(2)169    170    # For demo purposes, just delegate to our existing simulator171    return simulate_claude_api_call(prompt)172 173def make_claude_api_call(prompt, model="claude-3-haiku-20240307"):174    """175    Wrapper function for Claude API calls176    177    This function can be modified to use the real API in production178    or the simulator for the demo179    """180    try:181        # For demo, use the simulator182        return simulate_anthropic_api_call(model, prompt)183        184        # For production with real API, uncomment the following:185        # import anthropic186        # import os187        # client = anthropic.Client(api_key=os.environ.get("ANTHROPIC_API_KEY"))188        # response = client.completions.create(189        #     model=model,190        #     prompt=prompt,191        #     max_tokens_to_sample=1000,192        # )193        # return response.completion194        195    except Exception as e:196        return f"Error calling Claude API: {str(e)}"