Skip to content

Commit 92b86a1

Browse files
authored
Merge pull request #21 from beda-software/python-implementation
Python implementation
2 parents 375879c + a45265a commit 92b86a1

40 files changed

Lines changed: 3150 additions & 907 deletions

.github/workflows/github-actions.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: github-actions
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches:
5+
- "*"
6+
tags-ignore:
7+
- "v*.*.*"
38
env:
49
BUILD_IMAGE: bedasoftware/fhirpath-extract:main
510
jobs:
6-
Build:
11+
build-and-test-fpml-server-ts:
712
runs-on: ubuntu-latest
813
steps:
914
- name: Copy repository
@@ -29,8 +34,8 @@ jobs:
2934
run: yarn test:e2e
3035
working-directory: ts/server
3136

32-
Publish:
33-
needs: Build
37+
publish-fpml-server-ts-to-dockerhub:
38+
needs: build-and-test-fpml-server-ts
3439
if: github.ref == 'refs/heads/main'
3540
runs-on: ubuntu-latest
3641
steps:
@@ -48,3 +53,6 @@ jobs:
4853
docker buildx build --platform linux/arm64,linux/amd64
4954
--push --tag ${{ env.BUILD_IMAGE }} .
5055
working-directory: ts/server
56+
57+
test-fpml-py:
58+
uses: ./.github/workflows/test-python.yml

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: publish
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
jobs:
7+
test-fpml-py:
8+
uses: ./.github/workflows/test-python.yml
9+
10+
publish-fpml-py-to-pypi:
11+
needs: test-fpml-py
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python 3.11
16+
uses: actions/setup-python@v3
17+
with:
18+
python-version: "3.11"
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install poetry
23+
- name: Build a binary wheel and a source tarball
24+
run: poetry --project=./python build
25+
- name: Publish package
26+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test-python.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: test-python
2+
on: [workflow_call]
3+
jobs:
4+
test-fpml-py:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
include:
9+
- python-version: 3.9
10+
- python-version: "3.10"
11+
- python-version: "3.11"
12+
- python-version: "3.12"
13+
- python-version: "3.13"
14+
env:
15+
PYTHON: ${{ matrix.python-version }}
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Python ${{ matrix.python-version }} sample
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install poetry
26+
poetry --project=./python install
27+
- name: Run lint
28+
run: poetry --project=./python run ruff check ./python
29+
- name: Run typecheck
30+
run: poetry --project=./python run mypy ./python
31+
- name: Run tests
32+
run: poetry --project=./python run pytest --cov

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ coverage
55
htmlcov
66
.vscode
77
.history
8+
.coverage
9+
python/dist

README.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,18 @@ that will be transformed into:
547547

548548
## Examples
549549

550-
See real-life examples of mappers for [FHIR](https://github.com/beda-software/FHIRPathMappingLanguage/blob/main/ts/server/src/utils/__data__/complex-example.fhir.yaml) and [Aidbox](https://github.com/beda-software/FHIRPathMappingLanguage/blob/main/ts/server/src/utils/__data__/complex-example.aidbox.yaml)
550+
See real-life examples of mappers for [FHIR](https://github.com/beda-software/FHIRPathMappingLanguage/blob/main/tests/__data__/complex-example.fhir.yaml) and [Aidbox](https://github.com/beda-software/FHIRPathMappingLanguage/blob/main/tests/__data__/complex-example.aidbox.yaml)
551551

552552
and other usage in [unit tests](https://github.com/beda-software/FHIRPathMappingLanguage/tree/main/ts/server/src/utils).
553553

554554
## Reference implementation
555555

556-
TypeScript implementation that supports all the specification is already available [in this repository](https://github.com/beda-software/FHIRPathMappingLanguage/tree/main/server).
556+
### TypeScript
557+
558+
TypeScript implementation that supports all the specification is already available [in this repository](https://github.com/beda-software/FHIRPathMappingLanguage/tree/main/ts/server).
557559
Also, it is packed into a [docker image](https://hub.docker.com/r/bedasoftware/fhirpath-extract) to use as a microservice.
558560

559-
### Usage
561+
#### Usage
560562

561563
POST /r4/parse-template
562564

@@ -577,7 +579,7 @@ POST /r4/parse-template
577579
}
578580
```
579581

580-
### Strict mode
582+
#### Strict mode
581583

582584
FHIRPath provides a way of accessing the `resource` variables without the percent sign. It potentially leads to the issues made by typos in the variable names.
583585

@@ -603,4 +605,46 @@ POST /r4/parse-template?strict=true
603605
"status": "completed"
604606
}
605607
}
606-
```
608+
```
609+
610+
### Python
611+
612+
Python implementation that supports all the specification is already available [in this repository](https://github.com/beda-software/FHIRPathMappingLanguage/tree/main/python).
613+
Also, it's available as a PyPI package under the name `fpml` and can be installed using
614+
```
615+
pip install fpml
616+
```
617+
618+
#### Usage
619+
620+
```python
621+
from fpml import resolve_template
622+
623+
624+
resource = {
625+
"resourceType": "QuestionnaireResponse",
626+
"status": "completed",
627+
"item": [
628+
{
629+
"linkId": "name",
630+
"answer": [
631+
{
632+
"valueString": "Name"
633+
}
634+
]
635+
}
636+
]
637+
}
638+
639+
template = {
640+
"resourceType": "Patient",
641+
"name": "{{ item.where(linkId='name').answer.valueString }}"
642+
}
643+
644+
context = {}
645+
646+
result = resolve_template(resource, template, context)
647+
648+
print(result)
649+
# {'resourceType': 'Patient', 'name': 'Name'}
650+
```
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydian import DROP, Mapper, get
1+
from pydian import get
22

33

44
def map(qr):

0 commit comments

Comments
 (0)