Skip to content
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
30 changes: 17 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,34 @@ on:
branches: [ "main" ]
types: [opened, synchronize, reopened, ready_for_review]


jobs:
test:
if: github.event.pull_request.draft == false
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
poetry-version: [1.8.2]
python-version: ["3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{matrix.python-version}}
poetry-version: ${{matrix.poetry-version}}
- name: Install package
run: |
poetry install --no-interaction
version: "latest"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --all-extras --dev

- name: Lint with Ruff
run: |
poetry run ruff format
poetry run ruff check
uv run ruff format
uv run ruff check
continue-on-error: true

- name: Run tests
run: |
poetry run pytest
run: uv run pytest
16 changes: 9 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11" # Use a version compatible with >=3.8,<3.12
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.2 # Match local version
python-version: "3.11"
- name: Bump version
run: poetry version $(git describe --tags --abbrev=0)
run: |
VERSION=$(git describe --tags --abbrev=0)
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version "${VERSION#v}"
- name: Build a binary wheel and a source tarball
run: poetry build
run: uv build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ We believe that every contribution, big or small, makes a difference. Thank you

## How to Contribute Code

This project uses `poetry` for dependency management. For more information see the [poetry documentation](https://python-poetry.org/docs/).
This project uses `uv` for dependency management. For more information see the [uv documentation](https://docs.astral.sh/uv/).

1. Fork the repository to your own GitHub account. For more details check out [github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo).

2. Clone the forked repository to your local machine.

3. Run `poetry install --with dev` to install all the necessary development dependencies.
3. Run `uv sync --all-extras --dev` to install all the necessary development dependencies.

4. Try running `poetry run pytest` to check that all is working as expected.
4. Try running `uv run pytest` to check that all is working as expected.

5. Create a new branch for your feature or bugfix.

Expand Down Expand Up @@ -72,12 +72,12 @@ This project uses `poetry` for dependency management. For more information see t

We use `Mkdocs` for our documentation site. To download the dependencies for documentation, run:
```shell
poetry install --with docs
uv sync --group docs
```

To preview the docs page in development:
```shell
poetry run mkdocs serve
uv run mkdocs serve
```
#### Writing Clear Documentation

Expand Down
2 changes: 1 addition & 1 deletion healthchain/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def run_file(filename):
try:
result = subprocess.run(["poetry", "run", "python", filename], check=True)
result = subprocess.run(["uv", "run", "python", filename], check=True)
print(result.stdout)
except subprocess.CalledProcessError as e:
print(f"An error occurred while trying to run the file: {e}")
Expand Down
94 changes: 80 additions & 14 deletions healthchain/io/containers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,36 +318,102 @@ def problem_list(self) -> List[Condition]:
return self.get_resources("Condition")

@problem_list.setter
def problem_list(self, conditions: List[Condition]) -> None:
# TODO: should make this behaviour more explicit whether it's adding or replacing
"""Set problem list in the bundle."""
self.add_resources(conditions, "Condition")
def problem_list(self, value: Union[List[Condition], Dict[str, Any]]) -> None:
"""
Set problem list in the bundle.

By default, this adds the provided conditions to any existing conditions in the bundle.
To replace existing conditions instead, pass a dictionary with 'resources' and 'replace' keys.

Args:
value: Either a list of Condition resources (adds by default) or a dict with:
- 'resources': List of Condition resources
- 'replace': bool, whether to replace existing resources (default: False)

Examples:
>>> # Add to existing conditions (default behavior)
>>> fhir.problem_list = [condition1, condition2]
>>> # Replace existing conditions
>>> fhir.problem_list = {'resources': [condition1], 'replace': True}
"""
if isinstance(value, dict):
resources = value.get("resources", [])
replace = value.get("replace", False)
else:
resources = value
replace = False

self.add_resources(resources, "Condition", replace=replace)

@property
def medication_list(self) -> List[MedicationStatement]:
"""Get medication list from the bundle."""
return self.get_resources("MedicationStatement")

@medication_list.setter
def medication_list(self, medications: List[MedicationStatement]) -> None:
"""Set medication list in the bundle.
Medication statements are stored as MedicationStatement resources in the bundle.
See: https://www.hl7.org/fhir/medicationstatement.html
def medication_list(
self, value: Union[List[MedicationStatement], Dict[str, Any]]
) -> None:
"""
self.add_resources(medications, "MedicationStatement")
Set medication list in the bundle.

By default, this adds the provided medications to any existing medications in the bundle.
To replace existing medications instead, pass a dictionary with 'resources' and 'replace' keys.

Args:
value: Either a list of MedicationStatement resources (adds by default) or a dict with:
- 'resources': List of MedicationStatement resources
- 'replace': bool, whether to replace existing resources (default: False)

Examples:
>>> # Add to existing medications (default behavior)
>>> fhir.medication_list = [medication1, medication2]
>>> # Replace existing medications
>>> fhir.medication_list = {'resources': [medication1], 'replace': True}
"""
if isinstance(value, dict):
resources = value.get("resources", [])
replace = value.get("replace", False)
else:
resources = value
replace = False

self.add_resources(resources, "MedicationStatement", replace=replace)

@property
def allergy_list(self) -> List[AllergyIntolerance]:
"""Get allergy list from the bundle."""
return self.get_resources("AllergyIntolerance")

@allergy_list.setter
def allergy_list(self, allergies: List[AllergyIntolerance]) -> None:
"""Set allergy list in the bundle.
Allergy intolerances are stored as AllergyIntolerance resources in the bundle.
See: https://www.hl7.org/fhir/allergyintolerance.html
def allergy_list(
self, value: Union[List[AllergyIntolerance], Dict[str, Any]]
) -> None:
"""
self.add_resources(allergies, "AllergyIntolerance")
Set allergy list in the bundle.

By default, this adds the provided allergies to any existing allergies in the bundle.
To replace existing allergies instead, pass a dictionary with 'resources' and 'replace' keys.

Args:
value: Either a list of AllergyIntolerance resources (adds by default) or a dict with:
- 'resources': List of AllergyIntolerance resources
- 'replace': bool, whether to replace existing resources (default: False)

Examples:
>>> # Add to existing allergies (default behavior)
>>> fhir.allergy_list = [allergy1, allergy2]
>>> # Replace existing allergies
>>> fhir.allergy_list = {'resources': [allergy1], 'replace': True}
"""
if isinstance(value, dict):
resources = value.get("resources", [])
replace = value.get("replace", False)
else:
resources = value
replace = False

self.add_resources(resources, "AllergyIntolerance", replace=replace)

def get_prefetch_resources(self, key: str) -> List[Any]:
"""Get resources of a specific type from the prefetch bundle."""
Expand Down
Loading