Skip to content

Commit 46db618

Browse files
Refactor sandbox module
1 parent 869d4de commit 46db618

29 files changed

+606
-1937
lines changed

healthchain/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from .utils.logger import add_handlers
55
from .config.base import ConfigManager, ValidationLevel
66

7-
from .sandbox.decorator import sandbox, api, ehr
87

98
# Enable deprecation warnings
109
warnings.filterwarnings("always", category=DeprecationWarning, module="healthchain")
@@ -30,4 +29,14 @@ def __getattr__(name):
3029
from healthchain.sandbox import generators
3130

3231
return generators
32+
elif name == "use_cases":
33+
warnings.warn(
34+
"Importing use_cases from healthchain is deprecated. "
35+
"Use 'from healthchain.sandbox import use_cases' instead.",
36+
DeprecationWarning,
37+
stacklevel=2,
38+
)
39+
from healthchain.sandbox import use_cases
40+
41+
return use_cases
3342
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

healthchain/sandbox/__init__.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
# New simplified API
2-
from .sandbox_client import SandboxClient
1+
import warnings
2+
3+
from .sandboxclient import SandboxClient
34
from .datasets import DatasetRegistry, DatasetLoader, list_available_datasets
45

5-
# Import loaders to trigger auto-registration
66

7-
# Legacy decorators and classes (deprecated)
8-
from .decorator import sandbox, api, ehr
9-
from .environment import SandboxEnvironment
10-
from .use_cases import (
11-
ClinicalDecisionSupport,
12-
ClinicalDocumentation,
13-
CdsRequestConstructor,
14-
ClinDocRequestConstructor,
15-
)
16-
from .clients import EHRClient
7+
# Import loaders to trigger auto-registration
178

189
__all__ = [
19-
# New API
2010
"SandboxClient",
2111
"DatasetRegistry",
2212
"DatasetLoader",
2313
"list_available_datasets",
24-
# Legacy API (deprecated)
25-
"sandbox",
26-
"api",
27-
"ehr",
28-
"SandboxEnvironment",
29-
"ClinicalDecisionSupport",
30-
"ClinicalDocumentation",
31-
"CdsRequestConstructor",
32-
"ClinDocRequestConstructor",
33-
"EHRClient",
3414
]
15+
16+
17+
def __getattr__(name):
18+
deprecated_names = [
19+
"sandbox",
20+
"api",
21+
"ehr",
22+
"ClinicalDecisionSupport",
23+
"ClinicalDocumentation",
24+
]
25+
26+
if name in deprecated_names:
27+
warnings.warn(
28+
f"{name} is deprecated and has been removed. "
29+
f"Use SandboxClient instead.",
30+
DeprecationWarning,
31+
stacklevel=2,
32+
)
33+
raise AttributeError(f"{name} has been removed")
34+
raise AttributeError(f"module 'healthchain.sandbox' has no attribute '{name}'")

healthchain/sandbox/base.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
from abc import ABC, abstractmethod
2-
from typing import Dict, List, Optional
2+
from typing import Dict
3+
from enum import Enum
34

4-
from healthchain.sandbox.workflows import UseCaseType, Workflow
5+
from healthchain.models.hooks.prefetch import Prefetch
6+
from healthchain.sandbox.workflows import Workflow
57

68

7-
class BaseClient(ABC):
8-
"""Base client class
9-
A client can be an EHR or CPOE etc.
10-
The basic operation is that it sends data in a specified standard.
9+
class ApiProtocol(Enum):
1110
"""
11+
Enum defining the supported API protocols.
1212
13-
@abstractmethod
14-
def send_request(self) -> None:
15-
"""
16-
Sends a request to AI service
17-
"""
13+
Available protocols:
14+
- soap: SOAP protocol
15+
- rest: REST protocol
16+
"""
17+
18+
soap = "SOAP"
19+
rest = "REST"
1820

1921

2022
class BaseRequestConstructor(ABC):
@@ -30,40 +32,38 @@ def construct_request(self, data, workflow: Workflow) -> Dict:
3032
pass
3133

3234

33-
class BaseUseCase(ABC):
35+
class DatasetLoader(ABC):
3436
"""
35-
Abstract base class for healthcare use cases in the sandbox environment.
37+
Abstract base class for dataset loaders.
3638
37-
This class provides a foundation for implementing different healthcare use cases
38-
such as Clinical Decision Support (CDS) or Clinical Documentation (NoteReader).
39-
Subclasses must implement the type and strategy properties.
39+
Subclasses should implement the load() method to return Prefetch data
40+
from their specific dataset source.
4041
"""
4142

42-
def __init__(
43-
self,
44-
client: Optional[BaseClient] = None,
45-
) -> None:
46-
self._client: BaseClient = client
43+
@abstractmethod
44+
def load(self, **kwargs) -> Prefetch:
45+
"""
46+
Load dataset and return as Prefetch object.
4747
48-
self.responses: List[Dict[str, str]] = []
49-
self.sandbox_id = None
50-
self.url = None
48+
Args:
49+
**kwargs: Loader-specific parameters
5150
52-
@property
53-
@abstractmethod
54-
def type(self) -> UseCaseType:
51+
Returns:
52+
Prefetch object containing FHIR resources
53+
54+
Raises:
55+
FileNotFoundError: If dataset files are not found
56+
ValueError: If dataset parameters are invalid
57+
"""
5558
pass
5659

5760
@property
5861
@abstractmethod
59-
def strategy(self) -> BaseRequestConstructor:
62+
def name(self) -> str:
63+
"""Dataset name for registration."""
6064
pass
6165

6266
@property
63-
def path(self) -> str:
64-
path = self._path
65-
if not path.startswith("/"):
66-
path = "/" + path
67-
if not path.endswith("/"):
68-
path = path + "/"
69-
return path
67+
def description(self) -> str:
68+
"""Optional description of the dataset."""
69+
return ""

healthchain/sandbox/clients/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

healthchain/sandbox/clients/ehr.py

Lines changed: 0 additions & 121 deletions
This file was deleted.

healthchain/sandbox/datasets.py

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,14 @@
55
"""
66

77
import logging
8-
from abc import ABC, abstractmethod
8+
99
from typing import Any, Dict, List
1010

1111
from healthchain.models import Prefetch
12+
from healthchain.sandbox.base import DatasetLoader
1213

13-
log = logging.getLogger(__name__)
14-
15-
16-
class DatasetLoader(ABC):
17-
"""
18-
Abstract base class for dataset loaders.
19-
20-
Subclasses should implement the load() method to return Prefetch data
21-
from their specific dataset source.
22-
"""
23-
24-
@abstractmethod
25-
def load(self, **kwargs) -> Prefetch:
26-
"""
27-
Load dataset and return as Prefetch object.
2814

29-
Args:
30-
**kwargs: Loader-specific parameters
31-
32-
Returns:
33-
Prefetch object containing FHIR resources
34-
35-
Raises:
36-
FileNotFoundError: If dataset files are not found
37-
ValueError: If dataset parameters are invalid
38-
"""
39-
pass
40-
41-
@property
42-
@abstractmethod
43-
def name(self) -> str:
44-
"""Dataset name for registration."""
45-
pass
46-
47-
@property
48-
def description(self) -> str:
49-
"""Optional description of the dataset."""
50-
return ""
15+
log = logging.getLogger(__name__)
5116

5217

5318
class DatasetRegistry:

0 commit comments

Comments
 (0)