11import asyncio
22import logging
3- import time
43from datetime import datetime
54
65import coloredlogs
7- import sqlalchemy as sa
86from aiohttp import web
9- from sqlalchemy .sql .expression import insert , select
7+ from sqlalchemy .sql .expression import select
108
9+ from aidbox_python_sdk .db import DBProxy
1110from aidbox_python_sdk .handlers import routes
1211from aidbox_python_sdk .main import create_app as _create_app
1312from aidbox_python_sdk .sdk import SDK
@@ -129,37 +128,16 @@ async def daily_patient_report(operation, request):
129128 return web .json_response ({"type" : "report" , "success" : "Ok" , "msg" : "Response from APP" })
130129
131130
131+ async def get_app_ids (db : DBProxy ):
132+ app = db .App
133+ return await db .alchemy (select (app .c .id ))
134+
135+
132136@routes .get ("/db_tests" )
133137async def db_tests (request ):
134138 db = request .app ["db" ]
135- app = db .App .__table__
136- app_res = {
137- "type" : "app" ,
138- "resources" : {
139- "User" : {},
140- },
141- }
142- unique_id = f"abc{ time .time ()} "
143- test_statements = [
144- insert (app )
145- .values (id = unique_id , txid = 123 , status = "created" , resource = app_res )
146- .returning (app .c .id ),
147- app .update ()
148- .where (app .c .id == unique_id )
149- .values (resource = app .c .resource .op ("||" )({"additional" : "property" })),
150- app .select ().where (app .c .id == unique_id ),
151- app .select ().where (app .c .status == "recreated" ),
152- select ([app .c .resource ["type" ].label ("app_type" )]),
153- app .select ().where (app .c .resource ["resources" ].has_key ("User" )),
154- select ([app .c .id ]).where (app .c .resource ["type" ].astext == "app" ),
155- select ([sa .func .count (app .c .id )]).where (app .c .resource .contains ({"type" : "app" })),
156- # TODO: got an error for this query.
157- # select('*').where(app.c.resource['resources'].has_all(array(['User', 'Client']))),
158- ]
159- for statement in test_statements :
160- result = await db .alchemy (statement )
161- logging .debug ("Result:\n %s" , result )
162- return web .json_response ({})
139+
140+ return web .json_response (await get_app_ids (db ))
163141
164142
165143@sdk .operation (
@@ -169,6 +147,7 @@ async def db_tests(request):
169147 "fhirCode" : "observation-custom-op" ,
170148 "fhirUrl" : "http://test.com" ,
171149 "fhirResource" : ["Observation" ],
172- })
150+ },
151+ )
173152async def observation_custom_op (operation , request ):
174153 return {"message" : "Observation custom operation response" }
0 commit comments