public async Task GivenAnExistingDicomInstance_WhenAdded_ThenDicomInstanceAlreadyExistsExceptionShouldBeThrown() { string studyInstanceUid = TestUidGenerator.Generate(); string seriesInstanceUid = TestUidGenerator.Generate(); string sopInstanceUid = TestUidGenerator.Generate(); DicomDataset dataset = Samples.CreateRandomDicomFile(studyInstanceUid, seriesInstanceUid, sopInstanceUid).Dataset; long version = await _indexDataStore.BeginCreateInstanceIndexAsync(DefaultPartition.Key, dataset); await _indexDataStore.EndCreateInstanceIndexAsync(DefaultPartition.Key, dataset, version); await Assert.ThrowsAsync <InstanceAlreadyExistsException>(() => _indexDataStore.BeginCreateInstanceIndexAsync(DefaultPartition.Key, dataset)); }
public async Task GivenExistingExtendedQueryTagIndexData_WhenDeleteExtendedQueryTag_ThenShouldDeleteIndexData() { DicomTag tag = DicomTag.DeviceSerialNumber; // Prepare index data DicomDataset dataset = Samples.CreateRandomInstanceDataset(); dataset.Add(tag, "123"); await AddExtendedQueryTagsAsync(new AddExtendedQueryTagEntry[] { tag.BuildAddExtendedQueryTagEntry() }); ExtendedQueryTagStoreEntry storeEntry = await _extendedQueryTagStore.GetExtendedQueryTagAsync(tag.GetPath()); QueryTag queryTag = new QueryTag(storeEntry); long watermark = await _indexDataStore.BeginCreateInstanceIndexAsync(1, dataset, new QueryTag[] { queryTag }); await _indexDataStore.EndCreateInstanceIndexAsync(1, dataset, watermark, new QueryTag[] { queryTag }); var extendedQueryTagIndexData = await _extendedQueryTagStoreTestHelper.GetExtendedQueryTagDataForTagKeyAsync(ExtendedQueryTagDataType.StringData, storeEntry.Key); Assert.NotEmpty(extendedQueryTagIndexData); // Delete tag await _extendedQueryTagStore.DeleteExtendedQueryTagAsync(storeEntry.Path, storeEntry.VR); await VerifyTagNotExistAsync(storeEntry.Path); // Verify index data is removed extendedQueryTagIndexData = await _extendedQueryTagStoreTestHelper.GetExtendedQueryTagDataForTagKeyAsync(ExtendedQueryTagDataType.StringData, storeEntry.Key); Assert.Empty(extendedQueryTagIndexData); }
/// <inheritdoc /> public async Task StoreDicomInstanceEntryAsync( IDicomInstanceEntry dicomInstanceEntry, CancellationToken cancellationToken) { EnsureArg.IsNotNull(dicomInstanceEntry, nameof(dicomInstanceEntry)); var partitionKey = _contextAccessor.RequestContext.GetPartitionKey(); DicomDataset dicomDataset = await dicomInstanceEntry.GetDicomDatasetAsync(cancellationToken); IReadOnlyCollection <QueryTag> queryTags = await _queryTagService.GetQueryTagsAsync(cancellationToken : cancellationToken); long watermark = await _indexDataStore.BeginCreateInstanceIndexAsync(partitionKey, dicomDataset, queryTags, cancellationToken); var versionedInstanceIdentifier = dicomDataset.ToVersionedInstanceIdentifier(watermark); try { // We have successfully created the index, store the files. await Task.WhenAll( StoreFileAsync(versionedInstanceIdentifier, dicomInstanceEntry, cancellationToken), StoreInstanceMetadataAsync(dicomDataset, watermark, cancellationToken)); await _indexDataStore.EndCreateInstanceIndexAsync(partitionKey, dicomDataset, watermark, queryTags, cancellationToken : cancellationToken); } catch (Exception) { // Exception occurred while storing the file. Try delete the index. await TryCleanupInstanceIndexAsync(versionedInstanceIdentifier); throw; } }
private async Task <long> AddInstanceAsync(string studyId, string seriesId, string sopInstanceId) { DicomDataset dataset = Samples.CreateRandomInstanceDataset(studyId, seriesId, sopInstanceId); long watermark = await _indexDataStore.BeginCreateInstanceIndexAsync(1, dataset); await _indexDataStore.EndCreateInstanceIndexAsync(1, dataset, watermark); return(watermark); }
private async Task StoreDatasetsAndInstances(DicomDataset dataset, bool flagToStoreInstance) { long version = await _indexDataStore.BeginCreateInstanceIndexAsync(1, dataset); var versionedInstanceIdentifier = dataset.ToVersionedInstanceIdentifier(version); if (flagToStoreInstance) { var dicomFile = new DicomFile(dataset); Samples.AppendRandomPixelData(5, 5, 0, dicomFile); await using MemoryStream stream = _recyclableMemoryStreamManager.GetStream(); dicomFile.Save(stream); stream.Position = 0; await _fileStore.StoreFileAsync( versionedInstanceIdentifier, stream); } await _indexDataStore.EndCreateInstanceIndexAsync(1, dataset, version); }
public static Task EndCreateInstanceIndexAsync(this IIndexDataStore indexDataStore, int partitionKey, DicomDataset dicomDataset, long watermark, CancellationToken cancellationToken = default) => indexDataStore.EndCreateInstanceIndexAsync(partitionKey, dicomDataset, watermark, Array.Empty <QueryTag>(), true, cancellationToken);