comparison OrthancFramework/Sources/Enumerations.cpp @ 5807:8279eaab0d1d attach-custom-data

merged default -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 11:39:52 +0200
parents f7adfb22e20e
children 56352ae88120
comparison
equal deleted inserted replaced
5085:79f98ee4f04b 5807:8279eaab0d1d
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium 6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 * 8 *
8 * This program is free software: you can redistribute it and/or 9 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License 10 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of 11 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
22 23
23 24
24 #include "PrecompiledHeaders.h" 25 #include "PrecompiledHeaders.h"
25 #include "Enumerations.h" 26 #include "Enumerations.h"
26 27
28 #include "Logging.h"
29 #include "MultiThreading/Mutex.h"
27 #include "OrthancException.h" 30 #include "OrthancException.h"
28 #include "Toolbox.h" 31 #include "Toolbox.h"
29 #include "Logging.h" 32
30
31 #include <boost/thread/mutex.hpp>
32 #include <string.h> 33 #include <string.h>
33 #include <cassert> 34 #include <cassert>
35 #include <boost/algorithm/string/replace.hpp>
34 36
35 namespace Orthanc 37 namespace Orthanc
36 { 38 {
37 static const char* const MIME_CSS = "text/css";
38 static const char* const MIME_DICOM = "application/dicom";
39 static const char* const MIME_GIF = "image/gif";
40 static const char* const MIME_GZIP = "application/gzip";
41 static const char* const MIME_HTML = "text/html";
42 static const char* const MIME_JAVASCRIPT = "application/javascript";
43 static const char* const MIME_JPEG2000 = "image/jp2";
44 static const char* const MIME_NACL = "application/x-nacl";
45 static const char* const MIME_PLAIN_TEXT = "text/plain";
46 static const char* const MIME_PNACL = "application/x-pnacl";
47 static const char* const MIME_SVG = "image/svg+xml";
48 static const char* const MIME_WEB_ASSEMBLY = "application/wasm";
49 static const char* const MIME_WOFF = "application/x-font-woff";
50 static const char* const MIME_WOFF2 = "font/woff2";
51 static const char* const MIME_XML_2 = "text/xml";
52 static const char* const MIME_ZIP = "application/zip";
53 static const char* const MIME_DICOM_WEB_JSON = "application/dicom+json";
54 static const char* const MIME_DICOM_WEB_XML = "application/dicom+xml";
55 static const char* const MIME_ICO = "image/x-icon";
56
57 // This function is autogenerated by the script 39 // This function is autogenerated by the script
58 // "Resources/CodeGeneration/GenerateErrorCodes.py" 40 // "Resources/CodeGeneration/GenerateErrorCodes.py"
59 const char* EnumerationToString(ErrorCode error) 41 const char* EnumerationToString(ErrorCode error)
60 { 42 {
61 switch (error) 43 switch (error)
195 case ErrorCode_Revision: 177 case ErrorCode_Revision:
196 return "A bad revision number was provided, which might indicate conflict between multiple writers"; 178 return "A bad revision number was provided, which might indicate conflict between multiple writers";
197 179
198 case ErrorCode_MainDicomTagsMultiplyDefined: 180 case ErrorCode_MainDicomTagsMultiplyDefined:
199 return "A main DICOM Tag has been defined multiple times for the same resource level"; 181 return "A main DICOM Tag has been defined multiple times for the same resource level";
182
183 case ErrorCode_ForbiddenAccess:
184 return "Access to a resource is forbidden";
185
186 case ErrorCode_DuplicateResource:
187 return "Duplicate resource";
200 188
201 case ErrorCode_SQLiteNotOpened: 189 case ErrorCode_SQLiteNotOpened:
202 return "SQLite: The database is not opened"; 190 return "SQLite: The database is not opened";
203 191
204 case ErrorCode_SQLiteAlreadyOpened: 192 case ErrorCode_SQLiteAlreadyOpened:
875 { 863 {
876 switch (version) 864 switch (version)
877 { 865 {
878 case DicomVersion_2008: 866 case DicomVersion_2008:
879 return "2008"; 867 return "2008";
880 break;
881 868
882 case DicomVersion_2017c: 869 case DicomVersion_2017c:
883 return "2017c"; 870 return "2017c";
884 break;
885 871
886 case DicomVersion_2021b: 872 case DicomVersion_2021b:
887 return "2021b"; 873 return "2021b";
888 break; 874
875 case DicomVersion_2023b:
876 return "2023b";
889 877
890 default: 878 default:
891 throw OrthancException(ErrorCode_ParameterOutOfRange); 879 throw OrthancException(ErrorCode_ParameterOutOfRange);
892 } 880 }
893 } 881 }
1108 return MIME_DICOM_WEB_XML; 1096 return MIME_DICOM_WEB_XML;
1109 1097
1110 case MimeType_Ico: 1098 case MimeType_Ico:
1111 return MIME_ICO; 1099 return MIME_ICO;
1112 1100
1101 case MimeType_Obj:
1102 return MIME_OBJ;
1103
1104 case MimeType_Mtl:
1105 return MIME_MTL;
1106
1107 case MimeType_Stl:
1108 return MIME_STL;
1109
1113 default: 1110 default:
1114 throw OrthancException(ErrorCode_ParameterOutOfRange); 1111 throw OrthancException(ErrorCode_ParameterOutOfRange);
1115 } 1112 }
1116 } 1113 }
1117 1114
1639 } 1636 }
1640 else if (version == "2021b") 1637 else if (version == "2021b")
1641 { 1638 {
1642 return DicomVersion_2021b; 1639 return DicomVersion_2021b;
1643 } 1640 }
1641 else if (version == "2023b")
1642 {
1643 return DicomVersion_2023b;
1644 }
1644 else 1645 else
1645 { 1646 {
1646 throw OrthancException(ErrorCode_ParameterOutOfRange, 1647 throw OrthancException(ErrorCode_ParameterOutOfRange,
1647 "Unknown specific version of the DICOM standard: " + version); 1648 "Unknown specific version of the DICOM standard: " + version);
1648 } 1649 }
1726 else if (source == MIME_DICOM) 1727 else if (source == MIME_DICOM)
1727 { 1728 {
1728 target = MimeType_Dicom; 1729 target = MimeType_Dicom;
1729 return true; 1730 return true;
1730 } 1731 }
1731 else if (source == MIME_JPEG) 1732 else if (source == MIME_JPEG ||
1732 { 1733 source == "image/jpg")
1734 {
1735 // Note the tolerance for "image/jpg", which is *not* a standard MIME type
1736 // https://groups.google.com/g/orthanc-users/c/Y5x37UFKiDg/m/1zI260KTAwAJ
1737 // https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
1733 target = MimeType_Jpeg; 1738 target = MimeType_Jpeg;
1734 return true; 1739 return true;
1735 } 1740 }
1736 else if (source == MIME_JPEG2000) 1741 else if (source == MIME_JPEG2000)
1737 { 1742 {
1840 return true; 1845 return true;
1841 } 1846 }
1842 else if (source == MIME_ICO) 1847 else if (source == MIME_ICO)
1843 { 1848 {
1844 target = MimeType_Ico; 1849 target = MimeType_Ico;
1850 return true;
1851 }
1852 else if (source == MIME_OBJ)
1853 {
1854 target = MimeType_Obj;
1855 return true;
1856 }
1857 else if (source == MIME_MTL)
1858 {
1859 target = MimeType_Mtl;
1860 return true;
1861 }
1862 else if (source == MIME_STL)
1863 {
1864 target = MimeType_Stl;
1845 return true; 1865 return true;
1846 } 1866 }
1847 else 1867 else
1848 { 1868 {
1849 return false; 1869 return false;
1926 bool GetDicomEncoding(Encoding& encoding, 1946 bool GetDicomEncoding(Encoding& encoding,
1927 const char* specificCharacterSet) 1947 const char* specificCharacterSet)
1928 { 1948 {
1929 std::string s = Toolbox::StripSpaces(specificCharacterSet); 1949 std::string s = Toolbox::StripSpaces(specificCharacterSet);
1930 Toolbox::ToUpperCase(s); 1950 Toolbox::ToUpperCase(s);
1951
1952 // handle common spelling mistakes
1953 boost::replace_all(s, "ISO_IR_", "ISO_IR ");
1954 boost::replace_all(s, "ISO_2022_IR_", "ISO 2022 IR ");
1955
1931 1956
1932 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2 1957 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2
1933 // https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/SpecificCharacterSet.java 1958 // https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/SpecificCharacterSet.java
1934 if (s == "ISO_IR 6" || 1959 if (s == "ISO_IR 6" ||
1935 s == "ISO 2022 IR 6") 1960 s == "ISO 2022 IR 6")
2236 2261
2237 case ErrorCode_DatabaseCannotSerialize: 2262 case ErrorCode_DatabaseCannotSerialize:
2238 return HttpStatus_503_ServiceUnavailable; 2263 return HttpStatus_503_ServiceUnavailable;
2239 2264
2240 case ErrorCode_Revision: 2265 case ErrorCode_Revision:
2266 return HttpStatus_409_Conflict;
2267
2268 case ErrorCode_ForbiddenAccess:
2269 return HttpStatus_403_Forbidden;
2270
2271 case ErrorCode_DuplicateResource:
2241 return HttpStatus_409_Conflict; 2272 return HttpStatus_409_Conflict;
2242 2273
2243 case ErrorCode_CreateDicomNotString: 2274 case ErrorCode_CreateDicomNotString:
2244 return HttpStatus_400_BadRequest; 2275 return HttpStatus_400_BadRequest;
2245 2276
2331 throw OrthancException(ErrorCode_ParameterOutOfRange); 2362 throw OrthancException(ErrorCode_ParameterOutOfRange);
2332 } 2363 }
2333 } 2364 }
2334 2365
2335 2366
2336 static boost::mutex defaultEncodingMutex_; // Should not be necessary 2367 static Mutex defaultEncodingMutex_; // Should not be necessary
2337 static Encoding defaultEncoding_ = ORTHANC_DEFAULT_DICOM_ENCODING; 2368 static Encoding defaultEncoding_ = ORTHANC_DEFAULT_DICOM_ENCODING;
2338 2369
2339 Encoding GetDefaultDicomEncoding() 2370 Encoding GetDefaultDicomEncoding()
2340 { 2371 {
2341 boost::mutex::scoped_lock lock(defaultEncodingMutex_); 2372 Mutex::ScopedLock lock(defaultEncodingMutex_);
2342 return defaultEncoding_; 2373 return defaultEncoding_;
2343 } 2374 }
2344 2375
2345 void SetDefaultDicomEncoding(Encoding encoding) 2376 void SetDefaultDicomEncoding(Encoding encoding)
2346 { 2377 {
2347 std::string name = EnumerationToString(encoding); 2378 std::string name = EnumerationToString(encoding);
2348 2379
2349 { 2380 {
2350 boost::mutex::scoped_lock lock(defaultEncodingMutex_); 2381 Mutex::ScopedLock lock(defaultEncodingMutex_);
2351 defaultEncoding_ = encoding; 2382 defaultEncoding_ = encoding;
2352 } 2383 }
2353 2384
2354 LOG(INFO) << "Default encoding for DICOM was changed to: " << name; 2385 LOG(INFO) << "Default encoding for DICOM was changed to: " << name;
2355 } 2386 }
2442 else 2473 else
2443 { 2474 {
2444 throw OrthancException(ErrorCode_InternalError); 2475 throw OrthancException(ErrorCode_InternalError);
2445 } 2476 }
2446 } 2477 }
2478
2479 DicomTransferSyntax GetTransferSyntax(const std::string& value)
2480 {
2481 DicomTransferSyntax syntax;
2482 if (LookupTransferSyntax(syntax, value))
2483 {
2484 return syntax;
2485 }
2486 else
2487 {
2488 throw OrthancException(ErrorCode_ParameterOutOfRange,
2489 "Unknown transfer syntax: " + value);
2490 }
2491 }
2492
2447 } 2493 }
2448 2494
2449 2495
2450 #include "./Enumerations_TransferSyntaxes.impl.h" 2496 #include "./Enumerations_TransferSyntaxes.impl.h"