annotate OrthancStone/Sources/Toolbox/DicomStructuredReport.cpp @ 2085:554bc96e7508

added DicomStructuredReport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Nov 2023 17:03:38 +0100
parents
children 51c8b21b81e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2085
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Lesser General Public License for more details.
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * License along with this program. If not, see
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * <http://www.gnu.org/licenses/>.
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomStructuredReport.h"
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Scene2D/ScenePoint2D.h"
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <OrthancException.h>
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <SerializationToolbox.h>
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <dcmtk/dcmdata/dcdeftag.h>
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <dcmtk/dcmdata/dcsequen.h>
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <dcmtk/dcmdata/dcfilefo.h>
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 static std::string GetStringValue(DcmItem& dataset,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 const DcmTagKey& key)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 const char* value = NULL;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 if (dataset.findAndGetString(key, value).good() &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 value != NULL)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 return value;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 "Missing tag in DICOM-SR: " + key.toString());
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 static DcmSequenceOfItems& GetSequenceValue(DcmItem& dataset,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const DcmTagKey& key)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 DcmSequenceOfItems* sequence = NULL;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 if (dataset.findAndGetSequence(key, sequence).good() &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 sequence != NULL)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 return *sequence;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 "Missing sequence in DICOM-SR: " + key.toString());
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 static void CheckStringValue(DcmItem& dataset,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 const DcmTagKey& key,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 const std::string& expected)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (GetStringValue(dataset, key) != expected)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 static bool IsDicomTemplate(DcmItem& dataset,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const std::string& tid)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 DcmSequenceOfItems& sequence = GetSequenceValue(dataset, DCM_ContentTemplateSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 return (sequence.card() == 1 &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 GetStringValue(*sequence.getItem(0), DCM_MappingResource) == "DCMR" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 GetStringValue(*sequence.getItem(0), DCM_TemplateIdentifier) == tid);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 static bool IsValidConcept(DcmItem& dataset,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const DcmTagKey& key,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& scheme,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const std::string& concept)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 DcmSequenceOfItems& sequence = GetSequenceValue(dataset, key);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return (sequence.card() == 1 &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 GetStringValue(*sequence.getItem(0), DCM_CodingSchemeDesignator) == scheme &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 GetStringValue(*sequence.getItem(0), DCM_CodeValue) == concept);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 static bool IsDicomConcept(DcmItem& dataset,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 const std::string& concept)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return IsValidConcept(dataset, DCM_ConceptNameCodeSequence, "DCM", concept);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 namespace OrthancStone
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 class DicomStructuredReport::Structure : public boost::noncopyable
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 private:
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 std::string sopInstanceUid_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 bool hasFrameNumber_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 unsigned int frameNumber_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 bool hasProbabilityOfCancer_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 float probabilityOfCancer_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 public:
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 Structure(const std::string& sopInstanceUid) :
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 sopInstanceUid_(sopInstanceUid),
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 hasFrameNumber_(false),
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 hasProbabilityOfCancer_(false)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 virtual ~Structure()
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 void SetFrameNumber(unsigned int frame)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 if (frame <= 0)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 hasFrameNumber_ = true;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 frameNumber_ = frame;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 void SetProbabilityOfCancer(float probability)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 if (probability < 0 ||
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 probability > 100)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 hasProbabilityOfCancer_ = true;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 probabilityOfCancer_ = probability;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 bool HasFrameNumber() const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 return hasFrameNumber_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 bool HasProbabilityOfCancer() const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return hasProbabilityOfCancer_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 unsigned int GetFrameNumber() const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 if (hasFrameNumber_)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 return frameNumber_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 float GetProbabilityOfCancer() const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 if (hasProbabilityOfCancer_)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 return probabilityOfCancer_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 };
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 class DicomStructuredReport::Point : public Structure
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 private:
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 ScenePoint2D point_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 public:
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 Point(const std::string& sopInstanceUid,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 double x,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 double y) :
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 Structure(sopInstanceUid),
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 point_(x, y)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 const ScenePoint2D& GetPoint() const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 return point_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 };
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 class DicomStructuredReport::Polyline : public Structure
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 private:
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 std::vector<ScenePoint2D> points_;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 public:
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 Polyline(const std::string& sopInstanceUid,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 const float* points,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 unsigned long pointsCount) :
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 Structure(sopInstanceUid)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (pointsCount % 2 != 0)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 points_.reserve(pointsCount / 2);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 for (unsigned long i = 0; i < pointsCount; i += 2)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 points_.push_back(ScenePoint2D(points[i], points[i + 1]));
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 size_t GetSize() const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 return points_.size();
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 const ScenePoint2D& GetPoint(size_t i) const
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (i >= points_.size())
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 return points_[i];
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 };
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 void DicomStructuredReport::AddStructure(const std::string& sopInstanceUid,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 DcmItem& group,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 bool hasFrameNumber,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 unsigned int frameNumber,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 bool hasProbabilityOfCancer,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 float probabilityOfCancer)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 const std::string graphicType = GetStringValue(group, DCM_GraphicType);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 const Float32* coords = NULL;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 unsigned long coordsCount = 0;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 if (!group.findAndGetFloat32Array(DCM_GraphicData, coords, &coordsCount).good() ||
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 (coordsCount != 0 && coords == NULL))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 "Cannot read coordinates for region in DICOM-SR");
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 std::unique_ptr<Structure> structure;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 if (graphicType == "POINT")
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 if (coordsCount != 2)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 structure.reset(new Point(sopInstanceUid, coords[0], coords[1]));
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 else if (graphicType == "POLYLINE")
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 structure.reset(new Polyline(sopInstanceUid, coords, coordsCount));
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 return; // Unsupported graphic type
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 assert(structure.get() != NULL);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 if (hasFrameNumber)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 structure->SetFrameNumber(frameNumber);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 if (hasProbabilityOfCancer)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 structure->SetProbabilityOfCancer(probabilityOfCancer);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 structures_.push_back(structure.release());
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 DicomStructuredReport::DicomStructuredReport(Orthanc::ParsedDicomFile& dicom)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 DcmDataset& dataset = *dicom.GetDcmtkObject().getDataset();
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 CheckStringValue(dataset, DCM_Modality, "SR");
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 CheckStringValue(dataset, DCM_SOPClassUID, "1.2.840.10008.5.1.4.1.1.88.33"); // Comprehensive SR IOD
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 CheckStringValue(dataset, DCM_ValueType, "CONTAINER");
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 if (!IsDicomConcept(dataset, "126000") /* Imaging measurement report */ ||
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 !IsDicomTemplate(dataset, "1500"))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 DcmSequenceOfItems& sequence = GetSequenceValue(dataset, DCM_CurrentRequestedProcedureEvidenceSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 std::list<std::string> tmp;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 for (unsigned long i = 0; i < sequence.card(); i++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 std::string studyInstanceUid = GetStringValue(*sequence.getItem(i), DCM_StudyInstanceUID);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 DcmSequenceOfItems* referencedSeries = NULL;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 if (!sequence.getItem(i)->findAndGetSequence(DCM_ReferencedSeriesSequence, referencedSeries).good() ||
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 referencedSeries == NULL)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 for (unsigned long j = 0; j < referencedSeries->card(); j++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 std::string seriesInstanceUid = GetStringValue(*referencedSeries->getItem(j), DCM_SeriesInstanceUID);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 DcmSequenceOfItems* referencedInstances = NULL;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 if (!referencedSeries->getItem(j)->findAndGetSequence(DCM_ReferencedSOPSequence, referencedInstances).good() ||
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 referencedInstances == NULL)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 for (unsigned int k = 0; k < referencedInstances->card(); k++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 std::string sopClassUid = GetStringValue(*referencedInstances->getItem(k), DCM_ReferencedSOPClassUID);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 std::string sopInstanceUid = GetStringValue(*referencedInstances->getItem(k), DCM_ReferencedSOPInstanceUID);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 if (instancesInformation_.find(sopInstanceUid) == instancesInformation_.end())
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 instancesInformation_[sopInstanceUid] = ReferencedInstance(studyInstanceUid, seriesInstanceUid, sopClassUid);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 "Multiple occurrences of the same instance in DICOM-SR: " + sopInstanceUid);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 tmp.push_back(sopInstanceUid);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 orderedInstances_.reserve(tmp.size());
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 for (std::list<std::string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 orderedInstances_.push_back(*it);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 sequence = GetSequenceValue(dataset, DCM_ContentSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 for (unsigned long i = 0; i < sequence.card(); i++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 DcmItem& item = *sequence.getItem(i);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 if (GetStringValue(item, DCM_RelationshipType) == "CONTAINS" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 GetStringValue(item, DCM_ValueType) == "CONTAINER" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 IsDicomConcept(item, "126010" /* Imaging measurements */))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 DcmSequenceOfItems& measurements = GetSequenceValue(item, DCM_ContentSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 for (unsigned long j = 0; j < measurements.card(); j++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 DcmItem& measurement = *measurements.getItem(j);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 if (GetStringValue(measurement, DCM_RelationshipType) == "CONTAINS" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 GetStringValue(measurement, DCM_ValueType) == "CONTAINER" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 IsDicomConcept(measurement, "125007" /* Measurement group */) &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 IsDicomTemplate(measurement, "1410"))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 DcmSequenceOfItems& groups = GetSequenceValue(measurement, DCM_ContentSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 bool hasProbabilityOfCancer = false;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 float probabilityOfCancer = 0;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 for (unsigned int k = 0; k < groups.card(); k++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 DcmItem& group = *groups.getItem(k);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 if (GetStringValue(group, DCM_RelationshipType) == "CONTAINS" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 GetStringValue(group, DCM_ValueType) == "NUM" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 IsDicomConcept(group, "111047" /* Probability of cancer */))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 DcmSequenceOfItems& values = GetSequenceValue(group, DCM_MeasuredValueSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 if (values.card() == 1 &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 IsValidConcept(*values.getItem(0), DCM_MeasurementUnitsCodeSequence, "UCUM", "%"))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 std::string value = GetStringValue(*values.getItem(0), DCM_NumericValue);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 if (Orthanc::SerializationToolbox::ParseFloat(probabilityOfCancer, value))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 hasProbabilityOfCancer = true;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 "Cannot parse float in DICOM-SR: " + value);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 for (unsigned int k = 0; k < groups.card(); k++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 DcmItem& group = *groups.getItem(k);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 if (GetStringValue(group, DCM_RelationshipType) == "CONTAINS" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 GetStringValue(group, DCM_ValueType) == "SCOORD" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 IsDicomConcept(group, "111030" /* Image region */))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 DcmSequenceOfItems& regions = GetSequenceValue(group, DCM_ContentSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 for (unsigned int l = 0; l < regions.card(); l++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 DcmItem& region = *regions.getItem(l);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 if (GetStringValue(region, DCM_RelationshipType) == "SELECTED FROM" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 GetStringValue(region, DCM_ValueType) == "IMAGE" &&
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 IsDicomConcept(region, "111040") /* Original source */)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 DcmSequenceOfItems& instances = GetSequenceValue(region, DCM_ReferencedSOPSequence);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 if (instances.card() != 1)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 "Region cannot reference multiple instances in DICOM-SR");
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 std::string sopInstanceUid = GetStringValue(*instances.getItem(0), DCM_ReferencedSOPInstanceUID);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 if (instancesInformation_.find(sopInstanceUid) == instancesInformation_.end())
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 "Referencing unknown instance in DICOM-SR: " + sopInstanceUid);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 if (instances.getItem(0)->tagExists(DCM_ReferencedFrameNumber))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 std::string frames = GetStringValue(*instances.getItem(0), DCM_ReferencedFrameNumber);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 std::vector<std::string> tokens;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 Orthanc::Toolbox::SplitString(tokens, frames, '\\');
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 for (size_t m = 0; m < tokens.size(); m++)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 uint32_t frame;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 if (!Orthanc::SerializationToolbox::ParseUnsignedInteger32(frame, tokens[m]))
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 AddStructure(sopInstanceUid, group, true, frame, hasProbabilityOfCancer, probabilityOfCancer);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 else
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 AddStructure(sopInstanceUid, group, false, 0, hasProbabilityOfCancer, probabilityOfCancer);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 DicomStructuredReport::~DicomStructuredReport()
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 for (std::list<Structure*>::iterator it = structures_.begin(); it != structures_.end(); ++it)
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 assert(*it != NULL);
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 delete *it;
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }
554bc96e7508 added DicomStructuredReport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }