/// <summary> /// If the ‘update’ parameter is true, replaces all the DataSet Patient table information with the corresponding information from the DicomDataSet. /// </summary> /// <param name="patient">Row of the patient table that is being udpated</param> /// <param name="ds">The Leadtools.Dicom.DicomDataSet that is being stored</param> /// <param name="instanceDataSet">The DataSet that contains the patient, study, series, and instance tables</param> /// <param name="patientId">The PatientID of the patient being updated</param> /// <param name="retrieveAE">retrieveAe">AE Title of the client doing the retrieval</param> /// <param name="update">If 'true', updates the DataSet Patient table information with the corresponding information from the DicomDataSet</param> /// <remarks> /// This method needs to change based on your schema. For the MyDicomDb schema, we update all fields in the patient table /// <list> /// <item>PatientName</item> /// <item>PatientBirthday</item> /// <item>PatientSex</item> /// <item>PatientComments</item> /// </list> /// </remarks> private void FillPatientInformation(MyDataSet.MyPatientTableRow patient, DicomDataSet ds, MyDataSet instanceDataSet, string patientId, string retrieveAE, bool update) { try { // PatientName string patientName = ds.MyGetStringValue(DicomTag.PatientName, AutoTruncate, instanceDataSet.MyPatientTable.PatientNameColumn.MaxLength); if (CanSetValue(patientName, update, patient, instanceDataSet.MyPatientTable.PatientNameColumn)) { patient.PatientName = patientName; } // PatientBirthday DateTime?patientBirthDate = ds.MyGetDateTime(DicomTag.PatientBirthDate, DicomTag.PatientBirthTime); if (CanSetValue(patientBirthDate, update, patient, instanceDataSet.MyPatientTable.PatientBirthdayColumn)) { patient.PatientBirthday = patientBirthDate.Value; } // PatientSex char patientSex = ds.GetValue <char>(DicomTag.PatientSex, 'X'); string patientSexString = string.Empty; switch (patientSex) { case 'O': patientSexString = "O"; break; case 'M': patientSexString = "M"; break; case 'F': patientSexString = "F"; break; } if (CanSetValue(patientSex, update, patient, instanceDataSet.MyPatientTable.PatientSexColumn)) { patient.PatientSex = patientSexString; } // PatientComments string patientComments = ds.MyGetStringValue(DicomTag.PatientComments, AutoTruncate, instanceDataSet.MyPatientTable.PatientCommentsColumn.MaxLength); if (CanSetValue(patientComments, update, patient, instanceDataSet.MyPatientTable.PatientCommentsColumn)) { patient.PatientComments = patientComments; } } catch (Exception ex) { throw ex; } }
/// <summary> /// Adds a new row to the DataSet Patient table (MyPatientTable) if the DicomDataSet PatientID does not already exist /// </summary> /// <param name="ds">The Leadtools.Dicom.DicomDataSet that is being stored</param> /// <param name="instanceDataSet">The DataSet that contains the patient, study, series, and instance tables</param> /// <param name="updateExistentPatient">If 'true', update the existing patient with information from dicomDataSet</param> /// <param name="retrieveAe">retrieveAe">AE Title of the client doing the retrieval</param> private void FillPatientData(DicomDataSet ds, MyDataSet instanceDataSet, bool updateExistentPatient, string retrieveAe) { string patientId = ds.MyGetStringValue(DicomTag.PatientID, AutoTruncate, instanceDataSet.MyPatientTable.PatientIdColumn.MaxLength); if (null == patientId) { return; } MyDataSet.MyPatientTableRow patientRow = null; DataRow[] rows = instanceDataSet.MyPatientTable.Select(string.Format("PatientIdentification = '{0}'", patientId)); MyDataSet.MyPatientTableRow[] patientRows = (MyDataSet.MyPatientTableRow[])rows; if (patientRows != null && patientRows.Length > 0) { patientRow = patientRows[0]; } bool patientFound = (null != patientRow); if (!patientFound) { patientRow = instanceDataSet.MyPatientTable.NewMyPatientTableRow(); patientRow.PatientIdentification = patientId; instanceDataSet.MyPatientTable.AddMyPatientTableRow(patientRow); } else if (!updateExistentPatient) { return; } FillPatientInformation(patientRow, ds, instanceDataSet, patientId, retrieveAe, updateExistentPatient); }
internal static void UpdateCompositeInstance ( MyDataSet compositeInstanceDataSet, DbConnection connection, MyUpdateTableDelegate updateTable ) { try { DbTransaction DbTransaction = null; connection.Open(); try { try { MyDataSet.MyPatientTableRow patientRow = compositeInstanceDataSet.Tables["MyPatientTable"].Rows[0] as MyDataSet.MyPatientTableRow; MyDataSet.MyStudyTableRow studyRow = compositeInstanceDataSet.Tables["MyStudyTable"].Rows[0] as MyDataSet.MyStudyTableRow; MyDataSet.MySeriesTableRow seriesRow = compositeInstanceDataSet.Tables["MySeriesTable"].Rows[0] as MyDataSet.MySeriesTableRow; MyDataSet.MyInstanceTableRow dimageRow = compositeInstanceDataSet.Tables["MyInstanceTable"].Rows[0] as MyDataSet.MyInstanceTableRow; int?patientId = -1; int?studyId = -1; int?seriesId = -1; // ************************* // Patient // ************************* DbTransaction = connection.BeginTransaction(); UpdatePatientDataset(compositeInstanceDataSet, connection, DbTransaction, updateTable); DbTransaction.Commit(); // Use the last generated PatientId -- if RowState is 'unchanged', nothing gets updated in the patientRow // In this case, we need to read the patientId from the database patientId = patientRow.PatientId; if (patientId == -1) { patientId = GetIntValue(connection, "MyPatientTable", "patientId", "PatientIdentification", patientRow.PatientIdentification); } // ************************* // Study // ************************* DbTransaction = connection.BeginTransaction(); if ((studyRow.RowState != DataRowState.Unchanged && studyRow.StudyPatientId == -1) && (patientId != null)) { studyRow.StudyPatientId = patientId.Value; } UpdateStudyDataset(compositeInstanceDataSet, connection, DbTransaction, updateTable); DbTransaction.Commit(); studyId = studyRow.StudyId; if (studyId == -1) { studyId = GetIntValue(connection, "MyStudyTable", "studyId", "StudyStudyInstanceUID", studyRow.StudyStudyInstanceUID); } // ************************* // Series // ************************* // Use the last generated StudyId DbTransaction = connection.BeginTransaction(); if ((seriesRow.RowState != DataRowState.Unchanged && seriesRow.SeriesStudyId == -1) && (studyId != null)) { seriesRow.SeriesStudyId = studyId.Value; } UpdateSeriesDataset(compositeInstanceDataSet, connection, DbTransaction, updateTable); DbTransaction.Commit(); seriesId = seriesRow.SeriesId; if (seriesId == -1) { seriesId = GetIntValue(connection, "MySeriesTable", "SeriesId", "SeriesSeriesInstanceUID", seriesRow.SeriesSeriesInstanceUID); } // ************************* // Instance // ************************* // Use the last generated SeriesId DbTransaction = connection.BeginTransaction(); if ((dimageRow.RowState != DataRowState.Unchanged && dimageRow.ImageSeriesId == -1) && (seriesId != null)) { dimageRow.ImageSeriesId = seriesId.Value; } UpdateInstanceDataset(compositeInstanceDataSet, connection, DbTransaction, updateTable); DbTransaction.Commit(); } catch (Exception exception) { System.Diagnostics.Debug.Assert(false, exception.ToString()); DbTransaction.Rollback(); throw; } } finally { connection.Close(); } compositeInstanceDataSet.AcceptChanges(); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); System.Diagnostics.Debug.Assert(false); throw; } }