Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f451615
:sparkles: Mutation to upsert global IDs
znatty22 Feb 7, 2025
1117cb4
:recycle: Add upsert_global_descriptors to study API
znatty22 Feb 7, 2025
11a8228
:sparkles: REST client methods to upload study file, upsert global IDs
znatty22 Feb 7, 2025
9638996
:fire: Rm unit test for download hash report
znatty22 Feb 11, 2025
9ef44ab
:truck: Mv global ID methods to own module
znatty22 Feb 11, 2025
2cb178c
:sparkles: Add upsert global desc CLI command
znatty22 Feb 11, 2025
e65437b
:sparkles: Method to download global ID descriptors
znatty22 Feb 11, 2025
cee9287
:sparkles: Method and cmd to upsert and download the resulting descri…
znatty22 Feb 11, 2025
3939f7e
:seedling: Generate fake descriptors file for testing
znatty22 Feb 11, 2025
07ca54d
:bug: Add missing CLI cmd declarations
znatty22 Feb 12, 2025
269a067
:truck: Mv global id specific funcs into global_id module
znatty22 Feb 12, 2025
606141e
:bug: Fix bugs w global id cmd defs
znatty22 Feb 12, 2025
2f31616
:goal_net: Catch and log global ID upsert errors
znatty22 Feb 12, 2025
fc3e011
:recycle: Generate fake Dewrangle global IDs
znatty22 Feb 12, 2025
23f58d6
:white_check_mark: Test global ID file generator
znatty22 Feb 12, 2025
c7301cc
:bug: Fix default values for CLI cmds
znatty22 Feb 12, 2025
829fb48
:white_check_mark: Test global ID upsert/download commands
znatty22 Feb 12, 2025
0b498f6
:bug: Fix broken org tests
znatty22 Feb 12, 2025
459b964
:recycle: Change --descriptors to --download-all
znatty22 Feb 12, 2025
b1e9b9f
:sparkles: New CLI cmd to upsert,download 1 descriptor
znatty22 Feb 12, 2025
e65cc4f
:white_check_mark: Test single descriptor upsert
znatty22 Feb 12, 2025
6fc0e88
:rotating_light: Fix black formatter errors
znatty22 Feb 12, 2025
d9cd445
:recycle: Simplify if statement
znatty22 Feb 14, 2025
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
16 changes: 16 additions & 0 deletions d3b_api_client_cli/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
import click
from d3b_api_client_cli.cli.dewrangle import *
from d3b_api_client_cli.cli.postgres import *
from d3b_api_client_cli.cli.faker import *


@click.group()
def faker():
"""
Group of lower level CLI commands related to generating fake data
"""


@click.group()
Expand Down Expand Up @@ -35,6 +43,9 @@ def main():
"""


# Fake data commands
faker.add_command(generate_global_id_file)

# Postgres API commands
postgres.add_command(save_file_to_db)

Expand All @@ -57,7 +68,12 @@ def main():
dewrangle.add_command(create_billing_group)
dewrangle.add_command(delete_billing_group)
dewrangle.add_command(read_billing_groups)
dewrangle.add_command(upsert_global_descriptors)
dewrangle.add_command(download_global_descriptors)
dewrangle.add_command(upsert_and_download_global_descriptors)
dewrangle.add_command(upsert_and_download_global_descriptor)

# Add command groups to the root CLI
main.add_command(dewrangle)
main.add_command(postgres)
main.add_command(faker)
1 change: 1 addition & 0 deletions d3b_api_client_cli/cli/dewrangle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from d3b_api_client_cli.cli.dewrangle.volume_commands import *
from d3b_api_client_cli.cli.dewrangle.job_commands import *
from d3b_api_client_cli.cli.dewrangle.billing_group_commands import *
from d3b_api_client_cli.cli.dewrangle.global_id_commands import *
285 changes: 285 additions & 0 deletions d3b_api_client_cli/cli/dewrangle/global_id_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
"""
All CLI commands related to creating, updating, and downloading global IDs
in Dewrangle
"""

import os
import logging
import click

from d3b_api_client_cli.config import log, FHIR_RESOURCE_TYPES
from d3b_api_client_cli.dewrangle.global_id import GlobalIdDescriptorOptions
from d3b_api_client_cli.dewrangle.global_id import (
upsert_global_descriptors as _upsert_global_descriptors,
download_global_descriptors as _download_global_descriptors,
upsert_and_download_global_descriptors as _upsert_and_download_global_descriptors,
upsert_and_download_global_descriptor as _upsert_and_download_global_descriptor,
)

logger = logging.getLogger(__name__)


@click.command()
@click.option(
"--output-filepath",
type=click.Path(exists=False, file_okay=True, dir_okay=False),
help="If provided, download the file to this path. This takes "
"precedence over the --output-dir option",
)
@click.option(
"--output-dir",
default=os.getcwd(),
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help="If provided, download the file with the default file name into "
"this directory",
)
@click.option(
"--download-all",
is_flag=True,
help="What descriptor(s) for each global ID to download. Either download"
" all descriptors for each global ID or just the most recent",
)
@click.option(
"--study-global-id",
help="The global ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.option(
"--study-id",
help="The GraphQL ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.option(
"--global-id",
help="Global ID associated with this descriptor."
" If this is provided, and the descriptor is new, then Dewrangle"
" will append the descriptor to this global ID's descriptor list",
)
@click.option(
"--fhir-resource-type",
type=click.Choice([rt for rt in FHIR_RESOURCE_TYPES.keys()]),
required=True,
)
@click.option(
"--descriptor",
required=True,
)
def upsert_and_download_global_descriptor(
descriptor,
fhir_resource_type,
global_id,
study_id,
study_global_id,
download_all,
output_dir,
output_filepath,
):
"""
Send request to upsert one global ID descriptor in Dewrangle and
download the resulting global ID descriptors.

In order to create new global IDs provide:
descriptor, fhir-resource-type

In order to update existing global IDs:
descriptor, fhir-resource-type, global-id

\b
Arguments:
\b
input_filepath - Path to the file with global IDs and descriptors
"""

log.init_logger()

if (not study_id) and (not study_global_id):
raise click.BadParameter(
"❌ You must provide either the study's global ID in Dewrangle OR "
"the study's GraphQL ID in Dewrangle"
)
return _upsert_and_download_global_descriptor(
descriptor,
fhir_resource_type,
global_id=global_id,
study_global_id=study_global_id,
dewrangle_study_id=study_id,
download_all=download_all,
output_dir=output_dir,
output_filepath=output_filepath,
)


@click.command()
@click.option(
"--output-filepath",
type=click.Path(exists=False, file_okay=True, dir_okay=False),
help="If provided, download the file to this path. This takes "
"precedence over the --output-dir option",
)
@click.option(
"--output-dir",
default=os.getcwd(),
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help="If provided, download the file with the default file name into "
"this directory",
)
@click.option(
"--download-all",
is_flag=True,
help="What descriptor(s) for each global ID to download. Either download"
" all descriptors for each global ID or just the most recent",
)
@click.option(
"--study-global-id",
help="The global ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.option(
"--study-id",
help="The GraphQL ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.argument(
"input_filepath",
type=click.Path(exists=False, file_okay=True, dir_okay=False),
)
def upsert_and_download_global_descriptors(
input_filepath,
study_id,
study_global_id,
download_all,
output_dir,
output_filepath,
):
"""
Send request to upsert global ID descriptors in Dewrangle and
download the resulting global ID descriptors.

In order to create new global IDs provide a CSV file with the columns:
descriptor, fhirResourceType

In order to update existing global IDs provide a CSV file with the columns:
descriptor, fhirResourceType, globalId

\b
Arguments:
\b
input_filepath - Path to the file with global IDs and descriptors
"""

log.init_logger()

if (not study_id) and (not study_global_id):
raise click.BadParameter(
"❌ You must provide either the study's global ID in Dewrangle OR "
"the study's GraphQL ID in Dewrangle"
)

return _upsert_and_download_global_descriptors(
input_filepath,
study_global_id=study_global_id,
dewrangle_study_id=study_id,
download_all=download_all,
output_dir=output_dir,
output_filepath=output_filepath,
)


@click.command()
@click.option(
"--study-global-id",
help="The global ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.option(
"--study-id",
help="The GraphQL ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.argument(
"filepath",
type=click.Path(exists=False, file_okay=True, dir_okay=False),
)
def upsert_global_descriptors(filepath, study_id, study_global_id):
"""
Upsert global ID descriptors in Dewrangle for a study.

In order to create new global IDs provide a CSV file with the columns:
descriptor, fhirResourceType

In order to update existing global IDs provide a CSV file with the columns:
descriptor, fhirResourceType, globalId

\b
Arguments:
\b
filepath - Path to the file with global IDs and descriptors
"""

log.init_logger()

if (not study_id) and (not study_global_id):
raise click.BadParameter(
"❌ You must provide either the study's global ID in Dewrangle OR "
"the study's GraphQL ID in Dewrangle"
)

return _upsert_global_descriptors(filepath, study_global_id, study_id)


@click.command()
@click.option(
"--output-dir",
default=os.getcwd(),
type=click.Path(exists=True, file_okay=False, dir_okay=True),
help="If provided, download the file with the default file name into "
"this directory",
)
@click.option(
"--download-all",
is_flag=True,
help="What descriptor(s) for each global ID to download. Either download"
" all descriptors for each global ID or just the most recent",
)
@click.option(
"--job-id", help="Dewrangle job id from the upsert_global_descriptors cmd"
)
@click.option(
"--study-global-id",
help="The global ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.option(
"--study-id",
help="The GraphQL ID of the study in Dewrangle. You must provide either "
"the global ID of the study OR the GraphQL ID of the study but not both",
)
@click.option(
"--filepath",
type=click.Path(exists=False, file_okay=True, dir_okay=False),
help="If provided, download the file to this filepath. This takes "
"precedence over --output-dir",
)
def download_global_descriptors(
filepath, study_id, study_global_id, job_id, download_all, output_dir
):
"""
Download global ID descriptors in Dewrangle for a study.
"""

log.init_logger()

if (not study_id) and (not study_global_id):
raise click.BadParameter(
"❌ You must provide either the study's global ID in Dewrangle OR "
"the study's GraphQL ID in Dewrangle"
)

return _download_global_descriptors(
dewrangle_study_id=study_id,
study_global_id=study_global_id,
filepath=filepath,
job_id=job_id,
download_all=download_all,
output_dir=output_dir,
)
5 changes: 5 additions & 0 deletions d3b_api_client_cli/cli/faker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Package containing commands for fake data generation
"""

from d3b_api_client_cli.cli.faker.global_id_commands import *
Loading
Loading