annotate OrthancServer/DicomDirWriter.cpp @ 2151:8cbb55089a1d

New configuration option: "LoadPrivateDictionary"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 14 Nov 2016 14:22:45 +0100
parents fd5875662670
children a3a65de1840f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1893
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1130
diff changeset
4 * Department, University Hospital of Liege, Belgium
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 /*=========================================================================
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 This file is based on portions of the following project:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 Program: DCMTK 3.6.0
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 Module: http://dicom.offis.de/dcmtk.php.en
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 Copyright (C) 1994-2011, OFFIS e.V.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 All rights reserved.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 This software and supporting documentation were developed by
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 OFFIS e.V.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 R&D Division Health
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 Escherweg 2
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 26121 Oldenburg, Germany
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 Redistribution and use in source and binary forms, with or without
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 modification, are permitted provided that the following conditions
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 are met:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 - Redistributions of source code must retain the above copyright
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 notice, this list of conditions and the following disclaimer.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 - Redistributions in binary form must reproduce the above copyright
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 notice, this list of conditions and the following disclaimer in the
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 documentation and/or other materials provided with the distribution.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 - Neither the name of OFFIS nor the names of its contributors may be
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 used to endorse or promote products derived from this software
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 without specific prior written permission.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 =========================================================================*/
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 /***
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 Validation:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 # sudo apt-get install dicom3tools
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 # dciodvfy DICOMDIR 2>&1 | less
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 # dcentvfy DICOMDIR 2>&1 | less
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 http://www.dclunie.com/dicom3tools/dciodvfy.html
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 DICOMDIR viewer working with Wine under Linux:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 http://www.microdicom.com/
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ***/
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 #include "PrecompiledHeadersServer.h"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 #include "DicomDirWriter.h"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #include "FromDcmtkBridge.h"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 #include "ToDcmtkBridge.h"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
106 #include "../Core/Logging.h"
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 #include "../Core/OrthancException.h"
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
108 #include "../Core/TemporaryFile.h"
2143
fd5875662670 creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
109 #include "../Core/Toolbox.h"
fd5875662670 creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
110 #include "../Core/SystemToolbox.h"
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 #include <dcmtk/dcmdata/dcdicdir.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 #include <dcmtk/dcmdata/dcmetinf.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 #include <dcmtk/dcmdata/dcdeftag.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 #include <dcmtk/dcmdata/dcuid.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 #include <dcmtk/dcmdata/dcddirif.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #include <dcmtk/dcmdata/dcvrui.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 #include <dcmtk/dcmdata/dcsequen.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 #include <dcmtk/dcmdata/dcostrmf.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 #include "dcmtk/dcmdata/dcvrda.h" /* for class DcmDate */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 #include "dcmtk/dcmdata/dcvrtm.h" /* for class DcmTime */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 #include <memory>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 namespace Orthanc
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 class DicomDirWriter::PImpl
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 private:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 std::string fileSetId_;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
131 TemporaryFile file_;
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 std::auto_ptr<DcmDicomDir> dir_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 typedef std::pair<ResourceType, std::string> IndexKey;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 typedef std::map<IndexKey, DcmDirectoryRecord* > Index;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 Index index_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 DcmDicomDir& GetDicomDir()
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (dir_.get() == NULL)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 dir_.reset(new DcmDicomDir(file_.GetPath().c_str(),
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 fileSetId_.c_str()));
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
145 //SetTagValue(dir_->getRootRecord(), DCM_SpecificCharacterSet, GetDicomSpecificCharacterSet(Encoding_Utf8));
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 return *dir_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 DcmDirectoryRecord& GetRoot()
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 return GetDicomDir().getRootRecord();
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
158 static bool GetUtf8TagValue(std::string& result,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
159 DcmItem& source,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
160 Encoding encoding,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
161 const DcmTagKey& key)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
162 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
163 DcmElement* element = NULL;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
164
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
165 if (source.findAndGetElement(key, element).good())
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
166 {
1893
d7f63122c7f3 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
167 char* s = NULL;
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
168 if (element->isLeaf() &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
169 element->getString(s).good() &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
170 s != NULL)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
171 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
172 result = Toolbox::ConvertToUtf8(s, encoding);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
173 return true;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
174 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
175 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
176
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
177 result.clear();
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
178 return false;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
179 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
180
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
181
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
182 static void SetTagValue(DcmDirectoryRecord& target,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
183 const DcmTagKey& key,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
184 const std::string& valueUtf8)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
185 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
186 std::string s = Toolbox::ConvertFromUtf8(valueUtf8, Encoding_Ascii);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
187
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
188 if (!target.putAndInsertString(key, s.c_str()).good())
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
189 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
190 throw OrthancException(ErrorCode_InternalError);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
191 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
192 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
193
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
194
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
195
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
196 static bool CopyString(DcmDirectoryRecord& target,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
197 DcmDataset& source,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
198 Encoding encoding,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
199 const DcmTagKey& key,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
200 bool optional,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
201 bool copyEmpty)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
202 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
203 if (optional &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
204 !source.tagExistsWithValue(key) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
205 !(copyEmpty && source.tagExists(key)))
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
206 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
207 return false;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
208 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
209
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
210 std::string value;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
211 bool found = GetUtf8TagValue(value, source, encoding, key);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
212
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
213 SetTagValue(target, key, value);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
214 return found;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
215 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
216
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
217
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
218 static void CopyStringType1(DcmDirectoryRecord& target,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
219 DcmDataset& source,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
220 Encoding encoding,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
221 const DcmTagKey& key)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
222 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
223 CopyString(target, source, encoding, key, false, false);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
224 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
225
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
226 static void CopyStringType1C(DcmDirectoryRecord& target,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
227 DcmDataset& source,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
228 Encoding encoding,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
229 const DcmTagKey& key)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
230 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
231 CopyString(target, source, encoding, key, true, false);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
232 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
233
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
234 static void CopyStringType2(DcmDirectoryRecord& target,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
235 DcmDataset& source,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
236 Encoding encoding,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
237 const DcmTagKey& key)
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
238 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
239 CopyString(target, source, encoding, key, false, true);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
240 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
241
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
242
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 public:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 PImpl() : fileSetId_("ORTHANC_MEDIA")
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 void FillPatient(DcmDirectoryRecord& record,
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
249 DcmDataset& dicom,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
250 Encoding encoding)
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 // cf. "DicomDirInterface::buildPatientRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
254 CopyStringType1C(record, dicom, encoding, DCM_PatientID);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
255 CopyStringType2(record, dicom, encoding, DCM_PatientName);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 void FillStudy(DcmDirectoryRecord& record,
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
259 DcmDataset& dicom,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
260 Encoding encoding)
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 // cf. "DicomDirInterface::buildStudyRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
264 std::string nowDate, nowTime;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
265 SystemToolbox::GetNowDicom(nowDate, nowTime);
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
266
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
267 std::string studyDate;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
268 if (!GetUtf8TagValue(studyDate, dicom, encoding, DCM_StudyDate) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
269 !GetUtf8TagValue(studyDate, dicom, encoding, DCM_SeriesDate) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
270 !GetUtf8TagValue(studyDate, dicom, encoding, DCM_AcquisitionDate) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
271 !GetUtf8TagValue(studyDate, dicom, encoding, DCM_ContentDate))
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
272 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
273 studyDate = nowDate;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
274 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
275
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
276 std::string studyTime;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
277 if (!GetUtf8TagValue(studyTime, dicom, encoding, DCM_StudyTime) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
278 !GetUtf8TagValue(studyTime, dicom, encoding, DCM_SeriesTime) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
279 !GetUtf8TagValue(studyTime, dicom, encoding, DCM_AcquisitionTime) &&
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
280 !GetUtf8TagValue(studyTime, dicom, encoding, DCM_ContentTime))
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
281 {
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
282 studyTime = nowTime;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
283 }
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
284
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 /* copy attribute values from dataset to study record */
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
286 SetTagValue(record, DCM_StudyDate, studyDate);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
287 SetTagValue(record, DCM_StudyTime, studyTime);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
288 CopyStringType2(record, dicom, encoding, DCM_StudyDescription);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
289 CopyStringType1(record, dicom, encoding, DCM_StudyInstanceUID);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 /* use type 1C instead of 1 in order to avoid unwanted overwriting */
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
291 CopyStringType1C(record, dicom, encoding, DCM_StudyID);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
292 CopyStringType2(record, dicom, encoding, DCM_AccessionNumber);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 void FillSeries(DcmDirectoryRecord& record,
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
296 DcmDataset& dicom,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
297 Encoding encoding)
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 // cf. "DicomDirInterface::buildSeriesRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 /* copy attribute values from dataset to series record */
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
302 CopyStringType1(record, dicom, encoding, DCM_Modality);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
303 CopyStringType1(record, dicom, encoding, DCM_SeriesInstanceUID);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 /* use type 1C instead of 1 in order to avoid unwanted overwriting */
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
305 CopyStringType1C(record, dicom, encoding, DCM_SeriesNumber);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 void FillInstance(DcmDirectoryRecord& record,
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
309 DcmDataset& dicom,
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
310 Encoding encoding,
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 DcmMetaInfo& metaInfo,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 const char* path)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 // cf. "DicomDirInterface::buildImageRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 /* copy attribute values from dataset to image record */
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
317 CopyStringType1(record, dicom, encoding, DCM_InstanceNumber);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
318 //CopyElementType1C(record, dicom, encoding, DCM_ImageType);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
320 // REMOVED since 0.9.7: copyElementType1C(dicom, DCM_ReferencedImageSequence, record);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
322 std::string sopClassUid, sopInstanceUid, transferSyntaxUid;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
323 if (!GetUtf8TagValue(sopClassUid, dicom, encoding, DCM_SOPClassUID) ||
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
324 !GetUtf8TagValue(sopInstanceUid, dicom, encoding, DCM_SOPInstanceUID) ||
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
325 !GetUtf8TagValue(transferSyntaxUid, metaInfo, encoding, DCM_TransferSyntaxUID))
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 throw OrthancException(ErrorCode_BadFileFormat);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
329
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
330 SetTagValue(record, DCM_ReferencedFileID, path);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
331 SetTagValue(record, DCM_ReferencedSOPClassUIDInFile, sopClassUid);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
332 SetTagValue(record, DCM_ReferencedSOPInstanceUIDInFile, sopInstanceUid);
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
333 SetTagValue(record, DCM_ReferencedTransferSyntaxUIDInFile, transferSyntaxUid);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 bool CreateResource(DcmDirectoryRecord*& target,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 ResourceType level,
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
340 ParsedDicomFile& dicom,
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 const char* filename,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 const char* path)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
344 DcmDataset& dataset = *dicom.GetDcmtkObject().getDataset();
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
345 Encoding encoding = dicom.GetEncoding();
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
347 bool found;
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
348 std::string id;
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 E_DirRecType type;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 switch (level)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 case ResourceType_Patient:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
354 found = GetUtf8TagValue(id, dataset, encoding, DCM_PatientID);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 type = ERT_Patient;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 case ResourceType_Study:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
359 found = GetUtf8TagValue(id, dataset, encoding, DCM_StudyInstanceUID);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 type = ERT_Study;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 case ResourceType_Series:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
364 found = GetUtf8TagValue(id, dataset, encoding, DCM_SeriesInstanceUID);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 type = ERT_Series;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 case ResourceType_Instance:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
369 found = GetUtf8TagValue(id, dataset, encoding, DCM_SOPInstanceUID);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 type = ERT_Image;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 default:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 throw OrthancException(ErrorCode_InternalError);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
377 if (!found)
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
379 throw OrthancException(ErrorCode_BadFileFormat);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 IndexKey key = std::make_pair(level, std::string(id.c_str()));
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 Index::iterator it = index_.find(key);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 if (it != index_.end())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 target = it->second;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 return false; // Already existing
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 std::auto_ptr<DcmDirectoryRecord> record(new DcmDirectoryRecord(type, NULL, filename));
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 switch (level)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 case ResourceType_Patient:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
396 FillPatient(*record, dataset, encoding);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 case ResourceType_Study:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
400 FillStudy(*record, dataset, encoding);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 case ResourceType_Series:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
404 FillSeries(*record, dataset, encoding);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 case ResourceType_Instance:
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
408 FillInstance(*record, dataset, encoding, *dicom.GetDcmtkObject().getMetaInfo(), path);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 default:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 throw OrthancException(ErrorCode_InternalError);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
415 CopyStringType1C(*record, dataset, encoding, DCM_SpecificCharacterSet);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 target = record.get();
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 GetRoot().insertSub(record.release());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 index_[key] = target;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 return true; // Newly created
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 void Read(std::string& s)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 if (!GetDicomDir().write(DICOMDIR_DEFAULT_TRANSFERSYNTAX,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 EET_UndefinedLength /*encodingType*/,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 EGL_withoutGL /*groupLength*/).good())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 throw OrthancException(ErrorCode_InternalError);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 file_.Read(s);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 void SetFileSetId(const std::string& id)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 dir_.reset(NULL);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 fileSetId_ = id;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 };
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 DicomDirWriter::DicomDirWriter() : pimpl_(new PImpl)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 DicomDirWriter::~DicomDirWriter()
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 if (pimpl_)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 delete pimpl_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 void DicomDirWriter::SetFileSetId(const std::string& id)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 pimpl_->SetFileSetId(id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 void DicomDirWriter::Add(const std::string& directory,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 const std::string& filename,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 ParsedDicomFile& dicom)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 std::string path;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 if (directory.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 path = filename;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 else
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 if (directory[directory.length() - 1] == '/' ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 directory[directory.length() - 1] == '\\')
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 throw OrthancException(ErrorCode_ParameterOutOfRange);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 path = directory + '\\' + filename;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 DcmDirectoryRecord* instance;
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
482 bool isNewInstance = pimpl_->CreateResource(instance, ResourceType_Instance, dicom, filename.c_str(), path.c_str());
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 if (isNewInstance)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 DcmDirectoryRecord* series;
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
486 bool isNewSeries = pimpl_->CreateResource(series, ResourceType_Series, dicom, filename.c_str(), NULL);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 series->insertSub(instance);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 if (isNewSeries)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 DcmDirectoryRecord* study;
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
492 bool isNewStudy = pimpl_->CreateResource(study, ResourceType_Study, dicom, filename.c_str(), NULL);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 study->insertSub(series);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 if (isNewStudy)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 DcmDirectoryRecord* patient;
1885
5be57564ffc4 refactoring dicomdir generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1788
diff changeset
498 pimpl_->CreateResource(patient, ResourceType_Patient, dicom, filename.c_str(), NULL);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 patient->insertSub(study);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 void DicomDirWriter::Encode(std::string& target)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 pimpl_->Read(target);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }