# Study

## Quickstart

To write a report for a study with accession number `$ACCESSION_NUMBER` with username `$USERNAME` and private key filename `$PRIVATE_KEY_FILENAME`, run:

{% tabs %}
{% tab title="🐍 Python" %}

```python
from client_sdk import StudyAPIClient

async with StudyAPIClient(
    username="$USERNAME",
    private_key_filename="$PRIVATE_KEY_FILENAME",
) as client:
    await client.set_report(
        accession_number="$ACCESSION_NUMBER",
        report="$REPORT",
    )
```

{% endtab %}

{% tab title="🟦 TS/JS" %}

```javascript
import { StudyAPIClient } from 'bunkerhill-inference-api/client';

const client = new StudyAPIClient('$USERNAME', '$PRIVATE_KEY_FILENAME');

await client.setReport(
  '$ACCESSION_NUMBER',
  '$REPORT',
);
```

{% endtab %}
{% endtabs %}

## `StudyAPIClient` Reference

{% tabs %}
{% tab title="🐍 Python" %}

### Constructor

#### Method signature

<pre class="language-python"><code class="lang-python">def __init__(
<strong>    self,
</strong>    username: str,
    private_key_filename: Optional[str] = None,
    private_key_string: Optional[str] = None,
    base_url: str = 'https://api.bunkerhillhealth.com/',
) -> None:
    ...
</code></pre>

#### Parameters

* `username` (`str`): The username to authenticate the client.
* `private_key_filename` (`Optional[str]`): Filename of the RSA private key.
* `private_key_string` (`Optional[str]`): The RSA private key as a string.
* `base_url` (`str`, has a default): The base URL of the Inference API. Defaults to '<https://api.bunkerhillhealth.com/>'.

**Notes**

* At least one of `private_key_filename` or `private_key_string` must be provided.

***

### `set_report`

Sets a report for a `Study` object with a given accession number from the Study API. Must be called from an async context.

{% hint style="info" %}
Hint: The `set_report` method is asynchronous. To make use of this method from a synchronous application, calls to the `StudyAPIClient` can be wrapped in `asyncio.run()`.
{% endhint %}

#### Method signature

```python
def set_report(
  self,
  accession_number: str,
  report: str,
) -> None:
  ...
```

#### Parameters

* `accession_number` (`str`): The accession number of the study.
* `report` (`str`): The text of the report.

#### Returns

`None`

**Notes**

* You must have authorization to the specified `accession_number`. If not, a `403` error will be raised.
* Only studies corresponding to institutions that you are authorized to will be writable.
  {% endtab %}

{% tab title="🟦 TS/JS" %}

### Constructor

#### Method signature

```typescript
constructor(
  username: string,
  privateKeyFilename?: string,
  privateKeyString?: string,
  baseUrl: string = 'https://api.bunkerhillhealth.com/',
) {}
```

#### Parameters

* `username` (`string`): The username to authenticate the client.
* `privateKeyFilename` (`string`, optional): Filename of the RSA private key.
* `privateKeyString` (`string`, optional): The RSA private key as a string.
* `baseUrl` (`string`, has a default): The base URL of the Inference API. Defaults to '<https://api.bunkerhillhealth.com/>'.

**Notes**

* At least one of `privateKeyFilename` or `privateKeyString` must be provided.

***

### `setReport`

Sets a report for a `Study` object with a given accession number from the Study API. Must be called from an async context.

#### Method signature

```typescript
async getInferences(
  accessionNumber: string,
  report: string,
): Promise<void> {}
```

#### Parameters

* `accessionNumber` (`str`): The accession number of the study.
* `report` (`str`): The text of the report.

#### Returns

`Promise<void>`

**Notes**

* You must have authorization to the specified `accessionNumber`. If not, a `403` error will be raised.
* Only studies corresponding to institutions that you are authorized to will be accessible.
  {% endtab %}
  {% endtabs %}
