lloza7 commited on
Commit
21a6702
·
verified ·
1 Parent(s): 1d19d13

Upload 3 files

Browse files
Files changed (1) hide show
  1. thicc/insurance/coverage_explainer.py +248 -0
thicc/insurance/coverage_explainer.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Coverage Explanations Module - Provides insurance term explanations.
3
+ """
4
+
5
+ class CoverageExplainer:
6
+ """Explains insurance coverage terms in user-friendly language."""
7
+
8
+ COVERAGE_TERMS = {
9
+ "deductible": {
10
+ "brief": "The amount you pay before insurance starts covering costs",
11
+ "detailed": """A deductible is the amount you must pay out-of-pocket for covered healthcare services before your insurance plan starts to pay.
12
+
13
+ **Example**: If you have a $1,000 deductible:
14
+ • You pay the first $1,000 of covered services yourself
15
+ • After meeting your deductible, you typically pay only copays or coinsurance
16
+ • Deductibles reset yearly
17
+
18
+ **Important**: Some services like preventive care may be covered before you meet your deductible.""",
19
+ "keywords": ["deductible", "deductibles", "yearly amount", "before insurance pays"],
20
+ },
21
+
22
+ "copay": {
23
+ "brief": "A fixed amount you pay for a covered service",
24
+ "detailed": """A copay (copayment) is a fixed amount you pay for a covered healthcare service, usually at the time of service.
25
+
26
+ **Example**:
27
+ • Doctor visit: $25 copay
28
+ • Specialist visit: $50 copay
29
+ • Prescription: $10 copay
30
+
31
+ **Key Points**:
32
+ • Copays are typically the same regardless of the actual cost
33
+ • You usually pay copays even after meeting your deductible
34
+ • Different services have different copay amounts""",
35
+ "keywords": ["copay", "copayment", "fixed amount", "flat fee"],
36
+ },
37
+
38
+ "coinsurance": {
39
+ "brief": "Your percentage share of costs after deductible",
40
+ "detailed": """Coinsurance is your share of the costs of a covered healthcare service, calculated as a percentage of the allowed amount for the service.
41
+
42
+ **Example**: With 20% coinsurance:
43
+ • Insurance pays 80% of covered costs
44
+ • You pay 20% of covered costs
45
+ • This applies AFTER you meet your deductible
46
+
47
+ **Real Scenario**:
48
+ MRI costs $1,000 (after deductible met)
49
+ • Insurance pays: $800 (80%)
50
+ • You pay: $200 (20%)""",
51
+ "keywords": ["coinsurance", "percentage", "percent of cost", "cost sharing", "80/20", "70/30"],
52
+ },
53
+
54
+ "out_of_network": {
55
+ "brief": "Higher costs for providers not in your insurance network",
56
+ "detailed": """Out-of-network refers to healthcare providers who haven't contracted with your insurance company to provide services at negotiated rates.
57
+
58
+ **Penalties and Higher Costs**:
59
+ • Higher deductibles (often double in-network amounts)
60
+ • Higher coinsurance (40-50% vs 20-30%)
61
+ • No negotiated rates (you may pay full price)
62
+ • Balance billing (provider can bill you the difference)
63
+
64
+ **Example Cost Difference**:
65
+ Same procedure:
66
+ • In-network: You pay $500 (20% coinsurance)
67
+ • Out-of-network: You pay $2,000 (50% coinsurance + balance billing)
68
+
69
+ **Tip**: Always check if a provider is in-network before receiving care, except in emergencies.""",
70
+ "keywords": [
71
+ "out of network",
72
+ "out-of-network",
73
+ "network penalties",
74
+ "provider network",
75
+ "in-network",
76
+ "network",
77
+ ],
78
+ },
79
+
80
+ "out_of_pocket_maximum": {
81
+ "brief": "The most you'll pay in a year for covered services",
82
+ "detailed": """The out-of-pocket maximum is the most you have to pay for covered services in a plan year. After you reach this amount, your insurance pays 100% of covered services.
83
+
84
+ **What Counts**:
85
+ ✓ Deductibles
86
+ ✓ Copayments
87
+ ✓ Coinsurance
88
+
89
+ **What Doesn't Count**:
90
+ ✗ Monthly premiums
91
+ ✗ Out-of-network costs (usually)
92
+ ✗ Non-covered services
93
+
94
+ **Example**: $8,000 out-of-pocket maximum
95
+ Once you've paid $8,000 in deductibles, copays, and coinsurance, your insurance covers 100% for the rest of the year.""",
96
+ "keywords": [
97
+ "out of pocket maximum",
98
+ "out-of-pocket maximum",
99
+ "max",
100
+ "maximum",
101
+ "yearly limit",
102
+ "annual limit",
103
+ "oop max",
104
+ ],
105
+ },
106
+
107
+ "premium": {
108
+ "brief": "Monthly payment to maintain insurance coverage",
109
+ "detailed": """Your premium is the amount you pay for your health insurance every month to maintain coverage, regardless of whether you use services.
110
+
111
+ **Key Points**:
112
+ • Due monthly whether you use healthcare or not
113
+ • Doesn't count toward deductible or out-of-pocket maximum
114
+ • Higher premiums often mean lower deductibles/copays
115
+ • Employer may pay part of your premium
116
+
117
+ **Example Monthly Premiums**:
118
+ • Individual: $450/month
119
+ • Family: $1,200/month""",
120
+ "keywords": ["premium", "monthly payment", "monthly cost", "insurance payment"],
121
+ },
122
+
123
+ "prior_authorization": {
124
+ "brief": "Insurance approval needed before certain services",
125
+ "detailed": """Prior authorization (preauthorization) means your insurance company must approve a service before you receive it for the service to be covered.
126
+
127
+ **Common Services Requiring Authorization**:
128
+ • MRI/CT scans
129
+ • Surgery
130
+ • Expensive medications
131
+ • Specialist referrals (HMO plans)
132
+
133
+ **Important**:
134
+ • Without authorization, insurance may deny coverage
135
+ • Your doctor typically handles the authorization
136
+ • Can take days to weeks for approval
137
+ • Emergency services don't require prior authorization""",
138
+ "keywords": [
139
+ "prior authorization",
140
+ "preauthorization",
141
+ "pre-approval",
142
+ "authorization",
143
+ "approval needed",
144
+ ],
145
+ },
146
+ }
147
+
148
+ @classmethod
149
+ def explain_term(cls, term: str) -> str | None:
150
+ """Get detailed explanation for a specific coverage term."""
151
+ term_lower = term.lower().strip()
152
+
153
+ for key, info in cls.COVERAGE_TERMS.items():
154
+ if key in term_lower or any(keyword in term_lower for keyword in info["keywords"]):
155
+ return info["detailed"]
156
+
157
+ return None
158
+
159
+ @classmethod
160
+ def get_brief_explanation(cls, term: str) -> str | None:
161
+ """Get brief explanation for a coverage term."""
162
+ term_lower = term.lower().strip()
163
+
164
+ for key, info in cls.COVERAGE_TERMS.items():
165
+ if key in term_lower or any(keyword in term_lower for keyword in info["keywords"]):
166
+ return info["brief"]
167
+
168
+ return None
169
+
170
+ @classmethod
171
+ def explain_all_terms(cls) -> str:
172
+ """Return explanations for all coverage terms."""
173
+ explanations = ["**Understanding Your Insurance Coverage**\n"]
174
+
175
+ for term, info in cls.COVERAGE_TERMS.items():
176
+ title = term.replace("_", " ").title()
177
+ explanations.append(f"**{title}**")
178
+ explanations.append(info["detailed"])
179
+ explanations.append("")
180
+
181
+ return "\n".join(explanations)
182
+
183
+ @classmethod
184
+ def identify_coverage_question(cls, user_input: str) -> bool:
185
+ """Check if user is asking about coverage terms."""
186
+ user_input_lower = user_input.lower()
187
+
188
+ # General coverage question patterns
189
+ general_terms = [
190
+ "what is",
191
+ "what's",
192
+ "explain",
193
+ "how does",
194
+ "how do",
195
+ "tell me about",
196
+ "help me understand",
197
+ "coverage",
198
+ "insurance terms",
199
+ "insurance work",
200
+ ]
201
+
202
+ # Check for general questions with coverage terms
203
+ if any(term in user_input_lower for term in general_terms):
204
+ for term_info in cls.COVERAGE_TERMS.values():
205
+ if any(keyword in user_input_lower for keyword in term_info["keywords"]):
206
+ return True
207
+
208
+ # Direct term mentions
209
+ for term_info in cls.COVERAGE_TERMS.values():
210
+ if any(keyword in user_input_lower for keyword in term_info["keywords"]):
211
+ return True
212
+
213
+ return False
214
+
215
+ @classmethod
216
+ def get_matching_term(cls, user_input: str) -> str | None:
217
+ """Extract which coverage term the user is asking about."""
218
+ user_input_lower = user_input.lower()
219
+
220
+ for term_key, term_info in cls.COVERAGE_TERMS.items():
221
+ for keyword in term_info["keywords"]:
222
+ if keyword in user_input_lower:
223
+ return term_key
224
+
225
+ return None
226
+
227
+ @classmethod
228
+ def format_plan_coverage_summary(cls, plan_name: str, plan_details: dict) -> str:
229
+ """Format a summary of coverage for a specific plan."""
230
+ deductible = plan_details.get("deductible", 0)
231
+ copay = plan_details.get("copay", 0)
232
+ coinsurance = plan_details.get("coinsurance", 0) * 100
233
+
234
+ return f"""**Your {plan_name} Plan Coverage**
235
+
236
+ **Deductible**: ${deductible:,.0f}
237
+ • You pay this amount first before insurance helps
238
+
239
+ **Copay**: ${copay:.0f}
240
+ • Fixed amount you pay per visit
241
+
242
+ **Coinsurance**: {coinsurance:.0f}%
243
+ • Your percentage share after deductible
244
+
245
+ **How it works**:
246
+ 1. You pay 100% until you meet your ${deductible:,.0f} deductible
247
+ 2. Then you pay ${copay:.0f} copays or {coinsurance:.0f}% coinsurance
248
+ 3. Insurance covers the rest up to allowed amounts"""