public async Task GivenATransactionContextWithNoDicomPropertyValueChange_WhenprocessedForInstancee_ThenDicomPropertyValuesUpdateIsSkippedAsync() { DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset(); ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(StudyInstanceUid, new List <string>() { SeriesInstanceUid }, new List <string>() { SopInstanceUid }, PatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset); ImagingStudy.SeriesComponent series = imagingStudy.Series.First(); ImagingStudy.InstanceComponent instance = series.Instance.First(); await _imagingStudyInstancePropertySynchronizer.SynchronizeAsync(context, instance, DefaultCancellationToken); Assert.Equal(1, instance.Number); FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset); await _imagingStudyInstancePropertySynchronizer.SynchronizeAsync(newContext, instance, DefaultCancellationToken); Assert.Equal(1, instance.Number); }
public async Task GivenATransactionContexAndImagingStudyWithNewAccessionNumber_WhenProcessedForStudy_ThenNewAccessionNumberIsAddedAsync() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); await _imagingStudyPropertySynchronizer.SynchronizeAsync(context, imagingStudy); Assert.Collection( imagingStudy.Identifier, identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier), // studyinstanceUid identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier)); // accession number FhirTransactionContext newConText = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(accessionNumber: NewAccessionNumber)); await _imagingStudyPropertySynchronizer.SynchronizeAsync(newConText, imagingStudy); Assert.Collection( imagingStudy.Identifier, identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier), // studyinstanceUid identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier), // accession number identifier => ValidationUtility.ValidateAccessionNumber(null, NewAccessionNumber, identifier)); // new accession number }
public static ImagingStudy CreateImagingStudy(string acsn, string started, bool active) { ImagingStudy study = new ImagingStudy { Id = Guid.NewGuid().ToString(), Identifier = { new Identifier { Type = new CodeableConcept { Coding = new List <Coding> { new Coding { System = "http://terminology.hl7.org/CodeSystem/v2-0203", Code = "ACSN" } } }, Value = acsn } } }; if (!active) { study.Status = ImagingStudy.ImagingStudyStatus.Available; } if (null != started) { study.Started = started; } return(study); }
public void SynchronizeStudyProperties(FhirTransactionContext context, ImagingStudy imagingStudy) { EnsureArg.IsNotNull(context, nameof(context)); EnsureArg.IsNotNull(imagingStudy, nameof(imagingStudy)); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); }
public async Task GivenATransactionContextAndImagingStudyWithExistingEndpointReference_WhenProcessedForStudy_ThenEndpointResourceIsNotAddedAsync() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); Endpoint endpoint = FhirResourceBuilder.CreateEndpointResource(); var endpointResourceId = new ServerResourceId(ResourceType.Endpoint, endpoint.Id); var endpointReference = endpointResourceId.ToResourceReference(); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); context.Request.Endpoint = FhirTransactionRequestEntryGenerator.GenerateDefaultNoChangeRequestEntry <Endpoint>(endpointResourceId); imagingStudy.Endpoint.Add(endpointReference); await _imagingStudyPropertySynchronizer.SynchronizeAsync(context, imagingStudy); Assert.Collection( imagingStudy.Endpoint, endPoint => Assert.Equal(endpointReference, endPoint)); }
public async Task GivenAChangeFeedEntryToDeleteAnInstanceWithinAStudyContainingMoreThanOneSeries_WhenBuilt_ThenCorrectEntryComponentShouldBeCreated() { const string studyInstanceUid = "1"; const string seriesInstanceUid = "2"; const string seriesInstanceUid1 = "3"; const string sopInstanceUid = "3"; const string patientResourceId = "p1"; // create a new ImagingStudy ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>() { seriesInstanceUid, seriesInstanceUid1 }, new List <string>() { sopInstanceUid, }, patientResourceId); _fhirService.RetrieveImagingStudyAsync(Arg.Any <Identifier>(), Arg.Any <CancellationToken>()).Returns(imagingStudy); // delete an existing instance within a study FhirTransactionRequestEntry entry = await BuildImagingStudyEntryComponent(studyInstanceUid, seriesInstanceUid, sopInstanceUid, patientResourceId); ImagingStudy updatedImagingStudy = ValidationUtility.ValidateImagingStudyUpdate(studyInstanceUid, patientResourceId, entry); Assert.Equal(ImagingStudy.ImagingStudyStatus.Available, updatedImagingStudy.Status); Assert.Collection( updatedImagingStudy.Series, series => { ValidationUtility.ValidateSeries(series, seriesInstanceUid1, sopInstanceUid); }); }
public void GivenATransactionContextAndImagingStudyWithExitsingAccessionNumber_WhenProcessedForStudy_ThenAccessionNumberIsNotAdded() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Identifier, identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier), identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier)); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Identifier, identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{DefaultStudyInstanceUid}", identifier), identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier)); }
public async Task GivenATransactionContexAndImagingStudy_WhenprocessedForInstance_ThenDicomPropertiesAreCorrectlyMappedtoInstanceWithinImagingStudyAsync() { DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset(); ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(StudyInstanceUid, new List <string>() { SeriesInstanceUid }, new List <string>() { SopInstanceUid }, PatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset); if (imagingStudy.Series.Count() > 0) { System.Console.WriteLine(""); } ImagingStudy.SeriesComponent series = imagingStudy.Series.First(); ImagingStudy.InstanceComponent instance = series.Instance.First(); await _imagingStudyInstancePropertySynchronizer.SynchronizeAsync(context, instance, DefaultCancellationToken); Assert.Equal(SopClassUid, instance.SopClass.Code); Assert.Equal(1, instance.Number); }
public void GivenATransactionContextWithUpdatedInstanceNumber_WhenprocessedForInstance_ThenDicomPropertyValuesAreUpdatedCorrectly() { DicomDataset dataset = FhirTransactionContextBuilder.CreateDicomDataset(); ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>() { seriesInstanceUid }, new List <string>() { sopInstanceUid }, patientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(dataset); ImagingStudy.SeriesComponent series = imagingStudy.Series.First(); ImagingStudy.InstanceComponent instance = series.Instance.First(); _imagingStudyInstancePropertySynchronizer.Synchronize(context, instance); Assert.Equal(1, instance.Number); FhirTransactionContext newContext = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(instanceNumber: "2")); _imagingStudyInstancePropertySynchronizer.Synchronize(newContext, instance); Assert.Equal(2, instance.Number); }
public async Task GivenAChangeFeedWithExistingInstanceForAnExistingSeriesAndImagingStudy_WhenBuilt_ThenNoEntryComponentShouldBeReturned() { const string studyInstanceUid = "1"; const string seriesInstanceUid = "2"; const string sopInstanceUid = "3"; const string patientResourceId = "p1"; // create a new ImagingStudy ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>() { seriesInstanceUid }, new List <string>() { sopInstanceUid }, $"Patient/{patientResourceId}"); _fhirService.RetrieveImagingStudyAsync(Arg.Any <Identifier>(), Arg.Any <CancellationToken>()).Returns(imagingStudy); // try update an existing ImagingStudy FhirTransactionRequestEntry entry = await BuildImagingStudyEntryComponent(studyInstanceUid, seriesInstanceUid, sopInstanceUid, patientResourceId, addMetadata : false); // Validate no entry component is created as there is no update Assert.NotNull(entry); Assert.Equal(FhirTransactionRequestMode.None, entry.RequestMode); Assert.Null(entry.Request); Assert.IsType <ServerResourceId>(entry.ResourceId); Assert.True(imagingStudy.IsExactly(entry.Resource)); }
public void GivenATransactionContexAndImagingStudy_WhenProcessedForStudy_ThenDicomPropertiesAreCorrectlyMappedtoImagingStudy() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Endpoint, reference => string.Equals(reference.Reference, context.Request.Endpoint.Resource.ToString(), StringComparison.Ordinal)); Assert.Collection( imagingStudy.Modality, modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal)); Assert.Collection( imagingStudy.Note, note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal)); Assert.Equal(new FhirDateTime(1974, 7, 10, 7, 10, 24, TimeSpan.Zero), imagingStudy.StartedElement); }
public void GivenATransactionContexAndImagingStudyWithNewModality_WhenProcessedForStudy_ThenNewModalityIsAdded() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Modality, modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal)); FhirTransactionContext newConText = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(modalityInStudy: "NEWMODALITY", modalityInSeries: "NEWMODALITY")); _imagingStudyPropertySynchronizer.Synchronize(newConText, imagingStudy); Assert.Collection( imagingStudy.Modality, modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal), modality => string.Equals(modality.Code, "NEWMODALITY", StringComparison.Ordinal)); }
public void GivenATransactionContexAndImagingStudyWithNewStudyDescription_WhenProcessedForStudy_ThenNewNoteIsAdded() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Note, note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal)); // When studyDescription is same, note is not added twice _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Note, note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal)); // When study description is new, new note is added FhirTransactionContext newConText = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset(studyDescription: "New Study Description")); _imagingStudyPropertySynchronizer.Synchronize(newConText, imagingStudy); Assert.Collection( imagingStudy.Note, note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal), note => string.Equals(note.Text.ToString(), "New Study Description", StringComparison.Ordinal)); }
public void GivenATransactionContextAndImagingStudyWithNewEndpointReference_WhenProcessedForStudyWithEndpoint_ThenEndpointIsAdded() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); // Simulate the imaging study with an existing endpoint. Endpoint existingEndpoint = FhirResourceBuilder.CreateEndpointResource(id: "2345", name: "new wado-rs"); var existingEndpointResourceId = new ServerResourceId(ResourceType.Endpoint, existingEndpoint.Id); var existingEndpointReference = existingEndpointResourceId.ToResourceReference(); imagingStudy.Endpoint.Add(existingEndpointReference); Endpoint endpoint = FhirResourceBuilder.CreateEndpointResource(); var endpointResourceId = new ServerResourceId(ResourceType.Endpoint, endpoint.Id); var endpointReference = endpointResourceId.ToResourceReference(); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); context.Request.Endpoint = FhirTransactionRequestEntryGenerator.GenerateDefaultNoChangeRequestEntry <Endpoint>(endpointResourceId); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Endpoint, endPoint => Assert.Equal(existingEndpointReference, endPoint), endPoint => Assert.Equal(endpointReference, endPoint)); }
public async Task GivenAChangeFeedWithNewSeriesAndInstanceForAnExistingImagingStudy_WhenBuilt_ThenCorrectEntryComponentShouldBeCreated() { const string studyInstanceUid = "1"; const string seriesInstanceUid = "2"; const string sopInstanceUid = "3"; const string patientResourceId = "p1"; const string newSeriesInstanceUid = "3"; const string newSopInstanceUid = "4"; ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>() { seriesInstanceUid }, new List <string>() { sopInstanceUid }, patientResourceId); _fhirService.RetrieveImagingStudyAsync(Arg.Any <Identifier>(), Arg.Any <CancellationToken>()).Returns(imagingStudy); // Update an existing ImagingStudy FhirTransactionRequestEntry entry = await BuildImagingStudyEntryComponent(studyInstanceUid, newSeriesInstanceUid, newSopInstanceUid, patientResourceId); ImagingStudy updatedImagingStudy = ValidationUtility.ValidateImagingStudyUpdate(studyInstanceUid, patientResourceId, entry); Assert.Collection( updatedImagingStudy.Series, series => { ValidationUtility.ValidateSeries(series, seriesInstanceUid, sopInstanceUid); }, series => { ValidationUtility.ValidateSeries(series, newSeriesInstanceUid, newSopInstanceUid); }); }
public async Task GivenAChangeFeedWithNewInstanceAndNewSeiresForAnExistingImagingStudy_WhenBuilt_ThenCorrectEtagIsGeneratedd() { const string studyInstanceUid = "1"; const string seriesInstanceUid = "2"; const string sopInstanceUid = "3"; const string newSeriesInstanceUid = "3"; const string newSopInstanceUid = "3"; const string patientResourceId = "p1"; // create a new ImagingStudy ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(studyInstanceUid, new List <string>() { seriesInstanceUid }, new List <string>() { sopInstanceUid }, patientResourceId); _fhirService.RetrieveImagingStudyAsync(Arg.Any <Identifier>(), Arg.Any <CancellationToken>()).Returns(imagingStudy); // update an existing ImagingStudy FhirTransactionRequestEntry entry = await BuildImagingStudyEntryComponent(studyInstanceUid, newSeriesInstanceUid, newSopInstanceUid, patientResourceId); string expectedIfMatchCondition = $"W/\"1\""; Assert.Equal(expectedIfMatchCondition, entry.Request.IfMatch); }
private void ValidateDicomFilePropertiesAreCorrectlyMapped(ImagingStudy imagingStudy, ImagingStudy.SeriesComponent series, ImagingStudy.InstanceComponent instance) { Assert.Collection( imagingStudy.Endpoint, reference => string.Equals(reference.Reference, _fhirTransactionContext.Request.Endpoint.ToString(), StringComparison.Ordinal)); // Assert imaging study properties are mapped correctly Assert.Collection( imagingStudy.Modality, modality => string.Equals(modality.Code, "MODALITY", StringComparison.Ordinal)); Assert.Collection( imagingStudy.Note, note => string.Equals(note.Text.ToString(), "Study Description", StringComparison.Ordinal)); Assert.Equal(new FhirDateTime(1974, 7, 10, 7, 10, 24, TimeSpan.Zero), imagingStudy.StartedElement); // Assert series properties are mapped correctly Assert.Equal("Series Description", series.Description); Assert.Equal("MODALITY", series.Modality.Code); Assert.Equal(1, series.Number); Assert.Equal(new FhirDateTime(1974, 8, 10, 8, 10, 24, TimeSpan.Zero), series.StartedElement); // Assert instance properties are mapped correctly Assert.Equal("4444", instance.SopClass.Code); Assert.Equal(1, instance.Number); }
public static Bundle.RequestComponent GenerateDeleteRequest(ImagingStudy imagingStudy) { return(new Bundle.RequestComponent() { Method = Bundle.HTTPVerb.DELETE, Url = $"{ResourceType.ImagingStudy.GetLiteral()}/{imagingStudy.Id}", }); }
/// <inheritdoc/> public async Task <FhirTransactionRequestEntry> BuildAsync(FhirTransactionContext context, CancellationToken cancellationToken) { EnsureArg.IsNotNull(context, nameof(context)); EnsureArg.IsNotNull(context.ChangeFeedEntry, nameof(context.ChangeFeedEntry)); EnsureArg.IsNotNull(context.Request, nameof(context.Request)); IResourceId patientId = context.Request.Patient.ResourceId; ChangeFeedEntry changeFeedEntry = context.ChangeFeedEntry; Identifier imagingStudyIdentifier = ImagingStudyIdentifierUtility.CreateIdentifier(changeFeedEntry.StudyInstanceUid); ImagingStudy existingImagingStudy = await _fhirService.RetrieveImagingStudyAsync(imagingStudyIdentifier, cancellationToken); ImagingStudy imagingStudy = (ImagingStudy)existingImagingStudy?.DeepCopy(); FhirTransactionRequestMode requestMode = FhirTransactionRequestMode.None; if (existingImagingStudy == null) { imagingStudy = new ImagingStudy() { Status = ImagingStudy.ImagingStudyStatus.Available, Subject = patientId.ToResourceReference(), }; imagingStudy.Identifier.Add(imagingStudyIdentifier); requestMode = FhirTransactionRequestMode.Create; } SynchronizeImagingStudyProperties(context, imagingStudy); if (requestMode != FhirTransactionRequestMode.Create && !existingImagingStudy.IsExactly(imagingStudy)) { requestMode = FhirTransactionRequestMode.Update; } Bundle.RequestComponent request = requestMode switch { FhirTransactionRequestMode.Create => ImagingStudyPipelineHelper.GenerateCreateRequest(imagingStudyIdentifier), FhirTransactionRequestMode.Update => ImagingStudyPipelineHelper.GenerateUpdateRequest(imagingStudy), _ => null, }; IResourceId resourceId = requestMode switch { FhirTransactionRequestMode.Create => new ClientResourceId(), _ => existingImagingStudy.ToServerResourceId(), }; return(new FhirTransactionRequestEntry( requestMode, request, resourceId, imagingStudy)); }
public static Bundle.RequestComponent GenerateUpdateRequest(ImagingStudy imagingStudy) { return(new Bundle.RequestComponent() { Method = Bundle.HTTPVerb.PUT, IfMatch = ImagingStudyPipelineHelper.GenerateEtag(imagingStudy.Meta.VersionId), Url = $"{ResourceType.ImagingStudy.GetLiteral()}/{imagingStudy.Id}", }); }
private void AddImagingStudyEndpoint(ImagingStudy imagingStudy, FhirTransactionContext context) { var endpointReference = context.Request.Endpoint.ResourceId.ToResourceReference(); if (!imagingStudy.Endpoint.Any(endpoint => endpointReference.IsExactly(endpoint))) { imagingStudy.Endpoint.Add(endpointReference); } }
public static Bundle.RequestComponent GenerateUpdateRequest(ImagingStudy imagingStudy) { EnsureArg.IsNotNull(imagingStudy, nameof(imagingStudy)); return(new Bundle.RequestComponent() { Method = Bundle.HTTPVerb.PUT, IfMatch = GenerateEtag(imagingStudy.Meta.VersionId), Url = $"{ResourceType.ImagingStudy.GetLiteral()}/{imagingStudy.Id}", }); }
private void AddModality(ImagingStudy imagingStudy, DicomDataset dataset) { string modalityInString = ImagingStudyPipelineHelper.GetModalityInString(dataset); if (modalityInString != null) { Coding modality = ImagingStudyPipelineHelper.GetModality(modalityInString); List <Coding> existingModalities = imagingStudy.Modality; if (dataset.TryGetValues(DicomTag.ModalitiesInStudy, out string[] modalitiesInStudy) &&
private void btnApply_Click(object sender, EventArgs e) { //create the ImagingStudy json using form data ImagingStudy study = Common.CreateImagingStudy(txtAddAccession.Text, dtStudy.Value.ToString("yyyy-MM-dd"), rbCurrentStudy.Checked); var serializer = new FhirJsonSerializer(new SerializerSettings() { Pretty = true }); txtAddStudyJson.Text = serializer.SerializeToString(study); }
public string GetCachedItemMetaData(LifeImageCloudConnection Connection, RoutedItem routedItem, long taskID) { Throw.IfNull(Connection); var taskInfo = $"conn: {Connection.name} taskID: {taskID}"; RootObject rootObject = new RootObject { ImagingStudy = new List <ImagingStudy>() }; ImagingStudy study = new ImagingStudy { accession = new Accession(), patient = new Patient(), series = new List <Series>() }; var cacheItem = LifeImageCloudConnection.cache[routedItem.id].ToList(); var query = cacheItem .GroupBy(item => new { item.Study, item.Series, item.PatientID, item.AccessionNumber }) .Select(grp => new { Study = grp.Key.Study, Series = grp.Key.Series, PatientID = grp.Key.PatientID, Accession = grp.Key.AccessionNumber, Instances = grp.Count() }); foreach (var result in query) { _logger.Log(LogLevel.Debug, $"{taskInfo} Study:{result.Study} Series:{result.Series} PatientID:{result.PatientID} Accession:{result.Accession} Instances:{result.Instances}"); var series = new Series { number = result.Instances, uid = result.Series }; study.series.Add(series); } study.numberOfInstances = query.Sum(x => x.Instances); study.numberOfSeries = query.Count(); rootObject.ImagingStudy.Add(study); var json = JsonSerializer.Serialize(rootObject); _logger.Log(LogLevel.Debug, $"{taskInfo} Json:{json}"); return(json); }
/// <inheritdoc/> public async Task <FhirTransactionRequestEntry> BuildAsync(FhirTransactionContext context, CancellationToken cancellationToken) { EnsureArg.IsNotNull(context, nameof(context)); EnsureArg.IsNotNull(context.ChangeFeedEntry, nameof(context.ChangeFeedEntry)); ChangeFeedEntry changeFeedEntry = context.ChangeFeedEntry; Identifier imagingStudyIdentifier = ImagingStudyIdentifierUtility.CreateIdentifier(changeFeedEntry.StudyInstanceUid); ImagingStudy imagingStudy = await _fhirService.RetrieveImagingStudyAsync(imagingStudyIdentifier, cancellationToken); // Returns null if imagingStudy does not exists for given studyInstanceUid if (imagingStudy == null) { return(null); } string imagingStudySource = imagingStudy.Meta.Source; ImagingStudy.SeriesComponent series = ImagingStudyPipelineHelper.GetSeriesWithinAStudy(changeFeedEntry.SeriesInstanceUid, imagingStudy.Series); ImagingStudy.InstanceComponent instance = ImagingStudyPipelineHelper.GetInstanceWithinASeries(changeFeedEntry.SopInstanceUid, series); // Return null if the given instance is not present in ImagingStudy if (instance == null) { return(null); } // Removes instance from series collection series.Instance.Remove(instance); // Removes series from ImagingStudy if its instance collection is empty if (series.Instance.Count == 0) { imagingStudy.Series.Remove(series); } if (imagingStudy.Series.Count == 0 && _dicomWebEndpoint.Equals(imagingStudySource, System.StringComparison.Ordinal)) { return(new FhirTransactionRequestEntry( FhirTransactionRequestMode.Delete, ImagingStudyPipelineHelper.GenerateDeleteRequest(imagingStudy), imagingStudy.ToServerResourceId(), imagingStudy)); } return(new FhirTransactionRequestEntry( FhirTransactionRequestMode.Update, ImagingStudyPipelineHelper.GenerateUpdateRequest(imagingStudy), imagingStudy.ToServerResourceId(), imagingStudy)); }
private static void AddNote(ImagingStudy imagingStudy, DicomDataset dataset) { if (dataset.TryGetSingleValue(DicomTag.StudyDescription, out string description)) { if (!imagingStudy.Note.Any(note => string.Equals(note.Text.Value, description, StringComparison.Ordinal))) { Annotation annotation = new Annotation() { Text = new Markdown(description), }; imagingStudy.Note.Add(annotation); } } }
public async Task GivenAValidCreateChangeFeed_WhenBuilt_ThenCorrectEntryComponentShouldBeCreated() { const string studyInstanceUid = "1"; const string seriesInstanceUid = "2"; const string sopInstanceUid = "3"; const string patientResourceId = "p1"; ChangeFeedEntry changeFeedEntry = ChangeFeedGenerator.Generate( action: ChangeFeedAction.Create, studyInstanceUid: studyInstanceUid, seriesInstanceUid: seriesInstanceUid, sopInstanceUid: sopInstanceUid); FhirTransactionRequestEntry entry = await BuildImagingStudyEntryComponent(studyInstanceUid, seriesInstanceUid, sopInstanceUid, patientResourceId); ValidationUtility.ValidateRequestEntryMinimumRequirementForWithChange(FhirTransactionRequestMode.Create, "ImagingStudy", Bundle.HTTPVerb.POST, entry); ImagingStudy imagingStudy = Assert.IsType <ImagingStudy>(entry.Resource); string jsonString; jsonString = JsonSerializer.Serialize(entry); Assert.IsType <ClientResourceId>(entry.ResourceId); Assert.Equal(ImagingStudy.ImagingStudyStatus.Available, imagingStudy.Status); Assert.Null(entry.Request.IfMatch); ValidationUtility.ValidateResourceReference("Patient/p1", imagingStudy.Subject); Assert.Collection( imagingStudy.Identifier, identifier => ValidationUtility.ValidateIdentifier("urn:dicom:uid", $"urn:oid:{studyInstanceUid}", identifier), identifier => ValidationUtility.ValidateAccessionNumber(null, FhirTransactionContextBuilder.DefaultAccessionNumber, identifier)); Assert.Collection( imagingStudy.Series, series => { Assert.Equal(seriesInstanceUid, series.Uid); Assert.Collection( series.Instance, instance => Assert.Equal(sopInstanceUid, instance.Uid)); }); ValidateDicomFilePropertiesAreCorrectlyMapped(imagingStudy, series: imagingStudy.Series.First(), instance: imagingStudy.Series.First().Instance.First()); }
public void GivenATransactionContextAndImagingStudyWithNoEndpoint_WhenProcessedForStudy_ThenNewEndpointIsAdded() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); _imagingStudyPropertySynchronizer.Synchronize(context, imagingStudy); Assert.Collection( imagingStudy.Endpoint, endPoint => Assert.Equal(context.Request.Endpoint.ResourceId.ToResourceReference(), endPoint)); }
public async Task SyncPropertiesAsync_PartialValidationEnabledAndPropertyRequired_ThrowsError() { ImagingStudy imagingStudy = FhirResourceBuilder.CreateNewImagingStudy(DefaultStudyInstanceUid, new List <string>() { DefaultSeriesInstanceUid }, new List <string>() { DefaultSopInstanceUid }, DefaultPatientResourceId); FhirTransactionContext context = FhirTransactionContextBuilder.DefaultFhirTransactionContext(FhirTransactionContextBuilder.CreateDicomDataset()); Action <ImagingStudy, FhirTransactionContext> actionSubstitute = Substitute.For <Action <ImagingStudy, FhirTransactionContext> >(); actionSubstitute.When(x => x.Invoke(imagingStudy, context)).Do(x => throw new InvalidDicomTagValueException("invalid tag", "invalid tag")); await Assert.ThrowsAsync <InvalidDicomTagValueException>(() => ImagingStudyPipelineHelper.SynchronizePropertiesAsync(imagingStudy, context, actionSubstitute, true, true, _exceptionStore)); }