11import asyncio
2+ import json
23import logging
34from datetime import datetime
45
56import coloredlogs
67from aiohttp import web
8+ from fhirpy .base .exceptions import BaseFHIRError , OperationOutcome
79from sqlalchemy .sql .expression import select
810
911from aidbox_python_sdk .db import DBProxy
@@ -119,7 +121,7 @@ async def daily_patient_report(operation, request):
119121 GET /Patient/$weekly-report
120122 GET /Patient/$daily-report
121123 """
122- patients = request . app ["client" ].resources ("Patient" )
124+ patients = request [ " app" ] ["client" ].resources ("Patient" )
123125 async for p in patients :
124126 logging .debug (p .serialize ())
125127 logging .debug ("`daily_patient_report` operation handler" )
@@ -133,7 +135,7 @@ async def get_app_ids(db: DBProxy):
133135 return await db .alchemy (select (app .c .id ))
134136
135137
136- @routes .get ("/db_tests " )
138+ @routes .get ("/db-tests " )
137139async def db_tests (request ):
138140 db = request .app ["db" ]
139141
@@ -151,3 +153,42 @@ async def db_tests(request):
151153)
152154async def observation_custom_op (operation , request ):
153155 return {"message" : "Observation custom operation response" }
156+
157+
158+ @sdk .operation (
159+ ["POST" ],
160+ ["$operation-outcome-test" ],
161+ )
162+ async def operation_outcome_test_op (operation , request ):
163+ raise OperationOutcome (reason = "test reason" )
164+
165+
166+ @sdk .operation (
167+ ["POST" ],
168+ ["$base-fhir-error-json-test" ],
169+ )
170+ async def base_fhir_error_json_test_op (operation , request ):
171+ raise BaseFHIRError (
172+ json .dumps (
173+ {
174+ "resourceType" : "OperationOutcome" ,
175+ "id" : "not-found" ,
176+ "text" : {"status" : "generated" , "div" : "Resource Patient/id not found" },
177+ "issue" : [
178+ {
179+ "severity" : "fatal" ,
180+ "code" : "not-found" ,
181+ "diagnostics" : "Resource Patient/id not found" ,
182+ }
183+ ],
184+ }
185+ )
186+ )
187+
188+
189+ @sdk .operation (
190+ ["POST" ],
191+ ["$base-fhir-error-text-test" ],
192+ )
193+ async def base_fhir_error_text_test_op (operation , request ):
194+ raise BaseFHIRError ("plain" )
0 commit comments