-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f84f97
feat(docs): updating sync client. todo update async
jonahkaye cbf2fe9
Merge branch 'master' into 1212-update-python-docs
jonahkaye 20b018b
feat(readme): tested code and updated readme
jonahkaye 78fb2c0
feat(hack): rewrote import paths
jonahkaye 3f1feb9
feat(hack): rewrote import paths more
jonahkaye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
``` | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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