Skip to content

Commit

Permalink
Merge pull request #131 from OHDSI/dev_Validation
Browse files Browse the repository at this point in the history
Validation
  • Loading branch information
bradanton authored Nov 13, 2024
2 parents 07acff6 + c41276e commit 17ee583
Show file tree
Hide file tree
Showing 11 changed files with 828 additions and 502 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,4 @@ ETL-LambdaBuilder.Rproj
sources/Presentation/org.ohdsi.cdm.presentation.lambdabuilder/aws-lambda-tools-defaults.json
sources/Presentation/org.ohdsi.cdm.presentation.lambdamerge/aws-lambda-tools-defaults.json
/sources/Tests/RunLocal/App.config
/sources/RunValidation/App.config
13 changes: 13 additions & 0 deletions sources/Framework/org.ohdsi.cdm.framework/Common/Enums/Vendor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public override string ToString()
return this.Name;
}

public override bool Equals(object? obj)
{
if (obj is not Vendor other || other == null)
return false;

return this.Name == other.Name;
}

public override int GetHashCode()
{
return HashCode.Combine(this.Name);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using org.ohdsi.cdm.framework.common.Enums;
using org.ohdsi.cdm.framework.common.Extensions;
using org.ohdsi.cdm.framework.Common.Base;
using System.Linq;
using System.Reflection;

namespace org.ohdsi.cdm.framework.common.Utility
Expand Down Expand Up @@ -128,6 +129,7 @@ public static Vendor CreateVendorInstance(string etlLibraryPath, string name)
{
Console.WriteLine("CreateVendorInstance | assembly: " + assembly.GetName().Name);
Console.WriteLine("CreateVendorInstance | vendorType: " + vendorType);
Console.WriteLine();

return Activator.CreateInstance(vendorType) as Vendor;
}
Expand Down

This file was deleted.

98 changes: 98 additions & 0 deletions sources/RunValidation/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using CommandLine.Text;
using CommandLine;
using org.ohdsi.cdm.framework.common.Enums;
using org.ohdsi.cdm.framework.common.Utility;
using System.Configuration;
using org.ohdsi.cdm.framework.common.Omop;

namespace RunValidation
{
internal class Program
{
internal class Options
{
[Option('v', "vendor", Required = true, HelpText = "Vendor name.")]
public required string Vendor { get; set; }

[Option('b', "buildingId", Required = true, HelpText = "Building ID.")]
public required int BuildingId { get; set; }

[Option('e', "etlLibraryPath", Default = "", HelpText = "(Optional) Path to a folder containing an external ETL .dll")]
public string EtlLibraryPath { get; set; } = "";

[Option('l', "localTmpPath", Default = "C:\\_tmp", HelpText = "(Optional) Path to local folder to contain intermediary data")]
public string LocalTmpPath { get; set; } = "C:\\_tmp";

[Option('c', "chunks", Separator = ',', HelpText = "(Optional) Comma-separated list of chunk IDs to process. All of them, if omitted.")]
public IEnumerable<int> Chunks { get; set; } = new List<int>();

[Option('p', "personId", Default = null, HelpText = "(Optional) If specified, the usual check changes to finding SliceId for the given PersonId within the first specified ChunkId.")]
public long? PersonId { get; set; } = null;

[Usage(ApplicationAlias = "RunValidation")]
public static IEnumerable<Example> Examples
{
get
{
yield return new Example("Process all chunks of a vendor", new Options
{ Vendor = "VendorName", BuildingId = 123});
yield return new Example("Process all vendor's chunks from an external .dll", new Options
{ Vendor = "ExternalVendorName", BuildingId = 123, EtlLibraryPath = "C:\\PathToExternalDllFolder"});
yield return new Example("Process specified chunks of a vendor", new Options
{ Vendor = "VendorName", BuildingId = 123, Chunks = new List<int> { 1, 2, 3 } });
yield return new Example("Get SliceId within the given vendor's chunk containing the given PersonId", new Options
{ Vendor = "VendorName", BuildingId = 123, Chunks = new List<int> { 1 }, PersonId = 123 });
}
}
}

private static string _awsAccessKeyId => ConfigurationManager.AppSettings["awsAccessKeyId"] ?? throw new NullReferenceException("awsAccessKeyId");
private static string _awsSecretAccessKey => ConfigurationManager.AppSettings["awsSecretAccessKey"] ?? throw new NullReferenceException("awsSecretAccessKey");
private static string _bucket => ConfigurationManager.AppSettings["bucket"] ?? throw new NullReferenceException("bucket");
private static string _cdmFolder => ConfigurationManager.AppSettings["cdmFolder"] ?? "cdmCSV";

static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(RunWithOptions)
.WithNotParsed(HandleParseError);

GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true);
Console.ReadLine();
}

static void RunWithOptions(Options opts)
{
var chunks = opts.Chunks.ToList() ?? new List<int>();

Console.WriteLine("Options:");
//Console.WriteLine($"Keys: {_awsAccessKeyId} - {_awsSecretAccessKey}");
Console.WriteLine($"Bucket - folder: {_bucket} - {_cdmFolder}");

Console.WriteLine($"Vendor: {opts.Vendor}");
Console.WriteLine($"Building ID: {opts.BuildingId}");
Console.WriteLine($"Chunks: {string.Join(", ", chunks)}");
Console.WriteLine($"EtlLibraryPath: {opts.EtlLibraryPath}");
Console.WriteLine($"LocalTmpPath: {opts.LocalTmpPath}");
Console.WriteLine($"Current directory: {Directory.GetCurrentDirectory()}");
Console.WriteLine($"PersonId: {opts.PersonId.ToString() ?? ""}");
Console.WriteLine();

Vendor vendor = EtlLibrary.CreateVendorInstance(opts.EtlLibraryPath, opts.Vendor);
var validation = new Validation(_awsAccessKeyId, _awsSecretAccessKey, _bucket, opts.LocalTmpPath, _cdmFolder);
if (opts.PersonId.HasValue)
validation.ValidatePersonIdInSlice(vendor, opts.BuildingId, opts.Chunks.First(), opts.PersonId.Value);
else
validation.ValidateBuildingId(vendor, opts.BuildingId, chunks);
}

static void HandleParseError(IEnumerable<Error> errs)
{
Console.WriteLine("Failed to parse command-line arguments.");
foreach (var error in errs)
{
Console.WriteLine(error.ToString());
}
}
}
}
20 changes: 20 additions & 0 deletions sources/RunValidation/RunValidation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Framework\org.ohdsi.cdm.framework\org.ohdsi.cdm.framework.csproj" />
<ProjectReference Include="..\Presentation\org.ohdsi.cdm.presentation.lambdabuilder\org.ohdsi.cdm.presentation.lambdabuilder.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 17ee583

Please sign in to comment.