public bool Import(DicomMessage dicomMessage) { if (dicomMessage.DataSet == null) { throw new ArgumentException(); } var patient = new Patient { PatientId = dicomMessage.DataSet[DicomTags.PatientId].GetString(0, string.Empty), PatientName = dicomMessage.DataSet[DicomTags.PatientsName].GetString(0, string.Empty), PatientBirthDate = dicomMessage.DataSet[DicomTags.PatientsBirthDate].GetString(0, string.Empty), Issuer = dicomMessage.DataSet[DicomTags.IssuerOfPatientId].GetString(0, string.Empty), }; var study = new Study() { StudyId = dicomMessage.DataSet[DicomTags.StudyId].GetString(0, string.Empty), StudyUid = dicomMessage.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty), AccessionNumber = dicomMessage.DataSet[DicomTags.AccessionNumber].GetString(0, string.Empty), StudyDate = dicomMessage.DataSet[DicomTags.StudyDate].GetString(0, string.Empty), StudyTime = dicomMessage.DataSet[DicomTags.StudyTime].GetString(0, string.Empty), RefPhysician = dicomMessage.DataSet[DicomTags.ReferringPhysiciansName].GetString(0, string.Empty), StudyDescription = dicomMessage.DataSet[DicomTags.StudyDescription].GetString(0, string.Empty), PatientId = patient.PatientId, PatientName = patient.PatientName, PatientBirthday = patient.PatientBirthDate, PatientAge = dicomMessage.DataSet[DicomTags.PatientsAge].GetString(0, string.Empty), PatientSize = dicomMessage.DataSet[DicomTags.PatientsSize].GetString(0, string.Empty), PatientWeight = dicomMessage.DataSet[DicomTags.PatientsWeight].GetString(0, string.Empty), PatientSex = dicomMessage.DataSet[DicomTags.PatientsSex].GetString(0, string.Empty) }; var series = new Series() { SeriesUid = dicomMessage.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty), SeriesNumber = dicomMessage.DataSet[DicomTags.SeriesNumber].GetString(0, string.Empty), Modality = dicomMessage.DataSet[DicomTags.Modality].GetString(0, string.Empty), BodyPart = dicomMessage.DataSet[DicomTags.BodyPartExamined].GetString(0, string.Empty), Institution = dicomMessage.DataSet[DicomTags.InstitutionName].GetString(0, string.Empty), StationName = dicomMessage.DataSet[DicomTags.StationName].GetString(0, string.Empty), Department = dicomMessage.DataSet[DicomTags.InstitutionalDepartmentName].GetString(0, string.Empty), PerfPhysician = dicomMessage.DataSet[DicomTags.PerformingPhysiciansName].GetString(0, string.Empty), SeriesDate = dicomMessage.DataSet[DicomTags.SeriesDate].GetString(0, string.Empty), SeriesTime = dicomMessage.DataSet[DicomTags.SeriesTime].GetString(0, string.Empty), SeriesDescription = dicomMessage.DataSet[DicomTags.SeriesDescription].GetString(0, string.Empty), PerformedProcedureStepStartDate = dicomMessage.DataSet[DicomTags.PerformedProcedureStepStartDate].GetString(0, string.Empty), PerformedProcedureStepStartTime = dicomMessage.DataSet[DicomTags.PerformedProcedureStepStartTime].GetString(0, string.Empty), }; var instance = new Instance() { SopInstanceUid = dicomMessage.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty), SopClassUid = dicomMessage.DataSet[DicomTags.SopClassUid].GetString(0, string.Empty), InstanceNumber = dicomMessage.DataSet[DicomTags.InstanceNumber].GetString(0, string.Empty), ContentDate = dicomMessage.DataSet[DicomTags.ContentDate].GetString(0, string.Empty), ContentTime = dicomMessage.DataSet[DicomTags.ContentTime].GetString(0, string.Empty) }; if (string.IsNullOrEmpty(study.StudyUid) || string.IsNullOrEmpty(series.SeriesUid) || string.IsNullOrEmpty(instance.SopInstanceUid)) { throw new ArgumentException(); } // Get Patient Db Object using (var context = new PacsContext()) { Patient dbPatient = null; var dbStudy = InsertStudy(context, study, patient, out dbPatient); // Patient and study is exist in db now var dbSeries = InsertSeries(context, series, dbStudy, dbPatient); // insert instance var dbInstance = InsertImage(context, instance, dbSeries, dbStudy, dbPatient); var dbFile = InsertFile(context, dbInstance, dbSeries, dbStudy, dbPatient); var dicomFile = new DicomFile(dicomMessage, dbFile.FilePath); if (!Directory.Exists(Path.GetDirectoryName(dbFile.FilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(dbFile.FilePath)); } dicomFile.Save(); context.SaveChanges(); } return true; }
public DicomProcessingResult Import(DicomMessage dicomMessage) { var result = new DicomProcessingResult() { Successful = true, }; if (dicomMessage.DataSet == null) { result.Successful = false; } DateTime dt = new DateTime(); var patient = new Patient { PatientId = dicomMessage.DataSet[DicomTags.PatientId].GetString(0, string.Empty), PatientName = dicomMessage.DataSet[DicomTags.PatientsName].GetString(0, string.Empty), PatientBirthDate = dicomMessage.DataSet[DicomTags.PatientsBirthDate].GetDateTime(0, dt), IssuerOfPatientId = dicomMessage.DataSet[DicomTags.IssuerOfPatientId].GetString(0, string.Empty), }; var study = new Study() { StudyId = dicomMessage.DataSet[DicomTags.StudyId].GetString(0, string.Empty), StudyUid = dicomMessage.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty), AccessionNumber = dicomMessage.DataSet[DicomTags.AccessionNumber].GetString(0, string.Empty), StudyDate = dicomMessage.DataSet[DicomTags.StudyDate].GetDateTime(0, dt), StudyTime = dicomMessage.DataSet[DicomTags.StudyTime].GetDateTime(0, dt), RefPhysician = dicomMessage.DataSet[DicomTags.ReferringPhysiciansName].GetString(0, string.Empty), StudyDescription = dicomMessage.DataSet[DicomTags.StudyDescription].GetString(0, string.Empty), PatientId = patient.PatientId, PatientName = patient.PatientName, PatientBirthday = patient.PatientBirthDate, PatientAge = dicomMessage.DataSet[DicomTags.PatientsAge].GetString(0, string.Empty), PatientSize = dicomMessage.DataSet[DicomTags.PatientsSize].GetString(0, string.Empty), PatientWeight = dicomMessage.DataSet[DicomTags.PatientsWeight].GetString(0, string.Empty), PatientSex = dicomMessage.DataSet[DicomTags.PatientsSex].GetString(0, string.Empty) }; var series = new Series() { SeriesUid = dicomMessage.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty), SeriesNumber = dicomMessage.DataSet[DicomTags.SeriesNumber].GetString(0, string.Empty), Modality = dicomMessage.DataSet[DicomTags.Modality].GetString(0, string.Empty), BodyPart = dicomMessage.DataSet[DicomTags.BodyPartExamined].GetString(0, string.Empty), Institution = dicomMessage.DataSet[DicomTags.InstitutionName].GetString(0, string.Empty), StationName = dicomMessage.DataSet[DicomTags.StationName].GetString(0, string.Empty), Department = dicomMessage.DataSet[DicomTags.InstitutionalDepartmentName].GetString(0, string.Empty), PerfPhysician = dicomMessage.DataSet[DicomTags.PerformingPhysiciansName].GetString(0, string.Empty), SeriesDate = dicomMessage.DataSet[DicomTags.SeriesDate].GetDateTime(0, dt), SeriesTime = dicomMessage.DataSet[DicomTags.SeriesTime].GetDateTime(0, dt), SeriesDescription = dicomMessage.DataSet[DicomTags.SeriesDescription].GetString(0, string.Empty), PerformedProcedureStepStartDate = dicomMessage.DataSet[DicomTags.PerformedProcedureStepStartDate].GetDateTime(0, dt), PerformedProcedureStepStartTime = dicomMessage.DataSet[DicomTags.PerformedProcedureStepStartTime].GetDateTime(0, dt), }; var instance = new Instance() { SopInstanceUid = dicomMessage.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty), SopClassUid = dicomMessage.DataSet[DicomTags.SopClassUid].GetString(0, string.Empty), InstanceNumber = dicomMessage.DataSet[DicomTags.InstanceNumber].GetString(0, string.Empty), ContentDate = dicomMessage.DataSet[DicomTags.ContentDate].GetDateTime(0, dt), ContentTime = dicomMessage.DataSet[DicomTags.ContentTime].GetDateTime(0, dt) }; if (string.IsNullOrEmpty(study.StudyUid) || string.IsNullOrEmpty(series.SeriesUid) || string.IsNullOrEmpty(instance.SopInstanceUid)) { result.Successful = false; } // Get Patient Db Object using (var context = new PacsContext()) { Patient dbPatient = null; var dbStudy = InsertStudy(context, study, patient, out dbPatient); // Patient and study is exist in db now var dbSeries = InsertSeries(context, series, dbStudy, dbPatient); // insert instance var dbInstance = InsertImage(context, instance, dbSeries, dbStudy, dbPatient); var dbFile = InsertFile(context, dbInstance, dbSeries, dbStudy, dbPatient); var dicomFile = new DicomFile(dicomMessage, dbFile.FilePath); if (!Directory.Exists(Path.GetDirectoryName(dbFile.FilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(dbFile.FilePath)); } dicomFile.Save(); context.SaveChanges(); result.DicomStatus = DicomStatuses.Success; } return(result); }
public IDevice LookupDevice(IServerPartition partition, AssociationParameters association, out bool isNew) { isNew = false; Device device = null; using (var ctx = new PacsContext()) { var part = (from p in ctx.ServerPartitions select p).FirstOrDefault(); if (part != null) { device = part.Devices.FirstOrDefault(d => d.AeTitle.Equals(association.CallingAE)); } if (device == null) { if (!partition.AcceptAnyDevice) { return(null); } if (partition.AutoInsertDevice) { device = new Device() { AeTitle = association.CallingAE, Enabled = true, Description = string.Format("AE: {0}", association.CallingAE), Hostname = association.RemoteEndPoint.Address.ToString(), Port = 104, AllowQuery = true, AllowRetrieve = true, AllowStorage = true, ServerPartitionPK = part.Id, LastAccessTime = DateTime.Now }; ctx.Devices.Add(device); ctx.SaveChanges(); isNew = true; } } if (device != null) { if (device.Dhcp && !association.RemoteEndPoint.Address.ToString().Equals(device.Hostname)) { device.Hostname = association.RemoteEndPoint.Address.ToString(); device.LastAccessTime = DateTime.Now; ctx.SaveChanges(); } else if (!isNew) { device.LastAccessTime = DateTime.Now; ctx.SaveChanges(); } } } return(device); }
public static Device LookupDevice(ServerPartition partition, AssociationParameters association, out bool isNew) { isNew = false; Device device = null; using (var ctx = new PacsContext()) { var part = (from p in ctx.ServerPartitions select p).FirstOrDefault(); if (part != null) { device = part.Devices.FirstOrDefault(d => d.AeTitle.Equals(association.CallingAE)); } if (device == null) { if (!partition.AcceptAnyDevice) { return null; } if (partition.AutoInsertDevice) { device = new Device { AeTitle = association.CallingAE, Enabled = true, Description = string.Format("AE: {0}", association.CallingAE), //TODO Port = 104, AllowQuery = true, AllowRetrieve = true, AllowStorage = true, ServerPartitionPK = part.Id, LastAccessTime = DateTime.Now }; ctx.Devices.Add(device); ctx.SaveChanges(); isNew = true; } } if (device != null) { if (device.Dhcp && !association.RemoteEndPoint.Address.ToString().Equals(device.Hostname)) { device.Hostname = association.RemoteEndPoint.Address.ToString(); device.LastAccessTime = DateTime.Now; ctx.SaveChanges(); } else if (!isNew) { device.LastAccessTime = DateTime.Now; ctx.SaveChanges(); } } } return device; }