Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Python SDK Docs #2

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 68 additions & 34 deletions README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed updating the installation section, its still referring to fern-metriport

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr wasnt rebased. Should be good now

Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,97 @@ poetry add metriport

## Usage
```python
from metriport import BaseOrganization, OrgType, Address, UsState
import os
from dotenv import load_dotenv
from metriport.client import Metriport

metriport_client = Metriport(api_key="YOUR_API_KEY")

document = metriport_client.medical.organization.create(BaseOrganization(
type=OrgType.PostAcuteCare,
name="Metriport Inc.",
location=Address(
addressLine1="2261 Market Street",
addressLine2="#4818",
city="San Francisco",
state=UsState.CA,
zip="94114",
country="USA",
)
));
from metriport.resources.medical import BasePatient, PersonalIdentifier_DriversLicense
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change resources to models?

from metriport import Address, UsState

load_dotenv()

facility_id = os.environ.get("FACILITY_ID")
api_key = os.environ.get("API_KEY")
base_url = os.environ.get("BASE_URL") ## optional param to base to client if want to point to sandbox url.

client = Metriport(api_key=api_key)
patient_data = BasePatient(
first_name="John",
last_name="Doe",
dob="1980-01-01",
gender_at_birth="M",
personal_identifiers=[
PersonalIdentifier_DriversLicense(
type="driversLicense",
state=UsState.CA,
value="12345678",
)
],
address=[Address(
address_line_1="123 Main St",
city="Los Angeles",
state=UsState.CA,
zip="90001",
country="USA"
)]
)
response = client.medical.patient.create(facility_id=facility_id, request=patient_data)
```

## Async Client
Our Python SDK exports an async client that you can use with asyncio.

```python
from metriport import BaseOrganization, OrgType, Address, UsState
from metriport.client import AsyncMetriport

import os
from dotenv import load_dotenv
from metriport.client import AsyncMetriport
from metriport.resources.medical import BasePatient, PersonalIdentifier_DriversLicense
from metriport import Address, UsState
import asyncio

load_dotenv()

facility_id = os.environ.get("FACILITY_ID")
api_key = os.environ.get("API_KEY")

metriport_client = AsyncMetriport(api_key="YOUR_API_KEY")

async def create_organization():
document = metriport_client.medical.organization.create(BaseOrganization(
type=OrgType.PostAcuteCare,
name="Metriport Inc.",
location=Address(
addressLine1="2261 Market Street",
addressLine2="#4818",
city="San Francisco",
async def create_patient():
patient_data = BasePatient(
first_name="John",
last_name="Doe",
dob="1980-01-01",
gender_at_birth="M",
personal_identifiers=[
PersonalIdentifier_DriversLicense(
type="driversLicense",
state=UsState.CA,
value="12345678",
)
],
address=[Address(
address_line_1="123 Main St",
city="Los Angeles",
state=UsState.CA,
zip="94114",
country="USA",
)
));
zip="90001",
country="USA"
)]
)
response = client.medical.patient.create(facility_id=facility_id, request=patient_data)

asyncio.run(create_organization())
asyncio.run(create_patient())
```

## Error Handling
All exceptions thrown by the SDK will sublcass [ApiError](./src/metriport/core/api_error.py).

```python
from metriport.core import ApiError
from metriport import BadRequestError

try:
metriport.medical.patients.get(patient_id='my_id')
except APIError as e:
client.medical.patient.create(facility_id='bad_id', request="bad_req")
except ApiError as e:
print(e)
# handle any api related error
```

Expand Down
Loading