diff --git a/.gitignore b/.gitignore index ae3778db..868815e6 100644 --- a/.gitignore +++ b/.gitignore @@ -167,3 +167,4 @@ scrap/ .python-version .cursor/ scripts/ +.idea/ diff --git a/healthchain/gateway/events/dispatcher.py b/healthchain/gateway/events/dispatcher.py index 5d2ef09f..0a881383 100644 --- a/healthchain/gateway/events/dispatcher.py +++ b/healthchain/gateway/events/dispatcher.py @@ -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 diff --git a/healthchain/gateway/fhir/aio.py b/healthchain/gateway/fhir/aio.py index ef150688..8cebf24e 100644 --- a/healthchain/gateway/fhir/aio.py +++ b/healthchain/gateway/fhir/aio.py @@ -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) diff --git a/healthchain/gateway/fhir/base.py b/healthchain/gateway/fhir/base.py index ff397e63..dcb0f3eb 100644 --- a/healthchain/gateway/fhir/base.py +++ b/healthchain/gateway/fhir/base.py @@ -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) diff --git a/healthchain/interop/generators/cda.py b/healthchain/interop/generators/cda.py index 967f44ca..7551ed1a 100644 --- a/healthchain/interop/generators/cda.py +++ b/healthchain/interop/generators/cda.py @@ -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, } diff --git a/healthchain/io/containers/document.py b/healthchain/io/containers/document.py index 9bbf2690..1c8ee780 100644 --- a/healthchain/io/containers/document.py +++ b/healthchain/io/containers/document.py @@ -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) @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 6f417439..a84c619d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/conftest.py b/tests/conftest.py index c3fa7142..be60e5a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,7 +66,6 @@ def empty_bundle(): return create_bundle() - @pytest.fixture def test_condition(): """Provides a minimal, generic FHIR Condition resource. @@ -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 ) diff --git a/tests/gateway/test_base_fhir_gateway.py b/tests/gateway/test_base_fhir_gateway.py index 39f385c2..c354c682 100644 --- a/tests/gateway/test_base_fhir_gateway.py +++ b/tests/gateway/test_base_fhir_gateway.py @@ -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" diff --git a/tests/gateway/test_event_dispatcher.py b/tests/gateway/test_event_dispatcher.py index 60b5a29c..147da09b 100644 --- a/tests/gateway/test_event_dispatcher.py +++ b/tests/gateway/test_event_dispatcher.py @@ -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, ) @@ -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, ) @@ -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, ) diff --git a/tests/pipeline/test_cdsfhiradapter.py b/tests/pipeline/test_cdsfhiradapter.py index 981ec0c3..a8691aaf 100644 --- a/tests/pipeline/test_cdsfhiradapter.py +++ b/tests/pipeline/test_cdsfhiradapter.py @@ -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) @@ -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) @@ -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( @@ -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)