
    E|j                        d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z%  e jL                  e'      Z( e       Z) e jT                  e jV                  d        e jL                  e'      Z(edefd       Z, edde,      Z-e#e-j\                  _#        e-j_                  ee       e-ja                  ee!jb                  ddgdg       e-je                  d      defd       Z3e-ji                  e5      dede5fd       Z6e-jo                  ejp                  d d!g"       e-jo                  ejp                  d#d$g"       e-jo                  ejp                  d%d&g"       e-jo                  ejp                  d'd(g"       e-jo                  ejp                  d)d*g"       e-jo                  ejp                  d+d,g"       e-jo                  ejp                  d-d.g"       e-js                  d/ e	d01      d23       e-ju                  d4d5g6      d7        Z;y)8    N)FastAPIRequest)CORSMiddleware)JSONResponse)StaticFiles)asynccontextmanager)AsyncIOScheduler)_rate_limit_exceeded_handler)RateLimitExceeded)authstaffdepartmentssessionsrolesuploadspatients)error_codes)engine)Base)settings)limiter)purge_expiredz/%(asctime)s %(levelname)s %(name)s: %(message)s)levelformatappc                  K   t        j                         4 d {   }|j                  t        j                  j
                         d {    d d d       d {    t        j                  t        ddd       t        j                          t        j                  d       d  t        j                  d       t        j                  d       y 7 7 7 # 1 d {  7  sw Y   xY ww)	Ninterval   r   )hoursidu-   CT Surgery API starting — scheduler runningF)waitzCT Surgery API shutting down)r   beginrun_syncr   metadata
create_all
_scheduleradd_jobr   startloggerinfoshutdown)r   conns     -/var/www/html/ai-nims-dev/backend/app/main.pylifespanr.      s     ||~ 6 6mmDMM445556 6 }joN
KK?@	U#
KK./656 6 6 6sW   C3CC3-CCCC3CA<C3CC3C0$C'%C0,C3zCT Surgery APIz1.0.0)titleversionr.   T*)allow_originsallow_credentialsallow_methodsallow_headershttprequestc                   K   t         j                  d| j                  | j                  j                          ||        d {   }t         j                  d| j                  | j                  j                  |j
                         |S 7 Fw)Nz--> [%s] %sz<-- [%s] %s %s)r)   r*   methodurlpathstatus_code)r7   	call_nextresponses      r-   log_requestsr?   B   sb     
KKw~~w{{/?/?@w''H
KK '..'++2B2BHDXDXYO (s   ABB
ABexcc                    K   t         j                  d| j                  | j                  j                         t        ddt        j                  t        |      di      S w)NzUnhandled error on [%s] %si  detail)errormessage)r<   content)	r)   	exceptionr9   r:   r;   r   r   INTERNAL_ERRORstr)r7   r@   s     r-   global_error_handlerrI   L   sO     
17>>7;;CSCST[%?%?CPSHUV s   AA!z/authAuth)prefixtagsz/staffStaffz/departmentsDepartmentsz	/patientsPatientsz	/sessionsSessionsz/rolesRolesz/uploadsUploadsz/mediar   )	directorymedia)namez/healthHealth)rL   c                     K   ddiS w)Nstatusok rZ       r-   healthr\   c   s     ds   )<loggingfastapir   r   fastapi.middleware.corsr   fastapi.responsesr   fastapi.staticfilesr   
contextlibr   apscheduler.schedulers.asyncior	   slowapir
   slowapi.errorsr   app.apir   r   r   r   r   r   r   app.constantsr   app.db.enginer   
app.modelsr   app.core.configr   app.core.limiterr   app.services.data_wiper   	getLogger__name__r)   r&   basicConfigINFOr.   r   stateadd_exception_handleradd_middlewareALLOWED_ORIGINS
middlewarer?   exception_handler	ExceptionrI   include_routerroutermountgetr\   rZ   r[   r-   <module>r|      sM    $ 2 * + * ; 0 , P P P %    $ $ 0			8	$
   
,,< 
		8	$ 0 0 0 
 		    +-I J
   **%%      y! i  "   4;;wfX  >   5<<y  A   ;%%nM?  S   8??;j\  J   8??;j\  J   5<<y  A   7>>*I;  G 		(K)47	 C
 ($ %r[   