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

fhirpy client example #4

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

fhirpy client example #4

wants to merge 9 commits into from

Conversation

krvital
Copy link

@krvital krvital commented Dec 6, 2024

No description provided.


This example shows how to use the [fhir-py client](https://github.com/beda-software/fhir-py "fhir-py") with an Aidbox instance, demonstrating the Python SDK client in action.

Here, we provide several options for using the fhir-py SDK, including basic usage and advanced typing features. The examples start with the simplest solution, which does not include typings, and incrementally incorporate features related to typings.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Here, we provide several options for using the fhir-py SDK, including basic usage and advanced typing features. The examples start with the simplest solution, which does not include typings, and incrementally incorporate features related to typings.
In the example we demonstrate a several ways to implement import patient data from CSV file in Python. We describe it in the following steps:
1. Setup Aidbox Instance
1. Install [fhir-py](https://github.com/beda-software/fhir-py).
1. Use [fhir-py](https://github.com/beda-software/fhir-py):
1. with raw data (dictionaries and lists),
1. with manually defined dataclasses for FHIR Resources,
1. with generated dataclasses for FHIR Resources by [fhir-py-types](https://github.com/beda-software/fhir-py-types) from StructureDefinitions
1. (recommended) with generated dataclasses for FHIR Resources by [fhir-schema-codegen](https://github.com/fhir-schema/fhir-schema-codegen) from FHIR Schemas.

Comment on lines +63 to +65
#### Detailed example

For a more detailed example of how to use fhir-py client with raw data, including working code snippets, check out the [fhirpy_raw_data.py](fhirpy_raw_data.py)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### Detailed example
For a more detailed example of how to use fhir-py client with raw data, including working code snippets, check out the [fhirpy_raw_data.py](fhirpy_raw_data.py)
See full CSV import example: [fhirpy_raw_data.py](fhirpy_raw_data.py)

@@ -0,0 +1,122 @@
#####################################################################
# Use <https://github.com/beda-software/fhir-py>. With custom data models
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to be more similar to README text.

#### Installation

``` shell
poetry add [email protected]
Copy link
Contributor

Choose a reason for hiding this comment

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

And we need to explain how to generate dataclasses. Ideally, it will be nice to have similar structure for that and next section.

Comment on lines +163 to +167
#### Detailed example

For a more detailed example of how to use `fhirpy-types-r4b` in fhir-py client, check out the [fhirpy_fhirtypes.py](fhirpy_fhirtypes.py)


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### Detailed example
For a more detailed example of how to use `fhirpy-types-r4b` in fhir-py client, check out the [fhirpy_fhirtypes.py](fhirpy_fhirtypes.py)
See CSV import example: [fhirpy_fhirtypes.py](fhirpy_fhirtypes.py)

Comment on lines +79 to +80
- Be iterable
- Implement ResourceProtocol interface
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Be iterable
- Implement ResourceProtocol interface
- Be iterable (implemented by inheritance from `dict`).
- Implement `ResourceProtocol` interface (defined in fhir-py).


- Be iterable
- Implement ResourceProtocol interface

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Usage dataclasses for FHIR Resource representation allow programmers to use autocomplete and type checking. This approach allows user to have full control (including custom validations and hiding unused resource elements) but requires to write a lot of boilerplate code.

Comment on lines +117 to +119
#### Detailed example

For a more detailed example of how to write custom data models and use them in fhir-py client, check out the [fhirpy_custom_models.py](fhirpy_custom_models.py)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### Detailed example
For a more detailed example of how to write custom data models and use them in fhir-py client, check out the [fhirpy_custom_models.py](fhirpy_custom_models.py)
See full CSV import example: [fhirpy_custom_models.py](fhirpy_custom_models.py)

Comment on lines +223 to +225
#### Detailed Example

For a more detailed example of how to use `fhir-schema-codegen` generated data models in fhir-py client, check out the [fhirpy_fhir_schema_codegen.py](fhirpy_fhir_schema_codegen.py)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### Detailed Example
For a more detailed example of how to use `fhir-schema-codegen` generated data models in fhir-py client, check out the [fhirpy_fhir_schema_codegen.py](fhirpy_fhir_schema_codegen.py)
See full CSV import example: [fhirpy_fhir_schema_codegen.py](fhirpy_fhir_schema_codegen.py)


```sh
# generate FHIR data models
fscg generate --generator python --output generated --package hl7.fhir.r4.core:4.0.1
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also generate classes for our custom resources? E.g. AidboxSubscriptionTopic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants