Пример #1
0
        private void UpdateCurrentPatient()
        {
            Platform.Log(LogLevel.Info, "Update current patient record...");
            IPatientEntityBroker patientUpdateBroker = UpdateContext.GetBroker <IPatientEntityBroker>();

            patientUpdateBroker.Update(_curPatient);
        }
Пример #2
0
        private void UpdatePatientEncoding(Patient patient)
        {
            // Note: patient can be an existing one or a new one

            // set the SpecificCharacterSet of the patient and study record. This will update the database
            // and force Patient/Study/Series level query response to be encoded in UTF8. Image level responses
            // will be encoded using the character set in the image (see QueryScpExtension)
            //
            if (atLeastOneFileUpdatedToUTF8)
            {
                // Only update the db if necessary
                if (!IsUTF8(patient.SpecificCharacterSet))
                {
                    Platform.Log(LogLevel.Info, "Updating encoding for patient information in the database to UTF8 [ Name={0}, ID={1} ]", patient.Name, patient.PatientId);

                    // update to UTF8
                    patient.SpecificCharacterSet = UTF8;

                    // This method is called at the very end of UpdateDatabase(), update the database now
                    IPatientEntityBroker broker  = UpdateContext.GetBroker <IPatientEntityBroker>();
                    PatientUpdateColumns columns = new PatientUpdateColumns()
                    {
                        SpecificCharacterSet = UTF8
                    };
                    broker.Update(patient.Key, columns);
                }
            }
        }
Пример #3
0
        private Order FindOrderForStudy()
        {
            var select = new OrderSelectCriteria();

            select.ServerPartitionKey.EqualTo(_study.ServerPartitionKey);
            select.AccessionNumber.EqualTo(_study.AccessionNumber);
            select.PatientId.EqualTo(_study.PatientId);

            var broker = UpdateContext.GetBroker <IOrderEntityBroker>();

            return(broker.FindOne(select));
        }
Пример #4
0
        private void UpdateDatabase()
        {
            // Reload the StudyStorage and Study tables.
            LoadEntities();

            UpdateEntity(_study);
            UpdateEntity(_curPatient);
            UpdateEntity(_storage);

            SetStudyEncoding(_study);

            var order = FindOrderForStudy();

            _study.OrderKey = order == null ? null : order.Key;

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

            studyUpdateBroker.Update(_study);

            // Update the StudyStorage table
            var storageUpdateBroker = UpdateContext.GetBroker <IStudyStorageEntityBroker>();

            storageUpdateBroker.Update(_storage);

            // 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 (!_patientInfoChanged)
            {
                UpdatePatientDemographics(_curPatient.GetKey(), _newPatientInfo);
            }
            else if (_newPatient == null)
            {
                // No matching patient in the database. We should create a new patient for this study
                _newPatient = CreateNewPatient(_newPatientInfo);
                UpdatePatientDemographics(_newPatient.GetKey(), _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);
                UpdatePatientDemographics(_newPatient.GetKey(), _newPatientInfo);
            }
        }
        private void TransferStudy(ServerEntityKey studyKey, PatientInfo oldPatient, Patient newPatient)
        {
            Platform.Log(LogLevel.Info, "Transferring study from {0} [ID={1}] to {2} [ID={3}]",
                         oldPatient.Name, oldPatient.PatientId, newPatient.PatientsName, newPatient.PatientId);

            var attachStudyToPatientBroker = UpdateContext.GetBroker <IAttachStudyToPatient>();
            var parms = new AttachStudyToPatientParamaters
            {
                StudyKey      = studyKey,
                NewPatientKey = newPatient.GetKey()
            };

            attachStudyToPatientBroker.Execute(parms);
        }
Пример #6
0
        private void UpdatePatientDemographics(ServerEntityKey patientEntityKey, PatientInfo patientInfo)
        {
            Platform.Log(LogLevel.Info, "Update patient record...");
            var patientUpdateBroker = UpdateContext.GetBroker <IPatientEntityBroker>();
            var columns             = new PatientUpdateColumns();

            columns.IssuerOfPatientId = patientInfo.IssuerOfPatientId;
            columns.PatientId         = patientInfo.PatientId;
            columns.PatientsName      = patientInfo.PatientsName;
            if (atLeastOneFileUpdatedToUTF8)
            {
                columns.SpecificCharacterSet = UTF8;
            }

            patientUpdateBroker.Update(patientEntityKey, columns);
        }
        private Patient CreateNewPatient(PatientInfo patientInfo)
        {
            Platform.Log(LogLevel.Info, "Creating new patient {0}", patientInfo.PatientId);

            var createPatientForStudy = UpdateContext.GetBroker <ICreatePatientForStudy>();
            var parms = new CreatePatientForStudyParameters
            {
                IssuerOfPatientId    = patientInfo.IssuerOfPatientId,
                PatientId            = patientInfo.PatientId,
                PatientsName         = patientInfo.Name,
                SpecificCharacterSet = _curPatient.SpecificCharacterSet,                 // this will be updated at the end if necessary
                StudyKey             = _study.GetKey()
            };
            Patient newPatient = createPatientForStudy.FindOne(parms);

            if (newPatient == null)
            {
                throw new ApplicationException("Unable to create patient for the study");
            }

            return(newPatient);
        }
Пример #8
0
        public void Execute()
        {
            // Wrap the upgrade in a single commit.
            using (
                IUpdateContext updateContext =
                    PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                UpdateContext context = updateContext as UpdateContext;
                if (context == null)
                {
                    Console.WriteLine("Unexpected error opening connection to the database.");
                    throw new ApplicationException("Error opening connection to the database.");
                }

                ExecuteSql(context, GetScript());

                DatabaseVersionUpdateColumns  columns  = new DatabaseVersionUpdateColumns();
                DatabaseVersionSelectCriteria criteria = new DatabaseVersionSelectCriteria();

                columns.Revision = DestinationVersion.Revision.ToString();
                columns.Build    = DestinationVersion.Build.ToString();
                columns.Minor    = DestinationVersion.Minor.ToString();
                columns.Major    = DestinationVersion.Major.ToString();

                IDatabaseVersionEntityBroker broker = context.GetBroker <IDatabaseVersionEntityBroker>();
                broker.Update(criteria, columns);

                updateContext.Commit();
            }

            if (_upgradeStoredProcs)
            {
                RunSqlScriptApplication app = new RunSqlScriptApplication();
                app.RunApplication(new string[] { "-storedprocedures" });
            }
            return;
        }
        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);
                    }
                }
            }
        }