Skip to content

Practitioner

practitioner_dto

Bases: BaseModel

Represents a pagination link in a response, typically used for handling the next page in paginated data.

Attributes:

Name Type Description
next_page str

The URL or link to the next page in a paginated list.

Configuration

model_config: Configuration settings to enable population by name and use enum values for the model fields.

PractitionerFilterResponse

Bases: BaseModel, Generic[PractitionerEntry]

Represents the response containing a list of practitioners, along with pagination information and the total count.

Attributes:

Name Type Description
entry list[PractitionerEntry]

A list of practitioner entries in the response.

link Link

A link object that contains the URL for the next page in the paginated list, if available.

total int

The total number of practitioners available in the dataset.

Configuration

model_config: Configuration settings to enable population by name and use enum values for the model fields.

GetPractitionerResponse

Bases: BaseModel

DTO for representing the response when getting one or more practitioners.

Attributes:

Name Type Description
type Optional[str]

The type of response.

message Optional[str]

A message describing the response.

request_resource Optional[Any]

The original request resource.

total_number_of_records Optional[int]

Total number of records.

next_page_link Optional[str]

Link to the next page of results.

CreateUpdatePractitionerResponse

Bases: BaseModel

DTO for representing the response after creating or updating a practitioner.

Attributes:

Name Type Description
type Optional[str]

The type of response.

message Optional[str]

A message describing the response.

resource_id Optional[str]

The resource ID of the practitioner.

PractitionerBaseDTO

Bases: BaseModel

Base DTO for practitioner data with common validations.

This class is used as a base for both create and update practitioner DTOs, providing field definitions and validation logic for practitioner data.

Attributes:

Name Type Description
registration_id str

Unique registration ID for the practitioner.

department str

Department to which the practitioner belongs.

designation str

Designation of the practitioner.

status str

Current status of the practitioner (e.g., Active, Inactive).

joining_date str

Date of joining (YYYY-MM-DD).

staff_type str

Type of staff (e.g., Doctor, Nurse).

first_name str

First name of the practitioner.

middle_name Optional[str]

Middle name of the practitioner.

last_name Optional[str]

Last name of the practitioner.

birth_date Optional[str]

Date of birth (YYYY-MM-DD).

gender str

Gender of the practitioner.

mobile_number Optional[str]

Mobile number (+91 followed by 10 digits).

email_id Optional[str]

Email address.

address str

Address of the practitioner.

pincode Optional[str]

Pincode (6 digits).

state Optional[str]

State (must match StatesAndUnionTerritories).

wants_to_link_whatsapp Optional[bool]

Whether to link WhatsApp.

photo Optional[str]

Photo.

resource_type str

Resource type (must match ResourceType).

resource_id Optional[str]

Resource ID.

CreatePractitionerDTO

Bases: PractitionerBaseDTO

DTO for creating a new practitioner.

Inherits all fields and validations from PractitionerBaseDTO.

UpdatePractitionerDTO

Bases: PractitionerBaseDTO

DTO for updating an existing practitioner.

Inherits all fields and validations from PractitionerBaseDTO.

PractitionerFiltersDTO

Bases: BaseModel

Data Transfer Object (DTO) for filtering Practitioner records.

Attributes:

Name Type Description
first_name Optional[str]

The practitioner's first name.

last_name Optional[str]

The practitioner's last name.

birth_date Optional[str]

The practitioner's birth date.

gender Optional[str]

The practitioner's gender.

mobile_number Optional[str]

The practitioner's mobile number.

email_id Optional[str]

The practitioner's email ID.

count Optional[int]

The number of records to fetch.

state Optional[str]

The practitioner's state.

Configuration

model_config: Configuration settings to enable population by name and use enum values.

Practitioner

Practitioner(config: ClientConfig)

Bases: BaseService

SDK-friendly Practitioner service for managing practitioner-related operations.

This class provides asynchronous methods to interact with practitioner records: retrieving lists and individual records, creating new practitioners, updating existing records, deleting practitioners, and searching with complex filters.

Data validation and transformation is strictly performed via Pydantic-based DTOs for API reliability. The service manages errors gracefully and logs operation details for audit and troubleshooting.

Parameters:

Name Type Description Default
config ClientConfig

Configuration including API keys, base URL, and other connection parameters.

required

Raises:

Type Description
EhrApiError

If an error occurs during API calls.

ValidationError

If input data does not conform to expected schemas.

Example
config = ClientConfig(api_key="your_api_key")
practitioner_service = Practitioner(config)

# Fetch first page of practitioners
practitioners = asyncio.run(practitioner_service.find_all())
print(f"Total practitioners: {practitioners.total}")

# Fetch individual practitioner by ID
practitioner = asyncio.run(practitioner_service.find_by_id("pract123"))
print(practitioner.request_resource["firstName"])

# Create a new practitioner
new_practitioner = {
    "registrationId": "REG12345",
    "department": "Cardiology",
    "designation": "Senior Consultant",
    "status": "Active",
    "joiningDate": "2020-01-15",
    "staffType": "Doctor",
    "firstName": "Alice",
    "lastName": "Smith",
    "birthDate": "1980-06-10",
    "gender": "F",
    "mobileNumber": "+919876543210",
    "emailId": "alice.smith@example.com",
    "address": "123 Medical Street, City",
    "pincode": "110001",
    "state": "Delhi",
    "resourceType": "Practitioner"
}
created = asyncio.run(practitioner_service.create(new_practitioner))
print(created.message)

create async

create(practitioner: dict[str, Any]) -> CreateUpdatePractitionerResponse

Creates a new practitioner record.

Parameters:

Name Type Description Default
practitioner CreatePractitionerDTO

Practitioner creation data matching CreatePractitionerDTO schema.

required

Returns:

Name Type Description
CreatePractitionerResponse CreateUpdatePractitionerResponse

Confirmation and created resource details.

Raises:

Type Description
EhrError

On validation failure, duplicate record, or API error.

Example
new_prac = {
    "registrationId": "REG5678",
    "department": "Neurology",
    "designation": "Consultant",
    "status": "Active",
    "joiningDate": "2021-05-10",
    "staffType": "Doctor",
    "firstName": "Bob",
    "lastName": "John",
    "birthDate": "1975-09-22",
    "gender": "M",
    "mobileNumber": "+919876543210",
    "emailId": "bob.john@example.com",
    "address": "456 Medical Lane, City",
    "pincode": "560001",
    "state": "Karnataka",
    "resourceType": "Practitioner"
}
created = await practitioner_service.create(new_prac)
print(created.message)
Response:
Sample Output:
{
    "type": "success",
    "message": "Practitioner created successfully.",
    "resourceId": "pract123"
}

find_all async

find_all(next_page: Optional[str] = None) -> GetPractitionerResponse

Retrieves the list of practitioners, paginated.

Parameters:

Name Type Description Default
next_page str

Pagination token from previous call to fetch next page.

None

Returns:

Name Type Description
GetPractitionerResponse GetPractitionerResponse

Contains practitioner list, pagination info, and total count.

Raises:

Type Description
EhrError

On API communication or authentication failure.

Example
response = await practitioner_service.find_all()
print(f"Total practitioners: {response.total}")
for p in response.request_resource:
    print(p["firstName"], p["department"])
Response:
Sample Output:
{
    "type": "success",
    "message": "Practitioners fetched successfully.",
    "request_resource": [
        {
            "registrationId": "REG5678",
            "firstName": "Alice",
            "department": "Neurology",
            ...
        },
        ...
    ],
    "total_number_of_records": 25,
    "next_page_link": "token123"
}

find_by_id async

find_by_id(practitioner_id: str) -> GetPractitionerResponse

Retrieves detailed information about a specific practitioner.

Parameters:

Name Type Description Default
practitioner_id str

Unique identifier of the practitioner.

required

Returns:

Name Type Description
GetPractitionerResponse GetPractitionerResponse

Practitioner data response object.

Raises:

Type Description
EhrError

On invalid ID, not found, or API error.

Example
practitioner = await practitioner_service.find_by_id("pract123")
print(practitioner.request_resource["firstName"])
Response:
Sample Output:
{
    "type": "success",
    "message": "Practitioner found successfully.",
    "request_resource": {
        "registrationId": "REG5678",
        "firstName": "Alice",
        "department": "Neurology",
        ...
    }
}

exists async

exists(practitioner_id: str) -> bool

Checks if a practitioner exists based on their ID.

Parameters:

Name Type Description Default
practitioner_id str

Unique practitioner ID.

required

Returns:

Name Type Description
bool bool

True if practitioner exists, False otherwise.

Raises:

Type Description
EhrError

On API errors.

Example
exists = await practitioner_service.exists("pract123")
print("Exists:", exists)
Response:
Sample Output:
"Exists: True" or "Exists: False" based on practitioner existence.

update async

update(update_practitioner_data: dict[str, Any]) -> CreateUpdatePractitionerResponse

Updates an existing practitioner record.

Parameters:

Name Type Description Default
update_practitioner_data UpdatePractitionerDTO

Data to update per UpdatePractitionerDTO schema.

required

Returns:

Name Type Description
CreatePractitionerResponse CreateUpdatePractitionerResponse

Confirmation and updated resource details.

Raises:

Type Description
EhrError

On validation failure or API error.

Example
update_info = {
    "registrationId": "REG5678",
    "designation": "Senior Consultant",
    "status": "Active",
    "joiningDate": "2021-05-10",
    "staffType": "Doctor",
    "firstName": "Bob",
    "lastName": "John",
    "birthDate": "1975-09-22",
    "gender": "M",
    "mobileNumber": "+919876543210",
    "emailId": "bob.new@example.com",
    "address": "789 New Medical St, City",
    "pincode": "560002",
    "state": "Karnataka",
    "resourceType": "Practitioner",
    "resourceId": "pract123"
}
updated = await practitioner_service.update(update_info)
print(updated.message)
Response:
Sample Output:
{
    "type": "success",
    "message": "Practitioner updated successfully.",
    "resourceId": "pract123"
}

find_by_filters async

find_by_filters(filters: dict[str, Any], next_page: Optional[str] = None) -> PractitionerFilterResponse

Searches for practitioners matching filter criteria and supports pagination.

Raw user-entered filter keys are mapped to backend field names.

Parameters:

Name Type Description Default
filters dict

Filter conditions such as firstName, lastName, state, etc.

required
next_page str

Pagination token for subsequent pages.

None

Returns:

Name Type Description
PractitionerFilterResponse PractitionerFilterResponse

Contains matching practitioner entries and pagination info.

Raises:

Type Description
EhrError

On validation or API failure.

Example
filter_conditions = {
    "firstName": "Alice",
    "state": "Karnataka",
    "count": 10
}
results = await practitioner_service.find_by_filters(filter_conditions)
print(f"Total found: {results.total}")
for practitioner in results.entry:
    print(practitioner["firstName"], practitioner["department"])
Response:
Sample Output:
{
    "entry": [
        {
            "registrationId": "REG5678",
            "firstName": "Alice",
            "department": "Neurology",
            ...
        },
        ...
    ],
    "link": {"nextPage": "token123"},
    "total": 25
}

delete async

delete(practitioner_id: str) -> None

Deletes a practitioner by their unique ID.

Parameters:

Name Type Description Default
practitioner_id str

Unique identifier.

required

Raises:

Type Description
EhrError

On invalid ID or API failure.

Example
await practitioner_service.delete("pract123")
print("Practitioner deleted successfully")
Response:
Sample Output:
"Practitioner deleted successfully" or raises an error if deletion fails.

### Note:
This operation is irreversible. Ensure the practitioner is no longer needed before deletion.