Exemplo n.º 1
0
        /// <summary>
        /// Adds a new row to the DataSet Study Table (MyStudyTable) if the DicomDataSet StudyInstanceUID 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 FillStudiesData(DicomDataSet ds, MyDataSet instanceDataSet, bool updateExistentStudy, string retrieveAe)
        {
            string patientIdentification = ds.MyGetStringValue(DicomTag.PatientID, AutoTruncate, instanceDataSet.MyPatientTable.PatientIdentificationColumn.MaxLength);
            string studyInstanceUID      = ds.MyGetStringValue(DicomTag.StudyInstanceUID, AutoTruncate, instanceDataSet.MyStudyTable.StudyStudyInstanceUIDColumn.MaxLength);

            if (null == studyInstanceUID)
            {
                return;
            }

            MyDataSet.MyStudyTableRow studyRow = null;
            DataRow[] rows = instanceDataSet.MyStudyTable.Select(string.Format("StudyStudyInstanceUID = '{0}'", studyInstanceUID));
            MyDataSet.MyStudyTableRow[] studyRows = (MyDataSet.MyStudyTableRow[])rows;
            if (studyRows != null && studyRows.Length > 0)
            {
                studyRow = studyRows[0];
            }

            bool studyFound = (null != studyRow);

            if (!studyFound)
            {
                studyRow = instanceDataSet.MyStudyTable.NewMyStudyTableRow();

                studyRow.StudyPatientId        = -1;          // Fill this in later
                studyRow.StudyStudyInstanceUID = studyInstanceUID;

                instanceDataSet.MyStudyTable.AddMyStudyTableRow(studyRow);
            }
            else if (!updateExistentStudy)
            {
                return;
            }

            FillStudyInformation(studyRow,
                                 ds,
                                 instanceDataSet,
                                 patientIdentification,
                                 studyInstanceUID,
                                 retrieveAe,
                                 updateExistentStudy);
        }
Exemplo n.º 2
0
        /// <summary>
        /// If the ‘update’ parameter is true, replaces all the DataSet Study table information with the corresponding information from the DicomDataSet.
        /// </summary>
        /// <param name="study">Row of the 'study' 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="patientIdentification">The PatientID that corresponds to the study of the study row being updated</param>
        /// <param name="studyInstanceUID">The StudyInstanceUID of the study row being udpated.</param>
        /// <param name="retrieveAE">retrieveAe">AE Title of the client doing the retrieval</param>
        /// <param name="update">If 'true', updates the DataSet Study 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 'study' table
        /// <list>
        /// <item>StudyDate</item>
        /// <item>AccessionNumber</item>
        /// <item>StudyDescription</item>
        /// <item>StudyReferringPhysiciansName</item>
        /// </list>
        /// </remarks>
        private void FillStudyInformation(MyDataSet.MyStudyTableRow study, DicomDataSet ds, MyDataSet instanceDataSet, string patientIdentification, string studyInstanceUID, string retrieveAE, bool update)
        {
            // StudyDate
            DateTime?studyDate = ds.MyGetDateTime(DicomTag.StudyDate, DicomTag.StudyTime);

            if (CanSetValue(studyDate, update, study, instanceDataSet.MyStudyTable.StudyStudyDateColumn))
            {
                study.StudyStudyDate = studyDate.Value;
            }

            // AccessionNumber
            string accessionNumber = ds.MyGetStringValue(DicomTag.AccessionNumber, AutoTruncate, instanceDataSet.MyStudyTable.StudyAccessionNumberColumn.MaxLength);

            if (CanSetValue(accessionNumber, update, study, instanceDataSet.MyStudyTable.StudyAccessionNumberColumn))
            {
                study.StudyAccessionNumber = accessionNumber;
            }

            // StudyDescription
            string studyStudyDescription = ds.MyGetStringValue(DicomTag.StudyDescription, AutoTruncate, instanceDataSet.MyStudyTable.StudyStudyDescriptionColumn.MaxLength);

            if (CanSetValue(studyStudyDescription, update, study, instanceDataSet.MyStudyTable.StudyStudyDescriptionColumn))
            {
                study.StudyStudyDescription = studyStudyDescription;
            }

            // StudyReferringPhysiciansName
            string referringPhysiciansName = ds.MyGetStringValue(DicomTag.ReferringPhysicianName, AutoTruncate, instanceDataSet.MyStudyTable.StudyReferringPhysiciansNameColumn.MaxLength);

            if (CanSetValue(referringPhysiciansName, update, study, instanceDataSet.MyStudyTable.StudyReferringPhysiciansNameColumn))
            {
                study.StudyReferringPhysiciansName = referringPhysiciansName;
            }

            string studyStudyId = ds.MyGetStringValue(DicomTag.StudyID, AutoTruncate, instanceDataSet.MyStudyTable.StudyStudyIdColumn.MaxLength);

            if (CanSetValue(studyStudyId, update, study, instanceDataSet.MyStudyTable.StudyStudyIdColumn))
            {
                study.StudyStudyId = studyStudyId;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }