/// <summary> /// Insert a dicom file into the database. /// </summary> /// <param name="filename"></param> /// <returns></returns> public InsertReturn Insert(string filename) { DicomDataSet dcm; string patientID, studyInstanceUID; string seriesInstanceUID, sopInstanceUID; InsertReturn iret = InsertReturn.Success; dcm = new DicomDataSet(); if (dcm == null) { return(InsertReturn.Error); } try { FileInfo src = new FileInfo(filename); DirectoryInfo dstDir = new DirectoryInfo(ImageDir); if (src.Directory.FullName != dstDir.FullName) { filename = dstDir.FullName + src.Name; src.CopyTo(filename); } dcm.Load(filename, DicomDataSetLoadFlags.LoadAndClose); } catch { return(InsertReturn.Error); } patientID = AddPatient(dcm, ref iret); if (iret != InsertReturn.Success && iret != InsertReturn.Exists) { return(iret); } studyInstanceUID = AddStudy(dcm, patientID, ref iret); if (iret != InsertReturn.Success && iret != InsertReturn.Exists) { return(iret); } seriesInstanceUID = AddSeries(dcm, studyInstanceUID, patientID, ref iret); if (iret != InsertReturn.Success && iret != InsertReturn.Exists) { return(iret); } sopInstanceUID = AddImage(dcm, seriesInstanceUID, studyInstanceUID, patientID, filename, ref iret); if (iret == InsertReturn.Success) { Save(); } return(iret); }
private string AddStudy(DicomDataSet dcm, string patientID, ref InsertReturn ret) { string studyInstanceUID; string filter; ret = InsertReturn.Success; studyInstanceUID = Utils.GetStringValue(dcm, DemoDicomTags.StudyInstanceUID); if (studyInstanceUID.Length == 0) { ret = InsertReturn.Error; return(""); } lock (adoDatasetLock) { filter = "StudyInstanceUID = '" + studyInstanceUID + "' AND PatientID = '" + patientID + "'"; if (!RecordExists(ds.Tables["Studies"], filter)) { DataRow dr; dr = ds.Tables["Studies"].NewRow(); if (dr != null) { dr["StudyInstanceUID"] = studyInstanceUID; dr["StudyID"] = Utils.GetStringValue(dcm, DemoDicomTags.StudyID); dr["StudyDescription"] = Utils.GetStringValue(dcm, DemoDicomTags.StudyDescription); dr["AccessionNumber"] = Utils.GetStringValue(dcm, DemoDicomTags.AccessionNumber); dr["PatientID"] = patientID; dr["PatientName"] = Utils.GetStringValue(dcm, DemoDicomTags.PatientName); dr["ReferringDrName"] = Utils.GetStringValue(dcm, DemoDicomTags.ReferringPhysicianName); try { dr["StudyDate"] = DateTime.Parse(Utils.GetStringValue(dcm, DemoDicomTags.StudyDate)); dr["StudyTime"] = DateTime.Parse(Utils.GetStringValue(dcm, DemoDicomTags.StudyTime)); } catch { } ds.Tables["Studies"].Rows.Add(dr); } } else { ret = InsertReturn.Exists; } } return(studyInstanceUID); }
private string AddPatient(DicomDataSet dcm, ref InsertReturn ret) { string patientID; ret = InsertReturn.Success; patientID = Utils.GetStringValue(dcm, DemoDicomTags.PatientID); if (patientID.Length == 0) { ret = InsertReturn.Error; return(""); } lock (adoDatasetLock) { if (!RecordExists(ds.Tables["Patients"], "PatientID = '" + patientID + "'")) { DataRow dr; dr = ds.Tables["Patients"].NewRow(); if (dr != null) { dr["PatientID"] = patientID; dr["PatientName"] = Utils.GetStringValue(dcm, DemoDicomTags.PatientName); dr["PatientSex"] = Utils.GetStringValue(dcm, DemoDicomTags.PatientSex); dr["EthnicGroup"] = Utils.GetStringValue(dcm, DemoDicomTags.EthnicGroup); dr["PatientComments"] = Utils.GetStringValue(dcm, DemoDicomTags.PatientComments); try { dr["PatientBirthDate"] = DateTime.Parse(Utils.GetStringValue(dcm, DemoDicomTags.PatientBirthDate)); dr["PatientBirthTime"] = DateTime.Parse(Utils.GetStringValue(dcm, DemoDicomTags.PatientBirthTime)); } catch { } ds.Tables["Patients"].Rows.Add(dr); } } else { ret = InsertReturn.Exists; } } return(patientID); }
public InsertReturn Insert(DicomDataSet dcm, string filename) { string patientID; string studyInstanceUID; string seriesInstanceUID; string sopInstanceUID; InsertReturn ret = InsertReturn.Success; patientID = AddPatient(dcm, ref ret); if (ret != InsertReturn.Success && ret != InsertReturn.Exists) { return(ret); } studyInstanceUID = AddStudy(dcm, patientID, ref ret); seriesInstanceUID = AddSeries(dcm, studyInstanceUID, patientID, ref ret); sopInstanceUID = AddImage(dcm, seriesInstanceUID, studyInstanceUID, patientID, filename, ref ret); if (ret == InsertReturn.Success) { Save(); } return(ret); }
private string AddImage(DicomDataSet dcm, string seriesInstanceUID, string studyInstanceUID, string patientID, string filename, ref InsertReturn ret) { string sopInstanceUID; string filter; ret = InsertReturn.Success; sopInstanceUID = Utils.GetStringValue(dcm, DemoDicomTags.SOPInstanceUID); if (sopInstanceUID.Length == 0) { ret = InsertReturn.Error; return(""); } filter = "StudyInstanceUID = '" + studyInstanceUID + "' AND SeriesInstanceUID = '" + seriesInstanceUID + "'"; filter += " AND SOPInstanceUID = '" + sopInstanceUID + "'"; lock (adoDatasetLock) { if (!RecordExists(ds.Tables["Images"], filter)) { DataRow dr; dr = ds.Tables["Images"].NewRow(); if (dr != null) { string temp; dr["SOPInstanceUID"] = sopInstanceUID; dr["SeriesInstanceUID"] = seriesInstanceUID; dr["StudyInstanceUID"] = studyInstanceUID; dr["PatientID"] = patientID; dr["ReferencedFile"] = filename; temp = Utils.GetStringValue(dcm, DemoDicomTags.SOPClassUID); if (temp.Length == 0) { temp = Utils.GetStringValue(dcm, DemoDicomTags.MediaStorageSOPClassUID); if (temp.Length == 0) { temp = "1.1.1.1"; } } dr["SOPClassUID"] = temp; temp = Utils.GetStringValue(dcm, DemoDicomTags.TransferSyntaxUID); if (temp.Length == 0) { temp = DicomUidType.ImplicitVRLittleEndian; } dr["TransferSyntaxUID"] = temp; temp = Utils.GetStringValue(dcm, DemoDicomTags.InstanceNumber); if (temp.Length > 0) { dr["InstanceNumber"] = Convert.ToInt32(temp); } ds.Tables["Images"].Rows.Add(dr); } } else { ret = InsertReturn.Exists; } } return(sopInstanceUID); }
private string AddSeries(DicomDataSet dcm, string studyInstanceUID, string patientID, ref InsertReturn ret) { string seriesInstanceUID; string filter; ret = InsertReturn.Success; seriesInstanceUID = Utils.GetStringValue(dcm, DemoDicomTags.SeriesInstanceUID); if (seriesInstanceUID.Length == 0) { ret = InsertReturn.Error; return(""); } filter = "StudyInstanceUID = '" + studyInstanceUID + "' AND SeriesInstanceUID = '" + seriesInstanceUID + "'"; lock (adoDatasetLock) { if (!RecordExists(ds.Tables["Series"], filter)) { DataRow dr; dr = ds.Tables["Series"].NewRow(); if (dr != null) { string temp; temp = Utils.GetStringValue(dcm, DemoDicomTags.SeriesNumber); dr["SeriesInstanceUID"] = seriesInstanceUID; dr["StudyInstanceUID"] = studyInstanceUID; dr["Modality"] = Utils.GetStringValue(dcm, DemoDicomTags.Modality); dr["PatientID"] = patientID; try { dr["SeriesDate"] = DateTime.Parse(Utils.GetStringValue(dcm, DemoDicomTags.SeriesDate)); } catch { } try { if (temp.Length > 0) { dr["SeriesNumber"] = Convert.ToInt32(temp); } } catch { } ds.Tables["Series"].Rows.Add(dr); } } else { ret = InsertReturn.Exists; } } return(seriesInstanceUID); }