Clients
EHRClient
Bases: BaseClient
Source code in healthchain/clients/ehrclient.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
__init__(func, workflow, strategy, timeout=10.0)
Initializes the EHRClient with a data generator function and optional workflow and use case. Should be a subclass of BaseUseCase. Example - ClinicalDecisionSupport()
PARAMETER | DESCRIPTION |
---|---|
func
|
A function to generate data for requests.
TYPE:
|
workflow
|
The workflow context to apply to the data generator.
TYPE:
|
strategy
|
The strategy object to construct requests based on the generated data.
TYPE:
|
timeout
|
The maximum time in seconds to wait for a response from the server. This parameter determines how long the client will wait before considering a request timed out.
TYPE:
|
Source code in healthchain/clients/ehrclient.py
generate_request(*args, **kwargs)
Generates a request using the data produced by the data generator function, and appends it to the internal request queue.
Parameters:
*args (Any): Positional arguments passed to the data generator function.
**kwargs (Any): Keyword arguments passed to the data generator function.
Raises:
ValueError: If the use case is not configured.
Source code in healthchain/clients/ehrclient.py
send_request(url)
async
Sends all queued requests to the specified URL and collects the responses.
Parameters:
url (str): The URL to which the requests will be sent.
Returns:
List[dict]: A list of JSON responses from the server.
Notes:
This method logs errors rather than raising them, to avoid interrupting the batch processing of requests.
Source code in healthchain/clients/ehrclient.py
ehr(func=None, *, workflow, num=1)
A decorator that wraps around a data generator function and returns an EHRClient
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to be decorated. If None, this allows the decorator to be used with arguments.
TYPE:
|
workflow
|
The workflow identifier which should match an item in the Workflow enum. This specifies the context in which the EHR function will operate.
TYPE:
|
num
|
The number of requests to generate in the queue; defaults to 1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
A decorated callable that incorporates EHR functionality or the decorator itself if 'func' is None, allowing it to be used as a parameterized decorator.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the workflow does not correspond to any defined enum or if use case is not configured. |
NotImplementedError
|
If the use case class is not one of the supported types. |
Example
@ehr(workflow='patient-view', num=2) def generate_data(self, config): # Function implementation