File size: 1,176 Bytes
53ac08b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class StudyText(BaseModel):
    text: str

def extract_study_timeline(text: str):
    screening = re.search(r'(?:Screening|Pre-study observation|Initial Check)(?:\s*(?:phase|period))?\s*(?:is|:|-|of|lasts)?\s*(\d+)\s*weeks?', text, re.IGNORECASE)
    treatment = re.search(r'(?:Treatment|Intervention|Therapy|Dosing phase|Main study(?:\s*period)?)(?:\s*(?:is|:|-|of|lasts))?\s*(\d+)\s*weeks?', text, re.IGNORECASE)
    follow_up = re.search(r'(?:Follow[-\s]*up|Recovery|Post-study monitoring|Observation phase|After-treatment)(?:\s*(?:is|:|-|of|lasts))?\s*(\d+)\s*weeks?', text, re.IGNORECASE)

    return {
        "Screening": int(screening.group(1)) if screening else None,
        "Treatment": int(treatment.group(1)) if treatment else None,
        "Follow-Up": int(follow_up.group(1)) if follow_up else None
    }

@app.post("/extract-timeline/")
async def extract_timeline(request: StudyText):
    return extract_study_timeline(request.text)

@app.get("/")
async def root():
    return {"message": "Study Timeline Extractor API is running. Use /extract-timeline/ to extract data."}