Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FastAPI class with PHDI BaseService for container apps #520

Merged
merged 22 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7381283
replaced FastAPI class with PHDI BaseService class
robertmitchellv Apr 28, 2023
c85145f
added run command to update+upgrade and add git
robertmitchellv Apr 28, 2023
f9e18f6
rename `app` variable back to `api` since tests import variable; can …
robertmitchellv Apr 28, 2023
669bbe6
added phdi package to requirements; all tests pass for alerts
robertmitchellv Apr 28, 2023
1ce13d0
added phdi to requirements
robertmitchellv Apr 28, 2023
70746f6
removing phdi from requirements; going to skip FHIR converter since b…
robertmitchellv Apr 28, 2023
2ebbb46
replaced FastAPI class with PHDI BaseService class
robertmitchellv Apr 28, 2023
22f496b
replaced FastAPI class with PHDI BaseService class for message parser
robertmitchellv Apr 28, 2023
410ff23
replaced FastAPI class with PHDI BaseService for record linkage; reta…
robertmitchellv Apr 28, 2023
9494385
fixed issue with the import for DIBBS_BASIC; was local issue with loc…
robertmitchellv Apr 29, 2023
1ba9e36
tabulation: replaced FastAPI with PHDI BaseService; all tests pass
robertmitchellv Apr 29, 2023
9edf62f
validation: replaced FastAPI with BaseService, all tests passed; fixe…
robertmitchellv Apr 29, 2023
faef488
replaced FastAPI with PHDI BaseService for FHIR converter; renamed md…
robertmitchellv May 1, 2023
a375405
Removed `health_check` tests since we have test converage for it with…
robertmitchellv May 2, 2023
e9fe0c2
Added optional license argument with default value for BaseService; a…
robertmitchellv May 2, 2023
36e3de8
added licese from Microsoft's FHIR-Converter repo to the description.…
robertmitchellv May 2, 2023
434a612
removed conflicting FastAPI version from requirements
robertmitchellv May 3, 2023
191e27e
fixed merge conflicts
robertmitchellv May 5, 2023
ccbab92
accidentially retained this old branch's version of the test i changed
robertmitchellv May 5, 2023
0279d83
removing versions to let pip manage dependancies
robertmitchellv May 8, 2023
353f09c
Merge branch 'main' of https://github.com/CDCgov/phdi into robert/add…
robertmitchellv May 8, 2023
1e9f9f1
added run_migration()
robertmitchellv May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion containers/alerts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ FROM python:3.10-slim

WORKDIR /code

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git

COPY ./requirements.txt /code/requirements.txt
RUN pip install -r requirements.txt

COPY ./app /code/app
COPY ./description.md /code/description.md

EXPOSE 8080
CMD uvicorn app.main:api --host 0.0.0.0 --port 8080
CMD uvicorn app.main:api --host 0.0.0.0 --port 8080
34 changes: 6 additions & 28 deletions containers/alerts/app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from phdi.containers.base_service import BaseService
from azure.communication.identity import CommunicationIdentityClient
from azure.communication.phonenumbers import (
PhoneNumbersClient,
Expand All @@ -8,7 +9,7 @@
)
from azure.communication.sms import SmsClient
from azure.identity import DefaultAzureCredential
from fastapi import FastAPI, Response, status
from fastapi import Response, status
from pydantic import BaseModel, BaseSettings, Field
import pymsteams
from functools import lru_cache
Expand All @@ -17,24 +18,10 @@
from slack_sdk.errors import SlackApiError
from typing import Optional

# Instantiate FastAPI and set metadata.
description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)
api = FastAPI(
title="PHDI Alerts Service",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)
# Instantiate FastAPI via PHDI's BaseService class
api = BaseService(
"PHDI Alerts Service", Path(__file__).parent.parent / "description.md"
).start()


class Settings(BaseSettings):
Expand Down Expand Up @@ -73,15 +60,6 @@ class TeamsAlertInput(BaseModel):
message: str = Field(description="The message to send to the Teams channel.")


@api.get("/")
async def health_check():
"""
Check service status. If an HTTP 200 status code is returned along with
'{"status": "OK"}' then the alerts service is available and running properly.
"""
return {"status": "OK"}


@api.post("/sms-alert", status_code=200)
async def sms_alert(input: SmsAlertInput, response: Response):
"""
Expand Down
3 changes: 2 additions & 1 deletion containers/alerts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ uvicorn
httpx
slack_sdk
pymsteams
pytest
pytest
phdi @ git+https://github.com/CDCgov/phdi.git@main
2 changes: 1 addition & 1 deletion containers/fhir-converter/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ uvicorn==0.17.6
uvloop==0.16.0
watchgod==0.8.2
websockets==10.3
uuid
uuid
30 changes: 6 additions & 24 deletions containers/ingestion/app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import FastAPI
from phdi.containers.base_service import BaseService
from app.routers import (
fhir_harmonization_standardization,
fhir_geospatial,
Expand All @@ -12,32 +12,14 @@
# Read settings immediately to fail fast in case there are invalid values.
get_settings()

# Instantiate FastAPI and set metadata.
description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)
app = FastAPI(
title="PHDI Ingestion Service",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)
# Instantiate FastAPI via PHDI's BaseService class
app = BaseService(
service_name="PHDI Ingestion Service",
description_path=Path(__file__).parent.parent / "description.md",
).start()

app.include_router(fhir_harmonization_standardization.router)
app.include_router(fhir_geospatial.router)
app.include_router(fhir_linkage_link.router)
app.include_router(fhir_transport_http.router)
app.include_router(cloud_storage.router)


@app.get("/")
async def health_check():
return {"status": "OK"}
37 changes: 7 additions & 30 deletions containers/message-parser/app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI, Response, status
from phdi.containers.base_service import BaseService
from fastapi import Response, status
from pydantic import BaseModel, Field, root_validator
from typing import Literal, Optional, Union
from pathlib import Path
Expand All @@ -16,35 +17,11 @@
# Read settings immediately to fail fast in case there are invalid values.
get_settings()

# Instantiate FastAPI and set metadata.
description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)
app = FastAPI(
title="PHDI Message Parser",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)


# /health_check endpoint #
@app.get("/")
async def health_check():
"""
Check service status. If an HTTP 200 status code is returned along with
'{"status": "OK"}' then the extraction service is available and running properly.
"""
return {"status": "OK"}

# Instantiate FastAPI via PHDI's BaseService class
app = BaseService(
service_name="PHDI Message Parser",
description_path=Path(__file__).parent.parent / "description.md",
).start()

# /parse_message endpoint #

Expand Down
27 changes: 8 additions & 19 deletions containers/record-linkage/app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from app.config import get_settings
from fastapi import FastAPI, Response, status
from fastapi import Response, status
from pathlib import Path
from phdi.containers.base_service import BaseService
from phdi.linkage import (
add_person_resource,
link_record_against_mpi,
Expand Down Expand Up @@ -62,24 +63,12 @@ def run_migrations():
print_psycopg2_exception(err)


# Instantiate FastAPI and set metadata.
description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)
app = FastAPI(
title="DIBBs Record Linkage Service",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)
# Instantiate FastAPI via PHDI's BaseService class
app = BaseService(
service_name="DIBBs Record Linkage Service",
description_path=Path(__file__).parent.parent / "description.md",
include_health_check_endpoint=False,
).start()


# Request and and response models
Expand Down
36 changes: 8 additions & 28 deletions containers/tabulation/app/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from fastapi import FastAPI, Response, status
from fastapi import Response, status
from pydantic import BaseModel, Field, validator
from typing import Optional, Literal
import urllib.parse
import datetime
import jsonschema
from pathlib import Path
from phdi.containers.base_service import BaseService
from phdi.cloud.core import BaseCredentialManager
from phdi.tabulation import validate_schema
from phdi.tabulation.tables import write_data
Expand All @@ -23,24 +24,12 @@
# Read settings from environmnent.
get_settings()

# Instantiate FastAPI and set metadata.
description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)
app = FastAPI(
title="PHDI Tabulation Service",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)

# Instantiate FastAPI via PHDI's BaseService class
app = BaseService(
service_name="PHDI Tabulation Service",
description_path=Path(__file__).parent.parent / "description.md",
).start()


class SchemaValidationInput(BaseModel):
Expand Down Expand Up @@ -79,15 +68,6 @@ class TabulateInput(BaseModel):
)


@app.get("/")
async def health_check():
"""
Check service status. If an HTTP 200 status code is returned along with
'{"status": "OK"}' then the tabulation service is available and running properly.
"""
return {"status": "OK"}


@app.post("/validate-schema", status_code=200)
async def validate_schema_endpoint(input: SchemaValidationInput):
try:
Expand Down
34 changes: 6 additions & 28 deletions containers/validation/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import FastAPI
from pydantic import BaseModel, Field
from typing import Literal
from pathlib import Path
from phdi.containers.base_service import BaseService
from phdi.validation.validation import validate_ecr
from .utils import load_ecr_config, validate_error_types

Expand All @@ -11,24 +11,11 @@
ecr_config = load_ecr_config()


# Instantiate FastAPI and set metadata.
description = (Path(__file__).parent.parent / "description.md").read_text(
encoding="utf-8"
)
app = FastAPI(
title="PHDI Validation Service",
version="0.0.1",
contact={
"name": "CDC Public Health Data Infrastructure",
"url": "https://cdcgov.github.io/phdi-site/",
"email": "dmibuildingblocks@cdc.gov",
},
license_info={
"name": "Creative Commons Zero v1.0 Universal",
"url": "https://creativecommons.org/publicdomain/zero/1.0/",
},
description=description,
)
# Instantiate FastAPI via PHDI's BaseService class
app = BaseService(
service_name="PHDI Validation Service",
description_path=Path(__file__).parent.parent / "description.md",
).start()


# Request and and response models
Expand Down Expand Up @@ -117,15 +104,6 @@ def validate_vxu_msg(message: str, include_error_types: list) -> ValidateRespons


# Endpoints
@app.get("/")
async def health_check():
"""
Check service status. If an HTTP 200 status code is returned along with
'{"status": "OK"}' then the tabulation service is available and running properly.
"""
return {"status": "OK"}


@app.post("/validate", status_code=200)
async def validate_endpoint(input: ValidateInput) -> ValidateResponse:
"""
Expand Down