update dtq conditions

This commit is contained in:
ipu 2025-08-05 00:00:58 +03:00
parent 80916f6c3e
commit 0a41d9ba82
11 changed files with 915 additions and 303 deletions

View file

@ -0,0 +1,262 @@
import asyncio
import json
from datetime import date
from typing import Dict, Any
# Import models from the centralized models file
from src.models import (
Applicant, Plan, PHQ, Medication, Issue, IssueDetail,
Condition, Address, EstimationRequest, EstimationResponse
)
from src.services.estimation_service_v2 import EstimationService
async def example_estimation_request():
"""Example of how to use the v2 estimation service"""
# Create sample applicants
applicants = [
Applicant(
applicant=0,
firstName="John",
lastName="Doe",
midName="",
phone="555-123-4567",
gender="male",
dob=date(1985, 3, 15),
nicotine=False,
weight=180.0,
heightFt=6,
heightIn=1
),
Applicant(
applicant=1,
firstName="Jane",
lastName="Doe",
midName="",
phone="555-123-4568",
gender="female",
dob=date(1988, 7, 22),
nicotine=False,
weight=140.0,
heightFt=5,
heightIn=6
)
]
# Create sample plans
plans = [
Plan(
id=1,
coverage=1, # Individual coverage
tier=None
)
]
# Create sample medications
medications = [
Medication(
applicant=0,
name="Lisinopril",
rxcui="29046",
dosage="10mg",
frequency="daily",
description="ACE inhibitor for blood pressure"
),
Medication(
applicant=1,
name="Metformin",
rxcui="6809",
dosage="500mg",
frequency="twice daily",
description="Diabetes medication"
)
]
# Create sample issues
issues = [
Issue(
key="hypertension",
details=[
IssueDetail(
key="diagnosed",
description="Hypertension diagnosed in 2020"
),
IssueDetail(
key="controlled",
description="Well controlled with medication"
)
]
),
Issue(
key="diabetes",
details=[
IssueDetail(
key="type2",
description="Type 2 diabetes diagnosed in 2021"
),
IssueDetail(
key="controlled",
description="Controlled with Metformin"
)
]
)
]
# Create sample conditions
conditions = [
Condition(
key="hypertension",
description="Essential hypertension"
),
Condition(
key="diabetes",
description="Type 2 diabetes mellitus"
)
]
# Create PHQ
phq = PHQ(
treatment=False,
invalid=False,
pregnancy=False,
effectiveDate=date.today(),
disclaimer=True,
signature="John Doe",
medications=medications,
issues=issues,
conditions=conditions
)
# Create address
address = Address(
address1="123 Main Street",
address2="Apt 4B",
city="Springfield",
state="IL",
zipcode="62701"
)
# Create estimation request
request = EstimationRequest(
uid="test_estimation_001",
applicants=applicants,
plans=plans,
phq=phq,
income=75000.0,
address=address
)
print("=== Insurance Estimation Service V2 Example ===\n")
print("Request Data:")
print(json.dumps(request.model_dump(), indent=2, default=str))
print("\n" + "="*50 + "\n")
try:
# Create estimation service
estimation_service = EstimationService()
# Call the estimation service
print("Calling estimation service...")
result = await estimation_service.estimate_insurance(
applicants=applicants,
phq=phq,
plans=plans
)
print("Estimation Result:")
print(json.dumps(result.model_dump(), indent=2, default=str))
# Display a summary
if result.status == "accepted":
details = result.details
print(f"\n=== SUMMARY ===")
print(f"Status: {result.status}")
print(f"DTQ: {details.dtq}")
print(f"Reason: {details.reason}")
print(f"Tier: {details.tier}")
print(f"Total Price: ${details.total_price:,.2f}")
if result.results:
print(f"\nApplicant Results:")
for applicant_result in result.results:
print(f"- {applicant_result.name}")
print(f" Age: {applicant_result.age}")
print(f" BMI: {applicant_result.bmi:.1f}")
print(f" Tier: {applicant_result.tier}")
print(f" RX Spend: ${applicant_result.rx_spend:,.2f}")
print(f" Message: {applicant_result.message}")
else:
print(f"\nEstimation failed: {result.status}")
if result.details:
print(f"Reason: {result.details.reason}")
except Exception as e:
print(f"Error calling estimation service: {str(e)}")
import traceback
traceback.print_exc()
async def example_minimal_request():
"""Example with minimal required data"""
# Create minimal applicant
applicant = Applicant(
applicant=0,
firstName="Alice",
lastName="Smith",
midName="",
phone="",
gender="female",
dob=date(1990, 1, 1),
nicotine=False,
weight=150.0,
heightFt=5,
heightIn=7
)
# Create minimal plan
plan = Plan(
id=1,
coverage=1,
tier=None
)
# Create minimal PHQ
phq = PHQ(
treatment=False,
invalid=False,
pregnancy=False,
effectiveDate=date.today(),
disclaimer=True,
signature="Alice Smith",
medications=[],
issues=[],
conditions=[]
)
print("\n=== Minimal Request Example ===\n")
print("Minimal Request Data:")
print(f"Applicant: {applicant.firstName} {applicant.lastName}")
print(f"Age: {applicant.dob}")
print(f"Plan Coverage: {plan.coverage}")
print("\n" + "="*50 + "\n")
try:
estimation_service = EstimationService()
result = await estimation_service.estimate_insurance(
applicants=[applicant],
phq=phq,
plans=[plan]
)
print("Minimal Request Result:")
print(json.dumps(result.model_dump(), indent=2, default=str))
except Exception as e:
print(f"Error with minimal request: {str(e)}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
# Run the examples
asyncio.run(example_estimation_request())
asyncio.run(example_minimal_request())