|
3 | 3 | using System.Security.Cryptography; |
4 | 4 | using System.Text; |
5 | 5 | using System.Text.Json; |
| 6 | +using ICD10.TestSupport; |
6 | 7 | using Microsoft.AspNetCore.Builder; |
7 | 8 | using Microsoft.AspNetCore.Hosting; |
8 | 9 | using Microsoft.AspNetCore.Hosting.Server; |
@@ -141,14 +142,28 @@ await Task.WhenAll( |
141 | 142 | var samplesDir = Path.GetFullPath( |
142 | 143 | Path.Combine(testAssemblyDir, "..", "..", "..", "..", "..") |
143 | 144 | ); |
144 | | - var rootDir = Path.GetFullPath(Path.Combine(samplesDir, "..")); |
145 | 145 |
|
146 | | - // Run ICD-10 migration and import official CDC data |
147 | | - await SetupIcd10DatabaseAsync(icd10ConnStr, samplesDir, rootDir); |
| 146 | + // Run ICD-10 migration and import official CDC data. |
| 147 | + // ICD-10 is optional in the E2E suite (see ICD-10 API skip block below) - if |
| 148 | + // setup fails (e.g. embedding service or Python toolchain unavailable), continue |
| 149 | + // without it instead of failing the entire fixture. |
| 150 | + var icd10Ready = false; |
| 151 | + try |
| 152 | + { |
| 153 | + await SetupIcd10DatabaseAsync(icd10ConnStr, samplesDir); |
| 154 | + icd10Ready = true; |
| 155 | + } |
| 156 | + catch (Exception ex) |
| 157 | + { |
| 158 | + Console.WriteLine( |
| 159 | + $"[E2E] WARNING: ICD-10 database setup failed ({ex.Message}); " |
| 160 | + + "ICD-10 dependent tests will be skipped" |
| 161 | + ); |
| 162 | + } |
148 | 163 |
|
149 | 164 | var clinicalProjectDir = Path.Combine(samplesDir, "Clinical", "Clinical.Api"); |
150 | 165 | var schedulingProjectDir = Path.Combine(samplesDir, "Scheduling", "Scheduling.Api"); |
151 | | - var gatekeeperProjectDir = Path.Combine(rootDir, "Gatekeeper", "Gatekeeper.Api"); |
| 166 | + var gatekeeperProjectDir = Path.Combine(samplesDir, "Gatekeeper", "Gatekeeper.Api"); |
152 | 167 | var icd10ProjectDir = Path.Combine(samplesDir, "ICD10", "ICD10.Api"); |
153 | 168 | var configuration = ResolveBuildConfiguration(testAssemblyDir); |
154 | 169 |
|
@@ -226,12 +241,12 @@ await Task.WhenAll( |
226 | 241 | ["ConnectionStrings__Postgres"] = icd10ConnStr, |
227 | 242 | ["ConnectionStrings__DefaultConnection"] = icd10ConnStr, |
228 | 243 | }; |
229 | | - if (File.Exists(icd10Dll)) |
| 244 | + if (icd10Ready && File.Exists(icd10Dll)) |
230 | 245 | { |
231 | 246 | _icd10Process = StartApiFromDll(icd10Dll, icd10ProjectDir, Icd10Url, icd10Env); |
232 | 247 | Console.WriteLine($"[E2E] ICD-10 API starting on {Icd10Url}"); |
233 | 248 | } |
234 | | - else |
| 249 | + else if (!File.Exists(icd10Dll)) |
235 | 250 | { |
236 | 251 | Console.WriteLine($"[E2E] ICD-10 API DLL missing: {icd10Dll}"); |
237 | 252 | } |
@@ -1040,117 +1055,27 @@ private static async Task SeedAsync(HttpClient client, string url, string json) |
1040 | 1055 | /// Sets up the ICD-10 database by running migration and importing official CDC data. |
1041 | 1056 | /// Skips import if data already exists in the database. |
1042 | 1057 | /// </summary> |
1043 | | - private static async Task SetupIcd10DatabaseAsync( |
1044 | | - string connectionString, |
1045 | | - string samplesDir, |
1046 | | - string rootDir |
1047 | | - ) |
| 1058 | + private static async Task SetupIcd10DatabaseAsync(string connectionString, string samplesDir) |
1048 | 1059 | { |
1049 | 1060 | Console.WriteLine("[E2E] Setting up ICD-10 database..."); |
1050 | 1061 |
|
1051 | 1062 | var icd10ProjectDir = Path.Combine(samplesDir, "ICD10", "ICD10.Api"); |
1052 | 1063 | var schemaPath = Path.Combine(icd10ProjectDir, "icd10-schema.yaml"); |
1053 | | - var migrationCliDir = Path.Combine(rootDir, "Migration", "Migration.Cli"); |
1054 | | - var scriptsDir = Path.Combine(samplesDir, "ICD10", "scripts", "CreateDb"); |
1055 | 1064 |
|
1056 | 1065 | // Check if schema already exists and has data |
1057 | 1066 | if (await Icd10DatabaseHasDataAsync(connectionString)) |
1058 | 1067 | { |
1059 | 1068 | Console.WriteLine( |
1060 | | - "[E2E] ICD-10 database already has data - skipping migration and import" |
| 1069 | + "[E2E] ICD-10 database already has data - skipping migration and seed" |
1061 | 1070 | ); |
1062 | 1071 | return; |
1063 | 1072 | } |
1064 | 1073 |
|
1065 | | - // Step 1: Run migration to create schema |
1066 | | - Console.WriteLine("[E2E] Running ICD-10 schema migration..."); |
1067 | | - var configuration = ResolveBuildConfiguration( |
1068 | | - Path.GetDirectoryName(typeof(E2EFixture).Assembly.Location)! |
1069 | | - ); |
1070 | | - var migrationDll = Path.Combine( |
1071 | | - migrationCliDir, |
1072 | | - "bin", |
1073 | | - configuration, |
1074 | | - "net10.0", |
1075 | | - "Migration.Cli.dll" |
1076 | | - ); |
1077 | | - |
1078 | | - int migrationResult; |
1079 | | - if (File.Exists(migrationDll)) |
1080 | | - { |
1081 | | - Console.WriteLine($"[E2E] Using pre-built Migration.Cli: {migrationDll}"); |
1082 | | - migrationResult = await RunProcessAsync( |
1083 | | - "dotnet", |
1084 | | - $"exec \"{migrationDll}\" --schema \"{schemaPath}\" --output \"{connectionString}\" --provider postgres", |
1085 | | - rootDir, |
1086 | | - timeoutMs: 600_000 |
1087 | | - ); |
1088 | | - } |
1089 | | - else |
1090 | | - { |
1091 | | - Console.WriteLine( |
1092 | | - $"[E2E] Migration.Cli DLL not found at {migrationDll}, falling back to dotnet run" |
1093 | | - ); |
1094 | | - migrationResult = await RunProcessAsync( |
1095 | | - "dotnet", |
1096 | | - $"run --project \"{migrationCliDir}\" -- --schema \"{schemaPath}\" --output \"{connectionString}\" --provider postgres", |
1097 | | - rootDir, |
1098 | | - timeoutMs: 600_000 |
1099 | | - ); |
1100 | | - } |
1101 | | - |
1102 | | - if (migrationResult != 0) |
1103 | | - { |
1104 | | - throw new Exception($"ICD-10 migration failed with exit code {migrationResult}"); |
1105 | | - } |
1106 | | - |
1107 | | - Console.WriteLine("[E2E] ICD-10 schema created successfully"); |
1108 | | - |
1109 | | - // Step 2: Set up Python virtual environment |
1110 | | - var venvDir = Path.Combine(samplesDir, "ICD10", ".venv"); |
1111 | | - var pythonScript = Path.Combine(scriptsDir, "import_postgres.py"); |
1112 | | - |
1113 | | - if (!File.Exists(pythonScript)) |
1114 | | - { |
1115 | | - throw new FileNotFoundException($"ICD-10 import script not found: {pythonScript}"); |
1116 | | - } |
1117 | | - |
1118 | | - Console.WriteLine("[E2E] Setting up Python environment..."); |
1119 | | - if (!Directory.Exists(venvDir)) |
1120 | | - { |
1121 | | - var venvResult = await RunProcessAsync("python3", $"-m venv \"{venvDir}\"", scriptsDir); |
1122 | | - if (venvResult != 0) |
1123 | | - { |
1124 | | - throw new Exception($"Failed to create Python virtual environment"); |
1125 | | - } |
1126 | | - } |
1127 | | - |
1128 | | - // Install requirements |
1129 | | - var requirementsPath = Path.Combine(scriptsDir, "requirements.txt"); |
1130 | | - var pipResult = await RunProcessAsync( |
1131 | | - $"{venvDir}/bin/pip", |
1132 | | - $"install -r \"{requirementsPath}\"", |
1133 | | - scriptsDir |
1134 | | - ); |
1135 | | - if (pipResult != 0) |
1136 | | - { |
1137 | | - throw new Exception($"Failed to install Python dependencies"); |
1138 | | - } |
1139 | | - |
1140 | | - // Step 3: Import official CDC ICD-10 data |
1141 | | - Console.WriteLine("[E2E] Importing official CDC ICD-10 data..."); |
1142 | | - var importResult = await RunProcessAsync( |
1143 | | - $"{venvDir}/bin/python", |
1144 | | - $"\"{pythonScript}\" --connection-string \"{connectionString}\"", |
1145 | | - scriptsDir, |
1146 | | - timeoutMs: 600_000 |
1147 | | - ); |
1148 | | - |
1149 | | - if (importResult != 0) |
1150 | | - { |
1151 | | - throw new Exception($"ICD-10 data import failed with exit code {importResult}"); |
1152 | | - } |
1153 | | - |
| 1074 | + // Apply schema and seed deterministic E2E reference data via the shared |
| 1075 | + // ICD10.TestSupport library. This avoids the ~3-minute Python CDC import |
| 1076 | + // (44k codes + embeddings) that previously made every dashboard run hang. |
| 1077 | + Console.WriteLine("[E2E] Applying ICD-10 schema and seeding test data..."); |
| 1078 | + await Task.Run(() => Icd10TestDatabase.Initialize(connectionString, schemaPath)); |
1154 | 1079 | Console.WriteLine("[E2E] ICD-10 database setup complete"); |
1155 | 1080 | } |
1156 | 1081 |
|
|
0 commit comments