@@ -16,6 +16,7 @@ use Path::Tiny;
1616use OMOP::CSV::Validator; # Now loads the OO version (no explicit import list)
1717use JSON::XS;
1818use Pod::Usage;
19+ use Data::Dumper;
1920
2021# If you want the module's version, access it directly:
2122my $VERSION = $OMOP::CSV::Validator::VERSION ;
@@ -25,14 +26,16 @@ my $ddl_file;
2526my $csv_file ;
2627my $sep = ' ,' ;
2728my $table_name ; # <-- new optional parameter
29+ my $schemas_file ; # <-- new option to save schemas to file
2830
2931GetOptions(
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
3841pod2usage(1) if $help ;
@@ -51,7 +54,14 @@ my $validator = OMOP::CSV::Validator->new();
5154# Load schemas from the DDL
5255my $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.
5565my $schema ;
5666if ($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
111121to 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
115129Display 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
0 commit comments