Skip to content
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

Fix/use #51

Merged
merged 39 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3194f22
Merge pull request #49 from bmeg/development
teslajoy Oct 11, 2024
9b13c21
update medadmin occuranceTiming
teslajoy Oct 30, 2024
cd56f42
upgrade to latest g3t for validation
teslajoy Oct 30, 2024
e1f1288
bump
teslajoy Oct 30, 2024
d16604d
demographics days to death
teslajoy Oct 31, 2024
a2c436d
g3t validator cli
teslajoy Oct 31, 2024
92d2485
fhir data validation readme update
teslajoy Oct 31, 2024
e6a4b53
adds identifier use
teslajoy Nov 7, 2024
266fd8c
improves cli validate @bwalsh++
teslajoy Nov 26, 2024
e2a17cf
explicit procedure ids - data_type mapping
teslajoy Nov 26, 2024
799a6fb
reference fix
teslajoy Nov 26, 2024
de35ff0
cleans patient extension
teslajoy Nov 27, 2024
e534f72
change to quantity
teslajoy Nov 27, 2024
9352da2
updated cellosaurus age + specimen mintids + patient identifier use
teslajoy Dec 2, 2024
ccfead3
updated fixtures
teslajoy Dec 4, 2024
c118e6e
upgrading pydantic -> 2.10 and fhir.resources -> 8.0.0b4 - in-progress
teslajoy Dec 5, 2024
1766eb1
updated -> fhir.resource 8.0.0 & Pydantic 2.10
teslajoy Dec 6, 2024
7d860dc
bump
teslajoy Dec 6, 2024
6f268ec
fixes Pydantic serializer warning
teslajoy Dec 9, 2024
3aa7a70
initial researchstudy patient group
teslajoy Dec 9, 2024
cbf66d4
adds post processing of researchstudy researchsubjects Group entity
teslajoy Dec 10, 2024
0bf7fc6
bump
teslajoy Dec 10, 2024
ef7e6f1
adds explicit observations for time events
teslajoy Dec 10, 2024
588f935
patch for DocumentReference size limit
teslajoy Dec 13, 2024
da46831
docref memeber and initial value/string/Decimal + fields as empty obj…
teslajoy Dec 16, 2024
509ee6a
attempt to add files missing fields
teslajoy Dec 17, 2024
ee6af53
case submitter id for tril/error of file subject substring
teslajoy Dec 17, 2024
b0c7b2f
docref subject tmp fix + cleanup + submitter ids
teslajoy Dec 17, 2024
d4cac95
update fixtures
teslajoy Dec 17, 2024
0f525ca
misc
teslajoy Dec 17, 2024
b15b697
adds test for member and subject check
teslajoy Dec 18, 2024
c8c1bae
remove patient reference from observation focus - leaves reference to…
teslajoy Dec 18, 2024
8281667
bump
teslajoy Dec 18, 2024
24ba511
adds halo spinner + fixture fix
teslajoy Dec 18, 2024
0c91ad9
stop spinner before observation
teslajoy Dec 18, 2024
5101e61
cellosaurus new-versions output cleanup
teslajoy Dec 19, 2024
8bd598d
adds spinner to HTAN
teslajoy Dec 19, 2024
5613dea
moves clean resource to utils
teslajoy Dec 19, 2024
4a701d7
HTAN changes for new fhir.resource + pydantic versions + happi server…
teslajoy Dec 19, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,4 @@ venv/

# output logging file for content
output.log
.g3t
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ git clone repo
cd fhirizer
# create virtual env ex.
# NOTE: package_data folders must be in python path in virtual envs
python -m venv venv-fhirizer
source venv-fhirizer/bin/activate
python -m venv venv
source venv/bin/activate
pip install .
```

Expand Down Expand Up @@ -128,6 +128,26 @@ fhirizer case_init
fhirizer file_init
```

### FHIR data validation

#### disable gen3-client
```
mv ~/.gen3/gen3_client_config.ini ~/.gen3/gen3_client_config.ini-xxx
mv ~/.gen3/gen3-client ~/.gen3/gen3-client-xxx
```

#### Run validate
```
fhirizer validate --path <path_to_META_folder_with_fhir_ndjson_files>
```

#### Restore gen3-client

```
mv ~/.gen3/gen3-client-xxx ~/.gen3/gen3-client
mv ~/.gen3/gen3_client_config.ini-xxx ~/.gen3/gen3_client_config.ini

```

### Testing
```
Expand Down
4 changes: 4 additions & 0 deletions fhirizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from fhirizer.patcher import apply_patches

apply_patches()

78 changes: 71 additions & 7 deletions fhirizer/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import sys
import os
import json
from gen3_tracker.common import ERROR_COLOR, INFO_COLOR
from fhirizer import utils, mapping, entity2fhir, icgc2fhir, htan2fhir
import click
from pathlib import Path
import importlib.resources
import warnings
from halo import Halo


warnings.filterwarnings("ignore", category=SyntaxWarning)


class NotRequiredIf(click.Option):
Expand Down Expand Up @@ -159,33 +169,87 @@ def convert(name, in_path, out_path, verbose):
@click.option('--convert', is_flag=True, help='Boolean indicating to write converted keys to directory')
@click.option('--verbose', is_flag=True)
def generate(name, out_dir, entity_path, icgc, has_files, atlas, convert, verbose):
name_list = ['project', 'case', 'file', 'cellosaurus', 'icgc', 'htan']
name_list = ['case', 'file', 'cellosaurus', 'icgc', 'htan']
assert name in name_list, f'--name is not in {name_list}.'
if name != 'htan':
assert Path(out_dir).is_dir(), f"Path {out_dir} is not a valid directory path."
assert Path(entity_path).is_file(), f"Path {entity_path} is not a valid file path."
else:
assert Path("./projects/HTAN").is_dir()

if name in 'project':
entity2fhir.project_gdc_to_fhir_ndjson(out_dir=out_dir, projects_path=entity_path, convert=convert, verbose=verbose)
spinner = Halo(text="🔥 Transforming data", spinner='dots', placement='right', color='white')

if name in 'case':
entity2fhir.case_gdc_to_fhir_ndjson(out_dir=out_dir, name=name, cases_path=entity_path, convert=convert, verbose=verbose)
spinner.start()
entity2fhir.case_gdc_to_fhir_ndjson(out_dir=out_dir, name=name, cases_path=entity_path, convert=convert, verbose=verbose, spinner=spinner)
if name in 'file':
entity2fhir.file_gdc_to_fhir_ndjson(out_dir=out_dir, name=name, files_path=entity_path, convert=convert, verbose=verbose)
spinner.start()
entity2fhir.file_gdc_to_fhir_ndjson(out_dir=out_dir, name=name, files_path=entity_path, convert=convert, verbose=verbose, spinner=spinner)
if name in 'cellosaurus':
entity2fhir.cellosaurus2fhir(out_dir=out_dir, path=entity_path)
spinner.start()
entity2fhir.cellosaurus2fhir(out_dir=out_dir, path=entity_path, spinner=spinner)
if name in 'icgc' and icgc:
icgc2fhir.icgc2fhir(project_name=icgc, has_files=has_files)
if name in 'htan':

if isinstance(atlas, str):
if "," in atlas:
atlas = atlas.split(",")
atlas = [a.strip() for a in atlas]
else:
atlas = [atlas]

htan2fhir.htan2fhir(entity_atlas_name=atlas, verbose=verbose)
spinner.start()
htan2fhir.htan2fhir(entity_atlas_name=atlas, verbose=verbose, spinner=spinner)



@cli.command('validate')
@click.option("-d", "--debug", is_flag=True, default=False,
help="Run in debug mode.")
@click.option("-p", "--path", default=None,
help="Path to read the FHIR NDJSON files.")
def validate(debug: bool, path):
"""Validate the output FHIR ndjson files."""
from gen3_tracker.git import run_command

if not path:
path = str(Path(importlib.resources.files('cda2fhir').parent / 'data' / 'META'))
if not os.path.isdir(path):
raise ValueError(f"Path: '{path}' is not a valid directory.")

try:
from gen3_tracker.meta.validator import validate as validate_dir
from halo import Halo
with Halo(text='Validating', spinner='line', placement='right', color='white'):
result = validate_dir(path)
click.secho(result.resources, fg=INFO_COLOR, file=sys.stderr)
# print exceptions, set exit code to 1 if there are any
for _ in result.exceptions:
click.secho(f"{_.path}:{_.offset} {_.exception} {json.dumps(_.json_obj, separators=(',', ':'))}", fg=ERROR_COLOR, file=sys.stderr)
if result.exceptions:
sys.exit(1)
except Exception as e:
click.secho(str(e), fg=ERROR_COLOR, file=sys.stderr)
if debug:
raise


@cli.command('study_group')
@click.option("-p", '--path', required=True,
default='./META',
show_default=True,
help='Directory path to META folder.')
@click.option("-o", '--output_path', required=True,
show_default=True,
help='Directory path to folder to save the Group.ndjson file.')
def study_group(path, output_path):
"""Adds a FHIR ndjson Group file as a post-processing metadata that captures ResearchSubject or Participants to a
ResearchStudy."""
assert Path(path).is_dir(), f"Path {path} is not a valid directory path."
assert Path(output_path).is_dir(), f"Path {output_path} is not a valid directory path."

utils.study_groups(meta_path=path, out_path=output_path)


if __name__ == '__main__':
Expand Down
Loading