A small Flask-based FHIR extractor API for reading parquet FHIR resources and returning paginated results. Allows for filtration by patient, and field reduction.
Pull dependencies:
uv syncSet up parquet files. They should have a structure like this:
fhir_root/
├─ patient/
│ ├─ 1.parquet
├─ observation/
│ ├─ 1.parquet
│ ├─ 2.parquet
│ ├─ 3.parquet
├─ encounter/
│ ├─ 1.parquet
│ ├─ 2.parquet
Run query:
LOCAL_ROOT=/path/to/my/fhir_root/ python3 lambda/lambda.py --fhir_resource patient \
--body '{"patients": ["Patient/1"]}' \
--offset 0 --limit 50We provide a SAM template to deploy this code, and an example samconfig. Before deploying, you should have a trove of parquet files in S3 with the same structure as described above. After editing the example samconfig and uploading your parquets, you can deploy this to AWS:
sam build
sam deploy --config-file example_samconfig.toml --config-env dev --guidedThis repo consists of a SAM template that deploys a lambda backed REST API, and a small support ecosystem to provide data to that API. The key objects in this ecosystem are as follows:
- FHIRSourceBucket: a S3 bucket, lives outside this template. Where your athena data lives.
- FhirDataBucket: a S3 bucket. Where the template houses the FHIR data it queries and returns.
- FhirApi: Lambda function. The API itself. Reads from FhirDataBucket.
- Converter: Lambda function. Converts ndjsons that land in FhirDataBucket to parquets
- DataFetcher: Lambda function. Fetches data from FHIRSourceBucket via Athena queries and writes the resulting parquets to FhirDataBucket
curl -X POST http://127.0.0.1:5000/fhir/patient/ \
-H "Content-Type: application/json" \
-d '{}'curl -X POST http://127.0.0.1:5000/fhir/patient/count \
-H "Content-Type: application/json" \
-d '{}'curl -X POST http://127.0.0.1:5000/fhir/observation/ \
-H "Content-Type: application/json" \
-d '{"patients": ["Patient/1", "Patient/2"]}'curl -X POST http://127.0.0.1:5000/fhir/observation/count \
-H "Content-Type: application/json" \
-d '{"patients": ["Patient/1", "Patient/2"]}'curl -X POST http://127.0.0.1:5000/fhir/encounter/ \
-H "Content-Type: application/json" \
-d '{"patients": ["Patient/1"], "fields": ["id", "status", "code"]}'curl -X POST 'http://127.0.0.1:5000/fhir/condition/?offset=10&limit=5' \
-H "Content-Type: application/json" \
-d '{"patients": ["Patient/1"]}'