Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,5 @@ scrap/
.python-version
.cursor/
scripts/
.idea/
.idea/
2 changes: 1 addition & 1 deletion healthchain/gateway/events/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def publish(self, event: EHREvent, middleware_id: Optional[int] = None):
"""
# Convert event to the format expected by fastapi-events
event_name = event.event_type.value
event_data = event.model_dump()
event_data = event.model_dump(exclude_none=True)

# Use the provided middleware_id or fall back to the class's middleware_id
mid = middleware_id or self.middleware_id
Expand Down
4 changes: 3 additions & 1 deletion healthchain/gateway/fhir/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ async def modify(
updated_resource = await client.update(resource)

resource.id = updated_resource.id
for field_name, field_value in updated_resource.model_dump().items():
for field_name, field_value in updated_resource.model_dump(
exclude_none=True
).items():
if hasattr(resource, field_name):
setattr(resource, field_name, field_value)

Expand Down
2 changes: 1 addition & 1 deletion healthchain/gateway/fhir/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def capability_statement(
Includes both custom transform/aggregate operations (via REST endpoints)
and standard FHIR CRUD operations (via Python gateway methods).
"""
return fhir.build_capability_statement().model_dump()
return fhir.build_capability_statement().model_dump(exclude_none=True)

# Gateway status endpoint - returns operational metadata
@self.get("/status", response_class=JSONResponse)
Expand Down
2 changes: 1 addition & 1 deletion healthchain/interop/generators/cda.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _render_entry(
context = {
"timestamp": timestamp,
"text_reference_name": reference_name,
"resource": resource.model_dump(),
"resource": resource.model_dump(exclude_none=True),
"config": section_config,
}

Expand Down
6 changes: 4 additions & 2 deletions healthchain/io/containers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,9 @@ def update_problem_list_from_nlp(
system=coding_system,
)
set_problem_list_item_category(condition)
logger.debug(f"Adding condition from spaCy: {condition.model_dump()}")
logger.debug(
f"Adding condition from spaCy: {condition.model_dump(exclude_none=True)}"
)
new_conditions.append(condition)

# 2. Extract from generic NLP entities (framework-agnostic)
Expand All @@ -725,7 +727,7 @@ def update_problem_list_from_nlp(
)
set_problem_list_item_category(condition)
logger.debug(
f"Adding condition from entities: {condition.model_dump()}"
f"Adding condition from entities: {condition.model_dump(exclude_none=True)}"
)
new_conditions.append(condition)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include = [
"healthchain/configs/**/*.liquid"
]

[project.urls]
[tool.poetry.urls]
"Homepage" = "https://dotimplement.github.io/HealthChain/"
"Repository" = "https://github.com/dotimplement/HealthChain"

Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def empty_bundle():
return create_bundle()



@pytest.fixture
def test_condition():
"""Provides a minimal, generic FHIR Condition resource.
Expand Down Expand Up @@ -261,9 +260,12 @@ def doc_ref_without_content():
fhir.resources.documentreference.DocumentReference: An incomplete DocumentReference resource.
"""
from fhir.resources.attachment import Attachment

return DocumentReference(
status="current",
content=[DocumentReferenceContent(attachment=Attachment(contentType="text/plain"))], # Missing required data or url
content=[
DocumentReferenceContent(attachment=Attachment(contentType="text/plain"))
], # Missing required data or url
)


Expand Down
5 changes: 4 additions & 1 deletion tests/gateway/test_base_fhir_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def test_empty_capability_statement_with_no_handlers(fhir_gateway):
"""Gateway with no handlers generates minimal CapabilityStatement."""
capability = fhir_gateway.build_capability_statement()

assert capability.model_dump()["resourceType"] == "CapabilityStatement"
assert (
capability.model_dump(exclude_none=True)["resourceType"]
== "CapabilityStatement"
)
assert capability.status == "active"
assert capability.kind == "instance"

Expand Down
8 changes: 5 additions & 3 deletions tests/gateway/test_event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def test_event_publishing_with_default_middleware_id(

mock_dispatch.assert_called_once_with(
"fhir.read",
sample_ehr_event.model_dump(),
sample_ehr_event.model_dump(exclude_none=True),
middleware_id=event_dispatcher.middleware_id,
)

Expand All @@ -160,7 +160,9 @@ async def test_event_publishing_with_custom_middleware_id(
await event_dispatcher.publish(sample_ehr_event, middleware_id=custom_middleware_id)

mock_dispatch.assert_called_once_with(
"fhir.read", sample_ehr_event.model_dump(), middleware_id=custom_middleware_id
"fhir.read",
sample_ehr_event.model_dump(exclude_none=True),
middleware_id=custom_middleware_id,
)


Expand All @@ -182,7 +184,7 @@ async def mock_coroutine():
# Verify dispatch was called with correct parameters
mock_dispatch.assert_called_once_with(
"fhir.read",
sample_ehr_event.model_dump(),
sample_ehr_event.model_dump(exclude_none=True),
middleware_id=event_dispatcher.middleware_id,
)

Expand Down
16 changes: 12 additions & 4 deletions tests/pipeline/test_cdsfhiradapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def test_parse_with_document_reference(
cds_fhir_adapter, test_cds_request, doc_ref_with_content
):
# Add DocumentReference to prefetch data
test_cds_request.prefetch["document"] = doc_ref_with_content.model_dump()
test_cds_request.prefetch["document"] = doc_ref_with_content.model_dump(
exclude_none=True
)

# Call the input method
result = cds_fhir_adapter.parse(test_cds_request)
Expand All @@ -44,7 +46,9 @@ def test_parse_with_multiple_attachments(
cds_fhir_adapter, test_cds_request, doc_ref_with_multiple_content
):
# Add DocumentReference to prefetch data
test_cds_request.prefetch["document"] = doc_ref_with_multiple_content.model_dump()
test_cds_request.prefetch["document"] = doc_ref_with_multiple_content.model_dump(
exclude_none=True
)

# Call the input method
result = cds_fhir_adapter.parse(test_cds_request)
Expand Down Expand Up @@ -73,7 +77,9 @@ def test_parse_with_custom_document_key(
cds_fhir_adapter, test_cds_request, doc_ref_with_content
):
# Add DocumentReference to prefetch data with custom key
test_cds_request.prefetch["custom_key"] = doc_ref_with_content.model_dump()
test_cds_request.prefetch["custom_key"] = doc_ref_with_content.model_dump(
exclude_none=True
)

# Call the input method with custom key
result = cds_fhir_adapter.parse(
Expand All @@ -90,7 +96,9 @@ def test_parse_with_document_reference_error(
cds_fhir_adapter, test_cds_request, doc_ref_without_content, caplog
):
# Add invalid DocumentReference to prefetch data
test_cds_request.prefetch["document"] = doc_ref_without_content.model_dump()
test_cds_request.prefetch["document"] = doc_ref_without_content.model_dump(
exclude_none=True
)

# Call the input method
result = cds_fhir_adapter.parse(test_cds_request)
Expand Down