Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 0.2.1
## 0.2.2

- Revert BaseFHIRError exceptions from fhir-py in operation handlers b


## 0.2.1 (yanked)

- Handle BaseFHIRError exceptions from fhir-py in operation handlers

Expand Down
2 changes: 1 addition & 1 deletion aidbox_python_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "aidbox-python-sdk"
__version__ = "0.2.1"
__version__ = "0.2.2"
__author__ = "beda.software"
__license__ = "None"
__copyright__ = "Copyright 2024 beda.software"
Expand Down
9 changes: 1 addition & 8 deletions aidbox_python_sdk/handlers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import asyncio
import json
import logging
from typing import Any

from aiohttp import web
from fhirpy.base.exceptions import BaseFHIRError, OperationOutcome
from fhirpy.base.exceptions import OperationOutcome

from . import app_keys as ak

Expand Down Expand Up @@ -49,12 +48,6 @@ async def operation(request: web.Request, data: dict[str, Any]):
return result
except OperationOutcome as exc:
return web.json_response(exc.resource, status=422)
except BaseFHIRError as exc:
try:
payload = json.loads(str(exc))
return web.json_response(payload, status=422)
except (json.JSONDecodeError, TypeError):
return web.Response(text=str(exc), status=422, content_type="text/plain")


TYPES = {
Expand Down
34 changes: 1 addition & 33 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import asyncio
import json
import logging
from datetime import datetime

import coloredlogs
from aiohttp import web
from fhirpy.base.exceptions import BaseFHIRError, OperationOutcome
from fhirpy.base.exceptions import OperationOutcome
from sqlalchemy.sql.expression import select

from aidbox_python_sdk.db import DBProxy
Expand Down Expand Up @@ -161,34 +160,3 @@ async def observation_custom_op(operation, request):
)
async def operation_outcome_test_op(operation, request):
raise OperationOutcome(reason="test reason")


@sdk.operation(
["POST"],
["$base-fhir-error-json-test"],
)
async def base_fhir_error_json_test_op(operation, request):
raise BaseFHIRError(
json.dumps(
{
"resourceType": "OperationOutcome",
"id": "not-found",
"text": {"status": "generated", "div": "Resource Patient/id not found"},
"issue": [
{
"severity": "fatal",
"code": "not-found",
"diagnostics": "Resource Patient/id not found",
}
],
}
)
)


@sdk.operation(
["POST"],
["$base-fhir-error-text-test"],
)
async def base_fhir_error_text_test_op(operation, request):
raise BaseFHIRError("plain")
12 changes: 0 additions & 12 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,6 @@ async def test_aidbox_db_fixture(client, aidbox_db: DBProxy, safe_db):
assert app_ids == [{"id": "app-test"}]


async def test_operation_base_fhir_error_json_test_op(aidbox_client):
with pytest.raises(OperationOutcome) as exc:
await aidbox_client.execute("/$base-fhir-error-json-test")
assert exc.value.resource.get("issue")[0].get("diagnostics") == "Resource Patient/id not found"


async def test_operation_base_fhir_error_text_test_op(aidbox_client):
with pytest.raises(OperationOutcome) as exc:
await aidbox_client.execute("/$base-fhir-error-text-test")
assert exc.value.resource.get("issue")[0].get("diagnostics") == "plain"


async def test_operation_outcome_test_op(aidbox_client):
with pytest.raises(OperationOutcome) as exc:
await aidbox_client.execute("/$operation-outcome-test")
Expand Down
Loading