/// <summary> /// Check if a study is nearline and restore if requested. /// </summary> /// <param name="context"></param> /// <param name="partitionKey"></param> /// <param name="studyInstanceUid"></param> /// <param name="restore"></param> private static void CheckForStudyRestore(IPersistenceContext context, ServerEntityKey partitionKey, string studyInstanceUid, StudyRestore restore) { IStudyStorageEntityBroker selectBroker = context.GetBroker <IStudyStorageEntityBroker>(); StudyStorageSelectCriteria criteria = new StudyStorageSelectCriteria(); criteria.ServerPartitionKey.EqualTo(partitionKey); criteria.StudyInstanceUid.EqualTo(studyInstanceUid); StudyStorage storage = selectBroker.FindOne(criteria); if (storage != null) { if (restore == StudyRestore.True) { RestoreQueue restoreRq = storage.InsertRestoreRequest(); if (restoreRq != null) { throw new StudyIsNearlineException(true); } } throw new StudyIsNearlineException(false); } throw new StudyNotFoundException(studyInstanceUid); }
private static StudyStorage FindStudyStorage(ScanResultEntry result) { using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { IStudyStorageEntityBroker broker = ctx.GetBroker <IStudyStorageEntityBroker>(); StudyStorageSelectCriteria criteria = new StudyStorageSelectCriteria(); criteria.StudyInstanceUid.EqualTo(result.StudyInstanceUid); criteria.ServerPartitionKey.EqualTo(result.ServerPartitionKey); return(broker.FindOne(criteria)); } }
private void UpdateDatabase() { // Reload the StudyStorage and Study tables. LoadEntities(); UpdateEntity(_study); UpdateEntity(_curPatient); UpdateEntity(_storage); SetStudyEncoding(_study); // Update the Study table IStudyEntityBroker studyUpdateBroker = UpdateContext.GetBroker <IStudyEntityBroker>(); studyUpdateBroker.Update(_study); // Update the StudyStorage table IStudyStorageEntityBroker 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 (_patientInfoIsNotChanged) { UpdateCurrentPatient(); UpdatePatientEncoding(_curPatient); } else if (_newPatient == null) { // No matching patient in the database. We should create a new patient for this study _newPatient = CreateNewPatient(_newPatientInfo); UpdatePatientEncoding(_newPatient); } 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); UpdatePatientEncoding(_newPatient); } }
protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext) { // Update StudyStatusEnum in the StudyStorageTable IStudyStorageEntityBroker studyStorageUpdate = updateContext.GetBroker <IStudyStorageEntityBroker>(); StudyStorageUpdateColumns studyStorageUpdateColumns = new StudyStorageUpdateColumns(); studyStorageUpdateColumns.StudyStatusEnum = _newStatus; studyStorageUpdate.Update(_location.Key, studyStorageUpdateColumns); // Update ServerTransferSyntaxGUID in FilesystemStudyStorage IFilesystemStudyStorageEntityBroker filesystemUpdate = updateContext.GetBroker <IFilesystemStudyStorageEntityBroker>(); FilesystemStudyStorageUpdateColumns filesystemUpdateColumns = new FilesystemStudyStorageUpdateColumns(); filesystemUpdateColumns.ServerTransferSyntaxKey = _newSyntax.Key; filesystemUpdate.Update(_location.FilesystemStudyStorageKey, filesystemUpdateColumns); }
/// <summary> /// Get the Status of a study. /// </summary> /// <param name="studyInstanceUid">The Study to check for.</param> /// <param name="studyStorage">The returned study storage object</param> /// <returns>true on success, false on no records found.</returns> public bool GetStudyStatus(string studyInstanceUid, out StudyStorage studyStorage) { using (IReadContext read = _store.OpenReadContext()) { IStudyStorageEntityBroker selectBroker = read.GetBroker <IStudyStorageEntityBroker>(); StudyStorageSelectCriteria criteria = new StudyStorageSelectCriteria(); criteria.ServerPartitionKey.EqualTo(Partition.GetKey()); criteria.StudyInstanceUid.EqualTo(studyInstanceUid); IList <StudyStorage> storageList = selectBroker.Find(criteria); foreach (StudyStorage studyLocation in storageList) { studyStorage = studyLocation; return(true); } studyStorage = null; return(false); } }