File size: 2,991 Bytes
75660bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'''

    purpose:      

'''

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi import APIRouter, Request, Response
from fastapi.templating import Jinja2Templates
import uvicorn


from lib import claims as libClaims, providers as libProviders
import lib.utils as libUtils
from lib.models import mdl_utils as libMdlUtils


#--- imported route handlers
from routes.api.rte_api import rteApi
from routes.qa.rte_qa import rteQa
from routes.qa.rte_claims import rteClaims
from routes.qa.rte_providers import rteProv


#--- fastAPI self doc descriptors
description = """

    Fourthbrain Capstone:  MLE10 Cohort

    

    The Healthcare Claims Anomaly API is provided to assist with



    ## Claims Analysis

    ## Supervised Provider Predictions - Anomaly Detection (XGBoost)

    ## Unsupervised Claim Predictions - Anomaly Detection (KMeans Cluster)



    You will be able to:

    * Analyze Claims data

    * Identify potential Provider Anomalies

    * Idenitfy potential Claim Anomalies

"""

app = FastAPI(
    title="App:  Healthcare Claims - Anomaly Detection",
    description=description,
    version="0.0.1",
    terms_of_service="http://example.com/terms/",
    contact={
        "name": "Iain McKone",
        "email": "[email protected]",
    },
    license_info={
        "name": "Apache 2.0",
        "url": "https://www.apache.org/licenses/LICENSE-2.0.html",
    },
)


#--- configure route handlers
app.include_router(rteApi, prefix="/api")
app.include_router(rteQa, prefix="/qa")
app.include_router(rteClaims, prefix="/claims")
app.include_router(rteProv, prefix="/providers")



m_kstrPath_templ = libUtils.pth_templ
m_templRef = Jinja2Templates(directory=str(m_kstrPath_templ))


def get_jinja2Templ(request: Request, pdfResults, strParamTitle, lngNumRecords, blnIsTrain=False, blnIsSample=False):
    lngNumRecords = min(lngNumRecords, libUtils.m_klngMaxRecords)
    if (blnIsTrain):  strParamTitle = strParamTitle + " - Training Data"
    if (not blnIsTrain):  strParamTitle = strParamTitle + " - Test Data"
    if (blnIsSample):  lngNumRecords = libUtils.m_klngSampleSize
    strParamTitle = strParamTitle + " - max " + str(lngNumRecords) + " rows"

    pdfClaims = pdfResults.sample(lngNumRecords)
    htmlClaims = pdfClaims.to_html(classes='table table-striped')
    kstrTempl = 'templ_showDataframe.html'
    jsonContext = {'request': request, 
                'paramTitle': strParamTitle,
                'paramDataframe': htmlClaims
            }
    result = m_templRef.TemplateResponse(kstrTempl, jsonContext)
    return result


#--- get main ui/ux entry point
@app.get('/')
def index():
    return {
        "message": "Landing page:  Capstone Healthcare Anomaly Detection"
    }



if __name__ == '__main__':
    uvicorn.run("main:app", host="0.0.0.0", port=48300, reload=True)
#CMD ["uvicorn", "main:app", "--host=0.0.0.0", "--reload"]