cryogenic22 commited on
Commit
898a892
·
verified ·
1 Parent(s): 46922d7

Create api_simulator.py

Browse files
Files changed (1) hide show
  1. api_simulator.py +196 -0
api_simulator.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+
3
+ def 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 call
6
+ # For demo purposes, we'll return predefined responses based on the prompt
7
+
8
+ # Mock waiting time for API call to seem realistic
9
+ 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
+
14
+ 1. 72% would prescribe XenoGlip as a second-line therapy after metformin failure for patients with an A1C between 7.5-8.5%
15
+ 2. Key drivers include: perceived cardiovascular safety profile (83%), once-daily dosing (76%), and favorable formulary status (68%)
16
+ 3. Main barriers to adoption are: concerns about pancreatitis risk (41%), patient cost concerns (37%), and preference for newer GLP-1 options (29%)
17
+ 4. When comparing to competitors, physicians rate XenoGlip higher on "ease of use" and "patient adherence" but lower on "glycemic efficacy" and "weight management"
18
+
19
+ This 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
+
24
+ 1. Only 38% would prescribe XenoGlip as a second-line therapy, preferring GLP-1 agonists (47%) or SGLT2 inhibitors (15%)
25
+ 2. Key considerations include: comprehensive glycemic control (91%), weight effects (87%), and cardiorenal protection (83%)
26
+ 3. This segment is highly influenced by recent clinical trial data and guideline updates
27
+ 4. They express specific concerns about XenoGlip's efficacy in patients with A1C >9.0% and its neutral effect on weight
28
+
29
+ Messages 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
+
34
+ 1. For Primary Care: "XenoGlip provides reliable A1C reduction with once-daily dosing and proven cardiovascular safety" (estimated 76% receptivity)
35
+
36
+ 2. For Endocrinologists: "XenoGlip offers flexible integration into treatment regimens with minimal drug-drug interactions and established safety profile" (estimated 64% receptivity)
37
+
38
+ 3. 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
+
40
+ 4. 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
+
45
+ 1. If moved from Tier 3 to Tier 2 status on major commercial plans:
46
+ - 43% increase in new prescriptions among PCPs
47
+ - 26% increase among endocrinologists
48
+ - Overall market share would likely increase by 2.3 percentage points within 6 months
49
+
50
+ 2. If prior authorization requirements were removed:
51
+ - 38% of physicians who currently prescribe competitors would consider XenoGlip
52
+ - Time to first prescription would decrease by approximately 22 days
53
+
54
+ 3. 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
+
59
+ 1. 64% of PCPs would add XenoGlip
60
+ 2. 22% would add a GLP-1 agonist
61
+ 3. 14% would add an SGLT2 inhibitor
62
+
63
+ Key factors influencing this decision include:
64
+ - Patient's commercial insurance status and formulary positioning
65
+ - 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
+
69
+ If 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
+
74
+ 1. Near-term projection (6 months):
75
+ - 11.2% growth in total prescriptions
76
+ - Highest growth among PCPs practicing in group settings (17.4%)
77
+ - Limited growth among specialists (5.1%)
78
+
79
+ 2. 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
+
84
+ 3. 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
+
86
+ 4. 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
+
91
+ 1. Perceived efficacy limitations:
92
+ - 68% of non-prescribers cite concerns about efficacy relative to newer classes
93
+ - 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 populations
95
+
96
+ 2. Formulary and access issues:
97
+ - 72% indicate tier positioning as a significant barrier
98
+ - Prior authorization requirements delay initiation by an average of 18.4 days
99
+ - Patient abandonment rates of 31% when out-of-pocket costs exceed $50/month
100
+
101
+ 3. Competition from newer therapeutic classes:
102
+ - Growing preference for GLP-1s and SGLT2s due to extra-glycemic benefits
103
+ - Decreasing comfort with initiating DPP-4 inhibitors in patients with cardiovascular disease
104
+ - Perception gap between clinical trial results and real-world expectations
105
+
106
+ 4. Knowledge gaps in specific areas:
107
+ - 41% of physicians uncertain about long-term safety profile
108
+ - 36% unfamiliar with newest data on cardiovascular outcomes
109
+ - 28% unclear on appropriate patient selection criteria
110
+
111
+ The 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
+
116
+ 1. Relative to other DPP-4 inhibitors:
117
+ - Perceived as therapeutically similar by 76% of physicians
118
+ - Differentiated primarily on formulary status rather than clinical attributes
119
+ - Slight preference (53%) for XenoGlip among physicians who express a DPP-4 class preference
120
+
121
+ 2. 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 elderly
125
+ - Cost advantage perceived by 82% of physicians, though this varies by plan
126
+
127
+ 3. Against SGLT2 inhibitors:
128
+ - Lower perception of cardiorenal benefit (cited by 89% of physicians)
129
+ - Higher perceived safety in patients with renal impairment
130
+ - Fewer concerns about genitourinary side effects (important for 64% of PCPs)
131
+ - Similar formulary positioning in most regions
132
+
133
+ 4. Across all diabetes treatments:
134
+ - Ranked 4th in overall prescriber preference for second-line therapy
135
+ - Highest ranked for "ease of initiation" and "minimal monitoring requirements"
136
+ - Lowest ranked for "weight management" and "impact beyond glycemic control"
137
+
138
+ The 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
+
143
+ The 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
+
145
+ The simulation identified specific knowledge gaps around XenoGlip's cardiovascular safety data, with 37% of physicians uncertain about the CAROLINA trial results.
146
+
147
+ For 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
+
149
+ When comparing promotional channels, virtual detailing with targeted clinical content shows 1.6x higher engagement than traditional sales visits for this specific physician group."""
150
+
151
+ def simulate_anthropic_api_call(model, prompt, max_tokens=1000):
152
+ """
153
+ Simulate a call to Anthropic API with Claude
154
+
155
+ In a real implementation, this would use:
156
+
157
+ import anthropic
158
+ 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.completion
165
+ """
166
+
167
+ # Mock API call with delay for realism
168
+ time.sleep(2)
169
+
170
+ # For demo purposes, just delegate to our existing simulator
171
+ return simulate_claude_api_call(prompt)
172
+
173
+ def make_claude_api_call(prompt, model="claude-3-haiku-20240307"):
174
+ """
175
+ Wrapper function for Claude API calls
176
+
177
+ This function can be modified to use the real API in production
178
+ or the simulator for the demo
179
+ """
180
+ try:
181
+ # For demo, use the simulator
182
+ return simulate_anthropic_api_call(model, prompt)
183
+
184
+ # For production with real API, uncomment the following:
185
+ # import anthropic
186
+ # import os
187
+ # 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.completion
194
+
195
+ except Exception as e:
196
+ return f"Error calling Claude API: {str(e)}"