Skip to content

Commit 8bc7bb4

Browse files
Remove null values from CDS Hook API responses
* fixed: Remove null values from CDS Hook API responses #142 * fix: remove null values cds hook api response * Update .gitignore --------- Co-authored-by: Adam Kells <[email protected]>
1 parent 2f114b2 commit 8bc7bb4

File tree

11 files changed

+37
-17
lines changed

11 files changed

+37
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,4 @@ scrap/
167167
.python-version
168168
.cursor/
169169
scripts/
170+
.idea/

healthchain/gateway/events/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def publish(self, event: EHREvent, middleware_id: Optional[int] = None):
121121
"""
122122
# Convert event to the format expected by fastapi-events
123123
event_name = event.event_type.value
124-
event_data = event.model_dump()
124+
event_data = event.model_dump(exclude_none=True)
125125

126126
# Use the provided middleware_id or fall back to the class's middleware_id
127127
mid = middleware_id or self.middleware_id

healthchain/gateway/fhir/aio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ async def modify(
414414
updated_resource = await client.update(resource)
415415

416416
resource.id = updated_resource.id
417-
for field_name, field_value in updated_resource.model_dump().items():
417+
for field_name, field_value in updated_resource.model_dump(
418+
exclude_none=True
419+
).items():
418420
if hasattr(resource, field_name):
419421
setattr(resource, field_name, field_value)
420422

healthchain/gateway/fhir/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def capability_statement(
103103
Includes both custom transform/aggregate operations (via REST endpoints)
104104
and standard FHIR CRUD operations (via Python gateway methods).
105105
"""
106-
return fhir.build_capability_statement().model_dump()
106+
return fhir.build_capability_statement().model_dump(exclude_none=True)
107107

108108
# Gateway status endpoint - returns operational metadata
109109
@self.get("/status", response_class=JSONResponse)

healthchain/interop/generators/cda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _render_entry(
133133
context = {
134134
"timestamp": timestamp,
135135
"text_reference_name": reference_name,
136-
"resource": resource.model_dump(),
136+
"resource": resource.model_dump(exclude_none=True),
137137
"config": section_config,
138138
}
139139

healthchain/io/containers/document.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,9 @@ def update_problem_list_from_nlp(
700700
system=coding_system,
701701
)
702702
set_problem_list_item_category(condition)
703-
logger.debug(f"Adding condition from spaCy: {condition.model_dump()}")
703+
logger.debug(
704+
f"Adding condition from spaCy: {condition.model_dump(exclude_none=True)}"
705+
)
704706
new_conditions.append(condition)
705707

706708
# 2. Extract from generic NLP entities (framework-agnostic)
@@ -725,7 +727,7 @@ def update_problem_list_from_nlp(
725727
)
726728
set_problem_list_item_category(condition)
727729
logger.debug(
728-
f"Adding condition from entities: {condition.model_dump()}"
730+
f"Adding condition from entities: {condition.model_dump(exclude_none=True)}"
729731
)
730732
new_conditions.append(condition)
731733

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include = [
2222
"healthchain/configs/**/*.liquid"
2323
]
2424

25-
[project.urls]
25+
[tool.poetry.urls]
2626
"Homepage" = "https://dotimplement.github.io/HealthChain/"
2727
"Repository" = "https://github.com/dotimplement/HealthChain"
2828

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def empty_bundle():
6666
return create_bundle()
6767

6868

69-
7069
@pytest.fixture
7170
def test_condition():
7271
"""Provides a minimal, generic FHIR Condition resource.
@@ -261,9 +260,12 @@ def doc_ref_without_content():
261260
fhir.resources.documentreference.DocumentReference: An incomplete DocumentReference resource.
262261
"""
263262
from fhir.resources.attachment import Attachment
263+
264264
return DocumentReference(
265265
status="current",
266-
content=[DocumentReferenceContent(attachment=Attachment(contentType="text/plain"))], # Missing required data or url
266+
content=[
267+
DocumentReferenceContent(attachment=Attachment(contentType="text/plain"))
268+
], # Missing required data or url
267269
)
268270

269271

tests/gateway/test_base_fhir_gateway.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def test_empty_capability_statement_with_no_handlers(fhir_gateway):
119119
"""Gateway with no handlers generates minimal CapabilityStatement."""
120120
capability = fhir_gateway.build_capability_statement()
121121

122-
assert capability.model_dump()["resourceType"] == "CapabilityStatement"
122+
assert (
123+
capability.model_dump(exclude_none=True)["resourceType"]
124+
== "CapabilityStatement"
125+
)
123126
assert capability.status == "active"
124127
assert capability.kind == "instance"
125128

tests/gateway/test_event_dispatcher.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def test_event_publishing_with_default_middleware_id(
143143

144144
mock_dispatch.assert_called_once_with(
145145
"fhir.read",
146-
sample_ehr_event.model_dump(),
146+
sample_ehr_event.model_dump(exclude_none=True),
147147
middleware_id=event_dispatcher.middleware_id,
148148
)
149149

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

162162
mock_dispatch.assert_called_once_with(
163-
"fhir.read", sample_ehr_event.model_dump(), middleware_id=custom_middleware_id
163+
"fhir.read",
164+
sample_ehr_event.model_dump(exclude_none=True),
165+
middleware_id=custom_middleware_id,
164166
)
165167

166168

@@ -182,7 +184,7 @@ async def mock_coroutine():
182184
# Verify dispatch was called with correct parameters
183185
mock_dispatch.assert_called_once_with(
184186
"fhir.read",
185-
sample_ehr_event.model_dump(),
187+
sample_ehr_event.model_dump(exclude_none=True),
186188
middleware_id=event_dispatcher.middleware_id,
187189
)
188190

0 commit comments

Comments
 (0)