omop-semantic-projection 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omop_semantic_projection-0.1.0/.githooks/pre-commit +36 -0
- omop_semantic_projection-0.1.0/.github/CONTRIBUTING.md +27 -0
- omop_semantic_projection-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +66 -0
- omop_semantic_projection-0.1.0/.github/ISSUE_TEMPLATE/config.yml +5 -0
- omop_semantic_projection-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +32 -0
- omop_semantic_projection-0.1.0/.github/ISSUE_TEMPLATE/not_working.yml +65 -0
- omop_semantic_projection-0.1.0/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- omop_semantic_projection-0.1.0/.github/release-drafter.yml +31 -0
- omop_semantic_projection-0.1.0/.github/workflows/ci.yml +10 -0
- omop_semantic_projection-0.1.0/.github/workflows/merge.yml +13 -0
- omop_semantic_projection-0.1.0/.github/workflows/publish.yml +21 -0
- omop_semantic_projection-0.1.0/.gitignore +15 -0
- omop_semantic_projection-0.1.0/AGENTS.md +13 -0
- omop_semantic_projection-0.1.0/CLAUDE.md +1 -0
- omop_semantic_projection-0.1.0/PKG-INFO +67 -0
- omop_semantic_projection-0.1.0/README.md +51 -0
- omop_semantic_projection-0.1.0/docs/usage.md +86 -0
- omop_semantic_projection-0.1.0/pyproject.toml +54 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/__init__.py +5 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/config.py +55 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/plugin.py +62 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/py.typed +0 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/registry_audit.py +76 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/service.py +85 -0
- omop_semantic_projection-0.1.0/src/omop_semantic_projection/tools.py +65 -0
- omop_semantic_projection-0.1.0/tests/fixtures/projection_shapes.yaml +65 -0
- omop_semantic_projection-0.1.0/tests/test_live_mcp.py +261 -0
- omop_semantic_projection-0.1.0/tests/test_oracle.py +119 -0
- omop_semantic_projection-0.1.0/tests/test_plugin_contract.py +80 -0
- omop_semantic_projection-0.1.0/tests/test_projection_tools.py +256 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Canonical CAVA pre-commit hook: keeps uv.lock in sync with pyproject.toml.
|
|
3
|
+
#
|
|
4
|
+
# If pyproject.toml is staged, finds the specific dependency line(s) that
|
|
5
|
+
# changed (added, removed, or had their version spec edited) and refreshes
|
|
6
|
+
# only those packages in uv.lock via `uv lock --upgrade-package`. Does not
|
|
7
|
+
# touch any other package -- this is a targeted sync, not a blanket
|
|
8
|
+
# `uv lock`, so it never pulls in an unrelated upstream release.
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
|
|
11
|
+
if ! git diff --cached --name-only | grep -q '^pyproject\.toml$'; then
|
|
12
|
+
exit 0
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
if ! command -v uv >/dev/null 2>&1; then
|
|
16
|
+
echo "pre-commit: uv not found on PATH, skipping uv.lock sync" >&2
|
|
17
|
+
exit 0
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
changed_names=$(git diff --cached -- pyproject.toml \
|
|
21
|
+
| sed -nE 's/^[+-][[:space:]]*"([A-Za-z0-9][A-Za-z0-9._-]*).*/\1/p' \
|
|
22
|
+
| sort -u)
|
|
23
|
+
|
|
24
|
+
if [ -z "$changed_names" ]; then
|
|
25
|
+
exit 0
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
upgrade_args=()
|
|
29
|
+
while IFS= read -r name; do
|
|
30
|
+
upgrade_args+=(--upgrade-package "$name")
|
|
31
|
+
done <<< "$changed_names"
|
|
32
|
+
|
|
33
|
+
echo "pre-commit: syncing uv.lock for changed dependencies:"
|
|
34
|
+
echo "$changed_names" | sed 's/^/ - /'
|
|
35
|
+
uv lock "${upgrade_args[@]}"
|
|
36
|
+
git add uv.lock
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Development setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
uv sync --all-extras --dev
|
|
7
|
+
uv run pytest -q
|
|
8
|
+
uv run ruff check .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Opening a pull request
|
|
12
|
+
|
|
13
|
+
1. Apply **exactly one** label before merging:
|
|
14
|
+
|
|
15
|
+
| Label | When to use |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `breaking` | Public API change, backward-incompatible |
|
|
18
|
+
| `feature` | New functionality, backward-compatible |
|
|
19
|
+
| `fix` | Bug fix |
|
|
20
|
+
| `dependencies` | Dependency version update |
|
|
21
|
+
| `chore` | CI changes, refactoring, test additions, docs — anything that does not affect the public-facing package. Bypasses the label gate; excluded from the changelog and does not bump the version. |
|
|
22
|
+
|
|
23
|
+
2. When merging (squash), write a clear extended description in the merge dialog. That text — not the PR's opening description — becomes the changelog entry for this change. Leave it blank for `chore` PRs.
|
|
24
|
+
|
|
25
|
+
## Versioning and releases
|
|
26
|
+
|
|
27
|
+
Versions are derived from git tags; there is no version string in any source file. Releases are triggered by a maintainer publishing the standing draft release on the repository's Releases page. There is no automated commit-back to `main`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
name: "🐞 Bug Report"
|
|
2
|
+
description: Report a reproducible bug.
|
|
3
|
+
type: "Bug"
|
|
4
|
+
body:
|
|
5
|
+
- type: checkboxes
|
|
6
|
+
attributes:
|
|
7
|
+
label: Pre-flight
|
|
8
|
+
options:
|
|
9
|
+
- label: I searched existing issues and this is not a duplicate.
|
|
10
|
+
required: true
|
|
11
|
+
|
|
12
|
+
- type: textarea
|
|
13
|
+
id: summary
|
|
14
|
+
attributes:
|
|
15
|
+
label: Summary
|
|
16
|
+
description: One or two sentences describing the bug.
|
|
17
|
+
validations:
|
|
18
|
+
required: true
|
|
19
|
+
|
|
20
|
+
- type: textarea
|
|
21
|
+
id: reproduction
|
|
22
|
+
attributes:
|
|
23
|
+
label: Reproduction
|
|
24
|
+
description: Steps and/or a minimal code example that reproduces the issue. Wrap code in triple backticks.
|
|
25
|
+
placeholder: |
|
|
26
|
+
1. Import X and call Y with Z
|
|
27
|
+
2. Observe error
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
# minimal example
|
|
31
|
+
```
|
|
32
|
+
validations:
|
|
33
|
+
required: true
|
|
34
|
+
|
|
35
|
+
- type: textarea
|
|
36
|
+
id: actual
|
|
37
|
+
attributes:
|
|
38
|
+
label: Actual behaviour
|
|
39
|
+
validations:
|
|
40
|
+
required: true
|
|
41
|
+
|
|
42
|
+
- type: textarea
|
|
43
|
+
id: expected
|
|
44
|
+
attributes:
|
|
45
|
+
label: Expected behaviour
|
|
46
|
+
validations:
|
|
47
|
+
required: true
|
|
48
|
+
|
|
49
|
+
- type: textarea
|
|
50
|
+
id: logs
|
|
51
|
+
attributes:
|
|
52
|
+
label: Error output
|
|
53
|
+
description: Full traceback if applicable. Formatted automatically.
|
|
54
|
+
render: python-traceback
|
|
55
|
+
|
|
56
|
+
- type: textarea
|
|
57
|
+
id: system
|
|
58
|
+
attributes:
|
|
59
|
+
label: System info
|
|
60
|
+
description: |
|
|
61
|
+
Run this in your environment and paste the output:
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
python <(curl -s https://raw.githubusercontent.com/AustralianCancerDataNetwork/cava-devops/main/scripts/cava_system_info.py)
|
|
65
|
+
```
|
|
66
|
+
render: shell
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: "🚀 Feature Request"
|
|
2
|
+
description: Propose a new feature or enhancement.
|
|
3
|
+
type: "Feature"
|
|
4
|
+
body:
|
|
5
|
+
- type: checkboxes
|
|
6
|
+
attributes:
|
|
7
|
+
label: Pre-flight
|
|
8
|
+
options:
|
|
9
|
+
- label: I searched existing issues and this has not been requested before.
|
|
10
|
+
required: true
|
|
11
|
+
|
|
12
|
+
- type: textarea
|
|
13
|
+
id: problem
|
|
14
|
+
attributes:
|
|
15
|
+
label: Problem or motivation
|
|
16
|
+
description: What are you trying to do that you currently cannot?
|
|
17
|
+
validations:
|
|
18
|
+
required: true
|
|
19
|
+
|
|
20
|
+
- type: textarea
|
|
21
|
+
id: proposal
|
|
22
|
+
attributes:
|
|
23
|
+
label: Proposed solution
|
|
24
|
+
description: How would you like this to work?
|
|
25
|
+
validations:
|
|
26
|
+
required: true
|
|
27
|
+
|
|
28
|
+
- type: textarea
|
|
29
|
+
id: alternatives
|
|
30
|
+
attributes:
|
|
31
|
+
label: Alternatives considered
|
|
32
|
+
description: Other approaches you considered and why you ruled them out.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
name: "❗ Something is not working"
|
|
2
|
+
description: Something behaves unexpectedly but you are not sure if it is a bug.
|
|
3
|
+
body:
|
|
4
|
+
- type: checkboxes
|
|
5
|
+
attributes:
|
|
6
|
+
label: Pre-flight
|
|
7
|
+
options:
|
|
8
|
+
- label: I searched existing issues for this problem.
|
|
9
|
+
required: true
|
|
10
|
+
|
|
11
|
+
- type: textarea
|
|
12
|
+
id: summary
|
|
13
|
+
attributes:
|
|
14
|
+
label: Problem summary
|
|
15
|
+
description: 1-2 sentences describing what is not working.
|
|
16
|
+
validations:
|
|
17
|
+
required: true
|
|
18
|
+
|
|
19
|
+
- type: textarea
|
|
20
|
+
id: reproduction
|
|
21
|
+
attributes:
|
|
22
|
+
label: Reproduction
|
|
23
|
+
description: Steps and/or a minimal code example. Wrap code in triple backticks.
|
|
24
|
+
placeholder: |
|
|
25
|
+
1. Import X and call Y with Z
|
|
26
|
+
2. Observe unexpected behaviour
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
# minimal example
|
|
30
|
+
```
|
|
31
|
+
validations:
|
|
32
|
+
required: true
|
|
33
|
+
|
|
34
|
+
- type: textarea
|
|
35
|
+
id: actual
|
|
36
|
+
attributes:
|
|
37
|
+
label: Actual outcome
|
|
38
|
+
validations:
|
|
39
|
+
required: true
|
|
40
|
+
|
|
41
|
+
- type: textarea
|
|
42
|
+
id: expected
|
|
43
|
+
attributes:
|
|
44
|
+
label: Expected outcome
|
|
45
|
+
validations:
|
|
46
|
+
required: true
|
|
47
|
+
|
|
48
|
+
- type: textarea
|
|
49
|
+
id: logs
|
|
50
|
+
attributes:
|
|
51
|
+
label: Error messages
|
|
52
|
+
description: Full traceback if applicable. Formatted automatically.
|
|
53
|
+
render: python-traceback
|
|
54
|
+
|
|
55
|
+
- type: textarea
|
|
56
|
+
id: system
|
|
57
|
+
attributes:
|
|
58
|
+
label: System info
|
|
59
|
+
description: |
|
|
60
|
+
Run this in your environment and paste the output:
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
python <(curl -s https://raw.githubusercontent.com/AustralianCancerDataNetwork/cava-devops/main/scripts/cava_system_info.py)
|
|
64
|
+
```
|
|
65
|
+
render: shell
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
## Summary
|
|
2
|
+
|
|
3
|
+
<!-- What does this PR do? This text becomes the changelog entry — write it for a reader who will see it months from now, not for the reviewer reading the diff. Leave blank for chore PRs. -->
|
|
4
|
+
|
|
5
|
+
## Checklist
|
|
6
|
+
|
|
7
|
+
- [ ] Applied exactly one label (`breaking`, `feature`, `fix`, `dependencies`, or `chore`)
|
|
8
|
+
- [ ] Tests pass locally (`uv run pytest -q`)
|
|
9
|
+
- [ ] Lint passes (`uv run ruff check .`)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name-template: 'v$RESOLVED_VERSION'
|
|
2
|
+
tag-template: 'v$RESOLVED_VERSION'
|
|
3
|
+
commitish: main
|
|
4
|
+
|
|
5
|
+
categories:
|
|
6
|
+
- title: Breaking Changes
|
|
7
|
+
labels: ['breaking']
|
|
8
|
+
- title: Features
|
|
9
|
+
labels: ['feature']
|
|
10
|
+
- title: Fixes
|
|
11
|
+
labels: ['fix']
|
|
12
|
+
- title: Dependencies
|
|
13
|
+
labels: ['dependencies']
|
|
14
|
+
|
|
15
|
+
template: |
|
|
16
|
+
$CHANGES
|
|
17
|
+
|
|
18
|
+
change-template: '- **$TITLE** (#$NUMBER) @$AUTHOR'
|
|
19
|
+
|
|
20
|
+
version-resolver:
|
|
21
|
+
major:
|
|
22
|
+
labels: ['breaking']
|
|
23
|
+
minor:
|
|
24
|
+
labels: ['feature']
|
|
25
|
+
patch:
|
|
26
|
+
labels: ['fix', 'dependencies']
|
|
27
|
+
default: patch
|
|
28
|
+
|
|
29
|
+
exclude-labels: ['chore']
|
|
30
|
+
|
|
31
|
+
autolabeler: []
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches: [main]
|
|
5
|
+
types: [opened, synchronize, reopened, labeled, unlabeled]
|
|
6
|
+
jobs:
|
|
7
|
+
label-gate:
|
|
8
|
+
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/label-gate.yml@main
|
|
9
|
+
build-test:
|
|
10
|
+
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/build-test.yml@main
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
name: Release Update
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
types: [closed]
|
|
5
|
+
branches: [main]
|
|
6
|
+
permissions:
|
|
7
|
+
contents: write
|
|
8
|
+
pull-requests: read
|
|
9
|
+
jobs:
|
|
10
|
+
draft:
|
|
11
|
+
if: github.event.pull_request.merged == true
|
|
12
|
+
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/release-drafter.yml@main
|
|
13
|
+
secrets: inherit
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags: ['v*']
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/publish.yml@main
|
|
8
|
+
publish:
|
|
9
|
+
# Inline: PyPI OIDC checks job_workflow_ref, which must point to this file.
|
|
10
|
+
# Moving pypa/gh-action-pypi-publish into cava-devops would break the trusted publisher.
|
|
11
|
+
needs: build
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
environment:
|
|
16
|
+
name: pypi
|
|
17
|
+
url: https://pypi.org/p/omop-semantic-projection
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/download-artifact@v4
|
|
20
|
+
with: { name: dist, path: dist/ }
|
|
21
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Agent guidance
|
|
2
|
+
|
|
3
|
+
Keep this plugin aligned with the supported Groundworkers plugin contract. Check the Groundworkers version range in `pyproject.toml` before relying on a host API. Do not edit Groundworkers from this repository; make a separate host change when one is required.
|
|
4
|
+
|
|
5
|
+
## If you add query embeddings or vector search
|
|
6
|
+
|
|
7
|
+
- Keep MCP tools that encode queries asynchronous. Use `await model_backend.async_embed_texts([text], role=EmbeddingRole.QUERY)`, then pass the vector to the synchronous reader lookup. Do not call synchronous embedding APIs from the MCP event loop, or work around that with `asyncio.run` or a worker thread.
|
|
8
|
+
- Resolve embedding model records from the relevant vector-store registry. Use the registered record's model, provider, metric, dimensions, and index configuration. Before live encoding, confirm the backend matches the registered model and provider. If the live model is not registered, raise `NOT_FOUND`; never fall back to another registered model. Stored-vector queries against the host store must use a vector from that same registered model and provider.
|
|
9
|
+
- Open and close **plugin-owned** DuckDB stores per operation. Never close what `context.embedding_backend_factory()` returns: it is the host's shared reader, and the host owns its lifecycle. Make sure setup commands can open a writer after readiness or a query has run.
|
|
10
|
+
- Report backend and store failures with public `GroundworkersError` codes. Use `embedding_store_error` to map store failures. Reserve empty-result responses for valid queries that found no match.
|
|
11
|
+
- Keep embedding tests isolated from user data. Exercise registered tools on a running event loop with an async-only fake backend whose synchronous method raises; cover missing and incompatible model records; and verify a writer can acquire an isolated DuckDB file after a query. Gate real-backend integration tests behind an explicit opt-in config.
|
|
12
|
+
|
|
13
|
+
When Groundworkers documentation and implementation differ, follow the documented contract for the supported version and report the discrepancy. Do not copy private host helpers into the plugin as a substitute for a supported API.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: omop-semantic-projection
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Projects source records into OMOP CDM row fragments through Groundworkers.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: groundworkers<1,>=0.12
|
|
7
|
+
Requires-Dist: oa-configurator<3,>=2.1
|
|
8
|
+
Requires-Dist: omop-semantics<1,>=0.11
|
|
9
|
+
Requires-Dist: pydantic<3,>=2
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: groundworkers[duckdb]<1,>=0.12; extra == 'dev'
|
|
12
|
+
Requires-Dist: pytest<10,>=9; extra == 'dev'
|
|
13
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
14
|
+
Requires-Dist: ty>=0.0.59; extra == 'dev'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# OMOP Semantic Projection
|
|
18
|
+
|
|
19
|
+
OMOP Semantic Projection adds read-only tools to Groundworkers. Give it a record whose concepts
|
|
20
|
+
have already been mapped and a binding that connects source keys to a shape. It returns OMOP CDM
|
|
21
|
+
row fragments, links, and validation results. Your loader assigns IDs and inserts the rows.
|
|
22
|
+
|
|
23
|
+
## Tools
|
|
24
|
+
|
|
25
|
+
| Tool | Use |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `semantic_list_shapes` | List effective shapes and the roles, context and code groups each binding needs. |
|
|
28
|
+
| `semantic_check_binding` | Check a binding and its fixed concepts without projecting a record. |
|
|
29
|
+
| `semantic_project` | Apply one binding to one record and return the projection result. |
|
|
30
|
+
|
|
31
|
+
The `semantic_*` prefix is a deliberate exception to the Groundworkers plugin-name convention.
|
|
32
|
+
It preserves the existing `semantic_project` name.
|
|
33
|
+
|
|
34
|
+
## Quick start
|
|
35
|
+
|
|
36
|
+
Install `omop-semantic-projection` in the environment that runs Groundworkers and restart the
|
|
37
|
+
server. For a DuckDB CDM, install Groundworkers with its `duckdb` extra. The packaged shapes are
|
|
38
|
+
available with the existing Groundworkers configuration.
|
|
39
|
+
|
|
40
|
+
Call `semantic_project` with these arguments to project a numeric measurement.
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"binding": {
|
|
45
|
+
"shape": "numeric_measurement",
|
|
46
|
+
"roles": {"concept": "spirometry/test", "value": "spirometry/result"}
|
|
47
|
+
},
|
|
48
|
+
"record": {"spirometry/test": 3024653, "spirometry/result": "2.25"}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For a site catalogue, set `site_catalogues` in `[tools.omop_semantic_projection]`. Put named
|
|
53
|
+
maps under `[tools.omop_semantic_projection.external_maps]` as inline tables or paths to JSON
|
|
54
|
+
objects. Relative paths are resolved from the stack TOML's directory. See the configuration and
|
|
55
|
+
diagnosis example in the [usage guide](docs/usage.md).
|
|
56
|
+
|
|
57
|
+
## Contract owners
|
|
58
|
+
|
|
59
|
+
| Package | Contract |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `omop-semantics` | Shape catalogues, `ShapeBinding`, `ProjectionResult`, registry, and projection rules. |
|
|
62
|
+
| `groundworkers` | Plugin hosting, MCP errors, and routed vocabulary reads. |
|
|
63
|
+
| `omop-semantic-projection` | The MCP tools, site catalogue and map configuration, and vocabulary oracle adapter. |
|
|
64
|
+
|
|
65
|
+
Python integrations can also import `ProjectionVocabularyOracle` and `build_projection_oracle`
|
|
66
|
+
from `omop_semantic_projection`. The builder audits the supplied registry before returning an
|
|
67
|
+
oracle for an omop-semantics `ShapeRuntime`.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# OMOP Semantic Projection
|
|
2
|
+
|
|
3
|
+
OMOP Semantic Projection adds read-only tools to Groundworkers. Give it a record whose concepts
|
|
4
|
+
have already been mapped and a binding that connects source keys to a shape. It returns OMOP CDM
|
|
5
|
+
row fragments, links, and validation results. Your loader assigns IDs and inserts the rows.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Use |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `semantic_list_shapes` | List effective shapes and the roles, context and code groups each binding needs. |
|
|
12
|
+
| `semantic_check_binding` | Check a binding and its fixed concepts without projecting a record. |
|
|
13
|
+
| `semantic_project` | Apply one binding to one record and return the projection result. |
|
|
14
|
+
|
|
15
|
+
The `semantic_*` prefix is a deliberate exception to the Groundworkers plugin-name convention.
|
|
16
|
+
It preserves the existing `semantic_project` name.
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
Install `omop-semantic-projection` in the environment that runs Groundworkers and restart the
|
|
21
|
+
server. For a DuckDB CDM, install Groundworkers with its `duckdb` extra. The packaged shapes are
|
|
22
|
+
available with the existing Groundworkers configuration.
|
|
23
|
+
|
|
24
|
+
Call `semantic_project` with these arguments to project a numeric measurement.
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"binding": {
|
|
29
|
+
"shape": "numeric_measurement",
|
|
30
|
+
"roles": {"concept": "spirometry/test", "value": "spirometry/result"}
|
|
31
|
+
},
|
|
32
|
+
"record": {"spirometry/test": 3024653, "spirometry/result": "2.25"}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For a site catalogue, set `site_catalogues` in `[tools.omop_semantic_projection]`. Put named
|
|
37
|
+
maps under `[tools.omop_semantic_projection.external_maps]` as inline tables or paths to JSON
|
|
38
|
+
objects. Relative paths are resolved from the stack TOML's directory. See the configuration and
|
|
39
|
+
diagnosis example in the [usage guide](docs/usage.md).
|
|
40
|
+
|
|
41
|
+
## Contract owners
|
|
42
|
+
|
|
43
|
+
| Package | Contract |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `omop-semantics` | Shape catalogues, `ShapeBinding`, `ProjectionResult`, registry, and projection rules. |
|
|
46
|
+
| `groundworkers` | Plugin hosting, MCP errors, and routed vocabulary reads. |
|
|
47
|
+
| `omop-semantic-projection` | The MCP tools, site catalogue and map configuration, and vocabulary oracle adapter. |
|
|
48
|
+
|
|
49
|
+
Python integrations can also import `ProjectionVocabularyOracle` and `build_projection_oracle`
|
|
50
|
+
from `omop_semantic_projection`. The builder audits the supplied registry before returning an
|
|
51
|
+
oracle for an omop-semantics `ShapeRuntime`.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Project records with Groundworkers
|
|
2
|
+
|
|
3
|
+
## Configure site catalogues and maps
|
|
4
|
+
|
|
5
|
+
Install the plugin alongside Groundworkers. The plugin uses the host's configured vocabulary
|
|
6
|
+
connection and performs a registry audit at startup. Audit warnings appear in the server log.
|
|
7
|
+
|
|
8
|
+
Add any site catalogues in the order you want them loaded. The packaged omop-semantics catalogue
|
|
9
|
+
loads first. When two layers define the same shape, the later definition replaces the whole
|
|
10
|
+
earlier shape. Restart Groundworkers after editing a catalogue or map.
|
|
11
|
+
|
|
12
|
+
This stack TOML fragment loads network and site catalogues and configures two named maps.
|
|
13
|
+
|
|
14
|
+
```toml
|
|
15
|
+
[tools.omop_semantic_projection]
|
|
16
|
+
site_catalogues = ["catalogues/network.yaml", "catalogues/site.yaml"]
|
|
17
|
+
|
|
18
|
+
[tools.omop_semantic_projection.external_maps]
|
|
19
|
+
diagnosis-status = "maps/diagnosis-status.json"
|
|
20
|
+
severity-score = { mild = 1, severe = 3 }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Each name matches an `external_map` reference in a shape. The file
|
|
24
|
+
`maps/diagnosis-status.json` contains a JSON object such as the one below. Keep source codes as
|
|
25
|
+
strings. Use integer concept IDs for concept maps and finite numbers for numeric maps.
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{"principal": 32902, "secondary": 32908}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Absolute paths and paths starting with `~` are supported. Relative catalogue and map paths start
|
|
32
|
+
at the directory containing the stack TOML. If a file or shape cannot be loaded, Groundworkers
|
|
33
|
+
keeps serving its other tools. Use `groundworkers --describe` with the server's configuration to
|
|
34
|
+
check whether the plugin started, then consult the server log for the file and the error.
|
|
35
|
+
|
|
36
|
+
## Send a record
|
|
37
|
+
|
|
38
|
+
1. Call `semantic_list_shapes` with `{}`. Each entry lists the shape name, its roles and context,
|
|
39
|
+
which of those are optional, and the expected code groups.
|
|
40
|
+
2. Create a binding. Map a role or context name to a key in your record. A concept position can
|
|
41
|
+
also take `{"fixed": {"concept": "value_set.unit.label"}}`. Under `codes`, supply the
|
|
42
|
+
source-code strings for each code group. Call `semantic_check_binding` with your `binding`
|
|
43
|
+
to check this wiring and any available vocabulary checks for fixed concepts.
|
|
44
|
+
3. Call `semantic_project` with the binding and one record. Date values use `YYYY-MM-DD`.
|
|
45
|
+
|
|
46
|
+
This call uses `cancer_diagnosis_with_tumour_size` from the omop-semantics worked example
|
|
47
|
+
catalogue. To follow the example, include that catalogue in `site_catalogues` and configure
|
|
48
|
+
its `diagnosis-status` map as shown above.
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"binding": {
|
|
53
|
+
"shape": "cancer_diagnosis_with_tumour_size",
|
|
54
|
+
"roles": {"diagnosis": "dx_concept", "size_test": "size_concept", "size": "tumour_size"},
|
|
55
|
+
"context": {"visit_date": "visit_date", "visit": "visit_id", "status": "dx_status", "size_unit": "size_unit"}
|
|
56
|
+
},
|
|
57
|
+
"record": {
|
|
58
|
+
"dx_concept": 4112853,
|
|
59
|
+
"visit_date": "2026-03-04",
|
|
60
|
+
"visit_id": 1207,
|
|
61
|
+
"dx_status": "principal",
|
|
62
|
+
"size_concept": 3018102,
|
|
63
|
+
"tumour_size": 2.4,
|
|
64
|
+
"size_unit": 8582
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Read the result
|
|
70
|
+
|
|
71
|
+
`semantic_project` returns the omop-semantics `ProjectionResult` as JSON. The example returns a
|
|
72
|
+
condition, a measurement that describes it, and a link whose target is the local `diagnosis`
|
|
73
|
+
row. The result records the supplying layer in `shape_source` and stores the SHA-256 digest of
|
|
74
|
+
each consulted map in `maps`.
|
|
75
|
+
|
|
76
|
+
| Status | Meaning |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `ok` | All required output was produced. Read any issues for optional fields or rows. |
|
|
79
|
+
| `partial` | Required input or output is missing. |
|
|
80
|
+
| `suppressed` | The shape's rules skipped all rows. |
|
|
81
|
+
| `invalid` | A record value, policy, or check failed. |
|
|
82
|
+
|
|
83
|
+
Read `constraint_checks` for vocabulary results. When a runtime has no vocabulary oracle,
|
|
84
|
+
checks that need one are marked `deferred`. A binding error returns `INVALID_INPUT` with issue
|
|
85
|
+
codes and binding keys. For more detail, call `semantic_check_binding`. Typed Python clients
|
|
86
|
+
can import `ShapeBinding` and `ProjectionResult` from `omop_semantics.projection`.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "omop-semantic-projection"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "Projects source records into OMOP CDM row fragments through Groundworkers."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"groundworkers>=0.12,<1",
|
|
9
|
+
"oa-configurator>=2.1,<3",
|
|
10
|
+
"omop-semantics>=0.11,<1",
|
|
11
|
+
"pydantic>=2,<3",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.optional-dependencies]
|
|
15
|
+
dev = [
|
|
16
|
+
"groundworkers[duckdb]>=0.12,<1",
|
|
17
|
+
"pytest>=9,<10",
|
|
18
|
+
"ruff>=0.4",
|
|
19
|
+
"ty>=0.0.59",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
# Groundworkers discovers the plugin object through this group. The left-hand
|
|
23
|
+
# name is cosmetic; the object it points at must already be constructed.
|
|
24
|
+
[project.entry-points."groundworkers.plugins"]
|
|
25
|
+
omop_semantic_projection = "omop_semantic_projection.plugin:plugin"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.version]
|
|
32
|
+
source = "vcs"
|
|
33
|
+
raw-options = { tag_regex = '^v?(?P<version>[0-9]+\.[0-9]+\.[0-9]+)$' }
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["src/omop_semantic_projection"]
|
|
37
|
+
|
|
38
|
+
[tool.uv]
|
|
39
|
+
cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true } }]
|
|
40
|
+
constraint-dependencies = ["setuptools>=83.0.0"]
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
testpaths = ["tests"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff]
|
|
46
|
+
src = ["src", "tests"]
|
|
47
|
+
|
|
48
|
+
[tool.ruff.lint]
|
|
49
|
+
# Pinned explicitly: ruff's implicit default rule set widens between releases,
|
|
50
|
+
# which would otherwise break CI on a ruff upgrade rather than on a code change.
|
|
51
|
+
select = ["E4", "E7", "E9", "F", "I", "UP", "RUF"]
|
|
52
|
+
|
|
53
|
+
[tool.ty.src]
|
|
54
|
+
include = ["src"]
|