> ## Documentation Index
> Fetch the complete documentation index at: https://ekacare-fix-ts-sdk-github-npm-links.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK: ekacare

> A python sdk for ekacare backend

A comprehensive Python SDK for interacting with the Eka Care APIs. You can install it as a python package as below

```bash theme={null}
pip install ekacare
```

## Features

The SDK provides easy access to the following Eka Care APIs:

* Authentication
* Records Management (upload, list, update, delete)
* ABDM Connect (profile, consents, care contexts)
* Appointment Management
* Doctor & Clinic Management
* Patient Management
* Webhooks (register, manage, verify)
* Vitals (update patient vitals)
* Medical Document Parsing
* Assessment APIs
* Notifications
* Privacy Management

***

## Quick Start

### Authentication

```python theme={null}
from ekacare import EkaCareClient

# Initialize with client credentials
client = EkaCareClient(
    client_id="your_client_id",
    client_secret="your_client_secret"
)

# Or initialize with an existing access token
client = EkaCareClient(
    client_id="your_client_id",
    client_secret="your_client_secret",
    access_token="your_access_token"
)

# Manually get an access token
token_response = client.auth.login()
access_token = token_response["access_token"]
```

***

### Vitals Management

```python theme={null}
# Create vital records
heart_rate = client.vitals.create_heart_rate_vital(
    value=75,
    measured_at="2023-01-01T12:00:00"
)

blood_glucose = client.vitals.create_blood_glucose_vital(
    value=120,
    measured_at="2023-01-01T08:00:00",
    glucose_type="fasting"
)

blood_oxygen = client.vitals.create_blood_oxygen_vital(
    value=98,
    measured_at="2023-01-01T12:30:00"
)

blood_pressure = client.vitals.create_blood_pressure_vital(
    systolic=120,
    diastolic=80,
    measured_at="2023-01-01T14:45:00"
)

# Update patient vitals
client.vitals.update_vitals(
    txn_id="transaction_id",
    vitals_data=[heart_rate, blood_glucose, blood_oxygen] + blood_pressure
)
```

***

### Webhooks

```python theme={null}
# Register a webhook
response = client.webhooks.register_webhook(
    endpoint="https://your-app.com/webhook",
    scopes=["appointment.created", "prescription.created"],
    signing_key="your_secret_key"
)
webhook_id = response["id"]

# Get all webhooks
webhooks = client.webhooks.get_webhooks()

# Update a webhook's signing key
client.webhooks.update_webhook(
    webhook_id=webhook_id,
    signing_key="new_secret_key"
)

# Delete a webhook
client.webhooks.delete_webhook(webhook_id)

# Verify a webhook signature
is_valid = client.webhooks.verify_signature(
    payload=webhook_payload,
    signature=webhook_signature,
    secret_key="your_secret_key"
)
```

***

### Appointment Management

```python theme={null}
# Get Appointment Details
response = client.appointments.get_appointment_details("YOUR_APPOINTMENT_ID")

```

***

### Doctor & Clinic Management

```python theme={null}
# Get Clinic Details
response = client.clinic_doctor.get_clinic_details("YOUR_CLINIC_ID")


# Get Doctor Details
response = client.clinic_doctor.get_doctor_details("YOUR_DOCTOR_ID")

```

***

### Appointment Management

```python theme={null}
# Get Appointment Details
response = client.appointments.get_appointment_details("YOUR_APPOINTMENT_ID")

```

***

### Patient Details

```python theme={null}
# Get Patient Details
response = client.patient.get_patient("YOUR_PATIENT_ID")

```

***

### ABDM Profile Management

```python theme={null}
# Get ABHA profile
profile = client.abdm_profile.get_profile()
print(profile["abha_address"])

# Update profile
client.abdm_profile.update_profile({
    "address": "123 Main St",
    "pincode": "110001"
})

# Get ABHA card
card_image = client.abdm_profile.get_abha_card()
with open("abha_card.png", "wb") as f:
    f.write(card_image)

# Get QR code data
qr_data = client.abdm_profile.get_abha_qr_code()

# Initiate KYC
response = client.abdm_profile.initiate_kyc(
    method="abha-number",
    identifier="1234-5678-9012"
)
txn_id = response["txn_id"]

# Verify KYC OTP
client.abdm_profile.verify_kyc_otp(
    txn_id=txn_id,
    otp="123456"
)
```

***

### Assessments

You can take assessments using eka client.

#### 1. To start an assessment:

```python theme={null}
first_question_form = client.assessment.start(
    age=20, 
    gender="M", 
    workflow_id=4002,
    practitioner_uuid="example_pract_uuid_123",
    patient_uuid="example_patient_uuid_123",
    unique_identifier="example_unique_id_123",
    context=additional_context
)
```

You can set additional context as a stringified json.

```python theme={null}
import json
additional_context = json.loads(
    {
        "name": "Rakesh",
        "city": "Pune"
    }
)
```

<Tip>[Click here](/api-reference/health-ai/assessment/overview) to know more about eka care assessment platform.</Tip>

#### 2. Continue the assessment (get next question)

To get the next question, you need to answer the first question. The response can be a string for input type questions or a list of strings (ids) for choice type questions.

**get response**

<AccordionGroup>
  <Accordion title="For input type question">
    ```python theme={null}
    user_input = "2001-03-14"  # example date of birth
    first_question_response = response(  # format the user's input
        question=first_question, 
        answer=user_input
    )
    ```
  </Accordion>

  <Accordion title="For choice type question">
    ```python theme={null}
    choice_ids = ["abc", "def"] 
    first_question_response = response(  # format the user's choices
        question=first_question 
        answer=choice_ids
    )
    ```
  </Accordion>
</AccordionGroup>

<Tip>[Click here](/api-reference/health-ai/assessment/assessment-flow/continue/continue-request-formats#types-of-question-components) to know more about types of question component</Tip>

**get the next question using `first_question_response`**

```python theme={null}
client.assessment.next(
    qid=0, 
    user_response=first_response
)
```

#### 3. Submit the assessment when all questions are answered

```python theme={null}
client.assessment.submit()
```

***

## Error Handling

The SDK uses custom exceptions to handle errors:

```python theme={null}
from ekacare import EkaCareClient, EkaCareAPIError, EkaCareAuthError

client = EkaCareClient(
    client_id="your_client_id",
    client_secret="your_client_secret"
)

try:
    documents = client.records.list_documents()
except EkaCareAuthError as e:
    print(f"Authentication error: {e}")
except EkaCareAPIError as e:
    print(f"API error: {e}")
```

## License

This SDK is distributed under the MIT License.
