MCPcopy Create free account
hub / github.com/MITK/MITK / ResolveInjectionDateTime

Function ResolveInjectionDateTime

Modules/PET/src/mitkSUVCalculationHelper.cpp:106–158  ·  view source on GitHub ↗

Resolve the radiopharmaceutical injection time into an absolute OFDateTime. Returns (parsed time, derivedFromTimeOnlyTag). The bool tells the caller whether the rollover guard may safely subtract 24 h to recover an ambiguous timing situation.

Source from the content-addressed store, hash-verified

104 // whether the rollover guard may safely subtract 24 h to recover an
105 // ambiguous timing situation.
106 std::pair<OFDateTime, bool> ResolveInjectionDateTime(
107 const mitk::IPropertyProvider* provider,
108 const std::string& fallbackAcquisitionDate)
109 {
110 // Prefer the unambiguous DateTime tag.
111 mitk::DICOMTagPath startDateTimePath;
112 startDateTimePath.AddAnySelection(0x0054, 0x0016).AddElement(0x0018, 0x1078);
113 const auto* startDateTimeProp = FindFirstDICOMProperty(provider, startDateTimePath);
114
115 if (startDateTimeProp != nullptr)
116 {
117 OFDateTime parsed;
118 // (0018,1078) is a DT VR — date and time are already encoded together.
119 if (!ConvertDICOMDateTimeString("", startDateTimeProp->GetValue(0, 0, true, true), parsed))
120 {
121 mitkThrowException(mitk::InvalidDICOMPropertyValueException)
122 << "Cannot parse Radiopharmaceutical Start DateTime (0018,1078) value '"
123 << startDateTimeProp->GetValue(0, 0, true, true) << "'.";
124 }
125 return { parsed, false };
126 }
127
128 mitk::DICOMTagPath startTimePath;
129 startTimePath.AddAnySelection(0x0054, 0x0016).AddElement(0x0018, 0x1072);
130 const auto* startTimeProp = FindFirstDICOMProperty(provider, startTimePath);
131
132 if (startTimeProp != nullptr)
133 {
134 if (fallbackAcquisitionDate.empty())
135 {
136 mitkThrowException(mitk::MissingDICOMPropertyException)
137 << "Radiopharmaceutical Start Time (0018,1072) is present but no "
138 "fallback acquisition date is available to construct an absolute "
139 "injection timestamp.";
140 }
141 OFDateTime parsed;
142 if (!ConvertDICOMDateTimeString(fallbackAcquisitionDate,
143 startTimeProp->GetValue(0, 0, true, true),
144 parsed))
145 {
146 mitkThrowException(mitk::InvalidDICOMPropertyValueException)
147 << "Cannot parse Radiopharmaceutical Start Time (0018,1072) value '"
148 << startTimeProp->GetValue(0, 0, true, true)
149 << "' with fallback date '" << fallbackAcquisitionDate << "'.";
150 }
151 return { parsed, true };
152 }
153
154 mitkThrowException(mitk::MissingDICOMPropertyException)
155 << "No radiopharmaceutical injection time available: neither "
156 "(0018,1078) Radiopharmaceutical Start DateTime nor (0018,1072) "
157 "Radiopharmaceutical Start Time was found.";
158 }
159
160 // Numeric rollover guard for a precomputed (reference - injection)
161 // duration in seconds; it does not compute the difference itself.

Callers 1

DeduceDecayCorrectionMethod · 0.85

Calls 5

FindFirstDICOMPropertyFunction · 0.85
AddElementMethod · 0.80
GetValueMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected