annotate OrthancServer/DicomDirWriter.cpp @ 1164:0a55d8eb194e

Configuration/Lua to select the accepted C-Store SCP transfer syntaxes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Sep 2014 17:18:26 +0200
parents baac89e6cc4b
children 6e7e5ed91c2d
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 #include "../Core/OrthancException.h"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 #include "../Core/Uuid.h"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 #include <dcmtk/dcmdata/dcdicdir.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 #include <dcmtk/dcmdata/dcmetinf.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 #include <dcmtk/dcmdata/dcdeftag.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 #include <dcmtk/dcmdata/dcuid.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 #include <dcmtk/dcmdata/dcddirif.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 #include <dcmtk/dcmdata/dcvrui.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 #include <dcmtk/dcmdata/dcsequen.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 #include <dcmtk/dcmdata/dcostrmf.h>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 #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
118 #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
119
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 #include <memory>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 #include <glog/logging.h>
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 namespace Orthanc
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 class DicomDirWriter::PImpl
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 private:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 std::string fileSetId_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 Toolbox::TemporaryFile file_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 std::auto_ptr<DcmDicomDir> dir_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 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
133 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
134 Index index_;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
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 * Functions adapted from "dcmdata/libsrc/dcddirif.cc" from DCMTK 3.6.0
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 *******************************************************************************/
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 // print an error message to the console (stderr) that something went wrong with an attribute
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 static void printAttributeErrorMessage(const DcmTagKey &key,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 const OFCondition &error,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 const char *operation)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 if (error.bad())
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 OFString str;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 if (operation != NULL)
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 str = "cannot ";
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 str += operation;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 str += " ";
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 LOG(ERROR) << error.text() << ": " << str << DcmTag(key).getTagName() << " " << key;
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 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 // copy element from dataset to directory record
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 static void copyElement(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 const DcmTagKey &key,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 DcmDirectoryRecord& record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 const OFBool optional,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 const OFBool copyEmpty)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 /* check whether tag exists in source dataset (if optional) */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 if (!optional || (copyEmpty && dataset.tagExists(key)) || dataset.tagExistsWithValue(key))
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 DcmElement *delem = NULL;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 /* get copy of element from source dataset */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 OFCondition status = dataset.findAndGetElement(key, delem, OFFalse /*searchIntoSub*/, OFTrue /*createCopy*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 if (status.good())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 /* ... and insert it into the destination dataset (record) */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 status = record.insert(delem, OFTrue /*replaceOld*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (status.good())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 DcmTag tag(key);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 /* check for correct VR in the dataset */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 if (delem->getVR() != tag.getEVR())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 /* create warning message */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 LOG(WARNING) << "DICOMDIR: possibly wrong VR: "
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 << tag.getTagName() << " " << key << " with "
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 << DcmVR(delem->getVR()).getVRName() << " found, expected "
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 << tag.getVRName() << " instead";
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 } else
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 delete delem;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 } else if (status == EC_TagNotFound)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 status = record.insertEmptyElement(key);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 printAttributeErrorMessage(key, status, "insert");
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 // copy optional string value from dataset to directory record
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 static void copyStringWithDefault(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 const DcmTagKey &key,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 DcmDirectoryRecord& record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 const char *defaultValue,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 const OFBool printWarning)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 OFCondition status;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 if (dataset.tagExistsWithValue(key))
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 OFString stringValue;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 /* retrieve string value from source dataset and put it into the destination dataset */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 status = dataset.findAndGetOFStringArray(key, stringValue);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 if (status.good())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 status = record.putAndInsertString(key, stringValue.c_str());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 } else {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 if (printWarning && (defaultValue != NULL))
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 /* create warning message */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 LOG(WARNING) << "DICOMDIR: " << DcmTag(key).getTagName() << " "
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 << key << " missing, using alternative: " << defaultValue;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 /* put default value */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 status = record.putAndInsertString(key, defaultValue);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 // create alternative study date if absent in dataset
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 static OFString &alternativeStudyDate(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 OFString &result)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 /* use another date if present */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 if (dataset.findAndGetOFStringArray(DCM_SeriesDate, result).bad() || result.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (dataset.findAndGetOFStringArray(DCM_AcquisitionDate, result).bad() || result.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 if (dataset.findAndGetOFStringArray(DCM_ContentDate, result).bad() || result.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 /* use current date, "19000101" in case of error */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 DcmDate::getCurrentDate(result);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 return result;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 // create alternative study time if absent in dataset
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 static OFString &alternativeStudyTime(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 OFString &result)
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 /* use another time if present */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 if (dataset.findAndGetOFStringArray(DCM_SeriesTime, result).bad() || result.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (dataset.findAndGetOFStringArray(DCM_AcquisitionTime, result).bad() || result.empty())
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 if (dataset.findAndGetOFStringArray(DCM_ContentTime, result).bad() || result.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 /* use current time, "0000" in case of error */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 DcmTime::getCurrentTime(result);
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 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 return result;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 static void copyElementType1(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 const DcmTagKey &key,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 DcmDirectoryRecord& record)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 copyElement(dataset, key, record, OFFalse /*optional*/, OFFalse /*copyEmpty*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 static void copyElementType1C(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 const DcmTagKey &key,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 DcmDirectoryRecord& record)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 copyElement(dataset, key, record, OFTrue /*optional*/, OFFalse /*copyEmpty*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 static void copyElementType2(DcmItem& dataset,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 const DcmTagKey &key,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 DcmDirectoryRecord& record)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 copyElement(dataset, key, record, OFFalse /*optional*/, OFTrue /*copyEmpty*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 /*******************************************************************************
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 * End of functions adapted from "dcmdata/libsrc/dcddirif.cc" from DCMTK 3.6.0
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 *******************************************************************************/
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 DcmDicomDir& GetDicomDir()
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 if (dir_.get() == NULL)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 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
294 fileSetId_.c_str()));
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 return *dir_;
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
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 DcmDirectoryRecord& GetRoot()
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 return GetDicomDir().getRootRecord();
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
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 public:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 PImpl() : fileSetId_("ORTHANC_MEDIA")
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 void FillPatient(DcmDirectoryRecord& record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 DcmItem& dicom)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 // cf. "DicomDirInterface::buildPatientRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 copyElementType1C(dicom, DCM_PatientID, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 copyElementType2(dicom, DCM_PatientName, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 void FillStudy(DcmDirectoryRecord& record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 DcmItem& dicom)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 // cf. "DicomDirInterface::buildStudyRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 OFString tmpString;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 /* copy attribute values from dataset to study record */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 copyStringWithDefault(dicom, DCM_StudyDate, record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 alternativeStudyDate(dicom, tmpString).c_str(), OFTrue /*printWarning*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 copyStringWithDefault(dicom, DCM_StudyTime, record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 alternativeStudyTime(dicom, tmpString).c_str(), OFTrue /*printWarning*/);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 copyElementType2(dicom, DCM_StudyDescription, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 copyElementType1(dicom, DCM_StudyInstanceUID, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 /* use type 1C instead of 1 in order to avoid unwanted overwriting */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 copyElementType1C(dicom, DCM_StudyID, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 copyElementType2(dicom, DCM_AccessionNumber, record);
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 void FillSeries(DcmDirectoryRecord& record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 DcmItem& dicom)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 // cf. "DicomDirInterface::buildSeriesRecord()"
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 /* copy attribute values from dataset to series record */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 copyElementType1(dicom, DCM_Modality, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 copyElementType1(dicom, DCM_SeriesInstanceUID, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 /* use type 1C instead of 1 in order to avoid unwanted overwriting */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 copyElementType1C(dicom, DCM_SeriesNumber, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
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 void FillInstance(DcmDirectoryRecord& record,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 DcmItem& dicom,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 DcmMetaInfo& metaInfo,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 const char* path)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 // cf. "DicomDirInterface::buildImageRecord()"
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 /* copy attribute values from dataset to image record */
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 copyElementType1(dicom, DCM_InstanceNumber, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 //copyElementType1C(dicom, DCM_ImageType, record);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 copyElementType1C(dicom, DCM_ReferencedImageSequence, record);
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 OFString tmp;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 DcmElement* item = record.remove(DCM_ReferencedImageSequence);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 if (item != NULL)
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 delete item;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (record.putAndInsertString(DCM_ReferencedFileID, path).bad() ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 dicom.findAndGetOFStringArray(DCM_SOPClassUID, tmp).bad() ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 record.putAndInsertString(DCM_ReferencedSOPClassUIDInFile, tmp.c_str()).bad() ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 dicom.findAndGetOFStringArray(DCM_SOPInstanceUID, tmp).bad() ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 record.putAndInsertString(DCM_ReferencedSOPInstanceUIDInFile, tmp.c_str()).bad() ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 metaInfo.findAndGetOFStringArray(DCM_TransferSyntaxUID, tmp).bad() ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 record.putAndInsertString(DCM_ReferencedTransferSyntaxUIDInFile, tmp.c_str()).bad())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 throw OrthancException(ErrorCode_BadFileFormat);
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
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 bool CreateResource(DcmDirectoryRecord*& target,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 ResourceType level,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 DcmFileFormat& dicom,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 const char* filename,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 const char* path)
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 DcmDataset& dataset = *dicom.getDataset();
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 OFCondition result;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 OFString id;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 E_DirRecType type;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 switch (level)
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_Patient:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 result = dataset.findAndGetOFString(DCM_PatientID, id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 type = ERT_Patient;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 case ResourceType_Study:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 result = dataset.findAndGetOFString(DCM_StudyInstanceUID, id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 type = ERT_Study;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 case ResourceType_Series:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 result = dataset.findAndGetOFString(DCM_SeriesInstanceUID, id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 type = ERT_Series;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 break;
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 case ResourceType_Instance:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 result = dataset.findAndGetOFString(DCM_SOPInstanceUID, id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 type = ERT_Image;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 default:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 throw OrthancException(ErrorCode_InternalError);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }
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 if (!result.good())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 throw OrthancException(ErrorCode_InternalError);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 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
429 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
430
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 if (it != index_.end())
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 target = it->second;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 return false; // Already existing
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 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
438
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 switch (level)
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 case ResourceType_Patient:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 FillPatient(*record, dataset);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 case ResourceType_Study:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 FillStudy(*record, dataset);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 case ResourceType_Series:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 FillSeries(*record, dataset);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 case ResourceType_Instance:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 FillInstance(*record, dataset, *dicom.getMetaInfo(), path);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 break;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 default:
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 throw OrthancException(ErrorCode_InternalError);
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 if (record->isAffectedBySpecificCharacterSet())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 copyElementType1C(dataset, DCM_SpecificCharacterSet, *record);
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 target = record.get();
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 GetRoot().insertSub(record.release());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 index_[key] = target;
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 return true; // Newly created
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 void Read(std::string& s)
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 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
476 EET_UndefinedLength /*encodingType*/,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 EGL_withoutGL /*groupLength*/).good())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 throw OrthancException(ErrorCode_InternalError);
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 file_.Read(s);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
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 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
486 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 dir_.reset(NULL);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 fileSetId_ = id;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 }
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 DicomDirWriter::DicomDirWriter() : pimpl_(new PImpl)
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 }
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 DicomDirWriter::~DicomDirWriter()
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 if (pimpl_)
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 delete pimpl_;
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::SetFileSetId(const std::string& id)
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_->SetFileSetId(id);
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
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 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
511 const std::string& filename,
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 ParsedDicomFile& dicom)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 std::string path;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 if (directory.empty())
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 path = filename;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 else
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 if (directory[directory.length() - 1] == '/' ||
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 directory[directory.length() - 1] == '\\')
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 throw OrthancException(ErrorCode_ParameterOutOfRange);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 path = directory + '\\' + filename;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 DcmFileFormat& fileFormat = *reinterpret_cast<DcmFileFormat*>(dicom.GetDcmtkObject());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 DcmDirectoryRecord* instance;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 bool isNewInstance = pimpl_->CreateResource(instance, ResourceType_Instance, fileFormat, filename.c_str(), path.c_str());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 if (isNewInstance)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 DcmDirectoryRecord* series;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 bool isNewSeries = pimpl_->CreateResource(series, ResourceType_Series, fileFormat, filename.c_str(), NULL);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 series->insertSub(instance);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 if (isNewSeries)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 DcmDirectoryRecord* study;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 bool isNewStudy = pimpl_->CreateResource(study, ResourceType_Study, fileFormat, filename.c_str(), NULL);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 study->insertSub(series);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 if (isNewStudy)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 DcmDirectoryRecord* patient;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 pimpl_->CreateResource(patient, ResourceType_Patient, fileFormat, filename.c_str(), NULL);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 patient->insertSub(study);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 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
557 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 pimpl_->Read(target);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }