File size: 2,141 Bytes
2d6ca2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Pydantic models for request/response validation
"""

from pydantic import BaseModel, Field
from typing import List, Dict, Optional

class TextRequest(BaseModel):
    """Request model for text-only analysis"""
    text: str = Field(..., min_length=10, description="Radiology report text")
    
    class Config:
        json_schema_extra = {
            "example": {
                "text": "FINDINGS: The cardiac silhouette is within normal limits. The lungs are clear. No pleural effusion or pneumothorax."
            }
        }

class Entity(BaseModel):
    """Individual entity detected by NER"""
    text: str
    label: str
    start: int
    end: int
    confidence: float = 0.99

class StructuredReport(BaseModel):
    """Structured representation of report findings"""
    anatomy: List[str]
    all_observations: List[str]
    positive_findings: List[str]
    negative_findings: List[str]
    critical_findings: List[str]

class Summary(BaseModel):
    """Summary statistics of the analysis"""
    total_entities: int
    anatomy_count: int
    observations_count: int
    has_critical_findings: bool
    has_abnormalities: bool

class ImageData(BaseModel):
    """Extracted image from PDF"""
    page: int
    format: str
    width: int
    height: int
    data: str  # base64 encoded

class AnalysisResponse(BaseModel):
    """Complete analysis response"""
    status: str
    processing_time: float
    input_type: str
    ocr_used: bool
    ocr_engine: Optional[str] = None
    raw_text: str
    text_length: int
    entities: List[Entity]
    structured_report: StructuredReport
    summary: Summary
    recommendations: List[str]
    images: Optional[List[ImageData]] = None

class EncryptedRequest(BaseModel):
    """Encrypted and compressed file request"""
    ciphertext: str
    nonce: str 
    
    class Config:
        json_schema_extra = {
            "example": {
                "ciphertext": "mJXnK8p9VGhpN...",
                "nonce": "Y2FzZGFzZGFzZA=="
            }
        }

class EncryptedResponse(BaseModel):
    """Encrypted response"""
    ciphertext: str
    nonce: str
    status: str = "success"