File size: 2,719 Bytes
3b4ba75
 
 
 
 
 
 
 
b36498c
 
3b4ba75
 
 
 
 
b36498c
 
3b4ba75
 
 
 
 
 
b36498c
 
3b4ba75
 
 
 
 
 
 
 
b36498c
 
3b4ba75
 
 
 
b36498c
3b4ba75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b36498c
 
 
3b4ba75
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
#!/usr/bin/env python3
"""MedGenesis – **data schemas** powered by `pydantic`.

This module formalises the JSON objects exchanged between the backend
(orchestrator) and the Streamlit UI.  It now aligns with the *enhanced*
pipeline that returns live genes, trials, and Open Targets edges.
"""
from __future__ import annotations

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

# ----------------------------------------------------------------------
# Literature & concepts
# ----------------------------------------------------------------------

class Paper(BaseModel):
    title     : str
    authors   : str
    summary   : str
    link      : HttpUrl
    published : str  = Field(description="ISO date string")
    source    : str  = Field(description="'arxiv' | 'pubmed' | other")

class UMLSConcept(BaseModel):
    term       : str
    cui        : Optional[str]
    name       : Optional[str]
    rootSource : Optional[str]

# ----------------------------------------------------------------------
# Safety & biomedical enrichers
# ----------------------------------------------------------------------

class DrugSafety(BaseModel):
    safety_report_id : Optional[str]
    serious          : Optional[str]
    reactions        : Optional[List[str]]
    receivedate      : Optional[str]

class GeneInfo(BaseModel):
    symbol     : str
    name       : Optional[str]
    summary    : Optional[str]
    entrezgene : Optional[int]
    clinvar    : Optional[dict]

class MeshDefinition(BaseModel):
    term       : str
    definition : str

class GeneDiseaseLink(BaseModel):
    gene_symbol : str
    disease_id  : str
    score       : float

class ClinicalTrial(BaseModel):
    nct_id     : str = Field(alias="nctId")
    brief_title: str = Field(alias="briefTitle")
    phase      : Optional[str]
    status     : Optional[str]
    start_date : Optional[str]

class OTAssociation(BaseModel):
    score       : float
    datatypeId  : str
    datasourceId: str
    disease     : dict  # {id, name}
    target      : dict  # {id, symbol}

# ----------------------------------------------------------------------
# Search I/O
# ----------------------------------------------------------------------

class UnifiedSearchInput(BaseModel):
    query: str

class UnifiedSearchResult(BaseModel):
    papers          : List[Paper]
    umls            : List[UMLSConcept]
    drug_safety     : List[DrugSafety]
    genes           : List[GeneInfo]
    mesh_defs       : List[MeshDefinition]
    gene_disease    : List[GeneDiseaseLink]
    clinical_trials : List[ClinicalTrial]
    ot_associations : Optional[List[OTAssociation]] = []
    ai_summary      : str
    llm_used        : str