-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
115 lines (104 loc) · 3.23 KB
/
main.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from fastapi import FastAPI, status
from model.study_version import *
from model.wrapper import Wrapper
from uuid import UUID, uuid4
VERSION = "3.8.0"
SYSTEM_NAME = "DDF USDM API"
tags_metadata = [
{
"name": "Production",
"description": "Routes that form the production specification."
}
]
annotations = {
"study": {
'post': {
'summary': "Create a study",
'description': "Create a study resource"
},
'get': {
'summary': "List the studies",
'description': "Return the identifiers for all the studies in the repository"
},
'get_uuid': {
'summary': "Return a study",
'description': "Return an study resource"
}
},
"study_definition": {
'post': {
'summary': "Create a study",
'description': "Create an entire study including all child element with a single post"
},
'put': {
'summary': "Update a study",
'description': "Update an entire study including all child element with a single put"
},
'get': {
'summary': "List the studies",
'description': "Return the identifiers for all the studies in the repository"
},
'get_uuid': {
'summary': "Return a study",
'description': "Return an entire study including all child elements"
}
}
}
standard_response_fields = {
"status_code": "string",
"detail": "string",
"message": "string"
}
standard_responses = {
400: standard_response_fields,
401: standard_response_fields
}
app = FastAPI(
title = SYSTEM_NAME,
description = "A simple TransCelerate Digital Data Flow (DDF) Study Definitions Repository API.",
version = VERSION,
openapi_tags = tags_metadata
)
@app.post("/v3/studyDefinitions",
tags=["Production"],
summary=annotations['study_definition']['post']['summary'],
description=annotations['study_definition']['post']['description'],
status_code=status.HTTP_201_CREATED,
response_model=UUID,
responses=standard_responses)
async def create_study(study: Wrapper):
return str(uuid4())
@app.put("/v3/studyDefinitions/{studyId}",
tags=["Production"],
summary=annotations['study_definition']['put']['summary'],
description=annotations['study_definition']['put']['description'],
status_code=status.HTTP_200_OK,
response_model=UUID,
responses=standard_responses)
async def update_study(studyId: str, study: Wrapper):
return studyId
@app.get("/v3/studyDefinitions/{studyId}",
tags=["Production"],
summary=annotations['study_definition']['get_uuid']['summary'],
description=annotations['study_definition']['get_uuid']['description'],
response_model=Wrapper,
responses=standard_responses)
async def read_full_study(studyId: str):
return {}
@app.get("/v3/studyDefinitions/{studyId}/history",
tags=["Production"],
summary="Returns the study history",
description="Returns the history for the specified study",
response_model=List[Wrapper],
responses=standard_responses)
async def read_study_history(studyId: str):
return []
@app.get("/v3/studyDesigns",
tags=['Production'],
summary='Study designs for a study',
description='Returns all the study designs for a specified study.',
response_model=List[StudyDesign],
responses=standard_responses
)
async def search_study_design(studyId: UUID):
return []