Skip to content

Commit 39cd91c

Browse files
committed
Push v0.02
1 parent 36dcb47 commit 39cd91c

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

Changes

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Rvision history for Perl distribution OMOP-CSV-Validator
22

3-
0.02 2025-04-XXT00:00:00Z (Manuel Rueda <mrueda@cpan.org>)
3+
0.02 2025-04-02T00:00:00Z (Manuel Rueda <mrueda@cpan.org>)
44

5-
- Now CLI errors are sent to STDOUT (say) instead of STDERR (warn) for "easier" capture
6-
- Fixed #1 issue
7-
- Added optional <--table> parameter to provide table name to bin and utils
5+
- CLI errors are now sent to STDOUT (say) instead of STDERR (warn) for easier capture
6+
- Fixed issue #1
7+
- Added optional <--table> parameter to specify the table name for bin and utils
8+
- Added optional <--save-schemas> parameter to save JSON schemas of tables to a file
89

910
0.01 2025-03-29T00:00:00Z (Manuel Rueda <mrueda@cpan.org>)
1011

bin/omop-csv-validator

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use Path::Tiny;
1616
use OMOP::CSV::Validator; # Now loads the OO version (no explicit import list)
1717
use JSON::XS;
1818
use Pod::Usage;
19+
use Data::Dumper;
1920

2021
# If you want the module's version, access it directly:
2122
my $VERSION = $OMOP::CSV::Validator::VERSION;
@@ -25,14 +26,16 @@ my $ddl_file;
2526
my $csv_file;
2627
my $sep = ',';
2728
my $table_name; # <-- new optional parameter
29+
my $schemas_file; # <-- new option to save schemas to file
2830

2931
GetOptions(
30-
'ddl=s' => \$ddl_file, # Path to the DDL file (PostgreSQL)
31-
'input=s' => \$csv_file, # Path to the input CSV file
32-
'sep=s' => \$sep, # Field separator (default: comma)
33-
'table|t=s' => \$table_name, # Optional: override table name
34-
'help|h' => \my $help, # Show help message
35-
'version|V' => sub { say "$0 Version $VERSION"; exit; },
32+
'ddl=s' => \$ddl_file, # Path to the DDL file (PostgreSQL)
33+
'input=s' => \$csv_file, # Path to the input CSV file
34+
'sep=s' => \$sep, # Field separator (default: comma)
35+
'table|t=s' => \$table_name, # Optional: override table name
36+
'save-schemas=s' => \$schemas_file, # Optional: file to save schemas
37+
'help|h' => \my $help, # Show help message
38+
'version|V' => sub { say "$0 Version $VERSION"; exit; },
3639
) or pod2usage(2);
3740

3841
pod2usage(1) if $help;
@@ -51,7 +54,14 @@ my $validator = OMOP::CSV::Validator->new();
5154
# Load schemas from the DDL
5255
my $schemas = $validator->load_schemas_from_ddl($ddl_text);
5356

54-
# If --table was not passed, we derive from the CSV filename; otherwise, use what was provided.
57+
# Optionally save schemas to a file if --save-schemas was provided
58+
if ($schemas_file) {
59+
my $json = JSON::XS->new->utf8->pretty->encode($schemas);
60+
path($schemas_file)->spew_utf8($json);
61+
say "Schemas saved to '$schemas_file'";
62+
}
63+
64+
# If --table was not passed, derive from the CSV filename; otherwise, use what was provided.
5565
my $schema;
5666
if ($table_name) {
5767
# Attempt to find the schema by the given table name
@@ -87,7 +97,7 @@ omop_csv_validator - Validate OMOP CDM CSV files against DDL-derived schemas
8797
8898
=head1 SYNOPSIS
8999
90-
omop_csv_validator --ddl DDL.sql --input DATA.csv [--sep $'\t'] [--table person]
100+
omop_csv_validator --ddl DDL.sql --input DATA.csv [--sep $'\t'] [--table person] [--save-schemas schemas.json]
91101
92102
=head1 OPTIONS
93103
@@ -110,6 +120,10 @@ CSV field separator (default: comma). For tab, use: --sep $'\t'
110120
(optional) Table name to validate against. If not provided, the script will attempt
111121
to derive the table name from the CSV filename.
112122
123+
=item B<--save-schemas>
124+
125+
(optional) Path to a file where the DDL-derived schemas should be saved (in JSON format).
126+
113127
=item B<--help>, B<-h>
114128
115129
Display this help message.
@@ -124,5 +138,6 @@ Show the script's version (which corresponds to C<OMOP::CSV::Validator::VERSION>
124138
125139
bin/omop_csv_validator --ddl ddl/postgres.sql --input data/person.csv --sep $'\t'
126140
bin/omop_csv_validator --ddl ddl/postgres.sql --input data/ANY_CSV.csv --table person
141+
bin/omop_csv_validator --ddl ddl/postgres.sql --input data/ANY_CSV.csv --save-schemas schemas.json
127142
128143
=cut

lib/OMOP/CSV/Validator.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Text::CSV_XS;
99
use Scalar::Util qw(looks_like_number);
1010
use Path::Tiny;
1111

12-
our $VERSION = '0.01';
12+
our $VERSION = '0.02';
1313

1414
=head1 NAME
1515

0 commit comments

Comments
 (0)