-
Notifications
You must be signed in to change notification settings - Fork 1
feat(transform-csv): add ML to OMOP conversion pipeline with validation #14
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| verification.py | ||
|
|
||
| Quick sanity-checks for the four OMOP CSVs produced by convert.py. | ||
|
|
||
| • Ensures every person_id referenced in measurement.csv, observation.csv, | ||
| and visit_occurrence.csv exists in person.csv | ||
| • Verifies that the primary-key columns (person_id, measurement_id, | ||
| observation_id, visit_occurrence_id) are unique | ||
| • Prints a concise PASS / FAIL summary | ||
|
|
||
| Run *after* you have executed convert.py: | ||
|
|
||
| python3 verification.py | ||
| """ | ||
|
|
||
| import pandas as pd | ||
| from pathlib import Path | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def load_csv(path: str, required: bool = True) -> pd.DataFrame | None: | ||
| if not Path(path).exists(): | ||
| if required: | ||
| raise FileNotFoundError(f"{path} not found") | ||
| return None | ||
| return pd.read_csv(path) | ||
|
|
||
| # load files | ||
| person_df = load_csv("person.csv") | ||
| measurement_df = load_csv("measurement.csv") | ||
| observation_df = load_csv("observation.csv") | ||
| visit_df = load_csv("visit_occurrence.csv", required=False) # may be absent | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Helper for subset checks | ||
|
|
||
| def subset_ok(child_series: pd.Series, parent_set: set[int]) -> bool: | ||
| """Return True if *all* IDs in child_series are contained in parent_set.""" | ||
| return set(child_series.unique()).issubset(parent_set) | ||
|
|
||
| # Primary-key uniqueness checks | ||
| checks = [] | ||
|
|
||
| def unique_ok(df: pd.DataFrame, col: str) -> bool: | ||
| """Verify the column has unique non-null values.""" | ||
| return df[col].is_unique and df[col].notna().all() | ||
|
|
||
| checks.append(("person_id uniqueness", unique_ok(person_df, "person_id"))) | ||
| checks.append(( | ||
| "measurement_id uniqueness", | ||
| unique_ok(measurement_df, "measurement_id"), | ||
| )) | ||
| checks.append(( | ||
| "observation_id uniqueness", | ||
| unique_ok(observation_df, "observation_id"), | ||
| )) | ||
| if visit_df is not None: | ||
| checks.append(( | ||
| "visit_occurrence_id uniqueness", | ||
| unique_ok(visit_df, "visit_occurrence_id"), | ||
| )) | ||
|
|
||
| # FK-style subset checks | ||
| person_ids = set(person_df["person_id"].unique()) | ||
|
|
||
| checks.append(( | ||
| "measurement.person_id ⊆ person.person_id", | ||
| subset_ok(measurement_df["person_id"], person_ids), | ||
| )) | ||
| checks.append(( | ||
| "observation.person_id ⊆ person.person_id", | ||
| subset_ok(observation_df["person_id"], person_ids), | ||
| )) | ||
| if visit_df is not None: | ||
| checks.append(( | ||
| "visit_occurrence.person_id ⊆ person.person_id", | ||
| subset_ok(visit_df["person_id"], person_ids), | ||
| )) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Print summary | ||
|
|
||
| all_ok = True | ||
| print("\nValidation results:") | ||
| for name, result in checks: | ||
| status = "PASS" if result else "FAIL" | ||
| print(f" {status:<4} – {name}") | ||
| all_ok &= result | ||
|
|
||
| print("\nOverall:", "✔︎ ALL CHECKS PASSED" if all_ok else "✘ SOME CHECKS FAILED") |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.