|
1 | 1 | import json |
2 | | -import logging |
| 2 | +import os |
3 | 3 | import uuid |
4 | 4 |
|
5 | 5 | import fhirpy_types_r4b as r4b |
|
9 | 9 |
|
10 | 10 | from app import app_keys as ak |
11 | 11 | from app.sdk import sdk |
12 | | - |
| 12 | +from app.version import __version__ |
| 13 | + |
| 14 | +@sdk.operation(["GET"], ["validator", "version"], public=True) |
| 15 | +async def version_op(_operation: SDKOperation, request: SDKOperationRequest) -> web.Response: |
| 16 | + app = request["app"] |
| 17 | + client = app[ak.client] |
| 18 | + aidbox_config = await client.execute("$config", method="GET") |
| 19 | + validator_version = aidbox_config.get("about", {}).get("version", "Unknown") |
| 20 | + |
| 21 | + return web.json_response( |
| 22 | + { |
| 23 | + "validatorWrapperVersion": __version__, |
| 24 | + "validatorVersion": validator_version, |
| 25 | + } |
| 26 | + ) |
13 | 27 |
|
14 | 28 | @sdk.operation(["POST"], ["validate"], public=True) |
15 | 29 | async def validate_op(_operation: SDKOperation, request: SDKOperationRequest) -> web.Response: |
16 | | - fhir_client = request["app"][ak.fhir_client] |
| 30 | + app = request["app"] |
| 31 | + fhir_client = app[ak.fhir_client] |
17 | 32 | request_data = request["resource"] |
18 | | - logging.error("Validation request: %s", request_data) |
| 33 | + is_debug = os.environ.get("REQUEST_DEBUG", "False") == "True" |
| 34 | + if is_debug: |
| 35 | + await save_request(fhir_client, request_data) |
19 | 36 | formatted_request = official_format_to_aidbox(request_data) |
20 | 37 | resource_to_validate = formatted_request["resource"] |
21 | 38 | resource_type = resource_to_validate.get("resourceType", "Patient") |
22 | 39 | file_info = formatted_request["file_info"] |
23 | 40 | session_id = formatted_request["session_id"] |
24 | 41 |
|
25 | | - logging.error("Resource to validate: %s", resource_to_validate) |
26 | | - |
27 | 42 | validation_results = await fhir_client.execute( |
28 | | - f"fhir/{resource_type}/$validate", method="POST", data=resource_to_validate |
| 43 | + f"{resource_type}/$validate", method="POST", data=resource_to_validate |
29 | 44 | ) |
30 | 45 | validation_results = aidbox_response_to_official_format( |
31 | 46 | validation_results, file_info, session_id, resource_type |
32 | 47 | ) |
33 | 48 |
|
34 | | - logging.error("Validation results: %s", validation_results) |
35 | | - |
36 | 49 | return web.json_response(validation_results) |
37 | 50 |
|
38 | 51 |
|
@@ -102,7 +115,6 @@ def aidbox_response_to_official_format( |
102 | 115 |
|
103 | 116 |
|
104 | 117 | def format_issue(aidbox_issue: dict, location: str) -> dict: |
105 | | - logging.error("Aidbox issue: %s", aidbox_issue) |
106 | 118 | code = get_aidbox_issue_code(aidbox_issue) |
107 | 119 | diagnostics = aidbox_issue.get("diagnostics", "") |
108 | 120 | expressions = aidbox_issue.get("expression", []) |
|
0 commit comments