Skip to content

Commit 8c32d7b

Browse files
nathanwallJim Alcock
andauthored
new sandbox (#12)
* new sandbox * linting --------- Co-authored-by: Jim Alcock <[email protected]>
1 parent 2b208bc commit 8c32d7b

22 files changed

+923
-113
lines changed

azure/azure-release-pipeline.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ extends:
5757
# - template: ./templates/run-tests.yml
5858
- environment: sandbox
5959
proxy_path: sandbox
60-
post_deploy:
61-
- template: ./templates/run-tests.yml
6260
# # Enable int environment when ready by uncommenting:
6361
# - environment: int
6462
# depends_on:

ecs-proxies-deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ docker_service:
88
value: "{{ 'debug' if APIGEE_ENVIRONMENT == 'internal-dev' else 'info' }}"
99
- name: VERSION_INFO
1010
value: "{{ version_info | to_json }}"
11+
- name: SERVICE_BASE_PATH
12+
value: "{{ SERVICE_BASE_PATH }}"
1113
health_check:
1214
matcher: "200"
1315
path: "/_ping"

openapi.json

Lines changed: 1 addition & 95 deletions
Large diffs are not rendered by default.

sandbox/fhir_api/__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@
44
import os
55
from fastapi import FastAPI
66

7-
from fhir_api.routes import root
8-
from fhir_api.routes import endpoints
7+
from fhir_api.routes import (
8+
root,
9+
dynamodb,
10+
status_endpoints,
11+
)
12+
13+
from fhir_api.models.fhir_r4.common import Reference, Identifier
14+
15+
Reference.update_forward_refs(identifier=Identifier)
916

1017

1118
app = FastAPI(
1219
title=os.getenv('FASTAPI_TITLE', 'Immunization Fhir API'),
1320
description=os.getenv(
1421
'FASTAPI_DESC', 'API'),
15-
version=os.getenv('VERSION', 'SANDBOX'))
22+
version=os.getenv('VERSION', 'DEVELOPMENT'),
23+
root_path=f'/{os.getenv("SERVICE_BASE_PATH")}/',
24+
docs_url="/documentation",
25+
redoc_url="/redocumentation")
1626

1727

1828
# ENDPOINT ROUTERS
1929
app.include_router(root.router)
20-
app.include_router(endpoints.router)
30+
app.include_router(dynamodb.router)
31+
app.include_router(status_endpoints.router)

sandbox/fhir_api/exceptions/__init__.py

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
""" Base Exceptions that can be used across all collections """
2+
3+
4+
# pylint: disable=W0231
5+
6+
from typing import Type
7+
import fastapi
8+
from fastapi.responses import JSONResponse
9+
from fhir_api.models.errors import (
10+
NotFoundError,
11+
AlreadyExistsError,
12+
WebSocketError,
13+
BaseError,
14+
BaseIdentifiedError
15+
)
16+
17+
18+
class BaseAPIException(Exception):
19+
""" Base Error for custom API exceptions """
20+
message = "Exception Occured"
21+
code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR
22+
model = BaseError
23+
24+
def __init__(self, **kwargs):
25+
kwargs.setdefault("message", self.message)
26+
self.message = kwargs["message"]
27+
self.data = self.model(**kwargs)
28+
29+
def response(self):
30+
return JSONResponse(
31+
content=self.data.dict(),
32+
status_code=self.code
33+
)
34+
35+
@classmethod
36+
def response_model(cls):
37+
return {cls.code: {"model": cls.model}}
38+
39+
40+
class BaseIdentifiedException(BaseAPIException):
41+
"""Base error for exceptions related with entities, uniquely identified"""
42+
message = "Entity error"
43+
code = fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR
44+
model = BaseIdentifiedError
45+
46+
def __init__(self, identifier, **kwargs):
47+
super().__init__(identifier=identifier, **kwargs)
48+
49+
50+
class NotFoundException(BaseIdentifiedException):
51+
"""Base error for exceptions raised because an entity does not exist"""
52+
message = "The entity does not exist"
53+
code = fastapi.status.HTTP_404_NOT_FOUND
54+
model = NotFoundError
55+
56+
57+
class AlreadyExistsException(BaseIdentifiedException):
58+
"""Base error for exceptions raised because an entity already exists"""
59+
message = "The entity already exists"
60+
code = fastapi.status.HTTP_409_CONFLICT
61+
model = AlreadyExistsError
62+
63+
64+
class WebSocketException(BaseAPIException):
65+
""" Base Error for websocket exceptions """
66+
message = "Websocket encountered an error"
67+
code = fastapi.status.HTTP_418_IM_A_TEAPOT
68+
model = WebSocketError
69+
70+
71+
def get_exception_responses(*args: Type[BaseAPIException]) -> dict:
72+
""" return a dict of responses used on FastAPI endpoint """
73+
responses = {}
74+
for cls in args:
75+
responses.update(cls.response_model())
76+
return responses

sandbox/fhir_api/models/dynamodb/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
''' Data input model for DynamoDB '''
2+
3+
from typing import Optional
4+
from pydantic import (
5+
BaseModel,
6+
)
7+
8+
from fhir_api.models.fhir_r4.fhir_datatype_fields import FhirR4Fields
9+
10+
11+
class DataInput(BaseModel):
12+
''' Data input model '''
13+
nhsNumber: str = FhirR4Fields.string
14+
data: Optional[dict]
15+
16+
17+
class SuccessModel(BaseModel):
18+
''' SuccessModel for interacting with DynamoDB'''
19+
success: bool = FhirR4Fields.boolean
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
''' Read Models for Dynamodb'''
2+
from typing import (
3+
Union,
4+
Literal,
5+
Optional,
6+
)
7+
from pydantic import (
8+
BaseModel,
9+
Field,
10+
)
11+
12+
from fhir_api.models.fhir_r4.fhir_datatype_fields import FhirR4Fields
13+
from fhir_api.models.fhir_r4.immunization import Immunization
14+
from fhir_api.models.fhir_r4.patient import Patient
15+
16+
17+
class Resource(BaseModel):
18+
''' Wrapper Model for returned resource '''
19+
fullUrl: str = FhirR4Fields.uri
20+
resource: Union[Immunization, Patient]
21+
search: Optional[dict] = {"mode": "match"} # This looks to be api specific
22+
23+
24+
class BatchImmunizationRead(BaseModel):
25+
''' Model for Multiple records '''
26+
resourceType: Literal["Bundle"] = Field(default="Bundle")
27+
type: str = FhirR4Fields.string
28+
total: int = FhirR4Fields.integer
29+
entry: list[Resource]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
''' Models for interacting with tables '''
2+
3+
from pydantic import (
4+
BaseModel,
5+
Field,
6+
)
7+
8+
9+
class KeySchema(BaseModel):
10+
AttributeName: str = Field(description="Attribute Name for Key Schema", example="year")
11+
KeyType: str = Field(description="Key Type for Key Schema", example="HASH")
12+
13+
14+
class AttributeDefinitions(BaseModel):
15+
AttributeName: str = Field(description="Attribute Name for Attribute Definition", example="year")
16+
AttributeType: str = Field(description="Attribute Type for Attribute Definition", example="N")
17+
18+
19+
class ProvisionedThroughput(BaseModel):
20+
ReadCapacityUnits: int = Field(description="Read Capacity Units", example=10)
21+
WriteCapacityUnits: int = Field(description="Write Capacity Units", example=10)
22+
23+
24+
class CreateTable(BaseModel):
25+
table_name: str
26+
key_schema: list[KeySchema]
27+
attribute_definition: list[AttributeDefinitions]
28+
provisioned_throughput: ProvisionedThroughput

0 commit comments

Comments
 (0)