Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e887d99
feat: clarify FhirData setter behavior with explicit replace parameter
skalwaghe-56 Oct 7, 2025
82a14c1
Merge branch 'main' into fix-issue-123
skalwaghe-56 Oct 18, 2025
023181e
Merge branch 'main' into fix-issue-123
skalwaghe-56 Oct 28, 2025
d56ef8c
Merge branch 'main' into fix-issue-123
skalwaghe-56 Oct 31, 2025
7d79a15
Merge branch 'main' into fix-issue-123
adamkells Nov 28, 2025
db1a5f4
transition from poetry to uv
adamkells Nov 28, 2025
ef4d3a7
testing uv publish to test-pypi
adamkells Nov 28, 2025
62dcf25
Allow publishing with uv
adamkells Nov 28, 2025
1e2cef0
update docs for uv
adamkells Nov 28, 2025
c1e0fb0
Bump python version to 3.12
adamkells Nov 28, 2025
134b0f5
replacing spyne with fastapi WIP
adamkells Nov 28, 2025
e220187
remove spyne dependency fully
adamkells Dec 1, 2025
2d21c09
Merge branch 'main' into fix-issue-123
jenniferjiangkells Dec 2, 2025
717aa43
remove 3.9 testing
adamkells Dec 8, 2025
616f8a8
update dependencies
adamkells Dec 8, 2025
a6247c0
Potential fix for code scanning alert no. 15: XML external entity exp…
adamkells Dec 8, 2025
e027b12
Potential fix for code scanning alert no. 14: Information exposure th…
adamkells Dec 8, 2025
1e90ab7
Merge branch 'main' into improv/add_python312
adamkells Dec 8, 2025
1e51f9c
merge uv branch
adamkells Dec 8, 2025
228889a
update wsdl
adamkells Dec 9, 2025
7e2132d
Merge branch 'main' into improv/add_python312
adamkells Dec 10, 2025
812f877
Modify failing tests
adamkells Dec 10, 2025
d6bad3c
notereader/fhir -> notereader/?wsdl
jenniferjiangkells Dec 15, 2025
8f75f7b
Added timezone fix for naive datetimes
jenniferjiangkells Dec 15, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
if: github.event.pull_request.draft == false
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
steps:
- name: Check out the repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
- name: Bump version
run: |
VERSION=$(git describe --tags --abbrev=0)
Expand Down
2 changes: 1 addition & 1 deletion cookbook/notereader_clinical_coding_fhir.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run_server():

# Create sandbox client for testing
client = SandboxClient(
url="http://localhost:8000/notereader/fhir/",
url="http://localhost:8000/notereader/?wsdl",
workflow="sign-note-inpatient",
protocol="soap",
)
Expand Down
41 changes: 40 additions & 1 deletion healthchain/fhir/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import importlib
import re

from typing import Optional, Dict, Any, List
from fhir.resources.resource import Resource
Expand All @@ -14,6 +15,42 @@
logger = logging.getLogger(__name__)


def _fix_timezone_naive_datetimes(data: Any) -> Any:
"""
Recursively fix timezone-naive datetime strings by appending UTC timezone.

Pydantic v2 requires timezone-aware datetimes. This function walks through
nested dicts/lists and adds 'Z' (UTC) to datetime strings that match the
pattern YYYY-MM-DDTHH:MM:SS but lack timezone info.

Args:
data: Dict, list, or primitive value to process

Returns:
Processed data with timezone-aware datetime strings

Example:
>>> data = {"start": "2021-04-19T00:00:00", "name": "Test"}
>>> _fix_timezone_naive_datetimes(data)
{"start": "2021-04-19T00:00:00Z", "name": "Test"}
"""
# Pattern: YYYY-MM-DDTHH:MM:SS optionally followed by microseconds
# Must NOT already have timezone (Z or +/-HH:MM)
datetime_pattern = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$")

if isinstance(data, dict):
return {
key: _fix_timezone_naive_datetimes(value) for key, value in data.items()
}
elif isinstance(data, list):
return [_fix_timezone_naive_datetimes(item) for item in data]
elif isinstance(data, str) and datetime_pattern.match(data):
# Add UTC timezone
return f"{data}Z"
else:
return data


def create_resource_from_dict(
resource_dict: Dict, resource_type: str
) -> Optional[Resource]:
Expand Down Expand Up @@ -99,8 +136,10 @@ def convert_prefetch_to_fhir_objects(
resource_type = resource_data.get("resourceType")
if resource_type:
try:
# Fix timezone-naive datetimes before validation
fixed_data = _fix_timezone_naive_datetimes(resource_data)
resource_class = get_fhir_model_class(resource_type)
result[key] = resource_class(**resource_data)
result[key] = resource_class(**fixed_data)
except Exception as e:
logger.warning(
f"Failed to convert {resource_type} to FHIR object: {e}"
Expand Down
40 changes: 26 additions & 14 deletions healthchain/gateway/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from datetime import datetime
from fastapi import FastAPI, APIRouter, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.wsgi import WSGIMiddleware
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from termcolor import colored
Expand Down Expand Up @@ -233,10 +232,10 @@ def _add_component_routes(
# Case 2: WSGI services (like NoteReaderService) - only for services
if (
component_type == "service"
and hasattr(component, "create_wsgi_app")
and callable(component.create_wsgi_app)
and hasattr(component, "create_fastapi_router")
and callable(component.create_fastapi_router)
):
self._register_wsgi_service(
self._register_mounted_service(
component, component_name, endpoints_registry, path
)
return
Expand All @@ -249,7 +248,7 @@ def _add_component_routes(
else:
logger.warning(
f"Service {component_name} does not implement APIRouter or WSGI patterns. "
f"Services must either inherit from APIRouter or implement create_wsgi_app()."
f"Services must either inherit from APIRouter or implement create_fastapi_router()."
)

def _register_api_router(
Expand Down Expand Up @@ -277,29 +276,42 @@ def _register_api_router(
else:
logger.debug(f"Registered {component_name} as router (routes unknown)")

def _register_wsgi_service(
def _register_mounted_service( # Renamed from _register_wsgi_service
self,
service: BaseProtocolHandler,
service_name: str,
endpoints_registry: Dict[str, set],
path: Optional[str] = None,
) -> None:
"""Register a WSGI service."""
# Create WSGI app
wsgi_app = service.create_wsgi_app()
"""Register a service with a custom router."""
router_or_app = service.create_fastapi_router()

# Determine mount path with fallback chain
mount_path = (
path
or getattr(service.config, "default_mount_path", None)
or getattr(service.config, "base_path", None)
or f"/{service_name.lower().replace('service', '').replace('gateway', '')}"
)

# Mount the WSGI app
self.mount(mount_path, WSGIMiddleware(wsgi_app))
endpoints_registry[service_name].add(f"WSGI:{mount_path}")
logger.debug(f"Registered WSGI service {service_name} at {mount_path}")
logger.info(f"🔧 Registering {service_name} at: {mount_path}")
logger.info(f" Router type: {type(router_or_app)}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make these logs debug instead of info


# Use include_router for APIRouter instances
if isinstance(router_or_app, APIRouter):
if hasattr(router_or_app, "routes"):
logger.info(f" Routes in router: {len(router_or_app.routes)}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

for route in router_or_app.routes:
if hasattr(route, "methods") and hasattr(route, "path"):
logger.info(f" - {route.methods} {route.path}")

self.include_router(router_or_app, prefix=mount_path)
endpoints_registry[service_name].add(f"INCLUDED:{mount_path}")
logger.info(f"✅ Included router {service_name} at {mount_path}")
else:
# For FastAPI apps, use mount
self.mount(mount_path, router_or_app)
endpoints_registry[service_name].add(f"MOUNTED:{mount_path}")
logger.info(f"✅ Mounted app {service_name} at {mount_path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logs


def register_gateway(
self,
Expand Down
5 changes: 2 additions & 3 deletions healthchain/gateway/soap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from .notereader import NoteReaderService
from .utils.epiccds import CDSServices
from .notereader import NoteReaderService, NoteReaderConfig
from .utils.model import ClientFault, ServerFault

__all__ = [
"NoteReaderService",
"CDSServices",
"NoteReaderConfig",
"ClientFault",
"ServerFault",
]
Loading