Skip to content

Commit 58c762c

Browse files
authored
Dicom Cast Validation Bug (#3342)
* fix validation bug * Update observation pareser to create dicom code items individually * add a test case
1 parent 7d750be commit 58c762c

File tree

2 files changed

+48
-6
lines changed
  • converter/dicom-cast/src

2 files changed

+48
-6
lines changed

converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/FhirTransaction/Observation/ObservationParserTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -------------------------------------------------------------------------------------------------
1+
// -------------------------------------------------------------------------------------------------
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// -------------------------------------------------------------------------------------------------
@@ -254,4 +254,25 @@ public void RadiationEventWithoutIrradiationEventUid()
254254
new Identifier());
255255
Assert.Empty(observations);
256256
}
257+
258+
[Fact]
259+
public void RadiationEventWithInvalidDataNotInCodeCodeNoErrorThrown()
260+
{
261+
var report = new DicomStructuredReport(
262+
ObservationConstants.IrradiationEventXRayData,
263+
new DicomContentItem(
264+
ObservationConstants.IrradiationEventUid,
265+
DicomRelationship.Contains,
266+
new DicomUID("1.3.12.2.1234.5.4.5.123123.3000000111", "foobar", DicomUidType.Unknown)
267+
));
268+
report.Dataset.NotValidated();
269+
report.Dataset.Add(DicomTag.PatientBirthDateInAlternativeCalendar, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
270+
271+
var observations = ObservationParser.Parse(
272+
report.Dataset,
273+
new ResourceReference(),
274+
new ResourceReference(),
275+
new Identifier());
276+
Assert.Single(observations);
277+
}
257278
}

converter/dicom-cast/src/Microsoft.Health.DicomCast.Core/Features/Worker/FhirTransaction/Observation/ObservationParser.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,24 @@ private static IEnumerable<Observation> ParseDicomDataset(DicomDataset dataset,
3232
{
3333
if (dataset.TryGetSequence(DicomTag.ConceptNameCodeSequence, out DicomSequence codes) && codes.Items.Count > 0)
3434
{
35-
var code = new DicomCodeItem(codes);
35+
Observation observation = null;
36+
try
37+
{
38+
var code = createDicomCode(codes);
39+
40+
if (ObservationConstants.IrradiationEvents.Contains(code) && TryCreateIrradiationEvent(dataset, patientReference, identifier, out Observation irradiationEvent))
41+
observation = irradiationEvent;
3642

37-
if (ObservationConstants.IrradiationEvents.Contains(code) && TryCreateIrradiationEvent(dataset, patientReference, identifier, out Observation irradiationEvent))
38-
yield return irradiationEvent;
43+
if (ObservationConstants.DoseSummaryReportCodes.Contains(code))
44+
observation = CreateDoseSummary(dataset, imagingStudyReference, patientReference, identifier);
45+
}
46+
catch (DicomValidationException)
47+
{
48+
observation = null; //we can safely ignore any validation errors since we are only looking for irradiation and dose summary reports specifically. If the code fails to validate then it will not match either report.
49+
}
3950

40-
if (ObservationConstants.DoseSummaryReportCodes.Contains(code))
41-
yield return CreateDoseSummary(dataset, imagingStudyReference, patientReference, identifier);
51+
if (observation != null)
52+
yield return observation;
4253
}
4354

4455
// Recursively iterate through every child in the document checking for nested observations.
@@ -53,6 +64,16 @@ private static IEnumerable<Observation> ParseDicomDataset(DicomDataset dataset,
5364
}
5465
}
5566

67+
// We do not use the built in fo dicom method to create dicom codes as that validates the entire dataset by default and we do not want to do that
68+
private static DicomCodeItem createDicomCode(DicomSequence sequence)
69+
{
70+
string codeValue = sequence.Items[0].GetValueOrDefault(DicomTag.CodeValue, 0, string.Empty);
71+
string scheme = sequence.Items[0].GetValueOrDefault(DicomTag.CodingSchemeDesignator, 0, string.Empty);
72+
string meaning = sequence.Items[0].GetValueOrDefault(DicomTag.CodeMeaning, 0, string.Empty);
73+
74+
return new DicomCodeItem(codeValue, scheme, meaning);
75+
}
76+
5677
private static Observation CreateDoseSummary(
5778
DicomDataset dataset,
5879
ResourceReference imagingStudyReference,

0 commit comments

Comments
 (0)