Mercurial > hg > orthanc-wsi
comparison Resources/Orthanc/Core/Enumerations.cpp @ 59:7a3853d51c45
Move "Framework/Orthanc/" as "Resources/Orthanc/"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Nov 2016 16:34:34 +0100 |
parents | Framework/Orthanc/Core/Enumerations.cpp@533cbc4d520c |
children | 5b127ab0080b |
comparison
equal
deleted
inserted
replaced
58:35468714a38e | 59:7a3853d51c45 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "PrecompiledHeaders.h" | |
34 #include "Enumerations.h" | |
35 | |
36 #include "OrthancException.h" | |
37 #include "Toolbox.h" | |
38 #include "Logging.h" | |
39 | |
40 #include <string.h> | |
41 #include <cassert> | |
42 | |
43 namespace Orthanc | |
44 { | |
45 // This function is autogenerated by the script | |
46 // "Resources/GenerateErrorCodes.py" | |
47 const char* EnumerationToString(ErrorCode error) | |
48 { | |
49 switch (error) | |
50 { | |
51 case ErrorCode_InternalError: | |
52 return "Internal error"; | |
53 | |
54 case ErrorCode_Success: | |
55 return "Success"; | |
56 | |
57 case ErrorCode_Plugin: | |
58 return "Error encountered within the plugin engine"; | |
59 | |
60 case ErrorCode_NotImplemented: | |
61 return "Not implemented yet"; | |
62 | |
63 case ErrorCode_ParameterOutOfRange: | |
64 return "Parameter out of range"; | |
65 | |
66 case ErrorCode_NotEnoughMemory: | |
67 return "The server hosting Orthanc is running out of memory"; | |
68 | |
69 case ErrorCode_BadParameterType: | |
70 return "Bad type for a parameter"; | |
71 | |
72 case ErrorCode_BadSequenceOfCalls: | |
73 return "Bad sequence of calls"; | |
74 | |
75 case ErrorCode_InexistentItem: | |
76 return "Accessing an inexistent item"; | |
77 | |
78 case ErrorCode_BadRequest: | |
79 return "Bad request"; | |
80 | |
81 case ErrorCode_NetworkProtocol: | |
82 return "Error in the network protocol"; | |
83 | |
84 case ErrorCode_SystemCommand: | |
85 return "Error while calling a system command"; | |
86 | |
87 case ErrorCode_Database: | |
88 return "Error with the database engine"; | |
89 | |
90 case ErrorCode_UriSyntax: | |
91 return "Badly formatted URI"; | |
92 | |
93 case ErrorCode_InexistentFile: | |
94 return "Inexistent file"; | |
95 | |
96 case ErrorCode_CannotWriteFile: | |
97 return "Cannot write to file"; | |
98 | |
99 case ErrorCode_BadFileFormat: | |
100 return "Bad file format"; | |
101 | |
102 case ErrorCode_Timeout: | |
103 return "Timeout"; | |
104 | |
105 case ErrorCode_UnknownResource: | |
106 return "Unknown resource"; | |
107 | |
108 case ErrorCode_IncompatibleDatabaseVersion: | |
109 return "Incompatible version of the database"; | |
110 | |
111 case ErrorCode_FullStorage: | |
112 return "The file storage is full"; | |
113 | |
114 case ErrorCode_CorruptedFile: | |
115 return "Corrupted file (e.g. inconsistent MD5 hash)"; | |
116 | |
117 case ErrorCode_InexistentTag: | |
118 return "Inexistent tag"; | |
119 | |
120 case ErrorCode_ReadOnly: | |
121 return "Cannot modify a read-only data structure"; | |
122 | |
123 case ErrorCode_IncompatibleImageFormat: | |
124 return "Incompatible format of the images"; | |
125 | |
126 case ErrorCode_IncompatibleImageSize: | |
127 return "Incompatible size of the images"; | |
128 | |
129 case ErrorCode_SharedLibrary: | |
130 return "Error while using a shared library (plugin)"; | |
131 | |
132 case ErrorCode_UnknownPluginService: | |
133 return "Plugin invoking an unknown service"; | |
134 | |
135 case ErrorCode_UnknownDicomTag: | |
136 return "Unknown DICOM tag"; | |
137 | |
138 case ErrorCode_BadJson: | |
139 return "Cannot parse a JSON document"; | |
140 | |
141 case ErrorCode_Unauthorized: | |
142 return "Bad credentials were provided to an HTTP request"; | |
143 | |
144 case ErrorCode_BadFont: | |
145 return "Badly formatted font file"; | |
146 | |
147 case ErrorCode_DatabasePlugin: | |
148 return "The plugin implementing a custom database back-end does not fulfill the proper interface"; | |
149 | |
150 case ErrorCode_StorageAreaPlugin: | |
151 return "Error in the plugin implementing a custom storage area"; | |
152 | |
153 case ErrorCode_EmptyRequest: | |
154 return "The request is empty"; | |
155 | |
156 case ErrorCode_NotAcceptable: | |
157 return "Cannot send a response which is acceptable according to the Accept HTTP header"; | |
158 | |
159 case ErrorCode_NullPointer: | |
160 return "Cannot handle a NULL pointer"; | |
161 | |
162 case ErrorCode_SQLiteNotOpened: | |
163 return "SQLite: The database is not opened"; | |
164 | |
165 case ErrorCode_SQLiteAlreadyOpened: | |
166 return "SQLite: Connection is already open"; | |
167 | |
168 case ErrorCode_SQLiteCannotOpen: | |
169 return "SQLite: Unable to open the database"; | |
170 | |
171 case ErrorCode_SQLiteStatementAlreadyUsed: | |
172 return "SQLite: This cached statement is already being referred to"; | |
173 | |
174 case ErrorCode_SQLiteExecute: | |
175 return "SQLite: Cannot execute a command"; | |
176 | |
177 case ErrorCode_SQLiteRollbackWithoutTransaction: | |
178 return "SQLite: Rolling back a nonexistent transaction (have you called Begin()?)"; | |
179 | |
180 case ErrorCode_SQLiteCommitWithoutTransaction: | |
181 return "SQLite: Committing a nonexistent transaction"; | |
182 | |
183 case ErrorCode_SQLiteRegisterFunction: | |
184 return "SQLite: Unable to register a function"; | |
185 | |
186 case ErrorCode_SQLiteFlush: | |
187 return "SQLite: Unable to flush the database"; | |
188 | |
189 case ErrorCode_SQLiteCannotRun: | |
190 return "SQLite: Cannot run a cached statement"; | |
191 | |
192 case ErrorCode_SQLiteCannotStep: | |
193 return "SQLite: Cannot step over a cached statement"; | |
194 | |
195 case ErrorCode_SQLiteBindOutOfRange: | |
196 return "SQLite: Bing a value while out of range (serious error)"; | |
197 | |
198 case ErrorCode_SQLitePrepareStatement: | |
199 return "SQLite: Cannot prepare a cached statement"; | |
200 | |
201 case ErrorCode_SQLiteTransactionAlreadyStarted: | |
202 return "SQLite: Beginning the same transaction twice"; | |
203 | |
204 case ErrorCode_SQLiteTransactionCommit: | |
205 return "SQLite: Failure when committing the transaction"; | |
206 | |
207 case ErrorCode_SQLiteTransactionBegin: | |
208 return "SQLite: Cannot start a transaction"; | |
209 | |
210 case ErrorCode_DirectoryOverFile: | |
211 return "The directory to be created is already occupied by a regular file"; | |
212 | |
213 case ErrorCode_FileStorageCannotWrite: | |
214 return "Unable to create a subdirectory or a file in the file storage"; | |
215 | |
216 case ErrorCode_DirectoryExpected: | |
217 return "The specified path does not point to a directory"; | |
218 | |
219 case ErrorCode_HttpPortInUse: | |
220 return "The TCP port of the HTTP server is privileged or already in use"; | |
221 | |
222 case ErrorCode_DicomPortInUse: | |
223 return "The TCP port of the DICOM server is privileged or already in use"; | |
224 | |
225 case ErrorCode_BadHttpStatusInRest: | |
226 return "This HTTP status is not allowed in a REST API"; | |
227 | |
228 case ErrorCode_RegularFileExpected: | |
229 return "The specified path does not point to a regular file"; | |
230 | |
231 case ErrorCode_PathToExecutable: | |
232 return "Unable to get the path to the executable"; | |
233 | |
234 case ErrorCode_MakeDirectory: | |
235 return "Cannot create a directory"; | |
236 | |
237 case ErrorCode_BadApplicationEntityTitle: | |
238 return "An application entity title (AET) cannot be empty or be longer than 16 characters"; | |
239 | |
240 case ErrorCode_NoCFindHandler: | |
241 return "No request handler factory for DICOM C-FIND SCP"; | |
242 | |
243 case ErrorCode_NoCMoveHandler: | |
244 return "No request handler factory for DICOM C-MOVE SCP"; | |
245 | |
246 case ErrorCode_NoCStoreHandler: | |
247 return "No request handler factory for DICOM C-STORE SCP"; | |
248 | |
249 case ErrorCode_NoApplicationEntityFilter: | |
250 return "No application entity filter"; | |
251 | |
252 case ErrorCode_NoSopClassOrInstance: | |
253 return "DicomUserConnection: Unable to find the SOP class and instance"; | |
254 | |
255 case ErrorCode_NoPresentationContext: | |
256 return "DicomUserConnection: No acceptable presentation context for modality"; | |
257 | |
258 case ErrorCode_DicomFindUnavailable: | |
259 return "DicomUserConnection: The C-FIND command is not supported by the remote SCP"; | |
260 | |
261 case ErrorCode_DicomMoveUnavailable: | |
262 return "DicomUserConnection: The C-MOVE command is not supported by the remote SCP"; | |
263 | |
264 case ErrorCode_CannotStoreInstance: | |
265 return "Cannot store an instance"; | |
266 | |
267 case ErrorCode_CreateDicomNotString: | |
268 return "Only string values are supported when creating DICOM instances"; | |
269 | |
270 case ErrorCode_CreateDicomOverrideTag: | |
271 return "Trying to override a value inherited from a parent module"; | |
272 | |
273 case ErrorCode_CreateDicomUseContent: | |
274 return "Use \"Content\" to inject an image into a new DICOM instance"; | |
275 | |
276 case ErrorCode_CreateDicomNoPayload: | |
277 return "No payload is present for one instance in the series"; | |
278 | |
279 case ErrorCode_CreateDicomUseDataUriScheme: | |
280 return "The payload of the DICOM instance must be specified according to Data URI scheme"; | |
281 | |
282 case ErrorCode_CreateDicomBadParent: | |
283 return "Trying to attach a new DICOM instance to an inexistent resource"; | |
284 | |
285 case ErrorCode_CreateDicomParentIsInstance: | |
286 return "Trying to attach a new DICOM instance to an instance (must be a series, study or patient)"; | |
287 | |
288 case ErrorCode_CreateDicomParentEncoding: | |
289 return "Unable to get the encoding of the parent resource"; | |
290 | |
291 case ErrorCode_UnknownModality: | |
292 return "Unknown modality"; | |
293 | |
294 case ErrorCode_BadJobOrdering: | |
295 return "Bad ordering of filters in a job"; | |
296 | |
297 case ErrorCode_JsonToLuaTable: | |
298 return "Cannot convert the given JSON object to a Lua table"; | |
299 | |
300 case ErrorCode_CannotCreateLua: | |
301 return "Cannot create the Lua context"; | |
302 | |
303 case ErrorCode_CannotExecuteLua: | |
304 return "Cannot execute a Lua command"; | |
305 | |
306 case ErrorCode_LuaAlreadyExecuted: | |
307 return "Arguments cannot be pushed after the Lua function is executed"; | |
308 | |
309 case ErrorCode_LuaBadOutput: | |
310 return "The Lua function does not give the expected number of outputs"; | |
311 | |
312 case ErrorCode_NotLuaPredicate: | |
313 return "The Lua function is not a predicate (only true/false outputs allowed)"; | |
314 | |
315 case ErrorCode_LuaReturnsNoString: | |
316 return "The Lua function does not return a string"; | |
317 | |
318 case ErrorCode_StorageAreaAlreadyRegistered: | |
319 return "Another plugin has already registered a custom storage area"; | |
320 | |
321 case ErrorCode_DatabaseBackendAlreadyRegistered: | |
322 return "Another plugin has already registered a custom database back-end"; | |
323 | |
324 case ErrorCode_DatabaseNotInitialized: | |
325 return "Plugin trying to call the database during its initialization"; | |
326 | |
327 case ErrorCode_SslDisabled: | |
328 return "Orthanc has been built without SSL support"; | |
329 | |
330 case ErrorCode_CannotOrderSlices: | |
331 return "Unable to order the slices of the series"; | |
332 | |
333 case ErrorCode_NoWorklistHandler: | |
334 return "No request handler factory for DICOM C-Find Modality SCP"; | |
335 | |
336 case ErrorCode_AlreadyExistingTag: | |
337 return "Cannot override the value of a tag that already exists"; | |
338 | |
339 default: | |
340 if (error >= ErrorCode_START_PLUGINS) | |
341 { | |
342 return "Error encountered within some plugin"; | |
343 } | |
344 else | |
345 { | |
346 return "Unknown error code"; | |
347 } | |
348 } | |
349 } | |
350 | |
351 | |
352 const char* EnumerationToString(HttpMethod method) | |
353 { | |
354 switch (method) | |
355 { | |
356 case HttpMethod_Get: | |
357 return "GET"; | |
358 | |
359 case HttpMethod_Post: | |
360 return "POST"; | |
361 | |
362 case HttpMethod_Delete: | |
363 return "DELETE"; | |
364 | |
365 case HttpMethod_Put: | |
366 return "PUT"; | |
367 | |
368 default: | |
369 return "?"; | |
370 } | |
371 } | |
372 | |
373 | |
374 const char* EnumerationToString(HttpStatus status) | |
375 { | |
376 switch (status) | |
377 { | |
378 case HttpStatus_100_Continue: | |
379 return "Continue"; | |
380 | |
381 case HttpStatus_101_SwitchingProtocols: | |
382 return "Switching Protocols"; | |
383 | |
384 case HttpStatus_102_Processing: | |
385 return "Processing"; | |
386 | |
387 case HttpStatus_200_Ok: | |
388 return "OK"; | |
389 | |
390 case HttpStatus_201_Created: | |
391 return "Created"; | |
392 | |
393 case HttpStatus_202_Accepted: | |
394 return "Accepted"; | |
395 | |
396 case HttpStatus_203_NonAuthoritativeInformation: | |
397 return "Non-Authoritative Information"; | |
398 | |
399 case HttpStatus_204_NoContent: | |
400 return "No Content"; | |
401 | |
402 case HttpStatus_205_ResetContent: | |
403 return "Reset Content"; | |
404 | |
405 case HttpStatus_206_PartialContent: | |
406 return "Partial Content"; | |
407 | |
408 case HttpStatus_207_MultiStatus: | |
409 return "Multi-Status"; | |
410 | |
411 case HttpStatus_208_AlreadyReported: | |
412 return "Already Reported"; | |
413 | |
414 case HttpStatus_226_IMUsed: | |
415 return "IM Used"; | |
416 | |
417 case HttpStatus_300_MultipleChoices: | |
418 return "Multiple Choices"; | |
419 | |
420 case HttpStatus_301_MovedPermanently: | |
421 return "Moved Permanently"; | |
422 | |
423 case HttpStatus_302_Found: | |
424 return "Found"; | |
425 | |
426 case HttpStatus_303_SeeOther: | |
427 return "See Other"; | |
428 | |
429 case HttpStatus_304_NotModified: | |
430 return "Not Modified"; | |
431 | |
432 case HttpStatus_305_UseProxy: | |
433 return "Use Proxy"; | |
434 | |
435 case HttpStatus_307_TemporaryRedirect: | |
436 return "Temporary Redirect"; | |
437 | |
438 case HttpStatus_400_BadRequest: | |
439 return "Bad Request"; | |
440 | |
441 case HttpStatus_401_Unauthorized: | |
442 return "Unauthorized"; | |
443 | |
444 case HttpStatus_402_PaymentRequired: | |
445 return "Payment Required"; | |
446 | |
447 case HttpStatus_403_Forbidden: | |
448 return "Forbidden"; | |
449 | |
450 case HttpStatus_404_NotFound: | |
451 return "Not Found"; | |
452 | |
453 case HttpStatus_405_MethodNotAllowed: | |
454 return "Method Not Allowed"; | |
455 | |
456 case HttpStatus_406_NotAcceptable: | |
457 return "Not Acceptable"; | |
458 | |
459 case HttpStatus_407_ProxyAuthenticationRequired: | |
460 return "Proxy Authentication Required"; | |
461 | |
462 case HttpStatus_408_RequestTimeout: | |
463 return "Request Timeout"; | |
464 | |
465 case HttpStatus_409_Conflict: | |
466 return "Conflict"; | |
467 | |
468 case HttpStatus_410_Gone: | |
469 return "Gone"; | |
470 | |
471 case HttpStatus_411_LengthRequired: | |
472 return "Length Required"; | |
473 | |
474 case HttpStatus_412_PreconditionFailed: | |
475 return "Precondition Failed"; | |
476 | |
477 case HttpStatus_413_RequestEntityTooLarge: | |
478 return "Request Entity Too Large"; | |
479 | |
480 case HttpStatus_414_RequestUriTooLong: | |
481 return "Request-URI Too Long"; | |
482 | |
483 case HttpStatus_415_UnsupportedMediaType: | |
484 return "Unsupported Media Type"; | |
485 | |
486 case HttpStatus_416_RequestedRangeNotSatisfiable: | |
487 return "Requested Range Not Satisfiable"; | |
488 | |
489 case HttpStatus_417_ExpectationFailed: | |
490 return "Expectation Failed"; | |
491 | |
492 case HttpStatus_422_UnprocessableEntity: | |
493 return "Unprocessable Entity"; | |
494 | |
495 case HttpStatus_423_Locked: | |
496 return "Locked"; | |
497 | |
498 case HttpStatus_424_FailedDependency: | |
499 return "Failed Dependency"; | |
500 | |
501 case HttpStatus_426_UpgradeRequired: | |
502 return "Upgrade Required"; | |
503 | |
504 case HttpStatus_500_InternalServerError: | |
505 return "Internal Server Error"; | |
506 | |
507 case HttpStatus_501_NotImplemented: | |
508 return "Not Implemented"; | |
509 | |
510 case HttpStatus_502_BadGateway: | |
511 return "Bad Gateway"; | |
512 | |
513 case HttpStatus_503_ServiceUnavailable: | |
514 return "Service Unavailable"; | |
515 | |
516 case HttpStatus_504_GatewayTimeout: | |
517 return "Gateway Timeout"; | |
518 | |
519 case HttpStatus_505_HttpVersionNotSupported: | |
520 return "HTTP Version Not Supported"; | |
521 | |
522 case HttpStatus_506_VariantAlsoNegotiates: | |
523 return "Variant Also Negotiates"; | |
524 | |
525 case HttpStatus_507_InsufficientStorage: | |
526 return "Insufficient Storage"; | |
527 | |
528 case HttpStatus_509_BandwidthLimitExceeded: | |
529 return "Bandwidth Limit Exceeded"; | |
530 | |
531 case HttpStatus_510_NotExtended: | |
532 return "Not Extended"; | |
533 | |
534 default: | |
535 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
536 } | |
537 } | |
538 | |
539 | |
540 const char* EnumerationToString(ResourceType type) | |
541 { | |
542 switch (type) | |
543 { | |
544 case ResourceType_Patient: | |
545 return "Patient"; | |
546 | |
547 case ResourceType_Study: | |
548 return "Study"; | |
549 | |
550 case ResourceType_Series: | |
551 return "Series"; | |
552 | |
553 case ResourceType_Instance: | |
554 return "Instance"; | |
555 | |
556 default: | |
557 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
558 } | |
559 } | |
560 | |
561 | |
562 const char* EnumerationToString(ImageFormat format) | |
563 { | |
564 switch (format) | |
565 { | |
566 case ImageFormat_Png: | |
567 return "Png"; | |
568 | |
569 default: | |
570 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
571 } | |
572 } | |
573 | |
574 | |
575 const char* EnumerationToString(Encoding encoding) | |
576 { | |
577 switch (encoding) | |
578 { | |
579 case Encoding_Ascii: | |
580 return "Ascii"; | |
581 | |
582 case Encoding_Utf8: | |
583 return "Utf8"; | |
584 | |
585 case Encoding_Latin1: | |
586 return "Latin1"; | |
587 | |
588 case Encoding_Latin2: | |
589 return "Latin2"; | |
590 | |
591 case Encoding_Latin3: | |
592 return "Latin3"; | |
593 | |
594 case Encoding_Latin4: | |
595 return "Latin4"; | |
596 | |
597 case Encoding_Latin5: | |
598 return "Latin5"; | |
599 | |
600 case Encoding_Cyrillic: | |
601 return "Cyrillic"; | |
602 | |
603 case Encoding_Windows1251: | |
604 return "Windows1251"; | |
605 | |
606 case Encoding_Arabic: | |
607 return "Arabic"; | |
608 | |
609 case Encoding_Greek: | |
610 return "Greek"; | |
611 | |
612 case Encoding_Hebrew: | |
613 return "Hebrew"; | |
614 | |
615 case Encoding_Thai: | |
616 return "Thai"; | |
617 | |
618 case Encoding_Japanese: | |
619 return "Japanese"; | |
620 | |
621 case Encoding_Chinese: | |
622 return "Chinese"; | |
623 | |
624 default: | |
625 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
626 } | |
627 } | |
628 | |
629 | |
630 const char* EnumerationToString(PhotometricInterpretation photometric) | |
631 { | |
632 switch (photometric) | |
633 { | |
634 case PhotometricInterpretation_RGB: | |
635 return "RGB"; | |
636 | |
637 case PhotometricInterpretation_Monochrome1: | |
638 return "Monochrome1"; | |
639 | |
640 case PhotometricInterpretation_Monochrome2: | |
641 return "Monochrome2"; | |
642 | |
643 case PhotometricInterpretation_ARGB: | |
644 return "ARGB"; | |
645 | |
646 case PhotometricInterpretation_CMYK: | |
647 return "CMYK"; | |
648 | |
649 case PhotometricInterpretation_HSV: | |
650 return "HSV"; | |
651 | |
652 case PhotometricInterpretation_Palette: | |
653 return "Palette color"; | |
654 | |
655 case PhotometricInterpretation_YBRFull: | |
656 return "YBR full"; | |
657 | |
658 case PhotometricInterpretation_YBRFull422: | |
659 return "YBR full 422"; | |
660 | |
661 case PhotometricInterpretation_YBRPartial420: | |
662 return "YBR partial 420"; | |
663 | |
664 case PhotometricInterpretation_YBRPartial422: | |
665 return "YBR partial 422"; | |
666 | |
667 case PhotometricInterpretation_YBR_ICT: | |
668 return "YBR ICT"; | |
669 | |
670 case PhotometricInterpretation_YBR_RCT: | |
671 return "YBR RCT"; | |
672 | |
673 case PhotometricInterpretation_Unknown: | |
674 return "Unknown"; | |
675 | |
676 default: | |
677 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
678 } | |
679 } | |
680 | |
681 | |
682 const char* EnumerationToString(RequestOrigin origin) | |
683 { | |
684 switch (origin) | |
685 { | |
686 case RequestOrigin_Unknown: | |
687 return "Unknown"; | |
688 | |
689 case RequestOrigin_DicomProtocol: | |
690 return "DicomProtocol"; | |
691 | |
692 case RequestOrigin_RestApi: | |
693 return "RestApi"; | |
694 | |
695 case RequestOrigin_Plugins: | |
696 return "Plugins"; | |
697 | |
698 case RequestOrigin_Lua: | |
699 return "Lua"; | |
700 | |
701 default: | |
702 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
703 } | |
704 } | |
705 | |
706 | |
707 const char* EnumerationToString(LogLevel level) | |
708 { | |
709 switch (level) | |
710 { | |
711 case LogLevel_Error: | |
712 return "ERROR"; | |
713 | |
714 case LogLevel_Warning: | |
715 return "WARNING"; | |
716 | |
717 case LogLevel_Info: | |
718 return "INFO"; | |
719 | |
720 case LogLevel_Trace: | |
721 return "TRACE"; | |
722 | |
723 default: | |
724 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
725 } | |
726 } | |
727 | |
728 | |
729 const char* EnumerationToString(PixelFormat format) | |
730 { | |
731 switch (format) | |
732 { | |
733 case PixelFormat_RGB24: | |
734 return "RGB24"; | |
735 | |
736 case PixelFormat_RGBA32: | |
737 return "RGBA32"; | |
738 | |
739 case PixelFormat_BGRA32: | |
740 return "BGRA32"; | |
741 | |
742 case PixelFormat_Grayscale8: | |
743 return "Grayscale (unsigned 8bpp)"; | |
744 | |
745 case PixelFormat_Grayscale16: | |
746 return "Grayscale (unsigned 16bpp)"; | |
747 | |
748 case PixelFormat_SignedGrayscale16: | |
749 return "Grayscale (signed 16bpp)"; | |
750 | |
751 case PixelFormat_Float32: | |
752 return "Grayscale (float 32bpp)"; | |
753 | |
754 default: | |
755 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
756 } | |
757 } | |
758 | |
759 | |
760 Encoding StringToEncoding(const char* encoding) | |
761 { | |
762 std::string s(encoding); | |
763 Toolbox::ToUpperCase(s); | |
764 | |
765 if (s == "UTF8") | |
766 { | |
767 return Encoding_Utf8; | |
768 } | |
769 | |
770 if (s == "ASCII") | |
771 { | |
772 return Encoding_Ascii; | |
773 } | |
774 | |
775 if (s == "LATIN1") | |
776 { | |
777 return Encoding_Latin1; | |
778 } | |
779 | |
780 if (s == "LATIN2") | |
781 { | |
782 return Encoding_Latin2; | |
783 } | |
784 | |
785 if (s == "LATIN3") | |
786 { | |
787 return Encoding_Latin3; | |
788 } | |
789 | |
790 if (s == "LATIN4") | |
791 { | |
792 return Encoding_Latin4; | |
793 } | |
794 | |
795 if (s == "LATIN5") | |
796 { | |
797 return Encoding_Latin5; | |
798 } | |
799 | |
800 if (s == "CYRILLIC") | |
801 { | |
802 return Encoding_Cyrillic; | |
803 } | |
804 | |
805 if (s == "WINDOWS1251") | |
806 { | |
807 return Encoding_Windows1251; | |
808 } | |
809 | |
810 if (s == "ARABIC") | |
811 { | |
812 return Encoding_Arabic; | |
813 } | |
814 | |
815 if (s == "GREEK") | |
816 { | |
817 return Encoding_Greek; | |
818 } | |
819 | |
820 if (s == "HEBREW") | |
821 { | |
822 return Encoding_Hebrew; | |
823 } | |
824 | |
825 if (s == "THAI") | |
826 { | |
827 return Encoding_Thai; | |
828 } | |
829 | |
830 if (s == "JAPANESE") | |
831 { | |
832 return Encoding_Japanese; | |
833 } | |
834 | |
835 if (s == "CHINESE") | |
836 { | |
837 return Encoding_Chinese; | |
838 } | |
839 | |
840 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
841 } | |
842 | |
843 | |
844 ResourceType StringToResourceType(const char* type) | |
845 { | |
846 std::string s(type); | |
847 Toolbox::ToUpperCase(s); | |
848 | |
849 if (s == "PATIENT" || s == "PATIENTS") | |
850 { | |
851 return ResourceType_Patient; | |
852 } | |
853 else if (s == "STUDY" || s == "STUDIES") | |
854 { | |
855 return ResourceType_Study; | |
856 } | |
857 else if (s == "SERIES") | |
858 { | |
859 return ResourceType_Series; | |
860 } | |
861 else if (s == "INSTANCE" || s == "IMAGE" || | |
862 s == "INSTANCES" || s == "IMAGES") | |
863 { | |
864 return ResourceType_Instance; | |
865 } | |
866 | |
867 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
868 } | |
869 | |
870 | |
871 ImageFormat StringToImageFormat(const char* format) | |
872 { | |
873 std::string s(format); | |
874 Toolbox::ToUpperCase(s); | |
875 | |
876 if (s == "PNG") | |
877 { | |
878 return ImageFormat_Png; | |
879 } | |
880 | |
881 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
882 } | |
883 | |
884 | |
885 LogLevel StringToLogLevel(const char *level) | |
886 { | |
887 if (strcmp(level, "ERROR") == 0) | |
888 { | |
889 return LogLevel_Error; | |
890 } | |
891 else if (strcmp(level, "WARNING") == 0) | |
892 { | |
893 return LogLevel_Warning; | |
894 } | |
895 else if (strcmp(level, "INFO") == 0) | |
896 { | |
897 return LogLevel_Info; | |
898 } | |
899 else if (strcmp(level, "TRACE") == 0) | |
900 { | |
901 return LogLevel_Trace; | |
902 } | |
903 else | |
904 { | |
905 throw OrthancException(ErrorCode_InternalError); | |
906 } | |
907 } | |
908 | |
909 | |
910 ValueRepresentation StringToValueRepresentation(const std::string& vr, | |
911 bool throwIfUnsupported) | |
912 { | |
913 if (vr == "AE") | |
914 { | |
915 return ValueRepresentation_ApplicationEntity; | |
916 } | |
917 else if (vr == "AS") | |
918 { | |
919 return ValueRepresentation_AgeString; | |
920 } | |
921 else if (vr == "AT") | |
922 { | |
923 return ValueRepresentation_AttributeTag; | |
924 } | |
925 else if (vr == "CS") | |
926 { | |
927 return ValueRepresentation_CodeString; | |
928 } | |
929 else if (vr == "DA") | |
930 { | |
931 return ValueRepresentation_Date; | |
932 } | |
933 else if (vr == "DS") | |
934 { | |
935 return ValueRepresentation_DecimalString; | |
936 } | |
937 else if (vr == "DT") | |
938 { | |
939 return ValueRepresentation_DateTime; | |
940 } | |
941 else if (vr == "FL") | |
942 { | |
943 return ValueRepresentation_FloatingPointSingle; | |
944 } | |
945 else if (vr == "FD") | |
946 { | |
947 return ValueRepresentation_FloatingPointDouble; | |
948 } | |
949 else if (vr == "IS") | |
950 { | |
951 return ValueRepresentation_IntegerString; | |
952 } | |
953 else if (vr == "LO") | |
954 { | |
955 return ValueRepresentation_LongString; | |
956 } | |
957 else if (vr == "LT") | |
958 { | |
959 return ValueRepresentation_LongText; | |
960 } | |
961 else if (vr == "OB") | |
962 { | |
963 return ValueRepresentation_OtherByte; | |
964 } | |
965 else if (vr == "OD") | |
966 { | |
967 return ValueRepresentation_OtherDouble; | |
968 } | |
969 else if (vr == "OF") | |
970 { | |
971 return ValueRepresentation_OtherFloat; | |
972 } | |
973 else if (vr == "OL") | |
974 { | |
975 return ValueRepresentation_OtherLong; | |
976 } | |
977 else if (vr == "OW") | |
978 { | |
979 return ValueRepresentation_OtherWord; | |
980 } | |
981 else if (vr == "PN") | |
982 { | |
983 return ValueRepresentation_PersonName; | |
984 } | |
985 else if (vr == "SH") | |
986 { | |
987 return ValueRepresentation_ShortString; | |
988 } | |
989 else if (vr == "SL") | |
990 { | |
991 return ValueRepresentation_SignedLong; | |
992 } | |
993 else if (vr == "SQ") | |
994 { | |
995 return ValueRepresentation_Sequence; | |
996 } | |
997 else if (vr == "SS") | |
998 { | |
999 return ValueRepresentation_SignedShort; | |
1000 } | |
1001 else if (vr == "ST") | |
1002 { | |
1003 return ValueRepresentation_ShortText; | |
1004 } | |
1005 else if (vr == "TM") | |
1006 { | |
1007 return ValueRepresentation_Time; | |
1008 } | |
1009 else if (vr == "UC") | |
1010 { | |
1011 return ValueRepresentation_UnlimitedCharacters; | |
1012 } | |
1013 else if (vr == "UI") | |
1014 { | |
1015 return ValueRepresentation_UniqueIdentifier; | |
1016 } | |
1017 else if (vr == "UL") | |
1018 { | |
1019 return ValueRepresentation_UnsignedLong; | |
1020 } | |
1021 else if (vr == "UN") | |
1022 { | |
1023 return ValueRepresentation_Unknown; | |
1024 } | |
1025 else if (vr == "UR") | |
1026 { | |
1027 return ValueRepresentation_UniversalResource; | |
1028 } | |
1029 else if (vr == "US") | |
1030 { | |
1031 return ValueRepresentation_UnsignedShort; | |
1032 } | |
1033 else if (vr == "UT") | |
1034 { | |
1035 return ValueRepresentation_UnlimitedText; | |
1036 } | |
1037 else | |
1038 { | |
1039 std::string s = "Unsupported value representation encountered: " + vr; | |
1040 | |
1041 if (throwIfUnsupported) | |
1042 { | |
1043 LOG(ERROR) << s; | |
1044 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1045 } | |
1046 else | |
1047 { | |
1048 LOG(INFO) << s; | |
1049 return ValueRepresentation_NotSupported; | |
1050 } | |
1051 } | |
1052 } | |
1053 | |
1054 | |
1055 unsigned int GetBytesPerPixel(PixelFormat format) | |
1056 { | |
1057 switch (format) | |
1058 { | |
1059 case PixelFormat_Grayscale8: | |
1060 return 1; | |
1061 | |
1062 case PixelFormat_Grayscale16: | |
1063 case PixelFormat_SignedGrayscale16: | |
1064 return 2; | |
1065 | |
1066 case PixelFormat_RGB24: | |
1067 return 3; | |
1068 | |
1069 case PixelFormat_RGBA32: | |
1070 case PixelFormat_BGRA32: | |
1071 return 4; | |
1072 | |
1073 case PixelFormat_Float32: | |
1074 assert(sizeof(float) == 4); | |
1075 return 4; | |
1076 | |
1077 default: | |
1078 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1079 } | |
1080 } | |
1081 | |
1082 | |
1083 bool GetDicomEncoding(Encoding& encoding, | |
1084 const char* specificCharacterSet) | |
1085 { | |
1086 std::string s = specificCharacterSet; | |
1087 Toolbox::ToUpperCase(s); | |
1088 | |
1089 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2 | |
1090 // https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/SpecificCharacterSet.java | |
1091 if (s == "ISO_IR 6" || | |
1092 s == "ISO_IR 192" || | |
1093 s == "ISO 2022 IR 6") | |
1094 { | |
1095 encoding = Encoding_Utf8; | |
1096 } | |
1097 else if (s == "ISO_IR 100" || | |
1098 s == "ISO 2022 IR 100") | |
1099 { | |
1100 encoding = Encoding_Latin1; | |
1101 } | |
1102 else if (s == "ISO_IR 101" || | |
1103 s == "ISO 2022 IR 101") | |
1104 { | |
1105 encoding = Encoding_Latin2; | |
1106 } | |
1107 else if (s == "ISO_IR 109" || | |
1108 s == "ISO 2022 IR 109") | |
1109 { | |
1110 encoding = Encoding_Latin3; | |
1111 } | |
1112 else if (s == "ISO_IR 110" || | |
1113 s == "ISO 2022 IR 110") | |
1114 { | |
1115 encoding = Encoding_Latin4; | |
1116 } | |
1117 else if (s == "ISO_IR 148" || | |
1118 s == "ISO 2022 IR 148") | |
1119 { | |
1120 encoding = Encoding_Latin5; | |
1121 } | |
1122 else if (s == "ISO_IR 144" || | |
1123 s == "ISO 2022 IR 144") | |
1124 { | |
1125 encoding = Encoding_Cyrillic; | |
1126 } | |
1127 else if (s == "ISO_IR 127" || | |
1128 s == "ISO 2022 IR 127") | |
1129 { | |
1130 encoding = Encoding_Arabic; | |
1131 } | |
1132 else if (s == "ISO_IR 126" || | |
1133 s == "ISO 2022 IR 126") | |
1134 { | |
1135 encoding = Encoding_Greek; | |
1136 } | |
1137 else if (s == "ISO_IR 138" || | |
1138 s == "ISO 2022 IR 138") | |
1139 { | |
1140 encoding = Encoding_Hebrew; | |
1141 } | |
1142 else if (s == "ISO_IR 166" || s == "ISO 2022 IR 166") | |
1143 { | |
1144 encoding = Encoding_Thai; | |
1145 } | |
1146 else if (s == "ISO_IR 13" || s == "ISO 2022 IR 13") | |
1147 { | |
1148 encoding = Encoding_Japanese; | |
1149 } | |
1150 else if (s == "GB18030") | |
1151 { | |
1152 encoding = Encoding_Chinese; | |
1153 } | |
1154 /* | |
1155 else if (s == "ISO 2022 IR 149") | |
1156 { | |
1157 TODO | |
1158 } | |
1159 else if (s == "ISO 2022 IR 159") | |
1160 { | |
1161 TODO | |
1162 } | |
1163 else if (s == "ISO 2022 IR 87") | |
1164 { | |
1165 TODO | |
1166 } | |
1167 */ | |
1168 else | |
1169 { | |
1170 return false; | |
1171 } | |
1172 | |
1173 // The encoding was properly detected | |
1174 return true; | |
1175 } | |
1176 | |
1177 | |
1178 ResourceType GetChildResourceType(ResourceType type) | |
1179 { | |
1180 switch (type) | |
1181 { | |
1182 case ResourceType_Patient: | |
1183 return ResourceType_Study; | |
1184 | |
1185 case ResourceType_Study: | |
1186 return ResourceType_Series; | |
1187 | |
1188 case ResourceType_Series: | |
1189 return ResourceType_Instance; | |
1190 | |
1191 default: | |
1192 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1193 } | |
1194 } | |
1195 | |
1196 | |
1197 ResourceType GetParentResourceType(ResourceType type) | |
1198 { | |
1199 switch (type) | |
1200 { | |
1201 case ResourceType_Study: | |
1202 return ResourceType_Patient; | |
1203 | |
1204 case ResourceType_Series: | |
1205 return ResourceType_Study; | |
1206 | |
1207 case ResourceType_Instance: | |
1208 return ResourceType_Series; | |
1209 | |
1210 default: | |
1211 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1212 } | |
1213 } | |
1214 | |
1215 | |
1216 DicomModule GetModule(ResourceType type) | |
1217 { | |
1218 switch (type) | |
1219 { | |
1220 case ResourceType_Patient: | |
1221 return DicomModule_Patient; | |
1222 | |
1223 case ResourceType_Study: | |
1224 return DicomModule_Study; | |
1225 | |
1226 case ResourceType_Series: | |
1227 return DicomModule_Series; | |
1228 | |
1229 default: | |
1230 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1231 } | |
1232 } | |
1233 | |
1234 | |
1235 | |
1236 const char* GetDicomSpecificCharacterSet(Encoding encoding) | |
1237 { | |
1238 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2 | |
1239 switch (encoding) | |
1240 { | |
1241 case Encoding_Utf8: | |
1242 case Encoding_Ascii: | |
1243 return "ISO_IR 192"; | |
1244 | |
1245 case Encoding_Latin1: | |
1246 return "ISO_IR 100"; | |
1247 | |
1248 case Encoding_Latin2: | |
1249 return "ISO_IR 101"; | |
1250 | |
1251 case Encoding_Latin3: | |
1252 return "ISO_IR 109"; | |
1253 | |
1254 case Encoding_Latin4: | |
1255 return "ISO_IR 110"; | |
1256 | |
1257 case Encoding_Latin5: | |
1258 return "ISO_IR 148"; | |
1259 | |
1260 case Encoding_Cyrillic: | |
1261 return "ISO_IR 144"; | |
1262 | |
1263 case Encoding_Arabic: | |
1264 return "ISO_IR 127"; | |
1265 | |
1266 case Encoding_Greek: | |
1267 return "ISO_IR 126"; | |
1268 | |
1269 case Encoding_Hebrew: | |
1270 return "ISO_IR 138"; | |
1271 | |
1272 case Encoding_Japanese: | |
1273 return "ISO_IR 13"; | |
1274 | |
1275 case Encoding_Chinese: | |
1276 return "GB18030"; | |
1277 | |
1278 case Encoding_Thai: | |
1279 return "ISO_IR 166"; | |
1280 | |
1281 default: | |
1282 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1283 } | |
1284 } | |
1285 | |
1286 | |
1287 // This function is autogenerated by the script | |
1288 // "Resources/GenerateErrorCodes.py" | |
1289 HttpStatus ConvertErrorCodeToHttpStatus(ErrorCode error) | |
1290 { | |
1291 switch (error) | |
1292 { | |
1293 case ErrorCode_Success: | |
1294 return HttpStatus_200_Ok; | |
1295 | |
1296 case ErrorCode_ParameterOutOfRange: | |
1297 return HttpStatus_400_BadRequest; | |
1298 | |
1299 case ErrorCode_BadParameterType: | |
1300 return HttpStatus_400_BadRequest; | |
1301 | |
1302 case ErrorCode_InexistentItem: | |
1303 return HttpStatus_404_NotFound; | |
1304 | |
1305 case ErrorCode_BadRequest: | |
1306 return HttpStatus_400_BadRequest; | |
1307 | |
1308 case ErrorCode_UriSyntax: | |
1309 return HttpStatus_400_BadRequest; | |
1310 | |
1311 case ErrorCode_InexistentFile: | |
1312 return HttpStatus_404_NotFound; | |
1313 | |
1314 case ErrorCode_BadFileFormat: | |
1315 return HttpStatus_400_BadRequest; | |
1316 | |
1317 case ErrorCode_UnknownResource: | |
1318 return HttpStatus_404_NotFound; | |
1319 | |
1320 case ErrorCode_InexistentTag: | |
1321 return HttpStatus_404_NotFound; | |
1322 | |
1323 case ErrorCode_BadJson: | |
1324 return HttpStatus_400_BadRequest; | |
1325 | |
1326 case ErrorCode_Unauthorized: | |
1327 return HttpStatus_401_Unauthorized; | |
1328 | |
1329 case ErrorCode_NotAcceptable: | |
1330 return HttpStatus_406_NotAcceptable; | |
1331 | |
1332 default: | |
1333 return HttpStatus_500_InternalServerError; | |
1334 } | |
1335 } | |
1336 | |
1337 | |
1338 bool IsUserContentType(FileContentType type) | |
1339 { | |
1340 return (type >= FileContentType_StartUser && | |
1341 type <= FileContentType_EndUser); | |
1342 } | |
1343 | |
1344 | |
1345 bool IsBinaryValueRepresentation(ValueRepresentation vr) | |
1346 { | |
1347 // http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html | |
1348 | |
1349 switch (vr) | |
1350 { | |
1351 case ValueRepresentation_ApplicationEntity: // AE | |
1352 case ValueRepresentation_AgeString: // AS | |
1353 case ValueRepresentation_CodeString: // CS | |
1354 case ValueRepresentation_Date: // DA | |
1355 case ValueRepresentation_DecimalString: // DS | |
1356 case ValueRepresentation_DateTime: // DT | |
1357 case ValueRepresentation_IntegerString: // IS | |
1358 case ValueRepresentation_LongString: // LO | |
1359 case ValueRepresentation_LongText: // LT | |
1360 case ValueRepresentation_PersonName: // PN | |
1361 case ValueRepresentation_ShortString: // SH | |
1362 case ValueRepresentation_ShortText: // ST | |
1363 case ValueRepresentation_Time: // TM | |
1364 case ValueRepresentation_UnlimitedCharacters: // UC | |
1365 case ValueRepresentation_UniqueIdentifier: // UI (UID) | |
1366 case ValueRepresentation_UniversalResource: // UR (URI or URL) | |
1367 case ValueRepresentation_UnlimitedText: // UT | |
1368 { | |
1369 return false; | |
1370 } | |
1371 | |
1372 /** | |
1373 * Below are all the VR whose character repertoire is tagged as | |
1374 * "not applicable" | |
1375 **/ | |
1376 case ValueRepresentation_AttributeTag: // AT (2 x uint16_t) | |
1377 case ValueRepresentation_FloatingPointSingle: // FL (float) | |
1378 case ValueRepresentation_FloatingPointDouble: // FD (double) | |
1379 case ValueRepresentation_OtherByte: // OB | |
1380 case ValueRepresentation_OtherDouble: // OD | |
1381 case ValueRepresentation_OtherFloat: // OF | |
1382 case ValueRepresentation_OtherLong: // OL | |
1383 case ValueRepresentation_OtherWord: // OW | |
1384 case ValueRepresentation_SignedLong: // SL (int32_t) | |
1385 case ValueRepresentation_Sequence: // SQ | |
1386 case ValueRepresentation_SignedShort: // SS (int16_t) | |
1387 case ValueRepresentation_UnsignedLong: // UL (uint32_t) | |
1388 case ValueRepresentation_Unknown: // UN | |
1389 case ValueRepresentation_UnsignedShort: // US (uint16_t) | |
1390 { | |
1391 return true; | |
1392 } | |
1393 | |
1394 case ValueRepresentation_NotSupported: | |
1395 default: | |
1396 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1397 } | |
1398 } | |
1399 } |