From 38c5040c2b8d3ef32bbb39062ac5057ab13bfee4 Mon Sep 17 00:00:00 2001 From: Jeremy Stein Date: Thu, 4 Jan 2024 12:24:30 +0000 Subject: [PATCH] Enable deferred annotations everywhere and fix annotations and comments (#206) * Defer annotations in all files and fix some pre-existing comment quirks * Applied ruff fixes with and without `--unsafe-fixes` flag * Some manual fixes --- cli/src/pixl_cli/__init__.py | 1 + cli/src/pixl_cli/_io.py | 3 ++- cli/src/pixl_cli/_logging.py | 2 ++ cli/src/pixl_cli/_utils.py | 2 ++ cli/src/pixl_cli/main.py | 1 + cli/tests/conftest.py | 3 ++- cli/tests/test_copy_omop.py | 2 ++ cli/tests/test_messages_from_parquet.py | 6 +++++- cli/tests/test_queue_start_and_stop_parquet.py | 1 + hasher/src/hasher/__init__.py | 1 + hasher/src/hasher/endpoints.py | 1 + hasher/src/hasher/hashing.py | 1 + hasher/src/hasher/main.py | 1 + hasher/src/hasher/settings.py | 1 + hasher/tests/conftest.py | 1 + hasher/tests/test_endpoints.py | 2 ++ hasher/tests/test_hashing.py | 2 ++ orthanc/orthanc-anon/plugin/pixl.py | 15 +++++++-------- orthanc/orthanc-raw/plugin/pixl.py | 18 +++++++++--------- pixl_core/src/core/__init__.py | 1 + pixl_core/src/core/models.py | 2 ++ pixl_core/src/core/omop.py | 8 ++++++-- pixl_core/src/core/patient_queue/__init__.py | 1 + pixl_core/src/core/patient_queue/_base.py | 2 ++ pixl_core/src/core/patient_queue/message.py | 8 +++++--- pixl_core/src/core/patient_queue/producer.py | 7 +++++-- pixl_core/src/core/patient_queue/subscriber.py | 14 ++++++++++---- pixl_core/src/core/router.py | 1 + pixl_core/src/core/token_buffer/__init__.py | 2 +- pixl_core/src/core/token_buffer/tokens.py | 3 ++- pixl_core/tests/conftest.py | 2 ++ pixl_core/tests/patient_queue/test_message.py | 2 ++ pixl_core/tests/patient_queue/test_producer.py | 2 ++ .../tests/patient_queue/test_subscriber.py | 8 ++++++-- pixl_core/tests/token_buffer/test_tokens.py | 1 + pixl_dcmd/src/pixl_dcmd/__init__.py | 2 ++ pixl_dcmd/src/pixl_dcmd/_version.py | 1 + pixl_dcmd/src/pixl_dcmd/main.py | 2 ++ .../src/pixl_dcmd/tests/test_pixl_dcmd.py | 1 + pixl_dcmd/src/setup.py | 1 + pixl_ehr/src/pixl_ehr/_databases.py | 7 ++++--- pixl_ehr/src/pixl_ehr/_processing.py | 16 ++++++++++------ pixl_ehr/src/pixl_ehr/_queries.py | 2 ++ pixl_ehr/src/pixl_ehr/main.py | 6 +++--- pixl_ehr/src/pixl_ehr/report_deid/__init__.py | 5 +++-- pixl_ehr/src/pixl_ehr/report_deid/deid.py | 5 ++--- pixl_ehr/tests/conftest.py | 1 + pixl_ehr/tests/dummy-services/cogstack.py | 2 ++ pixl_ehr/tests/test_app.py | 2 ++ pixl_ehr/tests/test_processing.py | 2 ++ pixl_pacs/src/pixl_pacs/_orthanc.py | 2 ++ pixl_pacs/src/pixl_pacs/_processing.py | 9 +++++++-- pixl_pacs/src/pixl_pacs/main.py | 6 +++--- pixl_pacs/tests/test_processing.py | 2 ++ scripts/cmove_all_studies.py | 2 ++ scripts/delete_oldest_n_studies.py | 2 ++ .../filter_cohort_for_those_present_in_raw.py | 2 ++ scripts/list_newest_n_studies.py | 2 ++ 58 files changed, 153 insertions(+), 57 deletions(-) diff --git a/cli/src/pixl_cli/__init__.py b/cli/src/pixl_cli/__init__.py index 87d4e619f..0efc2d861 100644 --- a/cli/src/pixl_cli/__init__.py +++ b/cli/src/pixl_cli/__init__.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """PIXL command line interface""" +from __future__ import annotations from pixl_cli.main import cli diff --git a/cli/src/pixl_cli/_io.py b/cli/src/pixl_cli/_io.py index 5ba25f378..2aca5d0cd 100644 --- a/cli/src/pixl_cli/_io.py +++ b/cli/src/pixl_cli/_io.py @@ -11,8 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Reading and writing files from PIXL CLI.""" +from __future__ import annotations + import json from datetime import datetime from pathlib import Path diff --git a/cli/src/pixl_cli/_logging.py b/cli/src/pixl_cli/_logging.py index ffcf9049b..4d31b7c42 100644 --- a/cli/src/pixl_cli/_logging.py +++ b/cli/src/pixl_cli/_logging.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging import coloredlogs diff --git a/cli/src/pixl_cli/_utils.py b/cli/src/pixl_cli/_utils.py index 6cbca5bc9..d8223d934 100644 --- a/cli/src/pixl_cli/_utils.py +++ b/cli/src/pixl_cli/_utils.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + from pathlib import Path diff --git a/cli/src/pixl_cli/main.py b/cli/src/pixl_cli/main.py index 5223e33b3..0129c43b5 100644 --- a/cli/src/pixl_cli/main.py +++ b/cli/src/pixl_cli/main.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """PIXL command line interface functionality""" +from __future__ import annotations import json import os diff --git a/cli/tests/conftest.py b/cli/tests/conftest.py index 9b39fff49..88339dcf1 100644 --- a/cli/tests/conftest.py +++ b/cli/tests/conftest.py @@ -11,8 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """CLI testing fixtures.""" +from __future__ import annotations + import pathlib import pytest diff --git a/cli/tests/test_copy_omop.py b/cli/tests/test_copy_omop.py index 90f84909c..ac4b95add 100644 --- a/cli/tests/test_copy_omop.py +++ b/cli/tests/test_copy_omop.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """Test copying of OMOP ES data for later export.""" +from __future__ import annotations + import datetime import pytest diff --git a/cli/tests/test_messages_from_parquet.py b/cli/tests/test_messages_from_parquet.py index b944b84e0..598b430a6 100644 --- a/cli/tests/test_messages_from_parquet.py +++ b/cli/tests/test_messages_from_parquet.py @@ -12,13 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. """Unit tests for reading cohorts from parquet files.""" +from __future__ import annotations import datetime -from pathlib import Path +from typing import TYPE_CHECKING from core.patient_queue.message import Message from pixl_cli._io import copy_parquet_return_logfile_fields, messages_from_parquet +if TYPE_CHECKING: + from pathlib import Path + def test_messages_from_parquet(resources: Path) -> None: """ diff --git a/cli/tests/test_queue_start_and_stop_parquet.py b/cli/tests/test_queue_start_and_stop_parquet.py index 4affebb57..5c8503ea9 100644 --- a/cli/tests/test_queue_start_and_stop_parquet.py +++ b/cli/tests/test_queue_start_and_stop_parquet.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Patient queue tests""" +from __future__ import annotations from pathlib import Path diff --git a/hasher/src/hasher/__init__.py b/hasher/src/hasher/__init__.py index afd649b61..76118367e 100644 --- a/hasher/src/hasher/__init__.py +++ b/hasher/src/hasher/__init__.py @@ -21,6 +21,7 @@ The Azure infrastructure (Key Vault, ServicePrincipal & permissions) must be persistent and instructions are provided for creating these with the az CLI tool. """ +from __future__ import annotations import importlib.metadata diff --git a/hasher/src/hasher/endpoints.py b/hasher/src/hasher/endpoints.py index 50f17e151..1177aa238 100644 --- a/hasher/src/hasher/endpoints.py +++ b/hasher/src/hasher/endpoints.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Sets up endpoints for the hasher-api""" +from __future__ import annotations from fastapi import APIRouter from starlette.responses import Response diff --git a/hasher/src/hasher/hashing.py b/hasher/src/hasher/hashing.py index e89c6fee7..d7dc198c4 100644 --- a/hasher/src/hasher/hashing.py +++ b/hasher/src/hasher/hashing.py @@ -20,6 +20,7 @@ - generate_salt: generate a random text string in hexadecimal to be used as a salt """ +from __future__ import annotations import logging import os diff --git a/hasher/src/hasher/main.py b/hasher/src/hasher/main.py index 2306d1650..3c8df7b74 100644 --- a/hasher/src/hasher/main.py +++ b/hasher/src/hasher/main.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Defines the FastAPI app for the hasher""" +from __future__ import annotations import logging diff --git a/hasher/src/hasher/settings.py b/hasher/src/hasher/settings.py index 435e958cc..6ee743616 100644 --- a/hasher/src/hasher/settings.py +++ b/hasher/src/hasher/settings.py @@ -22,6 +22,7 @@ - "AZURE_KEY_VAULT_NAME" - "AZURE_KEY_VAULT_SECRET_NAME" """ +from __future__ import annotations import pprint import tempfile diff --git a/hasher/tests/conftest.py b/hasher/tests/conftest.py index 33c3011d5..1835819a3 100644 --- a/hasher/tests/conftest.py +++ b/hasher/tests/conftest.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import os diff --git a/hasher/tests/test_endpoints.py b/hasher/tests/test_endpoints.py index 975f863b0..40011acaa 100644 --- a/hasher/tests/test_endpoints.py +++ b/hasher/tests/test_endpoints.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import pytest from fastapi.testclient import TestClient from hasher.main import app diff --git a/hasher/tests/test_hashing.py b/hasher/tests/test_hashing.py index 1733b9c1b..90349b3fa 100644 --- a/hasher/tests/test_hashing.py +++ b/hasher/tests/test_hashing.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import pytest from hasher.hashing import generate_hash, generate_salt from hypothesis import HealthCheck, example, given, settings diff --git a/orthanc/orthanc-anon/plugin/pixl.py b/orthanc/orthanc-anon/plugin/pixl.py index e8e654111..5a3d8eec4 100644 --- a/orthanc/orthanc-anon/plugin/pixl.py +++ b/orthanc/orthanc-anon/plugin/pixl.py @@ -1,11 +1,3 @@ -""" - -Applies anonymisation scheme to datasets - -This module: --Modifies a DICOM instance received by Orthanc and applies anonymisation --Upload the resource to a dicom-web server - # Copyright (c) 2022 University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. """ +Applies anonymisation scheme to datasets + +This module: +-Modifies a DICOM instance received by Orthanc and applies anonymisation +-Upload the resource to a dicom-web server +""" +from __future__ import annotations import json import logging diff --git a/orthanc/orthanc-raw/plugin/pixl.py b/orthanc/orthanc-raw/plugin/pixl.py index cd59e9ba8..ac72c4fb5 100644 --- a/orthanc/orthanc-raw/plugin/pixl.py +++ b/orthanc/orthanc-raw/plugin/pixl.py @@ -1,12 +1,3 @@ -""" - -Facilitates routing of stable studies from orthanc-raw to orthanc-anon - -This module provides: --OnChange: route stable studies and if auto-routing enabled --ShouldAutoRoute: checks whether auto-routing is enabled --OnHeartBeat: extends the REST API - # Copyright (c) 2022 University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. """ +Facilitates routing of stable studies from orthanc-raw to orthanc-anon + +This module provides: +-OnChange: route stable studies and if auto-routing enabled +-ShouldAutoRoute: checks whether auto-routing is enabled +-OnHeartBeat: extends the REST API +""" +from __future__ import annotations + import os import orthanc diff --git a/pixl_core/src/core/__init__.py b/pixl_core/src/core/__init__.py index 32cce4b13..cf6b3921f 100644 --- a/pixl_core/src/core/__init__.py +++ b/pixl_core/src/core/__init__.py @@ -17,3 +17,4 @@ to interact with RabbitMQ and ensure suitable rate limiting of requests to the upstream services. """ +from __future__ import annotations diff --git a/pixl_core/src/core/models.py b/pixl_core/src/core/models.py index e9eb3c026..c93d1eabd 100644 --- a/pixl_core/src/core/models.py +++ b/pixl_core/src/core/models.py @@ -15,6 +15,8 @@ PIXL core models This module defines the data models used by the PIXL core service """ +from __future__ import annotations + from dataclasses import dataclass from pydantic import BaseModel diff --git a/pixl_core/src/core/omop.py b/pixl_core/src/core/omop.py index e8230fc20..e5ee41402 100644 --- a/pixl_core/src/core/omop.py +++ b/pixl_core/src/core/omop.py @@ -11,15 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Processing of OMOP parquet files.""" -import datetime +from __future__ import annotations + import logging import pathlib import shutil +from typing import TYPE_CHECKING import slugify +if TYPE_CHECKING: + import datetime + root_from_install = pathlib.Path(__file__).parents[3] logger = logging.getLogger(__file__) diff --git a/pixl_core/src/core/patient_queue/__init__.py b/pixl_core/src/core/patient_queue/__init__.py index 16b30d1f3..de21fa6cf 100644 --- a/pixl_core/src/core/patient_queue/__init__.py +++ b/pixl_core/src/core/patient_queue/__init__.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """RabbitMQ consumer for Pixl""" +from __future__ import annotations from .subscriber import PixlConsumer diff --git a/pixl_core/src/core/patient_queue/_base.py b/pixl_core/src/core/patient_queue/_base.py index 5f8a71dd3..9b0707079 100644 --- a/pixl_core/src/core/patient_queue/_base.py +++ b/pixl_core/src/core/patient_queue/_base.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging import os from typing import Any diff --git a/pixl_core/src/core/patient_queue/message.py b/pixl_core/src/core/patient_queue/message.py index c98a5decc..150474312 100644 --- a/pixl_core/src/core/patient_queue/message.py +++ b/pixl_core/src/core/patient_queue/message.py @@ -11,16 +11,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Classes to represent messages in the patient queue.""" +from __future__ import annotations import logging from dataclasses import dataclass -from datetime import date, datetime -from typing import Any +from typing import TYPE_CHECKING, Any from jsonpickle import decode, encode +if TYPE_CHECKING: + from datetime import date, datetime + logger = logging.getLogger(__name__) diff --git a/pixl_core/src/core/patient_queue/producer.py b/pixl_core/src/core/patient_queue/producer.py index b840a4584..2137bf51e 100644 --- a/pixl_core/src/core/patient_queue/producer.py +++ b/pixl_core/src/core/patient_queue/producer.py @@ -12,14 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. """Producer for RabbitMQ""" +from __future__ import annotations import logging from time import sleep - -from core.patient_queue.message import Message +from typing import TYPE_CHECKING from ._base import PixlBlockingInterface +if TYPE_CHECKING: + from core.patient_queue.message import Message + LOGGER = logging.getLogger(__name__) diff --git a/pixl_core/src/core/patient_queue/subscriber.py b/pixl_core/src/core/patient_queue/subscriber.py index 21c41453e..18bccb121 100644 --- a/pixl_core/src/core/patient_queue/subscriber.py +++ b/pixl_core/src/core/patient_queue/subscriber.py @@ -12,20 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. """Subscriber for RabbitMQ""" +from __future__ import annotations import asyncio import logging -from collections.abc import Awaitable, Callable from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any import aio_pika from core.patient_queue.message import Message, deserialise -from core.token_buffer.tokens import TokenBucket from ._base import PixlBlockingInterface, PixlQueueInterface +if TYPE_CHECKING: + from collections.abc import Awaitable, Callable + + from typing_extensions import Self + + from core.token_buffer.tokens import TokenBucket + logger = logging.getLogger(__name__) @@ -44,7 +50,7 @@ def __init__(self, queue_name: str, token_bucket: TokenBucket) -> None: def _url(self) -> str: return f"amqp://{self._username}:{self._password}@{self._host}:{self._port}/" - async def __aenter__(self) -> "PixlConsumer": + async def __aenter__(self) -> Self: """Establishes connection to queue.""" self._connection = await aio_pika.connect_robust(self._url) self._channel = await self._connection.channel() diff --git a/pixl_core/src/core/router.py b/pixl_core/src/core/router.py index af7823c3c..8ce33948a 100644 --- a/pixl_core/src/core/router.py +++ b/pixl_core/src/core/router.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Router for the API endpoints""" +from __future__ import annotations from fastapi import APIRouter, HTTPException, status diff --git a/pixl_core/src/core/token_buffer/__init__.py b/pixl_core/src/core/token_buffer/__init__.py index 881bf6d5a..2e7b301ce 100644 --- a/pixl_core/src/core/token_buffer/__init__.py +++ b/pixl_core/src/core/token_buffer/__init__.py @@ -11,8 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Implements the TokenBucket class""" +from __future__ import annotations from .tokens import TokenBucket diff --git a/pixl_core/src/core/token_buffer/tokens.py b/pixl_core/src/core/token_buffer/tokens.py index 69af2a32c..d570d162c 100644 --- a/pixl_core/src/core/token_buffer/tokens.py +++ b/pixl_core/src/core/token_buffer/tokens.py @@ -1,5 +1,4 @@ # noqa: D100 - # Copyright (c) 2022 University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +12,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import token_bucket as tb diff --git a/pixl_core/tests/conftest.py b/pixl_core/tests/conftest.py index e35e72ce8..833c0c945 100644 --- a/pixl_core/tests/conftest.py +++ b/pixl_core/tests/conftest.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import os os.environ["ENV"] = "test" diff --git a/pixl_core/tests/patient_queue/test_message.py b/pixl_core/tests/patient_queue/test_message.py index 0c9c9e65a..bb097ad42 100644 --- a/pixl_core/tests/patient_queue/test_message.py +++ b/pixl_core/tests/patient_queue/test_message.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import datetime from core.patient_queue.message import Message, deserialise diff --git a/pixl_core/tests/patient_queue/test_producer.py b/pixl_core/tests/patient_queue/test_producer.py index 4fbf01ed0..7eb1f38d4 100644 --- a/pixl_core/tests/patient_queue/test_producer.py +++ b/pixl_core/tests/patient_queue/test_producer.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import pytest from core.patient_queue.message import Message from core.patient_queue.producer import PixlProducer diff --git a/pixl_core/tests/patient_queue/test_subscriber.py b/pixl_core/tests/patient_queue/test_subscriber.py index 13b3b0117..e606738f1 100644 --- a/pixl_core/tests/patient_queue/test_subscriber.py +++ b/pixl_core/tests/patient_queue/test_subscriber.py @@ -11,10 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import asyncio -from collections.abc import Coroutine, Generator from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any from unittest import TestCase import pytest @@ -23,6 +24,9 @@ from core.patient_queue.subscriber import PixlBlockingConsumer, PixlConsumer from core.token_buffer.tokens import TokenBucket +if TYPE_CHECKING: + from collections.abc import Coroutine, Generator + TEST_QUEUE = "test_consume" TEST_MESSAGE = Message( mrn="111", diff --git a/pixl_core/tests/token_buffer/test_tokens.py b/pixl_core/tests/token_buffer/test_tokens.py index cd778e1d2..8e464ad40 100644 --- a/pixl_core/tests/token_buffer/test_tokens.py +++ b/pixl_core/tests/token_buffer/test_tokens.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import time diff --git a/pixl_dcmd/src/pixl_dcmd/__init__.py b/pixl_dcmd/src/pixl_dcmd/__init__.py index 5ee012e10..ae5377621 100644 --- a/pixl_dcmd/src/pixl_dcmd/__init__.py +++ b/pixl_dcmd/src/pixl_dcmd/__init__.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging from pixl_dcmd.main import ( diff --git a/pixl_dcmd/src/pixl_dcmd/_version.py b/pixl_dcmd/src/pixl_dcmd/_version.py index fddacd579..95072f451 100644 --- a/pixl_dcmd/src/pixl_dcmd/_version.py +++ b/pixl_dcmd/src/pixl_dcmd/_version.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations __version_info__ = ("0", "0", "2") __version__ = ".".join(__version_info__) diff --git a/pixl_dcmd/src/pixl_dcmd/main.py b/pixl_dcmd/src/pixl_dcmd/main.py index 5a70ff4f8..9a3d665cf 100644 --- a/pixl_dcmd/src/pixl_dcmd/main.py +++ b/pixl_dcmd/src/pixl_dcmd/main.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import hashlib import logging import re diff --git a/pixl_dcmd/src/pixl_dcmd/tests/test_pixl_dcmd.py b/pixl_dcmd/src/pixl_dcmd/tests/test_pixl_dcmd.py index a5b78b78a..a9e78ab34 100644 --- a/pixl_dcmd/src/pixl_dcmd/tests/test_pixl_dcmd.py +++ b/pixl_dcmd/src/pixl_dcmd/tests/test_pixl_dcmd.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import pydicom import pytest diff --git a/pixl_dcmd/src/setup.py b/pixl_dcmd/src/setup.py index f2917a26e..8fb52c98a 100644 --- a/pixl_dcmd/src/setup.py +++ b/pixl_dcmd/src/setup.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations from pathlib import Path diff --git a/pixl_ehr/src/pixl_ehr/_databases.py b/pixl_ehr/src/pixl_ehr/_databases.py index 46d8a2e3d..294264701 100644 --- a/pixl_ehr/src/pixl_ehr/_databases.py +++ b/pixl_ehr/src/pixl_ehr/_databases.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging from pathlib import Path from typing import TYPE_CHECKING, Optional @@ -18,12 +20,11 @@ import psycopg2 as pypg from decouple import config -from pixl_ehr._queries import SQLQuery - logger = logging.getLogger("uvicorn") if TYPE_CHECKING: from pixl_ehr._processing import PatientEHRData + from pixl_ehr._queries import SQLQuery class Database: @@ -99,7 +100,7 @@ def to_csv(self, schema_name: str, table_name: str, filename: str) -> None: with Path(filename, "w").open() as file: self._cursor.copy_expert(query, file) - def contains(self, data: "PatientEHRData") -> bool: + def contains(self, data: PatientEHRData) -> bool: """Does the database contain a set of data already?""" query = "SELECT * FROM emap_data.ehr_raw WHERE mrn = %s and accession_number = %s" self._cursor.execute(query=str(query), vars=[data.mrn, data.accession_number]) diff --git a/pixl_ehr/src/pixl_ehr/_processing.py b/pixl_ehr/src/pixl_ehr/_processing.py index 32550be6a..20f5ed48a 100644 --- a/pixl_ehr/src/pixl_ehr/_processing.py +++ b/pixl_ehr/src/pixl_ehr/_processing.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging import os from abc import ABC, abstractmethod @@ -18,10 +20,9 @@ from dataclasses import dataclass from datetime import datetime, timedelta from pathlib import Path -from typing import Optional +from typing import TYPE_CHECKING, Optional import requests -from core.patient_queue.message import Message from decouple import config from pixl_ehr._databases import EMAPStar, PIXLDatabase @@ -29,6 +30,9 @@ from .report_deid import deidentify_text +if TYPE_CHECKING: + from core.patient_queue.message import Message + logger = logging.getLogger("uvicorn") logger.setLevel(os.environ.get("LOG_LEVEL", "WARNING")) @@ -79,7 +83,7 @@ class PatientEHRData: report_text: Optional[str] = None @classmethod - def from_message(cls, message: Message) -> "PatientEHRData": + def from_message(cls, message: Message) -> PatientEHRData: """ Create a minimal set of patient EHR data required to start queries from a queue message @@ -93,7 +97,7 @@ def from_message(cls, message: Message) -> "PatientEHRData": logger.debug("Created %s from message data", self) return self - def update_using(self, pipeline: "ProcessingPipeline") -> None: + def update_using(self, pipeline: ProcessingPipeline) -> None: """Update these data using a processing pipeline""" for i, step in enumerate(pipeline.steps): logger.debug("Step %s", [i / len(pipeline.steps) - 1]) @@ -143,7 +147,7 @@ def persist(self, database: PIXLDatabase, schema_name: str, table_name: str) -> ) logger.debug("Persist successful!") - def anonymise(self) -> "PatientEHRData": + def anonymise(self) -> PatientEHRData: """Anonymise these patient data by processing text and hashing identifiers""" if self.report_text is not None: self.report_text = deidentify_text(self.report_text) @@ -156,7 +160,7 @@ def anonymise(self) -> "PatientEHRData": return self - def copy(self) -> "PatientEHRData": + def copy(self) -> PatientEHRData: return deepcopy(self) diff --git a/pixl_ehr/src/pixl_ehr/_queries.py b/pixl_ehr/src/pixl_ehr/_queries.py index d95da30db..495eeaf46 100644 --- a/pixl_ehr/src/pixl_ehr/_queries.py +++ b/pixl_ehr/src/pixl_ehr/_queries.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + from pathlib import Path diff --git a/pixl_ehr/src/pixl_ehr/main.py b/pixl_ehr/src/pixl_ehr/main.py index bd1b781d1..e2b69f7e8 100644 --- a/pixl_ehr/src/pixl_ehr/main.py +++ b/pixl_ehr/src/pixl_ehr/main.py @@ -1,5 +1,3 @@ -""" -pixl_ehr module is an EHR extraction service app # Copyright (c) University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" +"""pixl_ehr module is an EHR extraction service app""" +from __future__ import annotations + import asyncio import importlib.metadata import logging diff --git a/pixl_ehr/src/pixl_ehr/report_deid/__init__.py b/pixl_ehr/src/pixl_ehr/report_deid/__init__.py index a94845571..dcbad1182 100644 --- a/pixl_ehr/src/pixl_ehr/report_deid/__init__.py +++ b/pixl_ehr/src/pixl_ehr/report_deid/__init__.py @@ -1,4 +1,3 @@ -""" # Copyright (c) University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" +"""Deidentifaction of text""" +from __future__ import annotations + from .deid import deidentify_text __all__ = ["deidentify_text"] diff --git a/pixl_ehr/src/pixl_ehr/report_deid/deid.py b/pixl_ehr/src/pixl_ehr/report_deid/deid.py index f3ea47e75..c08cac599 100644 --- a/pixl_ehr/src/pixl_ehr/report_deid/deid.py +++ b/pixl_ehr/src/pixl_ehr/report_deid/deid.py @@ -1,5 +1,3 @@ -""" -Collection of functions for deidentifaction of text # Copyright (c) University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" +"""Collection of functions for deidentifaction of text""" +from __future__ import annotations import os diff --git a/pixl_ehr/tests/conftest.py b/pixl_ehr/tests/conftest.py index 96b05818e..d4fba0989 100644 --- a/pixl_ehr/tests/conftest.py +++ b/pixl_ehr/tests/conftest.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import os diff --git a/pixl_ehr/tests/dummy-services/cogstack.py b/pixl_ehr/tests/dummy-services/cogstack.py index 554f4edc7..38fa2c35c 100644 --- a/pixl_ehr/tests/dummy-services/cogstack.py +++ b/pixl_ehr/tests/dummy-services/cogstack.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import asyncio import fastapi diff --git a/pixl_ehr/tests/test_app.py b/pixl_ehr/tests/test_app.py index 42bf54e3c..469c34900 100644 --- a/pixl_ehr/tests/test_app.py +++ b/pixl_ehr/tests/test_app.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """This file contains unit tests for the API that do not require any test services""" +from __future__ import annotations + from fastapi.testclient import TestClient from pixl_ehr.main import app, state diff --git a/pixl_ehr/tests/test_processing.py b/pixl_ehr/tests/test_processing.py index e5a2e8d78..663264f27 100644 --- a/pixl_ehr/tests/test_processing.py +++ b/pixl_ehr/tests/test_processing.py @@ -17,6 +17,8 @@ - pixl postgres db - emap star """ +from __future__ import annotations + import contextlib import datetime diff --git a/pixl_pacs/src/pixl_pacs/_orthanc.py b/pixl_pacs/src/pixl_pacs/_orthanc.py index f249167d9..47f99acfe 100644 --- a/pixl_pacs/src/pixl_pacs/_orthanc.py +++ b/pixl_pacs/src/pixl_pacs/_orthanc.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging from abc import ABC, abstractmethod from json import JSONDecodeError diff --git a/pixl_pacs/src/pixl_pacs/_processing.py b/pixl_pacs/src/pixl_pacs/_processing.py index af0733444..100ee1905 100644 --- a/pixl_pacs/src/pixl_pacs/_processing.py +++ b/pixl_pacs/src/pixl_pacs/_processing.py @@ -11,17 +11,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging import os from asyncio import sleep from dataclasses import dataclass from time import time +from typing import TYPE_CHECKING -from core.patient_queue.message import Message from decouple import config from pixl_pacs._orthanc import Orthanc, PIXLRawOrthanc +if TYPE_CHECKING: + from core.patient_queue.message import Message + logger = logging.getLogger("uvicorn") logger.setLevel(os.environ.get("LOG_LEVEL", "WARNING")) @@ -66,7 +71,7 @@ class ImagingStudy: message: Message @classmethod - def from_message(cls, message: Message) -> "ImagingStudy": + def from_message(cls, message: Message) -> ImagingStudy: return ImagingStudy(message=message) @property diff --git a/pixl_pacs/src/pixl_pacs/main.py b/pixl_pacs/src/pixl_pacs/main.py index 486cea5a5..a7f31e2f0 100644 --- a/pixl_pacs/src/pixl_pacs/main.py +++ b/pixl_pacs/src/pixl_pacs/main.py @@ -1,5 +1,3 @@ -""" -pixl_pacs module queries the VNA to check if a dataset exists # Copyright (c) University College London Hospitals NHS Foundation Trust # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -""" +"""pixl_pacs module queries the VNA to check if a dataset exists""" +from __future__ import annotations + import asyncio import importlib.metadata import logging diff --git a/pixl_pacs/tests/test_processing.py b/pixl_pacs/tests/test_processing.py index 06597a957..103345239 100644 --- a/pixl_pacs/tests/test_processing.py +++ b/pixl_pacs/tests/test_processing.py @@ -15,6 +15,8 @@ These tests require executing from within the PACS API container with the dependent services being up """ +from __future__ import annotations + import datetime import os diff --git a/scripts/cmove_all_studies.py b/scripts/cmove_all_studies.py index 550d82120..1353a5c96 100644 --- a/scripts/cmove_all_studies.py +++ b/scripts/cmove_all_studies.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """C-Move all studies from Orthanc Raw to Anon""" +from __future__ import annotations + import argparse import os from datetime import datetime, timedelta diff --git a/scripts/delete_oldest_n_studies.py b/scripts/delete_oldest_n_studies.py index a51a8c0cc..7dde792ae 100644 --- a/scripts/delete_oldest_n_studies.py +++ b/scripts/delete_oldest_n_studies.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """Delete a number of studies from an Orthanc instance""" +from __future__ import annotations + import argparse import os from datetime import datetime diff --git a/scripts/filter_cohort_for_those_present_in_raw.py b/scripts/filter_cohort_for_those_present_in_raw.py index 4a4d213cb..aa28d9eed 100644 --- a/scripts/filter_cohort_for_those_present_in_raw.py +++ b/scripts/filter_cohort_for_those_present_in_raw.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """Filter a cohort .csv file for those that are not present in Orthanc raw""" +from __future__ import annotations + import os import sys from json import JSONDecodeError diff --git a/scripts/list_newest_n_studies.py b/scripts/list_newest_n_studies.py index ed8df9b4f..64bfe406b 100644 --- a/scripts/list_newest_n_studies.py +++ b/scripts/list_newest_n_studies.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """List the newest studies""" +from __future__ import annotations + import argparse import os from datetime import datetime