protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            // Setup the insert parameters
            var parms = new InsertInstanceParameters();

            _file.LoadDicomFields(parms);
            parms.ServerPartitionKey = _storageLocation.ServerPartitionKey;
            parms.StudyStorageKey    = _storageLocation.Key;

            // Get any extensions that exist and process them
            var ep         = new ProcessorInsertExtensionPoint();
            var extensions = ep.CreateExtensions();

            foreach (IInsertExtension e in extensions)
            {
                e.InsertExtension(_storageLocation.ServerPartitionKey, parms, _file);
            }

            // Get the Insert Instance broker and do the insert
            var insert = updateContext.GetBroker <IInsertInstance>();

            if (_file.DataSet.Contains(DicomTags.SpecificCharacterSet))
            {
                string cs = _file.DataSet[DicomTags.SpecificCharacterSet].ToString();
                parms.SpecificCharacterSet = cs;
            }

            _insertKey = insert.FindOne(parms);

            // If the Request Attributes Sequence is in the dataset, do an insert.
            if (_file.DataSet.Contains(DicomTags.RequestAttributesSequence))
            {
                var attribute = _file.DataSet[DicomTags.RequestAttributesSequence] as DicomAttributeSQ;
                if (attribute != null && !attribute.IsEmpty)
                {
                    foreach (DicomSequenceItem sequenceItem in (DicomSequenceItem[])attribute.Values)
                    {
                        var requestParms = new RequestAttributesInsertParameters();
                        sequenceItem.LoadDicomFields(requestParms);
                        requestParms.SeriesKey = _insertKey.SeriesKey;

                        var insertRequest = updateContext.GetBroker <IInsertRequestAttributes>();
                        insertRequest.Execute(requestParms);
                    }
                }
            }
        }
예제 #2
0
		protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
		{
			// Setup the insert parameters
			var parms = new InsertInstanceParameters();
			_file.LoadDicomFields(parms);
			parms.ServerPartitionKey = _storageLocation.ServerPartitionKey;
			parms.StudyStorageKey = _storageLocation.Key;

            // Get any extensions that exist and process them
		    var ep = new ProcessorInsertExtensionPoint();
		    var extensions = ep.CreateExtensions();
            foreach (IInsertExtension e in extensions)
                e.InsertExtension(parms, _file);
            
			// Get the Insert Instance broker and do the insert
			var insert = updateContext.GetBroker<IInsertInstance>();

			if (_file.DataSet.Contains(DicomTags.SpecificCharacterSet))
			{
				string cs = _file.DataSet[DicomTags.SpecificCharacterSet].ToString();
				parms.SpecificCharacterSet = cs;
			}

			_insertKey = insert.FindOne(parms);

			// If the Request Attributes Sequence is in the dataset, do an insert.
			if (_file.DataSet.Contains(DicomTags.RequestAttributesSequence))
			{
				var attribute = _file.DataSet[DicomTags.RequestAttributesSequence] as DicomAttributeSQ;
				if (attribute != null && !attribute.IsEmpty)
				{
					foreach (DicomSequenceItem sequenceItem in (DicomSequenceItem[]) attribute.Values)
					{
						var requestParms = new RequestAttributesInsertParameters();
						sequenceItem.LoadDicomFields(requestParms);
						requestParms.SeriesKey = _insertKey.SeriesKey;

						var insertRequest = updateContext.GetBroker<IInsertRequestAttributes>();
						insertRequest.Execute(requestParms);
					}
				}
			}
		}
        private void UpdateDatabase()
        {
            var patientUpdate = new PatientUpdateColumns();
            var seriesUpdate  = new SeriesUpdateColumns();
            var studyUpdate   = new StudyUpdateColumns();

            // Update Patient level info. Different cases can occur here:
            //      A) Patient demographic info is not changed ==> update the current patient
            //      B) New patient demographics matches (another) existing patient in the datbase
            //              ==> Transfer the study to that patient. This means the study count on both patients must be updated.
            //                  The current patient should also be deleted if there's no more study attached to it after the transfer.
            //      C) New patient demographics doesn't match any patient in the database
            //              ==> A new patient should be created for this study. The study count on the current patient should be updated
            //                  and the patient should also be deleted if this is the only study attached to it.
            if (_patientInfoIsNotChanged)
            {
                _newPatient = _curPatient;
            }
            else if (_newPatient == null)
            {
                // No matching patient in the database. We should create a new patient for this study
                _newPatient = CreateNewPatient(_newPatientInfo);
            }
            else
            {
                // There's already patient in the database with the new patient demographics
                // The study should be attached to that patient.
                TransferStudy(_study.Key, _oldPatientInfo, _newPatient);
            }

            // Copy the existing valus over into the study & series objects
            // Note, this sets up an update statement that will update the key columns for
            // Study Instance UID, Series Instance UID, however, note that the columns will not
            // actually change value.  Its alittle ugly, but it will make it so if we add new
            // columns in the future, it just "works".
            _file.DataSet.LoadDicomFields(patientUpdate);
            _file.DataSet.LoadDicomFields(studyUpdate);
            _file.DataSet.LoadDicomFields(seriesUpdate);

            // Get any extensions that exist and process them
            var ep         = new ProcessorInsertExtensionPoint();
            var extensions = ep.CreateExtensions();

            foreach (IInsertExtension e in extensions)
            {
                e.UpdateExtension(patientUpdate, studyUpdate, seriesUpdate, _file);
            }

            UpdatePatientEncoding(_newPatient, patientUpdate);
            SetStudyEncoding(_study, studyUpdate);

            // Update the Study table
            var patientUpdateBroker = UpdateContext.GetBroker <IPatientEntityBroker>();

            patientUpdateBroker.Update(_newPatient.Key, patientUpdate);

            // Update the Study table
            var studyUpdateBroker = UpdateContext.GetBroker <IStudyEntityBroker>();

            studyUpdateBroker.Update(_study.Key, studyUpdate);

            // Update the Series table
            var seriesUpdateBroker = UpdateContext.GetBroker <ISeriesEntityBroker>();

            seriesUpdateBroker.Update(_curSeries.Key, seriesUpdate);

            // If the Request Attributes Sequence is in the dataset, do an insert.
            // Small hole in this that if the value of this sequence has changed, both the old and
            // the new values will stay in the database, not much to do about it, except
            // reprocess the whole series, which doesn't seem worth it.
            if (_file.DataSet.Contains(DicomTags.RequestAttributesSequence))
            {
                var attribute = _file.DataSet[DicomTags.RequestAttributesSequence] as DicomAttributeSQ;
                if (attribute != null && !attribute.IsEmpty)
                {
                    foreach (DicomSequenceItem sequenceItem in (DicomSequenceItem[])attribute.Values)
                    {
                        var requestParms = new RequestAttributesInsertParameters();
                        sequenceItem.LoadDicomFields(requestParms);
                        requestParms.SeriesKey = _curSeries.Key;

                        var insertRequest = UpdateContext.GetBroker <IInsertRequestAttributes>();
                        insertRequest.Execute(requestParms);
                    }
                }
            }
        }
		private void UpdateDatabase()
		{
			var patientUpdate = new PatientUpdateColumns();
			var seriesUpdate = new SeriesUpdateColumns();
			var studyUpdate = new StudyUpdateColumns();

			// Update Patient level info. Different cases can occur here: 
			//      A) Patient demographic info is not changed ==> update the current patient
			//      B) New patient demographics matches (another) existing patient in the datbase 
			//              ==> Transfer the study to that patient. This means the study count on both patients must be updated.
			//                  The current patient should also be deleted if there's no more study attached to it after the transfer.
			//      C) New patient demographics doesn't match any patient in the database
			//              ==> A new patient should be created for this study. The study count on the current patient should be updated
			//                  and the patient should also be deleted if this is the only study attached to it.
			if (_patientInfoIsNotChanged)
			{
				_newPatient = _curPatient;
			}
			else if (_newPatient == null)
			{
				// No matching patient in the database. We should create a new patient for this study
				_newPatient = CreateNewPatient(_newPatientInfo);
			}
			else
			{
				// There's already patient in the database with the new patient demographics
				// The study should be attached to that patient.
				TransferStudy(_study.Key, _oldPatientInfo, _newPatient);
			}

			// Copy the existing valus over into the study & series objects
			// Note, this sets up an update statement that will update the key columns for
			// Study Instance UID, Series Instance UID, however, note that the columns will not
			// actually change value.  Its alittle ugly, but it will make it so if we add new
			// columns in the future, it just "works".
			_file.DataSet.LoadDicomFields(patientUpdate);
			_file.DataSet.LoadDicomFields(studyUpdate);
			_file.DataSet.LoadDicomFields(seriesUpdate);

			// Get any extensions that exist and process them
			var ep = new ProcessorInsertExtensionPoint();
			var extensions = ep.CreateExtensions();
			foreach (IInsertExtension e in extensions)
				e.UpdateExtension(_partition.Key, patientUpdate,studyUpdate,seriesUpdate, _file);

			UpdatePatientEncoding(_newPatient, patientUpdate);
			SetStudyEncoding(_study, studyUpdate);

			// Update the Study table
			var patientUpdateBroker = UpdateContext.GetBroker<IPatientEntityBroker>();
			patientUpdateBroker.Update(_newPatient.Key, patientUpdate);

			// Update the Study table
			var studyUpdateBroker = UpdateContext.GetBroker<IStudyEntityBroker>();
			studyUpdateBroker.Update(_study.Key, studyUpdate);

			// Update the Series table
			var seriesUpdateBroker = UpdateContext.GetBroker<ISeriesEntityBroker>();
			seriesUpdateBroker.Update(_curSeries.Key, seriesUpdate);

			// If the Request Attributes Sequence is in the dataset, do an insert.
			// Small hole in this that if the value of this sequence has changed, both the old and
			// the new values will stay in the database, not much to do about it, except
			// reprocess the whole series, which doesn't seem worth it.
			if (_file.DataSet.Contains(DicomTags.RequestAttributesSequence))
			{
				var attribute = _file.DataSet[DicomTags.RequestAttributesSequence] as DicomAttributeSQ;
				if (attribute != null && !attribute.IsEmpty)
				{
					foreach (DicomSequenceItem sequenceItem in (DicomSequenceItem[])attribute.Values)
					{
						var requestParms = new RequestAttributesInsertParameters();
						sequenceItem.LoadDicomFields(requestParms);
						requestParms.SeriesKey = _curSeries.Key;

						var insertRequest = UpdateContext.GetBroker<IInsertRequestAttributes>();
						insertRequest.Execute(requestParms);
					}
				}
			}
		}