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
Show file tree
Hide file tree
Changes from all 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.medical import BasePatient, PersonalIdentifier_DriversLicense
from metriport.commons 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.medical import BasePatient, PersonalIdentifier_DriversLicense
from metriport.commons 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
6 changes: 4 additions & 2 deletions src/metriport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file was auto-generated by Fern from our API Definition.

from .resources import Address, UsState, commons, fhir, medical
from .environment import MetriportEnvironment
from . import commons
from . import fhir
from . import medical

__all__ = ["Address", "MetriportEnvironment", "UsState", "commons", "fhir", "medical"]
__all__ = ["Address", "MetriportEnvironment", "fhir", "medical", "commons"]
2 changes: 1 addition & 1 deletion src/metriport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .environment import MetriportEnvironment
from .resources.medical.client import AsyncMedicalClient, MedicalClient
from .medical.client import AsyncMedicalClient, MedicalClient


class Metriport:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .us_state import UsState

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .address_type import AddressType
from .address_use import AddressUse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .age_comparator import AgeComparator
from .code import Code
from .decimal import Decimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .date_time import DateTime
from .markdown import Markdown

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .base_64_binary import Base64Binary
from .code import Code
from .date_time import DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .code import Code
from .extension import Extension
from .id import Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import typing_extensions

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .bundle_entry import BundleEntry
from .bundle_link import BundleLink
from .bundle_type import BundleType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .bundle_link import BundleLink
from .bundle_request import BundleRequest
from .bundle_response import BundleResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .extension import Extension
from .uri import Uri

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .bundle_request_method import BundleRequestMethod
from .extension import Extension
from .instant import Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .extension import Extension
from .instant import Instant
from .uri import Uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .bundle_search_mode import BundleSearchMode
from .decimal import Decimal
from .extension import Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime

try:
import pydantic.v1 as pydantic # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .code import Code
from .uri import Uri

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime

try:
import pydantic.v1 as pydantic # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .contact_point_system import ContactPointSystem
from .contact_point_use import ContactPointUse
from .positive_int import PositiveInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .contributor_type import ContributorType

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .code import Code
from .count_comparator import CountComparator
from .decimal import Decimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .canonical import Canonical
from .code import Code
from .positive_int import PositiveInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .canonical import Canonical

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime

try:
import pydantic.v1 as pydantic # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .data_requirement_sort_direction import DataRequirementSortDirection

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .code import Code
from .decimal import Decimal
from .distance_comparator import DistanceComparator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import typing_extensions

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .base_resource import BaseResource
from .code import Code
from .codeable_concept import CodeableConcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .attachment import Attachment
from .coding import Coding
from .extension import Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .codeable_concept import CodeableConcept
from .extension import Extension
from .period import Period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime
from ...core.datetime_utils import serialize_datetime
from .document_reference_relates_to_code import DocumentReferenceRelatesToCode
from .extension import Extension
from .reference import Reference
Expand Down
Loading
Loading