prod temp changes
This commit is contained in:
parent
c0ff0f35c3
commit
ae69d5ef41
136
Program.cs
136
Program.cs
@ -22,6 +22,7 @@ namespace DicomMigratorApp
|
||||
private static string senderAET;
|
||||
private static string targetAET;
|
||||
private static int targetPort;
|
||||
private static string db_status_to_pick;
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
@ -38,11 +39,12 @@ namespace DicomMigratorApp
|
||||
|
||||
_logger.LogInformation("Application started");
|
||||
|
||||
connectionString = Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection") ?? "";
|
||||
targetIP = Environment.GetEnvironmentVariable("Dest__IP") ?? "";
|
||||
senderAET = Environment.GetEnvironmentVariable("Sender__AET") ?? "";
|
||||
targetAET = Environment.GetEnvironmentVariable("Dest__AET") ?? "";
|
||||
var targetPortStr = Environment.GetEnvironmentVariable("Dest__Port") ?? "";
|
||||
connectionString = Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection") ?? "Server=127.0.0.1;Port=3306;Database=dms_db;User Id=root;Password=Rootmatrix23@;";
|
||||
targetIP = Environment.GetEnvironmentVariable("Dest__IP") ?? "127.0.0.1";
|
||||
senderAET = Environment.GetEnvironmentVariable("Sender__AET") ?? "MYAE";
|
||||
targetAET = Environment.GetEnvironmentVariable("Dest__AET") ?? "ORTHANC";
|
||||
var targetPortStr = Environment.GetEnvironmentVariable("Dest__Port") ?? "4242";
|
||||
db_status_to_pick = Environment.GetEnvironmentVariable("DB_STATUS") ?? "MIGRATION_QUEUE";
|
||||
|
||||
if (!int.TryParse(targetPortStr, out targetPort))
|
||||
{
|
||||
@ -54,38 +56,30 @@ namespace DicomMigratorApp
|
||||
{
|
||||
try
|
||||
{
|
||||
var migrationStudy = await GetMigrationStudy(connectionString);
|
||||
if (migrationStudy == null)
|
||||
var imagePaths = await GetMigrationImages(connectionString,db_status_to_pick);
|
||||
if (imagePaths == null || imagePaths.Count == 0)
|
||||
{
|
||||
await Task.Delay(5000);
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"Retrieved study details for migration: {migrationStudy.StudyInstanceUID}");
|
||||
|
||||
try
|
||||
foreach (var image in imagePaths)
|
||||
{
|
||||
var imagePaths = await GetImagePaths(connectionString, migrationStudy.StudyInstanceUID);
|
||||
|
||||
foreach (var image in imagePaths)
|
||||
try
|
||||
{
|
||||
await MigrateImage(image.Path);
|
||||
await UpdateImagePathStatus(connectionString, image.Id, "MIGRATION_COMPLETE");
|
||||
}
|
||||
|
||||
await UpdateSourceCFind(connectionString, migrationStudy.Id, "MIGRATION_COMPLETE");
|
||||
}
|
||||
catch (DicomAssociationRejectedException ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Association rejected for studyInstanceUID {migrationStudy.StudyInstanceUID}");
|
||||
await UpdateSourceCFind(connectionString, migrationStudy.Id, "MIGRATION_ERRORED");
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"An error occurred while retrieving or saving studyInstanceUID {migrationStudy.StudyInstanceUID}");
|
||||
await UpdateSourceCFind(connectionString, migrationStudy.Id, "MIGRATION_ERRORED");
|
||||
break;
|
||||
catch (DicomAssociationRejectedException ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Association rejected for image path {image.Path}");
|
||||
await UpdateImagePathStatus(connectionString, image.Id, "MIGRATION_ERRORED");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"An error occurred while migrating image path {image.Path}");
|
||||
await UpdateImagePathStatus(connectionString, image.Id, "MIGRATION_ERRORED");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
@ -101,53 +95,7 @@ namespace DicomMigratorApp
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<SourceStudy> GetMigrationStudy(string connectionString)
|
||||
{
|
||||
var qrStudy = new SourceStudy();
|
||||
|
||||
try
|
||||
{
|
||||
using (var connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
_logger.LogInformation("Opening a connection to the database");
|
||||
await connection.OpenAsync();
|
||||
_logger.LogInformation("Database connection established");
|
||||
var command = new MySqlCommand("SELECT id, study_instance_uid, patient_id, status FROM priority_migration_study WHERE status='QR_COMPLETE' ORDER BY schedule_date LIMIT 1", connection);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
qrStudy = new SourceStudy
|
||||
{
|
||||
Id = reader.IsDBNull(0) ? 0 : reader.GetInt32(0),
|
||||
StudyInstanceUID = reader.IsDBNull(1) ? null : reader.GetString(1),
|
||||
PatientID = reader.IsDBNull(2) ? null : reader.GetString(2),
|
||||
Status = reader.IsDBNull(3) ? null : reader.GetString(3)
|
||||
};
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
if (qrStudy.StudyInstanceUID != null)
|
||||
{
|
||||
_logger.LogInformation($"Picked study to be migrated from the database: {qrStudy.StudyInstanceUID}");
|
||||
await UpdateSourceCFind(connectionString, qrStudy.Id, "MIGRATION_INPROGRESS");
|
||||
}
|
||||
else
|
||||
{
|
||||
qrStudy = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving study to be migrated from the database");
|
||||
throw; // Re-throw the exception to ensure it is caught by the outer try-catch block
|
||||
}
|
||||
|
||||
return qrStudy;
|
||||
}
|
||||
|
||||
private static async Task<List<ImageRecord>> GetImagePaths(string connectionString, string studyInstanceUID)
|
||||
private static async Task<List<ImageRecord>> GetMigrationImages(string connectionString, string db_status_to_pick)
|
||||
{
|
||||
var imagePaths = new List<ImageRecord>();
|
||||
|
||||
@ -156,8 +104,11 @@ namespace DicomMigratorApp
|
||||
using (var connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
var command = new MySqlCommand("SELECT id, image_path FROM priority_migration_image WHERE study_instance_uid = @StudyInstanceUID AND (status != 'MIGRATION_COMPLETE' or status is null)", connection);
|
||||
command.Parameters.AddWithValue("@StudyInstanceUID", studyInstanceUID);
|
||||
_logger.LogInformation("Database connection established");
|
||||
|
||||
var command = new MySqlCommand("SELECT id, image_path FROM priority_migration_image WHERE status=@Status order by priority LIMIT 10", connection);
|
||||
command.Parameters.AddWithValue("@Status", db_status_to_pick);
|
||||
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
@ -171,7 +122,7 @@ namespace DicomMigratorApp
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
_logger.LogInformation($"Retrieved {imagePaths.Count} image paths for studyInstanceUID {studyInstanceUID}");
|
||||
_logger.LogInformation($"Retrieved {imagePaths.Count} image paths for migration");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -224,37 +175,6 @@ namespace DicomMigratorApp
|
||||
throw; // Re-throw the exception to ensure it is caught by the outer try-catch block
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task UpdateSourceCFind(string connectionString, int studyId, string updateStatus)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
var command = new MySqlCommand("UPDATE priority_migration_study SET status = @Status WHERE id = @StudyId", connection);
|
||||
|
||||
command.Parameters.AddWithValue("@StudyId", studyId);
|
||||
command.Parameters.AddWithValue("@Status", updateStatus);
|
||||
|
||||
await command.ExecuteNonQueryAsync();
|
||||
_logger.LogInformation($"Updated source C-FIND record for study ID {studyId} with status {updateStatus}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error updating source study record for study ID {studyId}");
|
||||
throw; // Re-throw the exception to ensure it is caught by the outer try-catch block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SourceStudy
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string PatientID { get; set; }
|
||||
public string StudyInstanceUID { get; set; }
|
||||
public string Status { get; set; }
|
||||
}
|
||||
|
||||
class ImageRecord
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user